Monday, March 12, 2007

Terrain

(History blog)
My first step was to create a terrain engine. I needed a method that would work well with the NiGHTS terrain I had, a method that would be fast to render, a method that would work as a general level partitioning system, and a method that would be easy for a beginner to implement (most important ;)). I chose to use a method simular to that which the sonic team used, which I discovered while hacking NiGHTS. A grid of grids (I will call the smaller grids nodes).

Clarity note:Sega saturn uses a quad rendering system, and each quad(2 polygons) has a texture that covers the entire quad. It is basicaly a 3d tile system(as you can see from the texturemaps in my last blog).

Each terrain node consists of 8 by 8 tiles. A terrain grid consists of x by y nodes. My rendering system uses this grid as the level partitioning grid, so not only does each grid hold a node, but it also holds a list of placeable objects within that node, event objects, and anything else that has a position. The culling system culls these 8x8 nodes, and the hittesting tests only within an active node. So, using this method I had culling, collision, object rendering, and position-based event triggering all ready to be implemented with minimal complexity.

Basic Structure of Terrain:

struct TERRAIN_NODE
{
public VertexBuffer vb;//vertex holds position texture and normal
public float[] Heights;//8x8 heights used for terrain collision testing
public float BSphere;//bounding sphere radius, used for culling
public vector3[] BBox;//bounding box,used for more accurate culling
//after this comes any other systems that are stored per node
//example
public PLACEABLES Placeables;
public VEGITATION Vegitation;
}
struct TERRAIN_GRID
{
public int Width;//map withd
public int Height;
public int ActiveNode;//index of node used for collisions
public TERRAIN_NODE[] Grid;
public IndexBuffer ib;//index buffer used to render a node
public Texture2D texture;//terrain texture (this would be the tiled texture from my first blog)
}

During the process of developing the terrain engine, I learned alot about XNA, C#, and .NET in general. Though I took a very C approach and kept to structs, linked lists via preallocated arrays of a fixed size, and files full of simular public functions. (not much oop to be found)

No comments: