I'm doing a top-down shooter game, in the Asteroid vein.
I'm quite the newbie for Love2d.
I'm having a bit of trouble with rotation ... my high-school trig knowledge has atrophied.
What's gotten me is that although we're working in radians, it seems backwards. As the number increases towards 2*PI, it rotates my object CLOCKWISE when it should be counter-clockwise as I understand Radians.
Is it a fair statement that this is due to the world be rotated 180 degrees, so that origin is the upper left (not lower left) BUT I can't quite figure out how that affects clockwise vs. counter-clockwise. Or am I interpreting love.graphics.draw() incorrectly?
Rotation Q
Re: Rotation Q
This quirk is due to the fact that the Y coordinate grows downwards rather than upwards, therefore mirroring the coordinate system over the horizontal X axis with respect to the normal conventions.hlship wrote: ↑Sat May 05, 2018 2:34 pm What's gotten me is that although we're working in radians, it seems backwards. As the number increases towards 2*PI, it rotates my object CLOCKWISE when it should be counter-clockwise as I understand Radians.
Is it a fair statement that this is due to the world be rotated 180 degrees, so that origin is the upper left (not lower left) BUT I can't quite figure out how that affects clockwise vs. counter-clockwise. Or am I interpreting love.graphics.draw() incorrectly?
Re: Rotation Q
Got it working.
Current (incomplete / incorrect) code:
Current (incomplete / incorrect) code:
Code: Select all
-- utilities for dealing with angles and rotation
local abs = math.abs;
local atan2 = math.atan2
local CIRCLE = 2 * math.pi
local angles = {CIRCLE = CIRCLE}
local function normalize(r)
if r < 0 then
r = r + CIRCLE
elseif r > CIRCLE then
r = math.mod(r, CIRCLE)
end
return r
end
function angles.rotateby(r, deltar)
return normalize(r + deltar)
end
-- angle from fx, fy to tx, ty
function angles.to(fx, fy, tx, ty)
return normalize(atan2(ty - fy, tx - fx))
end
-- Adjust r towards targetr by amount
-- this may increase or decreate targetr
-- returns normalized value
function angles.turnto(r, targetr, amount)
local delta = targetr - r
if delta > 0 and delta <= math.pi then
r = r + amount
else
r = r - amount
end
return normalize(r)
end
return angles
Who is online
Users browsing this forum: Amazon [Bot] and 5 guests