Code: Select all
Actor = require 'Actor'
That in turn means that here
Code: Select all
Player = Class{
__includes = Actor,
Oh, and I only just saw your edit, damn you!
Code: Select all
Actor = require 'Actor'
Code: Select all
Player = Class{
__includes = Actor,
Don't worry, sometimes explaining a problem to someone else is the best way to solve it. As you then think of all the things that in your mind are obvious as you are explaining them.Ford_Prefect wrote:[edit]
I screwed up my coordinate systems and should be ashamed of myself. Nothing to see here, move along.
Hah, you learn something new every daykikito wrote:Yep. It is called Rubber Duck Debugging.
Code: Select all
-- ref.: http://blog.signalsondisplay.com/?p=336
function vector:trim_inplace(maxLen)
local s = maxLen * maxLen / self:len2()
s = (s > 1 and 1) or math.sqrt(s)
self.x, self.y = self.x * s, self.y * s
return self
end
Code: Select all
-- trims vector size if above a given length
function vector:trim_inplace(maxLen)
assert(maxLen >= 0)
local d = self:len()
if d > maxLen then
local s = 1/d * maxLen -- 1/d = inverse length, could be simplified to: maxLen/d
self.x, self.y = self.x * s, self.y * s
end
return self
end
Code: Select all
function vector:trim_inplace(maxLen)
local d = self:len()
if d > maxLen and d > 0 then
local s = maxLen/d
self.x, self.y = self.x * s, self.y * s
end
return self
end
Code: Select all
function vector:trim_inplace(maxLen)
local d2 = self:len2()
if d2 > maxLen*maxLen and d2 > 0 then
local s = maxLen/math.sqrt(d2)
self.x, self.y = self.x * s, self.y * s
end
return self
end
Code: Select all
function vector:perpendicular()
return new(-self.y, self.x)
end
Code: Select all
function vector:rotate90ccw()
return new(-self.y, self.x)
end
function vector:rotate90cw()
return new(self.y, -self.x)
end
function vector:rotate180()
return new(-self.x, -self.y)
end
I think this would be great. I found :perpendicular() confusing at first, too.ivan wrote: PS. Also, I have another small suggestioncould become:Code: Select all
function vector:perpendicular() return new(-self.y, self.x) end
Code: Select all
function vector:rotate90ccw() return new(-self.y, self.x) end function vector:rotate90cw() return new(self.y, -self.x) end function vector:rotate180() return new(-self.x, -self.y) end
Code: Select all
function vector:angleTo(input)
return math.acos( (self.x * input.x + self.y * input.y) / (math.sqrt((self.x^2 + self.y^2)) * math.sqrt((input.x^2 + input.y^2))))
end
With trigonometry:Ford_Prefect wrote:I think this would be great. I found :perpendicular() confusing at first, too.
Also, I think HUMP rotates in the other direction than löve. (HUMP goes counterclockwise for positive values, löve clockwise.)
The angle between two vectors (R) is a classic problem, could be solved using the dot product instead of atan2:On a different note, I figured out what caused problems in my code. Take a look at the attached .love file. It's calculating the angle between a rotating vector and a vertical one.
See that jump from 1/2 pi to 3/2 pi? That's a frustration feature...
Code: Select all
-- for two normalized vectors:
cos(R) = dot(a,b)
R = acos(dot(a,b))
-- for any two vectors:
cos(R) = dot(a,b)/(length(a)*length(b))
R = acos(dot(a,b)/(length(a)*length(b)))
See my edit above, exactly what I didivan wrote:[...]
Users browsing this forum: No registered users and 5 guests