PageRenderTime 23ms CodeModel.GetById 14ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llmath/llmatrix4a.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 143 lines | 94 code | 23 blank | 26 comment | 0 complexity | 7aa5e5cd368ef02f4407051f594ca5b9 MD5 | raw file
  1/** 
  2 * @file llmatrix4a.h
  3 * @brief LLMatrix4a class header file - memory aligned and vectorized 4x4 matrix
  4 *
  5 * $LicenseInfo:firstyear=2007&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#ifndef	LL_LLMATRIX4A_H
 28#define	LL_LLMATRIX4A_H
 29
 30#include "llvector4a.h"
 31#include "m4math.h"
 32#include "m3math.h"
 33
 34class LLMatrix4a
 35{
 36public:
 37	LLVector4a mMatrix[4];
 38
 39	inline void clear()
 40	{
 41		mMatrix[0].clear();
 42		mMatrix[1].clear();
 43		mMatrix[2].clear();
 44		mMatrix[3].clear();
 45	}
 46
 47	inline void loadu(const LLMatrix4& src)
 48	{
 49		mMatrix[0] = _mm_loadu_ps(src.mMatrix[0]);
 50		mMatrix[1] = _mm_loadu_ps(src.mMatrix[1]);
 51		mMatrix[2] = _mm_loadu_ps(src.mMatrix[2]);
 52		mMatrix[3] = _mm_loadu_ps(src.mMatrix[3]);
 53		
 54	}
 55
 56	inline void loadu(const LLMatrix3& src)
 57	{
 58		mMatrix[0].load3(src.mMatrix[0]);
 59		mMatrix[1].load3(src.mMatrix[1]);
 60		mMatrix[2].load3(src.mMatrix[2]);
 61		mMatrix[3].set(0,0,0,1.f);
 62	}
 63
 64	inline void add(const LLMatrix4a& rhs)
 65	{
 66		mMatrix[0].add(rhs.mMatrix[0]);
 67		mMatrix[1].add(rhs.mMatrix[1]);
 68		mMatrix[2].add(rhs.mMatrix[2]);
 69		mMatrix[3].add(rhs.mMatrix[3]);
 70	}
 71
 72	inline void setRows(const LLVector4a& r0, const LLVector4a& r1, const LLVector4a& r2)
 73	{
 74		mMatrix[0] = r0;
 75		mMatrix[1] = r1;
 76		mMatrix[2] = r2;
 77	}
 78
 79	inline void setMul(const LLMatrix4a& m, const F32 s)
 80	{
 81		mMatrix[0].setMul(m.mMatrix[0], s);
 82		mMatrix[1].setMul(m.mMatrix[1], s);
 83		mMatrix[2].setMul(m.mMatrix[2], s);
 84		mMatrix[3].setMul(m.mMatrix[3], s);
 85	}
 86
 87	inline void setLerp(const LLMatrix4a& a, const LLMatrix4a& b, F32 w)
 88	{
 89		LLVector4a d0,d1,d2,d3;
 90		d0.setSub(b.mMatrix[0], a.mMatrix[0]);
 91		d1.setSub(b.mMatrix[1], a.mMatrix[1]);
 92		d2.setSub(b.mMatrix[2], a.mMatrix[2]);
 93		d3.setSub(b.mMatrix[3], a.mMatrix[3]);
 94
 95		// this = a + d*w
 96		
 97		d0.mul(w);
 98		d1.mul(w);
 99		d2.mul(w);
100		d3.mul(w);
101
102		mMatrix[0].setAdd(a.mMatrix[0],d0);
103		mMatrix[1].setAdd(a.mMatrix[1],d1);
104		mMatrix[2].setAdd(a.mMatrix[2],d2);
105		mMatrix[3].setAdd(a.mMatrix[3],d3);
106	}
107
108	inline void rotate(const LLVector4a& v, LLVector4a& res)
109	{
110		res = _mm_shuffle_ps(v, v, _MM_SHUFFLE(0, 0, 0, 0));
111		res.mul(mMatrix[0]);
112		
113		LLVector4a y;
114		y = _mm_shuffle_ps(v, v, _MM_SHUFFLE(1, 1, 1, 1));
115		y.mul(mMatrix[1]);
116
117		LLVector4a z;
118		z = _mm_shuffle_ps(v, v, _MM_SHUFFLE(2, 2, 2, 2));
119		z.mul(mMatrix[2]);
120
121		res.add(y);
122		res.add(z);
123	}
124
125	inline void affineTransform(const LLVector4a& v, LLVector4a& res)
126	{
127		LLVector4a x,y,z;
128
129		x = _mm_shuffle_ps(v, v, _MM_SHUFFLE(0, 0, 0, 0));
130		y = _mm_shuffle_ps(v, v, _MM_SHUFFLE(1, 1, 1, 1));
131		z = _mm_shuffle_ps(v, v, _MM_SHUFFLE(2, 2, 2, 2));
132		
133		x.mul(mMatrix[0]);
134		y.mul(mMatrix[1]);
135		z.mul(mMatrix[2]);
136
137		x.add(y);
138		z.add(mMatrix[3]);
139		res.setAdd(x,z);
140	}
141};
142
143#endif