From 9fe1652c2b34ae0918354a4f86f0bf76bf96c9c7 Mon Sep 17 00:00:00 2001 From: aramis_acg Date: Fri, 6 Feb 2009 22:43:08 +0000 Subject: [PATCH] Cleaned up public headers. git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@334 67173fc5-114c-0410-ac8e-9d2fd5bffc1f --- code/TextureTransform.cpp | 2 +- include/aiAnim.h | 74 +++++++++++++-- include/aiCamera.h | 8 +- include/aiDefines.h | 1 + include/aiMaterial.h | 2 - include/aiMatrix3x3.h | 80 ++++++++++++---- include/aiMatrix3x3.inl | 136 ++++++++++++++++++++++++++- include/aiMatrix4x4.h | 163 ++++++++++++++++++++------------ include/aiMatrix4x4.inl | 177 +++++++++++++++-------------------- include/aiPostProcess.h | 21 ++++- include/aiVector3D.h | 122 ++++++++++-------------- include/aiVector3D.inl | 169 ++++++++++++++++++++++++++++++++- workspaces/vc9/assimp.vcproj | 2 + 13 files changed, 686 insertions(+), 271 deletions(-) diff --git a/code/TextureTransform.cpp b/code/TextureTransform.cpp index 0eaf045d3..7b577d240 100644 --- a/code/TextureTransform.cpp +++ b/code/TextureTransform.cpp @@ -558,7 +558,7 @@ void TextureTransformStep::Execute( aiScene* pScene) m3.a3 = m3.b3 = -0.5f; if ((*it).mRotation > AI_TT_ROTATION_EPSILON ) - aiMatrix3x3::Rotation((*it).mRotation,matrix); + aiMatrix3x3::RotationZ((*it).mRotation,matrix); m5.a3 += trl.x; m5.b3 += trl.y; matrix = m2 * m4 * matrix * m3 * m5; diff --git a/include/aiAnim.h b/include/aiAnim.h index fafe9927a..bb18ec5a6 100644 --- a/include/aiAnim.h +++ b/include/aiAnim.h @@ -61,6 +61,7 @@ struct aiVectorKey C_STRUCT aiVector3D mValue; ///< The value of this key #ifdef __cplusplus + typedef aiVector3D elem_type; // time is not compared bool operator == (const aiVectorKey& o) const @@ -79,11 +80,9 @@ struct aiVectorKey bool operator > (const aiVectorKey& o) const {return mTime > o.mTime;} - #endif }; - // --------------------------------------------------------------------------- /** A time-value pair specifying a rotation for the given time. For joint * animations the rotation is usually expressed using a quaternion. @@ -94,6 +93,7 @@ struct aiQuatKey C_STRUCT aiQuaternion mValue; ///< The value of this key #ifdef __cplusplus + typedef aiQuaternion elem_type; // time is not compared bool operator == (const aiQuatKey& o) const @@ -111,7 +111,6 @@ struct aiQuatKey bool operator > (const aiQuatKey& o) const {return mTime < o.mTime;} - #endif }; @@ -161,7 +160,8 @@ enum aiAnimBehaviour * * @note All keys are returned in their correct, chronological order. * Duplicate keys don't pass the validation step. Most likely there - * will be no negative time keys, but they are not forbidden ... + * will be no negative time values, but they are not forbidden ( so you should + * be able to handle them ) */ struct aiNodeAnim { @@ -226,8 +226,8 @@ struct aiNodeAnim aiNodeAnim() { mNumPositionKeys = 0; mPositionKeys = NULL; - mNumRotationKeys= 0; mRotationKeys = NULL; - mNumScalingKeys = 0; mScalingKeys = NULL; + mNumRotationKeys = 0; mRotationKeys = NULL; + mNumScalingKeys = 0; mScalingKeys = NULL; mPreState = mPostState = aiAnimBehaviour_DEFAULT; } @@ -295,6 +295,66 @@ struct aiAnimation #ifdef __cplusplus } -#endif + +// some C++ utilities for inter- and extrapolation +namespace Assimp { + + +// --------------------------------------------------------------------------- +/** @brief Utility class to simplify interpolations of various data types. + * + * The type of interpolation is choosen automatically depending on the + * types of the arguments. + */ +template +struct Interpolator +{ + // ------------------------------------------------------------------ + /** @brief Get the result of the interpolation between a,b. + * + * The interpolation algorithm depends on the type of the operands. + * aiVectorKey LERPs, aiQuatKey SLERPs. Any other type lerps, too. + */ + void operator () (T& out,const T& a, const T& b, float d) const { + out = a + (b-a)*d; + } +}; // ! Interpolator + +// No need to have that in the doc, it is opaque. +// The compiler chooses the right variant and we're done. +#ifndef ASSIMP_DOXYGEN_BUILD + +template <> +struct Interpolator { + void operator () (aiQuaternion& out,const aiQuaternion& a, + const aiQuaternion& b, float d) const + { + aiQuaternion::Interpolate(out,a,b,d); + } +}; // ! Interpolator + +template <> +struct Interpolator { + void operator () (aiVector3D& out,const aiVectorKey& a, + const aiVectorKey& b, float d) const + { + Interpolator ipl; + ipl(out,a.mValue,b.mValue,d); + } +}; // ! Interpolator + +template <> +struct Interpolator { + void operator () (aiQuaternion& out, const aiQuatKey a, + const aiQuatKey& b, float d) const + { + Interpolator ipl; + ipl(out,a.mValue,b.mValue,d); + } +}; // ! Interpolator + +#endif // !! ASSIMP_DOXYGEN_BUILD +} // ! end namespace Assimp +#endif // __cplusplus #endif // AI_ANIM_H_INC diff --git a/include/aiCamera.h b/include/aiCamera.h index 0d7d441eb..fa6d7bfa6 100644 --- a/include/aiCamera.h +++ b/include/aiCamera.h @@ -91,7 +91,7 @@ extern "C" { * the point the camera is looking at (it can even be animated). Assimp * writes the target point as a subnode of the camera's main node, * called ".Target". However this is just additional information - * then, the transformation tracks of the camera main node make the + * then the transformation tracks of the camera main node make the * camera already look in the right direction. * */ @@ -192,9 +192,9 @@ struct aiCamera aiVector3D yaxis = mUp; yaxis.Normalize(); aiVector3D xaxis = mUp^mLookAt; xaxis.Normalize(); - out.a3 = -(xaxis * mPosition); - out.b3 = -(yaxis * mPosition); - out.c3 = -(zaxis * mPosition); + out.a4 = -(xaxis * mPosition); + out.b4 = -(yaxis * mPosition); + out.c4 = -(zaxis * mPosition); out.a1 = xaxis.x; out.a2 = xaxis.y; diff --git a/include/aiDefines.h b/include/aiDefines.h index 4c40f9d06..cfab02a3a 100644 --- a/include/aiDefines.h +++ b/include/aiDefines.h @@ -87,6 +87,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // FINDINVALIDDATA // TRANSFORMTEXCOORDS // GENUVCOORDS + // ENTITYMESHBUILDER // Compiler specific includes and definitions #if (defined _MSC_VER) diff --git a/include/aiMaterial.h b/include/aiMaterial.h index af394cf6a..8179400d9 100644 --- a/include/aiMaterial.h +++ b/include/aiMaterial.h @@ -636,8 +636,6 @@ extern "C" { /** @def AI_MATKEY_SHININESS * Defines the base shininess of the material * This is the exponent of the Phong shading equation. - * The range of this value depends on the file format, but usually - * you can assume that you won't get higher valzes than 128. *
* Type: float
* Default value: 0.0f
diff --git a/include/aiMatrix3x3.h b/include/aiMatrix3x3.h index d1cb803c0..2bd8356df 100644 --- a/include/aiMatrix3x3.h +++ b/include/aiMatrix3x3.h @@ -53,11 +53,16 @@ struct aiMatrix4x4; struct aiVector2D; // --------------------------------------------------------------------------- -/** Represents a row-major 3x3 matrix -*/ +/** @brief Represents a row-major 3x3 matrix + * + * There's much confusion about matrix layouts (colum vs. row order). + * This is *always* a row-major matrix. Even with the + * aiProcess_ConvertToLeftHanded flag. + */ struct aiMatrix3x3 { #ifdef __cplusplus + aiMatrix3x3 () : a1(1.0f), a2(0.0f), a3(0.0f), b1(0.0f), b2(1.0f), b3(0.0f), @@ -71,30 +76,73 @@ struct aiMatrix3x3 c1(_c1), c2(_c2), c3(_c3) {} - /** Construction from a 4x4 matrix. The remaining parts of the - matrix are ignored. */ +public: + + // matrix multiplication. beware, not commutative + aiMatrix3x3& operator *= (const aiMatrix3x3& m); + aiMatrix3x3 operator * (const aiMatrix3x3& m) const; + + // array access operators + float* operator[] (unsigned int p_iIndex); + const float* operator[] (unsigned int p_iIndex) const; + + // comparison operators + bool operator== (const aiMatrix4x4 m) const; + bool operator!= (const aiMatrix4x4 m) const; + +public: + + // ------------------------------------------------------------------- + /** @brief Construction from a 4x4 matrix. The remaining parts + * of the matrix are ignored. + */ explicit aiMatrix3x3( const aiMatrix4x4& pMatrix); - aiMatrix3x3& operator *= (const aiMatrix3x3& m); - aiMatrix3x3 operator* (const aiMatrix3x3& m) const; + // ------------------------------------------------------------------- + /** @brief Transpose the matrix + */ aiMatrix3x3& Transpose(); - - /** \brief Returns a rotation matrix - * \param a Rotation angle, in radians - * \param out Receives the output matrix - * \return Reference to the output matrix +public: + // ------------------------------------------------------------------- + /** @brief Returns a rotation matrix for a rotation around z + * @param a Rotation angle, in radians + * @param out Receives the output matrix + * @return Reference to the output matrix */ - static aiMatrix3x3& Rotation(float a, aiMatrix3x3& out); + static aiMatrix3x3& RotationZ(float a, aiMatrix3x3& out); + // ------------------------------------------------------------------- + /** @brief Returns a rotation matrix for a rotation around + * an arbitrary axis. + * + * @param a Rotation angle, in radians + * @param axis Axis to rotate around + * @param out To be filled + */ + static aiMatrix3x3& aiMatrix3x3::Rotation( float a, + const aiVector3D& axis, aiMatrix3x3& out); - /** \brief Returns a translation matrix - * \param v Translation vector - * \param out Receives the output matrix - * \return Reference to the output matrix + // ------------------------------------------------------------------- + /** @brief Returns a translation matrix + * @param v Translation vector + * @param out Receives the output matrix + * @return Reference to the output matrix */ static aiMatrix3x3& Translation( const aiVector2D& v, aiMatrix3x3& out); + // ------------------------------------------------------------------- + /** @brief A function for creating a rotation matrix that rotates a + * vector called "from" into another vector called "to". + * Input : from[3], to[3] which both must be *normalized* non-zero vectors + * Output: mtx[3][3] -- a 3x3 matrix in colum-major form + * Authors: Tomas Möller, John Hughes + * "Efficiently Building a Matrix to Rotate One Vector to Another" + * Journal of Graphics Tools, 4(4):1-4, 1999 + */ + static aiMatrix3x3& FromToMatrix(const aiVector3D& from, + const aiVector3D& to, aiMatrix3x3& out); + #endif // __cplusplus diff --git a/include/aiMatrix3x3.inl b/include/aiMatrix3x3.inl index 7768ea04f..f8c86a3ad 100644 --- a/include/aiMatrix3x3.inl +++ b/include/aiMatrix3x3.inl @@ -22,8 +22,7 @@ inline aiMatrix3x3::aiMatrix3x3( const aiMatrix4x4& pMatrix) // ------------------------------------------------------------------------------------------------ inline aiMatrix3x3& aiMatrix3x3::operator *= (const aiMatrix3x3& m) { - *this = aiMatrix3x3( - m.a1 * a1 + m.b1 * a2 + m.c1 * a3, + *this = aiMatrix3x3(m.a1 * a1 + m.b1 * a2 + m.c1 * a3, m.a2 * a1 + m.b2 * a2 + m.c2 * a3, m.a3 * a1 + m.b3 * a2 + m.c3 * a3, m.a1 * b1 + m.b1 * b2 + m.c1 * b3, @@ -43,6 +42,32 @@ inline aiMatrix3x3 aiMatrix3x3::operator* (const aiMatrix3x3& m) const return temp; } +// ------------------------------------------------------------------------------------------------ +inline float* aiMatrix3x3::operator[] (unsigned int p_iIndex) +{ + return &this->a1 + p_iIndex * 3; +} + +// ------------------------------------------------------------------------------------------------ +inline const float* aiMatrix3x3::operator[] (unsigned int p_iIndex) const +{ + return &this->a1 + p_iIndex * 3; +} + +// ------------------------------------------------------------------------------------------------ +inline bool aiMatrix3x3::operator== (const aiMatrix4x4 m) const +{ + return a1 == m.a1 && a2 == m.a2 && a3 == m.a3 && + b1 == m.b1 && b2 == m.b2 && b3 == m.b3 && + c1 == m.c1 && c2 == m.c2 && c3 == m.c3; +} + +// ------------------------------------------------------------------------------------------------ +inline bool aiMatrix3x3::operator!= (const aiMatrix4x4 m) const +{ + return !(*this == m); +} + // ------------------------------------------------------------------------------------------------ inline aiMatrix3x3& aiMatrix3x3::Transpose() { @@ -54,7 +79,7 @@ inline aiMatrix3x3& aiMatrix3x3::Transpose() } // ------------------------------------------------------------------------------------------------ -inline aiMatrix3x3& aiMatrix3x3::Rotation(float a, aiMatrix3x3& out) +inline aiMatrix3x3& aiMatrix3x3::RotationZ(float a, aiMatrix3x3& out) { out.a1 = out.b2 = ::cos(a); out.b1 = ::sin(a); @@ -66,6 +91,21 @@ inline aiMatrix3x3& aiMatrix3x3::Rotation(float a, aiMatrix3x3& out) return out; } +// ------------------------------------------------------------------------------------------------ +// Returns a rotation matrix for a rotation around an arbitrary axis. +inline aiMatrix3x3& aiMatrix3x3::Rotation( float a, const aiVector3D& axis, aiMatrix3x3& out) +{ + float c = cos( a), s = sin( a), t = 1 - c; + float x = axis.x, y = axis.y, z = axis.z; + + // Many thanks to MathWorld and Wikipedia + out.a1 = t*x*x + c; out.a2 = t*x*y - s*z; out.a3 = t*x*z + s*y; + out.b1 = t*x*y + s*z; out.b2 = t*y*y + c; out.b3 = t*y*z - s*x; + out.c1 = t*x*z - s*y; out.c2 = t*y*z + s*x; out.c3 = t*z*z + c; + + return out; +} + // ------------------------------------------------------------------------------------------------ inline aiMatrix3x3& aiMatrix3x3::Translation( const aiVector2D& v, aiMatrix3x3& out) { @@ -75,6 +115,96 @@ inline aiMatrix3x3& aiMatrix3x3::Translation( const aiVector2D& v, aiMatrix3x3& return out; } +// ---------------------------------------------------------------------------------------- +/** A function for creating a rotation matrix that rotates a vector called + * "from" into another vector called "to". + * Input : from[3], to[3] which both must be *normalized* non-zero vectors + * Output: mtx[3][3] -- a 3x3 matrix in colum-major form + * Authors: Tomas Möller, John Hughes + * "Efficiently Building a Matrix to Rotate One Vector to Another" + * Journal of Graphics Tools, 4(4):1-4, 1999 + */ +// ---------------------------------------------------------------------------------------- +inline aiMatrix3x3& aiMatrix3x3::FromToMatrix(const aiVector3D& from, + const aiVector3D& to, aiMatrix3x3& mtx) +{ + const aiVector3D v = from ^ to; + const float e = from * to; + const float f = (e < 0)? -e:e; + + if (f > 1.0 - 0.00001f) /* "from" and "to"-vector almost parallel */ + { + aiVector3D u,v; /* temporary storage vectors */ + aiVector3D x; /* vector most nearly orthogonal to "from" */ + + x.x = (from.x > 0.0)? from.x : -from.x; + x.y = (from.y > 0.0)? from.y : -from.y; + x.z = (from.z > 0.0)? from.z : -from.z; + + if (x.x < x.y) + { + if (x.x < x.z) + { + x.x = 1.0; x.y = x.z = 0.0; + } + else + { + x.z = 1.0; x.y = x.z = 0.0; + } + } + else + { + if (x.y < x.z) + { + x.y = 1.0; x.x = x.z = 0.0; + } + else + { + x.z = 1.0; x.x = x.y = 0.0; + } + } + + u.x = x.x - from.x; u.y = x.y - from.y; u.z = x.z - from.z; + v.x = x.x - to.x; v.y = x.y - to.y; v.z = x.z - to.z; + + const float c1 = 2.0f / (u * u); + const float c2 = 2.0f / (v * v); + const float c3 = c1 * c2 * (u * v); + + for (unsigned int i = 0; i < 3; i++) + { + for (unsigned int j = 0; j < 3; j++) + { + mtx[i][j] = - c1 * u[i] * u[j] - c2 * v[i] * v[j] + + c3 * v[i] * u[j]; + } + mtx[i][i] += 1.0; + } + } + else /* the most common case, unless "from"="to", or "from"=-"to" */ + { + /* ... use this hand optimized version (9 mults less) */ + const float h = 1.0f/(1.0f + e); /* optimization by Gottfried Chen */ + const float hvx = h * v.x; + const float hvz = h * v.z; + const float hvxy = hvx * v.y; + const float hvxz = hvx * v.z; + const float hvyz = hvz * v.y; + mtx[0][0] = e + hvx * v.x; + mtx[0][1] = hvxy - v.z; + mtx[0][2] = hvxz + v.y; + + mtx[1][0] = hvxy + v.z; + mtx[1][1] = e + h * v.y * v.y; + mtx[1][2] = hvyz - v.x; + + mtx[2][0] = hvxz - v.y; + mtx[2][1] = hvyz + v.x; + mtx[2][2] = e + hvz * v.z; + } + return mtx; +} + #endif // __cplusplus #endif // AI_MATRIX3x3_INL_INC diff --git a/include/aiMatrix4x4.h b/include/aiMatrix4x4.h index 8e893e034..91aab17fc 100644 --- a/include/aiMatrix4x4.h +++ b/include/aiMatrix4x4.h @@ -54,19 +54,25 @@ struct aiQuaternion; #include "./Compiler/pushpack1.h" // --------------------------------------------------------------------------- -/** Represents a row-major 4x4 matrix, -* use this for homogeneous coordinates -*/ -// --------------------------------------------------------------------------- +/** @brief Represents a row-major 4x4 matrix, use this for homogeneous + * coordinates. + * + * There's much confusion about matrix layouts (colum vs. row order). + * This is *always* a row-major matrix. Even with the + * aiProcess_ConvertToLeftHanded flag. + */ struct aiMatrix4x4 { #ifdef __cplusplus + + // default c'tor, init to zero aiMatrix4x4 () : a1(1.0f), a2(0.0f), a3(0.0f), a4(0.0f), b1(0.0f), b2(1.0f), b3(0.0f), b4(0.0f), c1(0.0f), c2(0.0f), c3(1.0f), c4(0.0f), d1(0.0f), d2(0.0f), d3(0.0f), d4(1.0f){} + // from single values aiMatrix4x4 ( float _a1, float _a2, float _a3, float _a4, float _b1, float _b2, float _b3, float _b4, float _c1, float _c2, float _c3, float _c4, @@ -77,98 +83,133 @@ struct aiMatrix4x4 d1(_d1), d2(_d2), d3(_d3), d4(_d4) {} - /** Constructor from 3x3 matrix. The remaining elements are set to identity. */ + + // ------------------------------------------------------------------- + /** @brief Constructor from 3x3 matrix. + * The remaining elements are set to identity. + */ explicit aiMatrix4x4( const aiMatrix3x3& m); +public: + + // array access operators + float* operator[] (unsigned int p_iIndex); + const float* operator[] (unsigned int p_iIndex) const; + + // comparison operators + bool operator== (const aiMatrix4x4 m) const; + bool operator!= (const aiMatrix4x4 m) const; + + // Matrix multiplication. Not commutative. aiMatrix4x4& operator *= (const aiMatrix4x4& m); - aiMatrix4x4 operator* (const aiMatrix4x4& m) const; + aiMatrix4x4 operator * (const aiMatrix4x4& m) const; + +public: + + // ------------------------------------------------------------------- + /** @brief Transpose the matrix + */ aiMatrix4x4& Transpose(); + + // ------------------------------------------------------------------- + /** @brief Invert the matrix. + * If the matrix is not invertible all elements are set to qnan. + * Beware, use (f != f) to check whether a float f is qnan. + */ aiMatrix4x4& Inverse(); float Determinant() const; + + // ------------------------------------------------------------------- + /** @brief Returns true of the matrix is the identity matrix. + * The check is performed against a not so small epsilon. + */ inline bool IsIdentity() const; - float* operator[](unsigned int p_iIndex); - const float* operator[](unsigned int p_iIndex) const; - - inline bool operator== (const aiMatrix4x4 m) const; - inline bool operator!= (const aiMatrix4x4 m) const; - - - /** \brief Decompose a trafo matrix into its original components - * \param scaling Receives the output scaling for the x,y,z axes - * \param rotation Receives the output rotation as a hamilton + // ------------------------------------------------------------------- + /** @brief Decompose a trafo matrix into its original components + * @param scaling Receives the output scaling for the x,y,z axes + * @param rotation Receives the output rotation as a hamilton * quaternion - * \param position Receives the output position for the x,y,z axes + * @param position Receives the output position for the x,y,z axes */ - inline void Decompose (aiVector3D& scaling, aiQuaternion& rotation, + void Decompose (aiVector3D& scaling, aiQuaternion& rotation, + aiVector3D& position) const; + + // ------------------------------------------------------------------- + /** @brief Decompose a trafo matrix with no scaling into its + * original components + * @param rotation Receives the output rotation as a hamilton + * quaternion + * @param position Receives the output position for the x,y,z axes + */ + void DecomposeNoScaling (aiQuaternion& rotation, aiVector3D& position) const; - /** \brief Decompose a trafo matrix with no scaling into its - * original components - * \param rotation Receives the output rotation as a hamilton - * quaternion - * \param position Receives the output position for the x,y,z axes + // ------------------------------------------------------------------- + /** @brief Creates a trafo matrix from a set of euler angles + * @param x Rotation angle for the x-axis, in radians + * @param y Rotation angle for the y-axis, in radians + * @param z Rotation angle for the z-axis, in radians */ - inline void DecomposeNoScaling (aiQuaternion& rotation, - aiVector3D& position) const; + void FromEulerAnglesXYZ(float x, float y, float z); + void FromEulerAnglesXYZ(const aiVector3D& blubb); - /** \brief Creates a trafo matrix from a set of euler angles - * \param x Rotation angle for the x-axis, in radians - * \param y Rotation angle for the y-axis, in radians - * \param z Rotation angle for the z-axis, in radians - */ - inline void FromEulerAnglesXYZ(float x, float y, float z); - inline void FromEulerAnglesXYZ(const aiVector3D& blubb); - - - /** \brief Returns a rotation matrix for a rotation around the x axis - * \param a Rotation angle, in radians - * \param out Receives the output matrix - * \return Reference to the output matrix +public: + // ------------------------------------------------------------------- + /** @brief Returns a rotation matrix for a rotation around the x axis + * @param a Rotation angle, in radians + * @param out Receives the output matrix + * @return Reference to the output matrix */ static aiMatrix4x4& RotationX(float a, aiMatrix4x4& out); - /** \brief Returns a rotation matrix for a rotation around the y axis - * \param a Rotation angle, in radians - * \param out Receives the output matrix - * \return Reference to the output matrix + // ------------------------------------------------------------------- + /** @brief Returns a rotation matrix for a rotation around the y axis + * @param a Rotation angle, in radians + * @param out Receives the output matrix + * @return Reference to the output matrix */ static aiMatrix4x4& RotationY(float a, aiMatrix4x4& out); - /** \brief Returns a rotation matrix for a rotation around the z axis - * \param a Rotation angle, in radians - * \param out Receives the output matrix - * \return Reference to the output matrix + // ------------------------------------------------------------------- + /** @brief Returns a rotation matrix for a rotation around the z axis + * @param a Rotation angle, in radians + * @param out Receives the output matrix + * @return Reference to the output matrix */ static aiMatrix4x4& RotationZ(float a, aiMatrix4x4& out); + // ------------------------------------------------------------------- /** Returns a rotation matrix for a rotation around an arbitrary axis. * @param a Rotation angle, in radians * @param axis Rotation axis, should be a normalized vector. * @param out Receives the output matrix - * \return Reference to the output matrix + * @return Reference to the output matrix */ - static aiMatrix4x4& Rotation(float a, const aiVector3D& axis, aiMatrix4x4& out); + static aiMatrix4x4& Rotation(float a, const aiVector3D& axis, + aiMatrix4x4& out); - /** \brief Returns a translation matrix - * \param v Translation vector - * \param out Receives the output matrix - * \return Reference to the output matrix + // ------------------------------------------------------------------- + /** @brief Returns a translation matrix + * @param v Translation vector + * @param out Receives the output matrix + * @return Reference to the output matrix */ static aiMatrix4x4& Translation( const aiVector3D& v, aiMatrix4x4& out); - /** A function for creating a rotation matrix that rotates a vector called - * "from" into another vector called "to". - * Input : from[3], to[3] which both must be *normalized* non-zero vectors - * Output: mtx[3][3] -- a 3x3 matrix in colum-major form - * Authors: Tomas Möller, John Hughes - * "Efficiently Building a Matrix to Rotate One Vector to Another" - * Journal of Graphics Tools, 4(4):1-4, 1999 - */ + // ------------------------------------------------------------------- + /** @brief A function for creating a rotation matrix that rotates a + * vector called "from" into another vector called "to". + * Input : from[3], to[3] which both must be *normalized* non-zero vectors + * Output: mtx[3][3] -- a 3x3 matrix in colum-major form + * Authors: Tomas Möller, John Hughes + * "Efficiently Building a Matrix to Rotate One Vector to Another" + * Journal of Graphics Tools, 4(4):1-4, 1999 + */ static aiMatrix4x4& FromToMatrix(const aiVector3D& from, const aiVector3D& to, aiMatrix4x4& out); @@ -179,7 +220,7 @@ struct aiMatrix4x4 float c1, c2, c3, c4; float d1, d2, d3, d4; -} PACK_STRUCT; +} PACK_STRUCT; // !class aiMatrix4x4 #include "./Compiler/poppack1.h" diff --git a/include/aiMatrix4x4.inl b/include/aiMatrix4x4.inl index 642746902..cd65a7006 100644 --- a/include/aiMatrix4x4.inl +++ b/include/aiMatrix4x4.inl @@ -1,3 +1,44 @@ +/* +--------------------------------------------------------------------------- +Open Asset Import Library (ASSIMP) +--------------------------------------------------------------------------- + +Copyright (c) 2006-2008, ASSIMP Development Team + +All rights reserved. + +Redistribution and use of this software in source and binary forms, +with or without modification, are permitted provided that the following +conditions are met: + +* Redistributions of source code must retain the above + copyright notice, this list of conditions and the + following disclaimer. + +* Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the + following disclaimer in the documentation and/or other + materials provided with the distribution. + +* Neither the name of the ASSIMP team, nor the names of its + contributors may be used to endorse or promote products + derived from this software without specific prior + written permission of the ASSIMP Development Team. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +--------------------------------------------------------------------------- +*/ + /** @file aiMatrix4x4.inl * @brief Inline implementation of the 4x4 matrix operators */ @@ -16,7 +57,7 @@ #include "aiAssert.h" #include "aiQuaternion.h" -// --------------------------------------------------------------------------- +// ---------------------------------------------------------------------------------------- inline aiMatrix4x4::aiMatrix4x4( const aiMatrix3x3& m) { a1 = m.a1; a2 = m.a2; a3 = m.a3; a4 = 0.0f; @@ -25,7 +66,7 @@ inline aiMatrix4x4::aiMatrix4x4( const aiMatrix3x3& m) d1 = 0.0f; d2 = 0.0f; d3 = 0.0f; d4 = 1.0f; } -// --------------------------------------------------------------------------- +// ---------------------------------------------------------------------------------------- inline aiMatrix4x4& aiMatrix4x4::operator *= (const aiMatrix4x4& m) { *this = aiMatrix4x4( @@ -48,7 +89,7 @@ inline aiMatrix4x4& aiMatrix4x4::operator *= (const aiMatrix4x4& m) return *this; } -// --------------------------------------------------------------------------- +// ---------------------------------------------------------------------------------------- inline aiMatrix4x4 aiMatrix4x4::operator* (const aiMatrix4x4& m) const { aiMatrix4x4 temp( *this); @@ -57,7 +98,7 @@ inline aiMatrix4x4 aiMatrix4x4::operator* (const aiMatrix4x4& m) const } -// --------------------------------------------------------------------------- +// ---------------------------------------------------------------------------------------- inline aiMatrix4x4& aiMatrix4x4::Transpose() { // (float&) don't remove, GCC complains cause of packed fields @@ -71,7 +112,7 @@ inline aiMatrix4x4& aiMatrix4x4::Transpose() } -// --------------------------------------------------------------------------- +// ---------------------------------------------------------------------------------------- inline float aiMatrix4x4::Determinant() const { return a1*b2*c3*d4 - a1*b2*c4*d3 + a1*b3*c4*d2 - a1*b3*c2*d4 @@ -82,7 +123,7 @@ inline float aiMatrix4x4::Determinant() const - a4*b2*c3*d1 + a4*b2*c1*d3 - a4*b3*c1*d2 + a4*b3*c2*d1; } -// --------------------------------------------------------------------------- +// ---------------------------------------------------------------------------------------- inline aiMatrix4x4& aiMatrix4x4::Inverse() { // Compute the reciprocal determinant @@ -126,31 +167,34 @@ inline aiMatrix4x4& aiMatrix4x4::Inverse() return *this; } -// --------------------------------------------------------------------------- +// ---------------------------------------------------------------------------------------- inline float* aiMatrix4x4::operator[](unsigned int p_iIndex) { return &this->a1 + p_iIndex * 4; } -// --------------------------------------------------------------------------- +// ---------------------------------------------------------------------------------------- inline const float* aiMatrix4x4::operator[](unsigned int p_iIndex) const { return &this->a1 + p_iIndex * 4; } -// --------------------------------------------------------------------------- + +// ---------------------------------------------------------------------------------------- inline bool aiMatrix4x4::operator== (const aiMatrix4x4 m) const { return (a1 == m.a1 && a2 == m.a2 && a3 == m.a3 && a4 == m.a4 && - b1 == m.b1 && b2 == m.b2 && b3 == m.b3 && b4 == m.b4 && - c1 == m.c1 && c2 == m.c2 && c3 == m.c3 && c4 == m.c4 && - d1 == m.d1 && d2 == m.d2 && d3 == m.d3 && d4 == m.d4); + b1 == m.b1 && b2 == m.b2 && b3 == m.b3 && b4 == m.b4 && + c1 == m.c1 && c2 == m.c2 && c3 == m.c3 && c4 == m.c4 && + d1 == m.d1 && d2 == m.d2 && d3 == m.d3 && d4 == m.d4); } -// --------------------------------------------------------------------------- + +// ---------------------------------------------------------------------------------------- inline bool aiMatrix4x4::operator!= (const aiMatrix4x4 m) const { return !(*this == m); } -// --------------------------------------------------------------------------- + +// ---------------------------------------------------------------------------------------- inline void aiMatrix4x4::Decompose (aiVector3D& scaling, aiQuaternion& rotation, aiVector3D& position) const { @@ -195,7 +239,8 @@ inline void aiMatrix4x4::Decompose (aiVector3D& scaling, aiQuaternion& rotation, // and generate the rotation quaternion from it rotation = aiQuaternion(m); } -// --------------------------------------------------------------------------- + +// ---------------------------------------------------------------------------------------- inline void aiMatrix4x4::DecomposeNoScaling (aiQuaternion& rotation, aiVector3D& position) const { @@ -209,12 +254,14 @@ inline void aiMatrix4x4::DecomposeNoScaling (aiQuaternion& rotation, // extract rotation rotation = aiQuaternion((aiMatrix3x3)_this); } -// --------------------------------------------------------------------------- + +// ---------------------------------------------------------------------------------------- inline void aiMatrix4x4::FromEulerAnglesXYZ(const aiVector3D& blubb) { FromEulerAnglesXYZ(blubb.x,blubb.y,blubb.z); } -// --------------------------------------------------------------------------- + +// ---------------------------------------------------------------------------------------- inline void aiMatrix4x4::FromEulerAnglesXYZ(float x, float y, float z) { aiMatrix4x4& _this = *this; @@ -242,7 +289,8 @@ inline void aiMatrix4x4::FromEulerAnglesXYZ(float x, float y, float z) _this.c3 = cr*cp ; } -// --------------------------------------------------------------------------- + +// ---------------------------------------------------------------------------------------- inline bool aiMatrix4x4::IsIdentity() const { // Use a small epsilon to solve floating-point inaccuracies @@ -266,7 +314,7 @@ inline bool aiMatrix4x4::IsIdentity() const d4 <= 1.f+epsilon && d4 >= 1.f-epsilon); } -// --------------------------------------------------------------------------- +// ---------------------------------------------------------------------------------------- inline aiMatrix4x4& aiMatrix4x4::RotationX(float a, aiMatrix4x4& out) { /* @@ -280,7 +328,7 @@ inline aiMatrix4x4& aiMatrix4x4::RotationX(float a, aiMatrix4x4& out) return out; } -// --------------------------------------------------------------------------- +// ---------------------------------------------------------------------------------------- inline aiMatrix4x4& aiMatrix4x4::RotationY(float a, aiMatrix4x4& out) { /* @@ -295,7 +343,7 @@ inline aiMatrix4x4& aiMatrix4x4::RotationY(float a, aiMatrix4x4& out) return out; } -// --------------------------------------------------------------------------- +// ---------------------------------------------------------------------------------------- inline aiMatrix4x4& aiMatrix4x4::RotationZ(float a, aiMatrix4x4& out) { /* @@ -309,7 +357,7 @@ inline aiMatrix4x4& aiMatrix4x4::RotationZ(float a, aiMatrix4x4& out) return out; } -// --------------------------------------------------------------------------- +// ---------------------------------------------------------------------------------------- // Returns a rotation matrix for a rotation around an arbitrary axis. inline aiMatrix4x4& aiMatrix4x4::Rotation( float a, const aiVector3D& axis, aiMatrix4x4& out) { @@ -327,7 +375,7 @@ inline aiMatrix4x4& aiMatrix4x4::Rotation( float a, const aiVector3D& axis, aiMa return out; } -// --------------------------------------------------------------------------- +// ---------------------------------------------------------------------------------------- inline aiMatrix4x4& aiMatrix4x4::Translation( const aiVector3D& v, aiMatrix4x4& out) { out = aiMatrix4x4(); @@ -337,7 +385,7 @@ inline aiMatrix4x4& aiMatrix4x4::Translation( const aiVector3D& v, aiMatrix4x4& return out; } -// --------------------------------------------------------------------------- +// ---------------------------------------------------------------------------------------- /** A function for creating a rotation matrix that rotates a vector called * "from" into another vector called "to". * Input : from[3], to[3] which both must be *normalized* non-zero vectors @@ -346,84 +394,13 @@ inline aiMatrix4x4& aiMatrix4x4::Translation( const aiVector3D& v, aiMatrix4x4& * "Efficiently Building a Matrix to Rotate One Vector to Another" * Journal of Graphics Tools, 4(4):1-4, 1999 */ -// --------------------------------------------------------------------------- +// ---------------------------------------------------------------------------------------- inline aiMatrix4x4& aiMatrix4x4::FromToMatrix(const aiVector3D& from, const aiVector3D& to, aiMatrix4x4& mtx) -{ - const aiVector3D v = from ^ to; - const float e = from * to; - const float f = (e < 0)? -e:e; - - if (f > 1.0 - 0.00001f) /* "from" and "to"-vector almost parallel */ - { - aiVector3D u,v; /* temporary storage vectors */ - aiVector3D x; /* vector most nearly orthogonal to "from" */ - - x.x = (from.x > 0.0)? from.x : -from.x; - x.y = (from.y > 0.0)? from.y : -from.y; - x.z = (from.z > 0.0)? from.z : -from.z; - - if (x.x < x.y) - { - if (x.x < x.z) - { - x.x = 1.0; x.y = x.z = 0.0; - } - else - { - x.z = 1.0; x.y = x.z = 0.0; - } - } - else - { - if (x.y < x.z) - { - x.y = 1.0; x.x = x.z = 0.0; - } - else - { - x.z = 1.0; x.x = x.y = 0.0; - } - } - - u.x = x.x - from.x; u.y = x.y - from.y; u.z = x.z - from.z; - v.x = x.x - to.x; v.y = x.y - to.y; v.z = x.z - to.z; - - const float c1 = 2.0f / (u * u); - const float c2 = 2.0f / (v * v); - const float c3 = c1 * c2 * (u * v); - - for (unsigned int i = 0; i < 3; i++) - { - for (unsigned int j = 0; j < 3; j++) - { - mtx[i][j] = - c1 * u[i] * u[j] - c2 * v[i] * v[j] - + c3 * v[i] * u[j]; - } - mtx[i][i] += 1.0; - } - } - else /* the most common case, unless "from"="to", or "from"=-"to" */ - { - /* ... use this hand optimized version (9 mults less) */ - const float h = 1.0f/(1.0f + e); /* optimization by Gottfried Chen */ - const float hvx = h * v.x; - const float hvz = h * v.z; - const float hvxy = hvx * v.y; - const float hvxz = hvx * v.z; - const float hvyz = hvz * v.y; - mtx[0][0] = e + hvx * v.x; - mtx[0][1] = hvxy - v.z; - mtx[0][2] = hvxz + v.y; - - mtx[1][0] = hvxy + v.z; - mtx[1][1] = e + h * v.y * v.y; - mtx[1][2] = hvyz - v.x; - - mtx[2][0] = hvxz - v.y; - mtx[2][1] = hvyz + v.x; - mtx[2][2] = e + hvz * v.z; - } +{ + aiMatrix3x3 m3; + aiMatrix3x3::FromToMatrix(from,to,m3); + mtx = aiMatrix4x4(m3); return mtx; } diff --git a/include/aiPostProcess.h b/include/aiPostProcess.h index 59984c40c..0fb6a762f 100644 --- a/include/aiPostProcess.h +++ b/include/aiPostProcess.h @@ -212,7 +212,21 @@ enum aiPostProcessSteps /** This step searches all meshes for degenerated primitives and * converts them to proper lines or points. * - * A face is degenerated if one or more of its faces are identical. + * A face is degenerated if one or more of its points are identical. + * To have the degenerated not only detected and collapsed but also + * removed use the following procedure: + *
    + *
  • Specify the aiProcess_FindDegenerates flag. + *
  • + *
  • Specify the aiProcess_SortByPType flag. This moves line and + * point primitives to separate meshes + *
  • + *
  • Set the AI_CONFIG_PP_SBP_REMOVE option to aiPrimitiveType_POINTS + * | aiPrimitiveType_LINES to cause SortByPType to reject point + * and line meshes from the scene. + *
  • + *
