The add frustum pass projection texture have some weak point:
1.Increase Triangle count(Multi Pass)
2.maybe project over two
I use unique triangle base to project the texture, it's can solve these problem,
it's weak point:
1.Need to do Dynamic collision(AABB with Triangles).(maybe bullet btBvhTriangleMeshShape processAllTriangles is the best solution)
2.lock vertex buffer and texture coordinate buffer.
how to do:
1.Do collide process to get the intersect triangles.
2.Lock and fill vertex buffer.
3.lock and fill Recalculate UV to texture coordinate buffer.
the Recalculate UV formula is here:
TranslateMatrix*ScaleMatrix*RotMatrix*DestUV;
the sample code is here:
Code: Select all
bool FillHardwareBuffers(const std::vector<Ogre::Real>& NewVertexBuffer)
{
if(!NewVertexBuffer.size())
return false;
Ogre::HardwareVertexBufferSharedPtr spVertexBuffer = mRenderOp.vertexData->vertexBufferBinding->getBuffer(VERTEX_DECLARATION_POSITION);
Ogre::Real* pRealPos = static_cast<Ogre::Real*>(spVertexBuffer->lock(Ogre::HardwareBuffer::HBL_DISCARD));
if(pRealPos)
{
memcpy(pRealPos, &(NewVertexBuffer)[0], mRenderOp.vertexData->vertexCount*3*sizeof(Ogre::Real));
spVertexBuffer->unlock();
}
Ogre::HardwareVertexBufferSharedPtr spTexcoordsVertexBuffer = mRenderOp.vertexData->vertexBufferBinding->getBuffer(
VERTEX_DECLARATION_TEXTURE_COORDINATES);
Ogre::Real* pRealUV = static_cast<Ogre::Real*>(spTexcoordsVertexBuffer->lock(Ogre::HardwareBuffer::HBL_DISCARD));
if(pRealUV)
{
Ogre::Matrix4 RotMat = Ogre::Matrix4::IDENTITY;
RotMat.makeTransform(Ogre::Vector3::ZERO, Ogre::Vector3::UNIT_SCALE,
Ogre::Quaternion(Ogre::Degree(-90.0f), Ogre::Vector3::UNIT_X));
Ogre::Matrix4 TransMat = Ogre::Matrix4::IDENTITY;
TransMat.setTrans(Ogre::Vector3(0.5f, 0.5f, 0.0f));
Ogre::Vector3 Size = mBox.getHalfSize();
Ogre::Vector3 ScaleFactor;
ScaleFactor.x = -0.5f / Size.x;
ScaleFactor.y = -0.5f / Size.z;
ScaleFactor.z = 1.0f /(1000.0f+10.0f);
Ogre::Matrix4 ScaleMat = Ogre::Matrix4::IDENTITY;
ScaleMat.setScale(ScaleFactor);
std::vector<Ogre::Real>::const_iterator it = NewVertexBuffer.begin();
Ogre::Vector3 DestUVW;
while(it != NewVertexBuffer.end())
{
DestUVW.x = (*it);
DestUVW.y = (*(it+1));
DestUVW.z = (*(it+2));
DestUVW = TransMat*ScaleMat*RotMat*DestUVW;
*pRealUV++ = DestUVW.x;
*pRealUV++ = DestUVW.y;
it += 3;
}
spTexcoordsVertexBuffer->unlock();
}
return true;
}
welcome to my blogger, thanks.

http://makedreamvsogre.blogspot.com/