Turning an image

General discussion about LÖVE, Lua, game development, puns, and unicorns.
LuaWeaver
Party member
Posts: 183
Joined: Wed Mar 02, 2011 11:15 pm
Location: Ohio, USA

Re: Turning an image

Post by LuaWeaver »

Would this work?

Code: Select all

deg=math.pi/180
function love.draw()
love.graphics.draw(..., 20, 20, deg*val) --Val is the number of degrees
end
Or maybe this?

Code: Select all

function math.rtd(degree) --rtd=radians to degrees
return math.pi/180/degree
end
Because math.pi/180==1 degree, and multiplying 1 by degree gives 1 degree times value, giving the degrees instead of radians? :nyu:
"your actions cause me to infer your ego is the size of three houses" -finley
User avatar
Jasoco
Inner party member
Posts: 3726
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Turning an image

Post by Jasoco »

Wouldn't these work:

math.rad()
math.deg()

?
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Turning an image

Post by Robin »

Jasoco wrote:Wouldn't these work:

math.rad()
math.deg()

?
Yes. math.rad() is the one LuaWeaver needs.
Help us help you: attach a .love.
User avatar
TheKraigose
Prole
Posts: 9
Joined: Tue Apr 12, 2011 5:20 pm
Location: Somewhere that's Hi in the middle, Round at Both Ends!
Contact:

Re: Turning an image

Post by TheKraigose »

I actually had to do this the other day for an overhead shooter I'm developing. My method is not the fastest, but it works for what I need to do.

I convert the radians to degrees, perform my calculations, then convert it back to radians using the corresponding math.* functions.

It's easier and seems to be pretty fast considering all the calculations being done:

Code: Select all

        -- Rotation code for turning right and left
	if love.keyboard.isDown("right") then
		hero.rot = math.deg(hero.rot)
		hero.rot = hero.rot + rotSpeed
		if hero.rot >= 360 then
			hero.rot = 0
		end
		hero.rot = math.rad(hero.rot)
	elseif love.keyboard.isDown("left") then
		hero.rot = math.deg(hero.rot)
		hero.rot = hero.rot - rotSpeed
		if hero.rot <= -1 then
			hero.rot = 359
		end
		hero.rot = math.rad(hero.rot)
	end
This is because I'm used to another engine which uses degrees, not radians, but the engine I was using was far less accessible than Love2D is.
Post Reply

Who is online

Users browsing this forum: No registered users and 8 guests