Main Page Namespace List Class Hierarchy Alphabetical List Compound List File List Namespace Members Compound Members File Members Related Pages

# OgreWireBoundingBox.cpp

Go to the documentation of this file.

    00001 /*
    00002 -----------------------------------------------------------------------------
    00003 This source file is part of OGRE
    00004     (Object-oriented Graphics Rendering Engine)
    00005 For the latest info, see http://www.ogre3d.org/
    00006
    00007 Copyright © 2000-2002 The OGRE Team
    00008 Also see acknowledgements in Readme.html
    00009
    00010 This program is free software; you can redistribute it and/or modify it under
    00011 the terms of the GNU Lesser General Public License as published by the Free Software
    00012 Foundation; either version 2 of the License, or (at your option) any later
    00013 version.
    00014
    00015 This program is distributed in the hope that it will be useful, but WITHOUT
    00016 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    00017 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
    00018
    00019 You should have received a copy of the GNU Lesser General Public License along with
    00020 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
    00021 Place - Suite 330, Boston, MA 02111-1307, USA, or go to
    00022 http://www.gnu.org/copyleft/lesser.txt.
    00023 -----------------------------------------------------------------------------
    00024 */
    00025 #include "OgreStableHeaders.h"
    00026 #include "OgreWireBoundingBox.h"
    00027
    00028 #include "OgreSimpleRenderable.h"
    00029 #include "OgreHardwareBufferManager.h"
    00030 #include "OgreCamera.h"
    00031
    00032 namespace Ogre {
    00033     #define POSITION_BINDING 0
    00034
    00035     WireBoundingBox::WireBoundingBox()
    00036     {
    00037         mRenderOp.vertexData = new VertexData();
    00038
    00039         mRenderOp.indexData = 0;
    00040         mRenderOp.vertexData->vertexCount = 24;
    00041         mRenderOp.vertexData->vertexStart = 0;
    00042         mRenderOp.operationType = RenderOperation::OT_LINE_LIST;
    00043         mRenderOp.useIndexes = false;
    00044
    00045         VertexDeclaration* decl = mRenderOp.vertexData->vertexDeclaration;
    00046         VertexBufferBinding* bind = mRenderOp.vertexData->vertexBufferBinding;
    00047
    00048         decl->addElement(POSITION_BINDING, 0, VET_FLOAT3, VES_POSITION);
    00049
    00050
    00051         HardwareVertexBufferSharedPtr vbuf =
    00052             HardwareBufferManager::getSingleton().createVertexBuffer(
    00053                 decl->getVertexSize(POSITION_BINDING),
    00054                 mRenderOp.vertexData->vertexCount,
    00055                 HardwareBuffer::HBU_STATIC_WRITE_ONLY);
    00056
    00057         // Bind buffer
    00058         bind->setBinding(POSITION_BINDING, vbuf);
    00059
    00060         // set basic white material
    00061         this->setMaterial("BaseWhiteNoLighting");
    00062
    00063
    00064
    00065     }
    00066
    00067     WireBoundingBox::~WireBoundingBox()
    00068     {
    00069         delete mRenderOp.vertexData;
    00070     }
    00071
    00072     void WireBoundingBox::setupBoundingBox(const AxisAlignedBox& aabb)
    00073     {
    00074         // init the vertices to the aabb
    00075         setupBoundingBoxVertices(aabb);
    00076
    00077         // setup the bounding box of this SimpleRenderable
    00078         setBoundingBox(aabb);
    00079
    00080     }
    00081
    00082     // Override this method to prevent parent transforms (rotation,translation,scale)
    00083     void WireBoundingBox::getWorldTransforms( Matrix4* xform ) const
    00084     {
    00085         // return identity matrix to prevent parent transforms
    00086         *xform = Matrix4::IDENTITY;
    00087     }
    00088     //-----------------------------------------------------------------------
    00089     const Quaternion& WireBoundingBox::getWorldOrientation(void) const
    00090     {
    00091         return Quaternion::IDENTITY;
    00092     }
    00093     //-----------------------------------------------------------------------
    00094     const Vector3& WireBoundingBox::getWorldPosition(void) const
    00095     {
    00096         return Vector3::ZERO;
    00097     }
    00098
    00099
    00100     void WireBoundingBox::setupBoundingBoxVertices(const AxisAlignedBox& aab) {
    00101
    00102         Vector3 vmax = aab.getMaximum();
    00103         Vector3 vmin = aab.getMinimum();
    00104
    00105         Real sqLen = std::max(vmax.squaredLength(), vmin.squaredLength());
    00106         mRadius = Math::Sqrt(sqLen);
    00107
    00108
    00109
    00110
    00111         Real maxx = vmax.x;
    00112         Real maxy = vmax.y;
    00113         Real maxz = vmax.z;
    00114
    00115         Real minx = vmin.x;
    00116         Real miny = vmin.y;
    00117         Real minz = vmin.z;
    00118
    00119         // fill in the Vertex buffer: 12 lines with 2 endpoints each make up a box
    00120         HardwareVertexBufferSharedPtr vbuf =
    00121             mRenderOp.vertexData->vertexBufferBinding->getBuffer(POSITION_BINDING);
    00122
    00123         Real* pPos = static_cast<Real*>(
    00124             vbuf->lock(HardwareBuffer::HBL_DISCARD));
    00125
    00126         // line 0
    00127         *pPos++ = minx;
    00128         *pPos++ = miny;
    00129         *pPos++ = minz;
    00130         *pPos++ = maxx;
    00131         *pPos++ = miny;
    00132         *pPos++ = minz;
    00133         // line 1
    00134         *pPos++ = minx;
    00135         *pPos++ = miny;
    00136         *pPos++ = minz;
    00137         *pPos++ = minx;
    00138         *pPos++ = miny;
    00139         *pPos++ = maxz;
    00140         // line 2
    00141         *pPos++ = minx;
    00142         *pPos++ = miny;
    00143         *pPos++ = minz;
    00144         *pPos++ = minx;
    00145         *pPos++ = maxy;
    00146         *pPos++ = minz;
    00147         // line 3
    00148         *pPos++ = minx;
    00149         *pPos++ = maxy;
    00150         *pPos++ = minz;
    00151         *pPos++ = minx;
    00152         *pPos++ = maxy;
    00153         *pPos++ = maxz;
    00154         // line 4
    00155         *pPos++ = minx;
    00156         *pPos++ = maxy;
    00157         *pPos++ = minz;
    00158         *pPos++ = maxx;
    00159         *pPos++ = maxy;
    00160         *pPos++ = minz;
    00161         // line 5
    00162         *pPos++ = maxx;
    00163         *pPos++ = miny;
    00164         *pPos++ = minz;
    00165         *pPos++ = maxx;
    00166         *pPos++ = miny;
    00167         *pPos++ = maxz;
    00168         // line 6
    00169         *pPos++ = maxx;
    00170         *pPos++ = miny;
    00171         *pPos++ = minz;
    00172         *pPos++ = maxx;
    00173         *pPos++ = maxy;
    00174         *pPos++ = minz;
    00175         // line 7
    00176         *pPos++ = minx;
    00177         *pPos++ = maxy;
    00178         *pPos++ = maxz;
    00179         *pPos++ = maxx;
    00180         *pPos++ = maxy;
    00181         *pPos++ = maxz;
    00182         // line 8
    00183         *pPos++ = minx;
    00184         *pPos++ = maxy;
    00185         *pPos++ = maxz;
    00186         *pPos++ = minx;
    00187         *pPos++ = miny;
    00188         *pPos++ = maxz;
    00189         // line 9
    00190         *pPos++ = maxx;
    00191         *pPos++ = maxy;
    00192         *pPos++ = minz;
    00193         *pPos++ = maxx;
    00194         *pPos++ = maxy;
    00195         *pPos++ = maxz;
    00196         // line 10
    00197         *pPos++ = maxx;
    00198         *pPos++ = miny;
    00199         *pPos++ = maxz;
    00200         *pPos++ = maxx;
    00201         *pPos++ = maxy;
    00202         *pPos++ = maxz;
    00203         // line 11
    00204         *pPos++ = minx;
    00205         *pPos++ = miny;
    00206         *pPos++ = maxz;
    00207         *pPos++ = maxx;
    00208         *pPos++ = miny;
    00209         *pPos++ = maxz;
    00210         vbuf->unlock();
    00211     }
    00212
    00213
    00214     Real WireBoundingBox::getSquaredViewDepth(const Camera* cam) const
    00215     {
    00216         Vector3 min, max, mid, dist;
    00217         min = mBox.getMinimum();
    00218         max = mBox.getMaximum();
    00219         mid = ((min - max) * 0.5) + min;
    00220         dist = cam->getDerivedPosition() - mid;
    00221
    00222
    00223         return dist.squaredLength();
    00224     }
    00225
    00226
    00227
    00228 }
    00229

Copyright © 2002-2003 by The OGRE Team
Last modified Sun Nov 28 19:48:52 2004