-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVectorOp.lua
More file actions
89 lines (65 loc) · 2.68 KB
/
Copy pathVectorOp.lua
File metadata and controls
89 lines (65 loc) · 2.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
--[[
0 1 0 1 0 0 1 1
0 1 1 0 1 1 1 1 ____ __ __
0 1 1 1 0 0 0 0 / __/__ ___ / / __ __/ /__ ___ __
0 1 1 0 1 0 0 0 _\ \/ _ \/ _ \/ _ \/ // / / _ `/\ \ /
0 1 1 1 1 0 0 1 /___/\___/ .__/_//_/\_, /_/\_,_//_\_\
0 1 1 0 1 1 0 0 /_/ /___/
0 1 1 0 0 0 0 1
0 1 1 1 1 0 0 0
Save as VectorOp.lua into Ensage\Scripts\libs.
Functions:
Vector:Clone(): Retruns a clone of the given Vector for copying purposes.
Vector2D:Clone(): Retruns a clone of the given Vector2D for copying purposes.
Vector:Unit(): Returns the unit Vector that is on the same xy direction as the given Vector.
Vector2D:Unit(): Returns the unit Vector2D that is on the same xy direction as the given Vector2D.
Vector:GetXYAngle(): Returns the XY angle of the given Vector.
Vector2D:GetXYAngle(): Returns the XY angle of the given Vector2D.
VectorOp.UnitVectorFromXYAngle(alpha): Creates and returns a unit Vector with given angle as its XY angle.
VectorOp.UnitVector2DFromXYAngle(alpha): Creates and returns a unit Vector2D with given angle as its XY angle.
Vector:GetDistance2D(a): Calculates the distance between the given Vector and parameter.
Vector2D:GetDistance2D(a): Calculates the distance between the given Vector2D and parameter.
--]]
VectorOp = {}
function Vector:Clone()
return Vector(self.x,self.y,self.z)
end
function Vector2D:Clone()
return Vector2D(self.x,self.y)
end
function Vector:Unit()
local self = self/#self
return Vector(self.x,self.y,0)
end
function Vector2D:Unit()
local self = self/#self
return Vector2D(self.x,self.y)
end
function Vector:GetXYAngle()
return math.atan2(self.y,self.x)
end
function Vector2D:GetXYAngle()
return math.atan2(self.y,self.x)
end
function VectorOp.UnitVectorFromXYAngle(alpha)
return Vector(math.cos(alpha),math.sin(alpha),0)
end
function VectorOp.UnitVector2DFromXYAngle(alpha)
return Vector2D(math.cos(alpha),math.sin(alpha))
end
function Vector:GetDistance2D(a)
assert(GetType(a) == "Vector" or GetType(a) == "LuaEntity" or GetType(a) == "Vector2D" or GetType(a) == "Projectile", "GetDistance2D: Invalid Parameter (Got "..GetType(a)..")")
if a.x == nil or a.y == nil then
return self:GetDistance2D(a.position)
else
return math.sqrt(math.pow(a.x-self.x,2)+math.pow(a.y-self.y,2))
end
end
function Vector2D:GetDistance2D(a)
assert(GetType(a) == "Vector" or GetType(a) == "LuaEntity" or GetType(a) == "Vector2D" or GetType(a) == "Projectile", "GetDistance2D: Invalid Parameter (Got "..GetType(a)..")")
if a.x == nil or a.y == nil then
return self:GetDistance2D(a.position)
else
return math.sqrt(math.pow(a.x-self.x,2)+math.pow(a.y-self.y,2))
end
end