void Track3D::render() const
{
- prepare_render();
+ prepare_render(true);
glPushName(reinterpret_cast<unsigned>(this));
void Track3D::render_endpoints() const
{
- prepare_render();
+ prepare_render(false);
const vector<Endpoint> &endpoints = track.get_type().get_endpoints();
for(unsigned i=0; i<endpoints.size(); ++i)
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, 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);
+ 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();
}
void Track3D::render_route(int route) const
{
- prepare_render();
+ prepare_render(true);
varray.apply();
if(route>=0 && static_cast<unsigned>(route)<route_seq.size())
glPopMatrix();
}
-void Track3D::prepare_render() const
+void Track3D::prepare_render(bool slope) const
{
const Point &pos = track.get_position();
float rot = track.get_rotation();
glPushMatrix();
glTranslatef(pos.x, pos.y, pos.z);
glRotatef(rot*180/M_PI, 0, 0, 1);
+ if(slope)
+ glRotatef(track.get_slope()/track.get_type().get_total_length()*180/M_PI, 0, -1, 0);
}
void Track3D::build_object()
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);
+ 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);
va_builder.vertex(v.x, v.y, v.z);
if(profile[j].z==0)
border.push_back(v);