From 25cda401c52b47475ab64c30687b08dc398c492c Mon Sep 17 00:00:00 2001 From: Eshed Date: Sat, 15 Oct 2016 03:29:45 +0300 Subject: [PATCH 1/2] use cmath and C++ (std::) versions of functions --- code/AssxmlExporter.cpp | 4 ++-- code/BlenderLoader.cpp | 2 +- code/ColladaLoader.cpp | 8 ++++---- code/FixNormalsStep.cpp | 6 +++--- code/LWOAnimation.cpp | 2 +- code/LWOMaterial.cpp | 2 +- code/SIBImporter.cpp | 4 ++-- code/X3DImporter.cpp | 2 +- code/X3DImporter_Geometry2D.cpp | 2 +- code/XGLLoader.cpp | 2 +- include/assimp/matrix4x4.inl | 18 +++++++++--------- include/assimp/types.h | 1 - 12 files changed, 26 insertions(+), 27 deletions(-) diff --git a/code/AssxmlExporter.cpp b/code/AssxmlExporter.cpp index 5bd174cce..e236df664 100644 --- a/code/AssxmlExporter.cpp +++ b/code/AssxmlExporter.cpp @@ -299,7 +299,7 @@ void WriteDump(const aiScene* scene, IOStream* io, bool shortened) { else if (!shortened){ ioprintf(io,"\t\t \n",tex->mWidth*tex->mHeight*4); - // const unsigned int width = (unsigned int)log10((double)std::max(tex->mHeight,tex->mWidth))+1; + // const unsigned int width = (unsigned int)std::log10((double)std::max(tex->mHeight,tex->mWidth))+1; for (unsigned int y = 0; y < tex->mHeight;++y) { for (unsigned int x = 0; x < tex->mWidth;++x) { aiTexel* tx = tex->pcData + y*tex->mWidth+x; @@ -457,7 +457,7 @@ void WriteDump(const aiScene* scene, IOStream* io, bool shortened) { ioprintf(io,"\n",scene->mNumMeshes); for (unsigned int i = 0; i < scene->mNumMeshes;++i) { aiMesh* mesh = scene->mMeshes[i]; - // const unsigned int width = (unsigned int)log10((double)mesh->mNumVertices)+1; + // const unsigned int width = (unsigned int)std::log10((double)mesh->mNumVertices)+1; // mesh header ioprintf(io,"\t\n", diff --git a/code/BlenderLoader.cpp b/code/BlenderLoader.cpp index 7bf9fde25..68388235f 100644 --- a/code/BlenderLoader.cpp +++ b/code/BlenderLoader.cpp @@ -1143,7 +1143,7 @@ aiCamera* BlenderImporter::ConvertCamera(const Scene& /*in*/, const Object* obj, out->mUp = aiVector3D(0.f, 1.f, 0.f); out->mLookAt = aiVector3D(0.f, 0.f, -1.f); if (cam->sensor_x && cam->lens) { - out->mHorizontalFOV = atan2(cam->sensor_x, 2.f * cam->lens); + out->mHorizontalFOV = std::atan2(cam->sensor_x, 2.f * cam->lens); } out->mClipPlaneNear = cam->clipsta; out->mClipPlaneFar = cam->clipend; diff --git a/code/ColladaLoader.cpp b/code/ColladaLoader.cpp index 04fcfd507..4f463f2ec 100644 --- a/code/ColladaLoader.cpp +++ b/code/ColladaLoader.cpp @@ -420,13 +420,13 @@ void ColladaLoader::BuildCamerasForNode( const ColladaParser& pParser, const Col out->mHorizontalFOV = srcCamera->mHorFov; if (srcCamera->mVerFov != 10e10f && srcCamera->mAspect == 10e10f) { - out->mAspect = tan(AI_DEG_TO_RAD(srcCamera->mHorFov)) / - tan(AI_DEG_TO_RAD(srcCamera->mVerFov)); + out->mAspect = std::tan(AI_DEG_TO_RAD(srcCamera->mHorFov)) / + std::tan(AI_DEG_TO_RAD(srcCamera->mVerFov)); } } else if (srcCamera->mAspect != 10e10f && srcCamera->mVerFov != 10e10f) { - out->mHorizontalFOV = 2.0f * AI_RAD_TO_DEG(atan(srcCamera->mAspect * - tan(AI_DEG_TO_RAD(srcCamera->mVerFov) * 0.5f))); + out->mHorizontalFOV = 2.0f * AI_RAD_TO_DEG(std::atan(srcCamera->mAspect * + std::tan(AI_DEG_TO_RAD(srcCamera->mVerFov) * 0.5f))); } // Collada uses degrees, we use radians diff --git a/code/FixNormalsStep.cpp b/code/FixNormalsStep.cpp index 9249b13e9..0325f8dfb 100644 --- a/code/FixNormalsStep.cpp +++ b/code/FixNormalsStep.cpp @@ -148,9 +148,9 @@ bool FixInfacingNormalsProcess::ProcessMesh( aiMesh* pcMesh, unsigned int index) // Check whether this is a planar surface const float fDelta1_yz = fDelta1_y * fDelta1_z; - if (fDelta1_x < 0.05f * sqrtf( fDelta1_yz ))return false; - if (fDelta1_y < 0.05f * sqrtf( fDelta1_z * fDelta1_x ))return false; - if (fDelta1_z < 0.05f * sqrtf( fDelta1_y * fDelta1_x ))return false; + if (fDelta1_x < 0.05f * std::sqrt( fDelta1_yz ))return false; + if (fDelta1_y < 0.05f * std::sqrt( fDelta1_z * fDelta1_x ))return false; + if (fDelta1_z < 0.05f * std::sqrt( fDelta1_y * fDelta1_x ))return false; // now compare the volumes of the bounding boxes if (std::fabs(fDelta0_x * fDelta0_y * fDelta0_z) < diff --git a/code/LWOAnimation.cpp b/code/LWOAnimation.cpp index 9f23c13b2..f41853dad 100644 --- a/code/LWOAnimation.cpp +++ b/code/LWOAnimation.cpp @@ -160,7 +160,7 @@ void AnimResolver::UpdateAnimRangeSetup() case LWO::PrePostBehaviour_Repeat: case LWO::PrePostBehaviour_Oscillate: { - const double start_time = delta - fmod(my_first-first,delta); + const double start_time = delta - std::fmod(my_first-first,delta); std::vector::iterator n = std::find_if((*it).keys.begin(),(*it).keys.end(), std::bind1st(std::greater(),start_time)),m; diff --git a/code/LWOMaterial.cpp b/code/LWOMaterial.cpp index 494f70033..961b16686 100644 --- a/code/LWOMaterial.cpp +++ b/code/LWOMaterial.cpp @@ -851,7 +851,7 @@ void LWOImporter::LoadLWO2Surface(unsigned int size) case AI_LWO_SMAN: { AI_LWO_VALIDATE_CHUNK_LENGTH(head.length,SMAN,4); - surf.mMaximumSmoothAngle = fabs( GetF4() ); + surf.mMaximumSmoothAngle = std::fabs( GetF4() ); break; } // vertex color channel to be applied to the surface diff --git a/code/SIBImporter.cpp b/code/SIBImporter.cpp index 8dfacc106..75a7ccf8e 100644 --- a/code/SIBImporter.cpp +++ b/code/SIBImporter.cpp @@ -710,8 +710,8 @@ static void ReadLightInfo(aiLight* light, StreamReaderLE* stream) // OpenGL: I = cos(angle)^E // Solving: angle = acos(I^(1/E)) ai_real E = 1.0 / std::max(spotExponent, (ai_real)0.00001); - ai_real inner = acos(pow((ai_real)0.99, E)); - ai_real outer = acos(pow((ai_real)0.01, E)); + ai_real inner = std::acos(std::pow((ai_real)0.99, E)); + ai_real outer = std::acos(std::pow((ai_real)0.01, E)); // Apply the cutoff. outer = std::min(outer, AI_DEG_TO_RAD(spotCutoff)); diff --git a/code/X3DImporter.cpp b/code/X3DImporter.cpp index 024eedb28..a14d87d80 100644 --- a/code/X3DImporter.cpp +++ b/code/X3DImporter.cpp @@ -796,7 +796,7 @@ void X3DImporter::GeometryHelper_Make_Arc2D(const float pStartAngle, const float } // calculate arc angle and check type of arc - float angle_full = fabs(pEndAngle - pStartAngle); + float angle_full = std::fabs(pEndAngle - pStartAngle); if ( ( angle_full > AI_MATH_TWO_PI_F ) || ( angle_full == 0.0f ) ) { angle_full = AI_MATH_TWO_PI_F; diff --git a/code/X3DImporter_Geometry2D.cpp b/code/X3DImporter_Geometry2D.cpp index 453313297..bfa1834ec 100644 --- a/code/X3DImporter_Geometry2D.cpp +++ b/code/X3DImporter_Geometry2D.cpp @@ -157,7 +157,7 @@ void X3DImporter::ParseNode_Geometry2D_ArcClose2D() // create point list of geometry object. GeometryHelper_Make_Arc2D(startAngle, endAngle, radius, 10, ((CX3DImporter_NodeElement_Geometry2D*)ne)->Vertices);///TODO: IME - AI_CONFIG for NumSeg // add chord or two radiuses only if not a circle was defined - if(!((fabs(endAngle - startAngle) >= AI_MATH_TWO_PI_F) || (endAngle == startAngle))) + if(!((std::fabs(endAngle - startAngle) >= AI_MATH_TWO_PI_F) || (endAngle == startAngle))) { std::list& vlist = ((CX3DImporter_NodeElement_Geometry2D*)ne)->Vertices;// just short alias. diff --git a/code/XGLLoader.cpp b/code/XGLLoader.cpp index 2df72849b..30f520097 100644 --- a/code/XGLLoader.cpp +++ b/code/XGLLoader.cpp @@ -501,7 +501,7 @@ aiMatrix4x4 XGLImporter::ReadTrafo() up.Normalize(); right = forward ^ up; - if (fabs(up * forward) > 1e-4) { + if (std::fabs(up * forward) > 1e-4) { // this is definitely wrong - a degenerate coordinate space ruins everything // so subtitute identity transform. LogError(" and vectors in are skewing, ignoring trafo"); diff --git a/include/assimp/matrix4x4.inl b/include/assimp/matrix4x4.inl index 2f579906e..a7977cd2c 100644 --- a/include/assimp/matrix4x4.inl +++ b/include/assimp/matrix4x4.inl @@ -367,21 +367,21 @@ inline void aiMatrix4x4t::Decompose(aiVector3t& pScaling, aiVector // Use a small epsilon to solve floating-point inaccuracies const TReal epsilon = 10e-3f; - pRotation.y = asin(vCols[2].x);// D. Angle around oY. + pRotation.y = std::asin(vCols[2].x);// D. Angle around oY. - TReal C = cos(pRotation.y); + TReal C = std::cos(pRotation.y); - if(fabs(C) > epsilon) + if(std::fabs(C) > epsilon) { // Finding angle around oX. TReal tan_x = vCols[2].z / C;// A TReal tan_y = -vCols[2].y / C;// B - pRotation.x = atan2(tan_y, tan_x); + pRotation.x = std::atan2(tan_y, tan_x); // Finding angle around oZ. tan_x = vCols[0].x / C;// E tan_y = -vCols[1].x / C;// F - pRotation.z = atan2(tan_y, tan_x); + pRotation.z = std::atan2(tan_y, tan_x); } else {// oY is fixed. @@ -391,7 +391,7 @@ inline void aiMatrix4x4t::Decompose(aiVector3t& pScaling, aiVector TReal tan_x = vCols[1].y;// -BDF+AE => E TReal tan_y = vCols[0].y;// BDE+AF => F - pRotation.z = atan2(tan_y, tan_x); + pRotation.z = std::atan2(tan_y, tan_x); } } @@ -407,14 +407,14 @@ aiQuaterniont pRotation; pRotation.Normalize(); TReal angle_cos = pRotation.w; - TReal angle_sin = sqrt(1.0f - angle_cos * angle_cos); + TReal angle_sin = std::sqrt(1.0f - angle_cos * angle_cos); - pRotationAngle = acos(angle_cos) * 2; + pRotationAngle = std::acos(angle_cos) * 2; // Use a small epsilon to solve floating-point inaccuracies const TReal epsilon = 10e-3f; - if(fabs(angle_sin) < epsilon) angle_sin = 1; + if(std::fabs(angle_sin) < epsilon) angle_sin = 1; pRotationAxis.x = pRotation.x / angle_sin; pRotationAxis.y = pRotation.y / angle_sin; diff --git a/include/assimp/types.h b/include/assimp/types.h index 465638675..0b48453c6 100644 --- a/include/assimp/types.h +++ b/include/assimp/types.h @@ -48,7 +48,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // Some runtime headers #include -#include #include #include #include From a84bf869c2e82454bbc498c03df87c98973731d2 Mon Sep 17 00:00:00 2001 From: Eshed Date: Sat, 15 Oct 2016 12:05:57 +0300 Subject: [PATCH 2/2] replace more math.h functions occurences with std:: --- code/CalcTangentsProcess.cpp | 2 +- code/ColladaLoader.cpp | 2 +- code/ComputeUVMappingProcess.cpp | 18 +++++++++--------- code/MD3FileData.h | 4 ++-- code/X3DImporter.cpp | 2 +- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/code/CalcTangentsProcess.cpp b/code/CalcTangentsProcess.cpp index dbba1bed3..c13ffcb24 100644 --- a/code/CalcTangentsProcess.cpp +++ b/code/CalcTangentsProcess.cpp @@ -256,7 +256,7 @@ bool CalcTangentsProcess::ProcessMesh( aiMesh* pMesh, unsigned int meshIndex) } std::vector verticesFound; - const float fLimit = cosf(configMaxAngle); + const float fLimit = std::cos(configMaxAngle); std::vector closeVertices; // in the second pass we now smooth out all tangents and bitangents at the same local position diff --git a/code/ColladaLoader.cpp b/code/ColladaLoader.cpp index 4f463f2ec..681f9965a 100644 --- a/code/ColladaLoader.cpp +++ b/code/ColladaLoader.cpp @@ -1181,7 +1181,7 @@ void ColladaLoader::CreateAnimation( aiScene* pScene, const ColladaParser& pPars const ai_real last_eval_angle = last_key_angle + (cur_key_angle - last_key_angle) * (time - last_key_time) / (cur_key_time - last_key_time); const ai_real delta = std::abs(cur_key_angle - last_eval_angle); if (delta >= 180.0) { - const int subSampleCount = static_cast(floorf(delta / 90.0)); + const int subSampleCount = static_cast(std::floor(delta / 90.0)); if (cur_key_time != time) { const ai_real nextSampleTime = time + (cur_key_time - time) / subSampleCount; nextTime = std::min(nextTime, nextSampleTime); diff --git a/code/ComputeUVMappingProcess.cpp b/code/ComputeUVMappingProcess.cpp index ff5142fc0..b7c1ffc10 100644 --- a/code/ComputeUVMappingProcess.cpp +++ b/code/ComputeUVMappingProcess.cpp @@ -206,7 +206,7 @@ void ComputeUVMappingProcess::ComputeSphereMapping(aiMesh* mesh,const aiVector3D // lon = arctan (y/x) for (unsigned int pnt = 0; pnt < mesh->mNumVertices;++pnt) { const aiVector3D diff = (mesh->mVertices[pnt]-center).Normalize(); - out[pnt] = aiVector3D((atan2 (diff.z, diff.y) + AI_MATH_PI_F ) / AI_MATH_TWO_PI_F, + out[pnt] = aiVector3D((std::atan2(diff.z, diff.y) + AI_MATH_PI_F ) / AI_MATH_TWO_PI_F, (std::asin (diff.x) + AI_MATH_HALF_PI_F) / AI_MATH_PI_F, 0.0); } } @@ -214,7 +214,7 @@ void ComputeUVMappingProcess::ComputeSphereMapping(aiMesh* mesh,const aiVector3D // ... just the same again for (unsigned int pnt = 0; pnt < mesh->mNumVertices;++pnt) { const aiVector3D diff = (mesh->mVertices[pnt]-center).Normalize(); - out[pnt] = aiVector3D((atan2 (diff.x, diff.z) + AI_MATH_PI_F ) / AI_MATH_TWO_PI_F, + out[pnt] = aiVector3D((std::atan2(diff.x, diff.z) + AI_MATH_PI_F ) / AI_MATH_TWO_PI_F, (std::asin (diff.y) + AI_MATH_HALF_PI_F) / AI_MATH_PI_F, 0.0); } } @@ -222,7 +222,7 @@ void ComputeUVMappingProcess::ComputeSphereMapping(aiMesh* mesh,const aiVector3D // ... just the same again for (unsigned int pnt = 0; pnt < mesh->mNumVertices;++pnt) { const aiVector3D diff = (mesh->mVertices[pnt]-center).Normalize(); - out[pnt] = aiVector3D((atan2 (diff.y, diff.x) + AI_MATH_PI_F ) / AI_MATH_TWO_PI_F, + out[pnt] = aiVector3D((std::atan2(diff.y, diff.x) + AI_MATH_PI_F ) / AI_MATH_TWO_PI_F, (std::asin (diff.z) + AI_MATH_HALF_PI_F) / AI_MATH_PI_F, 0.0); } } @@ -234,8 +234,8 @@ void ComputeUVMappingProcess::ComputeSphereMapping(aiMesh* mesh,const aiVector3D // again the same, except we're applying a transformation now for (unsigned int pnt = 0; pnt < mesh->mNumVertices;++pnt) { const aiVector3D diff = ((mTrafo*mesh->mVertices[pnt])-center).Normalize(); - out[pnt] = aiVector3D((atan2 (diff.y, diff.x) + AI_MATH_PI_F ) / AI_MATH_TWO_PI_F, - (asin (diff.z) + AI_MATH_HALF_PI_F) / AI_MATH_PI_F, 0.0); + out[pnt] = aiVector3D((std::atan2(diff.y, diff.x) + AI_MATH_PI_F ) / AI_MATH_TWO_PI_F, + (std::asin(diff.z) + AI_MATH_HALF_PI_F) / AI_MATH_PI_F, 0.0); } } @@ -268,7 +268,7 @@ void ComputeUVMappingProcess::ComputeCylinderMapping(aiMesh* mesh,const aiVector aiVector3D& uv = out[pnt]; uv.y = (pos.x - min.x) / diff; - uv.x = (atan2 ( pos.z - center.z, pos.y - center.y) +(ai_real)AI_MATH_PI ) / (ai_real)AI_MATH_TWO_PI; + uv.x = (std::atan2( pos.z - center.z, pos.y - center.y) +(ai_real)AI_MATH_PI ) / (ai_real)AI_MATH_TWO_PI; } } else if (axis * base_axis_y >= angle_epsilon) { @@ -281,7 +281,7 @@ void ComputeUVMappingProcess::ComputeCylinderMapping(aiMesh* mesh,const aiVector aiVector3D& uv = out[pnt]; uv.y = (pos.y - min.y) / diff; - uv.x = (atan2 ( pos.x - center.x, pos.z - center.z) +(ai_real)AI_MATH_PI ) / (ai_real)AI_MATH_TWO_PI; + uv.x = (std::atan2( pos.x - center.x, pos.z - center.z) +(ai_real)AI_MATH_PI ) / (ai_real)AI_MATH_TWO_PI; } } else if (axis * base_axis_z >= angle_epsilon) { @@ -294,7 +294,7 @@ void ComputeUVMappingProcess::ComputeCylinderMapping(aiMesh* mesh,const aiVector aiVector3D& uv = out[pnt]; uv.y = (pos.z - min.z) / diff; - uv.x = (atan2 ( pos.y - center.y, pos.x - center.x) +(ai_real)AI_MATH_PI ) / (ai_real)AI_MATH_TWO_PI; + uv.x = (std::atan2( pos.y - center.y, pos.x - center.x) +(ai_real)AI_MATH_PI ) / (ai_real)AI_MATH_TWO_PI; } } // slower code path in case the mapping axis is not one of the coordinate system axes @@ -310,7 +310,7 @@ void ComputeUVMappingProcess::ComputeCylinderMapping(aiMesh* mesh,const aiVector aiVector3D& uv = out[pnt]; uv.y = (pos.y - min.y) / diff; - uv.x = (atan2 ( pos.x - center.x, pos.z - center.z) +(ai_real)AI_MATH_PI ) / (ai_real)AI_MATH_TWO_PI; + uv.x = (std::atan2( pos.x - center.x, pos.z - center.z) +(ai_real)AI_MATH_PI ) / (ai_real)AI_MATH_TWO_PI; } } diff --git a/code/MD3FileData.h b/code/MD3FileData.h index 51a573959..a8869264a 100644 --- a/code/MD3FileData.h +++ b/code/MD3FileData.h @@ -298,10 +298,10 @@ inline void Vec3NormalToLatLng( const aiVector3D& p_vIn, uint16_t& p_iOut ) { int a, b; - a = int(57.2957795f * ( atan2f( p_vIn[1], p_vIn[0] ) ) * (255.0f / 360.0f )); + a = int(57.2957795f * ( std::atan2( p_vIn[1], p_vIn[0] ) ) * (255.0f / 360.0f )); a &= 0xff; - b = int(57.2957795f * ( acosf( p_vIn[2] ) ) * ( 255.0f / 360.0f )); + b = int(57.2957795f * ( std::acos( p_vIn[2] ) ) * ( 255.0f / 360.0f )); b &= 0xff; ((unsigned char*)&p_iOut)[0] = b; // longitude diff --git a/code/X3DImporter.cpp b/code/X3DImporter.cpp index a14d87d80..0d2d99fed 100644 --- a/code/X3DImporter.cpp +++ b/code/X3DImporter.cpp @@ -775,7 +775,7 @@ void X3DImporter::XML_ReadNode_GetAttrVal_AsListS(const int pAttrIdx, std::list< aiVector3D X3DImporter::GeometryHelper_Make_Point2D(const float pAngle, const float pRadius) { - return aiVector3D(pRadius * cosf(pAngle), pRadius * sinf(pAngle), 0); + return aiVector3D(pRadius * std::cos(pAngle), pRadius * std::sin(pAngle), 0); } void X3DImporter::GeometryHelper_Make_Arc2D(const float pStartAngle, const float pEndAngle, const float pRadius, size_t pNumSegments,