Sign in to follow this  
rocklobster

Basic collision detection and normals

Recommended Posts

rocklobster    415
[font=arial, verdana, tahoma, sans-serif][size=2]Hi guys,

I've been working on basic collision detection (ball and a plane) and I can get desired results using this formula[/size][/font]

newVelocity = I - (normal * 2 * I.dot( normal )

But this is with a hard coded value for the surface normal. My question is, in a more dynamic setting (say a ball bouncing around a room with a cube floating in the centre) where there will be multiple normals? Do i have to do something like this..

if (collides with back of cube)
normal = (0.0, 0.0, -1.0)
if (collides with bottom of cube)
normal = (0.0, -1.0, 0.0)

etc.

and then use the formula to calculate the angle of reflection?

Thanks for any help

-James

Share this post


Link to post
Share on other sites
RobTheBloke    2553
You typically use a scene wide query. eg:

[source]
while(1)
{
Vector3 collisionNormal;
Vector3 collisionPoint;
bool result = getCollisionFromAllObjectsInScene(oldVelocity, oldPosition, collisionNormal, collisionPoint);
if(!result) break;

// resolve collision

// update position and velocity of object
}
[/source]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this