mAngAxis.cpp 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. #include "math/mAngAxis.h"
  23. #include "math/mQuat.h"
  24. #include "math/mMatrix.h"
  25. AngAxisF & AngAxisF::set( const QuatF & q )
  26. {
  27. angle = 2.0f * mAcos( q.w );
  28. F32 sinHalfAngle = mSqrt(q.x * q.x + q.y * q.y + q.z * q.z);
  29. if (sinHalfAngle != 0.0f)
  30. axis.set( q.x / sinHalfAngle, q.y / sinHalfAngle, q.z / sinHalfAngle );
  31. else
  32. axis.set(1.0f,0.0f,0.0f);
  33. return *this;
  34. }
  35. AngAxisF & AngAxisF::set( const MatrixF & mat )
  36. {
  37. QuatF q( mat );
  38. set( q );
  39. return *this;
  40. }
  41. MatrixF * AngAxisF::setMatrix( MatrixF * mat ) const
  42. {
  43. QuatF q( *this );
  44. return q.setMatrix( mat );
  45. }
  46. void AngAxisF::RotateX(F32 angle, MatrixF * mat)
  47. {
  48. // for now...do it the easy way
  49. AngAxisF rotX(Point3F(1.0f,0.0f,0.0f),angle);
  50. rotX.setMatrix(mat);
  51. }
  52. void AngAxisF::RotateY(F32 angle, MatrixF * mat)
  53. {
  54. // for now...do it the easy way
  55. AngAxisF rotY(Point3F(0.0f,1.0f,0.0f),angle);
  56. rotY.setMatrix(mat);
  57. }
  58. void AngAxisF::RotateZ(F32 angle, MatrixF * mat)
  59. {
  60. // for now...do it the easy way
  61. AngAxisF rotZ(Point3F(0.0f,0.0f,1.0f),angle);
  62. rotZ.setMatrix(mat);
  63. }
  64. void AngAxisF::RotateX(F32 angle, const Point3F & from, Point3F * to)
  65. {
  66. // for now...do it the easy way
  67. MatrixF mat;
  68. AngAxisF::RotateX(angle,&mat);
  69. mat.mulV(from,to);
  70. }
  71. void AngAxisF::RotateY(F32 angle, const Point3F & from, Point3F * to)
  72. {
  73. // for now...do it the easy way
  74. MatrixF mat;
  75. AngAxisF::RotateY(angle,&mat);
  76. mat.mulV(from,to);
  77. }
  78. void AngAxisF::RotateZ(F32 angle, const Point3F & from, Point3F * to)
  79. {
  80. // for now...do it the easy way
  81. MatrixF mat;
  82. AngAxisF::RotateZ(angle,&mat);
  83. mat.mulV(from,to);
  84. }