# Marching Cubes Player-Terrain Collision Detection

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

## Recommended Posts

So I'm implementing a destructible terrain system in my game, using the marching cubes algorithm. I just need to make it so that the player does not fall through the ground, preferably using a continuous algorithm (as opposed to discrete testing). Right now, I have a simple collision response system: line-plane intersection, and I draw a line from the object's start and end points each frame. If it intersects with any planes inside the cube that it is in, it will set the object's location to the point of the closest intersection. However, this point is on the plane itself. And on subsequent frames, since the object's start point now intersects with the plane, any other movement is not possible. If I change it so that the start point is ignored in testing, then the player will be able to go through the wall. And if I make it so that the resultant point of the algorithm is actually shifted slightly in the direction of the normal of the plane, the object will jitter when it runs into the wall instead of smoothly stopping.

But those were just the problems of my implementation of collision detection.

Does anyone else have any ideas on how I can do this? Also, how can I do this with a sphere or cylinder, instead of just with a point?

I tried typing in plane-sphere continuous collision detection in google, but i couldn't find anything. Could someone help me please?

##### Share on other sites
My only sugguestion is to use bullet physics, an open source engine under zlib-license . In my case I wrote my own collision class which generates triangles on-the-fly (from a highmap), the player is simulated by a sphere and the rest is done by bullet.

##### Share on other sites
All right, thanks a ton! I downloaded it and set up all the libs, but I'm not quite sure where to start. And there aren't too many tutorials online, do you know any good ones? I found the hello world one on the wiki; but that's about it.

##### Share on other sites

All right, thanks a ton! I downloaded it and set up all the libs, but I'm not quite sure where to start. And there aren't too many tutorials online, do you know any good ones? I found the hello world one on the wiki; but that's about it.

Take a look at the demos folder, there're a lot of demos available, i.e. the terrain demo. I learned it from the demos,API and bullet forum.

##### Share on other sites
I've looked through many tutorials online, but from what I see and through my experimentation, I cannot find any way to make dynamic terrain. I realize this may be able to be done with the heightmap class, but right now I am using a btBvhTriangleMeshShape. And I cannot seem to find a way to make this dynamically change. Am I missing something, or does this engine not support this?

##### Share on other sites

I've looked through many tutorials online, but from what I see and through my experimentation, I cannot find any way to make dynamic terrain. I realize this may be able to be done with the heightmap class, but right now I am using a btBvhTriangleMeshShape. And I cannot seem to find a way to make this dynamically change. Am I missing something, or does this engine not support this?

I've got an older version of bullet, but I hope that it does not have changed a lot. I extended the btConcaveShape class. The method processAllTriangles takes a parameter a callback and an AABB. The AABB is the volume in which bullet wants to test a collision. You need to determine all surfaces inside this AABB and call the callback for each triangle found. This way you have full controll over an on-the-fly collision detection. When your moving object are relative small compared to your cubes, then this will be fast enough (returning only a handful of tris ). For larger objects you could add a cache later.
 class Xyz: public btConcaveShape { /** * Bullet interface */ virtual int getShapeType() const { return TERRAIN_SHAPE_PROXYTYPE;} virtual const char* getName() const {return "TERRAIN";} virtual void getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const; virtual void calculateLocalInertia(btScalar mass,btVector3& inertia) const {inertia=btVector3(0.,0.,0.);} virtual void setLocalScaling(const btVector3& scaling){/* not supported, assert or throw exception*/} virtual const btVector3& getLocalScaling() const { return m_scaling;} /* this is the important method */ virtual void processAllTriangles(btTriangleCallback* callback,const btVector3& aabbMin,const btVector3& aabbMax) const; }; 

1. 1
Rutin
24
2. 2
3. 3
JoeJ
18
4. 4
5. 5

• 38
• 23
• 13
• 13
• 17
• ### Forum Statistics

• Total Topics
631706
• Total Posts
3001833
×