源战役客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

114 lines
2.2 KiB

co = co or {}
local co = co
local CoVector2 = CoVector2
local math = math
--返回一个CoVector2
function co.Vector2(x, y)
-- print(debug.traceback(""))
-- print("111111111111co.Vector2")
return CoVector2.New(x, y)
end
co.free_vector2_list = co.free_vector2_list or {}
co.free_vector2_num = co.free_vector2_num or 0
function co.TempVector2(x, y)
local free_num = co.free_vector2_num
-- print("获取TempVector2:", free_num)
if free_num > 0 then
local v = co.free_vector2_list[free_num]
co.free_vector2_list[free_num] = nil
co.free_vector2_num = free_num - 1
v.x, v.y = x, y
return v
else
local v = CoVector2.New(x, y)
return v
end
end
function co.InitTempVectorArray()
for i=co.free_vector2_num, 90 do
local v = CoVector2.New(0, 0)
v:DeleteV()
end
end
function co.Vector2FromTable(t)
return CoVector2.New(t.x, t.y)
end
function co.RadianToDegree(radian)
return radian / math.pi * 180
end
function co.DegreeToRadian(degree)
return degree / 180 * math.pi
end
function co.TableXY(x, y)
return {x=x, y=y}
end
function co.PointDistance(t1, t2)
local xl = math.abs(t1.x - t2.x)
local yl = math.abs(t1.y - t2.y)
return math.sqrt(xl*xl + yl*yl)
end
function co.TableXYZ(x, y, z)
return {x=x, y=y, z=z}
end
function co.TableXYFromPos(pos)
return {x=pos.x, y=pos.y}
end
--把一个{x=.., y=..}的table归1化
function co.NormaliseXYTable(v)
local l = math.sqrt(v.x * v.x + v.y * v.y)
if l >= 1e-6 then
local f = 1 / l
v.x = v.x * f
v.y = v.y * f
end
return l
end
--把一个{x=.., y=..},z=..的table归1化
function co.NormaliseXYZTable(v)
local l = math.sqrt(v.x * v.x + v.y * v.y + v.z*v.z)
if l >= 1e-6 then
local f = 1 / l
v.x = v.x * f
v.y = v.y * f
v.z = v.z * f
end
return l
end
function co.MulXYTable(t1, t2)
return {x = t1.x*t2.x, y = t1.y*t2.y}
end
function co.SubtractXYTable(t1, t2 )
return {x=t1.x-t2.x, y=t1.y-t2.y}
end
function co.AddXY(t1, t2 )
return {x= t1.x + t2.x, y = t1.y+t2.y}
end
function co.AddXYZ(t1, t2 )
return {x= t1.x + t2.x, y = t1.y+t2.y, z = t1.z + t2.z}
end
function co.MoveXYTable(t1, dir, dist)
t1.x = t1.x + dir.x * dist
t1.y = t1.y + dir.y * dist
end
co.NegativeYAix = co.Vector2(0, -1)
co.XAix = co.Vector2(1, 0)