Original Post
Hello. I'm working on a game that uses a simple physics engine to simulate the movement of some (spherical, later maybe rectangular) 2D objects "inside" the screen, using an accelerometer to make them tumble about the (smallish, 240x320) screen. I need to use fixed point maths only (one potential culprit is my newtonian iteration function for the square root, but it seemed sufficiently robust so far). There are to be anywhere between 1 and 20 Objects of identical mass and size on the screen. "Gravity" is determined by the XYZ-accelerometer input, plus some special "toss" impulse changes that occur when a short peak input comes from the accelerometers. Here's what I have so far: I use an Euler integration method, but I'm tentatively looking into better ones. The problem is, my target platform has a very limited processing power and memory. Maybe you can suggest one? Object-to-wall collisions are simple, I just clip whatever coordinate exceeds the maximum, reverse the velocity, lock the object's degree of freedom for the frame, and reduce the speed a little to emulate a semi-elastic collision. Because I want something to graphically happen to the object in that instant, showing it exactly at the point of collision for one frame is an added benefit of my method. For object-object-collisions, I use simple "Pool Ball" physics to calculate the changes in direction when they collide, by determining the impact normal, separating the objects along this normal, projecting the impact velocity onto it, calculate the impulse and determining the result to the velocity vectors of the objects. It's a fully elastic collision. This seems to work fine, and is rather convincing. However, it gets tough once degrees of freedom are lost (at the edge of the screen). My objects keep accelerating too long per frame (20 to 100 milliseconds), meaning they penetrate too deeply - and worse: their velocities do not converge at 0. Thus, the objects never really come to rest on top of each other. Instead, they chaotically jumble around in the corner. Now, I guess one step in the right direction would be to determine the precise point of impact for the objects. Currently, I just separate them if I detect an overlap (objects passing through each other at high velocities aren't an issue, as this is not noticeable on the tiny screen). However, there could be multiple impacts every frame. Acceleration data from the accelerometers would need to be broken up and integrated over small "fragments" of the time slice. Remaining degrees of freedom need to be propagated through chaotic stacks of potentially dozens of objects. I have no idea how to do that in a simple fashion. It's frustrating, because it seems like such a simple thing to do, but I just can't sort it out. In my search for a simple solution, I wrote a little hack that simulates a partially elastic collision (as opposed to a fully elastic "pool ball" collision) in case one of the objects hits another one that is currently touching a wall. This helps as long as the acceleration forces are sufficiently (read: quite) low. [Edited by - Thygrrr on August 9, 2008 7:11:52 PM]