1
///////////////////////////////////////////////////////////////////////////////
2
/// @file OgreOpcodeDebugObject.cpp
3
/// @brief <TODO: insert file description here>
4
/// @remarks Based directly on code from OgreNewt, by Walaber.
5
/// @author The OgreOpcode Team
6
///////////////////////////////////////////////////////////////////////////////
8
/// This file is part of OgreOpcode.
10
/// A lot of the code is based on the Nebula Opcode Collision module, see docs/Nebula_license.txt
12
/// OgreOpcode is free software; you can redistribute it and/or
13
/// modify it under the terms of the GNU Lesser General Public
14
/// License as published by the Free Software Foundation; either
15
/// version 2.1 of the License, or (at your option) any later version.
17
/// OgreOpcode is distributed in the hope that it will be useful,
18
/// but WITHOUT ANY WARRANTY; without even the implied warranty of
19
/// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20
/// Lesser General Public License for more details.
22
/// You should have received a copy of the GNU Lesser General Public
23
/// License along with OgreOpcode; if not, write to the Free Software
24
/// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26
///////////////////////////////////////////////////////////////////////////////
27
#include "OgreOpcodeDebugObject.h"
34
OgreOpcodeDebugger::OgreOpcodeDebugger(const Ogre::String& name, SceneManager* sceneMgr)
35
: mSceneMgr(sceneMgr),
38
mContactsDebugNode(0),
39
mContactNormalsDebugNode(0),
44
mContactsDebugObject(0),
45
mContactNormalsDebugObject(0),
47
mShapesDebugObject(0),
50
mRadiiDebugNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("__OgreOpcode__RadiiDebugger__" + mName);
51
mContactsDebugNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("__OgreOpcode__ContactsDebugger__" + mName);
52
mContactNormalsDebugNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("__OgreOpcode__ContactNormalsDebugger__" + mName);
53
mBBsDebugNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("__OgreOpcode__BBsDebugger__" + mName);
54
mShapesDebugNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("__OgreOpcode__ShapesDebugger__" + mName);
55
mAABBsDebugNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("__OgreOpcode__AABBsDebugger__" + mName);
57
#ifdef BUILD_AGAINST_AZATHOTH
58
mRadiiDebugObject = new DebugLines();
59
mContactsDebugObject = new DebugLines();
60
mContactNormalsDebugObject = new DebugLines();
61
mBBsDebugObject = new DebugLines();
62
mShapesDebugObject = new DebugLines();
63
mAABBsDebugObject = new DebugLines();
65
mRadiiDebugObject = new ManualObject("__OgreOpcode__RadiiDebugger__" + mName);
66
mContactsDebugObject = new ManualObject("__OgreOpcode__ContactsDebugger__" + mName);
67
mContactNormalsDebugObject = new ManualObject("__OgreOpcode__ContactNormalsDebugger__" + mName);
68
mBBsDebugObject = new ManualObject("__OgreOpcode__BBsDebugger__" + mName);
69
mShapesDebugObject = new ManualObject("__OgreOpcode__ShapesDebugger__" + mName);
70
mAABBsDebugObject = new ManualObject("__OgreOpcode__AABBsDebugger__" + mName);
75
OgreOpcodeDebugger::~OgreOpcodeDebugger()
77
delete mRadiiDebugObject;
78
delete mContactsDebugObject;
79
delete mContactNormalsDebugObject;
80
delete mBBsDebugObject;
81
delete mShapesDebugObject;
82
delete mAABBsDebugObject;
84
mRadiiDebugNode->getParentSceneNode()->removeChild(mRadiiDebugNode);
85
mSceneMgr->destroySceneNode(mRadiiDebugNode->getName());
87
mContactsDebugNode->getParentSceneNode()->removeChild(mContactsDebugNode);
88
mSceneMgr->destroySceneNode(mContactsDebugNode->getName());
89
mContactsDebugNode = 0;
90
mContactNormalsDebugNode->getParentSceneNode()->removeChild(mContactNormalsDebugNode);
91
mSceneMgr->destroySceneNode(mContactNormalsDebugNode->getName());
92
mContactNormalsDebugNode = 0;
93
mBBsDebugNode->getParentSceneNode()->removeChild(mBBsDebugNode);
94
mSceneMgr->destroySceneNode(mBBsDebugNode->getName());
96
mShapesDebugNode->getParentSceneNode()->removeChild(mShapesDebugNode);
97
mSceneMgr->destroySceneNode(mShapesDebugNode->getName());
99
mAABBsDebugNode->getParentSceneNode()->removeChild(mAABBsDebugNode);
100
mSceneMgr->destroySceneNode(mAABBsDebugNode->getName());
104
void OgreOpcodeDebugger::addRadiiLine(Real lx1, Real ly1, Real lz1, Real lx2, Real ly2, Real lz2)
106
#ifdef BUILD_AGAINST_AZATHOTH
107
mRadiiDebugObject->addLine(lx1, ly1, lz1, lx2, ly2, lz2);
109
mRadiiDebugObject->position(lx1, ly1, lz1);
110
mRadiiDebugObject->position(lx2, ly2, lz2);
114
void OgreOpcodeDebugger::addContactLine(Real lx1, Real ly1, Real lz1, Real lx2, Real ly2, Real lz2)
116
#ifdef BUILD_AGAINST_AZATHOTH
117
mContactsDebugObject->addLine(lx1, ly1, lz1, lx2, ly2, lz2);
119
mContactsDebugObject->position(lx1, ly1, lz1);
120
mContactsDebugObject->position(lx2, ly2, lz2);
124
void OgreOpcodeDebugger::addContactNormalsLine(Real lx1, Real ly1, Real lz1, Real lx2, Real ly2, Real lz2)
126
#ifdef BUILD_AGAINST_AZATHOTH
127
mContactNormalsDebugObject->addLine(lx1, ly1, lz1, lx2, ly2, lz2);
129
mContactNormalsDebugObject->position(lx1, ly1, lz1);
130
mContactNormalsDebugObject->position(lx2, ly2, lz2);
134
void OgreOpcodeDebugger::addBBLine(Real lx1, Real ly1, Real lz1, Real lx2, Real ly2, Real lz2)
136
#ifdef BUILD_AGAINST_AZATHOTH
137
mBBsDebugObject->addLine(lx1, ly1, lz1, lx2, ly2, lz2);
139
mBBsDebugObject->position(lx1, ly1, lz1);
140
mBBsDebugObject->position(lx2, ly2, lz2);
144
void OgreOpcodeDebugger::addShapeLine(Real lx1, Real ly1, Real lz1, Real lx2, Real ly2, Real lz2)
146
#ifdef BUILD_AGAINST_AZATHOTH
147
mShapesDebugObject->addLine(lx1, ly1, lz1, lx2, ly2, lz2);
149
mShapesDebugObject->position(lx1, ly1, lz1);
150
mShapesDebugObject->position(lx2, ly2, lz2);
154
void OgreOpcodeDebugger::addAABBLine(Real lx1, Real ly1, Real lz1, Real lx2, Real ly2, Real lz2)
156
#ifdef BUILD_AGAINST_AZATHOTH
157
mAABBsDebugObject->addLine(lx1, ly1, lz1, lx2, ly2, lz2);
159
mAABBsDebugObject->position(lx1, ly1, lz1);
160
mAABBsDebugObject->position(lx2, ly2, lz2);
164
void OgreOpcodeDebugger::clearRadii()
166
mRadiiDebugNode->detachAllObjects();
167
mRadiiDebugObject->clear();
170
void OgreOpcodeDebugger::beginRadii()
172
#ifdef BUILD_AGAINST_AZATHOTH
173
mRadiiDebugObject->setMaterial("OgreOpcodeDebug/Radii");
175
mRadiiDebugObject->begin("OgreOpcodeDebug/Radii", Ogre::RenderOperation::OT_LINE_LIST);
179
void OgreOpcodeDebugger::endRadii()
181
#ifdef BUILD_AGAINST_AZATHOTH
182
mRadiiDebugObject->draw();
184
mRadiiDebugObject->end();
186
mRadiiDebugNode->attachObject(mRadiiDebugObject);
189
void OgreOpcodeDebugger::clearContacts()
191
mContactsDebugNode->detachAllObjects();
192
mContactsDebugObject->clear();
195
void OgreOpcodeDebugger::beginContacts()
197
#ifdef BUILD_AGAINST_AZATHOTH
198
mContactsDebugObject->setMaterial("OgreOpcodeDebug/Contacts");
200
mContactsDebugObject->begin("OgreOpcodeDebug/Contacts", Ogre::RenderOperation::OT_LINE_LIST);
204
void OgreOpcodeDebugger::endContacts()
206
#ifdef BUILD_AGAINST_AZATHOTH
207
mContactsDebugObject->draw();
209
mContactsDebugObject->end();
211
if(mContactsDebugNode->numAttachedObjects() < 1)
212
mContactsDebugNode->attachObject(mContactsDebugObject);
215
void OgreOpcodeDebugger::clearContactNormals()
217
mContactNormalsDebugNode->detachAllObjects();
218
mContactNormalsDebugObject->clear();
221
void OgreOpcodeDebugger::beginContactNormals()
223
#ifdef BUILD_AGAINST_AZATHOTH
224
mContactNormalsDebugObject->setMaterial("OgreOpcodeDebug/ContactNormals");
226
mContactNormalsDebugObject->begin("OgreOpcodeDebug/ContactNormals", Ogre::RenderOperation::OT_LINE_LIST);
230
void OgreOpcodeDebugger::endContactNormals()
232
#ifdef BUILD_AGAINST_AZATHOTH
233
mContactNormalsDebugObject->draw();
235
mContactNormalsDebugObject->end();
237
if(mContactNormalsDebugNode->numAttachedObjects() < 1)
238
mContactNormalsDebugNode->attachObject(mContactNormalsDebugObject);
241
void OgreOpcodeDebugger::clearBBs()
243
mBBsDebugNode->detachAllObjects();
244
mBBsDebugObject->clear();
247
void OgreOpcodeDebugger::beginBBs()
249
#ifdef BUILD_AGAINST_AZATHOTH
250
mBBsDebugObject->setMaterial("OgreOpcodeDebug/BBs");
252
mBBsDebugObject->begin("OgreOpcodeDebug/BBs", Ogre::RenderOperation::OT_LINE_LIST);
256
void OgreOpcodeDebugger::endBBs()
258
#ifdef BUILD_AGAINST_AZATHOTH
259
mBBsDebugObject->draw();
261
mBBsDebugObject->end();
263
mBBsDebugNode->attachObject(mBBsDebugObject);
266
void OgreOpcodeDebugger::clearShapes()
268
mShapesDebugNode->detachAllObjects();
269
mShapesDebugObject->clear();
272
void OgreOpcodeDebugger::beginShapes()
274
#ifdef BUILD_AGAINST_AZATHOTH
275
mShapesDebugObject->setMaterial("OgreOpcodeDebug/Shapes");
277
mShapesDebugObject->begin("OgreOpcodeDebug/Shapes", Ogre::RenderOperation::OT_LINE_LIST);
281
void OgreOpcodeDebugger::endShapes()
283
#ifdef BUILD_AGAINST_AZATHOTH
284
mShapesDebugObject->draw();
286
mShapesDebugObject->end();
288
mShapesDebugNode->attachObject(mShapesDebugObject);
291
void OgreOpcodeDebugger::clearAABBs()
293
mAABBsDebugNode->detachAllObjects();
294
mAABBsDebugObject->clear();
297
void OgreOpcodeDebugger::beginAABBs()
299
#ifdef BUILD_AGAINST_AZATHOTH
300
mAABBsDebugObject->setMaterial("OgreOpcodeDebug/AABBs");
302
mAABBsDebugObject->begin("OgreOpcodeDebug/AABBs", Ogre::RenderOperation::OT_LINE_LIST);
306
void OgreOpcodeDebugger::endAABBs()
308
#ifdef BUILD_AGAINST_AZATHOTH
309
mAABBsDebugObject->draw();
311
mAABBsDebugObject->end();
313
mAABBsDebugNode->attachObject(mAABBsDebugObject);
316
void OgreOpcodeDebugger::clearAll()
320
clearContactNormals();
326
#ifdef BUILD_AGAINST_AZATHOTH
327
DebugLines::DebugLines()
329
mRenderOp.vertexData = new VertexData();
333
void DebugLines::clear()
339
delete mRenderOp.vertexData;
341
mRenderOp.vertexData = new VertexData();
345
DebugLines::~DebugLines(void)
349
delete mRenderOp.vertexData;
352
void DebugLines::draw()
357
// Initialization stuff
358
mRenderOp.indexData = 0;
359
mRenderOp.vertexData->vertexCount = _points.size();
360
mRenderOp.vertexData->vertexStart = 0;
361
mRenderOp.operationType = RenderOperation::OT_LINE_LIST;
362
mRenderOp.useIndexes = false;
364
VertexDeclaration *decl = mRenderOp.vertexData->vertexDeclaration;
365
VertexBufferBinding *bind = mRenderOp.vertexData->vertexBufferBinding;
367
decl->addElement(0, 0, VET_FLOAT3, VES_POSITION);
369
HardwareVertexBufferSharedPtr vbuf =
370
HardwareBufferManager::getSingleton().createVertexBuffer(
371
decl->getVertexSize(0),
372
mRenderOp.vertexData->vertexCount,
373
HardwareBuffer::HBU_STATIC_WRITE_ONLY);
375
bind->setBinding(0, vbuf);
378
size_t size = _points.size();
379
Vector3 vaabMin = _points[0];
380
Vector3 vaabMax = _points[0];
382
Real *prPos = static_cast<Real*>(vbuf->lock(HardwareBuffer::HBL_DISCARD));
384
for(size_t i = 0; i < size; i++)
386
*prPos++ = _points[i].x;
387
*prPos++ = _points[i].y;
388
*prPos++ = _points[i].z;
390
if(_points[i].x < vaabMin.x)
391
vaabMin.x = _points[i].x;
392
if(_points[i].y < vaabMin.y)
393
vaabMin.y = _points[i].y;
394
if(_points[i].z < vaabMin.z)
395
vaabMin.z = _points[i].z;
397
if(_points[i].x > vaabMax.x)
398
vaabMax.x = _points[i].x;
399
if(_points[i].y > vaabMax.y)
400
vaabMax.y = _points[i].y;
401
if(_points[i].z > vaabMax.z)
402
vaabMax.z = _points[i].z;
407
mBox.setExtents(vaabMin, vaabMax);
410
Real DebugLines::getSquaredViewDepth(const Camera *cam) const
412
Vector3 vMin, vMax, vMid, vDist;
413
vMin = mBox.getMinimum();
414
vMax = mBox.getMaximum();
415
vMid = ((vMin - vMax) * 0.5) + vMin;
416
vDist = cam->getDerivedPosition() - vMid;
418
return vDist.squaredLength();
421
Real DebugLines::getBoundingRadius() const
423
return Math::Sqrt(std::max(mBox.getMaximum().squaredLength(), mBox.getMinimum().squaredLength()));
426
} // namespace Details
428
} // namespace OgreOpcode