#101583 - Omegas - Wed Sep 06, 2006 7:09 pm
I'm trying to rotate a 256x256 exrot background around the center of the screen (x=128, y=96). The BG_Rotation libnds example looks like it's trying to accomplish this so I took the code and tried it with my own images. I soon noticed that the rotation seems to be off-center for some reason. To confirm this I made a test background that has a dot in the middle and a crosshair showing where the rotation center should be. You can download this test at http://www.vilminko.net/henri/nds/rot_test.zip. The code is taken from the rotation example, I just added the crosshair image on BG2. Use L/R to rotate the image and you'll see that the center of rotation lies a dozen pixels down and left from the middle point of the screen.
Please don't tell me to read the Tonc chapter about affine transformations... That's what I did first and didn't find anything useful about rotating and scrolling backgrounds at the same time. I would appreciate it if someone could tell me how this bit is derived though:
(s and c being the sine and the cosine of the current rotation angle and rcX, rcY the coordinates the image should rotate about)
Last edited by Omegas on Thu Sep 07, 2006 3:16 pm; edited 1 time in total
Please don't tell me to read the Tonc chapter about affine transformations... That's what I did first and didn't find anything useful about rotating and scrolling backgrounds at the same time. I would appreciate it if someone could tell me how this bit is derived though:
Code: |
BG3_CX = (scrollX<<8) - rcX * (c - s);
BG3_CY = (scrollY<<8) - rcY * (s + c); |
(s and c being the sine and the cosine of the current rotation angle and rcX, rcY the coordinates the image should rotate about)
Last edited by Omegas on Thu Sep 07, 2006 3:16 pm; edited 1 time in total