mathUtils.h 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _MATHUTILS_H_
  23. #define _MATHUTILS_H_
  24. class Point3F;
  25. class MatrixF;
  26. struct Vector2;
  27. #ifndef _MPOINT_H_
  28. #include "mPoint.h"
  29. #endif
  30. /// Creates orientation matrix from a direction vector. Assumes ( 0 0 1 ) is up.
  31. MatrixF createOrientFromDir( Point3F &direction );
  32. /// Creates random direction given angle parameters similar to the particle system.
  33. ///
  34. /// The angles are relative to the specified axis. Both phi and theta are in degrees.
  35. Point3F randomDir( Point3F &axis, F32 thetaAngleMin, F32 thetaAngleMax, F32 phiAngleMin = 0.0, F32 phiAngleMax = 360.0 );
  36. /// Returns yaw and pitch angles from a given vector.
  37. ///
  38. /// Angles are in RADIANS.
  39. ///
  40. /// Assumes north is (0.0, 1.0, 0.0), the degrees move upwards clockwise.
  41. ///
  42. /// The range of yaw is 0 - 2PI. The range of pitch is -PI/2 - PI/2.
  43. ///
  44. /// <b>ASSUMES Z AXIS IS UP</b>
  45. void getAnglesFromVector( VectorF &vec, F32 &yawAng, F32 &pitchAng );
  46. /// Returns vector from given yaw and pitch angles.
  47. ///
  48. /// Angles are in RADIANS.
  49. ///
  50. /// Assumes north is (0.0, 1.0, 0.0), the degrees move upwards clockwise.
  51. ///
  52. /// The range of yaw is 0 - 2PI. The range of pitch is -PI/2 - PI/2.
  53. ///
  54. /// <b>ASSUMES Z AXIS IS UP</b>
  55. void getVectorFromAngles( VectorF &vec, F32 &yawAng, F32 &pitchAng );
  56. /// Returns a point on the given line ab that is closest to 'point'. 2D version.
  57. /// @param a The start of the line.
  58. /// @param b The end of the line.
  59. /// @param point The point to test with
  60. /// @return A Point2F of the nearest point that lies on the line
  61. Point2F getClosestPointOnLine( Point2F &a, Point2F &b, Point2F &point);
  62. #endif // _MATHUTILS_H_