Page 1 of 2

has anyone made an API for rotation?

Posted: Wed Jul 13, 2011 6:32 pm
by Lua Hal
Something like...

Code: Select all

Object = love.new.graphics.newImage("blah.jpg")
Object.Rotation = 90 --degrees
love.graphics.draw(Object,400,400)
Is this possible?

I have no idea how to use the current rotation, and this would make things easier for me.

Re: has anyone made an API for rotation?

Posted: Wed Jul 13, 2011 7:06 pm
by Lafolie
It's pretty easy to convert degrees to radians, and you should check out the parameters for love.graphics.draw.

Re: has anyone made an API for rotation?

Posted: Wed Jul 13, 2011 7:18 pm
by tentus
There's also love.graphics.rotate (which uses radians).

Re: has anyone made an API for rotation?

Posted: Wed Jul 13, 2011 7:19 pm
by schael
To convert degrees to radians you have to do pi*deg/180=rad
because 180 deg = pi rad

Re: has anyone made an API for rotation?

Posted: Wed Jul 13, 2011 7:20 pm
by thelinx
Or you could just use math.rad/deg

Re: has anyone made an API for rotation?

Posted: Wed Jul 13, 2011 8:01 pm
by Lua Hal
Yes, but it rotates around the center of the screen, I want to rotate around the center of the object.

Re: has anyone made an API for rotation?

Posted: Wed Jul 13, 2011 8:04 pm
by vrld
love.graphics.draw(drawable, x, y, r, sx, sy, ox, oy )

Drawable drawable - A drawable object.
number x - The position to draw the object (x-axis).
number y - The position to draw the object (y-axis).
number r (0) - Orientation (radians).
number sx (1) - Scale factor (x-axis). Can be negative.
number sy (sx) - Scale factor (y-axis). Can be negative.
number ox (0) - Origin offset (x-axis). (A value of 20 would effectively move your drawable object 20 pixels to the left.)
number oy (0) - Origin offset (y-axis). (A value of 20 would effectively move your drawable object 20 pixels up.)

Re: has anyone made an API for rotation?

Posted: Thu Jul 14, 2011 1:11 am
by BlackBulletIV
As vrld has pointed out, draw origins are what you need. You may want to take a look at my tutorial on them. Basically, all you'll need to do is make sure that the x/y coordinates you specify are referring to where you want the centre of the object drawn, and then in ox and oy you'll need to specify half the width and half the height. For example:

Code: Select all

love.graphics.draw(drawable, x + width / 2, y + height / 2, rotation, 1, 1, width / 2, height / 2)

Re: has anyone made an API for rotation?

Posted: Thu Jul 14, 2011 1:27 am
by slime
The above will work if your x and y variables correspond to the top-left coordinates of the image, which doesn't make much sense if you're also adding the offset. This will work fine:

Code: Select all

love.graphics.draw(drawable, x, y, rotation, 1, 1, width / 2, height / 2)

Re: has anyone made an API for rotation?

Posted: Thu Jul 14, 2011 3:02 am
by BlackBulletIV
slime wrote:The above will work if your x and y variables correspond to the top-left coordinates of the image, which doesn't make much sense if you're also adding the offset. This will work fine:

Code: Select all

love.graphics.draw(drawable, x, y, rotation, 1, 1, width / 2, height / 2)
I realise that; it all depends on which coordinate system you use (love.graphics uses top-left, but love.physics uses centric). You've also alerted me to the fact that I was subtracting the half width and height instead of adding (which I've fixed).