]>
Dogcows Code - chaz/yoink/blob - src/Moof/Aabb.hh
f3e92ab471c8b48701a19cf8e61a4427c66a46ab
2 /*] Copyright (c) 2009-2010, Charles McGarvey [**************************
3 **] All rights reserved.
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.
10 **************************************************************************/
12 #ifndef _MOOF_AABB_HH_
13 #define _MOOF_AABB_HH_
15 #include <Moof/Cullable.hh>
16 #include <Moof/Drawable.hh>
17 #include <Moof/Math.hh>
18 #include <Moof/Plane.hh>
19 #include <Moof/Shape.hh>
21 #include <Moof/Frustum.hh> // FIXME this file is quite broken
22 #include <Moof/OpenGL.hh>
23 #include <Moof/Texture.hh>
30 * Axis-aligned Bounding Box
34 struct Aabb
: public Cullable
, public Drawable
, public Shape
<D
>
36 typedef cml::vector
< Scalar
, cml::fixed
<D
> > Vector
;
43 Aabb(const Vector
& a
, const Vector
& b
)
48 Aabb(Scalar ax
, Scalar ay
, Scalar az
,
49 Scalar bx
, Scalar by
, Scalar bz
)
57 void init(const Vector
& a
, const Vector
& b
)
91 Vector
getCenter() const
93 return Vector((min
[0] + max
[0]) / 2.0,
94 (min
[1] + max
[1]) / 2.0,
95 (min
[2] + max
[2]) / 2.0);
98 //void getOctant(Aabb& octant, int num) const;
100 Plane
getPlaneXY() const
103 plane
.normal
= Vector(0.0, 0.0, 1.0);
104 plane
.d
= cml::dot(-plane
.normal
, getCenter());
108 Plane
getPlaneXZ() const
111 plane
.normal
= Vector(0.0, 1.0, 0.0);
112 plane
.d
= cml::dot(-plane
.normal
, getCenter());
116 Plane
getPlaneYZ() const
119 plane
.normal
= Vector(1.0, 0.0, 0.0);
120 plane
.d
= cml::dot(-plane
.normal
, getCenter());
125 void getCorners(Vector3 corners[8]) const;
127 void encloseVertices(const Vector3 vertices[], unsigned count);
129 void draw(Scalar alpha = 0.0) const;
130 bool isVisible(const Frustum& frustum) const;
134 void getCorners(Vector corners
[8]) const
136 corners
[0][0] = min
[0];
137 corners
[0][1] = min
[1];
138 corners
[0][2] = max
[2];
139 corners
[1][0] = max
[0];
140 corners
[1][1] = min
[1];
141 corners
[1][2] = max
[2];
142 corners
[2][0] = max
[0];
143 corners
[2][1] = max
[1];
144 corners
[2][2] = max
[2];
145 corners
[3][0] = min
[0];
146 corners
[3][1] = max
[1];
147 corners
[3][2] = max
[2];
148 corners
[4][0] = min
[0];
149 corners
[4][1] = min
[1];
150 corners
[4][2] = min
[2];
151 corners
[5][0] = max
[0];
152 corners
[5][1] = min
[1];
153 corners
[5][2] = min
[2];
154 corners
[6][0] = max
[0];
155 corners
[6][1] = max
[1];
156 corners
[6][2] = min
[2];
157 corners
[7][0] = min
[0];
158 corners
[7][1] = max
[1];
159 corners
[7][2] = min
[2];
163 void encloseVertices(const Vector vertices
[], unsigned count
)
168 for (unsigned i
= 1; i
< count
; ++i
)
170 min
.minimize(vertices
[i
]);
171 max
.maximize(vertices
[i
]);
176 void draw(Scalar alpha
= 0.0) const
178 Scalar vertices
[] = {min
[0], min
[1], min
[2],
179 min
[0], max
[1], min
[2],
180 max
[0], max
[1], min
[2],
181 max
[0], min
[1], min
[2],
182 min
[0], max
[1], max
[2],
183 min
[0], min
[1], max
[2],
184 max
[0], min
[1], max
[2],
185 max
[0], max
[1], max
[2]};
187 GLubyte indices
[] = {0, 1, 2, 3,
194 glEnableClientState(GL_VERTEX_ARRAY
);
195 glDisableClientState(GL_TEXTURE_COORD_ARRAY
);
196 glVertexPointer(3, GL_SCALAR
, 0, vertices
);
198 glPolygonMode(GL_FRONT_AND_BACK
, GL_LINE
);
199 Texture::resetBind();
201 glDrawElements(GL_QUADS
, sizeof(indices
), GL_UNSIGNED_BYTE
,
204 glEnableClientState(GL_TEXTURE_COORD_ARRAY
);
205 //glDisableClientState(GL_VERTEX_ARRAY);
207 glPolygonMode(GL_FRONT_AND_BACK
, GL_FILL
);
210 bool isVisible(const Frustum
& frustum
) const
212 return frustum
.contains(*this);
219 #endif // _MOOF_AABB_HH_
This page took 0.041313 seconds and 4 git commands to generate.