Gravity calculations

From: jeff hendrix <jhendrix_at_quark.com>
Date: Wed Nov 03 1999 - 16:04:40 EST

Thanks for all the suggestions, I got the gravity working and it's almost
perfect.
(at first it wasn't working right, then I remembered I had to turn friction
off to keep the orbit from decaying)

I used Zonn's shift lookup technique and built tables based on Paul's
suggestion.

Basically, since xvel = xdist/dist x 1/dist^2
then xvel = xdist/dist^3
so I built my table like this
for (i=0,i<256,i++) {
        val = pow(256.0/i,3);
}
(with some other code in there to only output the values needed for the
shift lookup table, I can post it if anybody is interested)
I multiplied my fraction by a constant so I would get an integer value which
I then use to calculate the lower bytes of a fixed point number.

So, to make gravity work, all I had to do was get xdist & ydist and square
them (using a table for speed).
Then use the shift lookup table to get my number.
Then multiply that number by xdist (then ydist) and add that value to the
velocity, and bingo, orbiting ships. (I let it run for about 20 minutes, and
the orbit was the same)

-jeff
Received on Wed Nov 3 15:06:06 1999

This archive was generated by hypermail 2.1.8 : Fri Aug 01 2003 - 00:32:27 EDT