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.

Coding > Zooming / Rotation from tutorial explained

#7679 - einhaender - Sun Jun 22, 2003 10:11 pm

Hi all,
on pernproject.com I have found a tutorial about zooming/rotating background maps. There they are using this function to archive that:

FIXED zoom = 1<<8;
void RotateBackground(Bg* bg, int angle,int x, int y, fixed zoom)
{
y = (y * zoom)>>8;
x = (x * zoom)>>8;

bg->DX = (bg->x_scroll-y*SIN[angle]-x*COS[angle]);
bg->DY = (bg->y_scroll-y*COS[angle]+x*SIN[angle]);

bg->PA = (COS[angle]*zoom)>>8;
bg->PB = (SIN[angle]*zoom)>>8;
bg->PC = (-SIN[angle]*zoom)>>8;
bg->PD = (COS[angle]*zoom)>>8;
}

followed by updating the appropriate registers.

To calculate PA...PD values however they use a different approach than
the developer manual tells, for example PA (BGxPA) should be
1 / a * COS[0] where a is the magnification along x-axis, why is
theirs different?
I could write my own logic using the math from the manual for
calculating BGxPA ... BGxPD but unfortunately I dont know the
values to put into BG2X_L, BG2X_H and BG2Y_L, BG2Y_H.

Also I wonder, for the effect of zooming a screen-centered element exactly in the middle without going along x or y axis, I would need to modify the rotation center coordinate every time before calling the above function, right? 1 pixel per frame?

And how can I zoom faster or slower? Lots of questions, hope somebody can help me a bit. Thanks

#7725 - Lupin - Mon Jun 23, 2003 4:39 pm

this function is for sprite rotation, why do you want to mess with background rotation registers then? I think sprite and background rotation are a bit different (never tried to rotate backgrounds though)

When you rotate the sprite, the center will be spritepos+spritesize/2 (simple - the center of the sprite :)), but the sprite will of course get clipped, because an 45? rotated 32x32 sprite couldn't fit into an 32x32 area, so you will have to use the double size option specified in... i think it was attribute 0 (you should perhaps look that up in pern project tutorial), the double size option will not double size your sprite, but it will double size the area the sprite is drawn in, so you'd have to move the sprite -32 pixels at the x and y axis, because the new center is at an different position, because of the doubled size

I hope that helped

#7743 - einhaender - Mon Jun 23, 2003 9:12 pm

no, the function is for background rotation, both sprite and bg rotation go after the same arithmetic. the only major difference is that you can define a center coordinate for backgrounds.