aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/llbbox.cpp
diff options
context:
space:
mode:
authorJacek Antonelli2008-08-15 23:44:46 -0500
committerJacek Antonelli2008-08-15 23:44:46 -0500
commit38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4 (patch)
treeadca584755d22ca041a2dbfc35d4eca01f70b32c /linden/indra/newview/llbbox.cpp
parentREADME.txt (diff)
downloadmeta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.zip
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.gz
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.bz2
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.xz
Second Life viewer sources 1.13.2.12
Diffstat (limited to 'linden/indra/newview/llbbox.cpp')
-rw-r--r--linden/indra/newview/llbbox.cpp157
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
36void 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
55void LLBBox::addPointAgent( LLVector3 p)
56{
57 p -= mPosAgent;
58 p.rotVec( ~mRotation );
59 addPointLocal( p );
60}
61
62
63void 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
94void 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
104LLVector3 LLBBox::localToAgent(const LLVector3& v) const
105{
106 LLMatrix4 m( mRotation );
107 m.translate( mPosAgent );
108 return v * m;
109}
110
111LLVector3 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
119LLVector3 LLBBox::localToAgentBasis(const LLVector3& v) const
120{
121 LLMatrix4 m( mRotation );
122 return v * m;
123}
124
125LLVector3 LLBBox::agentToLocalBasis(const LLVector3& v) const
126{
127 LLMatrix4 m( ~mRotation ); // inverse rotation
128 return v * m;
129}
130
131BOOL 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
145BOOL LLBBox::containsPointAgent(const LLVector3& p) const
146{
147 LLVector3 point_local = agentToLocal(p);
148 return containsPointLocal(point_local);
149}
150
151
152/*
153LLBBox operator*(const LLBBox &a, const LLMatrix4 &b)
154{
155 return LLBBox( a.mMin * b, a.mMax * b );
156}
157*/