]> git.tdb.fi Git - r2c2.git/blobdiff - source/3d/track.cpp
Change terminology to better distinguish routes on the layout from paths across track...
[r2c2.git] / source / 3d / track.cpp
index 85050c97f597a50d0b9b56d185d574bf8735ea62..b2ee4fad8fd34e942f25ceec0549169bad6cdb70 100644 (file)
@@ -64,7 +64,7 @@ void Track3D::get_bounds(float angle, Point &minp, Point &maxp) const
 
 void Track3D::render() const
 {
-       prepare_render();
+       prepare_render(true);
 
        glPushName(reinterpret_cast<unsigned>(this));
 
@@ -83,7 +83,7 @@ void Track3D::render() const
 
 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)
@@ -97,35 +97,58 @@ void Track3D::render_endpoints() const
 
                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();
        }
 
        glPopMatrix();
 }
 
-void Track3D::render_route(int route) const
+void Track3D::render_path(int path) const
 {
-       prepare_render();
+       prepare_render(true);
 
        varray.apply();
-       if(route>=0 && static_cast<unsigned>(route)<route_seq.size())
-               glDrawElements(GL_QUADS, route_seq[route].size(), GL_UNSIGNED_INT, &route_seq[route][0]);
+       if(path>=0 && static_cast<unsigned>(path)<path_seq.size())
+               glDrawElements(GL_QUADS, path_seq[path].size(), GL_UNSIGNED_INT, &path_seq[path][0]);
        else
        {
-               for(unsigned i=0; i<route_seq.size(); ++i)
-                       glDrawElements(GL_QUADS, route_seq[i].size(), GL_UNSIGNED_INT, &route_seq[i][0]);
+               for(unsigned i=0; i<path_seq.size(); ++i)
+                       glDrawElements(GL_QUADS, path_seq[i].size(), GL_UNSIGNED_INT, &path_seq[i][0]);
        }
 
        glPopMatrix();
 }
 
-void Track3D::prepare_render() const
+void Track3D::prepare_render(bool slope) const
 {
        const Point &pos = track.get_position();
        float rot = track.get_rotation();
@@ -133,6 +156,8 @@ void Track3D::prepare_render() const
        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()
@@ -142,8 +167,8 @@ void Track3D::build_object()
 
        base_seq.clear();
        rail_seq.clear();
-       route_seq.clear();
-       route_seq.resize(track.get_type().get_n_routes());
+       path_seq.clear();
+       path_seq.resize(track.get_type().get_n_paths());
 
        const vector<TrackPart> &parts = track.get_type().get_parts();
        unsigned index = 0;
@@ -196,7 +221,7 @@ void Track3D::build_part(const TrackPart &part, GL::VertexArrayBuilder &va_build
                        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);
@@ -219,10 +244,10 @@ void Track3D::build_part(const TrackPart &part, GL::VertexArrayBuilder &va_build
                        rail_seq.push_back(base_index+(i+1)*psize+1+j*2);
                        rail_seq.push_back(base_index+i*psize+1+j*2);
                }
-               route_seq[part.route].push_back(base_index+i*psize+18);
-               route_seq[part.route].push_back(base_index+(i+1)*psize+18);
-               route_seq[part.route].push_back(base_index+(i+1)*psize+19);
-               route_seq[part.route].push_back(base_index+i*psize+19);
+               path_seq[part.path].push_back(base_index+i*psize+18);
+               path_seq[part.path].push_back(base_index+(i+1)*psize+18);
+               path_seq[part.path].push_back(base_index+(i+1)*psize+19);
+               path_seq[part.path].push_back(base_index+i*psize+19);
        }
 
        base_index += (nsegs+1)*psize;