Code Explain

Max2

03-06-2006 18:35:19

Hi I don't know if I should write here, but I don't understand how this piece of code works


if ( use32bitindexes ) {

unsigned int* pInt = static_cast<unsigned int*>(ibuf->lock(Ogre::HardwareBuffer::HBL_READ_ONLY));

size_t offset = (submesh->useSharedVertices)? shared_offset : current_offset;


for ( size_t k = 0; k < numTris*3; ++k) {
mMeshFaces[index_offset] = pInt[k] + static_cast<unsigned int>(offset);
//mMaterials[index_offset++] = currentMaterialIndex;
}
}
else {
unsigned short* pShort = reinterpret_cast<unsigned short*>(ibuf->lock(Ogre::HardwareBuffer::HBL_READ_ONLY));
size_t offset = (submesh->useSharedVertices)? shared_offset : current_offset;

for ( size_t k = 0; k < numTris*3; ++k) {
mMeshFaces[index_offset] = static_cast<unsigned int>(pShort[k]) + static_cast<unsigned int>(offset);
//mMaterials[index_offset++] = currentMaterialIndex;

}

}


what I don't understand is

unsigned int* pInt = static_cast<unsigned int*>(ibuf->lock(Ogre::HardwareBuffer::HBL_READ_ONLY));

and than u use

mMeshFaces[index_offset] = pInt[k] + static_cast<unsigned int>(offset);


but from the API the lock function should return void, so how can u use pInt to get data from the buffer ?
pInt[k] ??? what is it ?? and
Pint[k] + offset... so u copy to the MeshFaces the indexes of the ibuf like u were using
readData (size_t offset, size_t length, void *pDest)

did I get ir right ??

sorry for the stupid question but I don't get it.

betajaen

03-06-2006 19:03:14

It's been a long time since I've been near that code, it's all from the Wiki and posts from the forums, except my addition of the material bits.

May I ask why you looking at it? It just seems a little odd to me ;)

Max2

03-06-2006 20:08:01

I'm just tring to make a cooking routine to save and speed up physics mesh loading.
It crash when it comes to cook the indexes.... :(

I wil live a look at the wiki and in the forum if I can find something tx anyway :P!

ciao

betajaen

03-06-2006 20:15:43

Ahhh, I understand now. Although surely the meshShape is fast, assuming you're using NxOgre?