source: trunk/VUT/OcclusionCullingSceneManager/src/OgreSolidBoundingBox.cpp @ 25

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