source: trunk/VUT/Ogre/src/OgreSolidHalfBoundingBox.cpp @ 117

Revision 117, 3.4 KB checked in by mattausch, 20 years ago (diff)
Line 
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
10namespace Ogre {
11
12#define POSITION_BINDING 0
13//-----------------------------------------------------------------------
14SolidHalfBoundingBox::SolidHalfBoundingBox()
15{
16        SetOcclusionQueryMaterial();
17       
18        mRenderOp.vertexData->vertexCount = 8;
19    mRenderOp.operationType = RenderOperation::OT_TRIANGLE_FAN;
20}
21//-----------------------------------------------------------------------
22void 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        // fan 1
44        if (isFirstHalf)
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
57        // fan 2
58        {
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
63
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
68        }
69
70    vbuf->unlock();
71}
72//-----------------------------------------------------------------------
73void SolidHalfBoundingBox::SetupBoundingBox(const AxisAlignedBox& aab,
74                                                                                        const bool isFirstHalf)
75{
76        // init the vertices to the aabb
77        SetupBoundingBoxVertices(aab, isFirstHalf);
78
79        Real sqLen = std::max(aab.getMaximum().squaredLength(),
80                                                  aab.getMinimum().squaredLength());
81    mRadius = Math::Sqrt(sqLen);
82
83    // setup the bounding box of this SimpleRenderable
84        setBoundingBox(aab);
85}
86//-----------------------------------------------------------------------
87void SolidHalfBoundingBox::SetOcclusionQueryMaterial( void )
88{
89        m_pMaterial = MaterialManager::getSingleton().getByName("Visibility/QueryMaterial");
90
91        if (m_pMaterial.isNull())
92        {
93                m_pMaterial = MaterialManager::getSingleton().
94                        create("Visibility/QueryMaterial", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
95        }
96
97        m_pMaterial->setColourWriteEnabled(false);
98        m_pMaterial->setDepthWriteEnabled(false);
99        m_pMaterial->setLightingEnabled(false);
100
101        setMaterial("Visibility/QueryMaterial");
102}
103
104} // namespace Ogre
105
Note: See TracBrowser for help on using the repository browser.