I am almost there!

I am able to feed OgreOpcode vertices and indices, and it happily detects collisions!

Proof:

Each terrain tile is being fed to OgreOpcode as separate models.

The *only* problem now is that the faces are degenerate, and refuses to render..

opcode.log wrote:OPCODE WARNING: found 1243316 degenerate faces in model! Collision might report wrong results!

<edit>

Please note that this is reported for each terrain tile (64 tiles in all) - I thought I would spare you the repetition.

</edit>

However, since the collisions are correctly reported, and since the OPCODE AABBs are OK, it is probably a small error in my code.

Here's the AABB boundingboxes from OPCODE:

And here's my code:

Code: Select all

```
void OgreOpcodeTerrainExample::pageConstructed(TerrainSceneManager* pSceneMgr, size_t pagex, size_t pagez, Real* heightData)
{
LogManager::getSingleton().logMessage("PageConstructed called.");
Vector3 Offset(0,0,0); // Set to something if required
Vector3 iScale(0,0,0);
int iPageSize(0);
int iTileSize(0);
iScale = static_cast<TerrainSceneManager*>(pSceneMgr)->getScale();
iPageSize = static_cast<TerrainSceneManager*>(pSceneMgr)->getPageSize();
iTileSize = static_cast<TerrainSceneManager*>(pSceneMgr)->getTileSize();
int heightDataNum = iTileSize * iTileSize;
int numIndexes = 0;
int index_size = iTileSize * iTileSize * 2 * 2 * 2;
int* indices = new int[index_size];
int nameCounter = 0;
// Create index data (Is this the same for each tile?)
for ( int j = 0; j < iTileSize-1; j++)
{
for ( int i = 0; i < iTileSize-1; i++ )
{
indices[numIndexes] = i + j * iTileSize; numIndexes++;
indices[numIndexes] = i + (j + 1) * iTileSize; numIndexes++;
indices[numIndexes] = (i + 1) + j * iTileSize; numIndexes++;
indices[numIndexes] = i + (j + 1) * iTileSize; numIndexes++;
indices[numIndexes] = (i + 1) + (j + 1) * iTileSize; numIndexes++;
indices[numIndexes] = (i + 1) + j * iTileSize; numIndexes++;
}
}
// Loop through all pages
for ( int startz = 0; startz < iPageSize - 1; startz += ( iTileSize - 1 ) )
{
for ( int startx = 0; startx < iPageSize - 1; startx += ( iTileSize - 1 ) )
{
float* OOData;
OOData = new float[heightDataNum*3];
int OODataCounter = 0;
// This should be a tile
for(int j = startz;j < (startz + iTileSize); j++)
{
for(int i = startx;i < (startx + iTileSize); i++)
{
Real height = heightData[j * iPageSize + i];
Vector3 Pt = Vector3((float) i * iScale.x, (float)height * iScale.y, (float)j * iScale.z);
// copy it over
OOData[OODataCounter + 0] = Pt.x;
OOData[OODataCounter + 1] = Pt.y;
OOData[OODataCounter + 2] = Pt.z;
OODataCounter += 3;
}
}
// create new shapes here!
PtrCollisionShape* tempTerrainShape;
CollisionObject* tempCollObject;
String shapeName = "terrainShape" + StringConverter::toString(nameCounter);
tempCollObject = mCollideContext->createObject(shapeName);
tempTerrainShape = CollisionManager::getSingletonPtr()->createPtrCollisionShape(shapeName);
tempTerrainShape->load(heightDataNum, index_size, OOData, indices);
tempCollObject->setCollClass("level");
tempCollObject->setShape(tempTerrainShape);
mCollideContext->addObject(tempCollObject);
nameCounter++;
}
}
// pass OOData to OgreOpcode..
//terrainShape->load(heightDataNum, index_size, OOData, indices);
//terrainCollObj->setShape(terrainShape);
//mCollideContext->addObject(terrainCollObj);
}
```

I try to mimick the way the Terrain SM works, but I am not sure what's supposed to go on with the

*step* variable in

*TerrainRenderable::generateTriListIndexes*:

This is the original index generating code:

Code: Select all

```
// Do the core vertices, minus stitches
for ( int j = north; j < mOptions->tileSize - 1 - south; j += step )
{
for ( int i = west; i < mOptions->tileSize - 1 - east; i += step )
{
//triangles
*pIdx++ = _index( i, j ); numIndexes++;
*pIdx++ = _index( i, j + step ); numIndexes++;
*pIdx++ = _index( i + step, j ); numIndexes++;
*pIdx++ = _index( i, j + step ); numIndexes++;
*pIdx++ = _index( i + step, j + step ); numIndexes++;
*pIdx++ = _index( i + step, j ); numIndexes++;
}
}
```

In my code I just replace the 'north', 'south', etc. with '0' and 'step' with '1'.

And I assume that the index data is the same for each terrain tile.

I think I need a couple hints more!