has anyone made an API for rotation?

General discussion about LÖVE, Lua, game development, puns, and unicorns.
User avatar
Lua Hal
Citizen
Posts: 58
Joined: Tue Jul 12, 2011 10:30 pm

has anyone made an API for rotation?

Post 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.
User avatar
Lafolie
Inner party member
Posts: 809
Joined: Tue Apr 05, 2011 2:59 pm
Location: SR388
Contact:

Re: has anyone made an API for rotation?

Post by Lafolie »

It's pretty easy to convert degrees to radians, and you should check out the parameters for love.graphics.draw.
Do you recognise when the world won't stop for you? Or when the days don't care what you've got to do? When the weight's too tough to lift up, what do you? Don't let them choose for you, that's on you.
User avatar
tentus
Inner party member
Posts: 1060
Joined: Sun Oct 31, 2010 7:56 pm
Location: Appalachia
Contact:

Re: has anyone made an API for rotation?

Post by tentus »

There's also love.graphics.rotate (which uses radians).
Kurosuke needs beta testers
User avatar
schael
Prole
Posts: 27
Joined: Mon Jul 11, 2011 5:13 pm
Location: France

Re: has anyone made an API for rotation?

Post by schael »

To convert degrees to radians you have to do pi*deg/180=rad
because 180 deg = pi rad
Last edited by schael on Wed Jul 13, 2011 7:21 pm, edited 1 time in total.
I'm learning...
User avatar
thelinx
The Strongest
Posts: 857
Joined: Fri Sep 26, 2008 3:56 pm
Location: Sweden

Re: has anyone made an API for rotation?

Post by thelinx »

Or you could just use math.rad/deg
User avatar
Lua Hal
Citizen
Posts: 58
Joined: Tue Jul 12, 2011 10:30 pm

Re: has anyone made an API for rotation?

Post by Lua Hal »

Yes, but it rotates around the center of the screen, I want to rotate around the center of the object.
User avatar
vrld
Party member
Posts: 917
Joined: Sun Apr 04, 2010 9:14 pm
Location: Germany
Contact:

Re: has anyone made an API for rotation?

Post 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.)
I have come here to chew bubblegum and kick ass... and I'm all out of bubblegum.

hump | HC | SUIT | moonshine
User avatar
BlackBulletIV
Inner party member
Posts: 1261
Joined: Wed Dec 29, 2010 8:19 pm
Location: Queensland, Australia
Contact:

Re: has anyone made an API for rotation?

Post 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)
Last edited by BlackBulletIV on Thu Jul 14, 2011 2:28 am, edited 1 time in total.
User avatar
slime
Solid Snayke
Posts: 3132
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: has anyone made an API for rotation?

Post 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)
User avatar
BlackBulletIV
Inner party member
Posts: 1261
Joined: Wed Dec 29, 2010 8:19 pm
Location: Queensland, Australia
Contact:

Re: has anyone made an API for rotation?

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

Who is online

Users browsing this forum: Bing [Bot] and 170 guests