]> git.tdb.fi Git - r2c2.git/blobdiff - source/3d/tracktype.cpp
Make use of the geometry part of libmspmath
[r2c2.git] / source / 3d / tracktype.cpp
index a5e97cc55a09ad10e89c0a7babbfa119fad1467b..6dfd2a4f86c166cbb9b336b8cdbcaa42e45ba592 100644 (file)
@@ -7,61 +7,6 @@
 using namespace std;
 using namespace Msp;
 
-namespace {
-
-bool compare_z(const R2C2::Vector &p1, const R2C2::Vector &p2)
-{
-       return p1.z<p2.z;
-}
-
-template<typename Iter>
-Iter graham_scan(Iter begin, Iter end)
-{
-       // http://en.wikipedia.org/wiki/Graham_scan
-
-       // Find point with lowest X coordinate
-       R2C2::Vector lowest = *begin;
-       for(Iter i=begin; i!=end; ++i)
-               if(i->x<lowest.x || (i->x==lowest.x && i->y>lowest.y))
-                       lowest = *i;
-
-       // Compute tangents and sort points
-       for(Iter i=begin; i!=end; ++i)
-               i->z = (i->x==lowest.x ? 1e5/(i->y-lowest.y-1) : (i->y-lowest.y)/(i->x-lowest.x));
-       sort(begin, end, compare_z);
-
-       for(Iter k=begin, i=k++, j=k++;; )
-       {
-               // Compute winding by cross product
-               float turn = cross(*j-*i, *k-*j).z;
-
-               if(turn<1e-5)
-               {
-                       // Right turn - throw the middle point away
-                       // Special case for collinear vertices in the beginning
-                       if(i==begin)
-                               j = k++;
-                       else
-                               j = i--;
-               }
-               else
-               {
-                       // Left turn - store the middle point and advance
-                       if(++i!=j)
-                               *i = *j;
-                       j = k++;
-               }
-
-               // Cycle back to beginning and terminate after checking the last point
-               if(k==end)
-                       k = begin;
-               else if(j==begin)
-                       return ++i;
-       }
-}
-
-}
-
 namespace R2C2 {
 
 TrackType3D::TrackType3D(Catalogue3D &cat3d, const TrackType &tt):
@@ -86,20 +31,7 @@ TrackType3D::TrackType3D(Catalogue3D &cat3d, const TrackType &tt):
 
        string obj_name = tt.get_object();
        if(!obj_name.empty())
-       {
                object = &catalogue.get<GL::Object>(obj_name);
-               const GL::Mesh *m = object->get_mesh();
-               const GL::VertexArray &vertices = m->get_vertices();
-               int vertex_offs = vertices.get_format().offset(GL::VERTEX2);
-               if(vertex_offs>=0)
-               {
-                       for(unsigned i=0; i<vertices.size(); ++i)
-                       {
-                               const float *v = vertices[i]+vertex_offs;
-                               border.push_back(Vector(v[0], v[1], 0));
-                       }
-               }
-       }
        else
        {
                mesh = new GL::Mesh((GL::NORMAL3, GL::TEXCOORD2, GL::VERTEX3));
@@ -138,14 +70,6 @@ TrackType3D::TrackType3D(Catalogue3D &cat3d, const TrackType &tt):
                }
                path_meshes.push_back(m);
        }
-
-       min_z = max_z = border.front().z;
-       for(vector<Vector>::iterator i=border.begin(); i!=border.end(); ++i)
-       {
-               min_z = min(min_z, i->z);
-               max_z = max(max_z, i->z);
-       }
-       border.erase(graham_scan(border.begin(), border.end()), border.end());
 }
 
 TrackType3D::~TrackType3D()
@@ -154,25 +78,6 @@ TrackType3D::~TrackType3D()
                delete *i;
 }
 
-void TrackType3D::get_bounds(const Angle &angle, Vector &minp, Vector &maxp) const
-{
-       Transform trans = Transform::rotation(-angle, Vector(0, 0, 1));
-
-       minp = maxp = Vector();
-       minp.z = min_z;
-       maxp.z = max_z;
-
-       for(vector<Vector>::const_iterator i=border.begin(); i!=border.end(); ++i)
-       {
-               Vector v = trans.transform(*i);
-
-               minp.x = min(minp.x, v.x);
-               minp.y = min(minp.y, v.y);
-               maxp.x = max(maxp.x, v.x);
-               maxp.y = max(maxp.y, v.y);
-       }
-}
-
 const GL::Mesh &TrackType3D::get_path_mesh(unsigned p) const
 {
        if(p>=path_meshes.size())
@@ -208,8 +113,6 @@ void TrackType3D::build_part(const TrackPart &part, const Profile &profile, cons
 
                        bld.normal(n.x, n.y, n.z);
                        bld.vertex(p.x, p.y, p.z);
-
-                       border.push_back(p);
                }
        }