gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Graphics > Rotating Background Issue

#112836 - Edelnutte - Wed Dec 20, 2006 7:37 pm

Hi, as the title might tell you, I have a question about rotatable BG's.
I read and understood how PA PA PB and PC affect the Background. But i can just scale them like this:
Code:

         /                   /
       /                   /
     /                   /
   


But how I want it is like this
Code:

         /                 \
       /                     \
     /                         \


Can anyone tell me how to do that please ?????

#112843 - DekuTree64 - Wed Dec 20, 2006 8:04 pm

The only way to do that is by changing the parameters each scanline during HBlank. The effect is usually called "mode 7", in reference to the mode on SNES that had a rotate/scale background.

How to actually calculate those parameters is a bit more difficult. The way I've done it before is by tracing the edges of a triangle (effectively a 2D view frustum) and setting the starting x/y to the left coordinate, and PA to (xRight - xLeft) / screenWidth, and PB to (yRight - yLeft) / screenWidth. PC and PD don't matter, since you're overwriting the current X and Y coordinates at the start of each scanline anyway.

I can give a better explanation later once I can check my old code, if that's not enough to go off of.
_________________
___________
The best optimization is to do nothing at all.
Therefore a fully optimized program doesn't exist.
-Deku

#112858 - Peter - Wed Dec 20, 2006 9:48 pm

DekuTree64 wrote:
The only way to do that is by changing the parameters each scanline during HBlank. The effect is usually called "mode 7" ...

You can find detailed information about this in TONC: Mode 7 and TONC: More Mode7 Tricks.

#112860 - Edelnutte - Wed Dec 20, 2006 10:09 pm

Thank you both. I already looked at TONC's Tutorial but not so close since I wanted to make it all by myself.
So DekuTree64 did I understand you righ, by changing the parameters each HBL-Scanline I just "mix" a BG that is scaled left with one that is scaled right to achieve that effect?

#112867 - tepples - Wed Dec 20, 2006 10:49 pm

Pretty much. For each scanline, you calculate the texel coordinate of the left side of the screen and the texel coordinate of the right side. Each scanline's data then consists of texel origin (left) and step size (right - left / 240).
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.