layout(catalogue, (options.driver.empty() ? 0 : Driver::create(options.driver))),
layout_3d(layout),
server(0),
- main_view(layout_3d, window.get_width(), window.get_height()),
- picking(false),
- picking_track(0),
- picking_entry(0),
- picking_path(0),
- pointer_moved(false)
+ main_view(layout_3d, window.get_width(), window.get_height())
{
// Setup GUI
window.set_title("Railroad Engineer");
}
// Setup 3D view
- DataFile::load(arrow_mesh, "arrow.mesh");
-
GL::Pipeline &pipeline = main_view.get_pipeline();
GL::Pipeline::Pass *pass = &pipeline.add_pass("unlit");
train_views.erase(remove(train_views.begin(), train_views.end(), &tv), train_views.end());
}
-void Engineer::pick(bool with_ep)
-{
- picking = true;
- picking_track = 0;
- picking_entry = (with_ep ? 0 : -1);
-}
-
int Engineer::main()
{
window.show();
main_view.render();
- if(pointer_moved)
- {
- pointer_moved = false;
-
- if(picking)
- {
- Track *track = dynamic_cast<Track *>(pick_object(pointer));
- if(track && track!=picking_track)
- {
- picking_track = track;
- if(picking_entry>=0)
- picking_entry = 0;
-
- delete picking_path;
- picking_path = new Path3D(layout_3d.get<Track3D>(*track));
- picking_path->set_color(GL::Color(0));
- picking_path->set_layer(2);
- }
- }
- }
-
- if(picking && picking_track && picking_entry>=0)
- {
- main_view.get_camera().apply();
- GL::MatrixStack::Push push_mat(GL::MatrixStack::modelview());
-
- Snap sn = picking_track->get_snap_node(picking_entry);
-
- GL::MatrixStack::modelview() *= GL::Matrix::translation(sn.position+GL::Vector3(0, 0, 0.03));
- GL::MatrixStack::modelview() *= GL::Matrix::rotation(sn.rotation+Angle::half_turn(), 0, 0, 1);
-
- arrow_mesh.draw();
- }
-
root->render();
window.swap_buffers();
void Engineer::button_press(unsigned btn)
{
- if(picking)
- {
- if(btn==1 && picking_track)
- {
- picking = false;
- delete picking_path;
- picking_path = 0;
- signal_pick_done.emit(picking_track, picking_entry);
- }
- else if(btn==3 && picking_entry>=0)
- {
- picking_entry = (picking_entry+1)%picking_track->get_type().get_endpoints().size();
- }
- }
- else
+ if(btn==1)
{
Object *obj = pick_object(pointer);
if(Track *track = dynamic_cast<Track *>(obj))
pointer.x = value;
if(axis==1)
pointer.y = value;
- pointer_moved = true;
}
void Engineer::view_all()
class Engineer: public Msp::RegisteredApplication<Engineer>
{
-public:
- sigc::signal<void, R2C2::Track *, int> signal_pick_done;
-
private:
Options options;
std::map<R2C2::Train *, Msp::GL::Color> train_colors;
R2C2::View3D main_view;
- Msp::GL::Mesh arrow_mesh;
MainWindow *main_wnd;
std::list<R2C2::Train *> new_trains;
std::list<TrainView *> train_views;
Msp::Time::TimeStamp status_timeout;
- bool picking;
- R2C2::Track *picking_track;
- int picking_entry;
- R2C2::Path3D *picking_path;
R2C2::Vector pointer;
- bool pointer_moved;
public:
Engineer(int argc, char **argv);
void set_status(const std::string &);
void add_train_view(TrainView &);
void remove_train_view(TrainView &);
- void pick(bool);
int main();
void quit() { exit(0); }
private: