#### /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
```  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
26#ifndef LL_LLPLANE_H
27#define LL_LLPLANE_H
28
29#include "v3math.h"
30#include "v4math.h"
31
32// A simple way to specify a plane is to give its normal,
33// and it's nearest approach to the origin.
34//
35// Given the equation for a plane : A*x + B*y + C*z + D = 0
36// The plane normal = [A, B, C]
37// The closest approach = D / sqrt(A*A + B*B + C*C)
38
39class LLPlane
40{
41public:
42
43	// Constructors
44	LLPlane() {}; // no default constructor
45	LLPlane(const LLVector3 &p0, F32 d) { setVec(p0, d); }
46	LLPlane(const LLVector3 &p0, const LLVector3 &n) { setVec(p0, n); }
47	inline void setVec(const LLVector3 &p0, F32 d) { mV.set(p0[0], p0[1], p0[2], d); }
48
49	// Set
50	inline void setVec(const LLVector3 &p0, const LLVector3 &n)
51	{
52		F32 d = -(p0 * n);
53		setVec(n, d);
54	}
55	inline void setVec(const LLVector3 &p0, const LLVector3 &p1, const LLVector3 &p2)
56	{
57		LLVector3 u, v, w;
58		u = p1 - p0;
59		v = p2 - p0;
60		w = u % v;
61		w.normVec();
62		F32 d = -(w * p0);
63		setVec(w, d);
64	}
65
66	inline LLPlane& operator=(const LLVector4& v2) {  mV.set(v2[0],v2[1],v2[2],v2[3]); return *this;}
67
68	inline LLPlane& operator=(const LLVector4a& v2) {  mV.set(v2[0],v2[1],v2[2],v2[3]); return *this;}
69
70	inline void set(const LLPlane& p2) { mV = p2.mV; }
71
72	//
73	F32 dist(const LLVector3 &v2) const { return mV[0]*v2[0] + mV[1]*v2[1] + mV[2]*v2[2] + mV[3]; }
74
75	inline LLSimdScalar dot3(const LLVector4a& b) const { return mV.dot3(b); }
76
77	// Read-only access a single float in this vector. Do not use in proximity to any function call that manipulates
78	// the data at the whole vector level or you will incur a substantial penalty. Consider using the splat functions instead
79	inline F32 operator[](const S32 idx) const { return mV[idx]; }
80
81	// preferable when index is known at compile time
82	template <int N> LL_FORCE_INLINE void getAt(LLSimdScalar& v) const { v = mV.getScalarAt<N>(); }
83
84	// reset the vector to 0, 0, 0, 1
85	inline void clear() { mV.set(0, 0, 0, 1); }
86
87	inline void getVector3(LLVector3& vec) const { vec.set(mV[0], mV[1], mV[2]); }
88
89	// Retrieve the mask indicating which of the x, y, or z axis are greater or equal to zero.
90	inline U8 calcPlaneMask()
91	{
92		return mV.greaterEqual(LLVector4a::getZero()).getGatheredBits() & LLVector4Logical::MASK_XYZ;
93	}
94
95private:
96	LLVector4a mV;
97};
98
99
100
101#endif // LL_LLPLANE_H
```