Bug found with math.rad

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
WhoppaGamer
Prole
Posts: 3
Joined: Fri Mar 31, 2023 1:09 pm

Bug found with math.rad

Post 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
WhoppaGamer
Prole
Posts: 3
Joined: Fri Mar 31, 2023 1:09 pm

Re: Bug found with math.rad

Post 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
User avatar
Bigfoot71
Party member
Posts: 287
Joined: Fri Mar 11, 2022 11:07 am

Re: Bug found with math.rad

Post 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.
My avatar code for the curious :D V1, V2, V3.
WhoppaGamer
Prole
Posts: 3
Joined: Fri Mar 31, 2023 1:09 pm

Re: Bug found with math.rad

Post by WhoppaGamer »

thanks for your answer, I discovered that I wanted to rotate by 270 instead of 180, seems my math knowledge is optimizable.
Post Reply

Who is online

Users browsing this forum: No registered users and 19 guests