diff options
author | Jacek Antonelli | 2008-09-06 18:24:57 -0500 |
---|---|---|
committer | Jacek Antonelli | 2008-09-06 18:25:07 -0500 |
commit | 798d367d54a6c6379ad355bd8345fa40e31e7fe9 (patch) | |
tree | 1921f1708cd0240648c97bc02df2c2ab5f2fc41e /linden/indra/llmath/llsdutil_math.cpp | |
parent | Second Life viewer sources 1.20.15 (diff) | |
download | meta-impy-798d367d54a6c6379ad355bd8345fa40e31e7fe9.zip meta-impy-798d367d54a6c6379ad355bd8345fa40e31e7fe9.tar.gz meta-impy-798d367d54a6c6379ad355bd8345fa40e31e7fe9.tar.bz2 meta-impy-798d367d54a6c6379ad355bd8345fa40e31e7fe9.tar.xz |
Second Life viewer sources 1.21.0-RC
Diffstat (limited to 'linden/indra/llmath/llsdutil_math.cpp')
-rw-r--r-- | linden/indra/llmath/llsdutil_math.cpp | 172 |
1 files changed, 172 insertions, 0 deletions
diff --git a/linden/indra/llmath/llsdutil_math.cpp b/linden/indra/llmath/llsdutil_math.cpp new file mode 100644 index 0000000..5b72875 --- /dev/null +++ b/linden/indra/llmath/llsdutil_math.cpp | |||
@@ -0,0 +1,172 @@ | |||
1 | /** | ||
2 | * @file llsdutil_math.cpp | ||
3 | * @author Phoenix | ||
4 | * @date 2006-05-24 | ||
5 | * @brief Implementation of classes, functions, etc, for using structured data. | ||
6 | * | ||
7 | * $LicenseInfo:firstyear=2006&license=viewergpl$ | ||
8 | * | ||
9 | * Copyright (c) 2006-2008, Linden Research, Inc. | ||
10 | * | ||
11 | * Second Life Viewer Source Code | ||
12 | * The source code in this file ("Source Code") is provided by Linden Lab | ||
13 | * to you under the terms of the GNU General Public License, version 2.0 | ||
14 | * ("GPL"), unless you have obtained a separate licensing agreement | ||
15 | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
16 | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
17 | * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2 | ||
18 | * | ||
19 | * There are special exceptions to the terms and conditions of the GPL as | ||
20 | * it is applied to this Source Code. View the full text of the exception | ||
21 | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
22 | * online at http://secondlifegrid.net/programs/open_source/licensing/flossexception | ||
23 | * | ||
24 | * By copying, modifying or distributing this software, you acknowledge | ||
25 | * that you have read and understood your obligations described above, | ||
26 | * and agree to abide by those obligations. | ||
27 | * | ||
28 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
29 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
30 | * COMPLETENESS OR PERFORMANCE. | ||
31 | * $/LicenseInfo$ | ||
32 | */ | ||
33 | |||
34 | #include "linden_common.h" | ||
35 | |||
36 | #include "llsdutil.h" | ||
37 | |||
38 | #include "v3math.h" | ||
39 | #include "v4math.h" | ||
40 | #include "v3dmath.h" | ||
41 | #include "v2math.h" | ||
42 | #include "llquaternion.h" | ||
43 | #include "v4color.h" | ||
44 | |||
45 | #if LL_WINDOWS | ||
46 | # define WIN32_LEAN_AND_MEAN | ||
47 | # include <winsock2.h> // for htonl | ||
48 | #elif LL_LINUX || LL_SOLARIS | ||
49 | # include <netinet/in.h> | ||
50 | #elif LL_DARWIN | ||
51 | # include <arpa/inet.h> | ||
52 | #endif | ||
53 | |||
54 | #include "llsdserialize.h" | ||
55 | |||
56 | // vector3 | ||
57 | LLSD ll_sd_from_vector3(const LLVector3& vec) | ||
58 | { | ||
59 | LLSD rv; | ||
60 | rv.append((F64)vec.mV[VX]); | ||
61 | rv.append((F64)vec.mV[VY]); | ||
62 | rv.append((F64)vec.mV[VZ]); | ||
63 | return rv; | ||
64 | } | ||
65 | |||
66 | LLVector3 ll_vector3_from_sd(const LLSD& sd, S32 start_index) | ||
67 | { | ||
68 | LLVector3 rv; | ||
69 | rv.mV[VX] = (F32)sd[start_index].asReal(); | ||
70 | rv.mV[VY] = (F32)sd[++start_index].asReal(); | ||
71 | rv.mV[VZ] = (F32)sd[++start_index].asReal(); | ||
72 | return rv; | ||
73 | } | ||
74 | |||
75 | // vector4 | ||
76 | LLSD ll_sd_from_vector4(const LLVector4& vec) | ||
77 | { | ||
78 | LLSD rv; | ||
79 | rv.append((F64)vec.mV[VX]); | ||
80 | rv.append((F64)vec.mV[VY]); | ||
81 | rv.append((F64)vec.mV[VZ]); | ||
82 | rv.append((F64)vec.mV[VW]); | ||
83 | return rv; | ||
84 | } | ||
85 | |||
86 | LLVector4 ll_vector4_from_sd(const LLSD& sd, S32 start_index) | ||
87 | { | ||
88 | LLVector4 rv; | ||
89 | rv.mV[VX] = (F32)sd[start_index].asReal(); | ||
90 | rv.mV[VY] = (F32)sd[++start_index].asReal(); | ||
91 | rv.mV[VZ] = (F32)sd[++start_index].asReal(); | ||
92 | rv.mV[VW] = (F32)sd[++start_index].asReal(); | ||
93 | return rv; | ||
94 | } | ||
95 | |||
96 | // vector3d | ||
97 | LLSD ll_sd_from_vector3d(const LLVector3d& vec) | ||
98 | { | ||
99 | LLSD rv; | ||
100 | rv.append(vec.mdV[VX]); | ||
101 | rv.append(vec.mdV[VY]); | ||
102 | rv.append(vec.mdV[VZ]); | ||
103 | return rv; | ||
104 | } | ||
105 | |||
106 | LLVector3d ll_vector3d_from_sd(const LLSD& sd, S32 start_index) | ||
107 | { | ||
108 | LLVector3d rv; | ||
109 | rv.mdV[VX] = sd[start_index].asReal(); | ||
110 | rv.mdV[VY] = sd[++start_index].asReal(); | ||
111 | rv.mdV[VZ] = sd[++start_index].asReal(); | ||
112 | return rv; | ||
113 | } | ||
114 | |||
115 | //vector2 | ||
116 | LLSD ll_sd_from_vector2(const LLVector2& vec) | ||
117 | { | ||
118 | LLSD rv; | ||
119 | rv.append((F64)vec.mV[VX]); | ||
120 | rv.append((F64)vec.mV[VY]); | ||
121 | return rv; | ||
122 | } | ||
123 | |||
124 | LLVector2 ll_vector2_from_sd(const LLSD& sd) | ||
125 | { | ||
126 | LLVector2 rv; | ||
127 | rv.mV[VX] = (F32)sd[0].asReal(); | ||
128 | rv.mV[VY] = (F32)sd[1].asReal(); | ||
129 | return rv; | ||
130 | } | ||
131 | |||
132 | // Quaternion | ||
133 | LLSD ll_sd_from_quaternion(const LLQuaternion& quat) | ||
134 | { | ||
135 | LLSD rv; | ||
136 | rv.append((F64)quat.mQ[VX]); | ||
137 | rv.append((F64)quat.mQ[VY]); | ||
138 | rv.append((F64)quat.mQ[VZ]); | ||
139 | rv.append((F64)quat.mQ[VW]); | ||
140 | return rv; | ||
141 | } | ||
142 | |||
143 | LLQuaternion ll_quaternion_from_sd(const LLSD& sd) | ||
144 | { | ||
145 | LLQuaternion quat; | ||
146 | quat.mQ[VX] = (F32)sd[0].asReal(); | ||
147 | quat.mQ[VY] = (F32)sd[1].asReal(); | ||
148 | quat.mQ[VZ] = (F32)sd[2].asReal(); | ||
149 | quat.mQ[VW] = (F32)sd[3].asReal(); | ||
150 | return quat; | ||
151 | } | ||
152 | |||
153 | // color4 | ||
154 | LLSD ll_sd_from_color4(const LLColor4& c) | ||
155 | { | ||
156 | LLSD rv; | ||
157 | rv.append(c.mV[0]); | ||
158 | rv.append(c.mV[1]); | ||
159 | rv.append(c.mV[2]); | ||
160 | rv.append(c.mV[3]); | ||
161 | return rv; | ||
162 | } | ||
163 | |||
164 | LLColor4 ll_color4_from_sd(const LLSD& sd) | ||
165 | { | ||
166 | LLColor4 c; | ||
167 | c.mV[0] = (F32)sd[0].asReal(); | ||
168 | c.mV[1] = (F32)sd[1].asReal(); | ||
169 | c.mV[2] = (F32)sd[2].asReal(); | ||
170 | c.mV[3] = (F32)sd[3].asReal(); | ||
171 | return c; | ||
172 | } | ||