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