deVector3f.h

Go to the documentation of this file.
00001 /* Copyright (c) 2005 Arachi, Inc. and Stanford University.
00002  *
00003  * Permission is hereby granted, free of charge, to any person obtaining
00004  * a copy of this software and associated documentation files (the
00005  * "Software"), to deal in the Software without restriction, including
00006  * without limitation the rights to use, copy, modify, merge, publish,
00007  * distribute, sublicense, and/or sell copies of the Software, and to
00008  * permit persons to whom the Software is furnished to do so, subject
00009  * to the following conditions:
00010  *
00011  * The above copyright notice and this permission notice shall be included
00012  * in all copies or substantial portions of the Software.
00013  *
00014  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00015  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00016  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
00017  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
00018  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
00019  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
00020  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00021  */
00022 
00023 #ifndef _deVector3f_h
00024 #define _deVector3f_h
00025 
00026 #ifdef __cplusplus
00027 extern "C" {
00028 #endif
00029 
00030 /* inlines */
00031 
00032 DE_MATH_API void deSetV3S3(deFloat* res, const deFloat x, const deFloat y, const deFloat z)
00033 {
00034         res[0] = x;
00035         res[1] = y;
00036         res[2] = z;
00037 }
00038 
00039 DE_MATH_API void deSetV3V3(deFloat* res, const deFloat* v1)
00040 {
00041         res[0] = v1[0];
00042         res[1] = v1[1];
00043         res[2] = v1[2];
00044 }
00045 
00046 DE_MATH_API void deNegateV3V3(deFloat* res, const deFloat* v1)
00047 {
00048         res[0] = -v1[0];
00049         res[1] = -v1[1];
00050         res[2] = -v1[2];
00051 }
00052 
00053 DE_MATH_API void deAddV3S1(deFloat* res, const deFloat s)
00054 {
00055         res[0] += s;
00056         res[1] += s;
00057         res[2] += s;
00058 }
00059 
00060 DE_MATH_API void deMulV3S1(deFloat* res, const deFloat s)
00061 {
00062         res[0] *= s;
00063         res[1] *= s;
00064         res[2] *= s;
00065 }
00066 
00067 DE_MATH_API int deIsEqualV3V3(const deFloat* v1, const deFloat* v2)
00068 {
00069         return (v1[0] == v2[0] && v1[1] == v2[1] && v1[2] == v2[2]);
00070 }
00071 
00072 DE_MATH_API deFloat deDotV3V3(const deFloat* v1, const deFloat* v2)
00073 {
00074         return (v1[0] * v2[0] + v1[1] * v2[1] + v1[2] * v2[2]);
00075 }
00076 
00077 DE_MATH_API void deZeroV3(deFloat* res)
00078 {
00079         res[0] = 0;
00080         res[1] = 0;
00081         res[2] = 0;
00082 }
00083 
00084 DE_MATH_API void deNegV3V3(deFloat* res, const deFloat* v1)
00085 {
00086         res[0] = -v1[0];
00087         res[1] = -v1[1];
00088         res[2] = -v1[2];
00089 }
00090 
00091 DE_MATH_API void deAddV3V3(deFloat* res, const deFloat* v1)
00092 {
00093         res[0] += v1[0];
00094         res[1] += v1[1];
00095         res[2] += v1[2];
00096 }
00097 
00098 DE_MATH_API void deSubV3V3(deFloat* res, const deFloat* v1)
00099 {
00100         res[0] -= v1[0];
00101         res[1] -= v1[1];
00102         res[2] -= v1[2];
00103 }
00104 
00105 DE_MATH_API void deMulV3V3(deFloat* res, const deFloat* v1)
00106 {
00107         res[0] *= v1[0];
00108         res[1] *= v1[1];
00109         res[2] *= v1[2];
00110 }
00111 
00112 DE_MATH_API void deAddV3V3S1(deFloat* res, const deFloat* v1, const deFloat s)
00113 {
00114         res[0] = v1[0] + s;
00115         res[1] = v1[1] + s;
00116         res[2] = v1[2] + s;
00117 }
00118 
00119 DE_MATH_API void deMulV3V3S1(deFloat* res, const deFloat* v1, const deFloat s)
00120 {
00121         res[0] = v1[0] * s;
00122         res[1] = v1[1] * s;
00123         res[2] = v1[2] * s;
00124 }
00125 
00126 
00127 DE_MATH_API void deAddV3V3V3(deFloat* res, const deFloat* v1, const deFloat* v2)
00128 {
00129         res[0] = v1[0] + v2[0];
00130         res[1] = v1[1] + v2[1];
00131         res[2] = v1[2] + v2[2];
00132 }
00133 
00134 DE_MATH_API void deSubV3V3V3(deFloat* res, const deFloat* v1, const deFloat* v2)
00135 {
00136     res[0] = v1[0] - v2[0];
00137     res[1] = v1[1] - v2[1];
00138     res[2] = v1[2] - v2[2];
00139 }
00140 
00141 DE_MATH_API void deMulV3V3V3(deFloat* res, const deFloat* v1, const deFloat* v2)
00142 {
00143         res[0] = v1[0] * v2[0];
00144         res[1] = v1[1] * v2[1];
00145         res[2] = v1[2] * v2[2];
00146 }
00147 
00148 DE_MATH_API void deCrossV3V3V3(deFloat* res, const deFloat* v1, const deFloat* v2)
00149 {
00150         res[0] = v1[1] * v2[2] - v1[2] * v2[1];
00151         res[1] = v1[2] * v2[0] - v1[0] * v2[2];
00152         res[2] = v1[0] * v2[1] - v1[1] * v2[0];
00153 }
00154 
00155 DE_MATH_API deFloat deMagnitudeV3(const deFloat* v1)
00156 {
00157         return deSqrt(v1[0] * v1[0] + v1[1] * v1[1] + v1[2] * v1[2]);
00158 }
00159 
00160 DE_MATH_API void deNormalizeV3(deFloat* res)
00161 {
00162         deFloat mag = 1 / deSqrt(res[0] * res[0] + res[1] * res[1] + res[2] * res[2]);
00163         res[0] *= mag;
00164         res[1] *= mag;
00165         res[2] *= mag;
00166 }
00167 
00168 DE_MATH_API void deMinV3V3(deFloat* res, const deFloat* v1)
00169 {
00170         if (v1[0] < res[0]) res[0] = v1[0];
00171         if (v1[1] < res[1]) res[1] = v1[1];
00172         if (v1[2] < res[2]) res[2] = v1[2];
00173 }
00174 
00175 DE_MATH_API void deMaxV3V3(deFloat* res, const deFloat* v1)
00176 {
00177         if (v1[0] > res[0]) res[0] = v1[0];
00178         if (v1[1] > res[1]) res[1] = v1[1];
00179         if (v1[2] > res[2]) res[2] = v1[2];
00180 }
00181 
00182 /* 
00183  * res = v1 + t * (v2 - v1)
00184  */
00185 DE_MATH_API void deLerpV3V3V3S1(deFloat* res, const deFloat* v1, const deFloat* v2, const deFloat t)
00186 {
00187   res[0] = v1[0] + t * (v2[0] - v1[0]);
00188   res[1] = v1[1] + t * (v2[1] - v1[1]);
00189   res[2] = v1[2] + t * (v2[2] - v1[2]);
00190 }
00191 
00192 #ifdef __cplusplus
00193 }
00194 #endif
00195 
00196 #endif /* _deVector3f_h */
00197 

Generated on Sun Apr 9 22:12:43 2006 for TAO by  doxygen 1.4.6-NO