It is currently Sat Aug 24, 2019 10:28 pm

 All times are UTC - 7 hours

 Page 1 of 2 [ 24 posts ] Go to page 1, 2  Next
 Print view Previous topic | Next topic
Author Message
 Post subject: How to describe a circle trajectory on nes?Posted: Thu Dec 28, 2017 9:41 am

Joined: Sun Jun 11, 2017 5:39 pm
Posts: 66
Simple, I know radius and angle.

I want to obtain X and Y positions

In real life, I would simply use sinus for the first unknown, then pythagore for the second one.

However I don't have a sin function neither a square root function.

I wouldn't want to enter values by hand in an array...

is there a better way?

Top

 Post subject: Re: How to describe a circle trajectory on nes?Posted: Thu Dec 28, 2017 9:46 am

Joined: Sun Jan 22, 2012 12:03 pm
Posts: 7568
A lookup table is effective, but since you've ruled that out...

If you can compromise on the shape a little bit, and would accept a circle-like curve, you might try a second-order approximation by just accelerating something alternately up, right, left, down at a fixed rate. i.e. accelerate right for 1 second, then accelerate down for 1 second... the object should travel in a stable curved path. Controlling the speed and radius specifically is a bit tricky, but it's not too hard to just tweak it until it looks right as an easier method.

* Also your starting velocity has to be 90 degrees rotated from your starting acceleration, or else you might get a diagonal oscillation instead of circular, i.e. if you start by accelerating up, set the initial velocity to full left, etc.

You can also use this kind of thing to seek toward a point, the value you clamp velocity at will determine the radius of the orbit.

You can also use this idea in 2D for a simple up-down sine-like motion (e.g. castlevania medusa).

Last edited by rainwarrior on Thu Dec 28, 2017 11:58 am, edited 1 time in total.

Top

 Post subject: Re: How to describe a circle trajectory on nes?Posted: Thu Dec 28, 2017 10:12 am

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 21564
Location: NE Indiana, USA (NTSC)
MartsINY wrote:
Simple, I know radius and angle.

I want to obtain X and Y positions
[...]
I wouldn't want to enter values by hand in an array...

is there a better way?

Yes: a Python script to generate the array that you bake into the ROM.

_________________
Pin Eight | Twitter | GitHub | Patreon

Top

 Post subject: Re: How to describe a circle trajectory on nes?Posted: Thu Dec 28, 2017 10:14 am

Joined: Sun Jun 11, 2017 5:39 pm
Posts: 66
tepples wrote:
MartsINY wrote:
Simple, I know radius and angle.

I want to obtain X and Y positions
[...]
I wouldn't want to enter values by hand in an array...

is there a better way?

Yes: a Python script to generate the array that you bake into the ROM.

Is that easy to incorporate the python script? Can you export the assembly and use it somehow?

Top

 Post subject: Re: How to describe a circle trajectory on nes?Posted: Thu Dec 28, 2017 10:19 am

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 21564
Location: NE Indiana, USA (NTSC)
A table generator program just needs to write a file full of .byte statements that you .include in your main assembly file. An example of such a table generator for an exponential function is at APU period table. It should be straightforward to adapt it to a sine table.

_________________
Pin Eight | Twitter | GitHub | Patreon

Top

 Post subject: Re: How to describe a circle trajectory on nes?Posted: Thu Dec 28, 2017 10:19 am

Joined: Thu Aug 13, 2015 4:40 pm
Posts: 416
Location: Rio de Janeiro - Brazil
Isn't that doing exactly what you said you didn't want to do? rainwarrior's solution looks good.

_________________

Top

 Post subject: Re: How to describe a circle trajectory on nes?Posted: Thu Dec 28, 2017 10:20 am

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 21564
Location: NE Indiana, USA (NTSC)
A table generator avoids the "by hand" in "I wouldn't want to enter values by hand in an array."

_________________
Pin Eight | Twitter | GitHub | Patreon

Top

 Post subject: Re: How to describe a circle trajectory on nes?Posted: Thu Dec 28, 2017 10:22 am

Joined: Sun Jun 11, 2017 5:39 pm
Posts: 66
nesrocks wrote:
Isn't that doing exactly what you said you didn't want to do? rainwarrior's solution looks good.

yeah I though of a table with X and Y this I didn't want.

However a table with sin and cos values would be better.

I will generate one through matlab

thanks!!

