[59] | 1 | #include "OgreStableHeaders.h"
|
---|
| 2 | #include "OgreSolidHalfBoundingBox.h"
|
---|
| 3 |
|
---|
| 4 | #include "OgreSimpleRenderable.h"
|
---|
| 5 | #include "OgreHardwareBufferManager.h"
|
---|
| 6 | #include "OgreCamera.h"
|
---|
| 7 | #include "OgreMaterialManager.h"
|
---|
| 8 | //#include <windows.h>
|
---|
| 9 |
|
---|
| 10 | namespace Ogre {
|
---|
| 11 |
|
---|
| 12 | #define POSITION_BINDING 0
|
---|
| 13 | //-----------------------------------------------------------------------
|
---|
| 14 | SolidHalfBoundingBox::SolidHalfBoundingBox(bool isFirstHalf)
|
---|
| 15 | :WireBoundingBox(), mIsFirstHalf(isFirstHalf)
|
---|
| 16 | {
|
---|
| 17 | setOcclusionQueryMaterial();
|
---|
| 18 |
|
---|
| 19 | mRenderOp.vertexData->vertexCount = 8;
|
---|
| 20 | mRenderOp.operationType = RenderOperation::OT_TRIANGLE_FAN;
|
---|
| 21 | }
|
---|
| 22 | //-----------------------------------------------------------------------
|
---|
| 23 | void SolidHalfBoundingBox::setupBoundingBoxVertices(const AxisAlignedBox& aab) {
|
---|
| 24 |
|
---|
| 25 | Vector3 vmax = aab.getMaximum();
|
---|
| 26 | Vector3 vmin = aab.getMinimum();
|
---|
| 27 |
|
---|
| 28 |
|
---|
| 29 | Real sqLen = std::max(vmax.squaredLength(), vmin.squaredLength());
|
---|
| 30 | mRadius = Math::Sqrt(sqLen);
|
---|
| 31 |
|
---|
| 32 | Real maxx = vmax.x;
|
---|
| 33 | Real maxy = vmax.y;
|
---|
| 34 | Real maxz = vmax.z;
|
---|
| 35 |
|
---|
| 36 | Real minx = vmin.x;
|
---|
| 37 | Real miny = vmin.y;
|
---|
| 38 | Real minz = vmin.z;
|
---|
| 39 |
|
---|
| 40 | // fill in the Vertex buffer: 12 lines with 2 endpoints each make up a box
|
---|
| 41 | HardwareVertexBufferSharedPtr vbuf =
|
---|
| 42 | mRenderOp.vertexData->vertexBufferBinding->getBuffer(POSITION_BINDING);
|
---|
| 43 |
|
---|
| 44 | float* pPos = static_cast<float*>(
|
---|
| 45 | vbuf->lock(HardwareBuffer::HBL_DISCARD));
|
---|
| 46 |
|
---|
| 47 | // 5+------+7 |
---|
| 48 | // /| /| |
---|
| 49 | // / | / | |
---|
| 50 | // / 1+---/--+3 |
---|
| 51 | // 2+------+6 / y z |
---|
| 52 | // | / | / | / |
---|
| 53 | // |/ |/ |/ |
---|
| 54 | // 0+------+4 *---x
|
---|
| 55 |
|
---|
| 56 | // fan 1
|
---|
| 57 | if(mIsFirstHalf)
|
---|
| 58 | {
|
---|
| 59 | *pPos++ = minx; *pPos++ = maxy; *pPos++ = maxz; //011
|
---|
| 60 | *pPos++ = minx; *pPos++ = miny; *pPos++ = maxz; //001
|
---|
| 61 | *pPos++ = maxx; *pPos++ = miny; *pPos++ = maxz; //101
|
---|
| 62 | *pPos++ = maxx; *pPos++ = maxy; *pPos++ = maxz; //111
|
---|
| 63 |
|
---|
| 64 | *pPos++ = maxx; *pPos++ = maxy; *pPos++ = minz; //110
|
---|
| 65 | *pPos++ = minx; *pPos++ = maxy; *pPos++ = minz; //010
|
---|
| 66 | *pPos++ = minx; *pPos++ = miny; *pPos++ = minz; //000
|
---|
| 67 | *pPos++ = minx; *pPos++ = miny; *pPos++ = maxz; //001
|
---|
| 68 |
|
---|
| 69 | }
|
---|
| 70 | else
|
---|
| 71 | // fan 2
|
---|
| 72 | {
|
---|
| 73 | *pPos++ = maxx; *pPos++ = miny; *pPos++ = minz; //100
|
---|
| 74 | *pPos++ = minx; *pPos++ = miny; *pPos++ = minz; //000
|
---|
| 75 | *pPos++ = minx; *pPos++ = maxy; *pPos++ = minz; //010
|
---|
| 76 | *pPos++ = maxx; *pPos++ = maxy; *pPos++ = minz; //110
|
---|
| 77 |
|
---|
| 78 | *pPos++ = maxx; *pPos++ = maxy; *pPos++ = maxz; //111
|
---|
| 79 | *pPos++ = maxx; *pPos++ = miny; *pPos++ = maxz; //101
|
---|
| 80 | *pPos++ = minx; *pPos++ = miny; *pPos++ = maxz; //001
|
---|
| 81 | *pPos++ = minx; *pPos++ = miny; *pPos++ = minz; //000
|
---|
| 82 | }
|
---|
| 83 |
|
---|
| 84 | vbuf->unlock();
|
---|
| 85 | }
|
---|
| 86 |
|
---|
| 87 | void SolidHalfBoundingBox::setupBoundingBox(const AxisAlignedBox& aabb)
|
---|
| 88 | {
|
---|
| 89 | // init the vertices to the aabb
|
---|
| 90 | SolidHalfBoundingBox::setupBoundingBoxVertices(aabb);
|
---|
| 91 |
|
---|
| 92 | // setup the bounding box of this SimpleRenderable
|
---|
| 93 | setBoundingBox(aabb);
|
---|
| 94 | }
|
---|
| 95 | // Override this method to prevent parent transforms (rotation,translation,scale)
|
---|
| 96 | void SolidHalfBoundingBox::getWorldTransforms( Matrix4* xform ) const
|
---|
| 97 | {
|
---|
| 98 | // return identity matrix to prevent parent transforms
|
---|
| 99 | *xform = Matrix4::IDENTITY;
|
---|
| 100 | }
|
---|
| 101 |
|
---|
| 102 | void SolidHalfBoundingBox::setOcclusionQueryMaterial( void )
|
---|
| 103 | {
|
---|
| 104 | m_pMaterial = MaterialManager::getSingleton().getByName("OcclusionQuery");
|
---|
| 105 |
|
---|
| 106 | if(m_pMaterial.isNull())
|
---|
| 107 | {
|
---|
| 108 | m_pMaterial = MaterialManager::getSingleton().
|
---|
| 109 | create("OcclusionQuery", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
|
---|
| 110 | }
|
---|
| 111 |
|
---|
| 112 | m_pMaterial->setColourWriteEnabled(false);
|
---|
| 113 | m_pMaterial->setDepthWriteEnabled(false);
|
---|
| 114 | m_pMaterial->setLightingEnabled(false);
|
---|
| 115 |
|
---|
| 116 | setMaterial("OcclusionQuery");
|
---|
| 117 | }
|
---|
| 118 |
|
---|
| 119 | } // namespace Ogre
|
---|
| 120 |
|
---|