1 /* 2 Copyright (c) 2008-2009 NetAllied Systems GmbH 3 4 This file is part of COLLADAMaya. 5 6 Portions of the code are: 7 Copyright (c) 2005-2007 Feeling Software Inc. 8 Copyright (c) 2005-2007 Sony Computer Entertainment America 9 Copyright (c) 2004-2005 Alias Systems Corp. 10 11 Licensed under the MIT Open Source License, 12 for details please see LICENSE file or the website 13 http://www.opensource.org/licenses/mit-license.php 14 */ 15 #ifndef __COLLADA_MAYA_TANGENT_POINT_H__ 16 #define __COLLADA_MAYA_TANGENT_POINT_H__ 17 18 #include "COLLADAMayaPrerequisites.h" 19 #include "COLLADASWLibraryAnimations.h" 20 #include "COLLADASWLibraryAnimationClips.h" 21 #include <maya/MFnAnimCurve.h> 22 23 namespace COLLADAMaya 24 { 25 26 /** 27 * The x and y coordinate of a point of a tangent. 28 */ 29 30 class TangentPoint 31 { 32 33 public: 34 union 35 { 36 float x; 37 float u; 38 }; 39 union 40 { 41 float y; 42 float v; 43 }; 44 45 public: 46 47 /** Default constructor */ TangentPoint()48 TangentPoint() : x(0), y(0) {} 49 50 /** Creates the std::vector with the coordinates given. 51 @param _u The first coordinate. 52 @param _v The second coordinate. */ TangentPoint(float _u,float _v)53 TangentPoint ( float _u, float _v ) : x(0), y(0) 54 { 55 u = _u; 56 v = _v; 57 } 58 59 /** Get this std::vector as an array of \c floats. 60 @return The \c float array. */ 61 inline operator float*() 62 { 63 return &u; 64 } 65 66 /** Adds two std::vector. 67 Adds to this std::vector's coordinates the individual components of the 68 given std::vector and returns this std::vector. 69 @param a The std::vector to add with this one. 70 @return This std::vector. */ 71 inline TangentPoint operator + ( TangentPoint& a ) 72 { 73 TangentPoint copy = *this; 74 copy += a; 75 return copy; 76 } 77 78 /** Adds two std::vector. 79 Adds to this std::vector's coordinates the individual components of the 80 given std::vector and returns this std::vector. 81 @param a The std::vector to add with this one. 82 @return This std::vector. */ 83 inline TangentPoint& operator += ( const TangentPoint& a ) 84 { 85 u += a.u; 86 v += a.v; 87 return *this; 88 } 89 90 inline TangentPoint operator - ( TangentPoint& a ) 91 { 92 TangentPoint copy = *this; 93 copy -= a; 94 return copy; 95 } 96 97 inline TangentPoint& operator -= ( const TangentPoint& a ) 98 { 99 u -= a.u; 100 v -= a.v; 101 return *this; 102 } 103 104 /** Multiplies this std::vector by a scaler. 105 Multiplies each of this std::vector's coordinates with the scaler and 106 returns this std::vector. 107 @param a The scalar to multiply with. 108 @return This std::vector. */ 109 inline TangentPoint& operator *= ( float a ) 110 { 111 u *= a; 112 v *= a; 113 return *this; 114 } 115 116 /** Assign this std::vector to the given float array. 117 Assigns each coordinate of this std::vector to the elements in the \c 118 float array. The first element to the first coordinate and the second to 119 the second. It returns this std::vector. 120 @param f The \c float array to assign with. 121 @return This std::vector. */ 122 inline TangentPoint& operator = ( const float* f ) 123 { 124 u = *f; 125 v = * ( f + 1 ); 126 return *this; 127 } 128 }; 129 130 /** Vector addition with two vectors. 131 @param a The first std::vector. 132 @param b The second std::vector. 133 @return The FMVector2 representation of the resulting std::vector. */ 134 inline TangentPoint operator + ( const TangentPoint& a, const TangentPoint& b ) 135 { 136 return TangentPoint ( a.u + b.u, a.v + b.v ); 137 } 138 139 /** Vector subtraction with two vectors. 140 @param a The first std::vector. 141 @param b The second std::vector. 142 @return The FMVector2 representation of the resulting std::vector. */ 143 inline TangentPoint operator - ( const TangentPoint& a, const TangentPoint& b ) 144 { 145 return TangentPoint ( a.u - b.u, a.v - b.v ); 146 } 147 148 /** Dot product of two vectors. 149 @param a The first std::vector. 150 @param b The second std::vector. 151 @return The result of the dot product. 152 */ 153 inline float operator * ( const TangentPoint& a, const TangentPoint& b ) 154 { 155 return a.u * b.u + a.v * b.v; 156 } 157 158 /** Scalar multiplication with a std::vector. 159 @param a The std::vector. 160 @param b The scalar. 161 @return The FMVector2 representing the resulting the std::vector. */ 162 inline TangentPoint operator * ( const TangentPoint& a, float b ) 163 { 164 return TangentPoint ( a.u * b, a.v * b ); 165 } 166 167 /** Scalar multiplication with a std::vector. 168 @param a The scalar. 169 @param b The std::vector. 170 @return The std::vector representing the resulting the std::vector. */ 171 inline TangentPoint operator * ( float a, const TangentPoint& b ) 172 { 173 return TangentPoint ( a * b.u, a * b.v ); 174 } 175 176 /** Scalar division with a std::vector. 177 @param a The std::vector. 178 @param b The scalar. 179 @return The std::vector representing the resulting the std::vector. */ 180 inline TangentPoint operator / ( const TangentPoint& a, float b ) 181 { 182 return TangentPoint ( a.x / b, a.y / b ); 183 } 184 185 } 186 187 #endif // __COLLADA_MAYA_TANGENT_POINT_H__ 188