1 | #include "OgreOdePrecompiledHeaders.h" |
---|
2 | #include "OgreOdeDebugObject.h" |
---|
3 | |
---|
4 | #include <OgreMaterialManager.h> |
---|
5 | #include <OgreTechnique.h> |
---|
6 | #include <OgreCamera.h> |
---|
7 | #include <OgreHardwareBufferManager.h> |
---|
8 | |
---|
9 | using namespace OgreOde; |
---|
10 | using namespace Ogre; |
---|
11 | |
---|
12 | //------------------------------------------------------------------------------------------------ |
---|
13 | bool DebugLines::_materials_created = false; |
---|
14 | //------------------------------------------------------------------------------------------------ |
---|
15 | DebugLines::DebugLines() : SimpleRenderable() |
---|
16 | { |
---|
17 | mRenderOp.vertexData = new Ogre::VertexData(); |
---|
18 | _drawn = false; |
---|
19 | |
---|
20 | if (!_materials_created) |
---|
21 | { |
---|
22 | MaterialPtr red = MaterialManager::getSingleton().create("OgreOdeDebugLines/Disabled","OgreOde"); |
---|
23 | MaterialPtr green = MaterialManager::getSingleton().create("OgreOdeDebugLines/Enabled","OgreOde"); |
---|
24 | MaterialPtr blue = MaterialManager::getSingleton().create("OgreOdeDebugLines/Static","OgreOde"); |
---|
25 | |
---|
26 | red->setReceiveShadows(false); |
---|
27 | red->getTechnique(0)->setLightingEnabled(true); |
---|
28 | red->getTechnique(0)->getPass(0)->setSelfIllumination(1,0,0); |
---|
29 | |
---|
30 | green->setReceiveShadows(false); |
---|
31 | green->getTechnique(0)->setLightingEnabled(true); |
---|
32 | green->getTechnique(0)->getPass(0)->setSelfIllumination(0,1,0); |
---|
33 | |
---|
34 | blue->setReceiveShadows(false); |
---|
35 | blue->getTechnique(0)->setLightingEnabled(true); |
---|
36 | blue->getTechnique(0)->getPass(0)->setSelfIllumination(0,0,1); |
---|
37 | |
---|
38 | _materials_created = true; |
---|
39 | } |
---|
40 | setCastShadows (false); |
---|
41 | this->setMaterial("OgreOdeDebugLines/Enabled"); |
---|
42 | } |
---|
43 | |
---|
44 | |
---|
45 | //------------------------------------------------------------------------------------------------ |
---|
46 | void DebugLines::clear() |
---|
47 | { |
---|
48 | if (_drawn) |
---|
49 | { |
---|
50 | _drawn = false; |
---|
51 | _points.clear(); |
---|
52 | delete mRenderOp.vertexData; |
---|
53 | |
---|
54 | mRenderOp.vertexData = new Ogre::VertexData(); |
---|
55 | } |
---|
56 | } |
---|
57 | //------------------------------------------------------------------------------------------------ |
---|
58 | DebugLines::~DebugLines(void) |
---|
59 | { |
---|
60 | clear(); |
---|
61 | |
---|
62 | delete mRenderOp.vertexData; |
---|
63 | } |
---|
64 | //------------------------------------------------------------------------------------------------ |
---|
65 | void DebugLines::draw() |
---|
66 | { |
---|
67 | if (_drawn) |
---|
68 | return; |
---|
69 | else |
---|
70 | _drawn = true; |
---|
71 | |
---|
72 | // Initialization stuff |
---|
73 | mRenderOp.indexData = 0; |
---|
74 | mRenderOp.vertexData->vertexCount = _points.size(); |
---|
75 | mRenderOp.vertexData->vertexStart = 0; |
---|
76 | mRenderOp.operationType = RenderOperation::OT_LINE_LIST; |
---|
77 | mRenderOp.useIndexes = false; |
---|
78 | |
---|
79 | Ogre::VertexDeclaration *decl = mRenderOp.vertexData->vertexDeclaration; |
---|
80 | Ogre::VertexBufferBinding *bind = mRenderOp.vertexData->vertexBufferBinding; |
---|
81 | |
---|
82 | decl->addElement(0, 0, VET_FLOAT3, VES_POSITION); |
---|
83 | |
---|
84 | HardwareVertexBufferSharedPtr vbuf = |
---|
85 | HardwareBufferManager::getSingleton().createVertexBuffer( |
---|
86 | decl->getVertexSize(0), |
---|
87 | mRenderOp.vertexData->vertexCount, |
---|
88 | HardwareBuffer::HBU_STATIC_WRITE_ONLY); |
---|
89 | |
---|
90 | bind->setBinding(0, vbuf); |
---|
91 | |
---|
92 | // Drawing stuff |
---|
93 | unsigned int size = (unsigned int)_points.size(); |
---|
94 | Ogre::Vector3 vaabMin = _points[0]; |
---|
95 | Ogre::Vector3 vaabMax = _points[0]; |
---|
96 | |
---|
97 | float *prPos = static_cast<float*>(vbuf->lock(HardwareBuffer::HBL_DISCARD)); |
---|
98 | |
---|
99 | for(unsigned int i = 0; i < size; i++) |
---|
100 | { |
---|
101 | *prPos++ = _points[i].x; |
---|
102 | *prPos++ = _points[i].y; |
---|
103 | *prPos++ = _points[i].z; |
---|
104 | |
---|
105 | if (_points[i].x < vaabMin.x) |
---|
106 | vaabMin.x = _points[i].x; |
---|
107 | if (_points[i].y < vaabMin.y) |
---|
108 | vaabMin.y = _points[i].y; |
---|
109 | if (_points[i].z < vaabMin.z) |
---|
110 | vaabMin.z = _points[i].z; |
---|
111 | |
---|
112 | if (_points[i].x > vaabMax.x) |
---|
113 | vaabMax.x = _points[i].x; |
---|
114 | if (_points[i].y > vaabMax.y) |
---|
115 | vaabMax.y = _points[i].y; |
---|
116 | if (_points[i].z > vaabMax.z) |
---|
117 | vaabMax.z = _points[i].z; |
---|
118 | } |
---|
119 | |
---|
120 | vbuf->unlock(); |
---|
121 | |
---|
122 | mBox.setExtents(vaabMin, vaabMax); |
---|
123 | } |
---|
124 | //------------------------------------------------------------------------------------------------ |
---|
125 | Real DebugLines::getSquaredViewDepth(const Camera *cam) const |
---|
126 | { |
---|
127 | Vector3 vMin, vMax, vMid, vDist; |
---|
128 | vMin = mBox.getMinimum(); |
---|
129 | vMax = mBox.getMaximum(); |
---|
130 | vMid = ((vMin - vMax) * 0.5) + vMin; |
---|
131 | vDist = cam->getDerivedPosition() - vMid; |
---|
132 | |
---|
133 | return vDist.squaredLength(); |
---|
134 | } |
---|
135 | //------------------------------------------------------------------------------------------------ |
---|
136 | Real DebugLines::getBoundingRadius() const |
---|
137 | { |
---|
138 | return Math::Sqrt(std::max(mBox.getMaximum().squaredLength(), mBox.getMinimum().squaredLength())); |
---|
139 | } |
---|
140 | //------------------------------------------------------------------------------------------------ |
---|
141 | DebugObject::DebugObject(DebugObject::Mode mode) |
---|
142 | { |
---|
143 | _mode = DebugObject::Mode_Unknown; |
---|
144 | setMode(mode); |
---|
145 | } |
---|
146 | //------------------------------------------------------------------------------------------------ |
---|
147 | void DebugObject::setMode(DebugObject::Mode mode) |
---|
148 | { |
---|
149 | if (mode != _mode) |
---|
150 | { |
---|
151 | _mode = mode; |
---|
152 | switch(_mode) |
---|
153 | { |
---|
154 | case DebugObject::Mode_Enabled: |
---|
155 | setMaterial("OgreOdeDebugLines/Enabled"); |
---|
156 | break; |
---|
157 | |
---|
158 | case DebugObject::Mode_Disabled: |
---|
159 | setMaterial("OgreOdeDebugLines/Disabled"); |
---|
160 | |
---|
161 | break; |
---|
162 | |
---|
163 | case DebugObject::Mode_Static: |
---|
164 | setMaterial("OgreOdeDebugLines/Static"); |
---|
165 | break; |
---|
166 | |
---|
167 | case DebugObject::Mode_Unknown: |
---|
168 | // don't do anything. Not handled. |
---|
169 | break; |
---|
170 | } |
---|
171 | } |
---|
172 | } |
---|
173 | //------------------------------------------------------------------------------------------------ |
---|
174 | DebugObject::~DebugObject() |
---|
175 | { |
---|
176 | } |
---|
177 | //------------------------------------------------------------------------------------------------ |
---|
178 | BoxDebugObject::BoxDebugObject(const Ogre::Vector3& size):DebugObject() |
---|
179 | { |
---|
180 | AxisAlignedBox aabb(-size.x * 0.5,-size.y * 0.5,-size.z * 0.5, |
---|
181 | size.x * 0.5,size.y * 0.5,size.z * 0.5); |
---|
182 | |
---|
183 | Vector3 vmax = aabb.getMaximum(); |
---|
184 | Vector3 vmin = aabb.getMinimum(); |
---|
185 | |
---|
186 | addLine(vmin.x,vmin.y,vmin.z,vmax.x,vmin.y,vmin.z); |
---|
187 | addLine(vmin.x,vmin.y,vmin.z,vmin.x,vmin.y,vmax.z); |
---|
188 | addLine(vmin.x,vmin.y,vmin.z,vmin.x,vmax.y,vmin.z); |
---|
189 | addLine(vmin.x,vmax.y,vmin.z,vmin.x,vmax.y,vmax.z); |
---|
190 | addLine(vmin.x,vmax.y,vmin.z,vmax.x,vmax.y,vmin.z); |
---|
191 | addLine(vmax.x,vmin.y,vmin.z,vmax.x,vmin.y,vmax.z); |
---|
192 | addLine(vmax.x,vmin.y,vmin.z,vmax.x,vmax.y,vmin.z); |
---|
193 | addLine(vmin.x,vmax.y,vmax.z,vmax.x,vmax.y,vmax.z); |
---|
194 | addLine(vmin.x,vmax.y,vmax.z,vmin.x,vmin.y,vmax.z); |
---|
195 | addLine(vmax.x,vmax.y,vmin.z,vmax.x,vmax.y,vmax.z); |
---|
196 | addLine(vmax.x,vmin.y,vmax.z,vmax.x,vmax.y,vmax.z); |
---|
197 | addLine(vmin.x,vmin.y,vmax.z,vmax.x,vmin.y,vmax.z); |
---|
198 | |
---|
199 | draw(); |
---|
200 | } |
---|
201 | //------------------------------------------------------------------------------------------------ |
---|
202 | BoxDebugObject::~BoxDebugObject() |
---|
203 | { |
---|
204 | } |
---|
205 | //------------------------------------------------------------------------------------------------ |
---|
206 | SphereDebugObject::SphereDebugObject(Real radius):DebugObject() |
---|
207 | { |
---|
208 | // X/Y axis |
---|
209 | |
---|
210 | // NW quadrant |
---|
211 | addLine(-radius, 0.0, 0.0, |
---|
212 | -0.866 * radius, 0.5 * radius, 0.0); |
---|
213 | |
---|
214 | addLine(-0.866 * radius, 0.5 * radius, 0.0, |
---|
215 | -0.5 * radius, 0.866 * radius, 0.0); |
---|
216 | |
---|
217 | addLine(-0.5 * radius, 0.866 * radius, 0.0, |
---|
218 | 0.0, radius, 0.0); |
---|
219 | |
---|
220 | // NE quadrant |
---|
221 | addLine(0.0, radius, 0.0, |
---|
222 | 0.5 * radius, 0.866 * radius, 0.0); |
---|
223 | |
---|
224 | addLine(0.5 * radius, 0.866 * radius, 0.0, |
---|
225 | 0.866 * radius, 0.5 * radius, 0.0); |
---|
226 | |
---|
227 | addLine(0.866 * radius, 0.5 * radius, 0.0, |
---|
228 | radius, 0.0, 0.0); |
---|
229 | |
---|
230 | // SW quadrant |
---|
231 | addLine(-radius, 0.0, 0.0, |
---|
232 | -0.866 * radius, -0.5 * radius, 0.0); |
---|
233 | |
---|
234 | addLine(-0.866 * radius, -0.5 * radius, 0.0, |
---|
235 | -0.5 * radius, -0.866 * radius, 0.0); |
---|
236 | |
---|
237 | addLine(-0.5 * radius, -0.866 * radius, 0.0, |
---|
238 | 0.0, -radius, 0.0); |
---|
239 | |
---|
240 | // SE quadrant |
---|
241 | addLine(0.0, -radius, 0.0, |
---|
242 | 0.5 * radius, -0.866 * radius, 0.0); |
---|
243 | |
---|
244 | addLine(0.5 * radius, -0.866 * radius, 0.0, |
---|
245 | 0.866 * radius, -0.5 * radius, 0.0); |
---|
246 | |
---|
247 | addLine(0.866 * radius, -0.5 * radius, 0.0, |
---|
248 | radius, 0.0, 0.0); |
---|
249 | |
---|
250 | // X/Z axis |
---|
251 | |
---|
252 | // NW quadrant |
---|
253 | addLine(-radius, 0.0, 0.0, |
---|
254 | -0.866 * radius, 0.0, 0.5 * radius); |
---|
255 | |
---|
256 | addLine(-0.866 * radius, 0.0, 0.5 * radius, |
---|
257 | -0.5 * radius, 0.0, 0.866 * radius); |
---|
258 | |
---|
259 | addLine(-0.5 * radius, 0.0, 0.866 * radius, |
---|
260 | 0.0, 0.0, radius); |
---|
261 | |
---|
262 | // NE quadrant |
---|
263 | addLine(0.0, 0.0, radius, |
---|
264 | 0.5 * radius, 0.0, 0.866 * radius); |
---|
265 | |
---|
266 | addLine(0.5 * radius, 0.0, 0.866 * radius, |
---|
267 | 0.866 * radius, 0.0, 0.5 * radius); |
---|
268 | |
---|
269 | addLine(0.866 * radius, 0.0, 0.5 * radius, |
---|
270 | radius, 0.0, 0.0); |
---|
271 | |
---|
272 | // SW quadrant |
---|
273 | addLine(-radius, 0.0, 0.0, |
---|
274 | -0.866 * radius, 0.0, -0.5 * radius); |
---|
275 | |
---|
276 | addLine(-0.866 * radius, 0.0, -0.5 * radius, |
---|
277 | -0.5 * radius, 0.0, -0.866 * radius); |
---|
278 | |
---|
279 | addLine(-0.5 * radius, 0.0, -0.866 * radius, |
---|
280 | 0.0, 0.0, -radius); |
---|
281 | |
---|
282 | // SE quadrant |
---|
283 | addLine(0.0, 0.0, -radius, |
---|
284 | 0.5 * radius, 0.0, -0.866 * radius); |
---|
285 | |
---|
286 | addLine(0.5 * radius, 0.0, -0.866 * radius, |
---|
287 | 0.866 * radius, 0.0, -0.5 * radius); |
---|
288 | |
---|
289 | addLine(0.866 * radius, 0.0, -0.5 * radius, |
---|
290 | radius, 0.0, 0.0); |
---|
291 | |
---|
292 | // Y/Z axis |
---|
293 | |
---|
294 | // NW quadrant |
---|
295 | addLine(0.0, -radius, 0.0, |
---|
296 | 0.0, -0.866 * radius, 0.5 * radius); |
---|
297 | |
---|
298 | addLine(0.0, -0.866 * radius, 0.5 * radius, |
---|
299 | 0.0, -0.5 * radius, 0.866 * radius); |
---|
300 | |
---|
301 | addLine(0.0, -0.5 * radius, 0.866 * radius, |
---|
302 | 0.0, 0.0, radius); |
---|
303 | |
---|
304 | // NE quadrant |
---|
305 | addLine(0.0, 0.0, radius, |
---|
306 | 0.0, 0.5 * radius, 0.866 * radius); |
---|
307 | |
---|
308 | addLine(0.0, 0.5 * radius, 0.866 * radius, |
---|
309 | 0.0, 0.866 * radius, 0.5 * radius); |
---|
310 | |
---|
311 | addLine(0.0, 0.866 * radius, 0.5 * radius, |
---|
312 | 0.0, radius, 0.0); |
---|
313 | |
---|
314 | // SW quadrant |
---|
315 | addLine(0.0, -radius, 0.0, |
---|
316 | 0.0, -0.866 * radius, -0.5 * radius); |
---|
317 | |
---|
318 | addLine(0.0, -0.866 * radius, -0.5 * radius, |
---|
319 | 0.0, -0.5 * radius, -0.866 * radius); |
---|
320 | |
---|
321 | addLine(0.0, -0.5 * radius, -0.866 * radius, |
---|
322 | 0.0, 0.0, -radius); |
---|
323 | |
---|
324 | // SE quadrant |
---|
325 | addLine(0.0, 0.0, -radius, |
---|
326 | 0.0, 0.5 * radius, -0.866 * radius); |
---|
327 | |
---|
328 | addLine(0.0, 0.5 * radius, -0.866 * radius, |
---|
329 | 0.0, 0.866 * radius, -0.5 * radius); |
---|
330 | |
---|
331 | addLine(0.0, 0.866 * radius, -0.5 * radius, |
---|
332 | 0.0, radius, 0.0); |
---|
333 | |
---|
334 | draw(); |
---|
335 | } |
---|
336 | //------------------------------------------------------------------------------------------------ |
---|
337 | SphereDebugObject::~SphereDebugObject() |
---|
338 | { |
---|
339 | } |
---|
340 | //------------------------------------------------------------------------------------------------ |
---|
341 | CapsuleDebugObject::CapsuleDebugObject(Real radius,Real length):DebugObject() |
---|
342 | { |
---|
343 | Real halflen = length * 0.5; |
---|
344 | AxisAlignedBox aabb(-radius,-radius,-(halflen + radius),radius,radius,halflen + radius); |
---|
345 | |
---|
346 | // X/Y axis - Near |
---|
347 | |
---|
348 | // NW quadrant |
---|
349 | addLine(-radius, 0.0, halflen, |
---|
350 | -0.866 * radius, 0.5 * radius, halflen); |
---|
351 | |
---|
352 | addLine(-0.866 * radius, 0.5 * radius, halflen, |
---|
353 | -0.5 * radius, 0.866 * radius, halflen); |
---|
354 | |
---|
355 | addLine(-0.5 * radius, 0.866 * radius, halflen, |
---|
356 | 0.0, radius, halflen); |
---|
357 | |
---|
358 | // NE quadrant |
---|
359 | addLine(0.0, radius, halflen, |
---|
360 | 0.5 * radius, 0.866 * radius, halflen); |
---|
361 | |
---|
362 | addLine(0.5 * radius, 0.866 * radius, halflen, |
---|
363 | 0.866 * radius, 0.5 * radius, halflen); |
---|
364 | |
---|
365 | addLine(0.866 * radius, 0.5 * radius, halflen, |
---|
366 | radius, 0.0, halflen); |
---|
367 | |
---|
368 | // SW quadrant |
---|
369 | addLine(-radius, 0.0, halflen, |
---|
370 | -0.866 * radius, -0.5 * radius, halflen); |
---|
371 | |
---|
372 | addLine(-0.866 * radius, -0.5 * radius, halflen, |
---|
373 | -0.5 * radius, -0.866 * radius, halflen); |
---|
374 | |
---|
375 | addLine(-0.5 * radius, -0.866 * radius, halflen, |
---|
376 | 0.0, -radius, halflen); |
---|
377 | |
---|
378 | // SE quadrant |
---|
379 | addLine(0.0, -radius, halflen, |
---|
380 | 0.5 * radius, -0.866 * radius, halflen); |
---|
381 | |
---|
382 | addLine(0.5 * radius, -0.866 * radius, halflen, |
---|
383 | 0.866 * radius, -0.5 * radius, halflen); |
---|
384 | |
---|
385 | addLine(0.866 * radius, -0.5 * radius, halflen, |
---|
386 | radius, 0.0, halflen); |
---|
387 | |
---|
388 | // X/Y axis - Far |
---|
389 | |
---|
390 | // NW quadrant |
---|
391 | addLine(-radius, 0.0, -halflen, |
---|
392 | -0.866 * radius, 0.5 * radius, -halflen); |
---|
393 | |
---|
394 | addLine(-0.866 * radius, 0.5 * radius, -halflen, |
---|
395 | -0.5 * radius, 0.866 * radius, -halflen); |
---|
396 | |
---|
397 | addLine(-0.5 * radius, 0.866 * radius, -halflen, |
---|
398 | 0.0, radius, -halflen); |
---|
399 | |
---|
400 | // NE quadrant |
---|
401 | addLine(0.0, radius, -halflen, |
---|
402 | 0.5 * radius, 0.866 * radius, -halflen); |
---|
403 | |
---|
404 | addLine(0.5 * radius, 0.866 * radius, -halflen, |
---|
405 | 0.866 * radius, 0.5 * radius, -halflen); |
---|
406 | |
---|
407 | addLine(0.866 * radius, 0.5 * radius, -halflen, |
---|
408 | radius, 0.0, -halflen); |
---|
409 | |
---|
410 | // SW quadrant |
---|
411 | addLine(-radius, 0.0, -halflen, |
---|
412 | -0.866 * radius, -0.5 * radius, -halflen); |
---|
413 | |
---|
414 | addLine(-0.866 * radius, -0.5 * radius, -halflen, |
---|
415 | -0.5 * radius, -0.866 * radius, -halflen); |
---|
416 | |
---|
417 | addLine(-0.5 * radius, -0.866 * radius, -halflen, |
---|
418 | 0.0, -radius, -halflen); |
---|
419 | |
---|
420 | // SE quadrant |
---|
421 | addLine(0.0, -radius, -halflen, |
---|
422 | 0.5 * radius, -0.866 * radius, -halflen); |
---|
423 | |
---|
424 | addLine(0.5 * radius, -0.866 * radius, -halflen, |
---|
425 | 0.866 * radius, -0.5 * radius, -halflen); |
---|
426 | |
---|
427 | addLine(0.866 * radius, -0.5 * radius, -halflen, |
---|
428 | radius, 0.0, -halflen); |
---|
429 | |
---|
430 | // X/Z axis |
---|
431 | |
---|
432 | // NW quadrant |
---|
433 | addLine(-radius, 0.0, halflen, |
---|
434 | -0.866 * radius, 0.0, (0.5 * radius) + halflen); |
---|
435 | |
---|
436 | addLine(-0.866 * radius, 0.0, (0.5 * radius) + halflen, |
---|
437 | -0.5 * radius, 0.0, (0.866 * radius) + halflen); |
---|
438 | |
---|
439 | addLine(-0.5 * radius, 0.0, (0.866 * radius) + halflen, |
---|
440 | 0.0, 0.0, radius + halflen); |
---|
441 | |
---|
442 | // NE quadrant |
---|
443 | addLine(0.0, 0.0, radius + halflen, |
---|
444 | 0.5 * radius, 0.0, (0.866 * radius) + halflen); |
---|
445 | |
---|
446 | addLine(0.5 * radius, 0.0, (0.866 * radius) + halflen, |
---|
447 | 0.866 * radius, 0.0, (0.5 * radius) + halflen); |
---|
448 | |
---|
449 | addLine(0.866 * radius, 0.0, (0.5 * radius) + halflen, |
---|
450 | radius, 0.0, halflen); |
---|
451 | |
---|
452 | // SW quadrant |
---|
453 | addLine(-radius, 0.0, -halflen, |
---|
454 | -0.866 * radius, 0.0, (-0.5 * radius) - halflen); |
---|
455 | |
---|
456 | addLine(-0.866 * radius, 0.0, (-0.5 * radius) - halflen, |
---|
457 | -0.5 * radius, 0.0, (-0.866 * radius) - halflen); |
---|
458 | |
---|
459 | addLine(-0.5 * radius, 0.0, (-0.866 * radius) - halflen, |
---|
460 | 0.0, 0.0, -radius - halflen); |
---|
461 | |
---|
462 | // SE quadrant |
---|
463 | addLine(0.0, 0.0, -radius - halflen, |
---|
464 | 0.5 * radius, 0.0, (-0.866 * radius) - halflen); |
---|
465 | |
---|
466 | addLine(0.5 * radius, 0.0, (-0.866 * radius) - halflen, |
---|
467 | 0.866 * radius, 0.0, (-0.5 * radius) - halflen); |
---|
468 | |
---|
469 | addLine(0.866 * radius, 0.0, (-0.5 * radius) - halflen, |
---|
470 | radius, 0.0, - halflen); |
---|
471 | |
---|
472 | // Y/Z axis |
---|
473 | |
---|
474 | // NW quadrant |
---|
475 | addLine(0.0, -radius, halflen, |
---|
476 | 0.0, -0.866 * radius, (0.5 * radius) + halflen); |
---|
477 | |
---|
478 | addLine(0.0, -0.866 * radius, (0.5 * radius) + halflen, |
---|
479 | 0.0, -0.5 * radius, (0.866 * radius) + halflen); |
---|
480 | |
---|
481 | addLine(0.0, -0.5 * radius, (0.866 * radius) + halflen, |
---|
482 | 0.0, 0.0, radius + halflen); |
---|
483 | |
---|
484 | // NE quadrant |
---|
485 | addLine(0.0, 0.0, radius + halflen, |
---|
486 | 0.0, 0.5 * radius, (0.866 * radius) + halflen); |
---|
487 | |
---|
488 | addLine(0.0, 0.5 * radius, (0.866 * radius) + halflen, |
---|
489 | 0.0, 0.866 * radius, (0.5 * radius) + halflen); |
---|
490 | |
---|
491 | addLine(0.0, 0.866 * radius, (0.5 * radius) + halflen, |
---|
492 | 0.0, radius, halflen); |
---|
493 | |
---|
494 | // SW quadrant |
---|
495 | addLine(0.0, -radius, -halflen, |
---|
496 | 0.0, -0.866 * radius, (-0.5 * radius) - halflen); |
---|
497 | |
---|
498 | addLine(0.0, -0.866 * radius, (-0.5 * radius) - halflen, |
---|
499 | 0.0, -0.5 * radius, (-0.866 * radius) - halflen); |
---|
500 | |
---|
501 | addLine(0.0, -0.5 * radius, (-0.866 * radius) - halflen, |
---|
502 | 0.0, 0.0, -radius - halflen); |
---|
503 | |
---|
504 | // SE quadrant |
---|
505 | addLine(0.0, 0.0, -radius - halflen, |
---|
506 | 0.0, 0.5 * radius, (-0.866 * radius) - halflen); |
---|
507 | |
---|
508 | addLine(0.0, 0.5 * radius, (-0.866 * radius) - halflen, |
---|
509 | 0.0, 0.866 * radius, (-0.5 * radius) - halflen); |
---|
510 | |
---|
511 | addLine(0.0, 0.866 * radius, (-0.5 * radius) - halflen, |
---|
512 | 0.0, radius, -halflen); |
---|
513 | |
---|
514 | // Side lines |
---|
515 | addLine(-radius, 0.0, -halflen, |
---|
516 | -radius, 0.0, halflen); |
---|
517 | |
---|
518 | addLine(radius, 0.0, -halflen, |
---|
519 | radius, 0.0, halflen); |
---|
520 | |
---|
521 | addLine(0.0, radius, -halflen, |
---|
522 | 0.0, radius, halflen); |
---|
523 | |
---|
524 | addLine(0.0, -radius, -halflen, |
---|
525 | 0.0, -radius, halflen); |
---|
526 | |
---|
527 | draw(); |
---|
528 | } |
---|
529 | //------------------------------------------------------------------------------------------------ |
---|
530 | CapsuleDebugObject::~CapsuleDebugObject() |
---|
531 | { |
---|
532 | } |
---|
533 | //------------------------------------------------------------------------------------------------ |
---|
534 | CylinderDebugObject::CylinderDebugObject(Real radius,Real length):DebugObject() |
---|
535 | { |
---|
536 | Real halflen = length * 0.5; |
---|
537 | AxisAlignedBox aabb(-radius,-radius,-(halflen + radius),radius,radius,halflen + radius); |
---|
538 | |
---|
539 | // X/Y axis - Near |
---|
540 | |
---|
541 | // NW quadrant |
---|
542 | addLine(-radius, 0.0, halflen, |
---|
543 | -0.866 * radius, 0.5 * radius, halflen); |
---|
544 | |
---|
545 | addLine(-0.866 * radius, 0.5 * radius, halflen, |
---|
546 | -0.5 * radius, 0.866 * radius, halflen); |
---|
547 | |
---|
548 | addLine(-0.5 * radius, 0.866 * radius, halflen, |
---|
549 | 0.0, radius, halflen); |
---|
550 | |
---|
551 | // NE quadrant |
---|
552 | addLine(0.0, radius, halflen, |
---|
553 | 0.5 * radius, 0.866 * radius, halflen); |
---|
554 | |
---|
555 | addLine(0.5 * radius, 0.866 * radius, halflen, |
---|
556 | 0.866 * radius, 0.5 * radius, halflen); |
---|
557 | |
---|
558 | addLine(0.866 * radius, 0.5 * radius, halflen, |
---|
559 | radius, 0.0, halflen); |
---|
560 | |
---|
561 | // SW quadrant |
---|
562 | addLine(-radius, 0.0, halflen, |
---|
563 | -0.866 * radius, -0.5 * radius, halflen); |
---|
564 | |
---|
565 | addLine(-0.866 * radius, -0.5 * radius, halflen, |
---|
566 | -0.5 * radius, -0.866 * radius, halflen); |
---|
567 | |
---|
568 | addLine(-0.5 * radius, -0.866 * radius, halflen, |
---|
569 | 0.0, -radius, halflen); |
---|
570 | |
---|
571 | // SE quadrant |
---|
572 | addLine(0.0, -radius, halflen, |
---|
573 | 0.5 * radius, -0.866 * radius, halflen); |
---|
574 | |
---|
575 | addLine(0.5 * radius, -0.866 * radius, halflen, |
---|
576 | 0.866 * radius, -0.5 * radius, halflen); |
---|
577 | |
---|
578 | addLine(0.866 * radius, -0.5 * radius, halflen, |
---|
579 | radius, 0.0, halflen); |
---|
580 | |
---|
581 | // X/Y axis - Far |
---|
582 | |
---|
583 | // NW quadrant |
---|
584 | addLine(-radius, 0.0, -halflen, |
---|
585 | -0.866 * radius, 0.5 * radius, -halflen); |
---|
586 | |
---|
587 | addLine(-0.866 * radius, 0.5 * radius, -halflen, |
---|
588 | -0.5 * radius, 0.866 * radius, -halflen); |
---|
589 | |
---|
590 | addLine(-0.5 * radius, 0.866 * radius, -halflen, |
---|
591 | 0.0, radius, -halflen); |
---|
592 | |
---|
593 | // NE quadrant |
---|
594 | addLine(0.0, radius, -halflen, |
---|
595 | 0.5 * radius, 0.866 * radius, -halflen); |
---|
596 | |
---|
597 | addLine(0.5 * radius, 0.866 * radius, -halflen, |
---|
598 | 0.866 * radius, 0.5 * radius, -halflen); |
---|
599 | |
---|
600 | addLine(0.866 * radius, 0.5 * radius, -halflen, |
---|
601 | radius, 0.0, -halflen); |
---|
602 | |
---|
603 | // SW quadrant |
---|
604 | addLine(-radius, 0.0, -halflen, |
---|
605 | -0.866 * radius, -0.5 * radius, -halflen); |
---|
606 | |
---|
607 | addLine(-0.866 * radius, -0.5 * radius, -halflen, |
---|
608 | -0.5 * radius, -0.866 * radius, -halflen); |
---|
609 | |
---|
610 | addLine(-0.5 * radius, -0.866 * radius, -halflen, |
---|
611 | 0.0, -radius, -halflen); |
---|
612 | |
---|
613 | // SE quadrant |
---|
614 | addLine(0.0, -radius, -halflen, |
---|
615 | 0.5 * radius, -0.866 * radius, -halflen); |
---|
616 | |
---|
617 | addLine(0.5 * radius, -0.866 * radius, -halflen, |
---|
618 | 0.866 * radius, -0.5 * radius, -halflen); |
---|
619 | |
---|
620 | addLine(0.866 * radius, -0.5 * radius, -halflen, |
---|
621 | radius, 0.0, -halflen); |
---|
622 | |
---|
623 | // X/Z axis |
---|
624 | |
---|
625 | // NW quadrant |
---|
626 | addLine(-radius, 0.0, halflen, |
---|
627 | -0.866 * radius, 0.0, (0.5 * radius) + halflen); |
---|
628 | |
---|
629 | addLine(-0.866 * radius, 0.0, (0.5 * radius) + halflen, |
---|
630 | -0.5 * radius, 0.0, (0.866 * radius) + halflen); |
---|
631 | |
---|
632 | addLine(-0.5 * radius, 0.0, (0.866 * radius) + halflen, |
---|
633 | 0.0, 0.0, radius + halflen); |
---|
634 | |
---|
635 | // NE quadrant |
---|
636 | addLine(0.0, 0.0, radius + halflen, |
---|
637 | 0.5 * radius, 0.0, (0.866 * radius) + halflen); |
---|
638 | |
---|
639 | addLine(0.5 * radius, 0.0, (0.866 * radius) + halflen, |
---|
640 | 0.866 * radius, 0.0, (0.5 * radius) + halflen); |
---|
641 | |
---|
642 | addLine(0.866 * radius, 0.0, (0.5 * radius) + halflen, |
---|
643 | radius, 0.0, halflen); |
---|
644 | |
---|
645 | // SW quadrant |
---|
646 | addLine(-radius, 0.0, -halflen, |
---|
647 | -0.866 * radius, 0.0, (-0.5 * radius) - halflen); |
---|
648 | |
---|
649 | addLine(-0.866 * radius, 0.0, (-0.5 * radius) - halflen, |
---|
650 | -0.5 * radius, 0.0, (-0.866 * radius) - halflen); |
---|
651 | |
---|
652 | addLine(-0.5 * radius, 0.0, (-0.866 * radius) - halflen, |
---|
653 | 0.0, 0.0, -radius - halflen); |
---|
654 | |
---|
655 | // SE quadrant |
---|
656 | addLine(0.0, 0.0, -radius - halflen, |
---|
657 | 0.5 * radius, 0.0, (-0.866 * radius) - halflen); |
---|
658 | |
---|
659 | addLine(0.5 * radius, 0.0, (-0.866 * radius) - halflen, |
---|
660 | 0.866 * radius, 0.0, (-0.5 * radius) - halflen); |
---|
661 | |
---|
662 | addLine(0.866 * radius, 0.0, (-0.5 * radius) - halflen, |
---|
663 | radius, 0.0, - halflen); |
---|
664 | |
---|
665 | // Y/Z axis |
---|
666 | |
---|
667 | // NW quadrant |
---|
668 | addLine(0.0, -radius, halflen, |
---|
669 | 0.0, -0.866 * radius, (0.5 * radius) + halflen); |
---|
670 | |
---|
671 | addLine(0.0, -0.866 * radius, (0.5 * radius) + halflen, |
---|
672 | 0.0, -0.5 * radius, (0.866 * radius) + halflen); |
---|
673 | |
---|
674 | addLine(0.0, -0.5 * radius, (0.866 * radius) + halflen, |
---|
675 | 0.0, 0.0, radius + halflen); |
---|
676 | |
---|
677 | // NE quadrant |
---|
678 | addLine(0.0, 0.0, radius + halflen, |
---|
679 | 0.0, 0.5 * radius, (0.866 * radius) + halflen); |
---|
680 | |
---|
681 | addLine(0.0, 0.5 * radius, (0.866 * radius) + halflen, |
---|
682 | 0.0, 0.866 * radius, (0.5 * radius) + halflen); |
---|
683 | |
---|
684 | addLine(0.0, 0.866 * radius, (0.5 * radius) + halflen, |
---|
685 | 0.0, radius, halflen); |
---|
686 | |
---|
687 | // SW quadrant |
---|
688 | addLine(0.0, -radius, -halflen, |
---|
689 | 0.0, -0.866 * radius, (-0.5 * radius) - halflen); |
---|
690 | |
---|
691 | addLine(0.0, -0.866 * radius, (-0.5 * radius) - halflen, |
---|
692 | 0.0, -0.5 * radius, (-0.866 * radius) - halflen); |
---|
693 | |
---|
694 | addLine(0.0, -0.5 * radius, (-0.866 * radius) - halflen, |
---|
695 | 0.0, 0.0, -radius - halflen); |
---|
696 | |
---|
697 | // SE quadrant |
---|
698 | addLine(0.0, 0.0, -radius - halflen, |
---|
699 | 0.0, 0.5 * radius, (-0.866 * radius) - halflen); |
---|
700 | |
---|
701 | addLine(0.0, 0.5 * radius, (-0.866 * radius) - halflen, |
---|
702 | 0.0, 0.866 * radius, (-0.5 * radius) - halflen); |
---|
703 | |
---|
704 | addLine(0.0, 0.866 * radius, (-0.5 * radius) - halflen, |
---|
705 | 0.0, radius, -halflen); |
---|
706 | |
---|
707 | // Side lines |
---|
708 | addLine(-radius, 0.0, -halflen, |
---|
709 | -radius, 0.0, halflen); |
---|
710 | |
---|
711 | addLine(radius, 0.0, -halflen, |
---|
712 | radius, 0.0, halflen); |
---|
713 | |
---|
714 | addLine(0.0, radius, -halflen, |
---|
715 | 0.0, radius, halflen); |
---|
716 | |
---|
717 | addLine(0.0, -radius, -halflen, |
---|
718 | 0.0, -radius, halflen); |
---|
719 | |
---|
720 | draw(); |
---|
721 | } |
---|
722 | //------------------------------------------------------------------------------------------------ |
---|
723 | CylinderDebugObject::~CylinderDebugObject() |
---|
724 | { |
---|
725 | } |
---|
726 | //------------------------------------------------------------------------------------------------ |
---|
727 | TriangleMeshDebugObject::TriangleMeshDebugObject(int vertex_count):DebugObject() |
---|
728 | { |
---|
729 | _points.reserve(vertex_count); |
---|
730 | _points.resize(vertex_count); |
---|
731 | } |
---|
732 | //------------------------------------------------------------------------------------------------ |
---|
733 | void TriangleMeshDebugObject::beginDefinition() |
---|
734 | { |
---|
735 | } |
---|
736 | //------------------------------------------------------------------------------------------------ |
---|
737 | void TriangleMeshDebugObject::setVertex(int index,const Ogre::Vector3& vertex) |
---|
738 | { |
---|
739 | assert ((unsigned int)index < _points.size()); |
---|
740 | _points[index] = vertex; |
---|
741 | } |
---|
742 | //------------------------------------------------------------------------------------------------ |
---|
743 | void TriangleMeshDebugObject::endDefinition() |
---|
744 | { |
---|
745 | draw(); |
---|
746 | } |
---|
747 | //------------------------------------------------------------------------------------------------ |
---|
748 | TriangleMeshDebugObject::~TriangleMeshDebugObject() |
---|
749 | { |
---|
750 | } |
---|
751 | //------------------------------------------------------------------------------------------------ |
---|
752 | RayDebugObject::RayDebugObject(const Ogre::Vector3& start, |
---|
753 | const Ogre::Vector3& direction, |
---|
754 | const Ogre::Real length): |
---|
755 | DebugObject() |
---|
756 | { |
---|
757 | |
---|
758 | Ogre::Vector3 end; |
---|
759 | |
---|
760 | if(length == Ogre::Math::POS_INFINITY) |
---|
761 | { |
---|
762 | end = (start + (direction.normalisedCopy() * 100000.0)); |
---|
763 | } |
---|
764 | else |
---|
765 | { |
---|
766 | end = (start + (direction.normalisedCopy() * length)); |
---|
767 | } |
---|
768 | |
---|
769 | addLine(start, end); |
---|
770 | |
---|
771 | draw(); |
---|
772 | } |
---|
773 | void RayDebugObject::setDefinition(const Ogre::Vector3& start, |
---|
774 | const Ogre::Vector3& direction, |
---|
775 | const Ogre::Real length) |
---|
776 | { |
---|
777 | clear(); |
---|
778 | |
---|
779 | Ogre::Vector3 end; |
---|
780 | |
---|
781 | if(length == Ogre::Math::POS_INFINITY) |
---|
782 | { |
---|
783 | end = (start + (direction.normalisedCopy() * 100000.0)); |
---|
784 | } |
---|
785 | else |
---|
786 | { |
---|
787 | end = (start + (direction.normalisedCopy() * length)); |
---|
788 | } |
---|
789 | |
---|
790 | addLine(start, end); |
---|
791 | |
---|
792 | draw(); |
---|
793 | } |
---|
794 | //------------------------------------------------------------------------------------------------ |
---|
795 | RayDebugObject::~RayDebugObject() |
---|
796 | { |
---|
797 | } |
---|
798 | //------------------------------------------------------------------------------------------------ |
---|
799 | |
---|