diff options
Diffstat (limited to 'linden/indra/llmath/xform.cpp')
-rw-r--r-- | linden/indra/llmath/xform.cpp | 115 |
1 files changed, 115 insertions, 0 deletions
diff --git a/linden/indra/llmath/xform.cpp b/linden/indra/llmath/xform.cpp new file mode 100644 index 0000000..fc2e060 --- /dev/null +++ b/linden/indra/llmath/xform.cpp | |||
@@ -0,0 +1,115 @@ | |||
1 | /** | ||
2 | * @file xform.cpp | ||
3 | * | ||
4 | * Copyright (c) 2001-2007, Linden Research, Inc. | ||
5 | * | ||
6 | * The source code in this file ("Source Code") is provided by Linden Lab | ||
7 | * to you under the terms of the GNU General Public License, version 2.0 | ||
8 | * ("GPL"), unless you have obtained a separate licensing agreement | ||
9 | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
10 | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
11 | * online at http://secondlife.com/developers/opensource/gplv2 | ||
12 | * | ||
13 | * There are special exceptions to the terms and conditions of the GPL as | ||
14 | * it is applied to this Source Code. View the full text of the exception | ||
15 | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
16 | * online at http://secondlife.com/developers/opensource/flossexception | ||
17 | * | ||
18 | * By copying, modifying or distributing this software, you acknowledge | ||
19 | * that you have read and understood your obligations described above, | ||
20 | * and agree to abide by those obligations. | ||
21 | * | ||
22 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
23 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
24 | * COMPLETENESS OR PERFORMANCE. | ||
25 | */ | ||
26 | |||
27 | #include "linden_common.h" | ||
28 | |||
29 | #include "xform.h" | ||
30 | |||
31 | LLXform::LLXform() | ||
32 | { | ||
33 | init(); | ||
34 | } | ||
35 | |||
36 | LLXform::~LLXform() | ||
37 | { | ||
38 | } | ||
39 | |||
40 | |||
41 | LLXform* LLXform::getRoot() const | ||
42 | { | ||
43 | const LLXform* root = this; | ||
44 | while(root->mParent) | ||
45 | { | ||
46 | root = root->mParent; | ||
47 | } | ||
48 | return (LLXform*)root; | ||
49 | } | ||
50 | |||
51 | BOOL LLXform::isRoot() const | ||
52 | { | ||
53 | return (!mParent); | ||
54 | } | ||
55 | |||
56 | BOOL LLXform::isRootEdit() const | ||
57 | { | ||
58 | return (!mParent); | ||
59 | } | ||
60 | |||
61 | LLXformMatrix::~LLXformMatrix() | ||
62 | { | ||
63 | } | ||
64 | |||
65 | void LLXformMatrix::update() | ||
66 | { | ||
67 | if (mParent) | ||
68 | { | ||
69 | mWorldPosition = mPosition; | ||
70 | if (mParent->getScaleChildOffset()) | ||
71 | { | ||
72 | mWorldPosition.scaleVec(mParent->getScale()); | ||
73 | } | ||
74 | mWorldPosition *= mParent->getWorldRotation(); | ||
75 | mWorldPosition += mParent->getWorldPosition(); | ||
76 | mWorldRotation = mRotation * mParent->getWorldRotation(); | ||
77 | } | ||
78 | else | ||
79 | { | ||
80 | mWorldPosition = mPosition; | ||
81 | mWorldRotation = mRotation; | ||
82 | } | ||
83 | } | ||
84 | |||
85 | void LLXformMatrix::updateMatrix(BOOL update_bounds) | ||
86 | { | ||
87 | update(); | ||
88 | |||
89 | mWorldMatrix.initAll(mScale, mWorldRotation, mWorldPosition); | ||
90 | |||
91 | if (update_bounds && (mChanged & MOVED)) | ||
92 | { | ||
93 | mMin.mV[0] = mMax.mV[0] = mWorldMatrix.mMatrix[3][0]; | ||
94 | mMin.mV[1] = mMax.mV[1] = mWorldMatrix.mMatrix[3][1]; | ||
95 | mMin.mV[2] = mMax.mV[2] = mWorldMatrix.mMatrix[3][2]; | ||
96 | |||
97 | F32 f0 = (fabs(mWorldMatrix.mMatrix[0][0])+fabs(mWorldMatrix.mMatrix[1][0])+fabs(mWorldMatrix.mMatrix[2][0])) * 0.5f; | ||
98 | F32 f1 = (fabs(mWorldMatrix.mMatrix[0][1])+fabs(mWorldMatrix.mMatrix[1][1])+fabs(mWorldMatrix.mMatrix[2][1])) * 0.5f; | ||
99 | F32 f2 = (fabs(mWorldMatrix.mMatrix[0][2])+fabs(mWorldMatrix.mMatrix[1][2])+fabs(mWorldMatrix.mMatrix[2][2])) * 0.5f; | ||
100 | |||
101 | mMin.mV[0] -= f0; | ||
102 | mMin.mV[1] -= f1; | ||
103 | mMin.mV[2] -= f2; | ||
104 | |||
105 | mMax.mV[0] += f0; | ||
106 | mMax.mV[1] += f1; | ||
107 | mMax.mV[2] += f2; | ||
108 | } | ||
109 | } | ||
110 | |||
111 | void LLXformMatrix::getMinMax(LLVector3& min, LLVector3& max) const | ||
112 | { | ||
113 | min = mMin; | ||
114 | max = mMax; | ||
115 | } | ||