X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2F3d%2Ftrack.cpp;h=5857e52d8813b8c29053e7dd107d882d7bf0f35c;hb=3df8cb5c78fbb0b919bcb79677c6c788b8028482;hp=d4b7079099406d016cee98e5406e0fb68ec17e48;hpb=de09cba1d12af38ff2e7e4312d67624fe63bf0e4;p=r2c2.git diff --git a/source/3d/track.cpp b/source/3d/track.cpp index d4b7079..5857e52 100644 --- a/source/3d/track.cpp +++ b/source/3d/track.cpp @@ -1,7 +1,7 @@ /* $Id$ This file is part of the MSP Märklin suite -Copyright © 2006-2008 Mikkosoft Productions, Mikko Rasa +Copyright © 2006-2009 Mikkosoft Productions, Mikko Rasa Distributed under the GPL */ @@ -14,8 +14,6 @@ Distributed under the GPL using namespace std; using namespace Msp; -#include - namespace Marklin { Track3D::Track3D(Track &t, unsigned q): @@ -96,10 +94,10 @@ void Track3D::render_endpoints() const float s=sin(ep.dir); glBegin(GL_QUADS); - glVertex3f(ep.x-s*0.025, ep.y+c*0.025, 0); - glVertex3f(ep.x+s*0.025, ep.y-c*0.025, 0); - glVertex3f(ep.x+s*0.025, ep.y-c*0.025, 0.02); - glVertex3f(ep.x-s*0.025, ep.y+c*0.025, 0.02); + glVertex3f(ep.pos.x-s*0.025, ep.pos.y+c*0.025, 0); + glVertex3f(ep.pos.x+s*0.025, ep.pos.y-c*0.025, 0); + glVertex3f(ep.pos.x+s*0.025, ep.pos.y-c*0.025, 0.02); + glVertex3f(ep.pos.x-s*0.025, ep.pos.y+c*0.025, 0.02); glEnd(); } @@ -173,63 +171,30 @@ void Track3D::build_part(const TrackPart &part, GL::VertexArrayBuilder &va_build } static unsigned psize=profile.size(); - const float &radius=part.radius; - const float &x=part.x; - const float &y=part.y; - const float &length=part.length; - const float &dir=part.dir; + unsigned nsegs=(part.radius ? static_cast(part.length*(1<(part.length*(1<=6) ? length/2 : length; - Point p(x+c*len*i-s*profile[j].y, y+s*len*i+c*profile[j].y, profile[j].z+i*track.get_slope()); - va_builder.vertex(p.x, p.y, p.z); - if(profile[j].z==0) - border.push_back(p); - } + unsigned k=j&~1; + float dy=profile[k+1].y-profile[k].y; + float dz=profile[k+1].z-profile[k].z; + float d=sqrt(dy*dy+dz*dz); + va_builder.normal(s*dz/d, -c*dz/d, dy/d); + + Point v(p.x+c*profile[j].x-s*profile[j].y, p.y+c*profile[j].y+s*profile[j].x, profile[j].z+i*track.get_slope()/nsegs); + va_builder.vertex(v.x, v.y, v.z); + if(profile[j].z==0) + border.push_back(v); } }