Jump to content
  • Advertisement
Sign in to follow this  
frankypoo

maintaining terrain/coll'n detection

This topic is 4524 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I see a lot of articles on collision detection and was hoping someone could point me to some of the more useful ones. I'm looking for collision detection with the terrain, keeping the char's feet on the ground, as well as preventing forward motion through obstructions. I was hoping these two tests could be performed in one fell swoop. If it makes a difference, I'm coding in DX (C++).

Share this post


Link to post
Share on other sites
Advertisement
One easy way to deal with collision with terrain is to use a heightmap.

Load the heightmap into memory, and sample it to get the height. You can use interpolation to get a smooth and accurate height.

This way you avoid having to shoot rays to it.

There are other ways, but this is one of the methods I have seen on some games and that seems to be fairly cheap.

i.e.

// pseudocode
CPhysics::GetTerrainHeightAtPoint(point)
{
// find x/z point on the heightmap
float x=0; float y=0;
TranslateCoordinatesToTexture(m_heightMap, &x, &y);

// interpolate
int x0= (int)x;
int y0= (int)y;
int x1= x0+1;
int y1= y0;
int x2= x0;
int y2= y0+1;
int x3= x0+1;
int y3= y0+1;

// sample at four points and interpolate
float h0 = SampleTexture(m_heightMap, x0, y0);
float h1 = SampleTexture(m_heightMap, x1, y1);
float h2 = SampleTexture(m_heightMap, x3, y3);
float h3 = SampleTexture(m_heightMap, x4, y4);

return interpolate(h0, h1, h2, h3, x, y); // interpolate based on fractional parts of x, y



}

Share this post


Link to post
Share on other sites
will this cover obstructions (walls, trees, etc), or only work for terrain-walking coll'n detection?
Also, I'm making most my terrain in 3ds max and loading the .x files in dx as meshes, breaking them down with octree to keep from rendering too large a mesh at a time. Will heightmap coll'n detection work for .x meshes?

Share this post


Link to post
Share on other sites
Quote:
Original post by frankypoo
will this cover obstructions (walls, trees, etc), or only work for terrain-walking coll'n detection?
Also, I'm making most my terrain in 3ds max and loading the .x files in dx as meshes, breaking them down with octree to keep from rendering too large a mesh at a time. Will heightmap coll'n detection work for .x meshes?


No. The method described above works by samping a greyscale image of a landscape. For what you've described you might want to look at General Collision Detection for Games Using Ellipsoids.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!