]> git.tdb.fi Git - r2c2.git/blobdiff - source/engineer/trainview.cpp
Add a common base class for dialogs that need to update dynamically
[r2c2.git] / source / engineer / trainview.cpp
index ad534acee085872161d030ae6742fc909029a330..aec102705e93960a5f150114009fdc787b9c378e 100644 (file)
@@ -13,11 +13,11 @@ using namespace Msp;
 using namespace R2C2;
 
 TrainView::TrainView(Engineer &e, const Train &t):
-       engineer(e),
+       DynamicDialog(e),
        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,25 +35,9 @@ 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);
-
-       engineer.add_train_view(*this);
-}
-
-TrainView::~TrainView()
-{
-       engineer.remove_train_view(*this);
 }
 
 void TrainView::set_mode(Mode m)
@@ -72,7 +56,7 @@ void TrainView::set_forward(bool f)
        forward = f;
 }
 
-void TrainView::prepare()
+void TrainView::update()
 {
        const Vehicle &veh = train.get_vehicle(0);
        const Vector &pos = veh.get_position();
@@ -83,14 +67,15 @@ 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:
                camera.set_position(pos-l*fwd_vec+Vector(0, 0, 0.07));
-               camera.set_look_direction(fwd_vec-Vector(0, 0, -0.2));
+               camera.set_look_direction(fwd_vec-Vector(0, 0, 0.2));
                break;
        case SIDE:
-               camera.set_position(pos-0.8f*fwd_vec+0.05f*side_vec+Vector(0, 0, 0.03));
+               camera.set_position(pos-0.08f*fwd_vec+0.05f*side_vec+Vector(0, 0, 0.03));
                camera.set_look_direction(fwd_vec-side_vec*0.2f);
                break;
        case HEAD:
@@ -101,5 +86,5 @@ void TrainView::prepare()
 
        GL::Bind _bind_fbo(fbo);
        fbo.clear(GL::COLOR_BUFFER_BIT|GL::DEPTH_BUFFER_BIT);
-       pipeline.render();
+       view.render();
 }