Oops Terrain Collision- CellWidth and CellDepth

Feb 2, 2008 at 3:41 AM
Hi,

I have been trying to use the Oops Terrain for collision, and can't seem to get it to work...yet :-P

I have resolved the terrain vertex winding as you have suggested. It looks like this now
  terrainIndices[(x + y * (WIDTH - 1)) * 6 + 0] = x + y * WIDTH;
                    terrainIndices[(x + y * (WIDTH - 1)) * 6 + 1] = (x + 1) + y * WIDTH;
                    terrainIndices[(x + y * (WIDTH - 1)) * 6 + 2] = x + (y + 1) * WIDTH;
 
                    terrainIndices[(x + y * (WIDTH - 1)) * 6 + 3] = x + (y + 1) * WIDTH;
                    terrainIndices[(x + y * (WIDTH - 1)) * 6 + 4] = (x + 1) + y * WIDTH;
                    terrainIndices[(x + y * (WIDTH - 1)) * 6 + 5] = (x + 1) + (y + 1) * WIDTH;

It seems to be working; however, collision is still wrong. I have been looking at your previous post where you suggest that
CollisionTerrain t = new CollisionTerrain(terrainScale, terrainScale, terrainScale, this);

However, as I am using 1.0f as my scale, and when I pass that in, the program bombed with at this part
// Create empty items.
				for (int i = 0; i < this.heightBuffer.Length; i++)
				{
					this.heightBuffer[i] = new TerrainVertex[zCount];
					for (int j = 0; j < this.heightBuffer[i].Length; j++)
					{
						this.heightBuffer[i][j] = new TerrainVertex();
					}
				}

Checking the debugger, it seems that zCount somehow has a value of -9.

What should be the proper values I pass in CellWidth and CellDepth? I made a mistake the last time by passing in the entire height and width of the terrain :-P
Coordinator
Feb 2, 2008 at 10:43 PM
Hi,

The changes to the vertex winding look correct.

The cellWidth and cellDepth parameters of the CollisionTerrain constructor represent the size of one square (two triangles) on the terrain, while the scale parameter is applied to the sample height of your heightData to increase or decrease the magnitude of height change.

A CellWidth and CellDepth of 1.0f are valid values but really need to match up with how far apart you are making the vertices of your terrain mesh. It looks like you are using the value stored in terrainScale to represent your cell size. I think you need to use this value for the cellWidth and cellDepth parameters of the CollisionTerrain constructor.

If you want and are still having issues, you can contact me here - http://www.codeplex.com/UserAccount/UserProfile.aspx?UserName=FretboardOfFury - and I'll respond so you can attach some code. I'll be glad to look over anything you send me and see if I can find any issues.

FYI - I am current working on an update to the framework that fixes a few issues with the collision terrain functionality, but I don't believe you are running into these yet.