Ball Physics

Hi guys and gals, first post so be gentle!

I have the requirement to model the movements of a ball across a 3d terrain.

I have the terrain in an extremely high resolution of data, which I currently (for testing purposes) have exported to create a surface (terrain) that is 20,000 polygons (triangles) in size. Its roughly 100 squares by 100 squares with each square made out of a pair of triangles.

The surface does not need to be in that layout, but as I say thats just testing at the moment whilst I find out the best structure.

I would like to simulate a ball rolling across this surface, and was wondering what peoples views are on either,

  1. using one of the 3d physics engines out there, and if so any recommendations for this function?
  2. simply calculating the angle of the polygon the ball is on and calculating the roll myself.

I am not scared of the maths involved in doing it myself, but if there is a simple library out there then simply for speed it makes sense to use that.

Id appreciate any feedback from the forum.

Dave

I would use JBullet. It’s easy enough to use, and there are plenty of tutorials.

If you are going the manual route, for this particular exercise there are a few things that I think greatly simplify calculations:

  • If the terrain is being rendered, you can reuse the surface normals used for smoothing to calculate physics interactions with the ball.
  • Since the object is a sphere, collisions can be an extension of point-collisions (using the radius to create an spherical bounding box, rather than bothering with bounding box geometry).
  • If the sphere has specific physical properties that limit how fast it can possibly move (wind drag / terminal velocity), the (maximum) potential collision area can be drastically reduced.
  • If the terrain can be simplified to a heightmap (no overhangs or other complex structures, just slopes), determining when the sphere is touching the ground is even simpler. Even if there are overhangs, maybe a large portion of the terrain can be abstracted as a heightmap to speed up detection.

But these are just ideas I’ve come up with while thinking about your problem. Maybe someone else has more experience on this sort of thing and can debunk/enhance these points.

As for a physics engine, I personally don’t like adding a complex engine if it is overkill, mostly because of the performance hit that might result from having more functionalities than those I require. But if the engine is scalable enough to mitigate that issue, go for it.

Adding to Oskuro’s post…

Given a point(sphere center + radius)

Use the plane equation to find the distance (Ax + By + Cz + D = 0) We want to find D.
So, we come up with D = -(Ax + By + Cz)
Basically, the negated dot product of the normal of the plane and the point.

normal is the triangle normal of the terrain and vpoint is your point to test.


planeDistance = - ((normal.x * vpoint.x) + (normal.y * vpoint.y) + (normal.z * vpoint.z))

After finding the distance, you need to know what side of the triangle your point is.

We use the famous distance formula to find the distance the center point of the sphere is from the polygon’s plane.


distance = (vnormal.x * vcenter.x + vnormal.y * vcenter.y + vnormal.z * vcenter.z + planeDistance)

where: vcenter is the center of the sphere.

Now check where the sphere lies in relation to the plane defined by your triangle…

If the absolute value of the distance we just found is less than the radius, the sphere intersected the plane.

    
    if( abs(distance) < radius )
    {
	INTERSECTS
    }    
    else if( abs(distance) >= radius )
    {    
        FRONT
    }
    else
    {
        BEHIND
    }

Then just project the sphere’s center to the plane and do your response.

Hi guys, sorry for the silence on this, I have been busy getting my application to the point of needing the ball physics and remembered I had posted this question.

The ground is on one level (no overhangs, cliffs etc) and I think using the plane (normal?) of the surface the ball is on to calculate its roll should pretty much do.

I am not even rendering the ball moving, simply want to know the path it took. I am going to begin this section of code and will be back for assistance no doubt!

Thanks again

D

Hi guys, sorry for the silence on this, I have been busy getting my application to the point of needing the ball physics and remembered I had posted this question.

The ground is on one level (no overhangs, cliffs etc) and I think using the plane (normal?) of the surface the ball is on to calculate its roll should pretty much do.

I am not even rendering the ball moving, simply want to know the path it took. I am going to begin this section of code and will be back for assistance no doubt!

Thanks again

D