WhiteBoxMathUtil.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #pragma once
  9. namespace AZ
  10. {
  11. class Quaternion;
  12. class Transform;
  13. class Vector3;
  14. }
  15. namespace WhiteBox
  16. {
  17. //! Intersect a segment with a cylinder
  18. //! Reference: Real-Time Collision Detection - 5.3.7 Intersecting Ray or Segment Against Cylinder
  19. //! @note: This exists because the version in AzCore has bugs. Should consider moving this to AzCore
  20. //! @param sa The start of the line segment
  21. //! @param sb The end of the line segment
  22. //! @param p The base of the cylinder
  23. //! @param q The top of the cylinder
  24. //! @param r The radius of the cylinder
  25. //! @param t The normalized distance along the line segment
  26. //! @return if an intersection occured or not
  27. bool IntersectSegmentCylinder(
  28. const AZ::Vector3& sa, const AZ::Vector3& sb, const AZ::Vector3& p, const AZ::Vector3& q, float r, float& t);
  29. //! Take a point in 'local' space, transform it to the new space, scale it uniformly, then return to 'local' space.
  30. AZ::Vector3 ScalePosition(float scale, const AZ::Vector3& localPosition, const AZ::Transform& localFromSpace);
  31. //! Hughes/Moeller calculate orthonormal basis.
  32. void CalculateOrthonormalBasis(const AZ::Vector3& n, AZ::Vector3& b1, AZ::Vector3& b2);
  33. //! Calculates local orientation from the orthonormal basis of the specified normal vector.
  34. AZ::Quaternion CalculateLocalOrientation(const AZ::Vector3& normal);
  35. } // namespace WhiteBox