- base_seq.clear();
- rail_seq.clear();
- path_seq.clear();
- path_seq.resize(track.get_type().get_n_paths());
-
- const vector<TrackPart> &parts = track.get_type().get_parts();
- unsigned index = 0;
- for(vector<TrackPart>::const_iterator i=parts.begin(); i!=parts.end(); ++i)
- build_part(*i, builder, index);
-}
-
-void Track3D::build_part(const TrackPart &part, GL::VertexArrayBuilder &va_builder, unsigned &base_index)
-{
- static vector<Point> profile;
- if(profile.empty())
- {
- profile.push_back(Point(0, -0.02, 0));
- profile.push_back(Point(0, -0.014, 0.008));
- profile.push_back(Point(0, -0.014, 0.008));
- profile.push_back(Point(0, 0.014, 0.008));
- profile.push_back(Point(0, 0.014, 0.008));
- profile.push_back(Point(0, 0.02, 0));
- for(unsigned i=0; i<2; ++i)
- {
- profile.push_back(Point(0, -0.009+i*0.017, 0.008));
- profile.push_back(Point(0, -0.009+i*0.017, 0.0103));
- profile.push_back(Point(0, -0.009+i*0.017, 0.0103));
- profile.push_back(Point(0, -0.008+i*0.017, 0.0103));
- profile.push_back(Point(0, -0.008+i*0.017, 0.0103));
- profile.push_back(Point(0, -0.008+i*0.017, 0.008));
- }
- profile.push_back(Point(0, -0.002, 0.012));
- profile.push_back(Point(0, 0.002, 0.012));
- }
- static unsigned psize = profile.size();
-
- unsigned nsegs = (part.radius ? static_cast<unsigned>(part.length*(1<<quality))+1 : 1);
- float plen = part.length;
- if(part.radius)
- plen *= abs(part.radius);
-
- for(unsigned i=0; i<=nsegs; ++i)
- {
- float a = part.dir+(part.radius ? i*plen/nsegs/part.radius : 0);
- float c = cos(a);
- float s = sin(a);
- Point p = part.get_point(i*plen/nsegs);
-
- for(unsigned j=0; j<psize; ++j)
- {
- 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);
- va_builder.vertex(v.x, v.y, v.z);
- if(profile[j].z==0)
- border.push_back(v);
- }
- }