# Omnimaga

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

Title: Vectors and Sprite Scaling
Post 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 0-256) 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.
Title: Re: Vectors and Sprite Scaling
Post by: JamesV on January 14, 2015, 05:55:05 pm
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
Title: Re: Vectors and Sprite Scaling
Post by: ACagliano on January 14, 2015, 07:21:07 pm
>B)Thanks I went to that link and shot the dude an email! :)

Edit: The email is invalid :(
Title: Re: Vectors and Sprite Scaling
Post by: JamesV on January 14, 2015, 09:29:53 pm
>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 :(
Title: Re: Vectors and Sprite Scaling
Post by: chickendude on January 15, 2015, 05:07:02 am
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.
Title: Re: Vectors and Sprite Scaling
Post by: TheMachine02 on January 15, 2015, 05:14:04 am
1. Is there a simple way to take an angle (period 0-256) 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.
Title: Re: Vectors and Sprite Scaling
Post by: Sorunome on January 15, 2015, 08:14:06 am
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))
Title: Re: Vectors and Sprite Scaling
Post by: ACagliano on January 15, 2015, 11:19:01 am
Code: [Select]
`calcCos: ld b,-64 add a,bcalcSin: cp 128 jr nc,greaterT128 cp 64 jr nc,greaterT64 jr sin_getEntrygreaterT64: ld b,a ld a,63 sub b jr sin_getEntrygreaterT128: ld b,128 sub b cp 64 jr nc,greaterT64 jr sin_getEntrysin_getEntry: ld c,a ld b,0 ld hl,sinLUT add hl,bc; hl = 8.8 FP resultsinLUT:.db 0,3,6,9,12,15,18,21,24,28 ; sin(0-9).db 31,34,37,40,43,46,48,51,54,57 ; sin(10-19).db 60,63,65,68,71,73,76,78,81,83 ; sin(20-29).db 85,88,90,92,94,96,98,100,102,104 ; sin(30-39).db 106,108,109,111,112,114,115,117,118,119 ; sin(40-49).db 120,121,122,123,124,124,125,126,126,127 ; sin(50-59).db 127,128,128,128 ; sin(60-63)`
Title: Re: Vectors and Sprite Scaling
Post by: Xeda112358 on February 11, 2015, 09:17:17 am
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.