--- /dev/null
+
+/*] 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_
+