Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Positive07
Party member
Posts: 1006
Joined: Sun Aug 12, 2012 4:34 pm
Location: Argentina

I'm pretty sure what xNick1 wrote would work in any device. It doesn't deal with multitouch so it will only detect a single finger, but it will work nonetheless.

If you need multitouch then what 4aiman said is better fit for the task.

Note that the first finger is mapped to the [wiki]love.mouse[/wiki] module, while if you need multitouch you should use [wiki]love.touch[/wiki] module
for i, person in ipairs(everybody) do
[tab]if not person.obey then person:setObey(true) end
end
love.system.openURL(Github.com/Positive07)

xNick1
Party member
Posts: 265
Joined: Wed Jun 15, 2016 8:27 am
Location: Rome, Italy

Positive07 wrote:I'm pretty sure what xNick1 wrote would work in any device. It doesn't deal with multitouch so it will only detect a single finger, but it will work nonetheless.

If you need multitouch then what 4aiman said is better fit for the task.

Note that the first finger is mapped to the [wiki]love.mouse[/wiki] module, while if you need multitouch you should use [wiki]love.touch[/wiki] module
Thanks man.
Very useful info as always
Currently working on a lucid dreaming adventure called Aarstider: http://bit.ly/2mXmgPI

c4p14in3_
Prole
Posts: 4
Joined: Wed Jan 04, 2017 10:52 pm

Hello, it's my first time of this forum so sorry if I sound dumb.

So I was playing with the flux tweening library and I wanted to tween the radius of my object so it can follow my mouse smoothly
but when the radius go from -3 to 3 the tweening go the other way around.
I understand that it's because i divide by 0 in the radius operation but I don't know how to correct it.

I you don't understand what i'm trying to say just play my code and you will understand directly.
main.lua
flux.lua
rectangle.jpg (2.02 KiB) Viewed 2501 times
thanks.

drunken_munki
Party member
Posts: 134
Joined: Tue Mar 29, 2011 11:05 pm

c4p14in3_ wrote:... I wanted to tween the radius of my object so it can follow my mouse smoothly...
Ok I went from here, I didn't use flux because I just wanted to see the issue you had, maybe this helps?

Code: Select all

--- Settings
local trackDelay       = 0.9 -- Slows down the tracking as it come closer to the target
local trackSpeed       = 2   -- General speed of the tracking

--- Locals
local rectangle        = nil
local centreX, centreY = nil, nil
local repereX, repereY = nil, nil
local angle            = 0
local currentAngle     = 0
local deltaAngle       = 0

rectangle            = love.graphics.newImage("rectangle.jpg")

centreX, centreY     = rectangle:getDimensions()
centreX              = centreX * 0.5
centreY              = centreY * 0.5

repereX, repereY     = love.graphics.getDimensions()
repereX              = repereX * 0.5
repereY              = repereY * 0.5

end

function love.update(dt)

--- Problem #1
-- This effectively goes from 0 to 180 (in degrees) if the mouse was below the centre and 0 to -180 when above:
angle                = math.atan2((love.mouse.getY() - repereY), (love.mouse.getX() - repereX))

-- So I re-purpose the angle to go from 0 -> 360:
local angle_deg      = math.deg(angle)
if angle_deg < 0 then
angle_deg          = angle_deg + 360
end

--- Problem #2
-- We create a new variable to store the current 'rendering' angle of the shape;
-- and we can slowly transition it towards the target angle.
-- So I start with the difference between the two, which would be positive if the shape
-- needs to track clockwise to the mouse, and negative to track anti-clockwise:
deltaAngle           = (angle - currentAngle)

--- Problem #3
-- The cross over from any point at 360 -> 0 degrees would make the transition loop all the way around;
-- so correct the deltaAngle to just continue:
if math.deg(deltaAngle) < -180 then
end

-- Finally, slowly transition the current angle towards the target angle:
currentAngle         = currentAngle + (deltaAngle * trackDelay * dt) * trackSpeed
-- currentAngle         = angle -- This would be the original movement

end

function love.mousepressed(mouseX, mouseY, button)
if button == 1 then
repereX = mouseX
repereY = mouseY
end

end

function twoDP(val)
return string.format("%5.2f", val)
end

function love.draw()

love.graphics.line(0, repereY, 800, repereY)
love.graphics.line(repereX, 0, repereX, 600)
love.graphics.draw(rectangle, repereX, repereY, currentAngle, _, _, centreX, centreY)

love.graphics.print("mouse angle: " .. twoDP(angle) .. ", " .. twoDP(math.deg(angle)), 0, 0)
love.graphics.print("current angle: " .. twoDP(currentAngle) .. ", " .. twoDP(math.deg(currentAngle)), 0, 30)
love.graphics.print("delta angle: " .. twoDP(deltaAngle) .. ", " .. twoDP(math.deg(deltaAngle)), 0, 60)

end
Ah crap there might still be an issue somewhere in all that.

If the thing is rotating one way, and you move the mouse the other way the transition looks a bit 'hard' when it changes direction... maybe it needs something clever here to make it softer.

Also, sometimes it goes a full ~270 degrees when it could just go -90. There might be a glitch somewhere, Sorry :/

zorg
Party member
Posts: 2801
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

c4p14in3_ wrote:(...)
Just do math.abs() on it so the sign won't matter... though that may not work as you want it to either.
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.

bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact: