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
Bug found with math.rad
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
-
- Prole
- Posts: 3
- Joined: Fri Mar 31, 2023 1:09 pm
Re: Bug found with math.rad
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
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
There is no reason, here is the response from the Lua interpreter:
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:
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.
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
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
Otherwise share your complete code so that we can try.
-
- Prole
- Posts: 3
- Joined: Fri Mar 31, 2023 1:09 pm
Re: Bug found with math.rad
thanks for your answer, I discovered that I wanted to rotate by 270 instead of 180, seems my math knowledge is optimizable.
Who is online
Users browsing this forum: Ahrefs [Bot], Google [Bot] and 4 guests