Programming question

From: jeff hendrix <jhendrix_at_Quark.Com>
Date: Wed Oct 27 1999 - 17:09:00 EDT

I'm working hard to try and finish up space wars that will run on space duel
hardware.
I've got most things in it working, except I'm having trouble with the
gravity.
I'm implementing the following procedure:

// calculate distance from the sun
xLen = sunPos.x - objPos.x;
yLen = sunPos.y - objPos.y;
lengthsqr = (xLen * xLen) + (yLen * yLen);
length = sqrt(lengthsqr);
// calculate unit vector
unitX = xLen / length;
unitY = yLen / length;
// gravity is inverse r squared
unitX = unitX/lengthsqr;
unitY = unitY/lengthsqr;
// update object speed
speed.x += unitX;
speed.y += unitY;

I have everything figured out except how to get the square root of
lengthsqr.
Is there any easy or fast way to calculate the square root of a 16 bit
number on a 6502?
Or is there another way to calculate the pull of gravity, separated into x
and y components, that still follows the rule of the inverse of the square
of the distance?

-jeff

ps. I might soon have a "incomplete" version that can be played on MAME.
Received on Wed Oct 27 16:10:21 1999

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