X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;ds=sidebyside;f=source%2Fdesigner%2Fdesigner.cpp;h=fde251cfccd4c8f7afc7da6050b458a25439d159;hb=3c04e77e639e7b7fff995ceb9cc8c00da622d26e;hp=5974816c65c1e2f4cff15df134d0e9f36c2f3e67;hpb=4e406ca29b1bb87a8e20324e5cf54f5b5de6afb8;p=r2c2.git diff --git a/source/designer/designer.cpp b/source/designer/designer.cpp index 5974816..fde251c 100644 --- a/source/designer/designer.cpp +++ b/source/designer/designer.cpp @@ -1,7 +1,7 @@ /* $Id$ This file is part of R²C² -Copyright © 2006-2010 Mikkosoft Productions, Mikko Rasa +Copyright © 2006-2011 Mikkosoft Productions, Mikko Rasa Distributed under the GPL */ @@ -14,8 +14,6 @@ Distributed under the GPL #include #include #include -#include -#include #include #include #include @@ -95,8 +93,6 @@ Designer::Designer(int argc, char **argv): } // Setup OpenGL - GL::enable(GL_CULL_FACE); - pipeline = new GL::Pipeline(window.get_width(), window.get_height(), false); pipeline->set_camera(&camera); pipeline->add_renderable_for_pass(layout_3d->get_scene(), 0); @@ -122,6 +118,9 @@ Designer::Designer(int argc, char **argv): pass->depth_test = &GL::DepthTest::lequal(); pass->blend = &GL::Blend::alpha(); + pass = &pipeline->add_pass("overlay"); + pass->blend = &GL::Blend::alpha(); + camera.set_up_direction(GL::Vector3(0, 0, 1)); camera.set_look_direction(GL::Vector3(0, 0.5, -0.866)); @@ -153,7 +152,8 @@ Designer::Designer(int argc, char **argv): statusbar->add(*lbl_status); lbl_status->set_geometry(GLtk::Geometry(20, 2, 300, 16)); - overlay = new Overlay3D(window, camera, ui_res.get_default_font()); + overlay = new Overlay3D(ui_res.get_default_font()); + pipeline->add_renderable_for_pass(*overlay, "overlay"); camera_ctl.view_all(); @@ -337,14 +337,14 @@ void Designer::add_selection_to_zone() show_zone(*cur_zone); } -Point Designer::map_pointer_to_ground(int x, int y) +Vector Designer::map_pointer_to_ground(int x, int y) { float xf = x*2.0/window.get_width()-1.0; float yf = y*2.0/window.get_height()-1.0; GL::Vector4 vec = camera.unproject(GL::Vector4(xf, yf, 0, 0)); const GL::Vector3 &pos = camera.get_position(); - return Point(pos.x-vec.x*pos.z/vec.z, pos.y-vec.y*pos.z/vec.z); + return Vector(pos.x-vec.x*pos.z/vec.z, pos.y-vec.y*pos.z/vec.z); } void Designer::tick() @@ -464,16 +464,16 @@ void Designer::button_press(int x, int y, unsigned btn, unsigned mod) y = window.get_height()-y-1; mod = Input::mod_from_sys(mod); - Point ground = map_pointer_to_ground(x, y); + Vector ground = map_pointer_to_ground(x, y); if(mode==CATALOGUE) { if(btn==1) { - Track3D *ctrack = pick_track(x, y); + Track *ctrack = pick_track(x, y); if(ctrack) { - Track *track = new Track(*layout, ctrack->get_track().get_type()); + Track *track = new Track(*layout, ctrack->get_type()); track->set_position(ground); selection.clear(); @@ -489,12 +489,12 @@ void Designer::button_press(int x, int y, unsigned btn, unsigned mod) { if(btn==1) { - Track3D *track = pick_track(x, y); + Track *track = pick_track(x, y); if(track) { if(!(mod&Input::MOD_SHIFT)) selection.clear(); - selection.toggle_track(&track->get_track()); + selection.toggle_track(track); } } } @@ -508,7 +508,7 @@ void Designer::pointer_motion(int x, int y) if(!root.get_child_at(x, y)) { - Point ground = map_pointer_to_ground(x, y); + Vector ground = map_pointer_to_ground(x, y); measure.pointer_motion(x, y, ground.x, ground.y); } } @@ -540,11 +540,6 @@ void Designer::render() else { pipeline->render_all(); - GL::enable(GL_CULL_FACE); - { - GL::Bind bind_blend(GL::Blend::alpha()); - overlay->render(0); - } GL::Bind bind_depth(GL::DepthTest::lequal()); if(mode==MEASURE) @@ -557,11 +552,11 @@ void Designer::render() GL::matrix_mode(GL::MODELVIEW); GL::load_identity(); - GL::disable(GL::DEPTH_TEST); - GL::Bind bind_blend(GL::Blend::alpha()); root.render(); + // XXX Should fix GLtk so these would not be needed GL::Texture::unbind(); + glColor3f(1.0, 1.0, 1.0); } void Designer::track_added(Track &trk) @@ -576,19 +571,18 @@ void Designer::track_removed(Track &trk) new_tracks.erase(i); } -Track3D *Designer::pick_track(int x, int y) +Track *Designer::pick_track(int x, int y) { - Layout3D *l = layout_3d; + float xx = x*2.0/window.get_width()-1.0; + float yy = y*2.0/window.get_height()-1.0; if(mode==CATALOGUE) - l = cat_layout_3d; - - float xx = ((float(x)-window.get_width()/2)/window.get_height())*0.82843; - float yy = (float(y)/window.get_height()-0.5)*0.82843; - float size = 4.0/window.get_height()*0.82843; - - apply_camera(); - - return l->pick_track(xx, yy, size); + return catalogue.get_layout().pick_track(Vector(0, 0, 1), Vector(xx*0.05523, yy*0.042421, -0.1)); + else + { + const GL::Vector3 &cpos = camera.get_position(); + GL::Vector4 cray = camera.unproject(GL::Vector4(xx, yy, 0, 0)); + return layout->pick_track(Vector(cpos.x, cpos.y, cpos.z), Vector(cray.x, cray.y, cray.z)); + } } void Designer::update_track_icon(Track3D &track) @@ -686,17 +680,16 @@ void Designer::svg_export_accept(const string &text) string Designer::tooltip(int x, int y) { - if(Track3D *t3d = pick_track(x, y)) + if(Track *track = pick_track(x, y)) { - const Track &track = t3d->get_track(); - const TrackType &ttype = track.get_type(); + const TrackType &ttype = track->get_type(); string info = format("%d %s", ttype.get_article_number(), ttype.get_description()); - if(mode!=CATALOGUE && abs(track.get_slope())>1e-4) - info += format(" (slope %.1f%%)", abs(track.get_slope()/ttype.get_total_length()*100)); - if(track.get_turnout_id()) - info += format(" (turnout %d)", track.get_turnout_id()); - else if(track.get_sensor_id()) - info += format(" (sensor %d)", track.get_sensor_id()); + if(mode!=CATALOGUE && abs(track->get_slope())>1e-4) + info += format(" (slope %.1f%%)", abs(track->get_slope()/ttype.get_total_length()*100)); + if(track->get_turnout_id()) + info += format(" (turnout %d)", track->get_turnout_id()); + else if(track->get_sensor_id()) + info += format(" (sensor %d)", track->get_sensor_id()); return info; }