]> Dogcows Code - chaz/yoink/blobdiff - src/moof/ray.hh
the massive refactoring effort
[chaz/yoink] / src / moof / ray.hh
diff --git a/src/moof/ray.hh b/src/moof/ray.hh
new file mode 100644 (file)
index 0000000..9413f0d
--- /dev/null
@@ -0,0 +1,84 @@
+
+/*]  Copyright (c) 2009-2010, 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_RAY_HH_
+#define _MOOF_RAY_HH_
+
+/**
+ * \file ray.hh
+ * A class for lines that start at one point and go to infinity in some
+ * direction.
+ */
+
+#include <moof/drawable.hh>
+#include <moof/math.hh>
+#include <moof/opengl.hh>
+#include <moof/texture.hh>
+
+
+namespace moof {
+
+
+/**
+ * A line that goes to infinity.
+ */
+template <int D>
+struct ray : public drawable
+{
+       typedef moof::vector< scalar, fixed<D> > vector;
+
+       // solution = point + t*direction
+       vector  point;
+       vector  direction;
+
+       struct contact
+       {
+               scalar  distance;       // distance from the origin to the nearest point
+               vector  normal;         // surface normal at contact point
+
+               bool operator < (const contact& rhs)
+               {
+                       return distance < rhs.distance;
+               }
+       };
+
+       void solve(vector& p, scalar t) const
+       {
+               p = point + t*direction;
+       }
+
+       void draw(scalar alpha = 0.0) const
+       {
+               vector end = point + 1000.0 * direction;
+               // FIXME: this is kinda cheesy
+
+               moof::texture::reset_binding();
+               glBegin(GL_LINES);
+                       glVertex(point);
+                       glVertex(end);
+               glEnd();
+       }
+
+       void normalize()
+       {
+               direction.normalize();
+       }
+};
+
+
+typedef ray<2> ray2;
+typedef ray<3> ray3;
+
+
+} // namespace moof
+
+#endif // _MOOF_RAY_HH_
+
This page took 0.027565 seconds and 4 git commands to generate.