namespace Marklin {
TrackType3D::TrackType3D(const Catalogue3D &cat3d, const TrackType &tt):
+ catalogue(cat3d),
ballast_mesh((GL::NORMAL3, GL::COLOR4_UBYTE, GL::VERTEX3)),
rail_mesh((GL::NORMAL3, GL::COLOR4_UBYTE, GL::VERTEX3))
{
}
}
-void TrackType3D::render() const
+void TrackType3D::render(const GL::Tag &tag) const
{
- ballast_mesh.draw();
- rail_mesh.draw();
+ if(tag==0)
+ {
+ catalogue.get_ballast_material().bind();
+ ballast_mesh.draw();
+ catalogue.get_rail_material().bind();
+ rail_mesh.draw();
+ }
}
void TrackType3D::build_part(const TrackPart &part, const Profile &profile, const Point &offset, GL::MeshBuilder &bld, unsigned &base_index)
{
- unsigned nsegs = (part.radius ? static_cast<unsigned>(part.length*16)+1 : 1);
- float plen = part.length;
- if(part.radius)
- plen *= abs(part.radius);
+ float plen = part.get_length();
+ unsigned nsegs = (part.is_curved() ? static_cast<unsigned>(plen*16)+1 : 1);
unsigned n_points = profile.get_n_points();
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 basep = part.get_point(i*plen/nsegs);
+ TrackPoint basep = part.get_point(i*plen/nsegs);
+ float c = cos(basep.dir);
+ float s = sin(basep.dir);
Point p;
for(unsigned j=0; j<n_points; ++j)
// TODO: smoothing - only duplicate vertex if the angle is large enough
p = profile.get_point(j);
- p.z = basep.z+p.y+offset.y;
- p.y = basep.y-c*(p.x+offset.x);
- p.x = basep.x+s*(p.x+offset.x);
+ p.z = basep.pos.z+p.y+offset.y;
+ p.y = basep.pos.y-c*(p.x+offset.x);
+ p.x = basep.pos.x+s*(p.x+offset.x);
if(j>0)
bld.vertex(p.x, p.y, p.z);