diff --git a/code/ColladaExporter.cpp b/code/ColladaExporter.cpp index 40f5da430..820c25b78 100644 --- a/code/ColladaExporter.cpp +++ b/code/ColladaExporter.cpp @@ -115,21 +115,11 @@ void ColladaExporter::WriteFile() mOutput << "" << endstr; } -// ------------------------------------------------------------------------------------------------ -// Utility function to test equality of scalars and quaternions -inline bool equal(double a, double b, double epsilon) { - return std::abs(a - b) <= epsilon; -} - -inline bool equal(aiQuaternion a, aiQuaternion b, double epsilon) { - return equal(a.x, b.x, epsilon) && equal(a.y, b.y, epsilon) && equal(a.z, b.z, epsilon) && equal(a.w, b.w, epsilon); -} - // ------------------------------------------------------------------------------------------------ // Writes the asset header void ColladaExporter::WriteHeader() { - static const double epsilon = 0.000001; + static const float epsilon = 0.000001f; static const aiQuaternion x_rot(aiMatrix3x3( 0, -1, 0, 1, 0, 0, @@ -156,18 +146,18 @@ void ColladaExporter::WriteHeader() mScene->mRootNode->mTransformation.Decompose(scaling, rotation, position); float scale = 1.0; - if(equal(scaling.x, scaling.y, epsilon) && equal(scaling.x, scaling.z, epsilon) && equal(scaling.y, scaling.z, epsilon)) { + if(std::abs(scaling.x - scaling.y) <= epsilon && std::abs(scaling.x - scaling.z) <= epsilon && std::abs(scaling.y - scaling.z) <= epsilon) { scale = scaling.x; } else { DefaultLogger::get()->warn("Collada: Unable to compute the global scale of the scene " + scene_name); } std::string up_axis = "Y_UP"; - if(equal(rotation, x_rot, epsilon)) { + if(rotation.Equal(x_rot, epsilon)) { up_axis = "X_UP"; - } else if(equal(rotation, y_rot, epsilon)) { + } else if(rotation.Equal(y_rot, epsilon)) { up_axis = "Y_UP"; - } else if(equal(rotation, z_rot, epsilon)) { + } else if(rotation.Equal(z_rot, epsilon)) { up_axis = "Z_UP"; } else { DefaultLogger::get()->warn("Collada: Unable to compute the up axis of the scene " + scene_name); diff --git a/include/assimp/matrix3x3.h b/include/assimp/matrix3x3.h index 029284111..962ae7249 100644 --- a/include/assimp/matrix3x3.h +++ b/include/assimp/matrix3x3.h @@ -90,8 +90,10 @@ public: const TReal* operator[] (unsigned int p_iIndex) const; // comparison operators - bool operator== (const aiMatrix4x4t m) const; - bool operator!= (const aiMatrix4x4t m) const; + bool operator== (const aiMatrix4x4t& m) const; + bool operator!= (const aiMatrix4x4t& m) const; + + bool Equal(const aiMatrix4x4t& m, float epsilon = 1e-6) const; template operator aiMatrix3x3t () const; diff --git a/include/assimp/matrix3x3.inl b/include/assimp/matrix3x3.inl index f47d2b78d..bbf3fdc94 100644 --- a/include/assimp/matrix3x3.inl +++ b/include/assimp/matrix3x3.inl @@ -113,7 +113,7 @@ inline const TReal* aiMatrix3x3t::operator[] (unsigned int p_iIndex) cons // ------------------------------------------------------------------------------------------------ template -inline bool aiMatrix3x3t::operator== (const aiMatrix4x4t m) const +inline bool aiMatrix3x3t::operator== (const aiMatrix4x4t& m) const { return a1 == m.a1 && a2 == m.a2 && a3 == m.a3 && b1 == m.b1 && b2 == m.b2 && b3 == m.b3 && @@ -122,11 +122,26 @@ inline bool aiMatrix3x3t::operator== (const aiMatrix4x4t m) const // ------------------------------------------------------------------------------------------------ template -inline bool aiMatrix3x3t::operator!= (const aiMatrix4x4t m) const +inline bool aiMatrix3x3t::operator!= (const aiMatrix4x4t& m) const { return !(*this == m); } +// --------------------------------------------------------------------------- +template +inline bool aiMatrix3x3t::Equal(const aiMatrix4x4t& m, float epsilon) const { + return + std::abs(a1 - m.a1) <= epsilon && + std::abs(a2 - m.a2) <= epsilon && + std::abs(a3 - m.a3) <= epsilon && + std::abs(b1 - m.b1) <= epsilon && + std::abs(b2 - m.b2) <= epsilon && + std::abs(b3 - m.b3) <= epsilon && + std::abs(c1 - m.c1) <= epsilon && + std::abs(c2 - m.c2) <= epsilon && + std::abs(c3 - m.c3) <= epsilon; +} + // ------------------------------------------------------------------------------------------------ template inline aiMatrix3x3t& aiMatrix3x3t::Transpose() diff --git a/include/assimp/matrix4x4.h b/include/assimp/matrix4x4.h index 020921430..f9cc422af 100644 --- a/include/assimp/matrix4x4.h +++ b/include/assimp/matrix4x4.h @@ -94,8 +94,10 @@ public: const TReal* operator[] (unsigned int p_iIndex) const; // comparison operators - bool operator== (const aiMatrix4x4t m) const; - bool operator!= (const aiMatrix4x4t m) const; + bool operator== (const aiMatrix4x4t& m) const; + bool operator!= (const aiMatrix4x4t& m) const; + + bool Equal(const aiMatrix4x4t& m, float epsilon = 1e-6) const; // matrix multiplication. aiMatrix4x4t& operator *= (const aiMatrix4x4t& m); diff --git a/include/assimp/matrix4x4.inl b/include/assimp/matrix4x4.inl index d7c8227d4..b5f048786 100644 --- a/include/assimp/matrix4x4.inl +++ b/include/assimp/matrix4x4.inl @@ -254,7 +254,7 @@ inline const TReal* aiMatrix4x4t::operator[](unsigned int p_iIndex) const // ---------------------------------------------------------------------------------------- template -inline bool aiMatrix4x4t::operator== (const aiMatrix4x4t m) const +inline bool aiMatrix4x4t::operator== (const aiMatrix4x4t& 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 && @@ -264,11 +264,33 @@ inline bool aiMatrix4x4t::operator== (const aiMatrix4x4t m) const // ---------------------------------------------------------------------------------------- template -inline bool aiMatrix4x4t::operator!= (const aiMatrix4x4t m) const +inline bool aiMatrix4x4t::operator!= (const aiMatrix4x4t& m) const { return !(*this == m); } +// --------------------------------------------------------------------------- +template +inline bool aiMatrix4x4t::Equal(const aiMatrix4x4t& m, float epsilon) const { + return + std::abs(a1 - m.a1) <= epsilon && + std::abs(a2 - m.a2) <= epsilon && + std::abs(a3 - m.a3) <= epsilon && + std::abs(a4 - m.a4) <= epsilon && + std::abs(b1 - m.b1) <= epsilon && + std::abs(b2 - m.b2) <= epsilon && + std::abs(b3 - m.b3) <= epsilon && + std::abs(b4 - m.b4) <= epsilon && + std::abs(c1 - m.c1) <= epsilon && + std::abs(c2 - m.c2) <= epsilon && + std::abs(c3 - m.c3) <= epsilon && + std::abs(c4 - m.c4) <= epsilon && + std::abs(d1 - m.d1) <= epsilon && + std::abs(d2 - m.d2) <= epsilon && + std::abs(d3 - m.d3) <= epsilon && + std::abs(d4 - m.d4) <= epsilon; +} + // ---------------------------------------------------------------------------------------- template inline void aiMatrix4x4t::Decompose (aiVector3t& scaling, aiQuaterniont& rotation, diff --git a/include/assimp/quaternion.h b/include/assimp/quaternion.h index 112d5766d..f6846d49e 100644 --- a/include/assimp/quaternion.h +++ b/include/assimp/quaternion.h @@ -79,6 +79,8 @@ public: bool operator== (const aiQuaterniont& o) const; bool operator!= (const aiQuaterniont& o) const; + bool Equal(const aiQuaterniont& o, float epsilon = 1e-6) const; + public: /** Normalize the quaternion */ diff --git a/include/assimp/quaternion.inl b/include/assimp/quaternion.inl index 9113848b8..9a5a4e63f 100644 --- a/include/assimp/quaternion.inl +++ b/include/assimp/quaternion.inl @@ -62,7 +62,15 @@ bool aiQuaterniont::operator!= (const aiQuaterniont& o) const return !(*this == o); } - +// --------------------------------------------------------------------------- +template +inline bool aiQuaterniont::Equal(const aiQuaterniont& o, float epsilon) const { + return + std::abs(x - o.x) <= epsilon && + std::abs(y - o.y) <= epsilon && + std::abs(z - o.z) <= epsilon && + std::abs(w - o.w) <= epsilon; +} // --------------------------------------------------------------------------- // Constructs a quaternion from a rotation matrix diff --git a/include/assimp/vector2.h b/include/assimp/vector2.h index 46165ad54..af50e766c 100644 --- a/include/assimp/vector2.h +++ b/include/assimp/vector2.h @@ -83,6 +83,8 @@ public: bool operator== (const aiVector2t& other) const; bool operator!= (const aiVector2t& other) const; + bool Equal(const aiVector2t& other, float epsilon = 1e-6) const; + aiVector2t& operator= (TReal f); const aiVector2t SymMul(const aiVector2t& o); diff --git a/include/assimp/vector2.inl b/include/assimp/vector2.inl index 04d11c56c..d6025e4cd 100644 --- a/include/assimp/vector2.inl +++ b/include/assimp/vector2.inl @@ -131,6 +131,14 @@ bool aiVector2t::operator!= (const aiVector2t& other) const { return x != other.x || y != other.y; } +// --------------------------------------------------------------------------- +template +bool aiVector2t::Equal(const aiVector2t& other, float epsilon) const { + return + std::abs(x - other.x) <= epsilon && + std::abs(y - other.y) <= epsilon; +} + // ------------------------------------------------------------------------------------------------ template aiVector2t& aiVector2t::operator= (TReal f) { diff --git a/include/assimp/vector3.h b/include/assimp/vector3.h index cbdee264d..4f340a66e 100644 --- a/include/assimp/vector3.h +++ b/include/assimp/vector3.h @@ -86,6 +86,8 @@ public: bool operator== (const aiVector3t& other) const; bool operator!= (const aiVector3t& other) const; + bool Equal(const aiVector3t& other, float epsilon = 1e-6) const; + template operator aiVector3t () const; diff --git a/include/assimp/vector3.inl b/include/assimp/vector3.inl index c03437980..159a0b8a9 100644 --- a/include/assimp/vector3.inl +++ b/include/assimp/vector3.inl @@ -147,6 +147,14 @@ template AI_FORCE_INLINE bool aiVector3t::operator!= (const aiVector3t& other) const { return x != other.x || y != other.y || z != other.z; } +// --------------------------------------------------------------------------- +template +AI_FORCE_INLINE bool aiVector3t::Equal(const aiVector3t& other, float epsilon) const { + return + std::abs(x - other.x) <= epsilon && + std::abs(y - other.y) <= epsilon && + std::abs(z - other.z) <= epsilon; +} // ------------------------------------------------------------------------------------------------ template AI_FORCE_INLINE const aiVector3t aiVector3t::SymMul(const aiVector3t& o) {