]> Dogcows Code - chaz/yoink/blob - src/Moof/Ray.hh
removed logging from script to fix compile error
[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 #include <Moof/Drawable.hh>
16 #include <Moof/Math.hh>
17 #include <Moof/OpenGL.hh>
18 #include <Moof/Texture.hh>
19
20
21 namespace Mf {
22
23
24 /**
25 * A line that goes to infinity.
26 */
27
28 template <int D>
29 struct Ray : public Drawable
30 {
31 typedef cml::vector< Scalar, cml::fixed<D> > Vector;
32
33 // solution = point + t*direction
34 Vector point;
35 Vector direction;
36
37 struct Contact
38 {
39 Scalar distance; // distance from the origin to the nearest point
40 Vector normal; // surface normal at contact point
41
42 bool operator < (const Contact& rhs)
43 {
44 return distance < rhs.distance;
45 }
46 };
47
48 void solve(Vector& p, Scalar t) const
49 {
50 p = point + t*direction;
51 }
52
53 void draw(Scalar alpha = 0.0) const
54 {
55 Vector end = point + 1000.0 * direction;
56 // FIXME this is kinda cheesy
57
58 Mf::Texture::resetBind();
59 glBegin(GL_LINES);
60 glVertex(point);
61 glVertex(end);
62 glEnd();
63 }
64
65 void normalize()
66 {
67 direction.normalize();
68 }
69 };
70
71
72 typedef Ray<2> Ray2;
73 typedef Ray<3> Ray3;
74
75
76 } // namespace Mf
77
78 #endif // _MOOF_RAY_HH_
79
This page took 0.031307 seconds and 4 git commands to generate.