#171494 - genecyst - Mon Nov 23, 2009 1:46 pm
hi, i'm trying to rotate a background (bg2 - mode 1) having as centre two coordinates x,y; reading tonc I haven't understand how he can place x and y where he want. there's someone who should explain it in a simpler way?
thanks a lot.
#171496 - Cearn - Mon Nov 23, 2009 4:25 pm
It helps if you look at the situation as if there are two centers of rotation, not one. There's one on the map (m0), and one on the screen (s0). The trouble is that the hardware only allows one BG scrolling offset (b), so you have to combine the map/screen points somehow. To do that you use:
b = m0 - P?s0
The interpretation of this is that you start with the reference point on the map, which is the standard scrolling offset, and then add a correction factor that accounts for where the rotation point should be on the screen.
In code it would look something like this (just watch your fixed point calculations):
Code: |
P = matrix { pa, pb, pc, pd } = REG_BGnPA - REG_BGnPD
m0 = (mapX0, mapY0)
s0 = (screenX0, screenY0)
b = (scrollX, scrollY) = (REG_BGnX, REG_BGnY)
scrollX = mapX0 - (pa*screenX0 + pb*screenY0);
scrollY = mapY0 - (pc*screenX0 + pd*screenY0);
|
Side note: this is actually similar to the two different ways of writing down a straight line. You can have
and
In the first expression, b is the intercept at x=0. The second expression is written in relative coordinates: you have an arbitrary starting point (x0, y0) that serves as the reference point for the expression. Change a and you'll see that the line basically rotates around (x0, y0).
What happens in the case of BG rotation is essentially the same thing: you have to translate from the second form to the first.
Last edited by Cearn on Mon Nov 23, 2009 5:10 pm; edited 1 time in total
#171497 - genecyst - Mon Nov 23, 2009 4:36 pm
it makes sense. tonight i'll try it out.
as usually thanks a lot Cearn.
#171498 - Cearn - Mon Nov 23, 2009 5:08 pm
<deleted>
Argh, that was not the 'edit' button. nvm.
#172006 - Erik Carrick - Fri Jan 08, 2010 9:23 am
Cearn have you done with it? I am too querying for the same. did you get results?
_________________
craft ideas | india news
#172008 - Ruben - Fri Jan 08, 2010 10:36 am
Cearn knows a LOT about mathematics, and has many demos, so I'm quite sure he's had correct results ;D
The code above is really as best explained as it can be, IMHO.
EDIT:
Here's a little demo I just pulled together (with source, duh =P), where the image rotates from center of the screen at (120, 80): link
#172402 - dovoto - Thu Feb 04, 2010 11:03 pm
http://libnds.devkitpro.org/a00111.html#g45a4ac9093b1fed3d0d205aac39164d4
doesnt work for you or you simply trying to do it manually for self education?
_________________
www.drunkencoders.com
#172420 - genecyst - Fri Feb 05, 2010 9:35 am
your second option is the right one!
almost right... i code for gba, not nds... :D