+ * */ aiProcess_FindDegenerates = 0x10000, @@ -255,6 +269,11 @@ enum aiPostProcessSteps * todo ... add more doc */ aiProcess_FindInstances = 0x100000 + + + // aiProcess_GenEntityMeshes = 0x100000, + // aiProcess_OptimizeAnimations = 0x200000 + // aiProcess_OptimizeNodes = 0x400000 }; diff --git a/include/aiVector3D.h b/include/aiVector3D.h index 9a3a9a99d..598be9d8e 100644 --- a/include/aiVector3D.h +++ b/include/aiVector3D.h @@ -52,6 +52,9 @@ extern "C" { #include "./Compiler/pushpack1.h" +struct aiMatrix3x3; +struct aiMatrix4x4; + // --------------------------------------------------------------------------- /** Represents a three-dimensional vector. */ struct aiVector3D @@ -62,29 +65,58 @@ struct aiVector3D aiVector3D (float _xyz) : x(_xyz), y(_xyz), z(_xyz) {} aiVector3D (const aiVector3D& o) : x(o.x), y(o.y), z(o.z) {} - void Set( float pX, float pY, float pZ) { x = pX; y = pY; z = pZ; } - float SquareLength() const { return x*x + y*y + z*z; } - float Length() const { return sqrt( SquareLength()); } - aiVector3D& Normalize() { *this /= Length(); return *this; } - const aiVector3D& operator += (const aiVector3D& o) { x += o.x; y += o.y; z += o.z; return *this; } - const aiVector3D& operator -= (const aiVector3D& o) { x -= o.x; y -= o.y; z -= o.z; return *this; } - const aiVector3D& operator *= (float f) { x *= f; y *= f; z *= f; return *this; } - const aiVector3D& operator /= (float f) { x /= f; y /= f; z /= f; return *this; } +public: - inline float operator[](unsigned int i) const {return *(&x + i);} - inline float& operator[](unsigned int i) {return *(&x + i);} + // combined operators + const aiVector3D& operator += (const aiVector3D& o); + const aiVector3D& operator -= (const aiVector3D& o); + const aiVector3D& operator *= (float f); + const aiVector3D& operator /= (float f); - inline bool operator== (const aiVector3D& other) const - {return x == other.x && y == other.y && z == other.z;} + // transform vector by matrix + aiVector3D& operator *= (const aiMatrix3x3& mat); + aiVector3D& operator *= (const aiMatrix4x4& mat); - inline bool operator!= (const aiVector3D& other) const - {return x != other.x || y != other.y || z != other.z;} + // access a single element + inline float operator[](unsigned int i) const; + inline float& operator[](unsigned int i); - inline aiVector3D& operator= (float f) - {x = y = z = f;return *this;} + // comparison + inline bool operator== (const aiVector3D& other) const; + inline bool operator!= (const aiVector3D& other) const; - const aiVector3D SymMul(const aiVector3D& o) - {return aiVector3D(x*o.x,y*o.y,z*o.z);} +public: + + /** @brief Set the components of a vector + * @param pX X component + * @param pY Y component + * @param pZ Z component + */ + void Set( float pX, float pY, float pZ); + + /** @brief Get the squared length of the vector + * @return Square length + */ + float SquareLength() const; + + + /** @brief Get the length of the vector + * @return length + */ + float Length() const; + + + /** @brief Normalize the vector + */ + aiVector3D& Normalize(); + + + /** @brief Componentwise multiplication of two vectors + * + * Note that vec*vec yields the dot product. + * @param o Second factor + */ + const aiVector3D SymMul(const aiVector3D& o); #endif // __cplusplus @@ -96,60 +128,6 @@ struct aiVector3D #ifdef __cplusplus } // end extern "C" -// symmetric addition -inline aiVector3D operator + (const aiVector3D& v1, const aiVector3D& v2) -{ - return aiVector3D( v1.x + v2.x, v1.y + v2.y, v1.z + v2.z); -} - -// symmetric subtraction -inline aiVector3D operator - (const aiVector3D& v1, const aiVector3D& v2) -{ - return aiVector3D( v1.x - v2.x, v1.y - v2.y, v1.z - v2.z); -} - -// scalar product -inline float operator * (const aiVector3D& v1, const aiVector3D& v2) -{ - return v1.x*v2.x + v1.y*v2.y + v1.z*v2.z; -} - -// scalar multiplication -inline aiVector3D operator * ( float f, const aiVector3D& v) -{ - return aiVector3D( f*v.x, f*v.y, f*v.z); -} - -// and the other way around -inline aiVector3D operator * ( const aiVector3D& v, float f) -{ - return aiVector3D( f*v.x, f*v.y, f*v.z); -} - -// scalar division -inline aiVector3D operator / ( const aiVector3D& v, float f) -{ - - return v * (1/f); -} - -// vector division -inline aiVector3D operator / ( const aiVector3D& v, const aiVector3D& v2) -{ - return aiVector3D(v.x / v2.x,v.y / v2.y,v.z / v2.z); -} - -// cross product -inline aiVector3D operator ^ ( const aiVector3D& v1, const aiVector3D& v2) -{ - return aiVector3D( v1.y*v2.z - v1.z*v2.y, v1.z*v2.x - v1.x*v2.z, v1.x*v2.y - v1.y*v2.x); -} - -// vector inversion -inline aiVector3D operator - ( const aiVector3D& v) -{ - return aiVector3D( -v.x, -v.y, -v.z); -} #endif // __cplusplus diff --git a/include/aiVector3D.inl b/include/aiVector3D.inl index e7a9531c6..394bf8663 100644 --- a/include/aiVector3D.inl +++ b/include/aiVector3D.inl @@ -1,5 +1,46 @@ -/** @file aiVector3D.inl - * @brief Inline implementation of vector3D operators +/* +--------------------------------------------------------------------------- +Open Asset Import Library (ASSIMP) +--------------------------------------------------------------------------- + +Copyright (c) 2006-2008, ASSIMP Development Team + +All rights reserved. + +Redistribution and use of this software in source and binary forms, +with or without modification, are permitted provided that the following +conditions are met: + +* Redistributions of source code must retain the above + copyright notice, this list of conditions and the + following disclaimer. + +* Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the + following disclaimer in the documentation and/or other + materials provided with the distribution. + +* Neither the name of the ASSIMP team, nor the names of its + contributors may be used to endorse or promote products + derived from this software without specific prior + written permission of the ASSIMP Development Team. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +--------------------------------------------------------------------------- +*/ + +/** @file aiVector3D.inl + * @brief Inline implementation of aiVector3D operators */ #ifndef AI_VECTOR3D_INL_INC #define AI_VECTOR3D_INL_INC @@ -7,9 +48,8 @@ #include "aiVector3D.h" #ifdef __cplusplus -#include "aiMatrix3x3.h" -#include "aiMatrix4x4.h" +// ------------------------------------------------------------------------------------------------ /** Transformation of a vector by a 3x3 matrix */ inline aiVector3D operator * (const aiMatrix3x3& pMatrix, const aiVector3D& pVector) { @@ -20,6 +60,7 @@ inline aiVector3D operator * (const aiMatrix3x3& pMatrix, const aiVector3D& pVec return res; } +// ------------------------------------------------------------------------------------------------ /** Transformation of a vector by a 4x4 matrix */ inline aiVector3D operator * (const aiMatrix4x4& pMatrix, const aiVector3D& pVector) { @@ -29,7 +70,127 @@ inline aiVector3D operator * (const aiMatrix4x4& pMatrix, const aiVector3D& pVec res.z = pMatrix.c1 * pVector.x + pMatrix.c2 * pVector.y + pMatrix.c3 * pVector.z + pMatrix.c4; return res; } +// ------------------------------------------------------------------------------------------------ +AI_FORCE_INLINE void aiVector3D::Set( float pX, float pY, float pZ) { + x = pX; y = pY; z = pZ; +} +// ------------------------------------------------------------------------------------------------ +AI_FORCE_INLINE float aiVector3D::SquareLength() const { + return x*x + y*y + z*z; +} +// ------------------------------------------------------------------------------------------------ +AI_FORCE_INLINE float aiVector3D::Length() const { + return sqrt( SquareLength()); +} +// ------------------------------------------------------------------------------------------------ +AI_FORCE_INLINE aiVector3D& aiVector3D::Normalize() { + *this /= Length(); return *this; +} +// ------------------------------------------------------------------------------------------------ +AI_FORCE_INLINE const aiVector3D& aiVector3D::operator += (const aiVector3D& o) { + x += o.x; y += o.y; z += o.z; return *this; +} +// ------------------------------------------------------------------------------------------------ +AI_FORCE_INLINE const aiVector3D& aiVector3D::operator -= (const aiVector3D& o) { + x -= o.x; y -= o.y; z -= o.z; return *this; +} +// ------------------------------------------------------------------------------------------------ +AI_FORCE_INLINE const aiVector3D& aiVector3D::operator *= (float f) { + x *= f; y *= f; z *= f; return *this; +} +// ------------------------------------------------------------------------------------------------ +AI_FORCE_INLINE const aiVector3D& aiVector3D::operator /= (float f) { + x /= f; y /= f; z /= f; return *this; +} +// ------------------------------------------------------------------------------------------------ +AI_FORCE_INLINE aiVector3D& aiVector3D::operator *= (const aiMatrix3x3& mat){ + return(*this = mat * (*this)); +} +// ------------------------------------------------------------------------------------------------ +AI_FORCE_INLINE aiVector3D& aiVector3D::operator *= (const aiMatrix4x4& mat){ + return(*this = mat * (*this)); +} +// ------------------------------------------------------------------------------------------------ +AI_FORCE_INLINE float aiVector3D::operator[](unsigned int i) const { + return *(&x + i); +} +// ------------------------------------------------------------------------------------------------ +AI_FORCE_INLINE float& aiVector3D::operator[](unsigned int i) { + return *(&x + i); +} +// ------------------------------------------------------------------------------------------------ +AI_FORCE_INLINE bool aiVector3D::operator== (const aiVector3D& other) const { + return x == other.x && y == other.y && z == other.z; +} +// ------------------------------------------------------------------------------------------------ +AI_FORCE_INLINE bool aiVector3D::operator!= (const aiVector3D& other) const { + return x != other.x || y != other.y || z != other.z; +} +// ------------------------------------------------------------------------------------------------ +AI_FORCE_INLINE const aiVector3D aiVector3D::SymMul(const aiVector3D& o) { + return aiVector3D(x*o.x,y*o.y,z*o.z); +} +// ------------------------------------------------------------------------------------------------ +// symmetric addition +AI_FORCE_INLINE aiVector3D operator + (const aiVector3D& v1, const aiVector3D& v2) { + return aiVector3D( v1.x + v2.x, v1.y + v2.y, v1.z + v2.z); +} +// ------------------------------------------------------------------------------------------------ +// symmetric subtraction +AI_FORCE_INLINE aiVector3D operator - (const aiVector3D& v1, const aiVector3D& v2) { + return aiVector3D( v1.x - v2.x, v1.y - v2.y, v1.z - v2.z); +} +// ------------------------------------------------------------------------------------------------ +// scalar product +AI_FORCE_INLINE float operator * (const aiVector3D& v1, const aiVector3D& v2) { + return v1.x*v2.x + v1.y*v2.y + v1.z*v2.z; +} +// ------------------------------------------------------------------------------------------------ +// scalar multiplication +AI_FORCE_INLINE aiVector3D operator * ( float f, const aiVector3D& v) { + return aiVector3D( f*v.x, f*v.y, f*v.z); +} +// ------------------------------------------------------------------------------------------------ +// and the other way around +AI_FORCE_INLINE aiVector3D operator * ( const aiVector3D& v, float f) { + return aiVector3D( f*v.x, f*v.y, f*v.z); +} +// ------------------------------------------------------------------------------------------------ +// scalar division +AI_FORCE_INLINE aiVector3D operator / ( const aiVector3D& v, float f) { + return v * (1/f); +} +// ------------------------------------------------------------------------------------------------ +// vector division +AI_FORCE_INLINE aiVector3D operator / ( const aiVector3D& v, const aiVector3D& v2) { + return aiVector3D(v.x / v2.x,v.y / v2.y,v.z / v2.z); +} +// ------------------------------------------------------------------------------------------------ +// cross product +AI_FORCE_INLINE aiVector3D operator ^ ( const aiVector3D& v1, const aiVector3D& v2) { + return aiVector3D( v1.y*v2.z - v1.z*v2.y, v1.z*v2.x - v1.x*v2.z, v1.x*v2.y - v1.y*v2.x); +} +// ------------------------------------------------------------------------------------------------ +// vector inversion +AI_FORCE_INLINE aiVector3D operator - ( const aiVector3D& v) { + return aiVector3D( -v.x, -v.y, -v.z); +} +#ifdef ASSIMP_INTERNAL_BUILD +namespace std { + + // std::min for aiVector3D + inline ::aiVector3D min (const ::aiVector3D& a, const ::aiVector3D& b) { + return ::aiVector3D (min(a.x,b.x),min(a.y,b.y),min(a.z,b.z)); + } + + // std::max for aiVector3D + inline ::aiVector3D max (const ::aiVector3D& a, const ::aiVector3D& b) { + return ::aiVector3D (max(a.x,b.x),max(a.y,b.y),max(a.z,b.z)); + } + +} // end namespace std +#endif // !! ASSIMP_INTERNAL_BUILD #endif // __cplusplus #endif // AI_VECTOR3D_INL_INC diff --git a/workspaces/vc9/assimp.vcproj b/workspaces/vc9/assimp.vcproj index 2334f8d87..43be68e09 100644 --- a/workspaces/vc9/assimp.vcproj +++ b/workspaces/vc9/assimp.vcproj @@ -197,6 +197,7 @@