I'm looking to write an algorithm that sets the trajectory of a sphere after collision with a flat polygon (under any orientation), and was wondering if anyone had any suggestions on how to approach the problem. The information I have available is the velocity vector of the sphere prior to collision, and the normal vector of the collision plane.
My code currently looks like this:
Code: Select all
if(velocity.dotProduct(n)>-0.000001)
{
if(n.X!=0)
velocity.X = velHack.X * n.X;
if(n.Y!=0)
velocity.Y = velHack.Y * n.Y;
if(n.Z!=0)
velocity.Z = velHack.Z * n.Z;
}
I believe the direction of the resultant velocity vector needs to be equal but opposite to the angle (i.e. the other side) between the incident velocity vector the normal vector of the polygon.
Thanks for the help!
James.