PageRenderTime 47ms CodeModel.GetById 19ms RepoModel.GetById 0ms 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
Possible License(s): LGPL-2.1
  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. #ifndef LL_LLMATRIX4A_H
  27. #define LL_LLMATRIX4A_H
  28. #include "llvector4a.h"
  29. #include "m4math.h"
  30. #include "m3math.h"
  31. class LLMatrix4a
  32. {
  33. public:
  34. LLVector4a mMatrix[4];
  35. inline void clear()
  36. {
  37. mMatrix[0].clear();
  38. mMatrix[1].clear();
  39. mMatrix[2].clear();
  40. mMatrix[3].clear();
  41. }
  42. inline void loadu(const LLMatrix4& src)
  43. {
  44. mMatrix[0] = _mm_loadu_ps(src.mMatrix[0]);
  45. mMatrix[1] = _mm_loadu_ps(src.mMatrix[1]);
  46. mMatrix[2] = _mm_loadu_ps(src.mMatrix[2]);
  47. mMatrix[3] = _mm_loadu_ps(src.mMatrix[3]);
  48. }
  49. inline void loadu(const LLMatrix3& src)
  50. {
  51. mMatrix[0].load3(src.mMatrix[0]);
  52. mMatrix[1].load3(src.mMatrix[1]);
  53. mMatrix[2].load3(src.mMatrix[2]);
  54. mMatrix[3].set(0,0,0,1.f);
  55. }
  56. inline void add(const LLMatrix4a& rhs)
  57. {
  58. mMatrix[0].add(rhs.mMatrix[0]);
  59. mMatrix[1].add(rhs.mMatrix[1]);
  60. mMatrix[2].add(rhs.mMatrix[2]);
  61. mMatrix[3].add(rhs.mMatrix[3]);
  62. }
  63. inline void setRows(const LLVector4a& r0, const LLVector4a& r1, const LLVector4a& r2)
  64. {
  65. mMatrix[0] = r0;
  66. mMatrix[1] = r1;
  67. mMatrix[2] = r2;
  68. }
  69. inline void setMul(const LLMatrix4a& m, const F32 s)
  70. {
  71. mMatrix[0].setMul(m.mMatrix[0], s);
  72. mMatrix[1].setMul(m.mMatrix[1], s);
  73. mMatrix[2].setMul(m.mMatrix[2], s);
  74. mMatrix[3].setMul(m.mMatrix[3], s);
  75. }
  76. inline void setLerp(const LLMatrix4a& a, const LLMatrix4a& b, F32 w)
  77. {
  78. LLVector4a d0,d1,d2,d3;
  79. d0.setSub(b.mMatrix[0], a.mMatrix[0]);
  80. d1.setSub(b.mMatrix[1], a.mMatrix[1]);
  81. d2.setSub(b.mMatrix[2], a.mMatrix[2]);
  82. d3.setSub(b.mMatrix[3], a.mMatrix[3]);
  83. // this = a + d*w
  84. d0.mul(w);
  85. d1.mul(w);
  86. d2.mul(w);
  87. d3.mul(w);
  88. mMatrix[0].setAdd(a.mMatrix[0],d0);
  89. mMatrix[1].setAdd(a.mMatrix[1],d1);
  90. mMatrix[2].setAdd(a.mMatrix[2],d2);
  91. mMatrix[3].setAdd(a.mMatrix[3],d3);
  92. }
  93. inline void rotate(const LLVector4a& v, LLVector4a& res)
  94. {
  95. res = _mm_shuffle_ps(v, v, _MM_SHUFFLE(0, 0, 0, 0));
  96. res.mul(mMatrix[0]);
  97. LLVector4a y;
  98. y = _mm_shuffle_ps(v, v, _MM_SHUFFLE(1, 1, 1, 1));
  99. y.mul(mMatrix[1]);
  100. LLVector4a z;
  101. z = _mm_shuffle_ps(v, v, _MM_SHUFFLE(2, 2, 2, 2));
  102. z.mul(mMatrix[2]);
  103. res.add(y);
  104. res.add(z);
  105. }
  106. inline void affineTransform(const LLVector4a& v, LLVector4a& res)
  107. {
  108. LLVector4a x,y,z;
  109. x = _mm_shuffle_ps(v, v, _MM_SHUFFLE(0, 0, 0, 0));
  110. y = _mm_shuffle_ps(v, v, _MM_SHUFFLE(1, 1, 1, 1));
  111. z = _mm_shuffle_ps(v, v, _MM_SHUFFLE(2, 2, 2, 2));
  112. x.mul(mMatrix[0]);
  113. y.mul(mMatrix[1]);
  114. z.mul(mMatrix[2]);
  115. x.add(y);
  116. z.add(mMatrix[3]);
  117. res.setAdd(x,z);
  118. }
  119. };
  120. #endif