Plane.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // Copyright (c) 2008-2023 the Urho3D project
  2. // License: MIT
  3. #include "../Precompiled.h"
  4. #include "../Math/Plane.h"
  5. #include "../DebugNew.h"
  6. namespace Urho3D
  7. {
  8. // Static initialization order can not be relied on, so do not use Vector3 constants
  9. const Plane Plane::UP(Vector3(0.0f, 1.0f, 0.0f), Vector3(0.0f, 0.0f, 0.0f));
  10. void Plane::Transform(const Matrix3& transform)
  11. {
  12. Define(Matrix4(transform).Inverse().Transpose() * ToVector4());
  13. }
  14. void Plane::Transform(const Matrix3x4& transform)
  15. {
  16. Define(transform.ToMatrix4().Inverse().Transpose() * ToVector4());
  17. }
  18. void Plane::Transform(const Matrix4& transform)
  19. {
  20. Define(transform.Inverse().Transpose() * ToVector4());
  21. }
  22. Matrix3x4 Plane::ReflectionMatrix() const
  23. {
  24. return Matrix3x4(
  25. -2.0f * normal_.x_ * normal_.x_ + 1.0f,
  26. -2.0f * normal_.x_ * normal_.y_,
  27. -2.0f * normal_.x_ * normal_.z_,
  28. -2.0f * normal_.x_ * d_,
  29. -2.0f * normal_.y_ * normal_.x_,
  30. -2.0f * normal_.y_ * normal_.y_ + 1.0f,
  31. -2.0f * normal_.y_ * normal_.z_,
  32. -2.0f * normal_.y_ * d_,
  33. -2.0f * normal_.z_ * normal_.x_,
  34. -2.0f * normal_.z_ * normal_.y_,
  35. -2.0f * normal_.z_ * normal_.z_ + 1.0f,
  36. -2.0f * normal_.z_ * d_
  37. );
  38. }
  39. Plane Plane::Transformed(const Matrix3& transform) const
  40. {
  41. return Plane(Matrix4(transform).Inverse().Transpose() * ToVector4());
  42. }
  43. Plane Plane::Transformed(const Matrix3x4& transform) const
  44. {
  45. return Plane(transform.ToMatrix4().Inverse().Transpose() * ToVector4());
  46. }
  47. Plane Plane::Transformed(const Matrix4& transform) const
  48. {
  49. return Plane(transform.Inverse().Transpose() * ToVector4());
  50. }
  51. }