SCL  1.0
Standard Control Library : Control, dynamics, physics, and simulation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Macros Groups Pages
TaoDeVector3f.h
1 /* Copyright (c) 2005 Arachi, Inc. and Stanford University. All rights reserved.
2  *
3  * Permission is hereby granted, free of charge, to any person obtaining
4  * a copy of this software and associated documentation files (the
5  * "Software"), to deal in the Software without restriction, including
6  * without limitation the rights to use, copy, modify, merge, publish,
7  * distribute, sublicense, and/or sell copies of the Software, and to
8  * permit persons to whom the Software is furnished to do so, subject
9  * to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included
12  * in all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21  */
22 
23 #ifndef _deVector3f_h
24 #define _deVector3f_h
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 
30 /* inlines */
31 
32 DE_MATH_API void deSetV3S3(deFloat* res, const deFloat x, const deFloat y, const deFloat z)
33 {
34  res[0] = x;
35  res[1] = y;
36  res[2] = z;
37 }
38 
39 DE_MATH_API void deSetV3V3(deFloat* res, const deFloat* v1)
40 {
41  res[0] = v1[0];
42  res[1] = v1[1];
43  res[2] = v1[2];
44 }
45 
46 DE_MATH_API void deNegateV3V3(deFloat* res, const deFloat* v1)
47 {
48  res[0] = -v1[0];
49  res[1] = -v1[1];
50  res[2] = -v1[2];
51 }
52 
53 DE_MATH_API void deAddV3S1(deFloat* res, const deFloat s)
54 {
55  res[0] += s;
56  res[1] += s;
57  res[2] += s;
58 }
59 
60 DE_MATH_API void deMulV3S1(deFloat* res, const deFloat s)
61 {
62  res[0] *= s;
63  res[1] *= s;
64  res[2] *= s;
65 }
66 
67 DE_MATH_API int deIsEqualV3V3(const deFloat* v1, const deFloat* v2)
68 {
69  return (v1[0] == v2[0] && v1[1] == v2[1] && v1[2] == v2[2]);
70 }
71 
72 DE_MATH_API deFloat deDotV3V3(const deFloat* v1, const deFloat* v2)
73 {
74  return (v1[0] * v2[0] + v1[1] * v2[1] + v1[2] * v2[2]);
75 }
76 
77 DE_MATH_API void deZeroV3(deFloat* res)
78 {
79  res[0] = 0;
80  res[1] = 0;
81  res[2] = 0;
82 }
83 
84 DE_MATH_API void deNegV3V3(deFloat* res, const deFloat* v1)
85 {
86  res[0] = -v1[0];
87  res[1] = -v1[1];
88  res[2] = -v1[2];
89 }
90 
91 DE_MATH_API void deAddV3V3(deFloat* res, const deFloat* v1)
92 {
93  res[0] += v1[0];
94  res[1] += v1[1];
95  res[2] += v1[2];
96 }
97 
98 DE_MATH_API void deSubV3V3(deFloat* res, const deFloat* v1)
99 {
100  res[0] -= v1[0];
101  res[1] -= v1[1];
102  res[2] -= v1[2];
103 }
104 
105 DE_MATH_API void deMulV3V3(deFloat* res, const deFloat* v1)
106 {
107  res[0] *= v1[0];
108  res[1] *= v1[1];
109  res[2] *= v1[2];
110 }
111 
112 DE_MATH_API void deAddV3V3S1(deFloat* res, const deFloat* v1, const deFloat s)
113 {
114  res[0] = v1[0] + s;
115  res[1] = v1[1] + s;
116  res[2] = v1[2] + s;
117 }
118 
119 DE_MATH_API void deMulV3V3S1(deFloat* res, const deFloat* v1, const deFloat s)
120 {
121  res[0] = v1[0] * s;
122  res[1] = v1[1] * s;
123  res[2] = v1[2] * s;
124 }
125 
126 
127 DE_MATH_API void deAddV3V3V3(deFloat* res, const deFloat* v1, const deFloat* v2)
128 {
129  res[0] = v1[0] + v2[0];
130  res[1] = v1[1] + v2[1];
131  res[2] = v1[2] + v2[2];
132 }
133 
134 DE_MATH_API void deSubV3V3V3(deFloat* res, const deFloat* v1, const deFloat* v2)
135 {
136  res[0] = v1[0] - v2[0];
137  res[1] = v1[1] - v2[1];
138  res[2] = v1[2] - v2[2];
139 }
140 
141 DE_MATH_API void deMulV3V3V3(deFloat* res, const deFloat* v1, const deFloat* v2)
142 {
143  res[0] = v1[0] * v2[0];
144  res[1] = v1[1] * v2[1];
145  res[2] = v1[2] * v2[2];
146 }
147 
148 DE_MATH_API void deCrossV3V3V3(deFloat* res, const deFloat* v1, const deFloat* v2)
149 {
150  res[0] = v1[1] * v2[2] - v1[2] * v2[1];
151  res[1] = v1[2] * v2[0] - v1[0] * v2[2];
152  res[2] = v1[0] * v2[1] - v1[1] * v2[0];
153 }
154 
155 DE_MATH_API deFloat deMagnitudeV3(const deFloat* v1)
156 {
157  return deSqrt(v1[0] * v1[0] + v1[1] * v1[1] + v1[2] * v1[2]);
158 }
159 
160 DE_MATH_API void deNormalizeV3(deFloat* res)
161 {
162  deFloat mag = 1 / deSqrt(res[0] * res[0] + res[1] * res[1] + res[2] * res[2]);
163  res[0] *= mag;
164  res[1] *= mag;
165  res[2] *= mag;
166 }
167 
168 DE_MATH_API void deMinV3V3(deFloat* res, const deFloat* v1)
169 {
170  if (v1[0] < res[0]) res[0] = v1[0];
171  if (v1[1] < res[1]) res[1] = v1[1];
172  if (v1[2] < res[2]) res[2] = v1[2];
173 }
174 
175 DE_MATH_API void deMaxV3V3(deFloat* res, const deFloat* v1)
176 {
177  if (v1[0] > res[0]) res[0] = v1[0];
178  if (v1[1] > res[1]) res[1] = v1[1];
179  if (v1[2] > res[2]) res[2] = v1[2];
180 }
181 
182 /*
183  * res = v1 + t * (v2 - v1)
184  */
185 DE_MATH_API void deLerpV3V3V3S1(deFloat* res, const deFloat* v1, const deFloat* v2, const deFloat t)
186 {
187  res[0] = v1[0] + t * (v2[0] - v1[0]);
188  res[1] = v1[1] + t * (v2[1] - v1[1]);
189  res[2] = v1[2] + t * (v2[2] - v1[2]);
190 }
191 
192 #ifdef __cplusplus
193 }
194 #endif
195 
196 #endif /* _deVector3f_h */
197