源战役客户端
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.

65 lines
1.5 KiB

  1. local setmetatable = setmetatable
  2. local Mathf = Mathf
  3. local Vector3 = Vector3
  4. local Plane = {}
  5. Plane.__index = function(t,k)
  6. return rawget(Plane, k)
  7. end
  8. Plane.__call = function(t,v)
  9. return Plane.New(v)
  10. end
  11. function Plane.New(normal, d)
  12. local plane = {}
  13. plane.normal = normal:Normalize()
  14. plane.distance = d
  15. setmetatable(plane, Plane)
  16. return plane
  17. end
  18. function Plane:Get()
  19. return self.normal, self.distance
  20. end
  21. function Plane:Raycast(ray)
  22. local a = Vector3.Dot(ray.direction, self.normal)
  23. local num2 = -Vector3.Dot(ray.origin, self.normal) - self.distance
  24. if Mathf.Approximately(a, 0) then
  25. return false, 0
  26. end
  27. local enter = num2 / a
  28. return enter > 0, enter
  29. end
  30. function Plane:SetNormalAndPosition(inNormal, inPoint)
  31. self.normal = inNormal:Normalize()
  32. self.distance = -Vector3.Dot(inNormal, inPoint)
  33. end
  34. function Plane:Set3Points(a, b, c)
  35. self.normal = Vector3.Normalize(Vector3.Cross(b - a, c - a))
  36. self.distance = -Vector3.Dot(self.normal, a)
  37. end
  38. function Plane:GetDistanceToPoint(inPt)
  39. return Vector3.Dot(self.normal, inPt) + self.distance
  40. end
  41. function Plane:GetSide(inPt)
  42. return (Vector3.Dot(self.normal, inPt) + self.distance) > 0
  43. end
  44. function Plane:SameSide(inPt0, inPt1)
  45. local distanceToPoint = self:GetDistanceToPoint(inPt0)
  46. local num2 = self:GetDistanceToPoint(inPt1)
  47. return (distanceToPoint > 0 and num2 > 0) or (distanceToPoint <= 0 and num2 <= 0)
  48. end
  49. UnityEngine.Plane = Plane
  50. setmetatable(Plane, Plane)
  51. return Plane