I detect a collision between some object and another, and I get a normal to the surface where the collision occured, and the point of that collision. I try to sort of pretend that the velocity vector of the colliding object and the surface normal make like an 'angle of incidence'. And then I go farther and deal with that whole dealiothingy in put it into the context of a polar system sort of. Looks like this (multiplication operator does dot product):
Code:
double incidence = std::acos( -v_ball.getNormalized() * normal );
// Into polar (theta, radius) form
double theta = std::acos( -v_ball.getNormalized() * CVector(1, 0) ) + incidence * 2;
double radius = v_ball.length();
// Into cartesian x, y form
CVector out = CVector( std::cos( theta ) * radius, std::sin( theta ) * radius );
m_ball.setVelocity( out );
So, basically my logic is like this. It's wrong I guess, because the ball goes all over the place unpredictably after the collision, but, it's my logic.