源战役客户端
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

113 wiersze
2.2 KiB

4 tygodni temu
  1. co = co or {}
  2. local co = co
  3. local CoVector2 = CoVector2
  4. local math = math
  5. --返回一个CoVector2
  6. function co.Vector2(x, y)
  7. -- print(debug.traceback(""))
  8. -- print("111111111111co.Vector2")
  9. return CoVector2.New(x, y)
  10. end
  11. co.free_vector2_list = co.free_vector2_list or {}
  12. co.free_vector2_num = co.free_vector2_num or 0
  13. function co.TempVector2(x, y)
  14. local free_num = co.free_vector2_num
  15. -- print("获取TempVector2:", free_num)
  16. if free_num > 0 then
  17. local v = co.free_vector2_list[free_num]
  18. co.free_vector2_list[free_num] = nil
  19. co.free_vector2_num = free_num - 1
  20. v.x, v.y = x, y
  21. return v
  22. else
  23. local v = CoVector2.New(x, y)
  24. return v
  25. end
  26. end
  27. function co.InitTempVectorArray()
  28. for i=co.free_vector2_num, 90 do
  29. local v = CoVector2.New(0, 0)
  30. v:DeleteV()
  31. end
  32. end
  33. function co.Vector2FromTable(t)
  34. return CoVector2.New(t.x, t.y)
  35. end
  36. function co.RadianToDegree(radian)
  37. return radian / math.pi * 180
  38. end
  39. function co.DegreeToRadian(degree)
  40. return degree / 180 * math.pi
  41. end
  42. function co.TableXY(x, y)
  43. return {x=x, y=y}
  44. end
  45. function co.PointDistance(t1, t2)
  46. local xl = math.abs(t1.x - t2.x)
  47. local yl = math.abs(t1.y - t2.y)
  48. return math.sqrt(xl*xl + yl*yl)
  49. end
  50. function co.TableXYZ(x, y, z)
  51. return {x=x, y=y, z=z}
  52. end
  53. function co.TableXYFromPos(pos)
  54. return {x=pos.x, y=pos.y}
  55. end
  56. --把一个{x=.., y=..}的table归1化
  57. function co.NormaliseXYTable(v)
  58. local l = math.sqrt(v.x * v.x + v.y * v.y)
  59. if l >= 1e-6 then
  60. local f = 1 / l
  61. v.x = v.x * f
  62. v.y = v.y * f
  63. end
  64. return l
  65. end
  66. --把一个{x=.., y=..},z=..的table归1化
  67. function co.NormaliseXYZTable(v)
  68. local l = math.sqrt(v.x * v.x + v.y * v.y + v.z*v.z)
  69. if l >= 1e-6 then
  70. local f = 1 / l
  71. v.x = v.x * f
  72. v.y = v.y * f
  73. v.z = v.z * f
  74. end
  75. return l
  76. end
  77. function co.MulXYTable(t1, t2)
  78. return {x = t1.x*t2.x, y = t1.y*t2.y}
  79. end
  80. function co.SubtractXYTable(t1, t2 )
  81. return {x=t1.x-t2.x, y=t1.y-t2.y}
  82. end
  83. function co.AddXY(t1, t2 )
  84. return {x= t1.x + t2.x, y = t1.y+t2.y}
  85. end
  86. function co.AddXYZ(t1, t2 )
  87. return {x= t1.x + t2.x, y = t1.y+t2.y, z = t1.z + t2.z}
  88. end
  89. function co.MoveXYTable(t1, dir, dist)
  90. t1.x = t1.x + dir.x * dist
  91. t1.y = t1.y + dir.y * dist
  92. end
  93. co.NegativeYAix = co.Vector2(0, -1)
  94. co.XAix = co.Vector2(1, 0)