[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 |
|
---|
[103] | 9 |
|
---|
[59] | 10 | namespace Ogre {
|
---|
| 11 |
|
---|
| 12 | #define POSITION_BINDING 0
|
---|
| 13 | //-----------------------------------------------------------------------
|
---|
[85] | 14 | SolidHalfBoundingBox::SolidHalfBoundingBox()
|
---|
[59] | 15 | {
|
---|
[85] | 16 | SetOcclusionQueryMaterial();
|
---|
[59] | 17 |
|
---|
| 18 | mRenderOp.vertexData->vertexCount = 8;
|
---|
| 19 | mRenderOp.operationType = RenderOperation::OT_TRIANGLE_FAN;
|
---|
| 20 | }
|
---|
| 21 | //-----------------------------------------------------------------------
|
---|
[85] | 22 | void SolidHalfBoundingBox::SetupBoundingBoxVertices(const AxisAlignedBox& aab,
|
---|
| 23 | const bool isFirstHalf)
|
---|
| 24 | {
|
---|
[91] | 25 | const Vector3& min = aab.getMinimum();
|
---|
| 26 | const Vector3& max = aab.getMaximum();
|
---|
| 27 |
|
---|
[85] | 28 | // fill the vertex buffer: 12 lines with 2 endpoints each make up a box
|
---|
[59] | 29 | HardwareVertexBufferSharedPtr vbuf =
|
---|
| 30 | mRenderOp.vertexData->vertexBufferBinding->getBuffer(POSITION_BINDING);
|
---|
| 31 |
|
---|
[91] | 32 | float* pPos = static_cast<float*>(vbuf->lock(HardwareBuffer::HBL_DISCARD));
|
---|
[59] | 33 |
|
---|
| 34 | // 5+------+7 |
---|
| 35 | // /| /| |
---|
| 36 | // / | / | |
---|
| 37 | // / 1+---/--+3 |
---|
| 38 | // 2+------+6 / y z |
---|
| 39 | // | / | / | / |
---|
| 40 | // |/ |/ |/ |
---|
| 41 | // 0+------+4 *---x
|
---|
| 42 |
|
---|
| 43 | // fan 1
|
---|
[100] | 44 | if (isFirstHalf)
|
---|
[59] | 45 | {
|
---|
[91] | 46 | *pPos++ = min.x; *pPos++ = max.y; *pPos++ = max.z; //011
|
---|
| 47 | *pPos++ = min.x; *pPos++ = min.y; *pPos++ = max.z; //001
|
---|
| 48 | *pPos++ = max.x; *pPos++ = min.y; *pPos++ = max.z; //101
|
---|
| 49 | *pPos++ = max.x; *pPos++ = max.y; *pPos++ = max.z; //111
|
---|
[59] | 50 |
|
---|
[91] | 51 | *pPos++ = max.x; *pPos++ = max.y; *pPos++ = min.z; //110
|
---|
| 52 | *pPos++ = min.x; *pPos++ = max.y; *pPos++ = min.z; //010
|
---|
| 53 | *pPos++ = min.x; *pPos++ = min.y; *pPos++ = min.z; //000
|
---|
| 54 | *pPos++ = min.x; *pPos++ = min.y; *pPos++ = max.z; //001
|
---|
[59] | 55 | }
|
---|
| 56 | else
|
---|
| 57 | // fan 2
|
---|
| 58 | {
|
---|
[91] | 59 | *pPos++ = max.x; *pPos++ = min.y; *pPos++ = min.z; //100
|
---|
| 60 | *pPos++ = min.x; *pPos++ = min.y; *pPos++ = min.z; //000
|
---|
| 61 | *pPos++ = min.x; *pPos++ = max.y; *pPos++ = min.z; //010
|
---|
| 62 | *pPos++ = max.x; *pPos++ = max.y; *pPos++ = min.z; //110
|
---|
[59] | 63 |
|
---|
[91] | 64 | *pPos++ = max.x; *pPos++ = max.y; *pPos++ = max.z; //111
|
---|
| 65 | *pPos++ = max.x; *pPos++ = min.y; *pPos++ = max.z; //101
|
---|
| 66 | *pPos++ = min.x; *pPos++ = min.y; *pPos++ = max.z; //001
|
---|
| 67 | *pPos++ = min.x; *pPos++ = min.y; *pPos++ = min.z; //000
|
---|
[59] | 68 | }
|
---|
| 69 |
|
---|
| 70 | vbuf->unlock();
|
---|
| 71 | }
|
---|
[85] | 72 | //-----------------------------------------------------------------------
|
---|
[91] | 73 | void SolidHalfBoundingBox::SetupBoundingBox(const AxisAlignedBox& aab,
|
---|
[85] | 74 | const bool isFirstHalf)
|
---|
[59] | 75 | {
|
---|
| 76 | // init the vertices to the aabb
|
---|
[91] | 77 | SetupBoundingBoxVertices(aab, isFirstHalf);
|
---|
[59] | 78 |
|
---|
[91] | 79 | Real sqLen = std::max(aab.getMaximum().squaredLength(),
|
---|
| 80 | aab.getMinimum().squaredLength());
|
---|
| 81 | mRadius = Math::Sqrt(sqLen);
|
---|
| 82 |
|
---|
[59] | 83 | // setup the bounding box of this SimpleRenderable
|
---|
[91] | 84 | setBoundingBox(aab);
|
---|
[59] | 85 | }
|
---|
[85] | 86 | //-----------------------------------------------------------------------
|
---|
| 87 | void SolidHalfBoundingBox::SetOcclusionQueryMaterial( void )
|
---|
[59] | 88 | {
|
---|
[117] | 89 | m_pMaterial = MaterialManager::getSingleton().getByName("Visibility/QueryMaterial");
|
---|
[59] | 90 |
|
---|
[100] | 91 | if (m_pMaterial.isNull())
|
---|
[59] | 92 | {
|
---|
| 93 | m_pMaterial = MaterialManager::getSingleton().
|
---|
[117] | 94 | create("Visibility/QueryMaterial", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
|
---|
[59] | 95 | }
|
---|
| 96 |
|
---|
| 97 | m_pMaterial->setColourWriteEnabled(false);
|
---|
| 98 | m_pMaterial->setDepthWriteEnabled(false);
|
---|
| 99 | m_pMaterial->setLightingEnabled(false);
|
---|
| 100 |
|
---|
[117] | 101 | setMaterial("Visibility/QueryMaterial");
|
---|
[59] | 102 | }
|
---|
| 103 |
|
---|
| 104 | } // namespace Ogre
|
---|
| 105 |
|
---|