Omnimaga
Calculator Community => Other CalcRelated Projects and Ideas => TI Z80 => Topic started by: ACagliano on January 14, 2015, 05:08:51 pm

Two separate questions, to resolve two issues, whereupon which I will be releasing a game.
1. Is there a simple way to take an angle (period 0256) and get an x vector and a y vector? I know that x is sin and y is cos, but i need the result to be a SIGNED 8.8 FIXED POINT.
2. If you have a sprite of size nxm, is there a way to, using its distance from you, scale its size so that it looks like its farther or closer and then render it?
Language is asm. Thanks.

Many years ago, Badja released some sprite scaling routines (although they only scaled down, not up). You can find them here on ticalc.org (http://www.ticalc.org/archives/files/fileinfo/192/19230.html) if that's any help :)
I don't know anything about the theory behind it, although funnily enough for one of my next projects I might need to learn about it :P

>B)Thanks I went to that link and shot the dude an email! :)
Edit: The email is invalid :(

>B)Thanks I went to that link and shot the dude an email! :)
Edit: The email is invalid :(
Yeah unfortunately Badja has been gone from the TI scene for many years now. I never had any contact with him back in the day either (even though he was a fellow Aussie), so I don't have any other email address for him, sorry :(

Hayleia probably has some input on this, i think the scaling in SSBO is based off of Badja's code. tr1p1ea probably is also pretty knowledgeable on this, especially with all their 3D demos and stuff.
For number 2, of course there's a way! I couldn't tell you how to do it though. At the very least you could do something like i believe Anarchy and Lotus Turbo Challenge did.

1. Is there a simple way to take an angle (period 0256) and get an x vector and a y vector? I know that x is sin and y is cos, but i need the result to be a SIGNED 8.8 FIXED POINT.
In that case you can just have a sin table wich is in 8.8 fixed point format, and the xy vector will be indeed {cos(alpha),sin(alpha)}
(I don't know how you calculate sin/cos in your program), but you can also convert the result of your routine to 8.8.

maybe a LUT for sin would do, that would only be 256 bytes large.
and for cos(x) you would do sin(x  (256/4))

calcCos:
ld b,64
add a,b
calcSin:
cp 128
jr nc,greaterT128
cp 64
jr nc,greaterT64
jr sin_getEntry
greaterT64:
ld b,a
ld a,63
sub b
jr sin_getEntry
greaterT128:
ld b,128
sub b
cp 64
jr nc,greaterT64
jr sin_getEntry
sin_getEntry:
ld c,a
ld b,0
ld hl,sinLUT
add hl,bc
; hl = 8.8 FP result
sinLUT:
.db 0,3,6,9,12,15,18,21,24,28 ; sin(09)
.db 31,34,37,40,43,46,48,51,54,57 ; sin(1019)
.db 60,63,65,68,71,73,76,78,81,83 ; sin(2029)
.db 85,88,90,92,94,96,98,100,102,104 ; sin(3039)
.db 106,108,109,111,112,114,115,117,118,119 ; sin(4049)
.db 120,121,122,123,124,124,125,126,126,127 ; sin(5059)
.db 127,128,128,128 ; sin(6063)

For the sprite scaling routine, I am currently working on writing my own version inspired by Bajda's to suit your purposes (masked, grayscale, scalable sprites). I found a bunch of optimizations, and it was just easier to start from scratch, especially since I needed to make it draw 3 layers of sprites.