Rotating the camera from the center rather than the top left

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
Snackrilege
Prole
Posts: 19
Joined: Sat Sep 06, 2014 8:50 pm

Rotating the camera from the center rather than the top left

Post 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?
User avatar
furi
Citizen
Posts: 73
Joined: Sat Feb 26, 2011 8:15 pm

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

Post 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.
Last edited by furi on Sun Sep 07, 2014 1:22 am, edited 1 time in total.
User avatar
DaedalusYoung
Party member
Posts: 407
Joined: Sun Jul 14, 2013 8:04 pm

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

Post 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.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 34 guests