]> Dogcows Code - chaz/yoink/blobdiff - src/moof/line.hh
fixed documentation about where to find licenses
[chaz/yoink] / src / moof / line.hh
index 35ebf29199afbfa78ef6329fd611f334428892c0..60a0b34eb89402ed23f1c1c2d9e3a63a41887fe7 100644 (file)
@@ -1,33 +1,31 @@
 
-/*]  Copyright (c) 2009-2010, Charles McGarvey  [**************************
+/*]  Copyright (c) 2009-2011, Charles McGarvey  [*****************************
 **]  All rights reserved.
 *
-* vi:ts=4 sw=4 tw=75
-*
 * Distributable under the terms and conditions of the 2-clause BSD license;
 * see the file COPYING for a complete text of the license.
 *
-**************************************************************************/
+*****************************************************************************/
 
 #ifndef _MOOF_LINE_HH_
 #define _MOOF_LINE_HH_
 
-/**
- * \file line.hh
- * Classes related to line segments.
- */
-
 #include <moof/contact.hh>
 #include <moof/drawable.hh>
+#include <moof/image.hh>
 #include <moof/log.hh>
 #include <moof/math.hh>
 #include <moof/opengl.hh>
 #include <moof/ray.hh>
 #include <moof/shape.hh>
 #include <moof/sphere.hh>
-#include <moof/texture.hh>
 
 
+/**
+ * \file line.hh
+ * Classes related to line segments.
+ */
+
 namespace moof {
 
 
@@ -36,18 +34,15 @@ struct line : public drawable, public shape<D>
 {
        typedef moof::vector< scalar, fixed<D> > vector;
 
-
        vector  a;
        vector  b;
 
-
        line() {}
 
        line(const vector& point1, const vector& point2) :
                a(point1),
                b(point2) {}
 
-
        vector direction() const
        {
                return b - a;
@@ -58,31 +53,31 @@ struct line : public drawable, public shape<D>
                return direction().length();
        }
 
-
        bool intersect(const line& other, contact<D>& hit) const
        {
                scalar d = (other.b[1] - other.a[1]) * (b[0] - a[0]) -
-                                  (other.b[0] - other.a[0]) * (b[1] - a[1]);
+                       (other.b[0] - other.a[0]) * (b[1] - a[1]);
 
-               if (d == SCALAR(0.0)) return false;                     // lines are parallel
+               if (d == SCALAR(0.0)) return false;     // lines are parallel
                // ignoring the (somewhat remote) possibility of coincidence
 
-               scalar m = ((other.b[0] - other.a[0]) * (a[1] - other.a[1]) -
-                                       (other.b[1] - other.a[1]) * (a[0] - other.a[0])) / d;
+               scalar m = ((other.b[0] - other.a[0]) *
+                               (a[1] - other.a[1]) -
+                               (other.b[1] - other.a[1]) *
+                               (a[0] - other.a[0])) / d;
 
                scalar n = ((b[0] - a[0]) * (b[1] - other.a[1]) -
-                                       (b[1] - a[1]) * (b[0] - other.a[0])) / d;
+                               (b[1] - a[1]) * (b[0] - other.a[0])) / d;
 
                if (m < SCALAR(0.0) || m > SCALAR(1.0) ||       // not intersecting
-                       n < SCALAR(0.0) || n > SCALAR(1.0)) return false;
+                       n < SCALAR(0.0) || n > SCALAR(1.0))
+                       return false;
 
                vector2 tangent = b - a;
                vector2 normal = perp(tangent).normalize();
 
                if (dot(normal, other.a - other.b) < SCALAR(0.0))
-               {
                        normal = -normal;
-               }
 
                hit.point = a + m * tangent;
                hit.normal = normal;
@@ -104,7 +99,6 @@ struct line : public drawable, public shape<D>
                if (projection < SCALAR(0.0) || projection > surfaceLength)
                {
                        // try endpoints
-                       
                        if (other.intersect(a, hit))
                        {
                                hit.normal = -hit.normal;
@@ -117,7 +111,6 @@ struct line : public drawable, public shape<D>
                                hit.point = b;
                                return true;
                        }
-                       
                        return false;
                }
 
@@ -126,7 +119,7 @@ struct line : public drawable, public shape<D>
 
                scalar distance = normal.length();
 
-               if (distance > other.radius) false;             // not intersecting
+               if (distance > other.radius) false;     // not intersecting
 
                normal.normalize();
 
@@ -137,8 +130,8 @@ struct line : public drawable, public shape<D>
                return true;
        }
 
-
-       bool intersect_ray(const ray<2>& ray, moof::ray<2>::contact& hit) const
+       bool
+       intersect_ray(const ray<2>& ray, moof::ray<2>::contact& hit) const
        {
                vector2 v1 = a - ray.point;
                scalar  a1 = signed_angle_2D(v1, b - ray.point);
@@ -170,7 +163,6 @@ struct line : public drawable, public shape<D>
                hit.normal = perp(a - b);
                return true;
 
-
                /*
                // solve: Cx + r*Dx = Ax + s(Bx - Ax)
                //        Cy + r*Dy = Ay + s(By - Ay)
@@ -222,10 +214,9 @@ struct line : public drawable, public shape<D>
                */
        }
 
-
        void draw(scalar alpha = 0.0) const
        {
-               texture::reset_binding();
+               image::reset_binding();
                glBegin(GL_LINES);
                        glVertex(a);
                        glVertex(b);
@@ -233,7 +224,6 @@ struct line : public drawable, public shape<D>
        }
 };
 
-
 typedef line<2>                line2;
 typedef line<3>                line3;
 
@@ -248,31 +238,26 @@ struct polygon : public drawable, public shape<D>
        polygon() {}
 
        bool intersect_ray(const ray<D>& ray,
-                                          typename moof::ray<D>::contact& hit)
+                       typename moof::ray<D>::contact& hit)
        {
                return false;
        }
 
        void draw(scalar alpha = 0.0) const
        {
-               texture::reset_binding();
+               image::reset_binding();
                glBegin(GL_POLYGON);
-               for (int i = 0; i < D; ++i)
-               {
-                       glVertex(points[0]);
-               }
+                       for (int i = 0; i < D; ++i) glVertex(points[0]);
                glEnd();
        }
 };
 
-
 typedef polygon<2,3>   triangle2;
 typedef polygon<3,3>   triangle3;
 
 
 template <int D>
-bool intersect(const line<D>& line, const sphere<D>& sphere,
-                          contact<D>& hit)
+bool intersect(const line<D>& line, const sphere<D>& sphere, contact<D>& hit)
 {
        return false;
 }
This page took 0.024494 seconds and 4 git commands to generate.