]> git.tdb.fi Git - r2c2.git/blobdiff - source/engineer/engineer.cpp
Make use of View3D in engineer
[r2c2.git] / source / engineer / engineer.cpp
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))))