Omnimaga

Calculator Community => Major Community Projects => The Axe Parser Project => Topic started by: Iambian on November 26, 2011, 04:11:26 am

Title: [Axiom] Aiming Utility
Post by: Iambian on November 26, 2011, 04:11:26 am
It spits out an angle that you can use to aim at targets given a delta X and Y. See the ReadME.

NOTE: This has not been tested. Please test this thing to see if it conforms to what the readme says. When I went about testing it, it drove me insane. I probably just need sleep.

Attached to this post is what I have so far. When I can verify that it works, I'll post another with source included in it. The arctangent routine that is used in the Axiom was sourced from CaDan. Please test it.

Arghablabbles. (This post will be edited as stuff is changed)

EDIT: Attachment replaced with one that actually works. This is to be version 0.02 of this Axiom. Thank you very much for your patience. I will continue to make this "better". And by better, I mean smaller with acceptable losses in accuracy, and also to make the routine "native" to the dimensions I gave it, rather than some hack job to make it "work". Also, source is included.
Title: Re: [Axiom] Aiming Utility
Post by: Yeong on November 26, 2011, 07:35:09 am
:D
so with this, we can have that crazy shitload of bullets like CaDan in Axe? :D
Perfect. XD
Title: Re: [Axiom] Aiming Utility
Post by: Darl181 on November 26, 2011, 07:01:07 pm
So this uses that giant method you posted in the CaDan topic? derp
Tho in my case imma stay with what's working already for Essence :P
Title: Re: [Axiom] Aiming Utility
Post by: epic7 on November 26, 2011, 07:02:46 pm
YES!
Title: Re: [Axiom] Aiming Utility
Post by: Iambian on November 27, 2011, 02:46:19 am
Remember guys. I need people to test this thing because I didn't think this thing would actually work the first time around. As far as I can tell, it doesn't crash the system, but I don't know if it's giving the right outputs.

:D
so with this, we can have that crazy shitload of bullets like CaDan in Axe? :D
Perfect. XD
No. This allows you to aim like the enemies can in CaDan. Your Axe project still needs to be responsible for the bullets it outputs.
Title: Re: [Axiom] Aiming Utility
Post by: Darl181 on November 27, 2011, 11:23:32 am
So this takes in X,Y,deltaX and deltaY?
How does it handle inflation...I'm supposing the coder has to inflate it theirself.  *256?
Title: Re: [Axiom] Aiming Utility
Post by: Iambian on November 27, 2011, 01:57:25 pm
So this takes in X,Y,deltaX and deltaY?
How does it handle inflation...I'm supposing the coder has to inflate it theirself.  *256?
No, it just takes a delta X and delta Y. You have to do the (X2-X1),(Y2-Y1) yourself. The Axiom takes two arguments and gives out a single answer.

Each 16 bit argument is truncated to 8 bits for you. I just simply chop off the high byte.
Title: Re: [Axiom] Aiming Utility
Post by: Quigibo on November 27, 2011, 02:26:49 pm
So basically this is the function better known as "atan2".  That's cool!  I added this recently for the next version of axe.
Title: Re: [Axiom] Aiming Utility
Post by: DJ Omnimaga on November 27, 2011, 04:13:47 pm
This seems interesting. I sometimes had troubles in the past with enemy aiming when I worked on some shooters, although in my case it was TI-BASIC. Good work I guess :D
Title: Re: [Axiom] Aiming Utility
Post by: Iambian on November 28, 2011, 08:57:06 am
So basically this is the function better known as "atan2".  That's cool!  I added this recently for the next version of axe.
Curious to know, but how are you calculating atan in your version? My guess is that you're going to use polynomial approximation?

My version uses a 256 byte LUT to help calculate the angle and it uses linear interpolation to fill the gap that the LUT creates. I can probably get away with a 64 byte LUT and further the linear interpolation to help give a "good enough" result, but I'd want a test routine to help me figure out if the values I'm getting are good.

And so it seems like I'm going to have to learn Axe (yeah, I don't know it very well) to pull together a test routine for this mess. Wish me luck on this one. Then I'll probably modify the routine and probably try to optimize it. But first thing is first. Gotta make sure it works.

EDIT: Also, I assume you're going to be using the tan-1( token? If you do that, what should I change mine to, since I happen to be using that as well?
EDIT2: Okay. Actually writing the test routine. Things appear to fail. Need some time to figure out the problem.
EDIT3: Success! (http://ourl.ca/14229/265981)
Title: Re: [Axiom] Aiming Utility
Post by: Quigibo on November 28, 2011, 04:39:15 pm
Yeah, mine is lossy, but its very compact and tiny.  The most I have seen it off is by 4 binary degrees but on average its usually less than 3.  It is exact every 45 degrees.  This is the routine I'm using:

Code: [Select]
p_ArcTan:
.db __ArcTanEnd-1-$
ex de,hl ;de = y
pop hl
ex (sp),hl ;hl = x
push hl
ld a,h ;\
xor d ; |Get pairity
rla ;/
jr c,__ArcTanSS ;\
add hl,de ; |
add hl,de ; |
__ArcTanSS: ; |
or a ; |hl = x +- y
sbc hl,de ;/
ex de,hl ;de = x +- y
ld b,6 ;\
__ArcTan64: ; |
add hl,hl ; |hl = 64y
djnz __ArcTan64 ;/
call $3F00+sub_SDiv ;hl = 64y/(x +- y)
pop af ;\
rla ; |Right side, fine
ret nc ;/
sbc a,a ;\
sub h ; |Reverse sign extend
ld h,a ;/
ld a,l ;\
add a,128 ; |Add or sub 128
ld l,a ;/
ret
__ArcTanEnd:

The arguments are currently backwards; (X,Y) instead of the traditional (Y,X).  I'm not sure which one I'm going to use yet.
Title: Re: [Axiom] Aiming Utility
Post by: Builderboy on November 28, 2011, 05:43:42 pm
I think (X,Y) would make more sense to newer users, as well as users that have not used the Atan2() function before.
Title: Re: [Axiom] Aiming Utility
Post by: Quigibo on November 29, 2011, 02:09:51 am
Yeah.  Nearly every programming language uses (Y,X) and every spreadsheet and math program uses (X,Y).  So I think I'll end up sticking with X,Y just because it optimizes better, and its more consistent with the rest of the Axe syntax when looked at independently of other programming languages.  Iambian used this convention as well.

Title: Re: [Axiom] Aiming Utility
Post by: Iambian on November 29, 2011, 04:52:37 am
Okay. Not tested yet, but I reduced the size of the LUT to 64 bytes (old was 256) and did more linear interpolating to make up the difference. In the end, the size of the compile went from 400 bytes down to 206. Once I can verify that the new routine works "well", I'd like to run a speed test to compare Quigibo's routine versus mine, you know, to see if all that "extra stuff" in my routine is actually worth it.

Just as a note, because of the way the lookup table works, the results you get from X or Y going past -110 and 110 gets unstable since it's reading outside of the table's boundaries. I'm hoping this isn't a problem for some people, especially since the screen's only 96 by 64 pixels.

Can't test right now, though. Got a long as hell road trip coming up in less than 12 hours and I should've been asleep a long time ago.

If you guys want to run those tests while I'm gone, feel free to do so. I'm going to drop the untested code as an attachment on this post. Compare the results with the attachment on the first post of this thread and see if there's (much) difference. The attachments include everything you need to rebuild the Axiom. If you're running a Windows system, just double-click Z_MAKE.bat after extracting everything and it'll do its magic. Oh, and don't forget that it compiles to a .8xp file while Axioms ought to be .8xv's (?). Whoops.