Page 2 of 2
Re: Turning an image
Posted: Mon Apr 11, 2011 9:23 pm
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?
Re: Turning an image
Posted: Mon Apr 11, 2011 9:25 pm
by Jasoco
Wouldn't these work:
math.rad()
math.deg()
?
Re: Turning an image
Posted: Tue Apr 12, 2011 5:32 am
by Robin
Jasoco wrote:Wouldn't these work:
math.rad()
math.deg()
?
Yes. math.rad() is the one LuaWeaver needs.
Re: Turning an image
Posted: Tue Apr 12, 2011 5:39 pm
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.