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