| 1 | /**************************************************************************************** |
| 2 | |
| 3 | Copyright (C) 2015 Autodesk, Inc. |
| 4 | All rights reserved. |
| 5 | |
| 6 | Use of this software is subject to the terms of the Autodesk license agreement |
| 7 | provided at the time of installation or download, or which otherwise accompanies |
| 8 | this software in either electronic or hard copy form. |
| 9 | |
| 10 | ****************************************************************************************/ |
| 11 | |
| 12 | //! \file fbxvector4.h |
| 13 | #ifndef _FBXSDK_CORE_MATH_VECTOR_4_H_ |
| 14 | #define _FBXSDK_CORE_MATH_VECTOR_4_H_ |
| 15 | |
| 16 | #include <fbxsdk/fbxsdk_def.h> |
| 17 | |
| 18 | #include <fbxsdk/fbxsdk_nsbegin.h> |
| 19 | |
| 20 | class FbxQuaternion; |
| 21 | |
| 22 | /** A four double mathematic vector class. |
| 23 | * \nosubgrouping |
| 24 | */ |
| 25 | class FBXSDK_DLL FbxVector4 : public FbxDouble4 |
| 26 | { |
| 27 | public: |
| 28 | /** |
| 29 | * \name Constructors and Destructor |
| 30 | */ |
| 31 | //@{ |
| 32 | //! Constructor. |
| 33 | FbxVector4(); |
| 34 | |
| 35 | /** Copy constructor. |
| 36 | * \param pVector4 The vector copied to this one. |
| 37 | */ |
| 38 | FbxVector4(const FbxVector4& pVector4); |
| 39 | |
| 40 | /** Constructor. |
| 41 | * \param pX X component. |
| 42 | * \param pY Y component. |
| 43 | * \param pZ Z component. |
| 44 | * \param pW W component. |
| 45 | */ |
| 46 | FbxVector4(double pX, double pY, double pZ, double pW=1.0); |
| 47 | |
| 48 | /** Constructor. |
| 49 | * \param pValue X,Y,Z,W components. |
| 50 | */ |
| 51 | FbxVector4(const double pValue[4]); |
| 52 | |
| 53 | /** Constructor. |
| 54 | * \param pValue X,Y,Z components. |
| 55 | * \remarks The fourth component of this object is assigned 1. |
| 56 | */ |
| 57 | FbxVector4(const FbxDouble3& pValue); |
| 58 | //@} |
| 59 | |
| 60 | /** |
| 61 | * \name Access |
| 62 | */ |
| 63 | //@{ |
| 64 | /** Assignment operation. |
| 65 | * \param pVector4 The vector assigned to this one. |
| 66 | * \return This vector after assignment. |
| 67 | */ |
| 68 | FbxVector4& operator=(const FbxVector4& pVector4); |
| 69 | |
| 70 | /** Assignment operation. |
| 71 | * \param pValue The pointer to an array whose elements are assigned to this vector. |
| 72 | * \return This vector after assignment. |
| 73 | */ |
| 74 | FbxVector4& operator=(const double* pValue); |
| 75 | |
| 76 | /** Assignment operation. |
| 77 | * \param pValue The vector with 3 elements assigned to this vector. |
| 78 | * \return This vector after assignment. |
| 79 | * \remarks The first three elements are assigned with pValue. The fourth element is set as 1.0 |
| 80 | */ |
| 81 | FbxVector4& operator=(const FbxDouble3& pValue); |
| 82 | |
| 83 | /** Set vector. |
| 84 | * \param pX The X component value. |
| 85 | * \param pY The Y component value. |
| 86 | * \param pZ The Z component value. |
| 87 | * \param pW The W component value. |
| 88 | */ |
| 89 | void Set(double pX, double pY, double pZ, double pW=1.0); |
| 90 | //@} |
| 91 | |
| 92 | /** |
| 93 | * \name Scalar Operations |
| 94 | */ |
| 95 | //@{ |
| 96 | /** Add a value to all vector components. |
| 97 | * \param pValue The value to add to each component of the vector. |
| 98 | * \return New vector. |
| 99 | * \remarks The passed value is not checked. |
| 100 | */ |
| 101 | FbxVector4 operator+(double pValue) const; |
| 102 | |
| 103 | /** Subtract a value from all vector components. |
| 104 | * \param pValue The value to subtract from each component of the vector. |
| 105 | * \return New vector. |
| 106 | * \remarks The passed value is not checked. |
| 107 | */ |
| 108 | FbxVector4 operator-(double pValue) const; |
| 109 | |
| 110 | /** Multiply a value to all vector components. |
| 111 | * \param pValue The value multiplying each component of the vector. |
| 112 | * \return New vector. |
| 113 | * \remarks The passed value is not checked. |
| 114 | */ |
| 115 | FbxVector4 operator*(double pValue) const; |
| 116 | |
| 117 | /** Divide all vector components by a value. |
| 118 | * \param pValue The value dividing each component of the vector. |
| 119 | * \return New vector. |
| 120 | * \remarks The passed value is not checked. |
| 121 | */ |
| 122 | FbxVector4 operator/(double pValue) const; |
| 123 | |
| 124 | /** Add a value to all vector components. |
| 125 | * \param pValue The value to add to each component of the vector. |
| 126 | * \return \e this updated with the operation result. |
| 127 | * \remarks The passed value is not checked. |
| 128 | */ |
| 129 | FbxVector4& operator+=(double pValue); |
| 130 | |
| 131 | /** Subtract a value from all vector components. |
| 132 | * \param pValue The value to subtract from each component of the vector. |
| 133 | * \return \e this updated with the operation result. |
| 134 | * \remarks The passed value is not checked. |
| 135 | */ |
| 136 | FbxVector4& operator-=(double pValue); |
| 137 | |
| 138 | /** Multiply a value to all vector elements. |
| 139 | * \param pValue The value multiplying each component of the vector. |
| 140 | * \return \e this updated with the operation result. |
| 141 | * \remarks The passed value is not checked. |
| 142 | */ |
| 143 | FbxVector4& operator*=(double pValue); |
| 144 | |
| 145 | /** Divide all vector elements by a value. |
| 146 | * \param pValue The value dividing each component of the vector. |
| 147 | * \return \e this updated with the operation result. |
| 148 | * \remarks The passed value is not checked. |
| 149 | */ |
| 150 | FbxVector4& operator/=(double pValue); |
| 151 | //@} |
| 152 | |
| 153 | /** |
| 154 | * \name Vector Operations |
| 155 | */ |
| 156 | //@{ |
| 157 | /** Unary minus operator. |
| 158 | * \return The vector that is the negation of \c this. |
| 159 | */ |
| 160 | FbxVector4 operator-() const; |
| 161 | |
| 162 | /** Add two vectors together. |
| 163 | * \param pVector Vector to add. |
| 164 | * \return The vector v' = this + pVector. |
| 165 | * \remarks The values in pVector are not checked. |
| 166 | */ |
| 167 | FbxVector4 operator+(const FbxVector4& pVector) const; |
| 168 | |
| 169 | /** Subtract a vector from another vector. |
| 170 | * \param pVector Vector to subtract. |
| 171 | * \return The vector v' = this - pVector. |
| 172 | * \remarks The values in pVector are not checked. |
| 173 | */ |
| 174 | FbxVector4 operator-(const FbxVector4& pVector) const; |
| 175 | |
| 176 | /** Memberwise multiplication of two vectors. |
| 177 | * \param pVector Multiplying vector. |
| 178 | * \return The vector v' = this * pVector. |
| 179 | * \remarks The values in pVector are not checked. |
| 180 | */ |
| 181 | FbxVector4 operator*(const FbxVector4& pVector) const; |
| 182 | |
| 183 | /** Memberwise division of a vector with another vector. |
| 184 | * \param pVector Dividing vector. |
| 185 | * \return The vector v[i]' = this[i] / pVector[i]. |
| 186 | * \remarks The values in pVector are not checked. |
| 187 | */ |
| 188 | FbxVector4 operator/(const FbxVector4& pVector) const; |
| 189 | |
| 190 | /** Add two vectors together. |
| 191 | * \param pVector Vector to add. |
| 192 | * \return \e this updated with the operation result. |
| 193 | * \remarks The values in pVector are not checked. |
| 194 | */ |
| 195 | FbxVector4& operator+=(const FbxVector4& pVector); |
| 196 | |
| 197 | /** Subtract a vector from another vector. |
| 198 | * \param pVector Vector to subtract. |
| 199 | * \return \e this updated with the operation result. |
| 200 | * \remarks The values in pVector are not checked. |
| 201 | */ |
| 202 | FbxVector4& operator-=(const FbxVector4& pVector); |
| 203 | |
| 204 | /** Memberwise multiplication of two vectors. |
| 205 | * \param pVector Multiplying vector. |
| 206 | * \return \e this updated with the operation result. |
| 207 | * \remarks The values in pVector are not checked. |
| 208 | */ |
| 209 | FbxVector4& operator*=(const FbxVector4& pVector); |
| 210 | |
| 211 | /** Memberwise division of a vector with another vector. |
| 212 | * \param pVector Dividing vector. |
| 213 | * \return \e this updated with the operation result. |
| 214 | * \remarks The values in pVector are not checked. |
| 215 | */ |
| 216 | FbxVector4& operator/=(const FbxVector4& pVector); |
| 217 | |
| 218 | /** Calculate the dot product of two vectors. |
| 219 | * \param pVector The second vector. |
| 220 | * \return The dot product value. |
| 221 | * \remarks Being considered as a XYZ vector with a weight, only the 3 first elements are considered in this operation. |
| 222 | */ |
| 223 | double DotProduct(const FbxVector4& pVector) const; |
| 224 | |
| 225 | /** Calculate the cross product of two vectors. |
| 226 | * \param pVector The second vector. |
| 227 | * \return The cross product vector. |
| 228 | * \remarks Being considered as a XYZ vector with a weight, only the first 3 elements are considered in this operation. |
| 229 | */ |
| 230 | FbxVector4 CrossProduct(const FbxVector4& pVector) const; |
| 231 | |
| 232 | /** Calculate the Euler rotation required to align axis pAB-pA on pAB-pB. |
| 233 | * \param pAB The intersection of the 2 axis. |
| 234 | * \param pA A point on axis to be aligned. |
| 235 | * \param pB A point on reference axis. |
| 236 | * \param pAngles Resulting euler angles. |
| 237 | * \return \c true on success. |
| 238 | * \remarks Being considered as a XYZ vector with a weight, only the first 3 elements are considered in this operation. |
| 239 | */ |
| 240 | static bool AxisAlignmentInEulerAngle(const FbxVector4& pAB, const FbxVector4& pA, const FbxVector4& pB, FbxVector4& pAngles); |
| 241 | //@} |
| 242 | |
| 243 | /** |
| 244 | * \name Boolean Operations |
| 245 | */ |
| 246 | //@{ |
| 247 | /** Equivalence operator. |
| 248 | * \param pVector The vector to be compared to \e this. |
| 249 | * \return \c true if the two vectors are equal (each element is within a FBXSDK_TOLERANCE tolerance) and \c false otherwise. |
| 250 | */ |
| 251 | bool operator==(const FbxVector4 & pVector) const; |
| 252 | |
| 253 | /** Non equivalence operator. |
| 254 | * \param pVector The vector to be compared to \e this. |
| 255 | * \return \c false if the two vectors are equal (each element is within a FBXSDK_TOLERANCE tolerance) and \c true otherwise. |
| 256 | */ |
| 257 | bool operator!=(const FbxVector4 & pVector) const; |
| 258 | //@} |
| 259 | |
| 260 | /** |
| 261 | * \name Length |
| 262 | */ |
| 263 | //@{ |
| 264 | /** Get the vector's length. |
| 265 | * \return The mathematical length of the vector. |
| 266 | * \remarks Being considered as a XYZ vector with a weight, only the first 3 elements are considered in this operation. |
| 267 | */ |
| 268 | double Length() const; |
| 269 | |
| 270 | /** Get the vector's length squared. |
| 271 | * \return The mathematical square length of the vector. |
| 272 | * \remarks Being considered as a XYZ vector with a weight, only the first 3 elements are considered in this operation. |
| 273 | */ |
| 274 | double SquareLength() const; |
| 275 | |
| 276 | /** Find the distance between 2 vectors. |
| 277 | * \param pVector The second vector. |
| 278 | * \return The mathematical distance between the two vectors. |
| 279 | * \remarks Being considered as a XYZ vector with a weight, only the 3 first elements are considered in this operation. |
| 280 | */ |
| 281 | double Distance(const FbxVector4& pVector) const; |
| 282 | |
| 283 | /** Normalize the vector, length set to 1. |
| 284 | * \remarks Being considered as a XYZ vector with a weight, only the first 3 elements are considered in this operation. |
| 285 | */ |
| 286 | void Normalize(); |
| 287 | |
| 288 | |
| 289 | /** Set the Euler XYZ from a Quaternion. |
| 290 | *\param pQuat Quaternion from which Euler XYZ information is got. |
| 291 | */ |
| 292 | void SetXYZ(const FbxQuaternion pQuat); |
| 293 | //@} |
| 294 | |
| 295 | /** |
| 296 | * \name Casting |
| 297 | */ |
| 298 | //@{ |
| 299 | //! Cast the vector in a double pointer. |
| 300 | operator double* (); |
| 301 | |
| 302 | //! Cast the vector in a const double pointer. |
| 303 | operator const double* () const; |
| 304 | //@} |
| 305 | |
| 306 | /** Find out if the vector is equal to zero. |
| 307 | * \param pSize The number of element to test, starting at beginning. Value must range between [1, 4]. |
| 308 | * \return \c true if all elements of the vector are zero, \c false otherwise. */ |
| 309 | bool IsZero(int pSize=4) const; |
| 310 | |
| 311 | // Fix value like 1.#IND, 1.#INF, nan, and inf |
| 312 | void FixIncorrectValue(); |
| 313 | |
| 314 | /***************************************************************************************************************************** |
| 315 | ** WARNING! Anything beyond these lines is for internal use, may not be documented and is subject to change without notice! ** |
| 316 | *****************************************************************************************************************************/ |
| 317 | #ifndef DOXYGEN_SHOULD_SKIP_THIS |
| 318 | int Compare(const FbxVector4& pV, const double pThreshold=FBXSDK_TOLERANCE) const; |
| 319 | #endif /* !DOXYGEN_SHOULD_SKIP_THIS *****************************************************************************************/ |
| 320 | }; |
| 321 | |
| 322 | #include <fbxsdk/fbxsdk_nsend.h> |
| 323 | |
| 324 | #endif /* _FBXSDK_CORE_MATH_VECTOR_4_H_ */ |
| 325 | |