X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fdesigner%2Fdesigner.cpp;h=0effc933f8d110de8e1d52b4199fa290422ba562;hb=c06f3dde10411cd34aae026d8bf22b7771bdc3e0;hp=bfb3d5629b60f2525e12f4c89a0df9b9e47b7b31;hpb=6c2b29fb45402ee86b010f05367dad20972d25ed;p=r2c2.git diff --git a/source/designer/designer.cpp b/source/designer/designer.cpp index bfb3d56..0effc93 100644 --- a/source/designer/designer.cpp +++ b/source/designer/designer.cpp @@ -1,10 +1,3 @@ -/* $Id$ - -This file is part of R²C² -Copyright © 2006-2011 Mikkosoft Productions, Mikko Rasa -Distributed under the GPL -*/ - #include #include #include @@ -18,9 +11,9 @@ Distributed under the GPL #include #include #include -#include +#include +#include #include -#include #include #include #include @@ -56,8 +49,7 @@ Designer::Designer(int argc, char **argv): cur_zone(0), mode(SELECT), manipulator(*this, root, selection), - measure(*this), - camera_ctl(*this, root, camera) + measure(*this) { window.set_title("Railway Designer"); window.signal_close.connect(sigc::bind(sigc::mem_fun(this, &Designer::exit), 0)); @@ -92,35 +84,27 @@ Designer::Designer(int argc, char **argv): } // Setup OpenGL - 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); - if(base_object) - pipeline->add_renderable(*base_object); - pipeline->add_renderable_for_pass(layout_3d->get_path_scene(), "unlit"); - pipeline->add_renderable_for_pass(layout_3d->get_endpoint_scene(), "unlit"); + cat_view = new View3D(*cat_layout_3d, window.get_width(), window.get_height()); - light.set_position(0, -0.259, 0.966, 0); - lighting.attach(0, light); - - GL::PipelinePass *pass = &pipeline->add_pass(0); - pass->lighting = &lighting; - pass->depth_test = &GL::DepthTest::lequal(); + main_view = new View3D(*layout_3d, window.get_width(), window.get_height()); + GL::Pipeline *pipeline = &main_view->get_pipeline(); - pass = &pipeline->add_pass("unlit"); + GL::PipelinePass *pass = &pipeline->add_pass("unlit"); pass->depth_test = &GL::DepthTest::lequal(); pass->blend = &GL::Blend::alpha(); pass = &pipeline->add_pass("blended"); - pass->lighting = &lighting; + pass->lighting = &layout_3d->get_lighting(); 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)); + if(base_object) + pipeline->add_renderable(*base_object); + pipeline->add_renderable_for_pass(layout_3d->get_path_scene(), "unlit"); + pipeline->add_renderable_for_pass(layout_3d->get_endpoint_scene(), "unlit"); // Setup UI root.signal_key_press.connect(sigc::mem_fun(this, &Designer::key_press)); @@ -155,7 +139,10 @@ Designer::Designer(int argc, char **argv): overlay = new Overlay3D(ui_res.get_default_font()); pipeline->add_renderable_for_pass(*overlay, "overlay"); - camera_ctl.view_all(); + camera_ctl = new CameraController(*main_view, root); + cat_view->get_camera().set_look_direction(GL::Vector3(0, 0.13053, -0.99144)); + cat_view->view_all(true); + main_view->view_all(); const Layout3D::TrackMap &tracks = layout_3d->get_tracks(); for(Layout3D::TrackMap::const_iterator i=tracks.begin(); i!=tracks.end(); ++i) @@ -166,11 +153,14 @@ Designer::~Designer() { for(vector::iterator i=toolbars.begin(); i!=toolbars.end(); ++i) delete *i; + delete camera_ctl; + delete track_wrap; delete overlay; - delete pipeline; + delete main_view; delete base_object; delete layout_3d; delete layout; + delete cat_view; delete cat_layout_3d; } @@ -290,7 +280,7 @@ void Designer::add_selection_to_route() { cur_route->add_tracks(selection.get_tracks()); } - catch(const Exception &e) + catch(const exception &e) { lbl_status->set_text(e.what()); } @@ -329,7 +319,7 @@ void Designer::add_selection_to_zone() { cur_zone->add_tracks(selection.get_tracks()); } - catch(const Exception &e) + catch(const exception &e) { lbl_status->set_text(e.what()); } @@ -341,8 +331,8 @@ 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(); + GL::Vector4 vec = main_view->get_camera().unproject(GL::Vector4(xf, yf, 0, 0)); + const GL::Vector3 &pos = main_view->get_camera().get_position(); return Vector(pos.x-vec.x*pos.z/vec.z, pos.y-vec.y*pos.z/vec.z); } @@ -358,7 +348,7 @@ void Designer::tick() window.tick(); root.tick(); - camera_ctl.tick(dt); + camera_ctl->tick(dt); for(list::iterator i=new_tracks.begin(); i!=new_tracks.end(); ++i) layout_3d->get_track(**i).get_path().set_mask(0); @@ -513,37 +503,16 @@ void Designer::pointer_motion(int x, int y) } } -void Designer::apply_camera() -{ - if(mode==CATALOGUE) - { - GL::matrix_mode(GL::PROJECTION); - GL::load_identity(); - GL::frustum_centered(0.11046, 0.082843, 0.1, 10); - GL::matrix_mode(GL::MODELVIEW); - GL::load_identity(); - GL::translate(0, 0, -1); - } - else - camera.apply(); -} - void Designer::render() { GL::Framebuffer::system().clear(GL::COLOR_BUFFER_BIT|GL::DEPTH_BUFFER_BIT); - if(mode==CATALOGUE) - { - apply_camera(); - cat_layout_3d->get_scene().render(); - } - else + View3D *view = (mode==CATALOGUE ? cat_view : main_view); + view->render(); + if(mode==MEASURE) { - pipeline->render_all(); - GL::Bind bind_depth(GL::DepthTest::lequal()); - if(mode==MEASURE) - measure.render(); + measure.render(); } GL::matrix_mode(GL::PROJECTION); @@ -575,14 +544,12 @@ Track *Designer::pick_track(int x, int y) { float xx = x*2.0/window.get_width()-1.0; float yy = y*2.0/window.get_height()-1.0; - if(mode==CATALOGUE) - 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)); - } + + View3D &view = *(mode==CATALOGUE ? cat_view : main_view); + const GL::Vector3 &cpos = view.get_camera().get_position(); + GL::Vector4 cray = view.get_camera().unproject(GL::Vector4(xx, yy, 0, 0)); + + return view.get_layout().get_layout().pick_track(Vector(cpos.x, cpos.y, cpos.z), Vector(cray.x, cray.y, cray.z)); } void Designer::update_track_icon(Track3D &track) @@ -595,14 +562,14 @@ void Designer::update_track_icon(Track3D &track) if(unsigned sid = track.get_track().get_sensor_id()) { overlay->add_graphic(track, "sensor"); - overlay->set_label(track, lexical_cast(sid)); + overlay->set_label(track, lexical_cast(sid)); } else if(unsigned tid = track.get_track().get_turnout_id()) { if(tid<0x800) { overlay->add_graphic(track, "turnout"); - overlay->set_label(track, lexical_cast(tid)); + overlay->set_label(track, lexical_cast(tid)); } } }