llmatrix3a.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /**
  2. * @file llmatrix3a.h
  3. * @brief LLMatrix3a class header file - memory aligned and vectorized 3x3 matrix
  4. *
  5. * $LicenseInfo:firstyear=2010&license=viewergpl$
  6. *
  7. * Copyright (C) 2010, 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
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #ifndef LL_LLMATRIX3A_H
  33. #define LL_LLMATRIX3A_H
  34. class LLMatrix3;
  35. /////////////////////////////
  36. // LLMatrix3a, LLRotation
  37. //
  38. // This class stores a 3x3 (technically 4x3) matrix in column-major order.
  39. //
  40. // These classes are intentionally minimal right now. If you need additional
  41. // functionality, please contact someone with SSE experience (e.g., Falcon or
  42. // Huseby).
  43. /////////////////////////////
  44. // LLMatrix3a is the base class for LLRotation, which should be used instead
  45. // any time you're dealing with a rotation matrix.
  46. class alignas(16) LLMatrix3a
  47. {
  48. public:
  49. // Utility function for quickly transforming an array of LLVector4a's.
  50. // For transforming a single LLVector4a, see LLVector4a::setRotated().
  51. static void batchTransform(const LLMatrix3a& xform, const LLVector4a* src,
  52. int numVectors, LLVector4a* dst);
  53. // Utility function to obtain the identity matrix
  54. static LL_INLINE const LLMatrix3a& getIdentity();
  55. LL_INLINE LLMatrix3a() {}
  56. // Ctor for setting by columns
  57. LL_INLINE LLMatrix3a(const LLVector4a& c0, const LLVector4a& c1,
  58. const LLVector4a& c2);
  59. // Loads from an LLMatrix3
  60. LL_INLINE void loadu(const LLMatrix3& src);
  61. // Set rows
  62. LL_INLINE void setRows(const LLVector4a& r0, const LLVector4a& r1,
  63. const LLVector4a& r2);
  64. // Set columns
  65. LL_INLINE void setColumns(const LLVector4a& c0, const LLVector4a& c1,
  66. const LLVector4a& c2);
  67. // Get the read-only access to a specified column. Valid columns are 0-2,
  68. // but the function is unchecked. You have been warned.
  69. LL_INLINE const LLVector4a& getColumn(U32 column) const;
  70. /////////////////////////
  71. // Matrix modification
  72. /////////////////////////
  73. // Set this matrix to the product of lhs and rhs (this = lhs * rhs)
  74. void setMul(const LLMatrix3a& lhs, const LLMatrix3a& rhs);
  75. // Set this matrix to the transpose of src
  76. LL_INLINE void setTranspose(const LLMatrix3a& src);
  77. // Set this matrix to a*w + b*(1-w)
  78. LL_INLINE void setLerp(const LLMatrix3a& a, const LLMatrix3a& b, F32 w);
  79. /////////////////////////
  80. // Matrix inspection
  81. /////////////////////////
  82. // Sets all 4 elements in 'dest' to the determinant of this matrix.
  83. // If you will be using the determinant in subsequent ops with LLVector4a,
  84. // use this version
  85. LL_INLINE void getDeterminant(LLVector4a& dest) const;
  86. // Returns the determinant as an LLSimdScalar. Use this if you will be
  87. // using the determinant primary for scalar operations.
  88. LL_INLINE LLSimdScalar getDeterminant() const;
  89. // Returns nonzero if rows 0-2 and colums 0-2 contain no NaN or INF values.
  90. // Row 3 is ignored
  91. LL_INLINE LLBool32 isFinite() const;
  92. // Returns true if this matrix is equal to 'rhs' up to 'tolerance'
  93. LL_INLINE bool isApproximatelyEqual(const LLMatrix3a& rhs,
  94. F32 tolerance = F_APPROXIMATELY_ZERO) const;
  95. protected:
  96. alignas(16) LLVector4a mColumns[3];
  97. };
  98. class alignas(16) LLRotation : public LLMatrix3a
  99. {
  100. public:
  101. LL_INLINE LLRotation() {}
  102. // Returns true if this rotation is orthonormal with det ~= 1
  103. LL_INLINE bool isOkRotation() const;
  104. };
  105. #endif