#167280 - headspin - Sat Mar 07, 2009 6:32 pm
Were looking at implementing directional fire into a game a friend and I are working on in asm. We have the following C code to work from.
To calculate the the angle from the alien to the ship
And then to move the bullet towards the ship from the alien
I've found an implementation of atan2 in asm on these boards which we can use. But is there a way to do the calculation without atan2? Also avoiding the divide would be nice. So basically any suggestions for an algorithm that would be faster in arm asm.
_________________
Warhawk DS | Manic Miner: The Lost Levels | The Detective Game
To calculate the the angle from the alien to the ship
Code: |
# Alien
x1 = 128 y1 = 128 # Ship x2 = 132 y2 = 132 deltax = x2 - x1 deltay = y2 - y1 angle_rad = atan2(deltay,deltax) |
And then to move the bullet towards the ship from the alien
Code: |
# alien starting point
x0 = 1.0 y0 = 1.5 # theta is the angle (in radians) of the direction in which to move theta = pi/6 # r is the distance to move r = 2.0 deltax = r * cos(theta) deltay = r * sin(theta) # new point x1 = x0 + deltax y1 = y0 + deltay |
I've found an implementation of atan2 in asm on these boards which we can use. But is there a way to do the calculation without atan2? Also avoiding the divide would be nice. So basically any suggestions for an algorithm that would be faster in arm asm.
_________________
Warhawk DS | Manic Miner: The Lost Levels | The Detective Game