I'm using OgreOpcode in my game, and currently considering if I should try and use the OgreOpcode TerrainShape class for ground collisions, or if I should mesh together ray casts with OgreOpcode sliding on other objects.
Looking at the OgreOpcode demo, it adds itself as a TerrainPageSource listener, and constructs a shape/collision object whenever the pageConstructed method is called.
Does ETSM use the TerrainPageSource class? I see it listed in OgreTerrainPrerequisites, but nowhere else.
Here is the code from the OgreOpcode example:
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) * 6;
int nameCounter = 0;
//Create indices
int* indices = new int[index_size];
for (int x=0;x<iTileSize-1;x++)
{
for (int y=0; y<iTileSize-1;y++)
{
indices[(x+y*(iTileSize-1))*6] = (x+1)+(y+1)*iTileSize;
indices[(x+y*(iTileSize-1))*6+1] = (x+1)+y*iTileSize;
indices[(x+y*(iTileSize-1))*6+2] = x+y*iTileSize;
indices[(x+y*(iTileSize-1))*6+3] = (x+1)+(y+1)*iTileSize;
indices[(x+y*(iTileSize-1))*6+4] = x+y*iTileSize;
indices[(x+y*(iTileSize-1))*6+5] = x+(y+1)*iTileSize;
}
}
// Loop through all pages
for ( int startz = 0; startz < iPageSize - 1; startz += ( iTileSize - 1 ) )
{
for ( int startx = 0; startx < iPageSize - 1; startx += ( iTileSize - 1 ) )
{
//int startx = 0;
//int startz = 0;
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*3, index_size, OOData, indices);
tempCollObject->setCollClass("level");
tempCollObject->setShape(tempTerrainShape);
mCollideContext->addObject(tempCollObject);
nameCounter++;
delete[] OOData;
OOData = 0;
}
}
delete[] indices;
indices = 0;
}
I believe the tileSize in the code would be the same as ETOptions::tileSize, but what is the equivalent for PageSize?
Does the function above look like it can be modified to work with ETSM?
If I register a class as a TerrainPageSource listeneter:
TerrainPageSource::addListener(this);
Will the class be called for every page that is created?
Thanks for any information/help.
KungFooMasta