X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2F3d%2Ftrack.cpp;h=549bc156ba6dce2de6babcb6db4889441ce4b221;hb=5b71cb905051d654c150cb0e098cade0cb502105;hp=c3eb388dc8bb4a96b35a4a797319cf53db8dd949;hpb=7e382cc3cad8c4f6945b0c9d89e2ca917b42b740;p=r2c2.git diff --git a/source/3d/track.cpp b/source/3d/track.cpp index c3eb388..549bc15 100644 --- a/source/3d/track.cpp +++ b/source/3d/track.cpp @@ -1,145 +1,73 @@ -/* $Id$ - -This file is part of the MSP Märklin suite -Copyright © 2006-2010 Mikkosoft Productions, Mikko Rasa -Distributed under the GPL -*/ - #include -#include -#include -#include "libmarklin/tracktype.h" +#include +#include +#include "libr2c2/tracktype.h" +#include "endpoint.h" #include "layout.h" +#include "path.h" #include "track.h" #include "tracktype.h" using namespace std; using namespace Msp; -namespace Marklin { +namespace R2C2 { Track3D::Track3D(Layout3D &l, Track &t): - layout(l), + Object3D(l, t), + GL::ObjectInstance(l.get_catalogue().get_3d(t.get_type()).get_object()), track(t), - type(layout.get_catalogue().get_track(track.get_type())), - color(1, 1, 1) -{ } - -void Track3D::set_color(const Msp::GL::Color &c) -{ - color = c; -} - -void Track3D::get_bounds(float angle, Point &minp, Point &maxp) const + type(layout.get_catalogue().get_3d(track.get_type())) { - type.get_bounds(angle-track.get_rotation(), minp, maxp); + layout.get_scene().add(*this); - float c = cos(-angle); - float s = sin(-angle); - - const Point &pos = track.get_position(); - minp.x += c*pos.x-s*pos.y; - maxp.x += c*pos.x-s*pos.y; - minp.y += s*pos.x+c*pos.y; - maxp.y += s*pos.x+c*pos.y; + const vector &type_eps = track.get_type().get_endpoints(); + const vector &links = track.get_links(); + for(unsigned i=0; i&track) + endpoints.push_back(new Endpoint3D(*this, i)); + else + endpoints.push_back(0); + } - float slope = track.get_slope(); - if(slope>0) - maxp.z += slope; - else - minp.z += slope; + track.signal_link_changed.connect(sigc::mem_fun(this, &Track3D::link_changed)); } -void Track3D::render() const +Track3D::~Track3D() { - prepare_render(true); - - glPushName(reinterpret_cast(this)); - - type.render(); + layout.get_scene().remove(*this); - glPopName(); - glPopMatrix(); + for(vector::iterator i=endpoints.begin(); i!=endpoints.end(); ++i) + delete *i; } -void Track3D::render_endpoints() const +Vector Track3D::get_node() const { - prepare_render(false); - - const vector &endpoints = track.get_type().get_endpoints(); - for(unsigned i=0; i bbox = track.get_type().get_shape()->get_axis_aligned_bounding_box(); + const Vector &minp = bbox.get_minimum_point(); + const Vector &maxp = bbox.get_maximum_point(); - float c = cos(ep.dir); - float s = sin(ep.dir); - float z = (i==1 ? track.get_slope() : 0); - - glBegin(GL_QUADS); - glVertex3f(ep.pos.x-s*0.025, ep.pos.y+c*0.025, z); - glVertex3f(ep.pos.x+s*0.025, ep.pos.y-c*0.025, z); - glVertex3f(ep.pos.x+s*0.025, ep.pos.y-c*0.025, z+0.02); - glVertex3f(ep.pos.x-s*0.025, ep.pos.y+c*0.025, z+0.02); - glEnd(); - } - - if(abs(track.get_slope())>1e-4) - { - Point p; - if(track.get_slope()>0) - { - p = endpoints[1].pos; - p.z += track.get_slope(); - } - else - p = endpoints[0].pos; - glBegin(GL_TRIANGLE_STRIP); - for(unsigned i=0; i<=16; ++i) - { - float c = cos(i*M_PI/8); - float s = sin(i*M_PI/8); - glNormal3f(c, s, 0); - glVertex3f(p.x+c*0.01, p.y+s*0.01, p.z); - glVertex3f(p.x+c*0.01, p.y+s*0.01, -track.get_position().z); - } - glEnd(); - } - - glPopMatrix(); + return matrix*((minp+maxp)/2.0f+Vector(0, 0, 0.02)); } -void Track3D::render_path(int path) const +void Track3D::setup_render(Msp::GL::Renderer &renderer, const GL::Tag &) const { - prepare_render(true); - - (void)path; - /*varray.apply(); - if(path>=0 && static_cast(path)&track) + { + if(!endpoints[i]) + endpoints[i] = new Endpoint3D(*this, i); + } + else if(endpoints[i]) + { + delete endpoints[i]; + endpoints[i] = 0; + } } -} // namespace Marklin +} // namespace R2C2