PageRenderTime 32ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/llmath/llplane.h

https://bitbucket.org/lindenlab/viewer-beta/
C Header | 101 lines | 43 code | 20 blank | 38 comment | 0 complexity | a3b235ace7274b1058118e9cc4368fa2 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llplane.h
  3. *
  4. * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  5. * Second Life Viewer Source Code
  6. * Copyright (C) 2010, Linden Research, Inc.
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation;
  11. * version 2.1 of the License only.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with this library; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. *
  22. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  23. * $/LicenseInfo$
  24. */
  25. #ifndef LL_LLPLANE_H
  26. #define LL_LLPLANE_H
  27. #include "v3math.h"
  28. #include "v4math.h"
  29. // A simple way to specify a plane is to give its normal,
  30. // and it's nearest approach to the origin.
  31. //
  32. // Given the equation for a plane : A*x + B*y + C*z + D = 0
  33. // The plane normal = [A, B, C]
  34. // The closest approach = D / sqrt(A*A + B*B + C*C)
  35. class LLPlane
  36. {
  37. public:
  38. // Constructors
  39. LLPlane() {}; // no default constructor
  40. LLPlane(const LLVector3 &p0, F32 d) { setVec(p0, d); }
  41. LLPlane(const LLVector3 &p0, const LLVector3 &n) { setVec(p0, n); }
  42. inline void setVec(const LLVector3 &p0, F32 d) { mV.set(p0[0], p0[1], p0[2], d); }
  43. // Set
  44. inline void setVec(const LLVector3 &p0, const LLVector3 &n)
  45. {
  46. F32 d = -(p0 * n);
  47. setVec(n, d);
  48. }
  49. inline void setVec(const LLVector3 &p0, const LLVector3 &p1, const LLVector3 &p2)
  50. {
  51. LLVector3 u, v, w;
  52. u = p1 - p0;
  53. v = p2 - p0;
  54. w = u % v;
  55. w.normVec();
  56. F32 d = -(w * p0);
  57. setVec(w, d);
  58. }
  59. inline LLPlane& operator=(const LLVector4& v2) { mV.set(v2[0],v2[1],v2[2],v2[3]); return *this;}
  60. inline LLPlane& operator=(const LLVector4a& v2) { mV.set(v2[0],v2[1],v2[2],v2[3]); return *this;}
  61. inline void set(const LLPlane& p2) { mV = p2.mV; }
  62. //
  63. F32 dist(const LLVector3 &v2) const { return mV[0]*v2[0] + mV[1]*v2[1] + mV[2]*v2[2] + mV[3]; }
  64. inline LLSimdScalar dot3(const LLVector4a& b) const { return mV.dot3(b); }
  65. // Read-only access a single float in this vector. Do not use in proximity to any function call that manipulates
  66. // the data at the whole vector level or you will incur a substantial penalty. Consider using the splat functions instead
  67. inline F32 operator[](const S32 idx) const { return mV[idx]; }
  68. // preferable when index is known at compile time
  69. template <int N> LL_FORCE_INLINE void getAt(LLSimdScalar& v) const { v = mV.getScalarAt<N>(); }
  70. // reset the vector to 0, 0, 0, 1
  71. inline void clear() { mV.set(0, 0, 0, 1); }
  72. inline void getVector3(LLVector3& vec) const { vec.set(mV[0], mV[1], mV[2]); }
  73. // Retrieve the mask indicating which of the x, y, or z axis are greater or equal to zero.
  74. inline U8 calcPlaneMask()
  75. {
  76. return mV.greaterEqual(LLVector4a::getZero()).getGatheredBits() & LLVector4Logical::MASK_XYZ;
  77. }
  78. private:
  79. LLVector4a mV;
  80. };
  81. #endif // LL_LLPLANE_H