Calculator Community > Axe
Moving sprites in a circle
_player1537:
Axe doesn't have a built in sin routine yet. I'll have to try what you were saying.
*looks for Will_W's math.inc file*
Will_W:
calc84 made some wicked optimizations to it, maybe he'll post them here if we're lucky.
--- Code: ---Sin_A:
;input a in pi/256 radians from [0,pi)
;output l is a binary value in the range [0,1)
;destroys h,de
;a is unmodified
;Will West
ld h,a
ld e,h
call HtimesE;hl=x^2
ex de,hl;x^2
ld l,a
ld h,0
or a;reset carry
sbc hl,de
add hl,hl
add hl,hl
ret
HtimesE:
ld l,0
ld d,0
sla h ; optimised 1st iteration
jr nc,$+3
ld l,e
add hl,hl ;1
jr nc,$+3 ;
add hl,de ;
add hl,hl ;2
jr nc,$+3 ;
add hl,de ;
add hl,hl ;3
jr nc,$+3 ;
add hl,de ;
add hl,hl ;4
jr nc,$+3 ;
add hl,de ;
add hl,hl ;5
jr nc,$+3 ;
add hl,de ;
add hl,hl ;6
jr nc,$+3 ;
add hl,de ;
add hl,hl ;7
jr nc,$+3 ;
add hl,de ;
ret
;;=================================================================================
;;does sin(a) where a is between (-pi,pi) and is in units of
;;128/pi radians
;;inputs a
;;outputs a
;;destroys bc,de,hl
;;=================================================================================
Sin_A_Signed:
bit 7,a
jr z,Sin_A_Signed2
neg
sla a
call Sin_A
ld a,l
neg
ret
Sin_A_Signed2:
sla a
call Sin_A
ld a,l
ret
--- End code ---
DJ Omnimaga:
--- Quote from: SirCmpwn on April 06, 2010, 06:20:31 pm ---That looks almost right.
The Pt-On line should look like this:
Look here↓
Pt-On(X*cos(Z)+Y*sin(Z),X*sin(Z)-Y*cos(Z
And, it can be optimized to this as well:
Pt-On(Xcos(Z)+Ysin(Z),Xsin(Z)-Ycos(Z // Removed "*" tokens
Keep in mind that it rotates around the origin, or the 0, 0 point. Also, you can keep adding 1 to Z, and it will still work. Z does not have to be between 0 and 360, 361 will rotate it 1 degree.
--- End quote ---
woops lol why did I forgot about those *? :D, I guess when I am used more to Axe, if I decide to go back to BASIC afterward, I'll have to be careful ^^
Navigation
[0] Message Index
[*] Previous page
Go to full version