Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
You are not logged in - nap
CSDb User Forums


Forums > C64 Coding > Simple "look at" function, avoiding atan2
2018-06-26 11:39
jamiefuller
Account closed

Registered: Mar 2018
Posts: 25
Simple "look at" function, avoiding atan2

Hi All,

I am writing a game that requires the player character to aim his gun at a movable point around the screen, I would usually calculate the angle using atan2 but don't want the overhead of a fully blown atan2 routine ( http://codebase64.org/doku.php?id=base:8bit_atan2_8-bit_angle )

The player can be any random x,y and the crosshaor can be any other random x,y

The gun sprite only needs to point in one of 8 directions so I can't help think that it must be easier to calculate/table. but I'm drawing a major blank :(

Any pointers or suggestions would be much appreciated.

Thanks
 
... 10 posts hidden. Click here to view all posts....
 
2018-06-28 12:37
TWW

Registered: Jul 2009
Posts: 545
In which case you only need to LDA X1 CMP X2
2018-06-28 12:47
jamiefuller
Account closed

Registered: Mar 2018
Posts: 25
Quote: In which case you only need to LDA X1 CMP X2

Good point, and I had to double check my code to make sure :)

but in this case while I am not using dx later, I am using dx to calculate absdx, so I still need to do the subtraction to calculate dx, just not store it anywhere, only store absdx.

But I think I could probably do that for the last subtraction
        sec
        sbc absdx

which calculates absdy-absdx and only uses the sign of the output. I'll give it a try :)
Previous - 1 | 2 - Next
RefreshSubscribe to this thread:

You need to be logged in to post in the forum.

Search the forum:
Search   for   in  
All times are CET.
Search CSDb
Advanced
Users Online
Hairdog/BOOM!^Dream
New Design/Excess
HBH.ZTH/Abnormal
MWR/Visdom
Martinland
iAN CooG/HVSC
4gentE/ΤRIΛD
TheRyk/MYD!
Nordischsound/Hokuto..
Freeze/Blazon
B.A./QUANTUM
Mike
St0rmfr0nt/Quantum
Case/Padua
Guests online: 107
Top Demos
1 Next Level  (9.7)
2 13:37  (9.7)
3 Mojo  (9.7)
4 Coma Light 13  (9.6)
5 Edge of Disgrace  (9.6)
6 What Is The Matrix 2  (9.6)
7 The Demo Coder  (9.6)
8 Uncensored  (9.6)
9 Comaland 100%  (9.6)
10 Wonderland XIV  (9.6)
Top onefile Demos
1 Layers  (9.6)
2 No Listen  (9.6)
3 Cubic Dream  (9.6)
4 Party Elk 2  (9.6)
5 Copper Booze  (9.6)
6 Dawnfall V1.1  (9.5)
7 Rainbow Connection  (9.5)
8 Onscreen 5k  (9.5)
9 Morph  (9.5)
10 Libertongo  (9.5)
Top Groups
1 Performers  (9.3)
2 Booze Design  (9.3)
3 Oxyron  (9.3)
4 Triad  (9.3)
5 Censor Design  (9.3)
Top Original Suppliers
1 Derbyshire Ram  (9.7)
2 Fungus  (9.3)
3 Black Beard  (9.2)
4 Baracuda  (9.2)
5 hedning  (9.1)

Home - Disclaimer
Copyright © No Name 2001-2024
Page generated in: 0.043 sec.