It is currently Sat Jul 21, 2018 10:20 pm

 All times are UTC - 7 hours

### Forum rules

Related:
• For making cartridges of your Super NES games, see Reproduction.

 Page 1 of 1 [ 5 posts ]
 Print view Previous topic | Next topic
Author Message
 Post subject: Routines for sine and parabolic motion?Posted: Thu Dec 29, 2016 4:08 pm

Joined: Wed Sep 01, 2010 12:17 am
Posts: 7
I've been trying to figure out formulas for getting a sprite to move in a sine wave or a parabola. Getting it close isn't hard, but the problem is making it customizable and precise. Specifically, I want to be able to set the exact parameters: the height and period of the sine wave and the height, width, and direction of the parabola. It would be easier if I could hardcode the parameters, but I don't want them to be hardcoded; I want them to be options for input, which would allow different values to be used for different sprites, or even different parts of the same sprite. I'd imagine lookup tables might help, but...surely such a table would have to be very large to encompass all possible values?

Top

 Post subject: Re: Routines for sine and parabolic motion?Posted: Thu Dec 29, 2016 4:47 pm

Joined: Wed May 19, 2010 6:12 pm
Posts: 2714
I use this LUT for anything using sine and cosine.

Code:
sine:
dw 0,6,13,19,25,31,38,44,50,56,62,68,74,80,86,92,98,104,109,115,121,126,132,137,142
dw 147,152,157,162,167,172,177,181,185,190,194,198,202,206,209,213,216,220,223,226,229
dw 231,234,237,239,241,243,245,247,248,250,251,252,253,254,255,255,256,256

cosine:
dw 256,256,256
dw 255,255,254,253,252,251,250,248,247,245,243,241,239,237,234,231,229,226,223,220,216
dw 213,209,206,202,198,194,190,185,181,177,172,167,162,157,152,147,142,137,132,126,121
dw 115,109,104,98,92,86,80,74,68,62,56,50,44,38,31,25,19,13,6,0,-6,-13,-19,-25,-31,-38
dw -44,-50,-56,-62,-68,-74,-80,-86,-92,-98,-104,-109,-115,-121,-126,-132,-137,-142
dw -147,-152,-157,-162,-167,-172,-177,-181,-185,-190,-194,-198,-202,-206,-209,-213,-216
dw -220,-223,-226,-229,-231,-234,-237,-239,-241,-243,-245,-247,-248,-250,-251,-252,-253
dw -254,-255,-255,-256,-256,-256,-256,-256,-255,-255,-254,-253,-252,-251,-250,-248
dw -247,-245,-243,-241,-239,-237,-234,-231,-229,-226,-223,-220,-216,-213,-209,-206,-202
dw -198,-194,-190,-185,-181,-177,-172,-167,-162,-157,-152,-147,-142,-137,-132,-126,-121
dw -115,-109,-104,-98,-92,-86,-80,-74,-68,-62,-56,-50,-44,-38,-31,-25,-19,-13,-6
dw 0,6,13,19,25,31,38,44,50,56,62,68,74,80,86,92,98,104,109,115,121,126,132,137,142
dw 147,152,157,162,167,172,177,181,185,190,194,198,202,206,209,213,216,220,223,226,229
dw 231,234,237,239,241,243,245,247,248,250,251,252,253,254,255,255,256,256

Top

 Post subject: Re: Routines for sine and parabolic motion?Posted: Thu Dec 29, 2016 4:55 pm

Joined: Sun Mar 27, 2011 10:49 am
Posts: 254
Location: Seattle
Use a table to get the hard to compute value, but do the rest of the math on the CPU.

Supposing you have a procedure Sine to get the sine value for an angle in A (either with a table or with Real Math), you can e.g. double the amplitude easily:

Code:
LDA Angle
JSR Sine
ASL

If you want non-power of two multipliers, you can use the SNES' built-in multiplier or implement your own software multiplier.

And if you generate the table for the smallest amplitude and longest period you want, you never have to divide.

Top

 Post subject: Re: Routines for sine and parabolic motion?Posted: Thu Dec 29, 2016 5:13 pm

Joined: Sun Mar 19, 2006 9:44 pm
Posts: 953
Location: Japan
You'll need one rather large sine table. If you want different frequencies of the sinewave, I guess you'll just have to sample from it, skipping a variable # of values.

For scaling a sine wave's amplitude, you can do addition of inverse sines. You'll need 2 pointers into the same sine table. If you add the values of the table at (x) and at (pi+x), you'll get zero amplitude, for example.

Anyone got ideas for parabolas?

_________________
http://www.chrismcovell.com

Top

 Post subject: Re: Routines for sine and parabolic motion?Posted: Fri Dec 30, 2016 9:25 am

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 20282
Location: NE Indiana, USA (NTSC)
To implement parabolic motion, such as gravity, keep displacement and velocity variables for each object. Then add a constant to the velocity each frame.

Once you have this in place, you can make sinusoidal motion without tables: subtract a fraction of displacement from center from the velocity each frame. (This is a second-order differential equation whose solution is a sinusoid.) The frequency depends on this fraction.

Top

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 5 posts ]

 All times are UTC - 7 hours

#### Who is online

Users browsing this forum: skaman and 5 guests

 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum

Search for:
 Jump to:  Select a forum ------------------ NES / Famicom    NESdev    NESemdev    NES Graphics    NES Music    Homebrew Projects       2018 NESdev Competition       2017 NESdev Competition       2016 NESdev Competition       2014 NESdev Competition       2011 NESdev Competition    Newbie Help Center    NES Hardware and Flash Equipment       Reproduction    NESdev International       FCdev       NESdev China       NESdev Middle East Other    General Stuff    Membler Industries    Other Retro Dev       SNESdev       GBDev    Test Forum Site Issues    phpBB Issues    Web Issues    nesdevWiki