Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 
 

127 linhas
4.0 KiB

  1. /*
  2. Open Asset Import Library (assimp)
  3. ----------------------------------------------------------------------
  4. Copyright (c) 2006-2012, assimp team
  5. All rights reserved.
  6. Redistribution and use of this software in source and binary forms,
  7. with or without modification, are permitted provided that the
  8. following conditions are met:
  9. * Redistributions of source code must retain the above
  10. copyright notice, this list of conditions and the
  11. following disclaimer.
  12. * Redistributions in binary form must reproduce the above
  13. copyright notice, this list of conditions and the
  14. following disclaimer in the documentation and/or other
  15. materials provided with the distribution.
  16. * Neither the name of the assimp team, nor the names of its
  17. contributors may be used to endorse or promote products
  18. derived from this software without specific prior
  19. written permission of the assimp team.
  20. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  21. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  22. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  23. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  24. OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  25. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  26. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  27. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  28. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  29. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  30. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. ----------------------------------------------------------------------
  32. */
  33. /** @file quaternion.h
  34. * @brief Quaternion structure, including operators when compiling in C++
  35. */
  36. #ifndef AI_QUATERNION_H_INC
  37. #define AI_QUATERNION_H_INC
  38. #ifdef __cplusplus
  39. template <typename TReal> class aiVector3t;
  40. template <typename TReal> class aiMatrix3x3t;
  41. // ---------------------------------------------------------------------------
  42. /** Represents a quaternion in a 4D vector. */
  43. template <typename TReal>
  44. class aiQuaterniont
  45. {
  46. public:
  47. aiQuaterniont() : w(1.0), x(), y(), z() {}
  48. aiQuaterniont(TReal pw, TReal px, TReal py, TReal pz)
  49. : w(pw), x(px), y(py), z(pz) {}
  50. /** Construct from rotation matrix. Result is undefined if the matrix is not orthonormal. */
  51. aiQuaterniont( const aiMatrix3x3t<TReal>& pRotMatrix);
  52. /** Construct from euler angles */
  53. aiQuaterniont( TReal rotx, TReal roty, TReal rotz);
  54. /** Construct from an axis-angle pair */
  55. aiQuaterniont( aiVector3t<TReal> axis, TReal angle);
  56. /** Construct from a normalized quaternion stored in a vec3 */
  57. aiQuaterniont( aiVector3t<TReal> normalized);
  58. /** Returns a matrix representation of the quaternion */
  59. aiMatrix3x3t<TReal> GetMatrix() const;
  60. public:
  61. bool operator== (const aiQuaterniont& o) const;
  62. bool operator!= (const aiQuaterniont& o) const;
  63. bool Equal(const aiQuaterniont& o, TReal epsilon = 1e-6) const;
  64. public:
  65. /** Normalize the quaternion */
  66. aiQuaterniont& Normalize();
  67. /** Compute quaternion conjugate */
  68. aiQuaterniont& Conjugate ();
  69. /** Rotate a point by this quaternion */
  70. aiVector3t<TReal> Rotate (const aiVector3t<TReal>& in);
  71. /** Multiply two quaternions */
  72. aiQuaterniont operator* (const aiQuaterniont& two) const;
  73. public:
  74. /** Performs a spherical interpolation between two quaternions and writes the result into the third.
  75. * @param pOut Target object to received the interpolated rotation.
  76. * @param pStart Start rotation of the interpolation at factor == 0.
  77. * @param pEnd End rotation, factor == 1.
  78. * @param pFactor Interpolation factor between 0 and 1. Values outside of this range yield undefined results.
  79. */
  80. static void Interpolate( aiQuaterniont& pOut, const aiQuaterniont& pStart,
  81. const aiQuaterniont& pEnd, TReal pFactor);
  82. public:
  83. //! w,x,y,z components of the quaternion
  84. TReal w, x, y, z;
  85. } ;
  86. typedef aiQuaterniont<float> aiQuaternion;
  87. #else
  88. struct aiQuaternion {
  89. float w, x, y, z;
  90. };
  91. #endif
  92. #endif // AI_QUATERNION_H_INC