diff options
author | Jacek Antonelli | 2008-08-15 23:44:46 -0500 |
---|---|---|
committer | Jacek Antonelli | 2008-08-15 23:44:46 -0500 |
commit | 38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4 (patch) | |
tree | adca584755d22ca041a2dbfc35d4eca01f70b32c /linden/indra/llmath/v3dmath.cpp | |
parent | README.txt (diff) | |
download | meta-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/llmath/v3dmath.cpp')
-rw-r--r-- | linden/indra/llmath/v3dmath.cpp | 148 |
1 files changed, 148 insertions, 0 deletions
diff --git a/linden/indra/llmath/v3dmath.cpp b/linden/indra/llmath/v3dmath.cpp new file mode 100644 index 0000000..5d3aad0 --- /dev/null +++ b/linden/indra/llmath/v3dmath.cpp | |||
@@ -0,0 +1,148 @@ | |||
1 | /** | ||
2 | * @file v3dmath.cpp | ||
3 | * @brief LLVector3d class implementation. | ||
4 | * | ||
5 | * Copyright (c) 2000-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 "linden_common.h" | ||
29 | |||
30 | //#include <sstream> // gcc 2.95.2 doesn't support sstream | ||
31 | |||
32 | #include "v3dmath.h" | ||
33 | |||
34 | //#include "vmath.h" | ||
35 | #include "v4math.h" | ||
36 | #include "m4math.h" | ||
37 | #include "m3math.h" | ||
38 | #include "llquaternion.h" | ||
39 | #include "llquantize.h" | ||
40 | |||
41 | // LLVector3d | ||
42 | // WARNING: Don't use these for global const definitions! | ||
43 | // For example: | ||
44 | // const LLQuaternion(0.5f * F_PI, LLVector3d::zero); | ||
45 | // at the top of a *.cpp file might not give you what you think. | ||
46 | const LLVector3d LLVector3d::zero(0,0,0); | ||
47 | const LLVector3d LLVector3d::x_axis(1, 0, 0); | ||
48 | const LLVector3d LLVector3d::y_axis(0, 1, 0); | ||
49 | const LLVector3d LLVector3d::z_axis(0, 0, 1); | ||
50 | const LLVector3d LLVector3d::x_axis_neg(-1, 0, 0); | ||
51 | const LLVector3d LLVector3d::y_axis_neg(0, -1, 0); | ||
52 | const LLVector3d LLVector3d::z_axis_neg(0, 0, -1); | ||
53 | |||
54 | |||
55 | // Clamps each values to range (min,max). | ||
56 | // Returns TRUE if data changed. | ||
57 | BOOL LLVector3d::clamp(F64 min, F64 max) | ||
58 | { | ||
59 | BOOL ret = FALSE; | ||
60 | |||
61 | if (mdV[0] < min) { mdV[0] = min; ret = TRUE; } | ||
62 | if (mdV[1] < min) { mdV[1] = min; ret = TRUE; } | ||
63 | if (mdV[2] < min) { mdV[2] = min; ret = TRUE; } | ||
64 | |||
65 | if (mdV[0] > max) { mdV[0] = max; ret = TRUE; } | ||
66 | if (mdV[1] > max) { mdV[1] = max; ret = TRUE; } | ||
67 | if (mdV[2] > max) { mdV[2] = max; ret = TRUE; } | ||
68 | |||
69 | return ret; | ||
70 | } | ||
71 | |||
72 | // Sets all values to absolute value of their original values | ||
73 | // Returns TRUE if data changed | ||
74 | BOOL LLVector3d::abs() | ||
75 | { | ||
76 | BOOL ret = FALSE; | ||
77 | |||
78 | if (mdV[0] < 0.0) { mdV[0] = -mdV[0]; ret = TRUE; } | ||
79 | if (mdV[1] < 0.0) { mdV[1] = -mdV[1]; ret = TRUE; } | ||
80 | if (mdV[2] < 0.0) { mdV[2] = -mdV[2]; ret = TRUE; } | ||
81 | |||
82 | return ret; | ||
83 | } | ||
84 | |||
85 | std::ostream& operator<<(std::ostream& s, const LLVector3d &a) | ||
86 | { | ||
87 | s << "{ " << a.mdV[VX] << ", " << a.mdV[VY] << ", " << a.mdV[VZ] << " }"; | ||
88 | return s; | ||
89 | } | ||
90 | |||
91 | const LLVector3d& LLVector3d::operator=(const LLVector4 &a) | ||
92 | { | ||
93 | mdV[0] = a.mV[0]; | ||
94 | mdV[1] = a.mV[1]; | ||
95 | mdV[2] = a.mV[2]; | ||
96 | return *this; | ||
97 | } | ||
98 | |||
99 | const LLVector3d& LLVector3d::rotVec(const LLMatrix3 &mat) | ||
100 | { | ||
101 | *this = *this * mat; | ||
102 | return *this; | ||
103 | } | ||
104 | |||
105 | const LLVector3d& LLVector3d::rotVec(const LLQuaternion &q) | ||
106 | { | ||
107 | *this = *this * q; | ||
108 | return *this; | ||
109 | } | ||
110 | |||
111 | const LLVector3d& LLVector3d::rotVec(F64 angle, const LLVector3d &vec) | ||
112 | { | ||
113 | if ( !vec.isExactlyZero() && angle ) | ||
114 | { | ||
115 | *this = *this * LLMatrix3((F32)angle, vec); | ||
116 | } | ||
117 | return *this; | ||
118 | } | ||
119 | |||
120 | const LLVector3d& LLVector3d::rotVec(F64 angle, F64 x, F64 y, F64 z) | ||
121 | { | ||
122 | LLVector3d vec(x, y, z); | ||
123 | if ( !vec.isExactlyZero() && angle ) | ||
124 | { | ||
125 | *this = *this * LLMatrix3((F32)angle, vec); | ||
126 | } | ||
127 | return *this; | ||
128 | } | ||
129 | |||
130 | |||
131 | BOOL LLVector3d::parseVector3d(const char* buf, LLVector3d* value) | ||
132 | { | ||
133 | if( buf == NULL || buf[0] == '\0' || value == NULL) | ||
134 | { | ||
135 | return FALSE; | ||
136 | } | ||
137 | |||
138 | LLVector3d v; | ||
139 | S32 count = sscanf( buf, "%lf %lf %lf", v.mdV + 0, v.mdV + 1, v.mdV + 2 ); | ||
140 | if( 3 == count ) | ||
141 | { | ||
142 | value->setVec( v ); | ||
143 | return TRUE; | ||
144 | } | ||
145 | |||
146 | return FALSE; | ||
147 | } | ||
148 | |||