Page 91 of 91
Re: "Questions that don't deserve their own thread" thread
Posted: Thu Jan 05, 2017 3:41 am
by Positive07
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
Re: "Questions that don't deserve their own thread" thread
Posted: Fri Jan 06, 2017 7:35 am
by xNick1
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
Re: "Questions that don't deserve their own thread" thread
Posted: Fri Jan 06, 2017 9:12 am
by c4p14in3_
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
- (784 Bytes) Downloaded 380 times
- flux.lua
- (5.02 KiB) Downloaded 368 times
- rectangle.jpg (2.02 KiB) Viewed 9038 times
thanks.
Re: "Questions that don't deserve their own thread" thread
Posted: Fri Jan 06, 2017 1:13 pm
by drunken_munki
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
function love.load()
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
angle = math.rad(angle_deg)
--- 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
deltaAngle = math.rad(math.deg(deltaAngle) + 360)
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 :/
Re: "Questions that don't deserve their own thread" thread
Posted: Fri Jan 06, 2017 2:11 pm
by zorg
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.
Re: "Questions that don't deserve their own thread" thread
Posted: Sun Jan 08, 2017 11:44 am
by bartbes
After over 90 pages of.. well, a mess, I think it's time we close this topic. If you've got a question you feel doesn't deserve its own thread: don't ask it. And if that doesn't help, it clearly deserves its own thread.