X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=src%2Fmoof%2Fray.hh;fp=src%2Fmoof%2Fray.hh;h=9413f0daba240cbeb88d0d15d4a65dde605365d6;hb=831f04d4bc19a390415ac0bbac4331c7a65509bc;hp=0000000000000000000000000000000000000000;hpb=299af4f2047e767e5d79501c26444473bda64c64;p=chaz%2Fyoink diff --git a/src/moof/ray.hh b/src/moof/ray.hh new file mode 100644 index 0000000..9413f0d --- /dev/null +++ b/src/moof/ray.hh @@ -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 +#include +#include +#include + + +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 + + 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_ +