diff options
Diffstat (limited to 'linden/indra/newview/llbbox.cpp')
-rw-r--r-- | linden/indra/newview/llbbox.cpp | 157 |
1 files changed, 157 insertions, 0 deletions
diff --git a/linden/indra/newview/llbbox.cpp b/linden/indra/newview/llbbox.cpp new file mode 100644 index 0000000..aa3d892 --- /dev/null +++ b/linden/indra/newview/llbbox.cpp | |||
@@ -0,0 +1,157 @@ | |||
1 | /** | ||
2 | * @file llbbox.cpp | ||
3 | * @brief General purpose bounding box class (Not axis aligned) | ||
4 | * | ||
5 | * Copyright (c) 2001-2007, Linden Research, Inc. | ||
6 | * | ||
7 | * The source code in this file ("Source Code") is provided by Linden Lab | ||
8 | * to you under the terms of the GNU General Public License, version 2.0 | ||
9 | * ("GPL"), unless you have obtained a separate licensing agreement | ||
10 | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
11 | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
12 | * online at http://secondlife.com/developers/opensource/gplv2 | ||
13 | * | ||
14 | * There are special exceptions to the terms and conditions of the GPL as | ||
15 | * it is applied to this Source Code. View the full text of the exception | ||
16 | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
17 | * online at http://secondlife.com/developers/opensource/flossexception | ||
18 | * | ||
19 | * By copying, modifying or distributing this software, you acknowledge | ||
20 | * that you have read and understood your obligations described above, | ||
21 | * and agree to abide by those obligations. | ||
22 | * | ||
23 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
24 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
25 | * COMPLETENESS OR PERFORMANCE. | ||
26 | */ | ||
27 | |||
28 | #include "llviewerprecompiledheaders.h" | ||
29 | |||
30 | // self include | ||
31 | #include "llbbox.h" | ||
32 | |||
33 | // library includes | ||
34 | #include "m4math.h" | ||
35 | |||
36 | void LLBBox::addPointLocal(const LLVector3& p) | ||
37 | { | ||
38 | if (mEmpty) | ||
39 | { | ||
40 | mMinLocal = p; | ||
41 | mMaxLocal = p; | ||
42 | mEmpty = FALSE; | ||
43 | } | ||
44 | else | ||
45 | { | ||
46 | mMinLocal.mV[VX] = llmin( p.mV[VX], mMinLocal.mV[VX] ); | ||
47 | mMinLocal.mV[VY] = llmin( p.mV[VY], mMinLocal.mV[VY] ); | ||
48 | mMinLocal.mV[VZ] = llmin( p.mV[VZ], mMinLocal.mV[VZ] ); | ||
49 | mMaxLocal.mV[VX] = llmax( p.mV[VX], mMaxLocal.mV[VX] ); | ||
50 | mMaxLocal.mV[VY] = llmax( p.mV[VY], mMaxLocal.mV[VY] ); | ||
51 | mMaxLocal.mV[VZ] = llmax( p.mV[VZ], mMaxLocal.mV[VZ] ); | ||
52 | } | ||
53 | } | ||
54 | |||
55 | void LLBBox::addPointAgent( LLVector3 p) | ||
56 | { | ||
57 | p -= mPosAgent; | ||
58 | p.rotVec( ~mRotation ); | ||
59 | addPointLocal( p ); | ||
60 | } | ||
61 | |||
62 | |||
63 | void LLBBox::addBBoxAgent(const LLBBox& b) | ||
64 | { | ||
65 | if (mEmpty) | ||
66 | { | ||
67 | mPosAgent = b.mPosAgent; | ||
68 | mRotation = b.mRotation; | ||
69 | mMinLocal.clearVec(); | ||
70 | mMaxLocal.clearVec(); | ||
71 | } | ||
72 | LLVector3 vertex[8]; | ||
73 | vertex[0].setVec( b.mMinLocal.mV[VX], b.mMinLocal.mV[VY], b.mMinLocal.mV[VZ] ); | ||
74 | vertex[1].setVec( b.mMinLocal.mV[VX], b.mMinLocal.mV[VY], b.mMaxLocal.mV[VZ] ); | ||
75 | vertex[2].setVec( b.mMinLocal.mV[VX], b.mMaxLocal.mV[VY], b.mMinLocal.mV[VZ] ); | ||
76 | vertex[3].setVec( b.mMinLocal.mV[VX], b.mMaxLocal.mV[VY], b.mMaxLocal.mV[VZ] ); | ||
77 | vertex[4].setVec( b.mMaxLocal.mV[VX], b.mMinLocal.mV[VY], b.mMinLocal.mV[VZ] ); | ||
78 | vertex[5].setVec( b.mMaxLocal.mV[VX], b.mMinLocal.mV[VY], b.mMaxLocal.mV[VZ] ); | ||
79 | vertex[6].setVec( b.mMaxLocal.mV[VX], b.mMaxLocal.mV[VY], b.mMinLocal.mV[VZ] ); | ||
80 | vertex[7].setVec( b.mMaxLocal.mV[VX], b.mMaxLocal.mV[VY], b.mMaxLocal.mV[VZ] ); | ||
81 | |||
82 | LLMatrix4 m( b.mRotation ); | ||
83 | m.translate( b.mPosAgent ); | ||
84 | m.translate( -mPosAgent ); | ||
85 | m.rotate( ~mRotation ); | ||
86 | |||
87 | for( S32 i=0; i<8; i++ ) | ||
88 | { | ||
89 | addPointLocal( vertex[i] * m ); | ||
90 | } | ||
91 | } | ||
92 | |||
93 | |||
94 | void LLBBox::expand( F32 delta ) | ||
95 | { | ||
96 | mMinLocal.mV[VX] -= delta; | ||
97 | mMinLocal.mV[VY] -= delta; | ||
98 | mMinLocal.mV[VZ] -= delta; | ||
99 | mMaxLocal.mV[VX] += delta; | ||
100 | mMaxLocal.mV[VY] += delta; | ||
101 | mMaxLocal.mV[VZ] += delta; | ||
102 | } | ||
103 | |||
104 | LLVector3 LLBBox::localToAgent(const LLVector3& v) const | ||
105 | { | ||
106 | LLMatrix4 m( mRotation ); | ||
107 | m.translate( mPosAgent ); | ||
108 | return v * m; | ||
109 | } | ||
110 | |||
111 | LLVector3 LLBBox::agentToLocal(const LLVector3& v) const | ||
112 | { | ||
113 | LLMatrix4 m; | ||
114 | m.translate( -mPosAgent ); | ||
115 | m.rotate( ~mRotation ); // inverse rotation | ||
116 | return v * m; | ||
117 | } | ||
118 | |||
119 | LLVector3 LLBBox::localToAgentBasis(const LLVector3& v) const | ||
120 | { | ||
121 | LLMatrix4 m( mRotation ); | ||
122 | return v * m; | ||
123 | } | ||
124 | |||
125 | LLVector3 LLBBox::agentToLocalBasis(const LLVector3& v) const | ||
126 | { | ||
127 | LLMatrix4 m( ~mRotation ); // inverse rotation | ||
128 | return v * m; | ||
129 | } | ||
130 | |||
131 | BOOL LLBBox::containsPointLocal(const LLVector3& p) const | ||
132 | { | ||
133 | if ( (p.mV[VX] < mMinLocal.mV[VX]) | ||
134 | ||(p.mV[VX] > mMaxLocal.mV[VX]) | ||
135 | ||(p.mV[VY] < mMinLocal.mV[VY]) | ||
136 | ||(p.mV[VY] > mMaxLocal.mV[VY]) | ||
137 | ||(p.mV[VZ] < mMinLocal.mV[VZ]) | ||
138 | ||(p.mV[VZ] > mMaxLocal.mV[VZ])) | ||
139 | { | ||
140 | return FALSE; | ||
141 | } | ||
142 | return TRUE; | ||
143 | } | ||
144 | |||
145 | BOOL LLBBox::containsPointAgent(const LLVector3& p) const | ||
146 | { | ||
147 | LLVector3 point_local = agentToLocal(p); | ||
148 | return containsPointLocal(point_local); | ||
149 | } | ||
150 | |||
151 | |||
152 | /* | ||
153 | LLBBox operator*(const LLBBox &a, const LLMatrix4 &b) | ||
154 | { | ||
155 | return LLBBox( a.mMin * b, a.mMax * b ); | ||
156 | } | ||
157 | */ | ||