PageRenderTime 26ms CodeModel.GetById 6ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llmath/llquaternion2.inl

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 102 lines | 42 code | 16 blank | 44 comment | 1 complexity | f213ee62d1d05f71f30efcd07f10f80e MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llquaternion2.inl
  3. * @brief LLQuaternion2 inline definitions
  4. *
  5. * $LicenseInfo:firstyear=2010&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2010, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. #include "llquaternion2.h"
  27. static const LLQuad LL_V4A_PLUS_ONE = {1.f, 1.f, 1.f, 1.f};
  28. static const LLQuad LL_V4A_MINUS_ONE = {-1.f, -1.f, -1.f, -1.f};
  29. // Ctor from LLQuaternion
  30. inline LLQuaternion2::LLQuaternion2( const LLQuaternion& quat )
  31. {
  32. mQ.set(quat.mQ[VX], quat.mQ[VY], quat.mQ[VZ], quat.mQ[VW]);
  33. }
  34. //////////////////////////
  35. // Get/Set
  36. //////////////////////////
  37. // Return the internal LLVector4a representation of the quaternion
  38. inline const LLVector4a& LLQuaternion2::getVector4a() const
  39. {
  40. return mQ;
  41. }
  42. inline LLVector4a& LLQuaternion2::getVector4aRw()
  43. {
  44. return mQ;
  45. }
  46. /////////////////////////
  47. // Quaternion modification
  48. /////////////////////////
  49. // Set this quaternion to the conjugate of src
  50. inline void LLQuaternion2::setConjugate(const LLQuaternion2& src)
  51. {
  52. static LL_ALIGN_16( const U32 F_QUAT_INV_MASK_4A[4] ) = { 0x80000000, 0x80000000, 0x80000000, 0x00000000 };
  53. mQ = _mm_xor_ps(src.mQ, *reinterpret_cast<const LLQuad*>(&F_QUAT_INV_MASK_4A));
  54. }
  55. // Renormalizes the quaternion. Assumes it has nonzero length.
  56. inline void LLQuaternion2::normalize()
  57. {
  58. mQ.normalize4();
  59. }
  60. // Quantize this quaternion to 8 bit precision
  61. inline void LLQuaternion2::quantize8()
  62. {
  63. mQ.quantize8( LL_V4A_MINUS_ONE, LL_V4A_PLUS_ONE );
  64. normalize();
  65. }
  66. // Quantize this quaternion to 16 bit precision
  67. inline void LLQuaternion2::quantize16()
  68. {
  69. mQ.quantize16( LL_V4A_MINUS_ONE, LL_V4A_PLUS_ONE );
  70. normalize();
  71. }
  72. /////////////////////////
  73. // Quaternion inspection
  74. /////////////////////////
  75. // Return true if this quaternion is equal to 'rhs'.
  76. // Note! Quaternions exhibit "double-cover", so any rotation has two equally valid
  77. // quaternion representations and they will NOT compare equal.
  78. inline bool LLQuaternion2::equals(const LLQuaternion2 &rhs, F32 tolerance/* = F_APPROXIMATELY_ZERO*/) const
  79. {
  80. return mQ.equals4(rhs.mQ, tolerance);
  81. }
  82. // Return true if all components are finite and the quaternion is normalized
  83. inline bool LLQuaternion2::isOkRotation() const
  84. {
  85. return mQ.isFinite4() && mQ.isNormalized4();
  86. }