"Questions that don't deserve their own thread" thread

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.
User avatar
Positive07
Party member
Posts: 1014
Joined: Sun Aug 12, 2012 4:34 pm
Location: Argentina

Re: "Questions that don't deserve their own thread" thread

Post 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
for i, person in ipairs(everybody) do
[tab]if not person.obey then person:setObey(true) end
end
love.system.openURL(github.com/pablomayobre)
User avatar
xNick1
Party member
Posts: 267
Joined: Wed Jun 15, 2016 8:27 am
Location: Rome, Italy

Re: "Questions that don't deserve their own thread" thread

Post 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 :D
c4p14in3_
Prole
Posts: 4
Joined: Wed Jan 04, 2017 10:52 pm

Re: "Questions that don't deserve their own thread" thread

Post 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 277 times
flux.lua
(5.02 KiB) Downloaded 272 times
rectangle.jpg
rectangle.jpg (2.02 KiB) Viewed 7832 times
thanks.
drunken_munki
Party member
Posts: 134
Joined: Tue Mar 29, 2011 11:05 pm

Re: "Questions that don't deserve their own thread" thread

Post 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 :/
User avatar
zorg
Party member
Posts: 3436
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: "Questions that don't deserve their own thread" thread

Post 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.
Me and my stuff :3True 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.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: "Questions that don't deserve their own thread" thread

Post 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.
Locked

Who is online

Users browsing this forum: Google [Bot] and 50 guests