source: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreSolidHalfBoundingBox.cpp @ 1146

Revision 1146, 3.4 KB checked in by mattausch, 18 years ago (diff)

use qt renderer as dll
changed vsp render heuristics sweep
capsulated thread

RevLine 
[59]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
[103]9
[59]10namespace Ogre {
11
12#define POSITION_BINDING 0
13//-----------------------------------------------------------------------
[85]14SolidHalfBoundingBox::SolidHalfBoundingBox()
[59]15{
[85]16        SetOcclusionQueryMaterial();
[59]17       
18        mRenderOp.vertexData->vertexCount = 8;
19    mRenderOp.operationType = RenderOperation::OT_TRIANGLE_FAN;
20}
21//-----------------------------------------------------------------------
[85]22void SolidHalfBoundingBox::SetupBoundingBoxVertices(const AxisAlignedBox& aab,
23                                                                                                        const bool isFirstHalf)
24{
[91]25        const Vector3& min = aab.getMinimum();
26    const Vector3& max = aab.getMaximum();
27
[85]28        // fill the vertex buffer: 12 lines with 2 endpoints each make up a box
[59]29    HardwareVertexBufferSharedPtr vbuf =
30        mRenderOp.vertexData->vertexBufferBinding->getBuffer(POSITION_BINDING);     
31
[91]32    float* pPos = static_cast<float*>(vbuf->lock(HardwareBuffer::HBL_DISCARD));
[59]33
34        //     5+------+7
35        //     /|     /|
36        //    / |    / |
37        //   / 1+---/--+3
38        // 2+------+6 /    y   z
39        //  | /    | /     |  /
40        //  |/     |/      |/
41        // 0+------+4      *---x
42
[1146]43       
44        if (isFirstHalf) // fan 1
[59]45        {
[91]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
[59]50               
[91]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
[59]55        }
[1146]56        else // fan 2
[59]57        {
[91]58                *pPos++ = max.x; *pPos++ = min.y; *pPos++ = min.z; //100
59                *pPos++ = min.x; *pPos++ = min.y; *pPos++ = min.z; //000                                       
60                *pPos++ = min.x; *pPos++ = max.y; *pPos++ = min.z; //010
61                *pPos++ = max.x; *pPos++ = max.y; *pPos++ = min.z; //110
[59]62
[91]63                *pPos++ = max.x; *pPos++ = max.y; *pPos++ = max.z; //111
64                *pPos++ = max.x; *pPos++ = min.y; *pPos++ = max.z; //101
65                *pPos++ = min.x; *pPos++ = min.y; *pPos++ = max.z; //001
66                *pPos++ = min.x; *pPos++ = min.y; *pPos++ = min.z; //000
[59]67        }
68
69    vbuf->unlock();
70}
[85]71//-----------------------------------------------------------------------
[91]72void SolidHalfBoundingBox::SetupBoundingBox(const AxisAlignedBox& aab,
[85]73                                                                                        const bool isFirstHalf)
[59]74{
75        // init the vertices to the aabb
[91]76        SetupBoundingBoxVertices(aab, isFirstHalf);
[59]77
[91]78        Real sqLen = std::max(aab.getMaximum().squaredLength(),
79                                                  aab.getMinimum().squaredLength());
80    mRadius = Math::Sqrt(sqLen);
81
[59]82    // setup the bounding box of this SimpleRenderable
[91]83        setBoundingBox(aab);
[59]84}
[85]85//-----------------------------------------------------------------------
86void SolidHalfBoundingBox::SetOcclusionQueryMaterial( void )
[59]87{
[117]88        m_pMaterial = MaterialManager::getSingleton().getByName("Visibility/QueryMaterial");
[59]89
[100]90        if (m_pMaterial.isNull())
[59]91        {
92                m_pMaterial = MaterialManager::getSingleton().
[117]93                        create("Visibility/QueryMaterial", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
[59]94        }
95
96        m_pMaterial->setColourWriteEnabled(false);
97        m_pMaterial->setDepthWriteEnabled(false);
98        m_pMaterial->setLightingEnabled(false);
99
[117]100        setMaterial("Visibility/QueryMaterial");
[59]101}
102
103} // namespace Ogre
104
Note: See TracBrowser for help on using the repository browser.