RE: Programming question

From: Clay Cowgill <ClayC_at_diamondmm.com>
Date: Wed Oct 27 1999 - 20:52:30 EDT

Here's a trick for gravity simulation in a vector game: pitch the entire
"physics" based model and go with what looks good. ;-)

Moon Lander on the Vectrex "feels" pretty cool when you play it, but all it
is a constant added to the y-velocity. It's actually more of a "friction"
function, but doesn't stop when the velocity gets to zero...

One other trick that seems OK is just to take the x and y distance between
two points (just use the upper byte if you're using 16 bit numebrs), shift
them left once, add them together, and shift that result right twice. It's
not a square root (more like a weird average), but it gives you a pretty
proportional number that's fairly predictable over most of the range. If
you don't need the full dynamic range, you can probably just shift right
once at the end and assume that objects far apart will overflow (but that
would mean they're so far away that they won't have a gravitational effect
anyway).

Courtesy of Excel:
 <<...>>

I just made up some X and Y distances and plugged them into Excel. "real
dist" = sqrt(x^2+y^2), "fake dist" = ((X*2)+(Y*2))/4 You can see that does
some kinda strange things sometimes, but if you mask off the results and
only need maybe 5 or 6 bits of resolution it can be useful sometimes...
Three or four shifts and an add depending on how you've got your fixed-point
math working...

If you want to take the time-- look for the Vectrex ROM BIOS disassembly
(there's a couple of commented ones on the net). I think there's a quick
little sqrt-like function in there in 6809 assembly. (Or maybe it was the
Vectrex Star Castle source?)

-Clay
Received on Wed Oct 27 19:53:03 1999

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