Author Topic: [Axiom] Aiming Utility  (Read 8021 times)

0 Members and 1 Guest are viewing this topic.

Offline Iambian

  • Coder Of Tomorrow
  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 739
  • Rating: +216/-3
  • Cherry Flavoured Nommer of Fishies
    • View Profile
[Axiom] Aiming Utility
« 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.
« Last Edit: November 28, 2011, 02:43:09 pm by Iambian »
A Cherry-Flavored Iambian draws near... what do you do? ...

Offline Yeong

  • Not a bridge
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3739
  • Rating: +278/-12
  • Survivor of Apocalypse
    • View Profile
Re: [Axiom] Aiming Utility
« Reply #1 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
Sig wipe!

Offline Darl181

  • «Yo buddy, you still alive?»
  • CoT Emeritus
  • LV12 Extreme Poster (Next: 5000)
  • *
  • Posts: 3408
  • Rating: +305/-13
  • VGhlIEdhbWU=
    • View Profile
    • darl181.webuda.com
Re: [Axiom] Aiming Utility
« Reply #2 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
« Last Edit: November 26, 2011, 07:03:23 pm by Darl181 »
Vy'o'us pleorsdti thl'e gjaemue

Offline epic7

  • Chopin!
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2200
  • Rating: +135/-8
  • I like robots
    • View Profile
Re: [Axiom] Aiming Utility
« Reply #3 on: November 26, 2011, 07:02:46 pm »
YES!

Offline Iambian

  • Coder Of Tomorrow
  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 739
  • Rating: +216/-3
  • Cherry Flavoured Nommer of Fishies
    • View Profile
Re: [Axiom] Aiming Utility
« Reply #4 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.
A Cherry-Flavored Iambian draws near... what do you do? ...

Offline Darl181

  • «Yo buddy, you still alive?»
  • CoT Emeritus
  • LV12 Extreme Poster (Next: 5000)
  • *
  • Posts: 3408
  • Rating: +305/-13
  • VGhlIEdhbWU=
    • View Profile
    • darl181.webuda.com
Re: [Axiom] Aiming Utility
« Reply #5 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?
« Last Edit: November 27, 2011, 11:23:51 am by Darl181 »
Vy'o'us pleorsdti thl'e gjaemue

Offline Iambian

  • Coder Of Tomorrow
  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 739
  • Rating: +216/-3
  • Cherry Flavoured Nommer of Fishies
    • View Profile
Re: [Axiom] Aiming Utility
« Reply #6 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.
A Cherry-Flavored Iambian draws near... what do you do? ...

Offline Quigibo

  • The Executioner
  • CoT Emeritus
  • LV11 Super Veteran (Next: 3000)
  • *
  • Posts: 2031
  • Rating: +1075/-24
  • I wish real life had a "Save" and "Load" button...
    • View Profile
Re: [Axiom] Aiming Utility
« Reply #7 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.
___Axe_Parser___
Today the calculator, tomorrow the world!

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55941
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: [Axiom] Aiming Utility
« Reply #8 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

Offline Iambian

  • Coder Of Tomorrow
  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 739
  • Rating: +216/-3
  • Cherry Flavoured Nommer of Fishies
    • View Profile
Re: [Axiom] Aiming Utility
« Reply #9 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!
« Last Edit: November 28, 2011, 02:43:54 pm by Iambian »
A Cherry-Flavored Iambian draws near... what do you do? ...

Offline Quigibo

  • The Executioner
  • CoT Emeritus
  • LV11 Super Veteran (Next: 3000)
  • *
  • Posts: 2031
  • Rating: +1075/-24
  • I wish real life had a "Save" and "Load" button...
    • View Profile
Re: [Axiom] Aiming Utility
« Reply #10 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.
« Last Edit: November 28, 2011, 04:40:07 pm by Quigibo »
___Axe_Parser___
Today the calculator, tomorrow the world!

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: [Axiom] Aiming Utility
« Reply #11 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.

Offline Quigibo

  • The Executioner
  • CoT Emeritus
  • LV11 Super Veteran (Next: 3000)
  • *
  • Posts: 2031
  • Rating: +1075/-24
  • I wish real life had a "Save" and "Load" button...
    • View Profile
Re: [Axiom] Aiming Utility
« Reply #12 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.

___Axe_Parser___
Today the calculator, tomorrow the world!

Offline Iambian

  • Coder Of Tomorrow
  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 739
  • Rating: +216/-3
  • Cherry Flavoured Nommer of Fishies
    • View Profile
Re: [Axiom] Aiming Utility
« Reply #13 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.
A Cherry-Flavored Iambian draws near... what do you do? ...