Page 1 of 1

Rotating the camera from the center rather than the top left

Posted: Sat Sep 06, 2014 9:01 pm
by Snackrilege
[Semi Solved. There is a great library than handles all this for you.]

hey! If anyone finds this via search, check out kikito's library, which he discusses in this thread! -- viewtopic.php?f=4&t=78216&p=173448#p173448

------------------------------------------------------




Hey, folks! first post.

So. the camera tutorial here http://love2d.org/wiki/Tutorial:Camerasis phenomenal.

It teaches you how to create a camera which can, among other things, rotate via the upper left corner, like this Image

and says, essentially, if you want to be able to do this:
Image

then do some math.... well, I've been racking my brain to find the answer, but I can not figure out how to perform the correct shift. Can anyone help me out?

Re: Rotating the camera from the center rather than the top

Posted: Sun Sep 07, 2014 12:49 am
by furi
Try using [wiki]love.graphics.push[/wiki], [wiki]love.graphics.pop[/wiki], [wiki]love.graphics.translate[/wiki] and [wiki]love.graphics.rotate[/wiki] in tandem. Love.graphics.push will save the current graphics translation so you can draw objects properly after the rotation. Love.graphics.pop will load that translation. The other two are fairly self-explanatory.

Code: Select all

love.graphics.push();
love.graphics.translate(-(love.graphics.getWidth()/2),-(love.graphics.getHeight()/2));
love.graphits.rotate(90);
--insert your code here
love.graphics.pop();
--insert your interface code here
Let me know if this works.

Edit: Thanks to Daedalus for further explaining. I'm not in peak condition right now, so my descriptiveness is somewhat suspect.

Re: Rotating the camera from the center rather than the top

Posted: Sun Sep 07, 2014 1:19 am
by DaedalusYoung
To clarify, love.graphics.translate moves the camera (or the coordinate system, depending on how you see it). The posted code will place the 0,0 coordinate in the centre of the screen, so you will need to shift everything you draw by the same amount to still have it on the right position on the screen. It might be easier to assign local variables instead of calling getWidth and getHeight for every draw call.
Love.graphics.rotate then simply rotates the camera around the 0,0 coordinate, which with this code now is the centre of the screen.