]> git.tdb.fi Git - r2c2.git/commitdiff
Make use of View3D in engineer
authorMikko Rasa <tdb@tdb.fi>
Sun, 21 Jul 2013 15:25:59 +0000 (18:25 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sun, 21 Jul 2013 15:25:59 +0000 (18:25 +0300)
source/3d/layout.cpp
source/3d/view.cpp
source/3d/view.h
source/engineer/engineer.cpp
source/engineer/engineer.h
source/engineer/trainview.cpp
source/engineer/trainview.h

index 72e5052e6689c5f2058b83b5d9e03c75098bf895..fe3514f4cd29437627cd1f213833e6e2f759a3ff 100644 (file)
@@ -16,6 +16,8 @@ Layout3D::Layout3D(Layout &l):
 {
        // South, 15° from zenith
        sun.set_position(0, -0.259, 0.966, 0);
+       sun.set_diffuse(GL::Color(0.9));
+       lighting.set_ambient(GL::Color(0.4));
        lighting.attach(0, sun);
 
        layout.signal_object_added.connect(sigc::mem_fun(this, &Layout3D::object_added));
index 017a526df71b215ca192218116f79b3fd97c7178..8943abce36e7e2c0307fca0b4f9bea6ce24ab11f 100644 (file)
@@ -10,6 +10,8 @@ namespace R2C2 {
 
 View3D::View3D(Layout3D &l, unsigned w, unsigned h):
        layout(l),
+       width(w),
+       height(h),
        pipeline(w, h)
 {
        pipeline.set_camera(&camera);
@@ -22,6 +24,7 @@ View3D::View3D(Layout3D &l, unsigned w, unsigned h):
        camera.set_up_direction(GL::Vector3(0, 0, 1));
        // Y+, 60° down
        camera.set_look_direction(GL::Vector3(0, 0.5, -0.866));
+       camera.set_aspect(float(width)/height);
 
        view_all();
 }
index f3e359c2b9524108b1f566a9e19ffc1ad0e31c92..ffe608e88cfe2a63113ea1f333e3dea86c68dc78 100644 (file)
@@ -12,6 +12,8 @@ class View3D
 {
 protected:
        Layout3D &layout;
+       unsigned width;
+       unsigned height;
        Msp::GL::Camera camera;
        Msp::GL::Pipeline pipeline;
 
index f0999d91cd9ffaddd1736f0c6fd6493e36077084..f89fbd174d061aad7b5838a885de09976f8390dc 100644 (file)
@@ -42,7 +42,7 @@ Engineer::Engineer(int argc, char **argv):
        layout(catalogue, (options.driver.empty() ? 0 : Driver::create(options.driver))),
        layout_3d(layout),
        server(0),
-       pipeline(window.get_width(), window.get_height(), false),
+       main_view(layout_3d, window.get_width(), window.get_height()),
        picking(false),
        picking_track(0),
        picking_entry(0),
@@ -95,25 +95,15 @@ Engineer::Engineer(int argc, char **argv):
        // Setup 3D view
        DataFile::load(arrow_mesh, "arrow.mesh");
 
-       pipeline.set_camera(&camera);
-       pipeline.add_renderable_for_pass(layout_3d.get_scene(), 0);
-       pipeline.add_renderable_for_pass(layout_3d.get_path_scene(), "unlit");
-       pipeline.add_renderable_for_pass(*overlay, "overlay");
+       GL::Pipeline &pipeline = main_view.get_pipeline();
 
-       light.set_position(GL::Vector4(0, -0.259, 0.966, 0));
-       light.set_diffuse(GL::Color(0.9));
-       lighting.set_ambient(GL::Color(0.4));
-       lighting.attach(0, light);
-
-       GL::Pipeline::Pass *pass = &pipeline.add_pass(0);
-       pass->set_depth_test(&GL::DepthTest::lequal());
-       pass->set_lighting(&lighting);
-
-       pass = &pipeline.add_pass("unlit");
+       GL::Pipeline::Pass *pass = &pipeline.add_pass("unlit");
        pass->set_depth_test(&GL::DepthTest::lequal());
+       pipeline.add_renderable_for_pass(layout_3d.get_path_scene(), "unlit");
 
        pass = &pipeline.add_pass("overlay");
        pass->set_blend(&GL::Blend::alpha());
+       pipeline.add_renderable_for_pass(*overlay, "overlay");
 
        view_all();
 
@@ -197,7 +187,7 @@ void Engineer::tick()
 
        GL::Framebuffer::system().clear(GL::COLOR_BUFFER_BIT|GL::DEPTH_BUFFER_BIT);
 
-       pipeline.render();
+       main_view.render();
 
        if(pointer_moved)
        {
@@ -222,7 +212,7 @@ void Engineer::tick()
 
        if(picking && picking_track && picking_entry>=0)
        {
-               camera.apply();
+               main_view.get_camera().apply();
                GL::MatrixStack::Push push_mat(GL::MatrixStack::modelview());
 
                Snap sn = picking_track->get_snap_node(picking_entry);
@@ -309,7 +299,7 @@ void Engineer::view_all()
        const Layout3D::ObjectMap &objects = layout_3d.get_all();
 
        float view_aspect = float(window.get_width())/window.get_height();
-       float view_height = tan(camera.get_field_of_view()/2.0f)*2.0f;
+       float view_height = tan(main_view.get_camera().get_field_of_view()/2.0f)*2.0f;
        float best_score = 0;
        GL::Vector3 pos;
        GL::Vector3 up;
@@ -344,6 +334,7 @@ void Engineer::view_all()
                }
        }
 
+       GL::Camera &camera = main_view.get_camera();
        camera.set_position(pos);
        camera.set_up_direction(up);
        camera.set_look_direction(GL::Vector3(0, 0, -1));
@@ -353,8 +344,8 @@ void Engineer::view_all()
 
 Object *Engineer::pick_object(const Vector &p)
 {
-       const GL::Vector3 &start = camera.get_position();
-       GL::Vector4 ray = camera.unproject(GL::Vector4(p.x, p.y, 0, 0));
+       const GL::Vector3 &start = main_view.get_camera().get_position();
+       GL::Vector4 ray = main_view.get_camera().unproject(GL::Vector4(p.x, p.y, 0, 0));
 
        // XXX Do this better; make this function a template?
        if(Vehicle *veh = layout.pick<Vehicle>(Ray(start, Vector(ray))))
index d7fb2b859ed61408abb4bff097db1642ab096674..612fe6671854854d70cb29affd0854b831e8bdb0 100644 (file)
@@ -14,6 +14,7 @@
 #include "3d/layout.h"
 #include "3d/overlay.h"
 #include "3d/path.h"
+#include "3d/view.h"
 #include "network/server.h"
 #include "options.h"
 
@@ -42,10 +43,7 @@ private:
        R2C2::Overlay3D *overlay;
        std::map<R2C2::Train *, Msp::GL::Color> train_colors;
 
-       Msp::GL::Camera camera;
-       Msp::GL::Lighting lighting;
-       Msp::GL::Light light;
-       Msp::GL::Pipeline pipeline;
+       R2C2::View3D main_view;
        Msp::GL::Mesh arrow_mesh;
 
        MainWindow *main_wnd;
@@ -68,7 +66,7 @@ public:
        const R2C2::Catalogue &get_catalogue() const { return catalogue; }
        R2C2::Layout &get_layout() { return layout; }
        R2C2::Layout3D &get_layout_3d() { return layout_3d; }
-       const Msp::GL::Lighting &get_lighting() const { return lighting; }
+       R2C2::View3D &get_main_view() { return main_view; }
        void set_status(const std::string &);
        void add_train_view(TrainView &);
        void remove_train_view(TrainView &);
index ad534acee085872161d030ae6742fc909029a330..107800926ffbcbe2829f501e7c465916615eaf32 100644 (file)
@@ -17,7 +17,7 @@ TrainView::TrainView(Engineer &e, const Train &t):
        train(t),
        mode(SIDE),
        forward(true),
-       pipeline(400, 300, false)
+       view(engineer.get_layout_3d(), 400, 300)
 {
        Loader::WidgetMap widgets;
        DataFile::load(*this, "data/trainview.ui", widgets);
@@ -35,16 +35,7 @@ TrainView::TrainView(Engineer &e, const Train &t):
        depth.storage(GL::DEPTH_COMPONENT, 400, 300);
        fbo.attach(GL::DEPTH_ATTACHMENT, depth);
 
-       camera.set_up_direction(GL::Vector3(0, 0, 1));
-       camera.set_depth_clip(0.01, 10);
-       camera.set_aspect(1);
-       pipeline.set_camera(&camera);
-
-       pipeline.add_renderable(engineer.get_layout_3d().get_scene());
-
-       GL::Pipeline::Pass *pass = &pipeline.add_pass(0);
-       pass->set_depth_test(&GL::DepthTest::lequal());
-       pass->set_lighting(&engineer.get_lighting());
+       view.get_camera().set_depth_clip(0.01, 10);
 
        dynamic_cast<GLtk::Image *>(get_item(widgets, "img_view"))->set_image(&tex);
 
@@ -83,6 +74,7 @@ void TrainView::prepare()
        Vector side_vec = rotated_vector(Vector(0, -1, 0), angle);
        float l = veh.get_type().get_length();
 
+       GL::Camera &camera = view.get_camera();
        switch(mode)
        {
        case ROOF:
@@ -101,5 +93,5 @@ void TrainView::prepare()
 
        GL::Bind _bind_fbo(fbo);
        fbo.clear(GL::COLOR_BUFFER_BIT|GL::DEPTH_BUFFER_BIT);
-       pipeline.render();
+       view.render();
 }
index 6ee9b4e77e4a66669b84859c23b444345b277711..598b43fab9209bb520228bd886d9961e9f8e5b34 100644 (file)
@@ -29,8 +29,7 @@ private:
        Msp::GL::Framebuffer fbo;
        Msp::GL::Texture2D tex;
        Msp::GL::Renderbuffer depth;
-       Msp::GL::Camera camera;
-       Msp::GL::Pipeline pipeline;
+       R2C2::View3D view;
 
 public:
        TrainView(Engineer &, const R2C2::Train &);