source: trunk/VUT/OcclusionCullingSceneManager/src/OgreSolidHalfBoundingBox.cpp @ 51

Revision 51, 3.1 KB checked in by mattausch, 19 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 <windows.h>
8
9namespace Ogre {
10    #define POSITION_BINDING 0
11        //-----------------------------------------------------------------------
12        SolidHalfBoundingBox::SolidHalfBoundingBox(bool isFirstHalf)
13                :WireBoundingBox(), mIsFirstHalf(isFirstHalf)
14    {
15                mRenderOp.vertexData->vertexCount = 8;
16        mRenderOp.operationType = RenderOperation::OT_TRIANGLE_FAN;
17        }
18        //-----------------------------------------------------------------------
19        void SolidHalfBoundingBox::setupBoundingBoxVertices(const AxisAlignedBox& aab) {
20
21                Vector3 vmax = aab.getMaximum();
22                Vector3 vmin = aab.getMinimum();
23               
24               
25                Real sqLen = std::max(vmax.squaredLength(), vmin.squaredLength());
26        mRadius = Math::Sqrt(sqLen);
27               
28                Real maxx = vmax.x;
29                Real maxy = vmax.y;
30                Real maxz = vmax.z;
31               
32                Real minx = vmin.x;
33                Real miny = vmin.y;
34                Real minz = vmin.z;
35               
36                // fill in the Vertex buffer: 12 lines with 2 endpoints each make up a box
37        HardwareVertexBufferSharedPtr vbuf =
38            mRenderOp.vertexData->vertexBufferBinding->getBuffer(POSITION_BINDING);     
39
40        float* pPos = static_cast<float*>(
41            vbuf->lock(HardwareBuffer::HBL_DISCARD));
42
43                //     5+------+7
44                //     /|     /|
45                //    / |    / |
46                //   / 1+---/--+3
47                // 2+------+6 /    y   z
48                //  | /    | /     |  /
49                //  |/     |/      |/
50                // 0+------+4      *---x
51
52                // fan 1
53                if(mIsFirstHalf)
54                {
55                        *pPos++ = minx; *pPos++ = maxy; *pPos++ = maxz; //011
56                        *pPos++ = minx; *pPos++ = miny; *pPos++ = maxz; //001
57                        *pPos++ = maxx; *pPos++ = miny; *pPos++ = maxz; //101
58                        *pPos++ = maxx; *pPos++ = maxy; *pPos++ = maxz; //111
59                       
60                        *pPos++ = maxx; *pPos++ = maxy; *pPos++ = minz; //110
61                        *pPos++ = minx; *pPos++ = maxy; *pPos++ = minz; //010
62                        *pPos++ = minx; *pPos++ = miny; *pPos++ = minz; //000
63                        *pPos++ = minx; *pPos++ = miny; *pPos++ = maxz; //001
64
65                }
66                else
67                // fan 2
68                {
69                        *pPos++ = maxx; *pPos++ = miny; *pPos++ = minz; //100
70                        *pPos++ = minx; *pPos++ = miny; *pPos++ = minz; //000                                   
71                        *pPos++ = minx; *pPos++ = maxy; *pPos++ = minz; //010
72                        *pPos++ = maxx; *pPos++ = maxy; *pPos++ = minz; //110
73
74                        *pPos++ = maxx; *pPos++ = maxy; *pPos++ = maxz; //111
75                        *pPos++ = maxx; *pPos++ = miny; *pPos++ = maxz; //101
76                        *pPos++ = minx; *pPos++ = miny; *pPos++ = maxz; //001
77                        *pPos++ = minx; *pPos++ = miny; *pPos++ = minz; //000
78                }
79
80        vbuf->unlock();
81        }
82
83        void SolidHalfBoundingBox::setupBoundingBox(const AxisAlignedBox& aabb)
84    {
85                // init the vertices to the aabb
86                SolidHalfBoundingBox::setupBoundingBoxVertices(aabb);
87
88        // setup the bounding box of this SimpleRenderable
89                setBoundingBox(aabb);
90        }
91        // Override this method to prevent parent transforms (rotation,translation,scale)
92    void SolidHalfBoundingBox::getWorldTransforms( Matrix4* xform ) const
93    {
94                // return identity matrix to prevent parent transforms
95        *xform = Matrix4::IDENTITY;
96    }
97}
98
Note: See TracBrowser for help on using the repository browser.