2 -----------------------------------------------------------------------------
3 This source file is part of OGRE
4 (Object-oriented Graphics Rendering Engine)
5 For the latest info, see http://www.ogre3d.org/
7 Copyright (c) 2000-2006 Torus Knot Software Ltd
8 Also see acknowledgements in Readme.html
10 This program is free software; you can redistribute it and/or modify it under
11 the terms of the GNU Lesser General Public License as published by the Free Software
12 Foundation; either version 2 of the License, or (at your option) any later
15 This program is distributed in the hope that it will be useful, but WITHOUT
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
19 You should have received a copy of the GNU Lesser General Public License along with
20 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21 Place - Suite 330, Boston, MA 02111-1307, USA, or go to
22 http://www.gnu.org/copyleft/lesser.txt.
24 You may alternatively use this source under the terms of a specific version of
25 the OGRE Unrestricted License provided you have obtained such a license from
26 Torus Knot Software Ltd.
27 -----------------------------------------------------------------------------
29 #include "OgreStableHeaders.h"
30 #include "OgreWireBoundingBox.h"
32 #include "OgreSimpleRenderable.h"
33 #include "OgreHardwareBufferManager.h"
34 #include "OgreCamera.h"
37 #define POSITION_BINDING 0
39 WireBoundingBox::WireBoundingBox()
41 mRenderOp
.vertexData
= OGRE_NEW
VertexData();
43 mRenderOp
.indexData
= 0;
44 mRenderOp
.vertexData
->vertexCount
= 24;
45 mRenderOp
.vertexData
->vertexStart
= 0;
46 mRenderOp
.operationType
= RenderOperation::OT_LINE_LIST
;
47 mRenderOp
.useIndexes
= false;
49 VertexDeclaration
* decl
= mRenderOp
.vertexData
->vertexDeclaration
;
50 VertexBufferBinding
* bind
= mRenderOp
.vertexData
->vertexBufferBinding
;
52 decl
->addElement(POSITION_BINDING
, 0, VET_FLOAT3
, VES_POSITION
);
55 HardwareVertexBufferSharedPtr vbuf
=
56 HardwareBufferManager::getSingleton().createVertexBuffer(
57 decl
->getVertexSize(POSITION_BINDING
),
58 mRenderOp
.vertexData
->vertexCount
,
59 HardwareBuffer::HBU_STATIC_WRITE_ONLY
);
62 bind
->setBinding(POSITION_BINDING
, vbuf
);
64 // set basic white material
65 this->setMaterial("BaseWhiteNoLighting");
71 WireBoundingBox::~WireBoundingBox()
73 OGRE_DELETE mRenderOp
.vertexData
;
76 void WireBoundingBox::setupBoundingBox(const AxisAlignedBox
& aabb
)
78 // init the vertices to the aabb
79 setupBoundingBoxVertices(aabb
);
81 // setup the bounding box of this SimpleRenderable
86 // Override this method to prevent parent transforms (rotation,translation,scale)
87 void WireBoundingBox::getWorldTransforms( Matrix4
* xform
) const
89 // return identity matrix to prevent parent transforms
90 *xform
= Matrix4::IDENTITY
;
92 //-----------------------------------------------------------------------
93 void WireBoundingBox::setupBoundingBoxVertices(const AxisAlignedBox
& aab
) {
95 Vector3 vmax
= aab
.getMaximum();
96 Vector3 vmin
= aab
.getMinimum();
98 Real sqLen
= std::max(vmax
.squaredLength(), vmin
.squaredLength());
99 mRadius
= Math::Sqrt(sqLen
);
112 // fill in the Vertex buffer: 12 lines with 2 endpoints each make up a box
113 HardwareVertexBufferSharedPtr vbuf
=
114 mRenderOp
.vertexData
->vertexBufferBinding
->getBuffer(POSITION_BINDING
);
116 float* pPos
= static_cast<float*>(
117 vbuf
->lock(HardwareBuffer::HBL_DISCARD
));
206 //-----------------------------------------------------------------------
207 Real
WireBoundingBox::getSquaredViewDepth(const Camera
* cam
) const
209 Vector3 min
, max
, mid
, dist
;
210 min
= mBox
.getMinimum();
211 max
= mBox
.getMaximum();
212 mid
= ((max
- min
) * 0.5) + min
;
213 dist
= cam
->getDerivedPosition() - mid
;
216 return dist
.squaredLength();