]> Dogcows Code - chaz/yoink/blob - src/moof/ray.hh
fixed documentation about where to find licenses
[chaz/yoink] / src / moof / ray.hh
1
2 /*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
3 **] All rights reserved.
4 *
5 * Distributable under the terms and conditions of the 2-clause BSD license;
6 * see the file COPYING for a complete text of the license.
7 *
8 *****************************************************************************/
9
10 #ifndef _MOOF_RAY_HH_
11 #define _MOOF_RAY_HH_
12
13 #include <moof/drawable.hh>
14 #include <moof/image.hh>
15 #include <moof/math.hh>
16 #include <moof/opengl.hh>
17
18
19 /**
20 * \file ray.hh
21 * A class for lines that start at one point and go to infinity in some
22 * direction.
23 */
24
25 namespace moof {
26
27
28 /**
29 * A line that goes to infinity.
30 */
31 template <int D>
32 struct ray : public drawable
33 {
34 typedef moof::vector< scalar, fixed<D> > vector;
35
36 // solution = point + t*direction
37 vector point;
38 vector direction;
39
40 struct contact
41 {
42 scalar distance; // distance from the origin to the nearest point
43 vector normal; // surface normal at contact point
44
45 bool operator < (const contact& rhs)
46 {
47 return distance < rhs.distance;
48 }
49 };
50
51 void solve(vector& p, scalar t) const
52 {
53 p = point + t*direction;
54 }
55
56 void draw(scalar alpha = 0.0) const
57 {
58 vector end = point + 1000.0 * direction;
59 // FIXME: this is kinda cheesy
60
61 image::reset_binding();
62 glBegin(GL_LINES);
63 glVertex(point);
64 glVertex(end);
65 glEnd();
66 }
67
68 void normalize()
69 {
70 direction.normalize();
71 }
72 };
73
74 typedef ray<2> ray2;
75 typedef ray<3> ray3;
76
77
78 } // namespace moof
79
80 #endif // _MOOF_RAY_HH_
81
This page took 0.038099 seconds and 5 git commands to generate.