Struggling with arcs (and trig!)
Posted: Fri Apr 17, 2015 7:31 pm
I'm creating a simple clock program and trying to make it so that the user can highlight an arc of time to give a visual reference for how much time is remaining until some certain future point.
It works fairly well right now unless you swipe across the vertical axis. The angle changes from 4.7 to -1.57 because the arctan function doesn't know the difference between the ratio of a -y/-x and y/x.
Any suggestions?
It works fairly well right now unless you swipe across the vertical axis. The angle changes from 4.7 to -1.57 because the arctan function doesn't know the difference between the ratio of a -y/-x and y/x.
Any suggestions?
Code: Select all
function love.draw()
drawTime()
love.graphics.setColor(255,0,0)
if (startingAngle ~= nil) and (endingAngle ~= nil) then
love.graphics.arc("fill", originX, originY, love.graphics.getWidth()/4, startingAngle, endingAngle, 500)
end
love.graphics.setColor(0,0,0)
love.graphics.print("startingAngle: " .. (startingAngle or 0), 0, 25)
love.graphics.print("endingAngle: " .. (endingAngle or 0), 0, 50)
radius = love.graphics.getWidth()/4
love.graphics.circle("line",originX,originY,love.graphics.getWidth()/4)
drawClockFace()
drawClockHand()
end
function love.update()
checkTime()
if love.mouse.isDown("l") then
angleX = love.mouse.getX() - originX
angleY = love.mouse.getY() - originY
endingAngle = math.atan(angleY/angleX)
if love.mouse.getX() <= originX then
endingAngle = endingAngle + math.pi
end
end
end
function love.mousepressed( x, y, button )
if button == "r" then
drawArc = 0
end
if button == "l" then
angleX = love.mouse.getX() - originX
angleY = love.mouse.getY() - originY
startingAngle = math.atan(angleY/angleX)
if love.mouse.getX() <= originX then
startingAngle = startingAngle + math.pi
end
end
end