#include "OgreStableHeaders.h" #include "OgreSolidHalfBoundingBox.h" #include "OgreSimpleRenderable.h" #include "OgreHardwareBufferManager.h" #include "OgreCamera.h" //#include namespace Ogre { #define POSITION_BINDING 0 //----------------------------------------------------------------------- SolidHalfBoundingBox::SolidHalfBoundingBox(bool isFirstHalf) :WireBoundingBox(), mIsFirstHalf(isFirstHalf) { mRenderOp.vertexData->vertexCount = 8; mRenderOp.operationType = RenderOperation::OT_TRIANGLE_FAN; } //----------------------------------------------------------------------- void SolidHalfBoundingBox::setupBoundingBoxVertices(const AxisAlignedBox& aab) { Vector3 vmax = aab.getMaximum(); Vector3 vmin = aab.getMinimum(); Real sqLen = std::max(vmax.squaredLength(), vmin.squaredLength()); mRadius = Math::Sqrt(sqLen); Real maxx = vmax.x; Real maxy = vmax.y; Real maxz = vmax.z; Real minx = vmin.x; Real miny = vmin.y; Real minz = vmin.z; // fill in the Vertex buffer: 12 lines with 2 endpoints each make up a box HardwareVertexBufferSharedPtr vbuf = mRenderOp.vertexData->vertexBufferBinding->getBuffer(POSITION_BINDING); float* pPos = static_cast( vbuf->lock(HardwareBuffer::HBL_DISCARD)); // 5+------+7 // /| /| // / | / | // / 1+---/--+3 // 2+------+6 / y z // | / | / | / // |/ |/ |/ // 0+------+4 *---x // fan 1 if(mIsFirstHalf) { *pPos++ = minx; *pPos++ = maxy; *pPos++ = maxz; //011 *pPos++ = minx; *pPos++ = miny; *pPos++ = maxz; //001 *pPos++ = maxx; *pPos++ = miny; *pPos++ = maxz; //101 *pPos++ = maxx; *pPos++ = maxy; *pPos++ = maxz; //111 *pPos++ = maxx; *pPos++ = maxy; *pPos++ = minz; //110 *pPos++ = minx; *pPos++ = maxy; *pPos++ = minz; //010 *pPos++ = minx; *pPos++ = miny; *pPos++ = minz; //000 *pPos++ = minx; *pPos++ = miny; *pPos++ = maxz; //001 } else // fan 2 { *pPos++ = maxx; *pPos++ = miny; *pPos++ = minz; //100 *pPos++ = minx; *pPos++ = miny; *pPos++ = minz; //000 *pPos++ = minx; *pPos++ = maxy; *pPos++ = minz; //010 *pPos++ = maxx; *pPos++ = maxy; *pPos++ = minz; //110 *pPos++ = maxx; *pPos++ = maxy; *pPos++ = maxz; //111 *pPos++ = maxx; *pPos++ = miny; *pPos++ = maxz; //101 *pPos++ = minx; *pPos++ = miny; *pPos++ = maxz; //001 *pPos++ = minx; *pPos++ = miny; *pPos++ = minz; //000 } vbuf->unlock(); } void SolidHalfBoundingBox::setupBoundingBox(const AxisAlignedBox& aabb) { // init the vertices to the aabb SolidHalfBoundingBox::setupBoundingBoxVertices(aabb); // setup the bounding box of this SimpleRenderable setBoundingBox(aabb); } // Override this method to prevent parent transforms (rotation,translation,scale) void SolidHalfBoundingBox::getWorldTransforms( Matrix4* xform ) const { // return identity matrix to prevent parent transforms *xform = Matrix4::IDENTITY; } }