Merge pull request #1032 from ashdnazg/master
use cmath and C++ (std::) versions of math functions
This commit is contained in:
@@ -299,7 +299,7 @@ void WriteDump(const aiScene* scene, IOStream* io, bool shortened) {
|
||||
else if (!shortened){
|
||||
ioprintf(io,"\t\t<Data length=\"%i\"> \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,"<MeshList num=\"%i\">\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<Mesh types=\"%s %s %s %s\" material_index=\"%i\">\n",
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -256,7 +256,7 @@ bool CalcTangentsProcess::ProcessMesh( aiMesh* pMesh, unsigned int meshIndex)
|
||||
}
|
||||
std::vector<unsigned int> verticesFound;
|
||||
|
||||
const float fLimit = cosf(configMaxAngle);
|
||||
const float fLimit = std::cos(configMaxAngle);
|
||||
std::vector<unsigned int> closeVertices;
|
||||
|
||||
// in the second pass we now smooth out all tangents and bitangents at the same local position
|
||||
|
||||
@@ -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
|
||||
@@ -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<int>(floorf(delta / 90.0));
|
||||
const int subSampleCount = static_cast<int>(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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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) <
|
||||
|
||||
@@ -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<LWO::Key>::iterator n = std::find_if((*it).keys.begin(),(*it).keys.end(),
|
||||
std::bind1st(std::greater<double>(),start_time)),m;
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -784,7 +784,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,
|
||||
@@ -805,7 +805,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;
|
||||
|
||||
@@ -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<aiVector3D>& vlist = ((CX3DImporter_NodeElement_Geometry2D*)ne)->Vertices;// just short alias.
|
||||
|
||||
|
||||
@@ -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("<forward> and <up> vectors in <transform> are skewing, ignoring trafo");
|
||||
|
||||
Reference in New Issue
Block a user