   Suggestions Needed (Collision Detection and Terrain)
  Hello All,   I need some suggestions on how to handle a problemBackground:I am using C# and Directx9, I am also using my own GameEngine.Problem:I am making a game where you control a ball and you are attempting to capture a resource (similar to Marble Madness I guess). The problem comes with Im not sure the best way to deal with the terrain.  What I would like to do is use a heightmap plus textures, but I'm not sure how I would handle collision detection plus gravity with the ball.Can anyone offer some resources or some hints on how I should approach this.  Thanks!   
  the best approach to generating a terrian is using height maps , if your not sure about the implementation details check the samples at www.moon-labs.com , frank luna implemented a similar algorithm.since your using a ball , a neat methodto calcualte collision detection is using bounding spheres. try googling "collision detection by using bounding spheres".gravity is best seen as a constant force acting down , the standard constant of the accelration it providesranges between 9.8-10. if your confused by a certian element of gravity ,please illustrate.   ;  Okay, so I found a function to read in my .raw file but its not coming out as expected, can anyone see anything wrong with me code?private void LoadTerrain()   {  heightData = new int[WIDTH, HEIGHT];  FileStream fs = new FileStream("heightdata.raw", FileMode.Open, FileAccess.Read);  BinaryReader r = new BinaryReader(fs);  for (int i = 0; i < HEIGHT; i++)  { for (int y = 0; y < WIDTH; y++) {int height = (int)(r.ReadByte());heightData[WIDTH - 1 - y, HEIGHT - 1 - i] = height; }  }  r.Close();  vb = new VertexBuffer(typeof(CustomVertex.PositionColored), WIDTH * HEIGHT, device, Usage.Dynamic | Usage.WriteOnly, CustomVertex.PositionColored.Format, Pool.Default);  vertices = new CustomVertex.PositionColored[WIDTH * HEIGHT];  for (int x = 0; x < WIDTH; x++)  { for (int y = 0; y < HEIGHT; y++) {vertices[x + y * WIDTH].Position = new Vector3(x, y, heightData[x, y]);vertices[x + y * WIDTH].Color = Color.White.ToArgb(); }  }  vb.SetData(vertices, 0, LockFlags.None);  ib = new IndexBuffer(typeof(int), (WIDTH - 1) * (HEIGHT - 1) * 6, device, Usage.WriteOnly, Pool.Default);  indices = new int[(WIDTH - 1) * (HEIGHT - 1) * 6];  for (int x = 0; x < WIDTH - 1; x++)  { for (int y = 0; y < HEIGHT - 1; y++) {indices[(x + y * (WIDTH - 1)) * 6] = (x + 1) + (y + 1) * WIDTH;indices[(x + y * (WIDTH - 1)) * 6 + 1] = (x + 1) + y * WIDTH;indices[(x + y * (WIDTH - 1)) * 6 + 2] = x + y * WIDTH;indices[(x + y * (WIDTH - 1)) * 6 + 3] = (x + 1) + (y + 1) * WIDTH;indices[(x + y * (WIDTH - 1)) * 6 + 4] = x + y * WIDTH;indices[(x + y * (WIDTH - 1)) * 6 + 5] = x + (y + 1) * WIDTH; }  }  ib.SetData(indices, 0, LockFlags.None);