Top

 Post subject: Re: How to describe a circle trajectory on nes?Posted: Thu Dec 28, 2017 11:01 am

Joined: Sat Feb 12, 2005 9:43 pm
Posts: 11401
Location: Rio de Janeiro - Brazil
MartsINY wrote:
However a table with sin and cos values would be better.

But then you need multiplications to do anything useful with those look-up tables. The 6502 isn't particularly good with multiplications, but you can do a handful of them per frame if you really need to. Just something to keep in mind.

Top

 Post subject: Re: How to describe a circle trajectory on nes?Posted: Thu Dec 28, 2017 11:47 am

Joined: Sun Jun 11, 2017 5:39 pm
Posts: 66
tokumaru wrote:
MartsINY wrote:
However a table with sin and cos values would be better.

But then you need multiplications to do anything useful with those look-up tables. The 6502 isn't particularly good with multiplications, but you can do a handful of them per frame if you really need to. Just something to keep in mind.

thanks!! actually I'm lucky mega man has a multiplication function!!

Top

 Post subject: Re: How to describe a circle trajectory on nes?Posted: Fri Dec 29, 2017 11:45 am

Joined: Wed May 19, 2010 6:12 pm
Posts: 2885
There is a way to multiplying a sine wave by adding two sine waves. I'm not sure how much precision it would have.

Top

 Post subject: Re: How to describe a circle trajectory on nes?Posted: Fri Dec 29, 2017 11:54 am

Joined: Tue Apr 04, 2017 1:22 pm
Posts: 38
Location: Ohio, USA
If you really want to do it without a lookup table, you could approximate the value using the Taylor series for sin/cos, calculated out to some degree of precision.
https://en.wikipedia.org/wiki/Taylor_series#Trigonometric_functions

But then you'd need functions for division, exponentiation, and factorial all without lookup tables...
By the time you coded that all up, it would likely use more ROM than just having the original, single lookup table.

_________________
http://zutanogames.com/ <-- my dev blog

Top

 Post subject: Re: How to describe a circle trajectory on nes?Posted: Fri Dec 29, 2017 12:15 pm

Joined: Sun Jan 22, 2012 12:03 pm
Posts: 7568
Those Taylor series are just one of many ways to compute that stuff, and they're really not a good way to go about it on 6502.

This is a well known set of techniques that's actually designed for this kind of hardware:
https://en.wikipedia.org/wiki/CORDIC

psycopathicteen wrote:
There is a way to multiplying a sine wave by adding two sine waves. I'm not sure how much precision it would have.

Yes, it's due to the family of identities that relate multiplication to sum and difference, e.g.:

cos(a) * cos(b) = (cos(a+b) + cos(a-b)) / 2

So if you have a cosine/sine table, you can get the multiplied result with a few sums, a few lookups, and a shift. Each step loses some precision, yes. I've half-written an NES demo experimenting with this concept but I haven't gotten around to finishing it yet.

Though, if you only need one size of circle you don't need any multiplication, just scale your sine table to the size of the circle to begin with. You only need to be multiplying if you are trying to reuse one sine table at various scales.

Top

 Post subject: Re: How to describe a circle trajectory on nes?Posted: Fri Dec 29, 2017 2:26 pm

Joined: Wed May 19, 2010 6:12 pm
Posts: 2885
If the sine table goes from -127 to 127, you would need at least 1024 sine table entries for every step.

Top

 Post subject: Re: How to describe a circle trajectory on nes?Posted: Fri Dec 29, 2017 5:36 pm

Joined: Sun Jan 22, 2012 12:03 pm
Posts: 7568
Where does the number 1024 come from?

The table is not a sine table but a sine * radius table. If you want to make a circle trajectory with a table, you only need as many entries as desired angles and radii. The only reason to have a sine table with separate multiplication step is if you need to have many different radius trajectories, or some other use for the sine.

e.g. If you only wanted a single radius, and to travel the circle in 64 frames, you could just have 64 entries in the table. You could also interpolate entries to shrink the table size as well, if you wanted to make some size/accuracy trade.

Last edited by rainwarrior on Fri Dec 29, 2017 6:12 pm, edited 2 times in total.

Top

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 2 [ 24 posts ] Go to page 1, 2  Next

 All times are UTC - 7 hours

#### Who is online

Users browsing this forum: No registered users and 2 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       2019 NESdev Competition       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