Author Topic: Vectors and Sprite Scaling  (Read 4165 times)

0 Members and 1 Guest are viewing this topic.

Offline ACagliano

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 919
  • Rating: +32/-2
    • View Profile
    • ClrHome Productions
Vectors and Sprite Scaling
« 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.

Offline JamesV

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 276
  • Rating: +77/-0
    • View Profile
    • James V's TI-Calculator page
Re: Vectors and Sprite Scaling
« Reply #1 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 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

Offline ACagliano

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 919
  • Rating: +32/-2
    • View Profile
    • ClrHome Productions
Re: Vectors and Sprite Scaling
« Reply #2 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 :(
« Last Edit: January 14, 2015, 08:02:05 pm by ACagliano »

Offline JamesV

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 276
  • Rating: +77/-0
    • View Profile
    • James V's TI-Calculator page
Re: Vectors and Sprite Scaling
« Reply #3 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 :(

Offline chickendude

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 817
  • Rating: +90/-1
  • Pro-Riot Squad
    • View Profile
Re: Vectors and Sprite Scaling
« Reply #4 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.

Offline TheMachine02

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 452
  • Rating: +105/-0
  • me = EF99+F41A
    • View Profile
Re: Vectors and Sprite Scaling
« Reply #5 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.
AXE/asm programmer - unleash the power of z80 //C++//C

epic 3D things http://www.ntu.edu.sg/home/ehchua/programming/opengl/CG_BasicsTheory.html

Offline Sorunome

  • Fox Fox Fox Fox Fox Fox Fox!
  • Support Staff
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 7920
  • Rating: +374/-13
  • Derpy Hooves
    • View Profile
    • My website! (You might lose the game)
Re: Vectors and Sprite Scaling
« Reply #6 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))

THE GAME
Also, check out my website
If OmnomIRC is screwed up, blame me!
Click here to give me an internet!

Offline ACagliano

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 919
  • Rating: +32/-2
    • View Profile
    • ClrHome Productions
Re: Vectors and Sprite Scaling
« Reply #7 on: January 15, 2015, 11:19:01 am »
Code: [Select]
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(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)

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: Vectors and Sprite Scaling
« Reply #8 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.