]> git.tdb.fi Git - r2c2.git/blobdiff - source/libr2c2/profile.cpp
Make use of the mspmath library
[r2c2.git] / source / libr2c2 / profile.cpp
index a9951b2aebc5ab88139edd69c1447b97f7333064..907da8adf791fb12a068dc3a318e13dde108429b 100644 (file)
@@ -17,20 +17,16 @@ void Profile::append_vertex(const Vector &p, bool smooth)
 
        if(!vertices.empty())
        {
-               float dx = p.x-vertices.back().pos.x;
-               float dy = p.y-vertices.back().pos.y;
-               float len = sqrt(dx*dx+dy*dy);
-               v.normal.x = dy/len;
-               v.normal.y = -dx/len;
+               Vector span = p-vertices.back().pos;
+               span.normalize();
+               v.normal.x = span.y;
+               v.normal.y = -span.x;
 
                if(vertices.back().smooth)
                {
                        Vector &n = vertices.back().normal;
-                       n.x += v.normal.x;
-                       n.y += v.normal.y;
-                       len = sqrt(n.x*n.x+n.y*n.y);
-                       n.x /= len;
-                       n.y /= len;
+                       n += v.normal;
+                       n.normalize();
                }
                else
                        vertices.back().normal = v.normal;
@@ -69,12 +65,12 @@ Profile::Loader::Loader(Profile &p):
 
 void Profile::Loader::point(float x, float y)
 {
-       obj.append_vertex(Vector(x/1000, y/1000), false);
+       obj.append_vertex(Vector(x/1000, y/1000, 0), false);
 }
 
 void Profile::Loader::smooth_point(float x, float y)
 {
-       obj.append_vertex(Vector(x/1000, y/1000), true);
+       obj.append_vertex(Vector(x/1000, y/1000, 0), true);
 }
 
 } // namespace R2C2