3 This file is part of the MSP Märklin suite
4 Copyright © 2010 Mikkosoft Productions, Mikko Rasa
5 Distributed under the GPL
8 #include <msp/gl/tests.h>
9 #include <msp/gltk/button.h>
10 #include <msp/gltk/image.h>
11 #include "libmarklin/vehicle.h"
12 #include "libmarklin/vehicletype.h"
14 #include "trainview.h"
17 using namespace Marklin;
19 TrainView::TrainView(Engineer &e, const Train &t):
20 GLtk::Widget(e.get_ui_resources()),
21 GLtk::Panel(e.get_ui_resources()),
25 pipeline(280, 280, false),
30 tex.set_min_filter(GL::LINEAR);
31 tex.storage(GL::RGB, 280, 280, 0);
32 tex.image(0, GL::RGB, GL::UNSIGNED_BYTE, 0);
33 fbo.attach(GL::COLOR_ATTACHMENT0, tex, 0);
34 depth.storage(GL::DEPTH_COMPONENT, 280, 280);
35 fbo.attach(GL::DEPTH_ATTACHMENT, depth);
37 camera.set_up_direction(GL::Vector3(0, 0, 1));
38 camera.set_depth_clip(0.01, 10);
40 pipeline.set_camera(&camera);
42 pipeline.add_renderable(engineer.get_layout_3d().get_scene());
44 GL::PipelinePass *pass = &pipeline.add_pass(0);
45 pass->depth_test = &GL::DepthTest::lequal();
46 pass->lighting = &engineer.get_lighting();
49 add(*(image = new GLtk::Image(res, &tex)));
50 image->set_geometry(GLtk::Geometry(10, 40, geom.w-20, geom.h-50));
54 add(*(btn = new GLtk::Button(res, "Roof")));
55 btn->set_geometry(GLtk::Geometry(10, 10, 36, 25));
56 btn->signal_clicked.connect(sigc::bind(sigc::mem_fun(this, &TrainView::set_mode), ROOF));
58 add(*(btn = new GLtk::Button(res, "Side")));
59 btn->set_geometry(GLtk::Geometry(46, 10, 36, 25));
60 btn->signal_clicked.connect(sigc::bind(sigc::mem_fun(this, &TrainView::set_mode), SIDE));
62 add(*(btn = new GLtk::Button(res, "Head")));
63 btn->set_geometry(GLtk::Geometry(82, 10, 36, 25));
64 btn->signal_clicked.connect(sigc::bind(sigc::mem_fun(this, &TrainView::set_mode), HEAD));
66 add(*(btn = new GLtk::Button(res, "Close")));
67 btn->set_geometry(GLtk::Geometry(geom.w-46, 10, 36, 25));
68 btn->signal_clicked.connect(sigc::mem_fun(this, &TrainView::close_clicked));
70 engineer.add_train_view(*this);
73 TrainView::~TrainView()
75 engineer.remove_train_view(*this);
78 void TrainView::set_mode(Mode m)
83 void TrainView::prepare()
85 const Vehicle &veh = train.get_vehicle(0);
86 const Point &pos = veh.get_position();
87 float angle = veh.get_direction();
90 float l = veh.get_type().get_length();
95 camera.set_position(GL::Vector3(pos.x-l*c, pos.y-l*s, pos.z+0.07));
96 camera.set_look_direction(GL::Vector3(c, s, -0.2));
99 camera.set_position(GL::Vector3(pos.x-l*0.8*c+0.05*s, pos.y-l*0.8*s-0.05*c, pos.z+0.03));
100 camera.set_look_direction(GL::Vector3(c-0.2*s, s+0.2*c, 0));
103 camera.set_position(GL::Vector3(pos.x+l*0.55*c, pos.y+l*0.55*s, pos.z+0.03));
104 camera.set_look_direction(GL::Vector3(c, s, 0));
108 GL::Bind _bind_fbo(fbo);
109 fbo.clear(GL::COLOR_BUFFER_BIT|GL::DEPTH_BUFFER_BIT);
110 pipeline.render_all();
113 void TrainView::button_release(int x, int y, unsigned btn)
115 GLtk::Panel::button_release(x, y, btn);
120 void TrainView::close_clicked()