Annotation of /linden_release/linden/indra/llmath/llv4matrix3.h
Parent Directory
|
Revision Log
Revision 57 - (view) (download)
| 1 : | mjm | 57 | /** |
| 2 : | * @file llviewerjointmesh.cpp | ||
| 3 : | * @brief LLV4* class header file - vector processor enabled math | ||
| 4 : | * | ||
| 5 : | * $LicenseInfo:firstyear=2007&license=viewergpl$ | ||
| 6 : | * | ||
| 7 : | * Copyright (c) 2007-2008, Linden Research, Inc. | ||
| 8 : | * | ||
| 9 : | * Second Life Viewer Source Code | ||
| 10 : | * The source code in this file ("Source Code") is provided by Linden Lab | ||
| 11 : | * to you under the terms of the GNU General Public License, version 2.0 | ||
| 12 : | * ("GPL"), unless you have obtained a separate licensing agreement | ||
| 13 : | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
| 14 : | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
| 15 : | * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2 | ||
| 16 : | * | ||
| 17 : | * There are special exceptions to the terms and conditions of the GPL as | ||
| 18 : | * it is applied to this Source Code. View the full text of the exception | ||
| 19 : | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
| 20 : | * online at http://secondlifegrid.net/programs/open_source/licensing/flossexception | ||
| 21 : | * | ||
| 22 : | * By copying, modifying or distributing this software, you acknowledge | ||
| 23 : | * that you have read and understood your obligations described above, | ||
| 24 : | * and agree to abide by those obligations. | ||
| 25 : | * | ||
| 26 : | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
| 27 : | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
| 28 : | * COMPLETENESS OR PERFORMANCE. | ||
| 29 : | * $/LicenseInfo$ | ||
| 30 : | */ | ||
| 31 : | |||
| 32 : | #ifndef LL_LLV4MATRIX3_H | ||
| 33 : | #define LL_LLV4MATRIX3_H | ||
| 34 : | |||
| 35 : | #include "llv4math.h" | ||
| 36 : | #include "llv4vector3.h" | ||
| 37 : | #include "m3math.h" | ||
| 38 : | |||
| 39 : | //----------------------------------------------------------------------------- | ||
| 40 : | //----------------------------------------------------------------------------- | ||
| 41 : | // LLV4Matrix3 | ||
| 42 : | //----------------------------------------------------------------------------- | ||
| 43 : | //----------------------------------------------------------------------------- | ||
| 44 : | |||
| 45 : | LL_LLV4MATH_ALIGN_PREFIX | ||
| 46 : | |||
| 47 : | class LLV4Matrix3 | ||
| 48 : | { | ||
| 49 : | public: | ||
| 50 : | union { | ||
| 51 : | F32 mMatrix[LLV4_NUM_AXIS][LLV4_NUM_AXIS]; | ||
| 52 : | V4F32 mV[LLV4_NUM_AXIS]; | ||
| 53 : | }; | ||
| 54 : | |||
| 55 : | void lerp(const LLV4Matrix3 &a, const LLV4Matrix3 &b, const F32 &w); | ||
| 56 : | void multiply(const LLVector3 &a, LLVector3& out) const; | ||
| 57 : | void multiply(const LLVector4 &a, LLV4Vector3& out) const; | ||
| 58 : | void multiply(const LLVector3 &a, LLV4Vector3& out) const; | ||
| 59 : | |||
| 60 : | const LLV4Matrix3& transpose(); | ||
| 61 : | const LLV4Matrix3& operator=(const LLMatrix3& a); | ||
| 62 : | |||
| 63 : | operator LLMatrix3() const { return (reinterpret_cast<const LLMatrix4*>(const_cast<const F32*>(&mMatrix[0][0])))->getMat3(); } | ||
| 64 : | |||
| 65 : | friend LLVector3 operator*(const LLVector3& a, const LLV4Matrix3& b); | ||
| 66 : | } | ||
| 67 : | |||
| 68 : | LL_LLV4MATH_ALIGN_POSTFIX; | ||
| 69 : | |||
| 70 : | |||
| 71 : | |||
| 72 : | //----------------------------------------------------------------------------- | ||
| 73 : | //----------------------------------------------------------------------------- | ||
| 74 : | // LLV4Matrix3 - SSE | ||
| 75 : | //----------------------------------------------------------------------------- | ||
| 76 : | //----------------------------------------------------------------------------- | ||
| 77 : | |||
| 78 : | #if LL_VECTORIZE | ||
| 79 : | |||
| 80 : | inline void LLV4Matrix3::lerp(const LLV4Matrix3 &a, const LLV4Matrix3 &b, const F32 &w) | ||
| 81 : | { | ||
| 82 : | __m128 vw = _mm_set1_ps(w); | ||
| 83 : | mV[VX] = _mm_add_ps(_mm_mul_ps(_mm_sub_ps(b.mV[VX], a.mV[VX]), vw), a.mV[VX]); // ( b - a ) * w + a | ||
| 84 : | mV[VY] = _mm_add_ps(_mm_mul_ps(_mm_sub_ps(b.mV[VY], a.mV[VY]), vw), a.mV[VY]); | ||
| 85 : | mV[VZ] = _mm_add_ps(_mm_mul_ps(_mm_sub_ps(b.mV[VZ], a.mV[VZ]), vw), a.mV[VZ]); | ||
| 86 : | } | ||
| 87 : | |||
| 88 : | inline void LLV4Matrix3::multiply(const LLVector3 &a, LLVector3& o) const | ||
| 89 : | { | ||
| 90 : | LLV4Vector3 j; | ||
| 91 : | j.v = _mm_mul_ps(_mm_set1_ps(a.mV[VX]), mV[VX]); // ( ax * vx ) + ... | ||
| 92 : | j.v = _mm_add_ps(j.v , _mm_mul_ps(_mm_set1_ps(a.mV[VY]), mV[VY])); | ||
| 93 : | j.v = _mm_add_ps(j.v , _mm_mul_ps(_mm_set1_ps(a.mV[VZ]), mV[VZ])); | ||
| 94 : | o.setVec(j.mV); | ||
| 95 : | } | ||
| 96 : | |||
| 97 : | inline void LLV4Matrix3::multiply(const LLVector4 &a, LLV4Vector3& o) const | ||
| 98 : | { | ||
| 99 : | o.v = _mm_mul_ps(_mm_set1_ps(a.mV[VX]), mV[VX]); // ( ax * vx ) + ... | ||
| 100 : | o.v = _mm_add_ps(o.v , _mm_mul_ps(_mm_set1_ps(a.mV[VY]), mV[VY])); | ||
| 101 : | o.v = _mm_add_ps(o.v , _mm_mul_ps(_mm_set1_ps(a.mV[VZ]), mV[VZ])); | ||
| 102 : | } | ||
| 103 : | |||
| 104 : | inline void LLV4Matrix3::multiply(const LLVector3 &a, LLV4Vector3& o) const | ||
| 105 : | { | ||
| 106 : | o.v = _mm_mul_ps(_mm_set1_ps(a.mV[VX]), mV[VX]); // ( ax * vx ) + ... | ||
| 107 : | o.v = _mm_add_ps(o.v , _mm_mul_ps(_mm_set1_ps(a.mV[VY]), mV[VY])); | ||
| 108 : | o.v = _mm_add_ps(o.v , _mm_mul_ps(_mm_set1_ps(a.mV[VZ]), mV[VZ])); | ||
| 109 : | } | ||
| 110 : | |||
| 111 : | //----------------------------------------------------------------------------- | ||
| 112 : | //----------------------------------------------------------------------------- | ||
| 113 : | // LLV4Matrix3 | ||
| 114 : | //----------------------------------------------------------------------------- | ||
| 115 : | //----------------------------------------------------------------------------- | ||
| 116 : | |||
| 117 : | #else | ||
| 118 : | |||
| 119 : | inline void LLV4Matrix3::lerp(const LLV4Matrix3 &a, const LLV4Matrix3 &b, const F32 &w) | ||
| 120 : | { | ||
| 121 : | mMatrix[VX][VX] = llv4lerp(a.mMatrix[VX][VX], b.mMatrix[VX][VX], w); | ||
| 122 : | mMatrix[VX][VY] = llv4lerp(a.mMatrix[VX][VY], b.mMatrix[VX][VY], w); | ||
| 123 : | mMatrix[VX][VZ] = llv4lerp(a.mMatrix[VX][VZ], b.mMatrix[VX][VZ], w); | ||
| 124 : | |||
| 125 : | mMatrix[VY][VX] = llv4lerp(a.mMatrix[VY][VX], b.mMatrix[VY][VX], w); | ||
| 126 : | mMatrix[VY][VY] = llv4lerp(a.mMatrix[VY][VY], b.mMatrix[VY][VY], w); | ||
| 127 : | mMatrix[VY][VZ] = llv4lerp(a.mMatrix[VY][VZ], b.mMatrix[VY][VZ], w); | ||
| 128 : | |||
| 129 : | mMatrix[VZ][VX] = llv4lerp(a.mMatrix[VZ][VX], b.mMatrix[VZ][VX], w); | ||
| 130 : | mMatrix[VZ][VY] = llv4lerp(a.mMatrix[VZ][VY], b.mMatrix[VZ][VY], w); | ||
| 131 : | mMatrix[VZ][VZ] = llv4lerp(a.mMatrix[VZ][VZ], b.mMatrix[VZ][VZ], w); | ||
| 132 : | } | ||
| 133 : | |||
| 134 : | inline void LLV4Matrix3::multiply(const LLVector3 &a, LLVector3& o) const | ||
| 135 : | { | ||
| 136 : | o.setVec( a.mV[VX] * mMatrix[VX][VX] + | ||
| 137 : | a.mV[VY] * mMatrix[VY][VX] + | ||
| 138 : | a.mV[VZ] * mMatrix[VZ][VX], | ||
| 139 : | |||
| 140 : | a.mV[VX] * mMatrix[VX][VY] + | ||
| 141 : | a.mV[VY] * mMatrix[VY][VY] + | ||
| 142 : | a.mV[VZ] * mMatrix[VZ][VY], | ||
| 143 : | |||
| 144 : | a.mV[VX] * mMatrix[VX][VZ] + | ||
| 145 : | a.mV[VY] * mMatrix[VY][VZ] + | ||
| 146 : | a.mV[VZ] * mMatrix[VZ][VZ]); | ||
| 147 : | } | ||
| 148 : | |||
| 149 : | inline void LLV4Matrix3::multiply(const LLVector4 &a, LLV4Vector3& o) const | ||
| 150 : | { | ||
| 151 : | o.setVec( a.mV[VX] * mMatrix[VX][VX] + | ||
| 152 : | a.mV[VY] * mMatrix[VY][VX] + | ||
| 153 : | a.mV[VZ] * mMatrix[VZ][VX], | ||
| 154 : | |||
| 155 : | a.mV[VX] * mMatrix[VX][VY] + | ||
| 156 : | a.mV[VY] * mMatrix[VY][VY] + | ||
| 157 : | a.mV[VZ] * mMatrix[VZ][VY], | ||
| 158 : | |||
| 159 : | a.mV[VX] * mMatrix[VX][VZ] + | ||
| 160 : | a.mV[VY] * mMatrix[VY][VZ] + | ||
| 161 : | a.mV[VZ] * mMatrix[VZ][VZ]); | ||
| 162 : | } | ||
| 163 : | |||
| 164 : | inline void LLV4Matrix3::multiply(const LLVector3 &a, LLV4Vector3& o) const | ||
| 165 : | { | ||
| 166 : | o.setVec( a.mV[VX] * mMatrix[VX][VX] + | ||
| 167 : | a.mV[VY] * mMatrix[VY][VX] + | ||
| 168 : | a.mV[VZ] * mMatrix[VZ][VX], | ||
| 169 : | |||
| 170 : | a.mV[VX] * mMatrix[VX][VY] + | ||
| 171 : | a.mV[VY] * mMatrix[VY][VY] + | ||
| 172 : | a.mV[VZ] * mMatrix[VZ][VY], | ||
| 173 : | |||
| 174 : | a.mV[VX] * mMatrix[VX][VZ] + | ||
| 175 : | a.mV[VY] * mMatrix[VY][VZ] + | ||
| 176 : | a.mV[VZ] * mMatrix[VZ][VZ]); | ||
| 177 : | } | ||
| 178 : | |||
| 179 : | //----------------------------------------------------------------------------- | ||
| 180 : | //----------------------------------------------------------------------------- | ||
| 181 : | // LLV4Matrix3 | ||
| 182 : | //----------------------------------------------------------------------------- | ||
| 183 : | //----------------------------------------------------------------------------- | ||
| 184 : | |||
| 185 : | #endif | ||
| 186 : | |||
| 187 : | inline const LLV4Matrix3& LLV4Matrix3::transpose() | ||
| 188 : | { | ||
| 189 : | #if LL_VECTORIZE && defined(_MM_TRANSPOSE4_PS) | ||
| 190 : | _MM_TRANSPOSE4_PS(mV[VX], mV[VY], mV[VZ], mV[VW]); | ||
| 191 : | return *this; | ||
| 192 : | #else | ||
| 193 : | F32 temp; | ||
| 194 : | temp = mMatrix[VX][VY]; mMatrix[VX][VY] = mMatrix[VY][VX]; mMatrix[VY][VX] = temp; | ||
| 195 : | temp = mMatrix[VX][VZ]; mMatrix[VX][VZ] = mMatrix[VZ][VX]; mMatrix[VZ][VX] = temp; | ||
| 196 : | temp = mMatrix[VY][VZ]; mMatrix[VY][VZ] = mMatrix[VZ][VY]; mMatrix[VZ][VY] = temp; | ||
| 197 : | #endif | ||
| 198 : | return *this; | ||
| 199 : | } | ||
| 200 : | |||
| 201 : | inline const LLV4Matrix3& LLV4Matrix3::operator=(const LLMatrix3& a) | ||
| 202 : | { | ||
| 203 : | memcpy(mMatrix[VX], a.mMatrix[VX], sizeof(F32) * 3 ); | ||
| 204 : | memcpy(mMatrix[VY], a.mMatrix[VY], sizeof(F32) * 3 ); | ||
| 205 : | memcpy(mMatrix[VZ], a.mMatrix[VZ], sizeof(F32) * 3 ); | ||
| 206 : | return *this; | ||
| 207 : | } | ||
| 208 : | |||
| 209 : | inline LLVector3 operator*(const LLVector3& a, const LLV4Matrix3& b) | ||
| 210 : | { | ||
| 211 : | return LLVector3( | ||
| 212 : | a.mV[VX] * b.mMatrix[VX][VX] + | ||
| 213 : | a.mV[VY] * b.mMatrix[VY][VX] + | ||
| 214 : | a.mV[VZ] * b.mMatrix[VZ][VX], | ||
| 215 : | |||
| 216 : | a.mV[VX] * b.mMatrix[VX][VY] + | ||
| 217 : | a.mV[VY] * b.mMatrix[VY][VY] + | ||
| 218 : | a.mV[VZ] * b.mMatrix[VZ][VY], | ||
| 219 : | |||
| 220 : | a.mV[VX] * b.mMatrix[VX][VZ] + | ||
| 221 : | a.mV[VY] * b.mMatrix[VY][VZ] + | ||
| 222 : | a.mV[VZ] * b.mMatrix[VZ][VZ] ); | ||
| 223 : | } | ||
| 224 : | |||
| 225 : | #endif |
| ViewVC Help | |
| Powered by ViewVC 1.0.0 |

