Game Development Reference
In-Depth Information
function _vec2D:limit(theLimit)
if self.x > theLimit then
self.x = theLimit
end
if self.y > theLimit then
self.y = theLimit
end
end
function _vec2D:equals(theVec)
if self.x == theVec.c and self.y == theVec.y
return true
else
return false
end
end
function _vec2D:add(theVec)
self.x = self.x + theVec.x
self.y = self.y + theVec.y
end
function _vec2D:sub(theVec)
self.x = self.x - theVec.x
self.y = self.y - theVec.y
end
function _vec2D:multiply(scalar)
self.x = self.x * scalar
self.y = self.y * scalar
end
function _vec2D:divide(scalar)
self.x = self.x / scalar
self.y = self.y / scalar
end
function _vec2D:dot(theVec)
return self.x * theVec.x + self.y * theVec.y
end
function _vec2D:dist()
return math.sqrt((self.x * self.x) + (self.y * self.y))
end
function _vec2D:Normalize(theVec)
local tmpVec = _vec2D:new(theVec.x, theVec.y)
local vecMag = tmpVec:magnitude()
if vecMag > 0 then
Search WWH ::




Custom Search