I'm hoping you can spot my nub mistake with tiling. I have made a function called
setupTerrainCollisionObject which is meant to imitate the TerrainCollisionShape constructor. It allows for user defined number of x and z tiles used for collision parts. (must be power of 2)
I am using a Manual Object to verify that I am getting the vertices correctly. Setting z tiling seems to work fine (1/2/4/8), but when I specify x tiling for more than 1, I get line artifacts. Oddly enough, I am only plotting points, so lines should not be possible!
Here is xTiling = 1, zTiling = 2 (Only top half of terrain is represented):
Here is xTiling = 2, zTiling = 1 (Only left half of terrain is represented):
Here is the beginning of the function:
Code: Select all
void setupTerrainCollisionObject(const std::vector<float>& HeightmapData, size_t Width, size_t Depth, Ogre::Vector3 Offset, Ogre::Vector3 Scale, unsigned int numTilesX = 2, unsigned int numTilesZ = 1)
{
// enforcing number of x and z tiles to be greater than zero, and also a power of 2: 2, 4, 8, 16, etc.
if( !powerOf2(numTilesX) || (numTilesX == 0) ) return;
if( !powerOf2(numTilesZ) || (numTilesZ == 0) ) return;
// TerrainShape constructor would init these values
mHeightmapData = &HeightmapData;
mWidth = Width;
mDepth = Depth;
mOffset = Offset;
mScale = Scale;
// calculate the number of vertices for each tile,
// for both x direction (in 3d space) verts, and z direction (in 3d space) verts
int xTileSize = ((mWidth - 1) / numTilesX) + 1;
int zTileSize = ((mDepth - 1) / numTilesZ) + 1;
And here is the Tiling code:
Code: Select all
// Loop through all tiles
for ( unsigned int startz = 0; startz < numTilesZ; startz += ( zTileSize - 1 ) )
{
for ( unsigned int startx = 0; startx < numTilesX; startx += ( xTileSize - 1 ) )
{
float* OOData;
int numVertsPerTile = xTileSize * zTileSize;
OOData = new float[numVertsPerTile * 3];
int OODataCounter = 0;
Ogre::ManualObject* mo = new Ogre::ManualObject("tile" + Ogre::StringConverter::toString(tileCounter++));
mo->begin("BaseWhiteNoLighting", Ogre::RenderOperation::OT_TRIANGLE_LIST);
// This should be a tile
for( unsigned int j = startz; j < (startz + zTileSize); j++)
{
for( unsigned int i = startx; i < (startx + xTileSize); i++)
{
Ogre::Vector3 v3(
mOffset.x + (i * mScale.x),
mOffset.y + (at(i,j) * mScale.y),
mOffset.z + (j * mScale.z)
);
OOData[OODataCounter + 0] = v3.x;
OOData[OODataCounter + 1] = v3.y;
OOData[OODataCounter + 2] = v3.z;
OODataCounter += 3;
mo->position(v3);
}
}
mo->end();
mSceneManager->getRootSceneNode()->attachObject(mo);
delete[] OOData;
OOData = 0;
}
break;
}
The break I added in is just to test one Tile. If more than one tile was loaded at 0,0,0 I wouldn't be able to tell tiles apart.
I am hoping I made some dumb obvious mistake. I don't see why lines should be appearing at all. And it only appears with xTiling > 1.
Thanks for any help,
KungFooMasta