nesdev.com
http://forums.nesdev.com/

Best way to calculate road parallax in racing games?
http://forums.nesdev.com/viewtopic.php?f=2&t=14274
Page 1 of 1

Author:  Vectrex2809 [ Sun May 22, 2016 2:40 am ]
Post subject:  Best way to calculate road parallax in racing games?

Right now, I'm thinking about making a racing game. So far, I managed to implement a routine that can easily calculate the next frame of the road's parallax, like so

Image to Image

The only problem is that it takes a long time in CPU time to calculate the next frame, as you can see on the pic below (This is for 2 road frames at once)

Image

This could potentially be a problem when the player encounters a sharp turn or gets sent to the other side of the road quickly, as it could be the source of slowdown (Not to mention road rendering takes a ton of CPU time too)

So I would like to know if there is a better way to calculate the road's parallax, making it possible to go from the pic on the left to the pic of the right directly.

Image to Image

Author:  Memblers [ Sun May 22, 2016 4:59 am ]
Post subject:  Re: Best way to calculate road parallax in racing games?

My first thought would be a look-up table, assuming you're not limited on ROM. If your scrolling covers 128 scanlines, then you'd have 128 entries in the table with the H value for each line. Then for the left-to-right position, duplicate the table for each step. In that case, 256 steps would make a 32kB table.

Author:  Vectrex2809 [ Sun May 22, 2016 5:50 am ]
Post subject:  Re: Best way to calculate road parallax in racing games?

I thought about this actually, but I don't want to waste too much ROM space even though I'll probably end up doing it on an MMC3 because IRQs

Author:  pubby [ Sun May 22, 2016 5:52 am ]
Post subject:  Re: Best way to calculate road parallax in racing games?

I was thinking use a lookup table but only for slope values. That way it would be only 256 128 bytes and not 32k.

Quote:
So I would like to know if there is a better way to calculate the road's parallax

It would really help if you were to describe your current attempt and how you want the parallax to actually behave.

Author:  Vectrex2809 [ Sun May 22, 2016 7:40 am ]
Post subject:  Re: Best way to calculate road parallax in racing games?

So I decided to transcribe the scroll values onto a massive file and do as Memblers suggested. It seems to work fine :D - I ended up saying "*%$@ it" and going MMC3!

Author:  tokumaru [ Sun May 22, 2016 9:06 am ]
Post subject:  Re: Best way to calculate road parallax in racing games?

pubby wrote:
I was thinking use a lookup table but only for slope values. That way it would be only 256 128 bytes and not 32k.

Slope values would work, since the road is straight, not curved like in many teaching games. These values would have to be fixed-point numbers, but they can probably still fit in 8 bits. But you'd also need the initial scroll value for the topmost scanline, doubling the amount of space necessary for this approach, but that's still waaaay less than full lookup tables with values for every scanline.

Author:  Espozo [ Sun May 22, 2016 9:44 am ]
Post subject:  Re: Best way to calculate road parallax in racing games?

I can't help but feel that the road should get even smaller toward the top. It looks like it's as wide as the buildings.

Author:  Bregalad [ Sun May 22, 2016 1:02 pm ]
Post subject:  Re: Best way to calculate road parallax in racing games?

What I did in the only demo I did who does that is use an exponential curve. The top scroll value is multiplied by a fixed-point constant and goes closer to zero each line. It works pretty well, although it's probably not the only way to do that.

Rad Racer does it all with lookup tables.

Author:  mikejmoffitt [ Sun May 22, 2016 5:13 pm ]
Post subject:  Re: Best way to calculate road parallax in racing games?

Espozo wrote:
I can't help but feel that the road should get even smaller toward the top. It looks like it's as wide as the buildings.

Certainly. The only other justification is the player is going around a small sphere or up a hill, forever.

Author:  Espozo [ Sun May 22, 2016 5:20 pm ]
Post subject:  Re: Best way to calculate road parallax in racing games?

It's going around the entire planet, those buildings are actually moving backward. :lol:

Page 1 of 1 All times are UTC - 7 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/