PageRenderTime 19ms CodeModel.GetById 11ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 1ms

/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
  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
 27#include "llquaternion2.h"
 28
 29static const LLQuad LL_V4A_PLUS_ONE = {1.f, 1.f, 1.f, 1.f};
 30static const LLQuad LL_V4A_MINUS_ONE = {-1.f, -1.f, -1.f, -1.f};
 31
 32// Ctor from LLQuaternion
 33inline LLQuaternion2::LLQuaternion2( const LLQuaternion& quat )
 34{
 35	mQ.set(quat.mQ[VX], quat.mQ[VY], quat.mQ[VZ], quat.mQ[VW]);
 36}
 37
 38//////////////////////////
 39// Get/Set
 40//////////////////////////
 41
 42// Return the internal LLVector4a representation of the quaternion
 43inline const LLVector4a& LLQuaternion2::getVector4a() const
 44{
 45	return mQ;
 46}
 47
 48inline LLVector4a& LLQuaternion2::getVector4aRw()
 49{
 50	return mQ;
 51}
 52
 53/////////////////////////
 54// Quaternion modification
 55/////////////////////////
 56
 57// Set this quaternion to the conjugate of src
 58inline void LLQuaternion2::setConjugate(const LLQuaternion2& src)
 59{
 60	static LL_ALIGN_16( const U32 F_QUAT_INV_MASK_4A[4] ) = { 0x80000000, 0x80000000, 0x80000000, 0x00000000 };
 61	mQ = _mm_xor_ps(src.mQ, *reinterpret_cast<const LLQuad*>(&F_QUAT_INV_MASK_4A));	
 62}
 63
 64// Renormalizes the quaternion. Assumes it has nonzero length.
 65inline void LLQuaternion2::normalize()
 66{
 67	mQ.normalize4();
 68}
 69
 70// Quantize this quaternion to 8 bit precision
 71inline void LLQuaternion2::quantize8()
 72{
 73	mQ.quantize8( LL_V4A_MINUS_ONE, LL_V4A_PLUS_ONE );
 74	normalize();
 75}
 76
 77// Quantize this quaternion to 16 bit precision
 78inline void LLQuaternion2::quantize16()
 79{
 80	mQ.quantize16( LL_V4A_MINUS_ONE, LL_V4A_PLUS_ONE );
 81	normalize();
 82}
 83
 84
 85/////////////////////////
 86// Quaternion inspection
 87/////////////////////////
 88
 89// Return true if this quaternion is equal to 'rhs'. 
 90// Note! Quaternions exhibit "double-cover", so any rotation has two equally valid
 91// quaternion representations and they will NOT compare equal.
 92inline bool LLQuaternion2::equals(const LLQuaternion2 &rhs, F32 tolerance/* = F_APPROXIMATELY_ZERO*/) const
 93{
 94	return mQ.equals4(rhs.mQ, tolerance);
 95}
 96
 97// Return true if all components are finite and the quaternion is normalized
 98inline bool LLQuaternion2::isOkRotation() const
 99{
100	return mQ.isFinite4() && mQ.isNormalized4();
101}
102