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