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