Ball Bounce Demo with Gravity and Physics
The code is here: BallBouncePhysics4.c
I compile it with the command:
gcc `sdl-config --cflags --libs` c4.c -o c4
Everything was slowing down and stopping so I had to put in an extra boost to the impulse to offset that. I think it was caused by the rounding down of the float to an int when I stored the impulse. I may upgrade the delta_x and delta_y of each object to a float to see if this eliminates the need for the added value. When two balls strike each other the two points where they hit are tangent to their surface and a line is perpendicular to this tangent and goes through both their centers. In order to calculate the result you need to rotate this perpendicular axis line so that it becomes the x axis. Each ball imparts an impulse that is transfered into the other ball. Their relative masses are part of this calculation. Here is a graphical example of how to calculate the value:http://en.wikipedia.org/wiki/Elastic_collision
No comments:
Post a Comment