vrshoot

view libs/assimp/assimp/vector3.inl @ 0:b2f14e535253

initial commit
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 01 Feb 2014 19:58:19 +0200
parents
children
line source
1 /*
2 ---------------------------------------------------------------------------
3 Open Asset Import Library (assimp)
4 ---------------------------------------------------------------------------
6 Copyright (c) 2006-2012, assimp team
8 All rights reserved.
10 Redistribution and use of this software in source and binary forms,
11 with or without modification, are permitted provided that the following
12 conditions are met:
14 * Redistributions of source code must retain the above
15 copyright notice, this list of conditions and the
16 following disclaimer.
18 * Redistributions in binary form must reproduce the above
19 copyright notice, this list of conditions and the
20 following disclaimer in the documentation and/or other
21 materials provided with the distribution.
23 * Neither the name of the assimp team, nor the names of its
24 contributors may be used to endorse or promote products
25 derived from this software without specific prior
26 written permission of the assimp team.
28 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 ---------------------------------------------------------------------------
40 */
42 /** @file aiVector3D.inl
43 * @brief Inline implementation of aiVector3t<TReal> operators
44 */
45 #ifndef AI_VECTOR3D_INL_INC
46 #define AI_VECTOR3D_INL_INC
48 #ifdef __cplusplus
49 #include "vector3.h"
51 // ------------------------------------------------------------------------------------------------
52 /** Transformation of a vector by a 3x3 matrix */
53 template <typename TReal>
54 inline aiVector3t<TReal> operator * (const aiMatrix3x3t<TReal>& pMatrix, const aiVector3t<TReal>& pVector)
55 {
56 aiVector3t<TReal> res;
57 res.x = pMatrix.a1 * pVector.x + pMatrix.a2 * pVector.y + pMatrix.a3 * pVector.z;
58 res.y = pMatrix.b1 * pVector.x + pMatrix.b2 * pVector.y + pMatrix.b3 * pVector.z;
59 res.z = pMatrix.c1 * pVector.x + pMatrix.c2 * pVector.y + pMatrix.c3 * pVector.z;
60 return res;
61 }
63 // ------------------------------------------------------------------------------------------------
64 /** Transformation of a vector by a 4x4 matrix */
65 template <typename TReal>
66 inline aiVector3t<TReal> operator * (const aiMatrix4x4t<TReal>& pMatrix, const aiVector3t<TReal>& pVector)
67 {
68 aiVector3t<TReal> res;
69 res.x = pMatrix.a1 * pVector.x + pMatrix.a2 * pVector.y + pMatrix.a3 * pVector.z + pMatrix.a4;
70 res.y = pMatrix.b1 * pVector.x + pMatrix.b2 * pVector.y + pMatrix.b3 * pVector.z + pMatrix.b4;
71 res.z = pMatrix.c1 * pVector.x + pMatrix.c2 * pVector.y + pMatrix.c3 * pVector.z + pMatrix.c4;
72 return res;
73 }
74 // ------------------------------------------------------------------------------------------------
75 template <typename TReal>
76 template <typename TOther>
77 aiVector3t<TReal>::operator aiVector3t<TOther> () const {
78 return aiVector3t<TOther>(static_cast<TOther>(x),static_cast<TOther>(y),static_cast<TOther>(z));
79 }
80 // ------------------------------------------------------------------------------------------------
81 template <typename TReal>
82 AI_FORCE_INLINE void aiVector3t<TReal>::Set( TReal pX, TReal pY, TReal pZ) {
83 x = pX; y = pY; z = pZ;
84 }
85 // ------------------------------------------------------------------------------------------------
86 template <typename TReal>
87 AI_FORCE_INLINE TReal aiVector3t<TReal>::SquareLength() const {
88 return x*x + y*y + z*z;
89 }
90 // ------------------------------------------------------------------------------------------------
91 template <typename TReal>
92 AI_FORCE_INLINE TReal aiVector3t<TReal>::Length() const {
93 return sqrt( SquareLength());
94 }
95 // ------------------------------------------------------------------------------------------------
96 template <typename TReal>
97 AI_FORCE_INLINE aiVector3t<TReal>& aiVector3t<TReal>::Normalize() {
98 *this /= Length(); return *this;
99 }
100 // ------------------------------------------------------------------------------------------------
101 template <typename TReal>
102 AI_FORCE_INLINE const aiVector3t<TReal>& aiVector3t<TReal>::operator += (const aiVector3t<TReal>& o) {
103 x += o.x; y += o.y; z += o.z; return *this;
104 }
105 // ------------------------------------------------------------------------------------------------
106 template <typename TReal>
107 AI_FORCE_INLINE const aiVector3t<TReal>& aiVector3t<TReal>::operator -= (const aiVector3t<TReal>& o) {
108 x -= o.x; y -= o.y; z -= o.z; return *this;
109 }
110 // ------------------------------------------------------------------------------------------------
111 template <typename TReal>
112 AI_FORCE_INLINE const aiVector3t<TReal>& aiVector3t<TReal>::operator *= (TReal f) {
113 x *= f; y *= f; z *= f; return *this;
114 }
115 // ------------------------------------------------------------------------------------------------
116 template <typename TReal>
117 AI_FORCE_INLINE const aiVector3t<TReal>& aiVector3t<TReal>::operator /= (TReal f) {
118 x /= f; y /= f; z /= f; return *this;
119 }
120 // ------------------------------------------------------------------------------------------------
121 template <typename TReal>
122 AI_FORCE_INLINE aiVector3t<TReal>& aiVector3t<TReal>::operator *= (const aiMatrix3x3t<TReal>& mat){
123 return(*this = mat * (*this));
124 }
125 // ------------------------------------------------------------------------------------------------
126 template <typename TReal>
127 AI_FORCE_INLINE aiVector3t<TReal>& aiVector3t<TReal>::operator *= (const aiMatrix4x4t<TReal>& mat){
128 return(*this = mat * (*this));
129 }
130 // ------------------------------------------------------------------------------------------------
131 template <typename TReal>
132 AI_FORCE_INLINE TReal aiVector3t<TReal>::operator[](unsigned int i) const {
133 return *(&x + i);
134 }
135 // ------------------------------------------------------------------------------------------------
136 template <typename TReal>
137 AI_FORCE_INLINE TReal& aiVector3t<TReal>::operator[](unsigned int i) {
138 return *(&x + i);
139 }
140 // ------------------------------------------------------------------------------------------------
141 template <typename TReal>
142 AI_FORCE_INLINE bool aiVector3t<TReal>::operator== (const aiVector3t<TReal>& other) const {
143 return x == other.x && y == other.y && z == other.z;
144 }
145 // ------------------------------------------------------------------------------------------------
146 template <typename TReal>
147 AI_FORCE_INLINE bool aiVector3t<TReal>::operator!= (const aiVector3t<TReal>& other) const {
148 return x != other.x || y != other.y || z != other.z;
149 }
150 // ------------------------------------------------------------------------------------------------
151 template <typename TReal>
152 AI_FORCE_INLINE const aiVector3t<TReal> aiVector3t<TReal>::SymMul(const aiVector3t<TReal>& o) {
153 return aiVector3t<TReal>(x*o.x,y*o.y,z*o.z);
154 }
155 // ------------------------------------------------------------------------------------------------
156 // symmetric addition
157 template <typename TReal>
158 AI_FORCE_INLINE aiVector3t<TReal> operator + (const aiVector3t<TReal>& v1, const aiVector3t<TReal>& v2) {
159 return aiVector3t<TReal>( v1.x + v2.x, v1.y + v2.y, v1.z + v2.z);
160 }
161 // ------------------------------------------------------------------------------------------------
162 // symmetric subtraction
163 template <typename TReal>
164 AI_FORCE_INLINE aiVector3t<TReal> operator - (const aiVector3t<TReal>& v1, const aiVector3t<TReal>& v2) {
165 return aiVector3t<TReal>( v1.x - v2.x, v1.y - v2.y, v1.z - v2.z);
166 }
167 // ------------------------------------------------------------------------------------------------
168 // scalar product
169 template <typename TReal>
170 AI_FORCE_INLINE TReal operator * (const aiVector3t<TReal>& v1, const aiVector3t<TReal>& v2) {
171 return v1.x*v2.x + v1.y*v2.y + v1.z*v2.z;
172 }
173 // ------------------------------------------------------------------------------------------------
174 // scalar multiplication
175 template <typename TReal>
176 AI_FORCE_INLINE aiVector3t<TReal> operator * ( TReal f, const aiVector3t<TReal>& v) {
177 return aiVector3t<TReal>( f*v.x, f*v.y, f*v.z);
178 }
179 // ------------------------------------------------------------------------------------------------
180 // and the other way around
181 template <typename TReal>
182 AI_FORCE_INLINE aiVector3t<TReal> operator * ( const aiVector3t<TReal>& v, TReal f) {
183 return aiVector3t<TReal>( f*v.x, f*v.y, f*v.z);
184 }
185 // ------------------------------------------------------------------------------------------------
186 // scalar division
187 template <typename TReal>
188 AI_FORCE_INLINE aiVector3t<TReal> operator / ( const aiVector3t<TReal>& v, TReal f) {
189 return v * (1/f);
190 }
191 // ------------------------------------------------------------------------------------------------
192 // vector division
193 template <typename TReal>
194 AI_FORCE_INLINE aiVector3t<TReal> operator / ( const aiVector3t<TReal>& v, const aiVector3t<TReal>& v2) {
195 return aiVector3t<TReal>(v.x / v2.x,v.y / v2.y,v.z / v2.z);
196 }
197 // ------------------------------------------------------------------------------------------------
198 // cross product
199 template <typename TReal>
200 AI_FORCE_INLINE aiVector3t<TReal> operator ^ ( const aiVector3t<TReal>& v1, const aiVector3t<TReal>& v2) {
201 return aiVector3t<TReal>( v1.y*v2.z - v1.z*v2.y, v1.z*v2.x - v1.x*v2.z, v1.x*v2.y - v1.y*v2.x);
202 }
203 // ------------------------------------------------------------------------------------------------
204 // vector negation
205 template <typename TReal>
206 AI_FORCE_INLINE aiVector3t<TReal> operator - ( const aiVector3t<TReal>& v) {
207 return aiVector3t<TReal>( -v.x, -v.y, -v.z);
208 }
211 #endif // __cplusplus
212 #endif // AI_VECTOR3D_INL_INC