Page 1 of 1

Bug found with math.rad

Posted: Fri Mar 31, 2023 1:16 pm
by WhoppaGamer
Found a bug with math.rad: If I want to rotate by 180 instead of 90 in the following code snippet, the last line seems to rotate not by 180 but by 45 or something

local wall_width = wall:getWidth()
for i=0,(windowWidth/wall_width)+1 do
love.graphics.draw(wall, 0-wall_width+10, i*wall_width)
love.graphics.draw(wall, windowWidth-10, i*wall_width)

love.graphics.draw(wall, i*wall_width, -wall_width+10, math.rad(90))
love.graphics.draw(wall, i*wall_width, windowHeight-10, math.rad(180))
end

Re: Bug found with math.rad

Posted: Fri Mar 31, 2023 1:42 pm
by WhoppaGamer
Got it working perfectly with the following code, but there seems to be a problem with 180 degree rotation

local wall_width = wall:getWidth()
local wall_height = wall:getHeight()

for i=0,(windowWidth/wall_height)+1 do
love.graphics.draw(wall, 0-wall_width+10, i*wall_height)
love.graphics.draw(wall, windowWidth-10, i*wall_height)

love.graphics.draw(wall, i*wall_height, -wall_width+10, math.rad(90))
love.graphics.draw(wall, i*wall_height, windowHeight-10, math.rad(90))
end

Re: Bug found with math.rad

Posted: Fri Mar 31, 2023 1:51 pm
by Bigfoot71
There is no reason, here is the response from the Lua interpreter:

Code: Select all

Lua 5.1.5  Copyright (C) 1994-2012 Lua.org, PUC-Rio
> print(math.rad(180), math.pi)
3.1415926535898	3.1415926535898
Put math.pi instead (it's 180° in radians), if the problem is still present wouldn't it be rather the orientation of your image? (I mean the file itself)

Don't forget to define ox,oy with the center of the image. Maybe that's your problem too, it's about the origin of the image, by default it's 0.0 so the image will rotate from the top left point of the image, you should do something like this:

Code: Select all

local wall_width = wall:getWidth()
local wall_height = wall:getHeight()

for i=0,(windowWidth/wall_height)+1 do
  love.graphics.draw(wall, 0-wall_width+10, i*wall_height)
  love.graphics.draw(wall, windowWidth-10, i*wall_height)

  love.graphics.draw(wall, i*wall_height, -wall_width+10, math.rad(90), 1, 1, wall_width/2, wall_height/2)
  love.graphics.draw(wall, i*wall_height, windowHeight-10, math.rad(90), 1, 1, wall_width/2, wall_height/2)
end
The wiki page if you want to know more: https://love2d.org/wiki/love.graphics.draw

Otherwise share your complete code so that we can try.

Re: Bug found with math.rad

Posted: Sat Apr 01, 2023 8:11 pm
by WhoppaGamer
thanks for your answer, I discovered that I wanted to rotate by 270 instead of 180, seems my math knowledge is optimizable.