/*] Copyright (c) 2009-2011, Charles McGarvey [***************************** **] All rights reserved. * * 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_ #include #include #include #include /** * \file ray.hh * A class for lines that start at one point and go to infinity in some * direction. */ namespace moof { /** * A line that goes to infinity. */ template struct ray : public drawable { typedef moof::vector< scalar, fixed > 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 image::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_