mAngAxis.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 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 _MANGAXIS_H_
  23. #define _MANGAXIS_H_
  24. #ifndef _MPOINT3_H_
  25. #include "math/mPoint3.h"
  26. #endif
  27. #ifndef USE_TEMPLATE_MATRIX
  28. class MatrixF;
  29. #else
  30. template<typename DATA_TYPE, U32 rows, U32 cols> class Matrix;
  31. typedef Matrix<F32, 4, 4> MatrixF;
  32. #endif
  33. class QuatF;
  34. //----------------------------------------------------------------------------
  35. // rotation about an arbitrary axis through the origin:
  36. class AngAxisF
  37. {
  38. public:
  39. Point3F axis;
  40. F32 angle;
  41. AngAxisF();
  42. AngAxisF( const Point3F & _axis, F32 _angle );
  43. explicit AngAxisF( const MatrixF &m );
  44. explicit AngAxisF( const QuatF &q );
  45. AngAxisF& set( const Point3F & _axis, F32 _angle );
  46. AngAxisF& set( const EulerF & _axis);
  47. AngAxisF& set( const MatrixF & m );
  48. AngAxisF& set( const QuatF & q );
  49. bool operator ==( const AngAxisF & c ) const;
  50. bool operator !=( const AngAxisF & c ) const;
  51. MatrixF * setMatrix( MatrixF * mat ) const;
  52. static void RotateX(F32 angle, MatrixF * mat);
  53. static void RotateY(F32 angle, MatrixF * mat);
  54. static void RotateZ(F32 angle, MatrixF * mat);
  55. static void RotateX(F32 angle, const Point3F & from, Point3F * to);
  56. static void RotateY(F32 angle, const Point3F & from, Point3F * to);
  57. static void RotateZ(F32 angle, const Point3F & from, Point3F * to);
  58. EulerF toEuler() const;
  59. };
  60. //----------------------------------------------------------------------------
  61. // AngAxisF implementation:
  62. inline AngAxisF::AngAxisF()
  63. {
  64. axis = Point3F(0.0f,0.0f,1.0f);
  65. angle = 0.0f;
  66. }
  67. inline AngAxisF::AngAxisF( const Point3F & _axis, F32 _angle )
  68. {
  69. set(_axis,_angle);
  70. }
  71. inline AngAxisF::AngAxisF( const MatrixF & mat )
  72. {
  73. set(mat);
  74. }
  75. inline AngAxisF::AngAxisF( const QuatF & quat )
  76. {
  77. set(quat);
  78. }
  79. inline AngAxisF& AngAxisF::set( const Point3F & _axis, F32 _angle )
  80. {
  81. axis = _axis;
  82. angle = _angle;
  83. return *this;
  84. }
  85. inline bool AngAxisF::operator ==( const AngAxisF & c ) const
  86. {
  87. return mFabs(angle-c.angle) < 0.0001f && (axis == c.axis);
  88. }
  89. inline bool AngAxisF::operator !=( const AngAxisF & c ) const
  90. {
  91. return !(*this == c);
  92. }
  93. #endif // _MANGAXIS_H_