source: trunk/VUT/obsolete/OcclusionCullingSceneManager/src/OgreSolidHalfBoundingBox.cpp @ 54

Revision 54, 3.6 KB checked in by mattausch, 19 years ago (diff)

fixed terrainscenemanager bug

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//#include <windows.h>
9
10namespace Ogre {
11    #define POSITION_BINDING 0
12        //-----------------------------------------------------------------------
13        SolidHalfBoundingBox::SolidHalfBoundingBox(bool isFirstHalf)
14                :WireBoundingBox(), mIsFirstHalf(isFirstHalf)
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
24                Vector3 vmax = aab.getMaximum();
25                Vector3 vmin = aab.getMinimum();
26               
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 in 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(mIsFirstHalf)
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                }
69                else
70                // fan 2
71                {
72                        *pPos++ = maxx; *pPos++ = miny; *pPos++ = minz; //100
73                        *pPos++ = minx; *pPos++ = miny; *pPos++ = minz; //000                                   
74                        *pPos++ = minx; *pPos++ = maxy; *pPos++ = minz; //010
75                        *pPos++ = maxx; *pPos++ = maxy; *pPos++ = minz; //110
76
77                        *pPos++ = maxx; *pPos++ = maxy; *pPos++ = maxz; //111
78                        *pPos++ = maxx; *pPos++ = miny; *pPos++ = maxz; //101
79                        *pPos++ = minx; *pPos++ = miny; *pPos++ = maxz; //001
80                        *pPos++ = minx; *pPos++ = miny; *pPos++ = minz; //000
81                }
82
83        vbuf->unlock();
84        }
85
86        void SolidHalfBoundingBox::setupBoundingBox(const AxisAlignedBox& aabb)
87    {
88                // init the vertices to the aabb
89                SolidHalfBoundingBox::setupBoundingBoxVertices(aabb);
90
91        // setup the bounding box of this SimpleRenderable
92                setBoundingBox(aabb);
93        }
94        // Override this method to prevent parent transforms (rotation,translation,scale)
95    void SolidHalfBoundingBox::getWorldTransforms( Matrix4* xform ) const
96    {
97                // return identity matrix to prevent parent transforms
98        *xform = Matrix4::IDENTITY;
99    }
100
101        void SolidHalfBoundingBox::setOcclusionQueryMaterial( void )
102        {
103                m_pMaterial = MaterialManager::getSingleton().getByName("OcclusionQuery");
104
105                if(m_pMaterial.isNull())
106                {
107                        m_pMaterial = MaterialManager::getSingleton().
108                                create("OcclusionQuery", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
109                }
110
111                m_pMaterial->setColourWriteEnabled(false);
112                m_pMaterial->setDepthWriteEnabled(false);
113                m_pMaterial->setLightingEnabled(false);
114
115                setMaterial("OcclusionQuery");
116        }
117}
118
Note: See TracBrowser for help on using the repository browser.