/* ----------------------------------------------------------------------------- This source file is part of OGRE (Object-oriented Graphics Rendering Engine) For the latest info, see http://www.ogre3d.org/ Copyright (c) 2000-2006 Torus Knot Software Ltd Also see acknowledgements in Readme.html You may use this sample code for anything you like, it is not covered by the LGPL like the rest of the engine. ----------------------------------------------------------------------------- */ #include "ThingRenderable.h" #include #include #include #include using namespace Ogre; ThingRenderable::ThingRenderable(float radius, size_t count, float qsize): mRadius(radius), mCount(count), mQSize(qsize) { mBox = Ogre::AxisAlignedBox(-radius, -radius, -radius, radius, radius, radius); initialise(); fillBuffer(); } ThingRenderable::~ThingRenderable() { // need to release IndexData and vertexData created for renderable delete mRenderOp.indexData; delete mRenderOp.vertexData; } void ThingRenderable::addTime(float t) { for(size_t x=0; xvertexStart = 0; vdata->vertexCount = nvertices; VertexDeclaration* decl = vdata->vertexDeclaration; VertexBufferBinding* bind = vdata->vertexBufferBinding; size_t offset = 0; decl->addElement(0, offset, VET_FLOAT3, VES_POSITION); offset += VertexElement::getTypeSize(VET_FLOAT3); vbuf = HardwareBufferManager::getSingleton().createVertexBuffer( offset, nvertices, HardwareBuffer::HBU_DYNAMIC_WRITE_ONLY); bind->setBinding(0, vbuf); //vbuf->writeData(0, vbuf->getSizeInBytes(), vertices, true); HardwareIndexBufferSharedPtr ibuf = HardwareBufferManager::getSingleton(). createIndexBuffer( HardwareIndexBuffer::IT_16BIT, mCount*6, HardwareBuffer::HBU_STATIC_WRITE_ONLY); idata->indexBuffer = ibuf; idata->indexCount = mCount*6; idata->indexStart = 0; ibuf->writeData(0, ibuf->getSizeInBytes(), faces, true); // Delete temporary buffers delete [] faces; // Now make the render operation mRenderOp.operationType = Ogre::RenderOperation::OT_TRIANGLE_LIST; mRenderOp.indexData = idata; mRenderOp.vertexData = vdata; mRenderOp.useIndexes = true; } void ThingRenderable::fillBuffer() { // Transfer vertices and normals float *vIdx = static_cast(vbuf->lock(Ogre::HardwareBuffer::HBL_DISCARD)); size_t elemsize = 1*3; // position only size_t planesize = 4*elemsize; // four vertices per plane for(size_t x=0; xunlock(); } Ogre::Real ThingRenderable::getBoundingRadius() const { return mRadius; } Ogre::Real ThingRenderable::getSquaredViewDepth(const Ogre::Camera* cam) const { Ogre::Vector3 min, max, mid, dist; min = mBox.getMinimum(); max = mBox.getMaximum(); mid = ((min - max) * 0.5) + min; dist = cam->getDerivedPosition() - mid; return dist.squaredLength(); }