Page 1 of 1

bgRotate() Rotate from center of graphic

Posted: Wed Sep 30, 2009 1:15 pm
by tomjkear
Hi,

I am new to development for the NDS but I am familiar with C++ and common programming concepts. Basically I am using grit to load a 16 bit .png image in as a background. I am then trying to make the background rotate in either direction.

I have found the function bgRotate() which I can use to rotate the background in an anti-clockwise direction around the top left corner. Can anyone tell me how I can rotate the graphic around its center point rather than the top left corner? I have already attempted to use the bgSetCenter() function but instead of keeping the background at its original coodinates and only moving the center point for the rotation, the image is being moved also.

I have Googled my socks off but cannot find anything that makes it any clearer to me. Any help would be much appreciated.

Cheers,
Tom

Re: bgRotate() Rotate from center of graphic

Posted: Wed Sep 30, 2009 6:21 pm
by Sylus101
The example under (your devkitpro install dir)\examples\nds\Graphics\Backgrounds\rotation\

Should be of great help.

Re: bgRotate() Rotate from center of graphic

Posted: Wed Sep 30, 2009 6:25 pm
by vuurrobin
AFAIK, the only way to rotate a background with the center as its rotation point is to rotate it from the top-left, and then move the background position to the correct place using some calculations. which is what the background api is doing. if it doesn't work then I think there is a bug in the calculations.

could you describe what is going wrong some more? does the background still rotate, where does its position move to ect. this might help finding the bug.


edit: sylus beats me to it <.< . check the examples to see if that works.

Re: bgRotate() Rotate from center of graphic

Posted: Wed Sep 30, 2009 6:50 pm
by tomjkear
Sylus101 wrote:The example under (your devkitpro install dir)\examples\nds\Graphics\Backgrounds\rotation\

Should be of great help.
Brilliant, I will take a look right away. Thanks for pointing that one out ;)
vuurrobin wrote:AFAIK, the only way to rotate a background with the center as its rotation point is to rotate it from the top-left, and then move the background position to the correct place using some calculations. which is what the background api is doing. if it doesn't work then I think there is a bug in the calculations.

could you describe what is going wrong some more? does the background still rotate, where does its position move to ect. this might help finding the bug.
The background rotates perfectly, but only around the top left corner. Moving the rotation centre actually moves the top left corner of the background. It therefore continues to rotate around the top left corner but with said corner positioned where the rotation centre was set to.

Re: bgRotate() Rotate from center of graphic

Posted: Wed Sep 30, 2009 7:00 pm
by tomjkear
Sylus101 wrote:The example under (your devkitpro install dir)\examples\nds\Graphics\Backgrounds\rotation\

Should be of great help.
Dude, this example is EXACTLY what I was after. You legend! :D