Original Post
Hi guys,
Sometimes my pool balls bounce off corners in a crazy way and I figured out that it's caused by roundoff errors.
Here is a perfect example:
// the normal to the wall (perfect diagonal) Vector2D vNormal; vNormal.x=1.0f; vNormal.y=1.0f; NormalizeVector(&vNormal); // the ball's direction (already normalized) Vector2D vBallDir; vBallDir.x= -1.0f; vBallDir.y=0.0f; // reflect ball direction (pseudo code) newDir=vBallDir-2.0f*((vBallDir*vNormal)*vNormal)Here is the result (should be 0.0f,1.0f): newDir.x: -0.000000059605 newDir.y: 0.999999940395 Now I don't really care if the direction is slightly off but when I use those numbers in other calculations it messes everything up. How should I go about handling this ? I guess I can see if a value is really close to 0.0 and then make it zero if it is and do the same with 1.0 but will that work ? Any guidance is appreciated. Thanks. [edited by - Endemoniada on August 7, 2003 2:59:45 PM]