2
0

mAngAxis.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. class MatrixF;
  28. class QuatF;
  29. //----------------------------------------------------------------------------
  30. // rotation about an arbitrary axis through the origin:
  31. class AngAxisF
  32. {
  33. public:
  34. Point3F axis;
  35. F32 angle;
  36. AngAxisF();
  37. AngAxisF( const Point3F & _axis, F32 _angle );
  38. explicit AngAxisF( const MatrixF &m );
  39. explicit AngAxisF( const QuatF &q );
  40. AngAxisF& set( const Point3F & _axis, F32 _angle );
  41. AngAxisF& set( const MatrixF & m );
  42. AngAxisF& set( const QuatF & q );
  43. bool operator ==( const AngAxisF & c ) const;
  44. bool operator !=( const AngAxisF & c ) const;
  45. MatrixF * setMatrix( MatrixF * mat ) const;
  46. static void RotateX(F32 angle, MatrixF * mat);
  47. static void RotateY(F32 angle, MatrixF * mat);
  48. static void RotateZ(F32 angle, MatrixF * mat);
  49. static void RotateX(F32 angle, const Point3F & from, Point3F * to);
  50. static void RotateY(F32 angle, const Point3F & from, Point3F * to);
  51. static void RotateZ(F32 angle, const Point3F & from, Point3F * to);
  52. };
  53. //----------------------------------------------------------------------------
  54. // AngAxisF implementation:
  55. inline AngAxisF::AngAxisF()
  56. {
  57. axis = Point3F(0.0f,0.0f,1.0f);
  58. angle = 0.0f;
  59. }
  60. inline AngAxisF::AngAxisF( const Point3F & _axis, F32 _angle )
  61. {
  62. set(_axis,_angle);
  63. }
  64. inline AngAxisF::AngAxisF( const MatrixF & mat )
  65. {
  66. set(mat);
  67. }
  68. inline AngAxisF::AngAxisF( const QuatF & quat )
  69. {
  70. set(quat);
  71. }
  72. inline AngAxisF& AngAxisF::set( const Point3F & _axis, F32 _angle )
  73. {
  74. axis = _axis;
  75. angle = _angle;
  76. return *this;
  77. }
  78. inline bool AngAxisF::operator ==( const AngAxisF & c ) const
  79. {
  80. return mFabs(angle-c.angle) < 0.0001f && (axis == c.axis);
  81. }
  82. inline bool AngAxisF::operator !=( const AngAxisF & c ) const
  83. {
  84. return !(*this == c);
  85. }
  86. #endif // _MANGAXIS_H_