diff --git a/CMakeLists.txt b/CMakeLists.txt index 28ce09560e9..0e0c5afaeb2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -64,6 +64,9 @@ endif() include(cmake/config.cmake) include(cmake/gamespy.cmake) +if (NOT IS_VS6_BUILD) + include(cmake/gamemath.cmake) +endif() include(cmake/lzhl.cmake) if (IS_VS6_BUILD) diff --git a/Core/CMakeLists.txt b/Core/CMakeLists.txt index 49bd9f6a0b9..a6c8dbae24d 100644 --- a/Core/CMakeLists.txt +++ b/Core/CMakeLists.txt @@ -14,6 +14,7 @@ target_include_directories(corei_libraries_source_wwvegas_wwlib INTERFACE "Libra target_include_directories(corei_main INTERFACE "Main") target_sources(corei_libraries_include PRIVATE + Libraries/Include/Lib/BaseDefines.h Libraries/Include/Lib/BaseType.h Libraries/Include/Lib/BaseTypeCore.h Libraries/Include/Lib/trig.h diff --git a/Core/GameEngine/Include/Common/Diagnostic/SimulationMathCrc.h b/Core/GameEngine/Include/Common/Diagnostic/SimulationMathCrc.h index 031bc2e3f88..530e707e561 100644 --- a/Core/GameEngine/Include/Common/Diagnostic/SimulationMathCrc.h +++ b/Core/GameEngine/Include/Common/Diagnostic/SimulationMathCrc.h @@ -18,8 +18,12 @@ #pragma once +// Flags for diagnostic math benchmarks +#define RUN_MATH_BENCHMARK_REPLAY400_FLAG (0) + class SimulationMathCrc { public: static UnsignedInt calculate(); + static void runBenchmark(int iterations = 10000); }; diff --git a/Core/GameEngine/Include/Common/GameDefines.h b/Core/GameEngine/Include/Common/GameDefines.h index 1bf9f096fcf..47745e15978 100644 --- a/Core/GameEngine/Include/Common/GameDefines.h +++ b/Core/GameEngine/Include/Common/GameDefines.h @@ -83,9 +83,7 @@ #define PRESERVE_RETAIL_SCRIPTED_CAMERA (1) // Retain scripted camera behavior present in retail Generals 1.08 and Zero Hour 1.04 #endif -#ifndef RETAIL_COMPATIBLE_CRC -#define RETAIL_COMPATIBLE_CRC (1) // Game is expected to be CRC compatible with retail Generals 1.08, Zero Hour 1.04 -#endif +// RETAIL_COMPATIBLE_CRC is default defined in BaseDefines.h #ifndef RETAIL_COMPATIBLE_XFER_SAVE #define RETAIL_COMPATIBLE_XFER_SAVE (1) // Game is expected to be Xfer Save compatible with retail Generals 1.08, Zero Hour 1.04 diff --git a/Core/GameEngine/Source/Common/Diagnostic/SimulationMathCrc.cpp b/Core/GameEngine/Source/Common/Diagnostic/SimulationMathCrc.cpp index 1b062f44e34..8c23e9e63ec 100644 --- a/Core/GameEngine/Source/Common/Diagnostic/SimulationMathCrc.cpp +++ b/Core/GameEngine/Source/Common/Diagnostic/SimulationMathCrc.cpp @@ -25,8 +25,10 @@ #include "GameLogic/FPUControl.h" #include +#include +#include -static void appendSimulationMathCrc(XferCRC &xfer) +static void appendSimulationMathCrc_Deterministic(XferCRC &xfer) { Matrix3D matrix; Matrix3D factorsMatrix; @@ -37,18 +39,48 @@ static void appendSimulationMathCrc(XferCRC &xfer) 0.9f, 1.0f, 2.1f, 1.2f); factorsMatrix.Set( - WWMath::Sin(0.7f) * log10f(2.3f), - WWMath::Cos(1.1f) * powf(1.1f, 2.0f), - tanf(0.3f), - asinf(0.967302263f), - acosf(0.967302263f), - atanf(0.967302263f) * powf(1.1f, 2.0f), - atan2f(0.4f, 1.3f), - sinhf(0.2f), - coshf(0.4f) * tanhf(0.5f), - sqrtf(55788.84375f), - expf(0.1f) * log10f(2.3f), - logf(1.4f)); + WWMath::Sinf(0.7f) * WWMath::Log10f(2.3f), + WWMath::Cosf(1.1f) * WWMath::Powf(1.1f, 2.0f), + WWMath::Tanf(0.3f), + WWMath::Asinf(0.967302263f), + WWMath::Acosf(0.967302263f), + WWMath::Atanf(0.967302263f) * WWMath::Powf(1.1f, 2.0f), + WWMath::Atan2f(0.4f, 1.3f), + WWMath::Sinhf(0.2f), + WWMath::Coshf(0.4f) * WWMath::Tanhf(0.5f), + WWMath::Sqrtf(55788.84375f), + WWMath::Expf(0.1f) * WWMath::Log10f(2.3f), + WWMath::Logf(1.4f)); + + Matrix3D::Multiply(matrix, factorsMatrix, &matrix); + matrix.Get_Inverse(matrix); + + xfer.xferMatrix3D(&matrix); +} + +static void appendSimulationMathCrc_Native(XferCRC &xfer) +{ + Matrix3D matrix; + Matrix3D factorsMatrix; + + matrix.Set( + 4.1f, 1.2f, 0.3f, 0.4f, + 0.5f, 3.6f, 0.7f, 0.8f, + 0.9f, 1.0f, 2.1f, 1.2f); + + factorsMatrix.Set( + (float)(::sin(0.7) * ::log10(2.3)), + (float)(::cos(1.1) * ::pow(1.1, 2.0)), + (float)::tan(0.3), + (float)::asin(0.967302263), + (float)::acos(0.967302263), + (float)(::atan(0.967302263) * ::pow(1.1, 2.0)), + (float)::atan2(0.4, 1.3), + (float)::sinh(0.2), + (float)(::cosh(0.4) * ::tanh(0.5)), + (float)::sqrt(55788.84375), + (float)(::exp(0.1) * ::log10(2.3)), + (float)::log(1.4)); Matrix3D::Multiply(matrix, factorsMatrix, &matrix); matrix.Get_Inverse(matrix); @@ -63,7 +95,7 @@ UnsignedInt SimulationMathCrc::calculate() setFPMode(); - appendSimulationMathCrc(xfer); + appendSimulationMathCrc_Deterministic(xfer); _fpreset(); @@ -71,3 +103,48 @@ UnsignedInt SimulationMathCrc::calculate() return xfer.getCRC(); } + +void SimulationMathCrc::runBenchmark(int iterations) +{ + int i; + clock_t startDet = clock(); + UnsignedInt crcDet = 0; + + setFPMode(); + + for (i = 0; i < iterations; ++i) + { + XferCRC xfer; + xfer.open("SimMathDet"); + appendSimulationMathCrc_Deterministic(xfer); + xfer.close(); + if (i == 0) + crcDet = xfer.getCRC(); + } + _fpreset(); + clock_t endDet = clock(); + double timeDetMs = (double)(endDet - startDet) / CLOCKS_PER_SEC * 1000.0; + + clock_t startNat = clock(); + UnsignedInt crcNat = 0; + + setFPMode(); + + for (i = 0; i < iterations; ++i) + { + XferCRC xfer; + xfer.open("SimMathNat"); + appendSimulationMathCrc_Native(xfer); + xfer.close(); + if (i == 0) + crcNat = xfer.getCRC(); + } + _fpreset(); + clock_t endNat = clock(); + double timeNatMs = (double)(endNat - startNat) / CLOCKS_PER_SEC * 1000.0; + + printf("\n================ MATH BENCHMARK (%d iterations) ================\n", iterations); + printf("Deterministic (WWMath): CRC = %08X, Time = %.2f ms\n", crcDet, timeDetMs); + printf("Native (system math): CRC = %08X, Time = %.2f ms\n", crcNat, timeNatMs); + printf("===========================================================\n\n"); +} diff --git a/Core/GameEngine/Source/Common/INI/INI.cpp b/Core/GameEngine/Source/Common/INI/INI.cpp index b3a26a5f4c1..2be6fc3e1c8 100644 --- a/Core/GameEngine/Source/Common/INI/INI.cpp +++ b/Core/GameEngine/Source/Common/INI/INI.cpp @@ -1789,7 +1789,7 @@ void INI::parseDurationReal( INI *ini, void * /*instance*/, void *store, const v void INI::parseDurationUnsignedInt( INI *ini, void * /*instance*/, void *store, const void* /*userData*/ ) { UnsignedInt val = scanUnsignedInt(ini->getNextToken()); - *(UnsignedInt *)store = (UnsignedInt)ceilf(ConvertDurationFromMsecsToFrames((Real)val)); + *(UnsignedInt *)store = (UnsignedInt)WWMath::Ceilf(ConvertDurationFromMsecsToFrames((Real)val)); } // ------------------------------------------------------------------------------------------------ @@ -1797,7 +1797,7 @@ void INI::parseDurationUnsignedInt( INI *ini, void * /*instance*/, void *store, void INI::parseDurationUnsignedShort( INI *ini, void * /*instance*/, void *store, const void* /*userData*/ ) { UnsignedInt val = scanUnsignedInt(ini->getNextToken()); - *(UnsignedShort *)store = (UnsignedShort)ceilf(ConvertDurationFromMsecsToFrames((Real)val)); + *(UnsignedShort *)store = (UnsignedShort)WWMath::Ceilf(ConvertDurationFromMsecsToFrames((Real)val)); } //------------------------------------------------------------------------------------------------- diff --git a/Core/GameEngine/Source/GameClient/MessageStream/LookAtXlat.cpp b/Core/GameEngine/Source/GameClient/MessageStream/LookAtXlat.cpp index b4ef8bfdbbb..9bc70024463 100644 --- a/Core/GameEngine/Source/GameClient/MessageStream/LookAtXlat.cpp +++ b/Core/GameEngine/Source/GameClient/MessageStream/LookAtXlat.cpp @@ -374,7 +374,7 @@ GameMessageDisposition LookAtTranslator::translateGameMessage(const GameMessage if (TheInGameUI->isInForceAttackMode()) { const Real snapRadians = DEG_TO_RADF(45); - targetAngle = WWMath::Round(targetAngle / snapRadians) * snapRadians; + targetAngle = WWMath::Roundf(targetAngle / snapRadians) * snapRadians; } TheTacticalView->userSetAngle(targetAngle); diff --git a/Core/GameEngine/Source/GameLogic/AI/AIPathfind.cpp b/Core/GameEngine/Source/GameLogic/AI/AIPathfind.cpp index 0614563bd43..6c8ccf871a8 100644 --- a/Core/GameEngine/Source/GameLogic/AI/AIPathfind.cpp +++ b/Core/GameEngine/Source/GameLogic/AI/AIPathfind.cpp @@ -727,9 +727,9 @@ inline Bool isReallyClose(const Coord3D& a, const Coord3D& b) { const Real CLOSE_ENOUGH = 0.1f; return - fabs(a.x-b.x) <= CLOSE_ENOUGH && - fabs(a.y-b.y) <= CLOSE_ENOUGH && - fabs(a.z-b.z) <= CLOSE_ENOUGH; + WWMath::Fabs(a.x-b.x) <= CLOSE_ENOUGH && + WWMath::Fabs(a.y-b.y) <= CLOSE_ENOUGH && + WWMath::Fabs(a.z-b.z) <= CLOSE_ENOUGH; } /** @@ -921,7 +921,7 @@ void Path::computePointOnPath( // compute distance of point from this path segment Real toDistSqr = sqr(toPos.x) + sqr(toPos.y); Real offsetDistSq = toDistSqr - sqr(alongPathDist); - Real offsetDist = (offsetDistSq <= 0.0) ? 0.0 : sqrt(offsetDistSq); + Real offsetDist = (offsetDistSq <= 0.0) ? 0.0 : WWMath::Sqrt(offsetDistSq); // If we are basically on the path, return the next path node as the movement goal. // However, the farther off the path we get, the movement goal becomes closer to our @@ -1011,8 +1011,8 @@ void Path::computePointOnPath( out.posOnPath.x = closeNodePos->x + alongPathDist * segmentDirNorm.x; out.posOnPath.y = closeNodePos->y + alongPathDist * segmentDirNorm.y; out.posOnPath.z = closeNodePos->z; - Real dx = fabs(pos.x - out.posOnPath.x); - Real dy = fabs(pos.y - out.posOnPath.y); + Real dx = WWMath::Fabs(pos.x - out.posOnPath.x); + Real dy = WWMath::Fabs(pos.y - out.posOnPath.y); if (dx<1 && dy<1 && closeNode->getNextOptimized() && closeNode->getNextOptimized()->getNextOptimized()) { out.posOnPath = *closeNode->getNextOptimized()->getNextOptimized()->getPosition(); } @@ -2070,7 +2070,7 @@ UnsignedInt PathfindCell::costToGoal( PathfindCell *goal ) Int dy = m_info->m_pos.y - goal->getYIndex(); #define NO_REAL_DIST #ifdef REAL_DIST - Int cost = COST_ORTHOGONAL*sqrt(dx*dx + dy*dy); + Int cost = COST_ORTHOGONAL*WWMath::Sqrt(dx*dx + dy*dy); #else if (dx<0) dx = -dx; if (dy<0) dy = -dy; @@ -2096,7 +2096,7 @@ UnsignedInt PathfindCell::costToHierGoal( PathfindCell *goal ) } Int dx = m_info->m_pos.x - goal->getXIndex(); Int dy = m_info->m_pos.y - goal->getYIndex(); - Int cost = REAL_TO_INT_FLOOR(COST_ORTHOGONAL*sqrt(dx*dx + dy*dy) + 0.5f); + Int cost = REAL_TO_INT_FLOOR(COST_ORTHOGONAL*WWMath::Sqrt(dx*dx + dy*dy) + 0.5f); return cost; } @@ -3963,8 +3963,8 @@ Bool PathfindLayer::isPointOnWall(ObjectID *wallPieces, Int numPieces, const Coo Real pty = pt->y - obj->getPosition()->y; // inverse-rotate it to the right coord system - Real ptx_new = (Real)fabs(ptx*c - pty*s); - Real pty_new = (Real)fabs(ptx*s + pty*c); + Real ptx_new = (Real)WWMath::Fabs(ptx*c - pty*s); + Real pty_new = (Real)WWMath::Fabs(ptx*s + pty*c); if (ptx_new <= major && pty_new <= minor) { @@ -6419,7 +6419,7 @@ Int Pathfinder::examineNeighboringCells(PathfindCell *parentCell, PathfindCell * toPos.y = newCellCoord.y * PATHFIND_CELL_SIZE_F ; toPos.z = TheTerrainLogic->getGroundHeight(toPos.x , toPos.y); - if ( fabs(fromPos.z - toPos.z)getPinched()) { @@ -6444,7 +6444,7 @@ Int Pathfinder::examineNeighboringCells(PathfindCell *parentCell, PathfindCell * } else { dx = newCellCoord.x - goalCell->getXIndex(); dy = newCellCoord.y - goalCell->getYIndex(); - costRemaining = COST_ORTHOGONAL*sqrt(dx*dx + dy*dy); + costRemaining = COST_ORTHOGONAL*WWMath::Sqrt(dx*dx + dy*dy); costRemaining -= attackDistance/2; if (costRemaining<0) costRemaining=0; @@ -6768,7 +6768,7 @@ Path *Pathfinder::internalFindPath( Object *obj, const LocomotorSet& locomotorSe dx = from->x - to->x; dy = from->y - to->y; - Int count = sqrt(dx*dx+dy*dy)/(PATHFIND_CELL_SIZE_F/2); + Int count = WWMath::Sqrt(dx*dx+dy*dy)/(PATHFIND_CELL_SIZE_F/2); if (count<2) count = 2; Int i; color.green = 0; @@ -7459,7 +7459,7 @@ Path *Pathfinder::findGroundPath( const Coord3D *from, dx = from->x - to->x; dy = from->y - to->y; - Int count = sqrt(dx*dx+dy*dy)/(PATHFIND_CELL_SIZE_F/2); + Int count = WWMath::Sqrt(dx*dx+dy*dy)/(PATHFIND_CELL_SIZE_F/2); if (count<2) count = 2; Int i; color.green = 0; @@ -8163,7 +8163,7 @@ Path *Pathfinder::internal_findHierarchicalPath( Bool isHuman, const LocomotorSu dx = from->x - to->x; dy = from->y - to->y; - Int count = sqrt(dx*dx+dy*dy)/(PATHFIND_CELL_SIZE_F/2); + Int count = WWMath::Sqrt(dx*dx+dy*dy)/(PATHFIND_CELL_SIZE_F/2); if (count<2) count = 2; Int i; color.green = 0; @@ -11216,7 +11216,7 @@ Path *Pathfinder::findSafePath( const Object *obj, const LocomotorSet& locomotor farthestDistanceSqr = distSqr; if (cellCount > MAX_CELLS) { #ifdef INTENSE_DEBUG - DEBUG_LOG(("Took intermediate path, dist %f, goal dist %f", sqrt(farthestDistanceSqr), repulsorRadius)); + DEBUG_LOG(("Took intermediate path, dist %f, goal dist %f", WWMath::Sqrt(farthestDistanceSqr), repulsorRadius)); #endif ok = true; // Already a big search, just take this one. } diff --git a/Core/GameEngineDevice/Source/W3DDevice/GameClient/BaseHeightMap.cpp b/Core/GameEngineDevice/Source/W3DDevice/GameClient/BaseHeightMap.cpp index 95f41b57f24..3fc3a3c96f1 100644 --- a/Core/GameEngineDevice/Source/W3DDevice/GameClient/BaseHeightMap.cpp +++ b/Core/GameEngineDevice/Source/W3DDevice/GameClient/BaseHeightMap.cpp @@ -1713,7 +1713,7 @@ void BaseHeightMapRenderObjClass::updateViewImpassableAreas(Bool partial, Int mi } // save calculating the tangent over and over again. - Real tanImpassableRad = tan(m_curImpassableSlope / 360.f * 2 * PI); + Real tanImpassableRad = WWMath::Tan(m_curImpassableSlope / 360.f * 2 * PI); for (Int j = minY; j < maxY; ++j) { for (Int i = minX; i < maxX; ++i) { m_showAsVisibleCliff[i + j * xSize] = evaluateAsVisibleCliff(i, j, tanImpassableRad); diff --git a/Core/GameEngineDevice/Source/W3DDevice/GameClient/CameraShakeSystem.cpp b/Core/GameEngineDevice/Source/W3DDevice/GameClient/CameraShakeSystem.cpp index 4d17d6eb417..486ba6e8ca5 100644 --- a/Core/GameEngineDevice/Source/W3DDevice/GameClient/CameraShakeSystem.cpp +++ b/Core/GameEngineDevice/Source/W3DDevice/GameClient/CameraShakeSystem.cpp @@ -160,10 +160,10 @@ void CameraShakeSystemClass::CameraShakerClass::Compute_Rotations(const Vector3 ** omega(t) = start_omega + (end_omega - start_omega) * t ** phi = random(0..start_omega) */ - float intensity = Intensity * (1.0f - WWMath::Sqrt(len2) / Radius) * (1.0f - ElapsedTime / Duration); + float intensity = Intensity * (1.0f - WWMath::Sqrt_Legacy(len2) / Radius) * (1.0f - ElapsedTime / Duration); for (int i=0; i<3; i++) { float omega = Omega[i] + (END_OMEGA - Omega[i]) * ElapsedTime; - (*set_angles)[i] += AXIS_ROTATION[i] * intensity * WWMath::Sin(omega * ElapsedTime + Phi[i]); + (*set_angles)[i] += AXIS_ROTATION[i] * intensity * WWMath::Sinf_Legacy(omega * ElapsedTime + Phi[i]); //WST 11/14/2002. Add in additional random fudge. There seems to be a too mathematical pattern of shake with the above Vector3 secondary_angles; diff --git a/Core/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DTankDraw.cpp b/Core/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DTankDraw.cpp index a00746a0fb9..e900c30e4b9 100644 --- a/Core/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DTankDraw.cpp +++ b/Core/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DTankDraw.cpp @@ -224,7 +224,7 @@ void W3DTankDraw::updateTreadPositions(Real uvDelta) } // ensure coordinates of offset are in [0, 1] range: - offset_u = offset_u - WWMath::Floor(offset_u); + offset_u = offset_u - WWMath::Floorf(offset_u); pTread->m_materialSettings.customUVOffset.Set(offset_u,0); pTread++; } @@ -398,7 +398,7 @@ void W3DTankDraw::doDrawModule(const Matrix3D* transformMtx) { offset_u = pTread->m_materialSettings.customUVOffset.X - treadScrollSpeed; // ensure coordinates of offset are in [0, 1] range: - offset_u = offset_u - WWMath::Floor(offset_u); + offset_u = offset_u - WWMath::Floorf(offset_u); pTread->m_materialSettings.customUVOffset.Set(offset_u,0); pTread++; } diff --git a/Core/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DTankTruckDraw.cpp b/Core/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DTankTruckDraw.cpp index 8d936948ed6..07f288a72a6 100644 --- a/Core/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DTankTruckDraw.cpp +++ b/Core/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DTankTruckDraw.cpp @@ -403,7 +403,7 @@ void W3DTankTruckDraw::updateTreadPositions(Real uvDelta) } // ensure coordinates of offset are in [0, 1] range: - offset_u = offset_u - WWMath::Floor(offset_u); + offset_u = offset_u - WWMath::Floorf(offset_u); pTread->m_materialSettings.customUVOffset.Set(offset_u,0); pTread++; } @@ -720,7 +720,7 @@ void W3DTankTruckDraw::doDrawModule(const Matrix3D* transformMtx) { offset_u = pTread->m_materialSettings.customUVOffset.X - treadScrollSpeed; // ensure coordinates of offset are in [0, 1] range: - offset_u = offset_u - WWMath::Floor(offset_u); + offset_u = offset_u - WWMath::Floorf(offset_u); pTread->m_materialSettings.customUVOffset.Set(offset_u,0); pTread++; } diff --git a/Core/GameEngineDevice/Source/W3DDevice/GameClient/HeightMap.cpp b/Core/GameEngineDevice/Source/W3DDevice/GameClient/HeightMap.cpp index 0789177cf81..2c209178520 100644 --- a/Core/GameEngineDevice/Source/W3DDevice/GameClient/HeightMap.cpp +++ b/Core/GameEngineDevice/Source/W3DDevice/GameClient/HeightMap.cpp @@ -1786,8 +1786,8 @@ void HeightMapRenderObjClass::updateCenter(CameraClass *camera, const Vector3 *c shiftPivot.X = viewDir.X * magicEdgeLenScale; shiftPivot.Y = viewDir.Y * magicEdgeLenScale; - newOrgX = WWMath::Round((cameraPivot->X + shiftPivot.X)/MAP_XY_FACTOR) - m_x/2 + m_map->getBorderSizeInline(); - newOrgY = WWMath::Round((cameraPivot->Y + shiftPivot.Y)/MAP_XY_FACTOR) - m_y/2 + m_map->getBorderSizeInline(); + newOrgX = WWMath::Roundf((cameraPivot->X + shiftPivot.X)/MAP_XY_FACTOR) - m_x/2 + m_map->getBorderSizeInline(); + newOrgY = WWMath::Roundf((cameraPivot->Y + shiftPivot.Y)/MAP_XY_FACTOR) - m_y/2 + m_map->getBorderSizeInline(); } WorldHeightMap::DrawArea newDrawArea = m_map->createDrawArea(newOrgX, newOrgY); diff --git a/Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DMouse.cpp b/Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DMouse.cpp index a3427a2cc2f..8ec14689726 100644 --- a/Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DMouse.cpp +++ b/Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DMouse.cpp @@ -568,7 +568,7 @@ void W3DMouse::draw() offset = TheInGameUI->getScrollAmount(); offset.normalize(); Real theta = atan2(-offset.y, offset.x); - theta -= (Real)M_PI/2; + theta -= (Real)WWMATH_HALF_PI; tm.Rotate_Z(theta); } cursorModels[m_currentW3DCursor]->Set_Transform(tm); @@ -672,12 +672,12 @@ void W3DMouse::setCursorDirection(MouseCursor cursor) { offset.normalize(); Real theta = atan2(offset.y, offset.x); - theta = fmod(theta+M_PI*2,M_PI*2); + theta = fmod(theta+WWMATH_TWO_PI,WWMATH_TWO_PI); Int numDirections=m_cursorInfo[m_currentCursor].numDirections; //Figure out which of our predrawn cursor orientations best matches the //actual cursor direction. Frame 0 is assumed to point right and continue //clockwise. - m_directionFrame=(Int)(theta/(2.0f*M_PI/(Real)numDirections)+0.5f); + m_directionFrame=(Int)(theta/(WWMATH_TWO_PI/(Real)numDirections)+0.5f); if (m_directionFrame >= numDirections) m_directionFrame = 0; } diff --git a/Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DProfilerFrameCapture.cpp b/Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DProfilerFrameCapture.cpp index 90a8d931982..2f5071c37ee 100644 --- a/Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DProfilerFrameCapture.cpp +++ b/Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DProfilerFrameCapture.cpp @@ -95,7 +95,7 @@ void W3DProfilerFrameCapture::Capture(UnsignedInt displayWidth, UnsignedInt disp // allocate surface class const Real aspectRatio = (Real)displayHeight / (Real)displayWidth; - unsigned int profilerImageHeight = min((int)WWMath::Round(PROFILER_FRAME_IMAGE_SIZE * aspectRatio), PROFILER_FRAME_IMAGE_SIZE); + unsigned int profilerImageHeight = min((int)WWMath::Roundf(PROFILER_FRAME_IMAGE_SIZE * aspectRatio), PROFILER_FRAME_IMAGE_SIZE); SurfaceClass *surfaceClass = NEW_REF(SurfaceClass, (PROFILER_FRAME_IMAGE_SIZE, profilerImageHeight, WW3D_FORMAT_A8R8G8B8)); if (!surfaceClass) { diff --git a/Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DTreeBuffer.cpp b/Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DTreeBuffer.cpp index e8f4bcfbfef..d1aaef4e8cf 100644 --- a/Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DTreeBuffer.cpp +++ b/Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DTreeBuffer.cpp @@ -1417,8 +1417,8 @@ void W3DTreeBuffer::addTree(DrawableID id, Coord3D location, Real scale, Real an } Real randomScale = GameClientRandomValueReal( 1.0f - randomScaleAmount, 1.0f+ randomScaleAmount ); - m_trees[m_numTrees].sin = WWMath::Sin(angle); - m_trees[m_numTrees].cos = WWMath::Cos(angle); + m_trees[m_numTrees].sin = WWMath::Sinf_Legacy(angle); + m_trees[m_numTrees].cos = WWMath::Cosf_Legacy(angle); if (randomScaleAmount>0.0f) { // Randomizes the scale and orientation of trees. m_trees[m_numTrees].scale = scale*randomScale; @@ -1462,8 +1462,8 @@ Bool W3DTreeBuffer::updateTreePosition(DrawableID id, Coord3D location, Real ang for (i=0; iisUsingAirborneLocomotor() && cameraLockObj->isAboveTerrainOrWater()) { Matrix3D camXForm; - Real idealZRot = cameraLockObj->getOrientation() - M_PI_2; + Real idealZRot = cameraLockObj->getOrientation() - WWMATH_HALF_PI; if (m_snapImmediate) { @@ -2235,7 +2235,7 @@ void W3DView::setPitchToDefault() void W3DView::setDefaultView(Real pitch, Real angle, Real maxHeight) { // MDC - we no longer want to rotate maps (design made all of them right to begin with) - // m_defaultAngle = angle * M_PI/180.0f; + // m_defaultAngle = angle * WWMATH_PI/180.0f; setDefaultPitch(pitch); m_maxHeightAboveGround = TheGlobalData->m_maxCameraHeight*maxHeight; if (m_minHeightAboveGround > m_maxHeightAboveGround) @@ -2792,7 +2792,7 @@ void W3DView::rotateCameraTowardPosition(const Coord3D *pLoc, Int milliseconds, Vector2 dir(pLoc->x-curPos.x, pLoc->y-curPos.y); const Real dirLength = dir.Length(); if (dirLength<0.1f) return; - Real angle = WWMath::Acos(dir.X/dirLength); + Real angle = WWMath::Acos_Legacy(dir.X/dirLength); if (dir.Y<0.0f) { angle = -angle; } @@ -2935,7 +2935,7 @@ void W3DView::cameraModLookToward(Coord3D *pLoc) Vector2 dir(pLoc->x-result.x, pLoc->y-result.y); const Real dirLength = dir.Length(); if (dirLength<0.1f) continue; - Real angle = WWMath::Acos(dir.X/dirLength); + Real angle = WWMath::Acos_Legacy(dir.X/dirLength); if (dir.Y<0.0f) { angle = -angle; } @@ -3016,7 +3016,7 @@ void W3DView::cameraModFinalLookToward(Coord3D *pLoc) Vector2 dir(pLoc->x-result.x, pLoc->y-result.y); const Real dirLength = dir.Length(); if (dirLength<0.1f) continue; - Real angle = WWMath::Acos(dir.X/dirLength); + Real angle = WWMath::Acos_Legacy(dir.X/dirLength); if (dir.Y<0.0f) { angle = -angle; } @@ -3197,7 +3197,7 @@ void W3DView::setupWaypointPath(Bool orient) m_mcwpInfo.waySegLength[i] = dirLength; m_mcwpInfo.totalDistance += m_mcwpInfo.waySegLength[i]; if (orient && dirLength >= 0.1f) { - angle = WWMath::Acos(dir.X/dirLength); + angle = WWMath::Acos_Legacy(dir.X/dirLength); if (dir.Y<0.0f) { angle = -angle; } @@ -3273,7 +3273,7 @@ static Real makeQuadraticS(Real t) tPrime = 0.5 * (2*t*2*t); } else { tPrime = (t-0.5)*2; - tPrime = WWMath::Sqrt(tPrime); + tPrime = WWMath::Sqrt_Legacy(tPrime); tPrime = 0.5 + 0.5*(tPrime); } return tPrime*0.5 + t*0.5; @@ -3307,7 +3307,7 @@ void W3DView::rotateCameraOneFrame() const Real dirLength = dir.Length(); if (dirLength>=0.1f) { - Real angle = WWMath::Acos(dir.X/dirLength); + Real angle = WWMath::Acos_Legacy(dir.X/dirLength); if (dir.Y<0.0f) { angle = -angle; } diff --git a/Core/Libraries/Include/Lib/BaseDefines.h b/Core/Libraries/Include/Lib/BaseDefines.h new file mode 100644 index 00000000000..662009d86e8 --- /dev/null +++ b/Core/Libraries/Include/Lib/BaseDefines.h @@ -0,0 +1,37 @@ +/* +** Command & Conquer Generals Zero Hour(tm) +** Copyright 2026 TheSuperHackers +** +** This program is free software: you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation, either version 3 of the License, or +** (at your option) any later version. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program. If not, see . +*/ + +#pragma once + +#ifndef RETAIL_COMPATIBLE_CRC +#define RETAIL_COMPATIBLE_CRC (1) // Game is expected to be CRC compatible with retail Generals 1.08, Zero Hour 1.04 +#endif + +#ifndef USE_DETERMINISTIC_MATH +#define USE_DETERMINISTIC_MATH (1) // Game uses deterministic math for game simulation compatibility among different system architectures in peer to peer networks +#endif + +#if defined(__has_include) +#if __has_include("gmath.h") +#define HAS_GAMEMATH (1) +#endif +#endif + +#if !HAS_GAMEMATH || RETAIL_COMPATIBLE_CRC +#undef USE_DETERMINISTIC_MATH // Cannot actually use deterministic math :( +#endif diff --git a/Core/Libraries/Include/Lib/BaseType.h b/Core/Libraries/Include/Lib/BaseType.h index 8b5e760aff4..2b6e5507219 100644 --- a/Core/Libraries/Include/Lib/BaseType.h +++ b/Core/Libraries/Include/Lib/BaseType.h @@ -29,8 +29,9 @@ #pragma once -#include "Lib/BaseTypeCore.h" -#include "Lib/trig.h" +#include "BaseDefines.h" +#include "BaseTypeCore.h" +#include "trig.h" //----------------------------------------------------------------------------- typedef wchar_t WideChar; ///< multi-byte character representations @@ -224,7 +225,7 @@ __forceinline float fast_float_ceil(float f) #define INT_TO_REAL(x) ((Real)(x)) // once we've ceiled/floored, trunc and round are identical, and currently, round is faster... (srj) -#if RTS_GENERALS /*&& RETAIL_COMPATIBLE_CRC*/ +#if RTS_GENERALS && RETAIL_COMPATIBLE_CRC #define REAL_TO_INT_CEIL(x) (fast_float2long_round(ceilf(x))) #define REAL_TO_INT_FLOOR(x) (fast_float2long_round(floorf(x))) #else @@ -283,7 +284,7 @@ struct Coord2D return x == value && y == value; } - Real length() const { return (Real)sqrt( x*x + y*y ); } + Real length() const { return Sqrt( x*x + y*y ); } Real lengthSqr() const { return x*x + y*y; } void normalize() @@ -355,7 +356,7 @@ inline Real Coord2D::toAngle() const vector.x = x; vector.y = y; - Real dist = (Real)sqrt(vector.x * vector.x + vector.y * vector.y); + Real dist = Sqrt(vector.x * vector.x + vector.y * vector.y); // normalize if (dist == 0.0f) @@ -422,7 +423,7 @@ struct ICoord2D return x == value && y == value; } - Int length() const { return (Int)sqrt( (double)(x*x + y*y) ); } + Int length() const { return (Int)Sqrt( (double)(x*x + y*y) ); } Int lengthSqr() const { return x*x + y*y; } void add( const ICoord2D &a ) @@ -519,7 +520,16 @@ struct Coord3D { Real x, y, z; - Real length() const { return (Real)sqrt( x*x + y*y + z*z ); } + Real length() const + { +#if RETAIL_COMPATIBLE_CRC + // Must not touch this function because it affects its inline-ability + // and therefore changes the logic at an unknown call site that relies on it. It is a bug. + return (Real)sqrt( x*x + y*y + z*z ); +#else + return Sqrt( x*x + y*y + z*z ); +#endif + } Real lengthSqr() const { return ( x*x + y*y + z*z ); } void normalize() @@ -631,7 +641,7 @@ struct ICoord3D { Int x, y, z; - Int length() const { return (Int)sqrt( (double)(x*x + y*y + z*z) ); } + Int length() const { return (Int)Sqrt( (double)(x*x + y*y + z*z) ); } Int lengthSqr() const { return x*x + y*y + z*z; } void zero() diff --git a/Core/Libraries/Include/Lib/trig.h b/Core/Libraries/Include/Lib/trig.h index d6f3fa22cd8..27fa8cb8391 100644 --- a/Core/Libraries/Include/Lib/trig.h +++ b/Core/Libraries/Include/Lib/trig.h @@ -28,3 +28,5 @@ Real Cos(Real); Real Tan(Real); Real ACos(Real); Real ASin(Real x); +Real Sqrt(Real x); +double Sqrt(double x); diff --git a/Core/Libraries/Source/WWVegas/WW3D2/animatedsoundmgr.cpp b/Core/Libraries/Source/WWVegas/WW3D2/animatedsoundmgr.cpp index bf89eb93e77..a1cd0bb7201 100644 --- a/Core/Libraries/Source/WWVegas/WW3D2/animatedsoundmgr.cpp +++ b/Core/Libraries/Source/WWVegas/WW3D2/animatedsoundmgr.cpp @@ -512,7 +512,7 @@ AnimatedSoundMgrClass::Trigger_Sound // // Don't trigger the sound if its skipped too far past... // - //if (WWMath::Fabs (new_frame - old_frame) < 3.0F) { + //if (WWMath::Fabsf (new_frame - old_frame) < 3.0F) { // // Stop the audio? diff --git a/Core/Libraries/Source/WWVegas/WW3D2/colorspace.h b/Core/Libraries/Source/WWVegas/WW3D2/colorspace.h index e4974a00545..c61b297c198 100644 --- a/Core/Libraries/Source/WWVegas/WW3D2/colorspace.h +++ b/Core/Libraries/Source/WWVegas/WW3D2/colorspace.h @@ -95,7 +95,7 @@ inline void HSV_To_RGB(Vector3 &rgb, const Vector3 &hsv) if (h==360.0f) h=0.0f; h/=60.0f; - i=WWMath::Floor(h); + i=WWMath::Floorf(h); f=h-i; p=v*(1.0f-s); q=v*(1.0f-(s*f)); diff --git a/Core/Libraries/Source/WWVegas/WW3D2/coltest.cpp b/Core/Libraries/Source/WWVegas/WW3D2/coltest.cpp index 5639973d50b..71ff8c728fd 100644 --- a/Core/Libraries/Source/WWVegas/WW3D2/coltest.cpp +++ b/Core/Libraries/Source/WWVegas/WW3D2/coltest.cpp @@ -71,7 +71,7 @@ AABoxCollisionTestClass::AABoxCollisionTestClass(const AABoxClass & aabox,const bool AABoxCollisionTestClass::Cull(const AABoxClass & box) { // const float MOVE_THRESHOLD = 2.0f; -// if (WWMath::Fabs(Move.X) + WWMath::Fabs(Move.Y) + WWMath::Fabs(Move.Z) > MOVE_THRESHOLD) { +// if (WWMath::Fabsf(Move.X) + WWMath::Fabsf(Move.Y) + WWMath::Fabsf(Move.Z) > MOVE_THRESHOLD) { // CastResultStruct res; // return !Box.Cast_To_Box(Move,box,&res); // } else { @@ -287,17 +287,17 @@ OBBoxCollisionTestClass::OBBoxCollisionTestClass Move(move) { Vector3 max_extent; - max_extent.X = WWMath::Fabs(Box.Basis[0][0] * Box.Extent.X) + - WWMath::Fabs(Box.Basis[0][1] * Box.Extent.Y) + - WWMath::Fabs(Box.Basis[0][2] * Box.Extent.Z) + 0.01f; + max_extent.X = WWMath::Fabsf_Legacy(Box.Basis[0][0] * Box.Extent.X) + + WWMath::Fabsf_Legacy(Box.Basis[0][1] * Box.Extent.Y) + + WWMath::Fabsf_Legacy(Box.Basis[0][2] * Box.Extent.Z) + 0.01f; - max_extent.Y = WWMath::Fabs(Box.Basis[1][0] * Box.Extent.X) + - WWMath::Fabs(Box.Basis[1][1] * Box.Extent.Y) + - WWMath::Fabs(Box.Basis[1][2] * Box.Extent.Z) + 0.01f; + max_extent.Y = WWMath::Fabsf_Legacy(Box.Basis[1][0] * Box.Extent.X) + + WWMath::Fabsf_Legacy(Box.Basis[1][1] * Box.Extent.Y) + + WWMath::Fabsf_Legacy(Box.Basis[1][2] * Box.Extent.Z) + 0.01f; - max_extent.Z = WWMath::Fabs(Box.Basis[2][0] * Box.Extent.X) + - WWMath::Fabs(Box.Basis[2][1] * Box.Extent.Y) + - WWMath::Fabs(Box.Basis[2][2] * Box.Extent.Z) + 0.01f; + max_extent.Z = WWMath::Fabsf_Legacy(Box.Basis[2][0] * Box.Extent.X) + + WWMath::Fabsf_Legacy(Box.Basis[2][1] * Box.Extent.Y) + + WWMath::Fabsf_Legacy(Box.Basis[2][2] * Box.Extent.Z) + 0.01f; SweepMin = Box.Center - max_extent; SweepMax = Box.Center + max_extent; diff --git a/Core/Libraries/Source/WWVegas/WW3D2/hanim.cpp b/Core/Libraries/Source/WWVegas/WW3D2/hanim.cpp index 89a64a8f369..bb011796d28 100644 --- a/Core/Libraries/Source/WWVegas/WW3D2/hanim.cpp +++ b/Core/Libraries/Source/WWVegas/WW3D2/hanim.cpp @@ -304,7 +304,7 @@ bool HAnimComboClass::Normalize_Weights() } // weight_total should be very close to 1. If not, normalize this pivot's weights - if (weight_total != 0.0 && WWMath::Fabs( weight_total - 1.0 ) > WWMATH_EPSILON) { + if (weight_total != 0.0 && WWMath::Fabsf_Legacy( weight_total - 1.0 ) > WWMATH_EPSILON) { float oo_total = 1.0f / weight_total; for (anim_idx = 0; anim_idx < anim_count; anim_idx++ ) { if (Peek_Motion(anim_idx) != nullptr ) { @@ -329,7 +329,7 @@ bool HAnimComboClass::Normalize_Weights() } // weight_total should be very close to 1. If not, normalize this pivot's weights - if (weight_total != 0.0 && WWMath::Fabs( weight_total - 1.0 ) > WWMATH_EPSILON) { + if (weight_total != 0.0 && WWMath::Fabsf_Legacy( weight_total - 1.0 ) > WWMATH_EPSILON) { float oo_total = 1.0f / weight_total; for (anim_idx = 0; anim_idx < anim_count; anim_idx++ ) { if (Peek_Motion(anim_idx) != nullptr ) { diff --git a/Core/Libraries/Source/WWVegas/WW3D2/htree.cpp b/Core/Libraries/Source/WWVegas/WW3D2/htree.cpp index 15158407861..2824d3a8ba3 100644 --- a/Core/Libraries/Source/WWVegas/WW3D2/htree.cpp +++ b/Core/Libraries/Source/WWVegas/WW3D2/htree.cpp @@ -866,7 +866,7 @@ void HTreeClass::Combo_Update if (weight_total != 0.0f ) { // SKB: Removed assert because I have a case where I don't want normalization. // One anim moves X, the other moves Y. Assert was just in to warn programmers. -// WWASSERT(WWMath::Fabs( weight_total - 1.0 ) < WWMATH_EPSILON); +// WWASSERT(WWMath::Fabsf( weight_total - 1.0 ) < WWMATH_EPSILON); pivot->Transform.Translate(trans); #ifdef ALLOW_TEMPORARIES @@ -1204,8 +1204,8 @@ HTreeClass * HTreeClass::Create_Interpolated(const HTreeClass * tree_base, // Clone the first one, HTreeClass * new_tree = W3DNEW HTreeClass( *tree_base ); - float a_scale_abs = WWMath::Fabs( a_scale ); - float b_scale_abs = WWMath::Fabs( b_scale ); + float a_scale_abs = WWMath::Fabsf_Legacy( a_scale ); + float b_scale_abs = WWMath::Fabsf_Legacy( b_scale ); if ( a_scale_abs + b_scale_abs > 0 ) { diff --git a/Core/Libraries/Source/WWVegas/WW3D2/inttest.h b/Core/Libraries/Source/WWVegas/WW3D2/inttest.h index 11b189f3e73..f6faa971435 100644 --- a/Core/Libraries/Source/WWVegas/WW3D2/inttest.h +++ b/Core/Libraries/Source/WWVegas/WW3D2/inttest.h @@ -127,9 +127,9 @@ inline bool AABoxIntersectionTestClass::Cull(const AABoxClass & cull_box) Vector3::Subtract(cull_box.Center,Box.Center,&dc); Vector3::Add(cull_box.Extent,Box.Extent,&r); - if (WWMath::Fabs(dc.X) > r.X) return true; - if (WWMath::Fabs(dc.Y) > r.Y) return true; - if (WWMath::Fabs(dc.Z) > r.Z) return true; + if (WWMath::Fabsf_Legacy(dc.X) > r.X) return true; + if (WWMath::Fabsf_Legacy(dc.Y) > r.Y) return true; + if (WWMath::Fabsf_Legacy(dc.Z) > r.Z) return true; return false; } @@ -228,9 +228,9 @@ inline bool OBBoxIntersectionTestClass::Cull(const AABoxClass & cull_box) Vector3::Subtract(cull_box.Center,BoundingBox.Center,&dc); Vector3::Add(cull_box.Extent,BoundingBox.Extent,&r); - if (WWMath::Fabs(dc.X) > r.X) return true; - if (WWMath::Fabs(dc.Y) > r.Y) return true; - if (WWMath::Fabs(dc.Z) > r.Z) return true; + if (WWMath::Fabsf_Legacy(dc.X) > r.X) return true; + if (WWMath::Fabsf_Legacy(dc.Y) > r.Y) return true; + if (WWMath::Fabsf_Legacy(dc.Z) > r.Z) return true; return false; } diff --git a/Core/Libraries/Source/WWVegas/WW3D2/metalmap.cpp b/Core/Libraries/Source/WWVegas/WW3D2/metalmap.cpp index 9f917fbe3f4..fe899bde465 100644 --- a/Core/Libraries/Source/WWVegas/WW3D2/metalmap.cpp +++ b/Core/Libraries/Source/WWVegas/WW3D2/metalmap.cpp @@ -316,9 +316,9 @@ void MetalMapManagerClass::Update_Textures() result.Update_Min(white); // Clamp to white unsigned char b,g,r,a; - b= (unsigned char)WWMath::Floor(result.Z * 255.99f); // B - g= (unsigned char)WWMath::Floor(result.Y * 255.99f); // G - r= (unsigned char)WWMath::Floor(result.X * 255.99f); // R + b= (unsigned char)WWMath::Floorf(result.Z * 255.99f); // B + g= (unsigned char)WWMath::Floorf(result.Y * 255.99f); // G + r= (unsigned char)WWMath::Floorf(result.X * 255.99f); // R a= 0xFF; // A if (Use16Bit) { diff --git a/Core/Libraries/Source/WWVegas/WW3D2/ringobj.cpp b/Core/Libraries/Source/WWVegas/WW3D2/ringobj.cpp index 84b80c13a98..7ae35d8737e 100644 --- a/Core/Libraries/Source/WWVegas/WW3D2/ringobj.cpp +++ b/Core/Libraries/Source/WWVegas/WW3D2/ringobj.cpp @@ -1538,8 +1538,8 @@ void RingMeshClass::Generate(float radius, int slices) for (index = 0; index < Vertex_ct; index += 2) { - float x_pos = -WWMath::Sin (angle); - float y_pos = WWMath::Cos (angle); + float x_pos = -WWMath::Sinf_Legacy (angle); + float y_pos = WWMath::Cosf_Legacy (angle); // // Place the inner index diff --git a/Core/Libraries/Source/WWVegas/WW3D2/segline.cpp b/Core/Libraries/Source/WWVegas/WW3D2/segline.cpp index 60c1a12a33c..79a2fc1f253 100644 --- a/Core/Libraries/Source/WWVegas/WW3D2/segline.cpp +++ b/Core/Libraries/Source/WWVegas/WW3D2/segline.cpp @@ -258,7 +258,7 @@ void SegmentedLineClass::Set_Opacity(float opacity) void SegmentedLineClass::Set_Noise_Amplitude(float amplitude) { - LineRenderer.Set_Noise_Amplitude(WWMath::Fabs(amplitude)); + LineRenderer.Set_Noise_Amplitude(WWMath::Fabsf_Legacy(amplitude)); Invalidate_Cached_Bounding_Volumes(); } diff --git a/Core/Libraries/Source/WWVegas/WW3D2/shattersystem.cpp b/Core/Libraries/Source/WWVegas/WW3D2/shattersystem.cpp index c06d1dc1dcf..77a190dbc8e 100644 --- a/Core/Libraries/Source/WWVegas/WW3D2/shattersystem.cpp +++ b/Core/Libraries/Source/WWVegas/WW3D2/shattersystem.cpp @@ -450,7 +450,7 @@ void PolygonClass::Compute_Plane() ay /= (double)NumVerts; az /= (double)NumVerts; - double len = WWMath::Sqrt(nx*nx + ny*ny + nz*nz); + double len = WWMath::Sqrt_Legacy(nx*nx + ny*ny + nz*nz); nx /= len; ny /= len; nz /= len; diff --git a/Core/Libraries/Source/WWVegas/WW3D2/streak.cpp b/Core/Libraries/Source/WWVegas/WW3D2/streak.cpp index 035ea56ff19..aa3992c46b1 100644 --- a/Core/Libraries/Source/WWVegas/WW3D2/streak.cpp +++ b/Core/Libraries/Source/WWVegas/WW3D2/streak.cpp @@ -362,7 +362,7 @@ void StreakLineClass::Set_Opacity(float opacity) void StreakLineClass::Set_Noise_Amplitude(float amplitude) { - LineRenderer.Set_Noise_Amplitude(WWMath::Fabs(amplitude)); + LineRenderer.Set_Noise_Amplitude(WWMath::Fabsf_Legacy(amplitude)); Invalidate_Cached_Bounding_Volumes(); } diff --git a/Core/Libraries/Source/WWVegas/WW3D2/texproject.cpp b/Core/Libraries/Source/WWVegas/WW3D2/texproject.cpp index 59068d97f2d..eba9e40b87a 100644 --- a/Core/Libraries/Source/WWVegas/WW3D2/texproject.cpp +++ b/Core/Libraries/Source/WWVegas/WW3D2/texproject.cpp @@ -940,7 +940,7 @@ bool TexProjectClass::Compute_Perspective_Projection ** If the box is behind the viewpoint or the viewpoint is inside the box ** our FOV will be > 180 degrees. Have to give up */ - if ((box.Center.Z > 0.0f) || (box.Extent.Z > WWMath::Fabs(box.Center.Z))) { + if ((box.Center.Z > 0.0f) || (box.Extent.Z > WWMath::Fabsf_Legacy(box.Center.Z))) { return false; } @@ -958,10 +958,10 @@ bool TexProjectClass::Compute_Perspective_Projection zfar = box.Center.Z + user_zfar; } - float tan_hfov2 = WWMath::Fabs(box.Extent.X / (box.Center.Z + box.Extent.Z)); - float tan_vfov2 = WWMath::Fabs(box.Extent.Y / (box.Center.Z + box.Extent.Z)); - float hfov = 2.0f * WWMath::Atan(tan_hfov2); - float vfov = 2.0f * WWMath::Atan(tan_vfov2); + float tan_hfov2 = WWMath::Fabsf_Legacy(box.Extent.X / (box.Center.Z + box.Extent.Z)); + float tan_vfov2 = WWMath::Fabsf_Legacy(box.Extent.Y / (box.Center.Z + box.Extent.Z)); + float hfov = 2.0f * WWMath::Atan_Legacy(tan_hfov2); + float vfov = 2.0f * WWMath::Atan_Legacy(tan_vfov2); /* ** Plug in the results. diff --git a/Core/Libraries/Source/WWVegas/WW3D2/visrasterizer.cpp b/Core/Libraries/Source/WWVegas/WW3D2/visrasterizer.cpp index 89bc691f2f1..22b7b3d8f03 100644 --- a/Core/Libraries/Source/WWVegas/WW3D2/visrasterizer.cpp +++ b/Core/Libraries/Source/WWVegas/WW3D2/visrasterizer.cpp @@ -476,8 +476,8 @@ struct EdgeStruct { EdgeStruct(const GradientsStruct & grad,const Vector3 * verts,int top,int bottom) { - Y = WWMath::Ceil(verts[top].Y); - Height = WWMath::Ceil(verts[bottom].Y) - Y; + Y = WWMath::Ceilf(verts[top].Y); + Height = WWMath::Ceilf(verts[bottom].Y) - Y; float y_prestep = Y - verts[top].Y; float real_height = verts[bottom].Y - verts[top].Y; @@ -654,8 +654,8 @@ int IDBufferClass::Render_Occluder_Scanline(GradientsStruct & grads,EdgeStruct * return 0; } - int xstart = WWMath::Float_To_Long(WWMath::Max(WWMath::Ceil(left->X),1.0f)); - int width = WWMath::Float_To_Long(WWMath::Ceil(right->X)) - xstart; + int xstart = WWMath::Float_To_Long(WWMath::Max(WWMath::Ceilf(left->X),1.0f)); + int width = WWMath::Float_To_Long(WWMath::Ceilf(right->X)) - xstart; if (xstart + width > ResWidth) { width = ResWidth - xstart; } @@ -704,8 +704,8 @@ int IDBufferClass::Render_Non_Occluder_Scanline(GradientsStruct & grads,EdgeStru return 0; } - int xstart = WWMath::Float_To_Long(WWMath::Max(WWMath::Ceil(left->X),1)); - int width = WWMath::Float_To_Long(WWMath::Ceil(right->X)) - xstart; + int xstart = WWMath::Float_To_Long(WWMath::Max(WWMath::Ceilf(left->X),1)); + int width = WWMath::Float_To_Long(WWMath::Ceilf(right->X)) - xstart; if (xstart + width > ResWidth) { width = ResWidth - xstart; } diff --git a/Core/Libraries/Source/WWVegas/WWAudio/SoundPseudo3D.cpp b/Core/Libraries/Source/WWVegas/WWAudio/SoundPseudo3D.cpp index 8de1e8ffda4..b98f429680c 100644 --- a/Core/Libraries/Source/WWVegas/WWAudio/SoundPseudo3D.cpp +++ b/Core/Libraries/Source/WWVegas/WWAudio/SoundPseudo3D.cpp @@ -213,7 +213,7 @@ SoundPseudo3DClass::Update_Pseudo_Pan () // // Calculate a normalized pan from 0 (hard left) to 1.0F (hard right) // - float angle = WWMath::Atan2 (rel_sound_pos.Y, rel_sound_pos.X); + float angle = WWMath::Atan2_Legacy (rel_sound_pos.Y, rel_sound_pos.X); float pan = -WWMath::Fast_Sin (angle); pan = (pan / 2.0F) + 0.5F; diff --git a/Core/Libraries/Source/WWVegas/WWLib/Point.h b/Core/Libraries/Source/WWVegas/WWLib/Point.h index 78a9f8c7ea9..bde3fbf100b 100644 --- a/Core/Libraries/Source/WWVegas/WWLib/Point.h +++ b/Core/Libraries/Source/WWVegas/WWLib/Point.h @@ -36,6 +36,8 @@ #pragma once +#include "wwmath.h" + template class TRect; /* @@ -76,9 +78,9 @@ class TPoint2D { TPoint2D const operator - () const {return(TPoint2D(-X, -Y));} // Vector support functions. - T Length() const {return(T(sqrt(X*X + Y*Y)));} + T Length() const {return(T(WWMath::Sqrt(X*X + Y*Y)));} TPoint2D const Normalize() const { - double len = sqrt(X*X + Y*Y); + double len = WWMath::Sqrt(X*X + Y*Y); if (len != 0.0) { return(TPoint2D((T)((double)X / len), (T)((double)Y / len))); } else { @@ -163,9 +165,9 @@ class TPoint3D : public TPoint2D { TPoint3D const operator - () const {return(TPoint3D(-X, -Y, -Z));} // Vector support functions. - T Length() const {return(T(sqrt(X*X + Y*Y + Z*Z)));} + T Length() const {return(T(WWMath::Sqrt(X*X + Y*Y + Z*Z)));} TPoint3D const Normalize() const { - double len = sqrt(X*X + Y*Y + Z*Z); + double len = WWMath::Sqrt(X*X + Y*Y + Z*Z); if (len != 0.0) { return(TPoint3D(X / len, Y / len, Z / len)); } else { diff --git a/Core/Libraries/Source/WWVegas/WWLib/WWDefines.h b/Core/Libraries/Source/WWVegas/WWLib/WWDefines.h index eb25d597db8..853a3716579 100644 --- a/Core/Libraries/Source/WWVegas/WWLib/WWDefines.h +++ b/Core/Libraries/Source/WWVegas/WWLib/WWDefines.h @@ -18,6 +18,8 @@ #pragma once +#include "Lib/BaseDefines.h" + // Enable translation and rotation interpolation for raw animation (HRawAnimClass) updates. // This was intentionally disabled in the retail version, but likely not fully thought through. // Interpolation is certainly desired for animations that move and rotate meshes, but may not be diff --git a/Core/Libraries/Source/WWVegas/WWLib/visualc.h b/Core/Libraries/Source/WWVegas/WWLib/visualc.h index a400314d917..31639b9e623 100644 --- a/Core/Libraries/Source/WWVegas/WWLib/visualc.h +++ b/Core/Libraries/Source/WWVegas/WWLib/visualc.h @@ -103,22 +103,5 @@ #pragma warning(disable : 4711) - -#define M_E 2.71828182845904523536 -#define M_LOG2E 1.44269504088896340736 -#define M_LOG10E 0.434294481903251827651 -#define M_LN2 0.693147180559945309417 -#define M_LN10 2.30258509299404568402 -#define M_PI 3.14159265358979323846 -#define M_PI_2 1.57079632679489661923 -#define M_PI_4 0.785398163397448309616 -#define M_1_PI 0.318309886183790671538 -#define M_2_PI 0.636619772367581343076 -#define M_1_SQRTPI 0.564189583547756286948 -#define M_2_SQRTPI 1.12837916709551257390 -#define M_SQRT2 1.41421356237309504880 -#define M_SQRT_2 0.707106781186547524401 - - #endif diff --git a/Core/Libraries/Source/WWVegas/WWMath/CMakeLists.txt b/Core/Libraries/Source/WWVegas/WWMath/CMakeLists.txt index dca9eb68fef..4669b675165 100644 --- a/Core/Libraries/Source/WWVegas/WWMath/CMakeLists.txt +++ b/Core/Libraries/Source/WWVegas/WWMath/CMakeLists.txt @@ -91,5 +91,11 @@ target_link_libraries(core_wwmath PRIVATE core_wwsaveload ) +if (NOT IS_VS6_BUILD) + target_link_libraries(core_wwmath PUBLIC + gamemath + ) +endif() + # @todo Test its impact and see what to do with the legacy functions. #add_compile_definitions(core_wwmath PUBLIC ALLOW_TEMPORARIES) # Enables legacy math with "temporaries" diff --git a/Core/Libraries/Source/WWVegas/WWMath/aabox.h b/Core/Libraries/Source/WWVegas/WWMath/aabox.h index ac78b52c2b6..613b44bc37b 100644 --- a/Core/Libraries/Source/WWVegas/WWMath/aabox.h +++ b/Core/Libraries/Source/WWVegas/WWMath/aabox.h @@ -436,7 +436,7 @@ WWINLINE float AABoxClass::Project_To_Axis(const Vector3 & axis) const float z = Extent[2] * axis[2]; // projection is the sum of the absolute values of the projections of the three extents - return (WWMath::Fabs(x) + WWMath::Fabs(y) + WWMath::Fabs(z)); + return (WWMath::Fabsf_Legacy(x) + WWMath::Fabsf_Legacy(y) + WWMath::Fabsf_Legacy(z)); } /*********************************************************************************************** diff --git a/Core/Libraries/Source/WWVegas/WWMath/colmathaabox.cpp b/Core/Libraries/Source/WWVegas/WWMath/colmathaabox.cpp index decb97274f4..592a980ecf0 100644 --- a/Core/Libraries/Source/WWVegas/WWMath/colmathaabox.cpp +++ b/Core/Libraries/Source/WWVegas/WWMath/colmathaabox.cpp @@ -70,9 +70,9 @@ bool CollisionMath::Intersection_Test(const AABoxClass & box,const AABoxClass & { Vector3 dc = box2.Center - box.Center; - if (box.Extent.X + box2.Extent.X < WWMath::Fabs(dc.X)) return false; - if (box.Extent.Y + box2.Extent.Y < WWMath::Fabs(dc.Y)) return false; - if (box.Extent.Z + box2.Extent.Z < WWMath::Fabs(dc.Z)) return false; + if (box.Extent.X + box2.Extent.X < WWMath::Fabsf_Legacy(dc.X)) return false; + if (box.Extent.Y + box2.Extent.Y < WWMath::Fabsf_Legacy(dc.Y)) return false; + if (box.Extent.Z + box2.Extent.Z < WWMath::Fabsf_Legacy(dc.Z)) return false; return true; } @@ -101,9 +101,9 @@ CollisionMath::OverlapType CollisionMath::Overlap_Test(const AABoxClass & box,co // // Check to see if the sphere is completely outside the box // - if (WWMath::Fabs(dist.X) > extent.X) return OUTSIDE; - if (WWMath::Fabs(dist.Y) > extent.Y) return OUTSIDE; - if (WWMath::Fabs(dist.Z) > extent.Z) return OUTSIDE; + if (WWMath::Fabsf_Legacy(dist.X) > extent.X) return OUTSIDE; + if (WWMath::Fabsf_Legacy(dist.Y) > extent.Y) return OUTSIDE; + if (WWMath::Fabsf_Legacy(dist.Z) > extent.Z) return OUTSIDE; return INSIDE; } @@ -224,21 +224,21 @@ CollisionMath::OverlapType CollisionMath::Overlap_Test(const AABoxClass & box,co // that 'dp' will always project to zero for this axis. Vector3 axis; axis.Set(0,-line.Get_Dir().Z,line.Get_Dir().Y); // == (1,0,0) cross (x,y,z) - box_proj = WWMath::Fabs(axis.Y*box.Extent.Y) + WWMath::Fabs(axis.Z*box.Extent.Z); + box_proj = WWMath::Fabsf_Legacy(axis.Y*box.Extent.Y) + WWMath::Fabsf_Legacy(axis.Z*box.Extent.Z); p0_proj = Vector3::Dot_Product(axis,dp0); - if (WWMath::Fabs(p0_proj) > box_proj) return OUTSIDE; + if (WWMath::Fabsf_Legacy(p0_proj) > box_proj) return OUTSIDE; // Project box and line onto (y cross line) axis.Set(line.Get_Dir().Z,0,-line.Get_Dir().X); // == (0,1,0) cross (x,y,z) - box_proj = WWMath::Fabs(axis.X*box.Extent.X) + WWMath::Fabs(axis.Z*box.Extent.Z); + box_proj = WWMath::Fabsf_Legacy(axis.X*box.Extent.X) + WWMath::Fabsf_Legacy(axis.Z*box.Extent.Z); p0_proj = Vector3::Dot_Product(axis,dp0); - if (WWMath::Fabs(p0_proj) > box_proj) return OUTSIDE; + if (WWMath::Fabsf_Legacy(p0_proj) > box_proj) return OUTSIDE; // Project box and line onto (z cross line) axis.Set(-line.Get_Dir().Y,line.Get_Dir().X,0); // == (0,0,1) cross (x,y,z) - box_proj = WWMath::Fabs(axis.X*box.Extent.X) + WWMath::Fabs(axis.Y*box.Extent.Y); + box_proj = WWMath::Fabsf_Legacy(axis.X*box.Extent.X) + WWMath::Fabsf_Legacy(axis.Y*box.Extent.Y); p0_proj = Vector3::Dot_Product(axis,dp0); - if (WWMath::Fabs(p0_proj) > box_proj) return OUTSIDE; + if (WWMath::Fabsf_Legacy(p0_proj) > box_proj) return OUTSIDE; } return OVERLAPPED; diff --git a/Core/Libraries/Source/WWVegas/WWMath/colmathaabox.h b/Core/Libraries/Source/WWVegas/WWMath/colmathaabox.h index 70b8c50c0bb..8ae71d94781 100644 --- a/Core/Libraries/Source/WWVegas/WWMath/colmathaabox.h +++ b/Core/Libraries/Source/WWVegas/WWMath/colmathaabox.h @@ -60,9 +60,9 @@ *=============================================================================================*/ WWINLINE CollisionMath::OverlapType CollisionMath::Overlap_Test(const AABoxClass & box,const Vector3 & point) { - if (WWMath::Fabs(point.X - box.Center.X) > box.Extent.X) return POS; - if (WWMath::Fabs(point.Y - box.Center.Y) > box.Extent.Y) return POS; - if (WWMath::Fabs(point.Z - box.Center.Z) > box.Extent.Z) return POS; + if (WWMath::Fabsf_Legacy(point.X - box.Center.X) > box.Extent.X) return POS; + if (WWMath::Fabsf_Legacy(point.Y - box.Center.Y) > box.Extent.Y) return POS; + if (WWMath::Fabsf_Legacy(point.Z - box.Center.Z) > box.Extent.Z) return POS; return NEG; } @@ -84,9 +84,9 @@ WWINLINE CollisionMath::OverlapType CollisionMath::Overlap_Test(const AABoxClass Vector3 dc; Vector3::Subtract(box2.Center,box.Center,&dc); - if (box.Extent.X + box2.Extent.X < WWMath::Fabs(dc.X)) return POS; - if (box.Extent.Y + box2.Extent.Y < WWMath::Fabs(dc.Y)) return POS; - if (box.Extent.Z + box2.Extent.Z < WWMath::Fabs(dc.Z)) return POS; + if (box.Extent.X + box2.Extent.X < WWMath::Fabsf_Legacy(dc.X)) return POS; + if (box.Extent.Y + box2.Extent.Y < WWMath::Fabsf_Legacy(dc.Y)) return POS; + if (box.Extent.Z + box2.Extent.Z < WWMath::Fabsf_Legacy(dc.Z)) return POS; if ( (dc.X + box2.Extent.X <= box.Extent.X) && (dc.Y + box2.Extent.Y <= box.Extent.Y) && diff --git a/Core/Libraries/Source/WWVegas/WWMath/colmathaabtri.cpp b/Core/Libraries/Source/WWVegas/WWMath/colmathaabtri.cpp index e64265243a7..f26699eba5e 100644 --- a/Core/Libraries/Source/WWVegas/WWMath/colmathaabtri.cpp +++ b/Core/Libraries/Source/WWVegas/WWMath/colmathaabtri.cpp @@ -288,9 +288,9 @@ static inline bool aabtri_check_axis() } // compute coordinates of the leading edge of the box at t0 and t1 - leb0 = CollisionContext.Box->Extent.X * WWMath::Fabs(CollisionContext.TestAxis.X) + - CollisionContext.Box->Extent.Y * WWMath::Fabs(CollisionContext.TestAxis.Y) + - CollisionContext.Box->Extent.Z * WWMath::Fabs(CollisionContext.TestAxis.Z); + leb0 = CollisionContext.Box->Extent.X * WWMath::Fabsf_Legacy(CollisionContext.TestAxis.X) + + CollisionContext.Box->Extent.Y * WWMath::Fabsf_Legacy(CollisionContext.TestAxis.Y) + + CollisionContext.Box->Extent.Z * WWMath::Fabsf_Legacy(CollisionContext.TestAxis.Z); leb1 = leb0 + axismove; // compute coordinate of "leading edge of the triangle" relative to the box center. @@ -449,9 +449,9 @@ static inline bool aabtri_check_normal_axis() CollisionContext.TestSide = 1.0f; } - leb0 = CollisionContext.Box->Extent.X * WWMath::Fabs(CollisionContext.AN[0]) + - CollisionContext.Box->Extent.Y * WWMath::Fabs(CollisionContext.AN[1]) + - CollisionContext.Box->Extent.Z * WWMath::Fabs(CollisionContext.AN[2]); + leb0 = CollisionContext.Box->Extent.X * WWMath::Fabsf_Legacy(CollisionContext.AN[0]) + + CollisionContext.Box->Extent.Y * WWMath::Fabsf_Legacy(CollisionContext.AN[1]) + + CollisionContext.Box->Extent.Z * WWMath::Fabsf_Legacy(CollisionContext.AN[2]); leb1 = leb0 + axismove; CollisionContext.TestPoint = 0; lp = dist; // this is the "optimization", don't have to find lp @@ -574,7 +574,7 @@ inline void VERIFY_CROSS(const Vector3 & a, const Vector3 & b,const Vector3 & cr Vector3 tmp_cross; Vector3::Cross_Product(a,b,&tmp_cross); Vector3 diff = cross - tmp_cross; - WWASSERT(WWMath::Fabs(diff.Length()) < 0.0001f); + WWASSERT(WWMath::Fabsf_Legacy(diff.Length()) < 0.0001f); #endif } @@ -650,7 +650,7 @@ bool CollisionMath::Collide CollisionContext.TestAxisId = AXIS_A0E0; if (CollisionContext.TestAxis.Length2() > AXISLEN_EPSILON2) { dp = CollisionContext.AN[0]; - leb0 = box.Extent[1]*WWMath::Fabs(CollisionContext.AE[2][0]) + box.Extent[2]*WWMath::Fabs(CollisionContext.AE[1][0]); + leb0 = box.Extent[1]*WWMath::Fabsf_Legacy(CollisionContext.AE[2][0]) + box.Extent[2]*WWMath::Fabsf_Legacy(CollisionContext.AE[1][0]); if (aabtri_check_cross_axis(dp,2,leb0)) goto exit; } @@ -663,7 +663,7 @@ bool CollisionMath::Collide CollisionContext.TestAxisId = AXIS_A0E1; if (CollisionContext.TestAxis.Length2() > AXISLEN_EPSILON2) { dp = -CollisionContext.AN[0]; - leb0 = box.Extent[1]*WWMath::Fabs(CollisionContext.AE[2][1]) + box.Extent[2]*WWMath::Fabs(CollisionContext.AE[1][1]); + leb0 = box.Extent[1]*WWMath::Fabsf_Legacy(CollisionContext.AE[2][1]) + box.Extent[2]*WWMath::Fabsf_Legacy(CollisionContext.AE[1][1]); if (aabtri_check_cross_axis(dp,1,leb0)) goto exit; } @@ -681,7 +681,7 @@ bool CollisionMath::Collide if (CollisionContext.TestAxis.Length2() > AXISLEN_EPSILON2) { dp = -CollisionContext.AN[0]; - leb0 = box.Extent[1]*WWMath::Fabs(CollisionContext.AE[2][2]) + box.Extent[2]*WWMath::Fabs(CollisionContext.AE[1][2]); + leb0 = box.Extent[1]*WWMath::Fabsf_Legacy(CollisionContext.AE[2][2]) + box.Extent[2]*WWMath::Fabsf_Legacy(CollisionContext.AE[1][2]); if (aabtri_check_cross_axis(dp,1,leb0)) goto exit; } @@ -694,7 +694,7 @@ bool CollisionMath::Collide CollisionContext.TestAxisId = AXIS_A1E0; if (CollisionContext.TestAxis.Length2() > AXISLEN_EPSILON2) { dp = CollisionContext.AN[1]; - leb0 = box.Extent[0]*WWMath::Fabs(CollisionContext.AE[2][0]) + box.Extent[2]*WWMath::Fabs(CollisionContext.AE[0][0]); + leb0 = box.Extent[0]*WWMath::Fabsf_Legacy(CollisionContext.AE[2][0]) + box.Extent[2]*WWMath::Fabsf_Legacy(CollisionContext.AE[0][0]); if (aabtri_check_cross_axis(dp,2,leb0)) goto exit; } @@ -707,7 +707,7 @@ bool CollisionMath::Collide CollisionContext.TestAxisId = AXIS_A1E1; if (CollisionContext.TestAxis.Length2() > AXISLEN_EPSILON2) { dp = -CollisionContext.AN[1]; - leb0 = box.Extent[0]*WWMath::Fabs(CollisionContext.AE[2][1]) + box.Extent[2]*WWMath::Fabs(CollisionContext.AE[0][1]); + leb0 = box.Extent[0]*WWMath::Fabsf_Legacy(CollisionContext.AE[2][1]) + box.Extent[2]*WWMath::Fabsf_Legacy(CollisionContext.AE[0][1]); if (aabtri_check_cross_axis(dp,1,leb0)) goto exit; } @@ -720,7 +720,7 @@ bool CollisionMath::Collide CollisionContext.TestAxisId = AXIS_A1E2; if (CollisionContext.TestAxis.Length2() > AXISLEN_EPSILON2) { dp = -CollisionContext.AN[1]; - leb0 = box.Extent[0]*WWMath::Fabs(CollisionContext.AE[2][2]) + box.Extent[2]*WWMath::Fabs(CollisionContext.AE[0][2]); + leb0 = box.Extent[0]*WWMath::Fabsf_Legacy(CollisionContext.AE[2][2]) + box.Extent[2]*WWMath::Fabsf_Legacy(CollisionContext.AE[0][2]); if (aabtri_check_cross_axis(dp,1,leb0)) goto exit; } @@ -733,7 +733,7 @@ bool CollisionMath::Collide CollisionContext.TestAxisId = AXIS_A2E0; if (CollisionContext.TestAxis.Length2() > AXISLEN_EPSILON2) { dp = CollisionContext.AN[2]; - leb0 = box.Extent[0]*WWMath::Fabs(CollisionContext.AE[1][0]) + box.Extent[1]*WWMath::Fabs(CollisionContext.AE[0][0]); + leb0 = box.Extent[0]*WWMath::Fabsf_Legacy(CollisionContext.AE[1][0]) + box.Extent[1]*WWMath::Fabsf_Legacy(CollisionContext.AE[0][0]); if (aabtri_check_cross_axis(dp,2,leb0)) goto exit; } @@ -746,7 +746,7 @@ bool CollisionMath::Collide CollisionContext.TestAxisId = AXIS_A2E1; if (CollisionContext.TestAxis.Length2() > AXISLEN_EPSILON2) { dp = -CollisionContext.AN[2]; - leb0 = box.Extent[0]*WWMath::Fabs(CollisionContext.AE[1][1]) + box.Extent[1]*WWMath::Fabs(CollisionContext.AE[0][1]); + leb0 = box.Extent[0]*WWMath::Fabsf_Legacy(CollisionContext.AE[1][1]) + box.Extent[1]*WWMath::Fabsf_Legacy(CollisionContext.AE[0][1]); if (aabtri_check_cross_axis(dp,1,leb0)) goto exit; } @@ -759,7 +759,7 @@ bool CollisionMath::Collide CollisionContext.TestAxisId = AXIS_A2E2; if (CollisionContext.TestAxis.Length2() > AXISLEN_EPSILON2) { dp = -CollisionContext.AN[2]; - leb0 = box.Extent[0]*WWMath::Fabs(CollisionContext.AE[1][2]) + box.Extent[1]*WWMath::Fabs(CollisionContext.AE[0][2]); + leb0 = box.Extent[0]*WWMath::Fabsf_Legacy(CollisionContext.AE[1][2]) + box.Extent[1]*WWMath::Fabsf_Legacy(CollisionContext.AE[0][2]); if (aabtri_check_cross_axis(dp,1,leb0)) goto exit; } @@ -830,11 +830,11 @@ bool CollisionMath::Collide ** If this polygon cuts off more of the move -OR- this polygon cuts ** of the same amount but has a "better" normal, then use this normal */ - if ( (WWMath::Fabs(CollisionContext.MaxFrac - result->Fraction) > WWMATH_EPSILON) || + if ( (WWMath::Fabsf_Legacy(CollisionContext.MaxFrac - result->Fraction) > WWMATH_EPSILON) || (Vector3::Dot_Product(tmp_norm,move) < Vector3::Dot_Product(result->Normal,move))) { result->Normal = tmp_norm; - WWASSERT(WWMath::Fabs(result->Normal.Length() - 1.0f) < WWMATH_EPSILON); + WWASSERT(WWMath::Fabsf_Legacy(result->Normal.Length() - 1.0f) < WWMATH_EPSILON); } result->Fraction = CollisionContext.MaxFrac; @@ -1017,9 +1017,9 @@ static inline bool aabtri_intersect_normal_axis axis = -axis; } - leb0 = IntersectContext.Box->Extent.X * WWMath::Fabs(IntersectContext.AN[0]) + - IntersectContext.Box->Extent.Y * WWMath::Fabs(IntersectContext.AN[1]) + - IntersectContext.Box->Extent.Z * WWMath::Fabs(IntersectContext.AN[2]); + leb0 = IntersectContext.Box->Extent.X * WWMath::Fabsf_Legacy(IntersectContext.AN[0]) + + IntersectContext.Box->Extent.Y * WWMath::Fabsf_Legacy(IntersectContext.AN[1]) + + IntersectContext.Box->Extent.Z * WWMath::Fabsf_Legacy(IntersectContext.AN[2]); lp = dist; // this is the "optimization", don't have to find lp return (lp - leb0 > -WWMATH_EPSILON); @@ -1085,7 +1085,7 @@ bool CollisionMath::Intersection_Test(const AABoxClass & box,const TriClass & tr axis = IntersectContext.AxE[0][0]; if (axis.Length2() > AXISLEN_EPSILON2) { dp = IntersectContext.AN[0]; - leb0 = box.Extent[1]*WWMath::Fabs(IntersectContext.AE[2][0]) + box.Extent[2]*WWMath::Fabs(IntersectContext.AE[1][0]); + leb0 = box.Extent[1]*WWMath::Fabsf_Legacy(IntersectContext.AE[2][0]) + box.Extent[2]*WWMath::Fabsf_Legacy(IntersectContext.AE[1][0]); if (aabtri_intersect_cross_axis(axis,dp,leb0)) return false; } @@ -1096,7 +1096,7 @@ bool CollisionMath::Intersection_Test(const AABoxClass & box,const TriClass & tr axis = IntersectContext.AxE[0][1]; if (axis.Length2() > AXISLEN_EPSILON2) { dp = -IntersectContext.AN[0]; - leb0 = box.Extent[1]*WWMath::Fabs(IntersectContext.AE[2][1]) + box.Extent[2]*WWMath::Fabs(IntersectContext.AE[1][1]); + leb0 = box.Extent[1]*WWMath::Fabsf_Legacy(IntersectContext.AE[2][1]) + box.Extent[2]*WWMath::Fabsf_Legacy(IntersectContext.AE[1][1]); if (aabtri_intersect_cross_axis(axis,dp,leb0)) return false; } @@ -1109,7 +1109,7 @@ bool CollisionMath::Intersection_Test(const AABoxClass & box,const TriClass & tr IntersectContext.AE[2][2] = IntersectContext.E[2].Z; if (axis.Length2() > AXISLEN_EPSILON2) { dp = -IntersectContext.AN[0]; - leb0 = box.Extent[1]*WWMath::Fabs(IntersectContext.AE[2][2]) + box.Extent[2]*WWMath::Fabs(IntersectContext.AE[1][2]); + leb0 = box.Extent[1]*WWMath::Fabsf_Legacy(IntersectContext.AE[2][2]) + box.Extent[2]*WWMath::Fabsf_Legacy(IntersectContext.AE[1][2]); if (aabtri_intersect_cross_axis(axis,dp,leb0)) return false; } @@ -1120,7 +1120,7 @@ bool CollisionMath::Intersection_Test(const AABoxClass & box,const TriClass & tr axis = IntersectContext.AxE[1][0]; if (axis.Length2() > AXISLEN_EPSILON2) { dp = IntersectContext.AN[1]; - leb0 = box.Extent[0]*WWMath::Fabs(IntersectContext.AE[2][0]) + box.Extent[2]*WWMath::Fabs(IntersectContext.AE[0][0]); + leb0 = box.Extent[0]*WWMath::Fabsf_Legacy(IntersectContext.AE[2][0]) + box.Extent[2]*WWMath::Fabsf_Legacy(IntersectContext.AE[0][0]); if (aabtri_intersect_cross_axis(axis,dp,leb0)) return false; } @@ -1131,7 +1131,7 @@ bool CollisionMath::Intersection_Test(const AABoxClass & box,const TriClass & tr axis = IntersectContext.AxE[1][1]; if (axis.Length2() > AXISLEN_EPSILON2) { dp = -IntersectContext.AN[1]; - leb0 = box.Extent[0]*WWMath::Fabs(IntersectContext.AE[2][1]) + box.Extent[2]*WWMath::Fabs(IntersectContext.AE[0][1]); + leb0 = box.Extent[0]*WWMath::Fabsf_Legacy(IntersectContext.AE[2][1]) + box.Extent[2]*WWMath::Fabsf_Legacy(IntersectContext.AE[0][1]); if (aabtri_intersect_cross_axis(axis,dp,leb0)) return false; } @@ -1143,7 +1143,7 @@ bool CollisionMath::Intersection_Test(const AABoxClass & box,const TriClass & tr IntersectContext.AE[0][2] = IntersectContext.E[2].X; if (axis.Length2() > AXISLEN_EPSILON2) { dp = -IntersectContext.AN[1]; - leb0 = box.Extent[0]*WWMath::Fabs(IntersectContext.AE[2][2]) + box.Extent[2]*WWMath::Fabs(IntersectContext.AE[0][2]); + leb0 = box.Extent[0]*WWMath::Fabsf_Legacy(IntersectContext.AE[2][2]) + box.Extent[2]*WWMath::Fabsf_Legacy(IntersectContext.AE[0][2]); if (aabtri_intersect_cross_axis(axis,dp,leb0)) return false; } @@ -1154,7 +1154,7 @@ bool CollisionMath::Intersection_Test(const AABoxClass & box,const TriClass & tr axis = IntersectContext.AxE[2][0]; if (axis.Length2() > AXISLEN_EPSILON2) { dp = IntersectContext.AN[2]; - leb0 = box.Extent[0]*WWMath::Fabs(IntersectContext.AE[1][0]) + box.Extent[1]*WWMath::Fabs(IntersectContext.AE[0][0]); + leb0 = box.Extent[0]*WWMath::Fabsf_Legacy(IntersectContext.AE[1][0]) + box.Extent[1]*WWMath::Fabsf_Legacy(IntersectContext.AE[0][0]); if (aabtri_intersect_cross_axis(axis,dp,leb0)) return false; } @@ -1165,7 +1165,7 @@ bool CollisionMath::Intersection_Test(const AABoxClass & box,const TriClass & tr axis = IntersectContext.AxE[2][1]; if (axis.Length2() > AXISLEN_EPSILON2) { dp = -IntersectContext.AN[2]; - leb0 = box.Extent[0]*WWMath::Fabs(IntersectContext.AE[1][1]) + box.Extent[1]*WWMath::Fabs(IntersectContext.AE[0][1]); + leb0 = box.Extent[0]*WWMath::Fabsf_Legacy(IntersectContext.AE[1][1]) + box.Extent[1]*WWMath::Fabsf_Legacy(IntersectContext.AE[0][1]); if (aabtri_intersect_cross_axis(axis,dp,leb0)) return false; } @@ -1176,7 +1176,7 @@ bool CollisionMath::Intersection_Test(const AABoxClass & box,const TriClass & tr axis = IntersectContext.AxE[2][2]; if (axis.Length2() > AXISLEN_EPSILON2) { dp = -IntersectContext.AN[2]; - leb0 = box.Extent[0]*WWMath::Fabs(IntersectContext.AE[1][2]) + box.Extent[1]*WWMath::Fabs(IntersectContext.AE[0][2]); + leb0 = box.Extent[0]*WWMath::Fabsf_Legacy(IntersectContext.AE[1][2]) + box.Extent[1]*WWMath::Fabsf_Legacy(IntersectContext.AE[0][2]); if (aabtri_intersect_cross_axis(axis,dp,leb0)) return false; } diff --git a/Core/Libraries/Source/WWVegas/WWMath/colmathline.cpp b/Core/Libraries/Source/WWVegas/WWMath/colmathline.cpp index c55036b636d..f6531b07424 100644 --- a/Core/Libraries/Source/WWVegas/WWMath/colmathline.cpp +++ b/Core/Libraries/Source/WWVegas/WWMath/colmathline.cpp @@ -253,7 +253,7 @@ bool CollisionMath::Collide(const LineSegClass & line,const SphereClass & sphere if (disc < 0.0f) { return false; } else { - float d = WWMath::Sqrt(disc); + float d = WWMath::Sqrt_Legacy(disc); float frac = (clen - d) / line.Get_Length(); if (frac<0.0f) frac = (clen + d) / line.Get_Length(); diff --git a/Core/Libraries/Source/WWVegas/WWMath/colmathobbobb.cpp b/Core/Libraries/Source/WWVegas/WWMath/colmathobbobb.cpp index 9af3fd1e007..f7eeff34222 100644 --- a/Core/Libraries/Source/WWVegas/WWMath/colmathobbobb.cpp +++ b/Core/Libraries/Source/WWVegas/WWMath/colmathobbobb.cpp @@ -177,9 +177,9 @@ static bool obb_intersect_box0_basis // ra = box0 projection onto the axis // rb = box1 projection onto the axis float ra = context.Box0.Extent[axis_index]; - float rb = WWMath::Fabs(context.Box1.Extent[0]*context.AB[axis_index][0]) + - WWMath::Fabs(context.Box1.Extent[1]*context.AB[axis_index][1]) + - WWMath::Fabs(context.Box1.Extent[2]*context.AB[axis_index][2]); + float rb = WWMath::Fabsf_Legacy(context.Box1.Extent[0]*context.AB[axis_index][0]) + + WWMath::Fabsf_Legacy(context.Box1.Extent[1]*context.AB[axis_index][1]) + + WWMath::Fabsf_Legacy(context.Box1.Extent[2]*context.AB[axis_index][2]); float rsum = ra+rb; // u = projected distance between the box centers @@ -214,9 +214,9 @@ static bool obb_intersect_box1_basis { // ra = box0 projection onto the axis // rb = box1 projection onto the axis - float ra = WWMath::Fabs(context.Box0.Extent[0]*context.AB[0][axis_index]) + - WWMath::Fabs(context.Box0.Extent[1]*context.AB[1][axis_index]) + - WWMath::Fabs(context.Box0.Extent[2]*context.AB[2][axis_index]); + float ra = WWMath::Fabsf_Legacy(context.Box0.Extent[0]*context.AB[0][axis_index]) + + WWMath::Fabsf_Legacy(context.Box0.Extent[1]*context.AB[1][axis_index]) + + WWMath::Fabsf_Legacy(context.Box0.Extent[2]*context.AB[2][axis_index]); float rb = context.Box1.Extent[axis_index]; float rsum = ra+rb; @@ -340,8 +340,8 @@ bool intersect_obb_obb ///////////////////////////////////////////////////////////////////////// Vector3::Cross_Product(context.A[0],context.B[0],&axis); if (axis.Length2() > AXISLEN_EPSILON2) { - ra = WWMath::Fabs(context.Box0.Extent[1]*context.AB[2][0])+WWMath::Fabs(context.Box0.Extent[2]*context.AB[1][0]); - rb = WWMath::Fabs(context.Box1.Extent[1]*context.AB[0][2])+WWMath::Fabs(context.Box1.Extent[2]*context.AB[0][1]); + ra = WWMath::Fabsf_Legacy(context.Box0.Extent[1]*context.AB[2][0])+WWMath::Fabsf_Legacy(context.Box0.Extent[2]*context.AB[1][0]); + rb = WWMath::Fabsf_Legacy(context.Box1.Extent[1]*context.AB[0][2])+WWMath::Fabsf_Legacy(context.Box1.Extent[2]*context.AB[0][1]); if (obb_intersect_axis(context,axis,ra,rb)) return false; } @@ -350,8 +350,8 @@ bool intersect_obb_obb ///////////////////////////////////////////////////////////////////////// Vector3::Cross_Product(context.A[0],context.B[1],&axis); if (axis.Length2() > AXISLEN_EPSILON2) { - ra = WWMath::Fabs(context.Box0.Extent[1]*context.AB[2][1])+WWMath::Fabs(context.Box0.Extent[2]*context.AB[1][1]); - rb = WWMath::Fabs(context.Box1.Extent[0]*context.AB[0][2])+WWMath::Fabs(context.Box1.Extent[2]*context.AB[0][0]); + ra = WWMath::Fabsf_Legacy(context.Box0.Extent[1]*context.AB[2][1])+WWMath::Fabsf_Legacy(context.Box0.Extent[2]*context.AB[1][1]); + rb = WWMath::Fabsf_Legacy(context.Box1.Extent[0]*context.AB[0][2])+WWMath::Fabsf_Legacy(context.Box1.Extent[2]*context.AB[0][0]); if (obb_intersect_axis(context,axis,ra,rb)) return false; } @@ -360,8 +360,8 @@ bool intersect_obb_obb ///////////////////////////////////////////////////////////////////////// Vector3::Cross_Product(context.A[0],context.B[2],&axis); if (axis.Length2() > AXISLEN_EPSILON2) { - ra = WWMath::Fabs(context.Box0.Extent[1]*context.AB[2][2])+WWMath::Fabs(context.Box0.Extent[2]*context.AB[1][2]); - rb = WWMath::Fabs(context.Box1.Extent[0]*context.AB[0][1])+WWMath::Fabs(context.Box1.Extent[1]*context.AB[0][0]); + ra = WWMath::Fabsf_Legacy(context.Box0.Extent[1]*context.AB[2][2])+WWMath::Fabsf_Legacy(context.Box0.Extent[2]*context.AB[1][2]); + rb = WWMath::Fabsf_Legacy(context.Box1.Extent[0]*context.AB[0][1])+WWMath::Fabsf_Legacy(context.Box1.Extent[1]*context.AB[0][0]); if (obb_intersect_axis(context,axis,ra,rb)) return false; } @@ -370,8 +370,8 @@ bool intersect_obb_obb ///////////////////////////////////////////////////////////////////////// Vector3::Cross_Product(context.A[1],context.B[0],&axis); if (axis.Length2() > AXISLEN_EPSILON2) { - ra = WWMath::Fabs(context.Box0.Extent[0]*context.AB[2][0])+WWMath::Fabs(context.Box0.Extent[2]*context.AB[0][0]); - rb = WWMath::Fabs(context.Box1.Extent[1]*context.AB[1][2])+WWMath::Fabs(context.Box1.Extent[2]*context.AB[1][1]); + ra = WWMath::Fabsf_Legacy(context.Box0.Extent[0]*context.AB[2][0])+WWMath::Fabsf_Legacy(context.Box0.Extent[2]*context.AB[0][0]); + rb = WWMath::Fabsf_Legacy(context.Box1.Extent[1]*context.AB[1][2])+WWMath::Fabsf_Legacy(context.Box1.Extent[2]*context.AB[1][1]); if (obb_intersect_axis(context,axis,ra,rb)) return false; } @@ -380,8 +380,8 @@ bool intersect_obb_obb ///////////////////////////////////////////////////////////////////////// Vector3::Cross_Product(context.A[1],context.B[1],&axis); if (axis.Length2() > AXISLEN_EPSILON2) { - ra = WWMath::Fabs(context.Box0.Extent[0]*context.AB[2][1])+WWMath::Fabs(context.Box0.Extent[2]*context.AB[0][1]); - rb = WWMath::Fabs(context.Box1.Extent[0]*context.AB[1][2])+WWMath::Fabs(context.Box1.Extent[2]*context.AB[1][0]); + ra = WWMath::Fabsf_Legacy(context.Box0.Extent[0]*context.AB[2][1])+WWMath::Fabsf_Legacy(context.Box0.Extent[2]*context.AB[0][1]); + rb = WWMath::Fabsf_Legacy(context.Box1.Extent[0]*context.AB[1][2])+WWMath::Fabsf_Legacy(context.Box1.Extent[2]*context.AB[1][0]); if (obb_intersect_axis(context,axis,ra,rb)) return false; } @@ -390,8 +390,8 @@ bool intersect_obb_obb ///////////////////////////////////////////////////////////////////////// Vector3::Cross_Product(context.A[1],context.B[2],&axis); if (axis.Length2() > AXISLEN_EPSILON2) { - ra = WWMath::Fabs(context.Box0.Extent[0]*context.AB[2][2])+WWMath::Fabs(context.Box0.Extent[2]*context.AB[0][2]); - rb = WWMath::Fabs(context.Box1.Extent[0]*context.AB[1][1])+WWMath::Fabs(context.Box1.Extent[1]*context.AB[1][0]); + ra = WWMath::Fabsf_Legacy(context.Box0.Extent[0]*context.AB[2][2])+WWMath::Fabsf_Legacy(context.Box0.Extent[2]*context.AB[0][2]); + rb = WWMath::Fabsf_Legacy(context.Box1.Extent[0]*context.AB[1][1])+WWMath::Fabsf_Legacy(context.Box1.Extent[1]*context.AB[1][0]); if (obb_intersect_axis(context,axis,ra,rb)) return false; } @@ -400,8 +400,8 @@ bool intersect_obb_obb ///////////////////////////////////////////////////////////////////////// Vector3::Cross_Product(context.A[2],context.B[0],&axis); if (axis.Length2() > AXISLEN_EPSILON2) { - ra = WWMath::Fabs(context.Box0.Extent[0]*context.AB[1][0])+WWMath::Fabs(context.Box0.Extent[1]*context.AB[0][0]); - rb = WWMath::Fabs(context.Box1.Extent[1]*context.AB[2][2])+WWMath::Fabs(context.Box1.Extent[2]*context.AB[2][1]); + ra = WWMath::Fabsf_Legacy(context.Box0.Extent[0]*context.AB[1][0])+WWMath::Fabsf_Legacy(context.Box0.Extent[1]*context.AB[0][0]); + rb = WWMath::Fabsf_Legacy(context.Box1.Extent[1]*context.AB[2][2])+WWMath::Fabsf_Legacy(context.Box1.Extent[2]*context.AB[2][1]); if (obb_intersect_axis(context,axis,ra,rb)) return false; } @@ -410,8 +410,8 @@ bool intersect_obb_obb ///////////////////////////////////////////////////////////////////////// Vector3::Cross_Product(context.A[2],context.B[1],&axis); if (axis.Length2() > AXISLEN_EPSILON2) { - ra = WWMath::Fabs(context.Box0.Extent[0]*context.AB[1][1])+WWMath::Fabs(context.Box0.Extent[1]*context.AB[0][1]); - rb = WWMath::Fabs(context.Box1.Extent[0]*context.AB[2][2])+WWMath::Fabs(context.Box1.Extent[2]*context.AB[2][0]); + ra = WWMath::Fabsf_Legacy(context.Box0.Extent[0]*context.AB[1][1])+WWMath::Fabsf_Legacy(context.Box0.Extent[1]*context.AB[0][1]); + rb = WWMath::Fabsf_Legacy(context.Box1.Extent[0]*context.AB[2][2])+WWMath::Fabsf_Legacy(context.Box1.Extent[2]*context.AB[2][0]); if (obb_intersect_axis(context,axis,ra,rb)) return false; } @@ -420,8 +420,8 @@ bool intersect_obb_obb ///////////////////////////////////////////////////////////////////////// Vector3::Cross_Product(context.A[2],context.B[2],&axis); if (axis.Length2() > AXISLEN_EPSILON2) { - ra = WWMath::Fabs(context.Box0.Extent[0]*context.AB[1][2])+WWMath::Fabs(context.Box0.Extent[1]*context.AB[0][2]); - rb = WWMath::Fabs(context.Box1.Extent[0]*context.AB[2][1])+WWMath::Fabs(context.Box1.Extent[1]*context.AB[2][0]); + ra = WWMath::Fabsf_Legacy(context.Box0.Extent[0]*context.AB[1][2])+WWMath::Fabsf_Legacy(context.Box0.Extent[1]*context.AB[0][2]); + rb = WWMath::Fabsf_Legacy(context.Box1.Extent[0]*context.AB[2][1])+WWMath::Fabsf_Legacy(context.Box1.Extent[1]*context.AB[2][0]); if (obb_intersect_axis(context,axis,ra,rb)) return false; } @@ -593,7 +593,7 @@ static inline bool obb_separation_test if ( u1 > rsum ) { context.MaxFrac = 1.0f; return true; - } else if (WWMath::Fabs(u1-u0) > 0.0f) { + } else if (WWMath::Fabsf_Legacy(u1-u0) > 0.0f) { tmp = (rsum-u0)/(u1-u0); if ( tmp > context.MaxFrac ) { context.MaxFrac = tmp; @@ -606,7 +606,7 @@ static inline bool obb_separation_test if ( u1 < -rsum ) { context.MaxFrac = 1.0f; return true; - } else if (WWMath::Fabs(u1-u0) > 0.0f) { + } else if (WWMath::Fabsf_Legacy(u1-u0) > 0.0f) { tmp = (-rsum-u0)/(u1-u0); if ( tmp > context.MaxFrac ) { context.MaxFrac = tmp; @@ -640,9 +640,9 @@ static bool obb_check_box0_basis // ra = box0 projection onto the axis // rb = box1 projection onto the axis float ra = context.Box0.Extent[axis_index]; - float rb = WWMath::Fabs(context.Box1.Extent[0]*context.AB[axis_index][0]) + - WWMath::Fabs(context.Box1.Extent[1]*context.AB[axis_index][1]) + - WWMath::Fabs(context.Box1.Extent[2]*context.AB[axis_index][2]); + float rb = WWMath::Fabsf_Legacy(context.Box1.Extent[0]*context.AB[axis_index][0]) + + WWMath::Fabsf_Legacy(context.Box1.Extent[1]*context.AB[axis_index][1]) + + WWMath::Fabsf_Legacy(context.Box1.Extent[2]*context.AB[axis_index][2]); // u0 = projected distance between the box centers at t0 // u1 = projected distance between the box centers at t1 @@ -673,9 +673,9 @@ static bool obb_check_box1_basis { // ra = box0 projection onto the axis // rb = box1 projection onto the axis - float ra = WWMath::Fabs(context.Box0.Extent[0]*context.AB[0][axis_index]) + - WWMath::Fabs(context.Box0.Extent[1]*context.AB[1][axis_index]) + - WWMath::Fabs(context.Box0.Extent[2]*context.AB[2][axis_index]); + float ra = WWMath::Fabsf_Legacy(context.Box0.Extent[0]*context.AB[0][axis_index]) + + WWMath::Fabsf_Legacy(context.Box0.Extent[1]*context.AB[1][axis_index]) + + WWMath::Fabsf_Legacy(context.Box0.Extent[2]*context.AB[2][axis_index]); float rb = context.Box1.Extent[axis_index]; // u0 = projected distance between the box centers at t0 @@ -730,13 +730,13 @@ static inline void obb_compute_projections float * rb ) { - *ra = context.Box0.Extent.X * WWMath::Fabs(Vector3::Dot_Product(context.A[0],context.TestAxis)) + - context.Box0.Extent.Y * WWMath::Fabs(Vector3::Dot_Product(context.A[1],context.TestAxis)) + - context.Box0.Extent.Z * WWMath::Fabs(Vector3::Dot_Product(context.A[2],context.TestAxis)); + *ra = context.Box0.Extent.X * WWMath::Fabsf_Legacy(Vector3::Dot_Product(context.A[0],context.TestAxis)) + + context.Box0.Extent.Y * WWMath::Fabsf_Legacy(Vector3::Dot_Product(context.A[1],context.TestAxis)) + + context.Box0.Extent.Z * WWMath::Fabsf_Legacy(Vector3::Dot_Product(context.A[2],context.TestAxis)); - *rb = context.Box1.Extent.X * WWMath::Fabs(Vector3::Dot_Product(context.B[0],context.TestAxis)) + - context.Box1.Extent.Y * WWMath::Fabs(Vector3::Dot_Product(context.B[1],context.TestAxis)) + - context.Box1.Extent.Z * WWMath::Fabs(Vector3::Dot_Product(context.B[2],context.TestAxis)); + *rb = context.Box1.Extent.X * WWMath::Fabsf_Legacy(Vector3::Dot_Product(context.B[0],context.TestAxis)) + + context.Box1.Extent.Y * WWMath::Fabsf_Legacy(Vector3::Dot_Product(context.B[1],context.TestAxis)) + + context.Box1.Extent.Z * WWMath::Fabsf_Legacy(Vector3::Dot_Product(context.B[2],context.TestAxis)); } @@ -923,7 +923,7 @@ static inline void compute_contact_point(ObbCollisionStruct & context,CastResult y[2] = eval_side(context.AB[0][1],context.Side) * context.Box1.Extent[2]; den = (1.0f - context.AB[0][0] * context.AB[0][0]); - if (WWMath::Fabs(den) > 0.0f) { + if (WWMath::Fabsf_Legacy(den) > 0.0f) { x[0] = Vector3::Dot_Product(context.A[0],dcnew); x[0] += context.AB[0][0] * (Vector3::Dot_Product(-context.B[0],dcnew) + context.AB[1][0]*x[1] + context.AB[2][0]*x[2]); x[0] += context.AB[0][1] * y[1] + context.AB[0][2] * y[2]; @@ -940,7 +940,7 @@ static inline void compute_contact_point(ObbCollisionStruct & context,CastResult y[2] = -eval_side(context.AB[0][0],context.Side) * context.Box1.Extent[2]; den = (1.0f - context.AB[0][1] * context.AB[0][1]); - if (WWMath::Fabs(den) > 0.0f) { + if (WWMath::Fabsf_Legacy(den) > 0.0f) { x[0] = Vector3::Dot_Product(context.A[0],dcnew); x[0] += context.AB[0][1] * (Vector3::Dot_Product(-context.B[1],dcnew) + context.AB[1][1]*x[1] + context.AB[2][1]*x[2]); x[0] += context.AB[0][0] * y[0] + context.AB[0][2] * y[2]; @@ -957,7 +957,7 @@ static inline void compute_contact_point(ObbCollisionStruct & context,CastResult y[1] = eval_side(context.AB[0][0],context.Side) * context.Box1.Extent[1]; den = (1.0f - context.AB[0][2] * context.AB[0][2]); - if (WWMath::Fabs(den) > 0.0f) { + if (WWMath::Fabsf_Legacy(den) > 0.0f) { x[0] = Vector3::Dot_Product(context.A[0],dcnew); x[0] += context.AB[0][2] * (Vector3::Dot_Product(-context.B[2],dcnew) + context.AB[1][2]*x[1] + context.AB[2][2]*x[2]); x[0] += context.AB[0][0] * y[0] + context.AB[0][1] * y[1]; @@ -974,7 +974,7 @@ static inline void compute_contact_point(ObbCollisionStruct & context,CastResult y[2] = eval_side(context.AB[1][1],context.Side) * context.Box1.Extent[2]; den = (1.0f - context.AB[1][0] * context.AB[1][0]); - if (WWMath::Fabs(den) > 0.0f) { + if (WWMath::Fabsf_Legacy(den) > 0.0f) { x[1] = Vector3::Dot_Product(context.A[1],dcnew); x[1] += context.AB[1][0] * (Vector3::Dot_Product(-context.B[0],dcnew) + context.AB[0][0]*x[0] + context.AB[2][0]*x[2]); x[1] += context.AB[1][1] * y[1] + context.AB[1][2] * y[2]; @@ -991,7 +991,7 @@ static inline void compute_contact_point(ObbCollisionStruct & context,CastResult y[2] = -eval_side(context.AB[1][0],context.Side) * context.Box1.Extent[2]; den = 1.0f / (1.0f - context.AB[1][1] * context.AB[1][1]); - if (WWMath::Fabs(den) > 0.0f) { + if (WWMath::Fabsf_Legacy(den) > 0.0f) { x[1] = Vector3::Dot_Product(context.A[1],dcnew); x[1] += context.AB[1][1] * (Vector3::Dot_Product(-context.B[1],dcnew) + context.AB[0][1]*x[0] + context.AB[2][1]*x[2]); x[1] += context.AB[1][0] * y[0] + context.AB[1][2] * y[2]; @@ -1008,7 +1008,7 @@ static inline void compute_contact_point(ObbCollisionStruct & context,CastResult y[1] = eval_side(context.AB[1][0],context.Side) * context.Box1.Extent[1]; den = (1.0f - context.AB[1][2] * context.AB[1][2]); - if (WWMath::Fabs(den) > 0.0f) { + if (WWMath::Fabsf_Legacy(den) > 0.0f) { x[1] = Vector3::Dot_Product(context.A[1],dcnew); x[1] += context.AB[1][2] * (Vector3::Dot_Product(-context.B[2],dcnew) + context.AB[0][2]*x[0] + context.AB[2][2]*x[2]); x[1] += context.AB[1][0] * y[0] + context.AB[1][1] * y[1]; @@ -1025,7 +1025,7 @@ static inline void compute_contact_point(ObbCollisionStruct & context,CastResult y[2] = eval_side(context.AB[2][1],context.Side) * context.Box1.Extent[2]; den = (1.0f - context.AB[2][0] * context.AB[2][0]); - if (WWMath::Fabs(den) > 0.0f) { + if (WWMath::Fabsf_Legacy(den) > 0.0f) { x[2] = Vector3::Dot_Product(context.A[2],dcnew); x[2] += context.AB[2][0] * (Vector3::Dot_Product(-context.B[0],dcnew) + context.AB[0][0]*x[0] + context.AB[1][0]*x[1]); x[2] += context.AB[2][1] * y[1] + context.AB[2][2] * y[2]; @@ -1042,7 +1042,7 @@ static inline void compute_contact_point(ObbCollisionStruct & context,CastResult y[2] = -eval_side(context.AB[2][0],context.Side) * context.Box1.Extent[2]; den = (1.0f - context.AB[2][1] * context.AB[2][1]); - if (WWMath::Fabs(den) > 0.0f) { + if (WWMath::Fabsf_Legacy(den) > 0.0f) { x[2] = Vector3::Dot_Product(context.A[2],dcnew); x[2] += context.AB[2][1] * (Vector3::Dot_Product(-context.B[1],dcnew) + context.AB[0][1]*x[0] + context.AB[1][1]*x[1]); x[2] += context.AB[2][0] * y[0] + context.AB[2][2] * y[2]; @@ -1059,7 +1059,7 @@ static inline void compute_contact_point(ObbCollisionStruct & context,CastResult y[1] = eval_side(context.AB[2][0],context.Side) * context.Box1.Extent[1]; den = (1.0f - context.AB[2][2] * context.AB[2][2]); - if (WWMath::Fabs(den) > 0.0f) { + if (WWMath::Fabsf_Legacy(den) > 0.0f) { x[2] = Vector3::Dot_Product(context.A[2],dcnew); x[2] += context.AB[2][2] * (Vector3::Dot_Product(-context.B[2],dcnew) + context.AB[0][2]*x[0] + context.AB[1][2]*x[1]); x[2] += context.AB[2][0] * y[0] + context.AB[2][1] * y[1]; @@ -1177,8 +1177,8 @@ bool collide_obb_obb Vector3::Cross_Product(context.A[0],context.B[0],&context.TestAxis); context.TestAxisId = AXIS_A0B0; if (context.TestAxis.Length2() > AXISLEN_EPSILON2) { - ra = WWMath::Fabs(context.Box0.Extent[1]*context.AB[2][0])+WWMath::Fabs(context.Box0.Extent[2]*context.AB[1][0]); - rb = WWMath::Fabs(context.Box1.Extent[1]*context.AB[0][2])+WWMath::Fabs(context.Box1.Extent[2]*context.AB[0][1]); + ra = WWMath::Fabsf_Legacy(context.Box0.Extent[1]*context.AB[2][0])+WWMath::Fabsf_Legacy(context.Box0.Extent[2]*context.AB[1][0]); + rb = WWMath::Fabsf_Legacy(context.Box1.Extent[1]*context.AB[0][2])+WWMath::Fabsf_Legacy(context.Box1.Extent[2]*context.AB[0][1]); if (obb_check_axis(context,ra,rb)) goto exit; } @@ -1188,8 +1188,8 @@ bool collide_obb_obb Vector3::Cross_Product(context.A[0],context.B[1],&context.TestAxis); context.TestAxisId = AXIS_A0B1; if (context.TestAxis.Length2() > AXISLEN_EPSILON2) { - ra = WWMath::Fabs(context.Box0.Extent[1]*context.AB[2][1])+WWMath::Fabs(context.Box0.Extent[2]*context.AB[1][1]); - rb = WWMath::Fabs(context.Box1.Extent[0]*context.AB[0][2])+WWMath::Fabs(context.Box1.Extent[2]*context.AB[0][0]); + ra = WWMath::Fabsf_Legacy(context.Box0.Extent[1]*context.AB[2][1])+WWMath::Fabsf_Legacy(context.Box0.Extent[2]*context.AB[1][1]); + rb = WWMath::Fabsf_Legacy(context.Box1.Extent[0]*context.AB[0][2])+WWMath::Fabsf_Legacy(context.Box1.Extent[2]*context.AB[0][0]); if (obb_check_axis(context,ra,rb)) goto exit; } @@ -1199,8 +1199,8 @@ bool collide_obb_obb Vector3::Cross_Product(context.A[0],context.B[2],&context.TestAxis); context.TestAxisId = AXIS_A0B2; if (context.TestAxis.Length2() > AXISLEN_EPSILON2) { - ra = WWMath::Fabs(context.Box0.Extent[1]*context.AB[2][2])+WWMath::Fabs(context.Box0.Extent[2]*context.AB[1][2]); - rb = WWMath::Fabs(context.Box1.Extent[0]*context.AB[0][1])+WWMath::Fabs(context.Box1.Extent[1]*context.AB[0][0]); + ra = WWMath::Fabsf_Legacy(context.Box0.Extent[1]*context.AB[2][2])+WWMath::Fabsf_Legacy(context.Box0.Extent[2]*context.AB[1][2]); + rb = WWMath::Fabsf_Legacy(context.Box1.Extent[0]*context.AB[0][1])+WWMath::Fabsf_Legacy(context.Box1.Extent[1]*context.AB[0][0]); if (obb_check_axis(context,ra,rb)) goto exit; } @@ -1210,8 +1210,8 @@ bool collide_obb_obb Vector3::Cross_Product(context.A[1],context.B[0],&context.TestAxis); context.TestAxisId = AXIS_A1B0; if (context.TestAxis.Length2() > AXISLEN_EPSILON2) { - ra = WWMath::Fabs(context.Box0.Extent[0]*context.AB[2][0])+WWMath::Fabs(context.Box0.Extent[2]*context.AB[0][0]); - rb = WWMath::Fabs(context.Box1.Extent[1]*context.AB[1][2])+WWMath::Fabs(context.Box1.Extent[2]*context.AB[1][1]); + ra = WWMath::Fabsf_Legacy(context.Box0.Extent[0]*context.AB[2][0])+WWMath::Fabsf_Legacy(context.Box0.Extent[2]*context.AB[0][0]); + rb = WWMath::Fabsf_Legacy(context.Box1.Extent[1]*context.AB[1][2])+WWMath::Fabsf_Legacy(context.Box1.Extent[2]*context.AB[1][1]); if (obb_check_axis(context,ra,rb)) goto exit; } @@ -1221,8 +1221,8 @@ bool collide_obb_obb Vector3::Cross_Product(context.A[1],context.B[1],&context.TestAxis); context.TestAxisId = AXIS_A1B1; if (context.TestAxis.Length2() > AXISLEN_EPSILON2) { - ra = WWMath::Fabs(context.Box0.Extent[0]*context.AB[2][1])+WWMath::Fabs(context.Box0.Extent[2]*context.AB[0][1]); - rb = WWMath::Fabs(context.Box1.Extent[0]*context.AB[1][2])+WWMath::Fabs(context.Box1.Extent[2]*context.AB[1][0]); + ra = WWMath::Fabsf_Legacy(context.Box0.Extent[0]*context.AB[2][1])+WWMath::Fabsf_Legacy(context.Box0.Extent[2]*context.AB[0][1]); + rb = WWMath::Fabsf_Legacy(context.Box1.Extent[0]*context.AB[1][2])+WWMath::Fabsf_Legacy(context.Box1.Extent[2]*context.AB[1][0]); if (obb_check_axis(context,ra,rb)) goto exit; } @@ -1232,8 +1232,8 @@ bool collide_obb_obb Vector3::Cross_Product(context.A[1],context.B[2],&context.TestAxis); context.TestAxisId = AXIS_A1B2; if (context.TestAxis.Length2() > AXISLEN_EPSILON2) { - ra = WWMath::Fabs(context.Box0.Extent[0]*context.AB[2][2])+WWMath::Fabs(context.Box0.Extent[2]*context.AB[0][2]); - rb = WWMath::Fabs(context.Box1.Extent[0]*context.AB[1][1])+WWMath::Fabs(context.Box1.Extent[1]*context.AB[1][0]); + ra = WWMath::Fabsf_Legacy(context.Box0.Extent[0]*context.AB[2][2])+WWMath::Fabsf_Legacy(context.Box0.Extent[2]*context.AB[0][2]); + rb = WWMath::Fabsf_Legacy(context.Box1.Extent[0]*context.AB[1][1])+WWMath::Fabsf_Legacy(context.Box1.Extent[1]*context.AB[1][0]); if (obb_check_axis(context,ra,rb)) goto exit; } @@ -1243,8 +1243,8 @@ bool collide_obb_obb Vector3::Cross_Product(context.A[2],context.B[0],&context.TestAxis); context.TestAxisId = AXIS_A2B0; if (context.TestAxis.Length2() > AXISLEN_EPSILON2) { - ra = WWMath::Fabs(context.Box0.Extent[0]*context.AB[1][0])+WWMath::Fabs(context.Box0.Extent[1]*context.AB[0][0]); - rb = WWMath::Fabs(context.Box1.Extent[1]*context.AB[2][2])+WWMath::Fabs(context.Box1.Extent[2]*context.AB[2][1]); + ra = WWMath::Fabsf_Legacy(context.Box0.Extent[0]*context.AB[1][0])+WWMath::Fabsf_Legacy(context.Box0.Extent[1]*context.AB[0][0]); + rb = WWMath::Fabsf_Legacy(context.Box1.Extent[1]*context.AB[2][2])+WWMath::Fabsf_Legacy(context.Box1.Extent[2]*context.AB[2][1]); if (obb_check_axis(context,ra,rb)) goto exit; } @@ -1254,8 +1254,8 @@ bool collide_obb_obb Vector3::Cross_Product(context.A[2],context.B[1],&context.TestAxis); context.TestAxisId = AXIS_A2B1; if (context.TestAxis.Length2() > AXISLEN_EPSILON2) { - ra = WWMath::Fabs(context.Box0.Extent[0]*context.AB[1][1])+WWMath::Fabs(context.Box0.Extent[1]*context.AB[0][1]); - rb = WWMath::Fabs(context.Box1.Extent[0]*context.AB[2][2])+WWMath::Fabs(context.Box1.Extent[2]*context.AB[2][0]); + ra = WWMath::Fabsf_Legacy(context.Box0.Extent[0]*context.AB[1][1])+WWMath::Fabsf_Legacy(context.Box0.Extent[1]*context.AB[0][1]); + rb = WWMath::Fabsf_Legacy(context.Box1.Extent[0]*context.AB[2][2])+WWMath::Fabsf_Legacy(context.Box1.Extent[2]*context.AB[2][0]); if (obb_check_axis(context,ra,rb)) goto exit; } @@ -1265,8 +1265,8 @@ bool collide_obb_obb Vector3::Cross_Product(context.A[2],context.B[2],&context.TestAxis); context.TestAxisId = AXIS_A2B2; if (context.TestAxis.Length2() > AXISLEN_EPSILON2) { - ra = WWMath::Fabs(context.Box0.Extent[0]*context.AB[1][2])+WWMath::Fabs(context.Box0.Extent[1]*context.AB[0][2]); - rb = WWMath::Fabs(context.Box1.Extent[0]*context.AB[2][1])+WWMath::Fabs(context.Box1.Extent[1]*context.AB[2][0]); + ra = WWMath::Fabsf_Legacy(context.Box0.Extent[0]*context.AB[1][2])+WWMath::Fabsf_Legacy(context.Box0.Extent[1]*context.AB[0][2]); + rb = WWMath::Fabsf_Legacy(context.Box1.Extent[0]*context.AB[2][1])+WWMath::Fabsf_Legacy(context.Box1.Extent[1]*context.AB[2][0]); if (obb_check_axis(context,ra,rb)) goto exit; } diff --git a/Core/Libraries/Source/WWVegas/WWMath/colmathobbox.cpp b/Core/Libraries/Source/WWVegas/WWMath/colmathobbox.cpp index 8dd15f3ad16..b2a3784039a 100644 --- a/Core/Libraries/Source/WWVegas/WWMath/colmathobbox.cpp +++ b/Core/Libraries/Source/WWVegas/WWMath/colmathobbox.cpp @@ -59,13 +59,13 @@ CollisionMath::Overlap_Test(const OBBoxClass & box,const Vector3 & point) Matrix3x3::Transpose_Rotate_Vector(box.Basis,(point - box.Center),&localpoint); // if the point is outside any of the extents, it is outside the box - if (WWMath::Fabs(localpoint.X) > box.Extent.X) { + if (WWMath::Fabsf_Legacy(localpoint.X) > box.Extent.X) { return OUTSIDE; } - if (WWMath::Fabs(localpoint.Y) > box.Extent.Y) { + if (WWMath::Fabsf_Legacy(localpoint.Y) > box.Extent.Y) { return OUTSIDE; } - if (WWMath::Fabs(localpoint.Z) > box.Extent.Z) { + if (WWMath::Fabsf_Legacy(localpoint.Z) > box.Extent.Z) { return OUTSIDE; } return INSIDE; diff --git a/Core/Libraries/Source/WWVegas/WWMath/colmathobbtri.cpp b/Core/Libraries/Source/WWVegas/WWMath/colmathobbtri.cpp index 1b3418efb59..246fc092371 100644 --- a/Core/Libraries/Source/WWVegas/WWMath/colmathobbtri.cpp +++ b/Core/Libraries/Source/WWVegas/WWMath/colmathobbtri.cpp @@ -313,9 +313,9 @@ static inline bool obbtri_check_collision_axis(BTCollisionStruct & context) } // compute coordinates of the leading edge of the box at t0 and t1 - leb0 = context.Box.Extent.X * WWMath::Fabs(Vector3::Dot_Product(context.TestAxis,context.A[0])) + - context.Box.Extent.Y * WWMath::Fabs(Vector3::Dot_Product(context.TestAxis,context.A[1])) + - context.Box.Extent.Z * WWMath::Fabs(Vector3::Dot_Product(context.TestAxis,context.A[2])); + leb0 = context.Box.Extent.X * WWMath::Fabsf_Legacy(Vector3::Dot_Product(context.TestAxis,context.A[0])) + + context.Box.Extent.Y * WWMath::Fabsf_Legacy(Vector3::Dot_Product(context.TestAxis,context.A[1])) + + context.Box.Extent.Z * WWMath::Fabsf_Legacy(Vector3::Dot_Product(context.TestAxis,context.A[2])); leb1 = leb0 + axismove; // compute coordinate of "leading edge of the triangle" relative to the box center. @@ -479,9 +479,9 @@ static inline bool obbtri_check_collision_normal_axis(BTCollisionStruct & contex context.TestSide = 1.0f; } - leb0 = context.Box.Extent.X * WWMath::Fabs(context.AN[0]) + - context.Box.Extent.Y * WWMath::Fabs(context.AN[1]) + - context.Box.Extent.Z * WWMath::Fabs(context.AN[2]); + leb0 = context.Box.Extent.X * WWMath::Fabsf_Legacy(context.AN[0]) + + context.Box.Extent.Y * WWMath::Fabsf_Legacy(context.AN[1]) + + context.Box.Extent.Z * WWMath::Fabsf_Legacy(context.AN[2]); leb1 = leb0 + axismove; context.TestPoint = 0; lp = dist; // this is the "optimization", don't have to find lp @@ -610,7 +610,7 @@ static inline void eval_A0_point(const BTCollisionStruct & context,float * x,int if (context.Point == 0) { yval = 0.0f; } else { yval = 1.0f; } den = Vector3::Dot_Product(context.N,context.AxE[0][edge]); - if (WWMath::Fabs(den) > 0.0f) { + if (WWMath::Fabsf_Legacy(den) > 0.0f) { Vector3::Cross_Product(context.FinalD,context.E[edge],&DxE); x[0] = Vector3::Dot_Product(context.N,DxE); @@ -653,7 +653,7 @@ static inline void eval_A1_point(const BTCollisionStruct & context,float * x,int if (context.Point == 0) { yval = 0.0f; } else { yval = 1.0f; } den = Vector3::Dot_Product(context.N,context.AxE[1][edge]); - if (WWMath::Fabs(den) > 0.0f) { + if (WWMath::Fabsf_Legacy(den) > 0.0f) { Vector3::Cross_Product(context.FinalD,context.E[edge],&DxE); x[1] = Vector3::Dot_Product(context.N,DxE); @@ -695,7 +695,7 @@ static inline void eval_A2_point(const BTCollisionStruct & context,float * x,int if (context.Point == 0) { yval = 0.0f; } else { yval = 1.0f; } den = Vector3::Dot_Product(context.N,context.AxE[2][edge]); - if (WWMath::Fabs(den) > 0.0f) { + if (WWMath::Fabsf_Legacy(den) > 0.0f) { Vector3::Cross_Product(context.FinalD,context.E[edge],&DxE); x[2] = Vector3::Dot_Product(context.N,DxE); @@ -937,7 +937,7 @@ bool CollisionMath::Collide context.TestAxisId = AXIS_A0E0; if (context.TestAxis.Length2() > AXISLEN_EPSILON2) { dp = context.AN[0]; - leb0 = box.Extent[1]*WWMath::Fabs(context.AE[2][0]) + box.Extent[2]*WWMath::Fabs(context.AE[1][0]); + leb0 = box.Extent[1]*WWMath::Fabsf_Legacy(context.AE[2][0]) + box.Extent[2]*WWMath::Fabsf_Legacy(context.AE[1][0]); if (obbtri_check_collision_cross_axis(context,dp,2,leb0)) goto exit; } @@ -949,7 +949,7 @@ bool CollisionMath::Collide context.TestAxisId = AXIS_A0E1; if (context.TestAxis.Length2() > AXISLEN_EPSILON2) { dp = -context.AN[0]; - leb0 = box.Extent[1]*WWMath::Fabs(context.AE[2][1]) + box.Extent[2]*WWMath::Fabs(context.AE[1][1]); + leb0 = box.Extent[1]*WWMath::Fabsf_Legacy(context.AE[2][1]) + box.Extent[2]*WWMath::Fabsf_Legacy(context.AE[1][1]); if (obbtri_check_collision_cross_axis(context,dp,1,leb0)) goto exit; } @@ -963,7 +963,7 @@ bool CollisionMath::Collide context.AE[2][2] = Vector3::Dot_Product(context.A[2],context.E[2]); if (context.TestAxis.Length2() > AXISLEN_EPSILON2) { dp = -context.AN[0]; - leb0 = box.Extent[1]*WWMath::Fabs(context.AE[2][2]) + box.Extent[2]*WWMath::Fabs(context.AE[1][2]); + leb0 = box.Extent[1]*WWMath::Fabsf_Legacy(context.AE[2][2]) + box.Extent[2]*WWMath::Fabsf_Legacy(context.AE[1][2]); if (obbtri_check_collision_cross_axis(context,dp,1,leb0)) goto exit; } @@ -975,7 +975,7 @@ bool CollisionMath::Collide context.TestAxisId = AXIS_A1E0; if (context.TestAxis.Length2() > AXISLEN_EPSILON2) { dp = context.AN[1]; - leb0 = box.Extent[0]*WWMath::Fabs(context.AE[2][0]) + box.Extent[2]*WWMath::Fabs(context.AE[0][0]); + leb0 = box.Extent[0]*WWMath::Fabsf_Legacy(context.AE[2][0]) + box.Extent[2]*WWMath::Fabsf_Legacy(context.AE[0][0]); if (obbtri_check_collision_cross_axis(context,dp,2,leb0)) goto exit; } @@ -987,7 +987,7 @@ bool CollisionMath::Collide context.TestAxisId = AXIS_A1E1; if (context.TestAxis.Length2() > AXISLEN_EPSILON2) { dp = -context.AN[1]; - leb0 = box.Extent[0]*WWMath::Fabs(context.AE[2][1]) + box.Extent[2]*WWMath::Fabs(context.AE[0][1]); + leb0 = box.Extent[0]*WWMath::Fabsf_Legacy(context.AE[2][1]) + box.Extent[2]*WWMath::Fabsf_Legacy(context.AE[0][1]); if (obbtri_check_collision_cross_axis(context,dp,1,leb0)) goto exit; } @@ -1000,7 +1000,7 @@ bool CollisionMath::Collide context.AE[0][2] = Vector3::Dot_Product(context.A[0],context.E[2]); if (context.TestAxis.Length2() > AXISLEN_EPSILON2) { dp = -context.AN[1]; - leb0 = box.Extent[0]*WWMath::Fabs(context.AE[2][2]) + box.Extent[2]*WWMath::Fabs(context.AE[0][2]); + leb0 = box.Extent[0]*WWMath::Fabsf_Legacy(context.AE[2][2]) + box.Extent[2]*WWMath::Fabsf_Legacy(context.AE[0][2]); if (obbtri_check_collision_cross_axis(context,dp,1,leb0)) goto exit; } @@ -1012,7 +1012,7 @@ bool CollisionMath::Collide context.TestAxisId = AXIS_A2E0; if (context.TestAxis.Length2() > AXISLEN_EPSILON2) { dp = context.AN[2]; - leb0 = box.Extent[0]*WWMath::Fabs(context.AE[1][0]) + box.Extent[1]*WWMath::Fabs(context.AE[0][0]); + leb0 = box.Extent[0]*WWMath::Fabsf_Legacy(context.AE[1][0]) + box.Extent[1]*WWMath::Fabsf_Legacy(context.AE[0][0]); if (obbtri_check_collision_cross_axis(context,dp,2,leb0)) goto exit; } @@ -1024,7 +1024,7 @@ bool CollisionMath::Collide context.TestAxisId = AXIS_A2E1; if (context.TestAxis.Length2() > AXISLEN_EPSILON2) { dp = -context.AN[2]; - leb0 = box.Extent[0]*WWMath::Fabs(context.AE[1][1]) + box.Extent[1]*WWMath::Fabs(context.AE[0][1]); + leb0 = box.Extent[0]*WWMath::Fabsf_Legacy(context.AE[1][1]) + box.Extent[1]*WWMath::Fabsf_Legacy(context.AE[0][1]); if (obbtri_check_collision_cross_axis(context,dp,1,leb0)) goto exit; } @@ -1036,7 +1036,7 @@ bool CollisionMath::Collide context.TestAxisId = AXIS_A2E2; if (context.TestAxis.Length2() > AXISLEN_EPSILON2) { dp = -context.AN[2]; - leb0 = box.Extent[0]*WWMath::Fabs(context.AE[1][2]) + box.Extent[1]*WWMath::Fabs(context.AE[0][2]); + leb0 = box.Extent[0]*WWMath::Fabsf_Legacy(context.AE[1][2]) + box.Extent[1]*WWMath::Fabsf_Legacy(context.AE[0][2]); if (obbtri_check_collision_cross_axis(context,dp,1,leb0)) goto exit; } @@ -1098,7 +1098,7 @@ bool CollisionMath::Collide Vector3 normal; obbtri_compute_contact_normal(context,&normal); - if ( (WWMath::Fabs(context.MaxFrac - result->Fraction) > WWMATH_EPSILON) || + if ( (WWMath::Fabsf_Legacy(context.MaxFrac - result->Fraction) > WWMATH_EPSILON) || (Vector3::Dot_Product(normal,move) < Vector3::Dot_Product(result->Normal,move)) ) { result->Normal = normal; //obbtri_compute_contact_normal(context,result); @@ -1337,9 +1337,9 @@ static inline bool obbtri_check_intersection_normal_axis dist = -dist; } - leb0 = context.Box.Extent.X * WWMath::Fabs(context.AN[0]) + - context.Box.Extent.Y * WWMath::Fabs(context.AN[1]) + - context.Box.Extent.Z * WWMath::Fabs(context.AN[2]); + leb0 = context.Box.Extent.X * WWMath::Fabsf_Legacy(context.AN[0]) + + context.Box.Extent.Y * WWMath::Fabsf_Legacy(context.AN[1]) + + context.Box.Extent.Z * WWMath::Fabsf_Legacy(context.AN[2]); lp = dist; // this is the "optimization", don't have to find lp return obbtri_intersection_separation_test(context,lp,leb0); @@ -1408,7 +1408,7 @@ bool CollisionMath::Intersection_Test(const OBBoxClass & box,const TriClass & tr context.TestAxis = context.AxE[0][0]; if (context.TestAxis.Length2() > AXISLEN_EPSILON2) { dp = context.AN[0]; - leb0 = box.Extent[1]*WWMath::Fabs(context.AE[2][0]) + box.Extent[2]*WWMath::Fabs(context.AE[1][0]); + leb0 = box.Extent[1]*WWMath::Fabsf_Legacy(context.AE[2][0]) + box.Extent[2]*WWMath::Fabsf_Legacy(context.AE[1][0]); if (obbtri_check_intersection_cross_axis(context,dp,leb0)) return false; } @@ -1419,7 +1419,7 @@ bool CollisionMath::Intersection_Test(const OBBoxClass & box,const TriClass & tr context.TestAxis = context.AxE[0][1]; if (context.TestAxis.Length2() > AXISLEN_EPSILON2) { dp = -context.AN[0]; - leb0 = box.Extent[1]*WWMath::Fabs(context.AE[2][1]) + box.Extent[2]*WWMath::Fabs(context.AE[1][1]); + leb0 = box.Extent[1]*WWMath::Fabsf_Legacy(context.AE[2][1]) + box.Extent[2]*WWMath::Fabsf_Legacy(context.AE[1][1]); if (obbtri_check_intersection_cross_axis(context,dp,leb0)) return false; } @@ -1432,7 +1432,7 @@ bool CollisionMath::Intersection_Test(const OBBoxClass & box,const TriClass & tr context.AE[2][2] = Vector3::Dot_Product(context.A[2],context.E[2]); if (context.TestAxis.Length2() > AXISLEN_EPSILON2) { dp = -context.AN[0]; - leb0 = box.Extent[1]*WWMath::Fabs(context.AE[2][2]) + box.Extent[2]*WWMath::Fabs(context.AE[1][2]); + leb0 = box.Extent[1]*WWMath::Fabsf_Legacy(context.AE[2][2]) + box.Extent[2]*WWMath::Fabsf_Legacy(context.AE[1][2]); if (obbtri_check_intersection_cross_axis(context,dp,leb0)) return false; } @@ -1443,7 +1443,7 @@ bool CollisionMath::Intersection_Test(const OBBoxClass & box,const TriClass & tr context.TestAxis = context.AxE[1][0]; if (context.TestAxis.Length2() > AXISLEN_EPSILON2) { dp = context.AN[1]; - leb0 = box.Extent[0]*WWMath::Fabs(context.AE[2][0]) + box.Extent[2]*WWMath::Fabs(context.AE[0][0]); + leb0 = box.Extent[0]*WWMath::Fabsf_Legacy(context.AE[2][0]) + box.Extent[2]*WWMath::Fabsf_Legacy(context.AE[0][0]); if (obbtri_check_intersection_cross_axis(context,dp,leb0)) return false; } @@ -1454,7 +1454,7 @@ bool CollisionMath::Intersection_Test(const OBBoxClass & box,const TriClass & tr context.TestAxis = context.AxE[1][1]; if (context.TestAxis.Length2() > AXISLEN_EPSILON2) { dp = -context.AN[1]; - leb0 = box.Extent[0]*WWMath::Fabs(context.AE[2][1]) + box.Extent[2]*WWMath::Fabs(context.AE[0][1]); + leb0 = box.Extent[0]*WWMath::Fabsf_Legacy(context.AE[2][1]) + box.Extent[2]*WWMath::Fabsf_Legacy(context.AE[0][1]); if (obbtri_check_intersection_cross_axis(context,dp,leb0)) return false; } @@ -1466,7 +1466,7 @@ bool CollisionMath::Intersection_Test(const OBBoxClass & box,const TriClass & tr context.AE[0][2] = Vector3::Dot_Product(context.A[0],context.E[2]); if (context.TestAxis.Length2() > AXISLEN_EPSILON2) { dp = -context.AN[1]; - leb0 = box.Extent[0]*WWMath::Fabs(context.AE[2][2]) + box.Extent[2]*WWMath::Fabs(context.AE[0][2]); + leb0 = box.Extent[0]*WWMath::Fabsf_Legacy(context.AE[2][2]) + box.Extent[2]*WWMath::Fabsf_Legacy(context.AE[0][2]); if (obbtri_check_intersection_cross_axis(context,dp,leb0)) return false; } @@ -1477,7 +1477,7 @@ bool CollisionMath::Intersection_Test(const OBBoxClass & box,const TriClass & tr context.TestAxis = context.AxE[2][0]; if (context.TestAxis.Length2() > AXISLEN_EPSILON2) { dp = context.AN[2]; - leb0 = box.Extent[0]*WWMath::Fabs(context.AE[1][0]) + box.Extent[1]*WWMath::Fabs(context.AE[0][0]); + leb0 = box.Extent[0]*WWMath::Fabsf_Legacy(context.AE[1][0]) + box.Extent[1]*WWMath::Fabsf_Legacy(context.AE[0][0]); if (obbtri_check_intersection_cross_axis(context,dp,leb0)) return false; } @@ -1488,7 +1488,7 @@ bool CollisionMath::Intersection_Test(const OBBoxClass & box,const TriClass & tr context.TestAxis = context.AxE[2][1]; if (context.TestAxis.Length2() > AXISLEN_EPSILON2) { dp = -context.AN[2]; - leb0 = box.Extent[0]*WWMath::Fabs(context.AE[1][1]) + box.Extent[1]*WWMath::Fabs(context.AE[0][1]); + leb0 = box.Extent[0]*WWMath::Fabsf_Legacy(context.AE[1][1]) + box.Extent[1]*WWMath::Fabsf_Legacy(context.AE[0][1]); if (obbtri_check_intersection_cross_axis(context,dp,leb0)) return false; } @@ -1499,7 +1499,7 @@ bool CollisionMath::Intersection_Test(const OBBoxClass & box,const TriClass & tr context.TestAxis = context.AxE[2][2]; if (context.TestAxis.Length2() > AXISLEN_EPSILON2) { dp = -context.AN[2]; - leb0 = box.Extent[0]*WWMath::Fabs(context.AE[1][2]) + box.Extent[1]*WWMath::Fabs(context.AE[0][2]); + leb0 = box.Extent[0]*WWMath::Fabsf_Legacy(context.AE[1][2]) + box.Extent[1]*WWMath::Fabsf_Legacy(context.AE[0][2]); if (obbtri_check_intersection_cross_axis(context,dp,leb0)) return false; } diff --git a/Core/Libraries/Source/WWVegas/WWMath/colmathsphere.cpp b/Core/Libraries/Source/WWVegas/WWMath/colmathsphere.cpp index 1485c2efc19..13da0114ce1 100644 --- a/Core/Libraries/Source/WWVegas/WWMath/colmathsphere.cpp +++ b/Core/Libraries/Source/WWVegas/WWMath/colmathsphere.cpp @@ -75,9 +75,9 @@ bool CollisionMath::Intersection_Test(const SphereClass & sphere,const AABoxClas ** against a cube which encloses the sphere... */ Vector3 dc = box.Center - sphere.Center; - if (WWMath::Fabs(dc.X) < box.Extent.X + sphere.Radius) return false; - if (WWMath::Fabs(dc.Y) < box.Extent.Y + sphere.Radius) return false; - if (WWMath::Fabs(dc.Z) < box.Extent.Z + sphere.Radius) return false; + if (WWMath::Fabsf_Legacy(dc.X) < box.Extent.X + sphere.Radius) return false; + if (WWMath::Fabsf_Legacy(dc.Y) < box.Extent.Y + sphere.Radius) return false; + if (WWMath::Fabsf_Legacy(dc.Z) < box.Extent.Z + sphere.Radius) return false; return true; } @@ -103,9 +103,9 @@ bool CollisionMath::Intersection_Test(const SphereClass & sphere,const OBBoxClas Vector3 box_rel_center; Matrix3D::Inverse_Transform_Vector(tm,sphere.Center,&box_rel_center); - if (box.Extent.X < WWMath::Fabs(box_rel_center.X)) return false; - if (box.Extent.Y < WWMath::Fabs(box_rel_center.Y)) return false; - if (box.Extent.Z < WWMath::Fabs(box_rel_center.Z)) return false; + if (box.Extent.X < WWMath::Fabsf_Legacy(box_rel_center.X)) return false; + if (box.Extent.Y < WWMath::Fabsf_Legacy(box_rel_center.Y)) return false; + if (box.Extent.Z < WWMath::Fabsf_Legacy(box_rel_center.Z)) return false; return true; } diff --git a/Core/Libraries/Source/WWVegas/WWMath/euler.cpp b/Core/Libraries/Source/WWVegas/WWMath/euler.cpp index 5cf23f242b4..9685ec39705 100644 --- a/Core/Libraries/Source/WWVegas/WWMath/euler.cpp +++ b/Core/Libraries/Source/WWVegas/WWMath/euler.cpp @@ -180,35 +180,35 @@ void EulerAnglesClass::From_Matrix(const Matrix3D & M, int order) _euler_unpack_order(order,i,j,k,h,n,s,f); if (s == EULER_REPEAT_YES) { - double sy = sqrt(M[i][j]*M[i][j] + M[i][k]*M[i][k]); + double sy = WWMath::Sqrt(M[i][j]*M[i][j] + M[i][k]*M[i][k]); if (sy > 16*FLT_EPSILON) { - Angle[0] = WWMath::Atan2(M[i][j],M[i][k]); - Angle[1] = WWMath::Atan2(sy,M[i][i]); - Angle[2] = WWMath::Atan2(M[j][i],-M[k][i]); + Angle[0] = WWMath::Atan2_Legacy(M[i][j],M[i][k]); + Angle[1] = WWMath::Atan2_Legacy(sy,M[i][i]); + Angle[2] = WWMath::Atan2_Legacy(M[j][i],-M[k][i]); } else { - Angle[0] = WWMath::Atan2(-M[j][k],M[j][j]); - Angle[1] = WWMath::Atan2(sy,M[i][i]); + Angle[0] = WWMath::Atan2_Legacy(-M[j][k],M[j][j]); + Angle[1] = WWMath::Atan2_Legacy(sy,M[i][i]); Angle[2] = 0.0; } } else { - double cy = sqrt(M[i][i]*M[i][i] + M[j][i]*M[j][i]); + double cy = WWMath::Sqrt(M[i][i]*M[i][i] + M[j][i]*M[j][i]); if (cy > 16*FLT_EPSILON) { - Angle[0] = WWMath::Atan2(M[k][j],M[k][k]); - Angle[1] = WWMath::Atan2(-M[k][i],cy); - Angle[2] = WWMath::Atan2(M[j][i],M[i][i]); + Angle[0] = WWMath::Atan2_Legacy(M[k][j],M[k][k]); + Angle[1] = WWMath::Atan2_Legacy(-M[k][i],cy); + Angle[2] = WWMath::Atan2_Legacy(M[j][i],M[i][i]); } else { - Angle[0] = WWMath::Atan2(-M[j][k],M[j][j]); - Angle[1] = WWMath::Atan2(-M[k][i],cy); + Angle[0] = WWMath::Atan2_Legacy(-M[j][k],M[j][j]); + Angle[1] = WWMath::Atan2_Legacy(-M[k][i],cy); Angle[2] = 0; } } @@ -284,8 +284,8 @@ void EulerAnglesClass::To_Matrix(Matrix3D & M) } ti = a0; tj = a1; th = a2; - ci = WWMath::Cos(ti); cj = WWMath::Cos(tj); ch = WWMath::Cos(th); - si = WWMath::Sin(ti); sj = WWMath::Sin(tj); sh = WWMath::Sin(th); + ci = WWMath::Cosf_Legacy(ti); cj = WWMath::Cosf_Legacy(tj); ch = WWMath::Cosf_Legacy(th); + si = WWMath::Sinf_Legacy(ti); sj = WWMath::Sinf_Legacy(tj); sh = WWMath::Sinf_Legacy(th); cc = ci*ch; cs = ci*sh; diff --git a/Core/Libraries/Source/WWVegas/WWMath/lookuptable.h b/Core/Libraries/Source/WWVegas/WWMath/lookuptable.h index 468f8e57d4d..8fe961bfaa7 100644 --- a/Core/Libraries/Source/WWVegas/WWMath/lookuptable.h +++ b/Core/Libraries/Source/WWVegas/WWMath/lookuptable.h @@ -86,7 +86,7 @@ inline float LookupTableClass::Get_Value(float input) } float normalized_input = (float)(OutputSamples.Length()-1) * (input - MinInputValue) * OOMaxMinusMin; - float input0 = WWMath::Floor(normalized_input); + float input0 = WWMath::Floorf(normalized_input); int index0 = WWMath::Float_To_Long(input0); int index1 = index0+1; diff --git a/Core/Libraries/Source/WWVegas/WWMath/matrix3.cpp b/Core/Libraries/Source/WWVegas/WWMath/matrix3.cpp index fa85c2396bf..c0b15e44186 100644 --- a/Core/Libraries/Source/WWVegas/WWMath/matrix3.cpp +++ b/Core/Libraries/Source/WWVegas/WWMath/matrix3.cpp @@ -338,9 +338,9 @@ int Matrix3x3::Is_Orthogonal() const if (Vector3::Dot_Product(y,z) > WWMATH_EPSILON) return 0; if (Vector3::Dot_Product(z,x) > WWMATH_EPSILON) return 0; - if (WWMath::Fabs(x.Length() - 1.0f) > WWMATH_EPSILON) return 0; - if (WWMath::Fabs(y.Length() - 1.0f) > WWMATH_EPSILON) return 0; - if (WWMath::Fabs(z.Length() - 1.0f) > WWMATH_EPSILON) return 0; + if (WWMath::Fabsf_Legacy(x.Length() - 1.0f) > WWMATH_EPSILON) return 0; + if (WWMath::Fabsf_Legacy(y.Length() - 1.0f) > WWMATH_EPSILON) return 0; + if (WWMath::Fabsf_Legacy(z.Length() - 1.0f) > WWMATH_EPSILON) return 0; return 1; } diff --git a/Core/Libraries/Source/WWVegas/WWMath/matrix3.h b/Core/Libraries/Source/WWVegas/WWMath/matrix3.h index 6fd98508d3b..07aa1ede0d3 100644 --- a/Core/Libraries/Source/WWVegas/WWMath/matrix3.h +++ b/Core/Libraries/Source/WWVegas/WWMath/matrix3.h @@ -361,12 +361,12 @@ WWINLINE Matrix3x3::Matrix3x3(const Vector3 & axis,float s_angle,float c_angle) WWINLINE void Matrix3x3::Set(const Vector3 & axis,float angle) { - Set(axis,sinf(angle),cosf(angle)); + Set(axis,WWMath::Sinf(angle),WWMath::Cosf(angle)); } WWINLINE void Matrix3x3::Set(const Vector3 & axis,float s,float c) { - WWASSERT(WWMath::Fabs(axis.Length2() - 1.0f) < 0.001f); + WWASSERT(WWMath::Fabsf_Legacy(axis.Length2() - 1.0f) < 0.001f); Row[0].Set( (float)(axis[0]*axis[0] + c*(1.0f - axis[0]*axis[0])), @@ -437,7 +437,7 @@ WWINLINE Matrix3x3 Matrix3x3::Inverse() const // Gauss-Jordan elimination wit // Find largest pivot in column j among rows j..3 i1 = j; for (i=j+1; i<3; i++) { - if (WWMath::Fabs(a[i][j]) > WWMath::Fabs(a[i1][j])) { + if (WWMath::Fabsf_Legacy(a[i][j]) > WWMath::Fabsf_Legacy(a[i1][j])) { i1 = i; } } @@ -589,7 +589,7 @@ WWINLINE Matrix3x3& Matrix3x3::operator /= (float d) WWINLINE float Matrix3x3::Get_X_Rotation() const { Vector3 v = (*this) * Vector3(0.0,1.0,0.0); - return WWMath::Atan2(v[2], v[1]); + return WWMath::Atan2_Legacy(v[2], v[1]); } /*********************************************************************************************** @@ -607,7 +607,7 @@ WWINLINE float Matrix3x3::Get_X_Rotation() const WWINLINE float Matrix3x3::Get_Y_Rotation() const { Vector3 v = (*this) * Vector3(0.0,0.0,1.0); - return WWMath::Atan2(v[0],v[2]); + return WWMath::Atan2_Legacy(v[0],v[2]); } /*********************************************************************************************** @@ -625,7 +625,7 @@ WWINLINE float Matrix3x3::Get_Y_Rotation() const WWINLINE float Matrix3x3::Get_Z_Rotation() const { Vector3 v = (*this) * Vector3(1.0,0.0,0.0); - return WWMath::Atan2(v[1],v[0]); + return WWMath::Atan2_Legacy(v[1],v[0]); } WWINLINE Vector3 Matrix3x3::Get_X_Vector() const @@ -775,7 +775,7 @@ WWINLINE int operator != (const Matrix3x3 & a, const Matrix3x3 & b) *=============================================================================================*/ WWINLINE void Matrix3x3::Rotate_X(float theta) { - Rotate_X(sinf(theta),cosf(theta)); + Rotate_X(WWMath::Sinf(theta),WWMath::Cosf(theta)); } WWINLINE void Matrix3x3::Rotate_X(float s,float c) @@ -809,7 +809,7 @@ WWINLINE void Matrix3x3::Rotate_X(float s,float c) *=============================================================================================*/ WWINLINE void Matrix3x3::Rotate_Y(float theta) { - Rotate_Y(sinf(theta),cosf(theta)); + Rotate_Y(WWMath::Sinf(theta),WWMath::Cosf(theta)); } WWINLINE void Matrix3x3::Rotate_Y(float s,float c) @@ -844,7 +844,7 @@ WWINLINE void Matrix3x3::Rotate_Y(float s,float c) *=============================================================================================*/ WWINLINE void Matrix3x3::Rotate_Z(float theta) { - Rotate_Z(sinf(theta),cosf(theta)); + Rotate_Z(WWMath::Sinf(theta),WWMath::Cosf(theta)); } WWINLINE void Matrix3x3::Rotate_Z(float s,float c) @@ -898,7 +898,7 @@ WWINLINE Matrix3x3 Create_X_Rotation_Matrix3(float s,float c) WWINLINE Matrix3x3 Create_X_Rotation_Matrix3(float rad) { - return Create_X_Rotation_Matrix3(sinf(rad),cosf(rad)); + return Create_X_Rotation_Matrix3(WWMath::Sinf(rad),WWMath::Cosf(rad)); } /*********************************************************************************************** @@ -934,7 +934,7 @@ WWINLINE Matrix3x3 Create_Y_Rotation_Matrix3(float s,float c) WWINLINE Matrix3x3 Create_Y_Rotation_Matrix3(float rad) { - return Create_Y_Rotation_Matrix3(sinf(rad),cosf(rad)); + return Create_Y_Rotation_Matrix3(WWMath::Sinf(rad),WWMath::Cosf(rad)); } /*********************************************************************************************** @@ -970,7 +970,7 @@ WWINLINE Matrix3x3 Create_Z_Rotation_Matrix3(float s,float c) WWINLINE Matrix3x3 Create_Z_Rotation_Matrix3(float rad) { - return Create_Z_Rotation_Matrix3(sinf(rad),cosf(rad)); + return Create_Z_Rotation_Matrix3(WWMath::Sinf(rad),WWMath::Cosf(rad)); } WWINLINE void Matrix3x3::Rotate_Vector(const Matrix3x3 & A,const Vector3 & in,Vector3 * out) @@ -1018,7 +1018,7 @@ WWINLINE void Matrix3x3::Rotate_AABox_Extent(const Vector3 & extent,Vector3 * se (*set_extent)[i] = 0.0f; for (int j=0; j<3; j++) { - (*set_extent)[i] += WWMath::Fabs(Row[i][j] * extent[j]); + (*set_extent)[i] += WWMath::Fabsf_Legacy(Row[i][j] * extent[j]); } } } diff --git a/Core/Libraries/Source/WWVegas/WWMath/matrix3d.cpp b/Core/Libraries/Source/WWVegas/WWMath/matrix3d.cpp index 5f2c886884a..1bb6b74abeb 100644 --- a/Core/Libraries/Source/WWVegas/WWMath/matrix3d.cpp +++ b/Core/Libraries/Source/WWVegas/WWMath/matrix3d.cpp @@ -248,7 +248,7 @@ void Matrix3D::Set_Rotation(const Quaternion & q) *=============================================================================================*/ float Matrix3D::Get_X_Rotation() const { - return WWMath::Atan2(Row[2][1], Row[1][1]); + return WWMath::Atan2_Legacy(Row[2][1], Row[1][1]); } @@ -266,7 +266,7 @@ float Matrix3D::Get_X_Rotation() const *=============================================================================================*/ float Matrix3D::Get_Y_Rotation() const { - return WWMath::Atan2(Row[0][2], Row[2][2]); + return WWMath::Atan2_Legacy(Row[0][2], Row[2][2]); } @@ -284,7 +284,7 @@ float Matrix3D::Get_Y_Rotation() const *=============================================================================================*/ float Matrix3D::Get_Z_Rotation() const { - return WWMath::Atan2(Row[1][0], Row[0][0]); + return WWMath::Atan2_Legacy(Row[1][0], Row[0][0]); } @@ -372,7 +372,7 @@ void Matrix3D::Look_At_Dir(const Vector3 &pos, const Vector3 &dir, float roll) float dz = dir.Z; // length of projection onto XY plane - float len2 = (float)WWMath::Sqrt(dx*dx + dy*dy); + float len2 = (float)WWMath::Sqrt_Legacy(dx*dx + dy*dy); // pitch sinp = dz; @@ -414,7 +414,7 @@ void Matrix3D::buildTransformMatrix( const Vector3 &pos, const Vector3 &dir ) float sinp, cosp; // sine and cosine of the pitch ("up-down" tilt about y) float siny, cosy; // sine and cosine of the yaw ("left-right"tilt about z) - float len2 = (float)sqrt( (dir.X * dir.X) + (dir.Y * dir.Y) ); + float len2 = (float)WWMath::Sqrt( (dir.X * dir.X) + (dir.Y * dir.Y) ); sinp = dir.Z; cosp = len2; @@ -472,8 +472,8 @@ void Matrix3D::Obj_Look_At(const Vector3 &p,const Vector3 &t,float roll) dy = (t[1] - p[1]); dz = (t[2] - p[2]); - len1 = (float)sqrt(dx*dx + dy*dy + dz*dz); - len2 = (float)sqrt(dx*dx + dy*dy); + len1 = (float)WWMath::Sqrt(dx*dx + dy*dy + dz*dz); + len2 = (float)WWMath::Sqrt(dx*dx + dy*dy); if (len1 != 0.0f) { sinp = dz/len1; @@ -552,7 +552,7 @@ Matrix3D * Matrix3D::Get_Inverse(Matrix3D * out, float * detOut, const Matrix3D if (detOut) *detOut = det; - if (fabsf(det) < 1e-8f) + if (WWMath::Fabsf(det) < 1e-8f) return NULL; const float invDet = 1.0f / det; @@ -1121,7 +1121,7 @@ void Matrix3D::Transform_Center_Extent_AABox for (int j=0; j<3; j++) { (*set_center)[i] += Row[i][j] * center[j]; - (*set_extent)[i] += WWMath::Fabs(Row[i][j] * extent[j]); + (*set_extent)[i] += WWMath::Fabsf_Legacy(Row[i][j] * extent[j]); } } @@ -1150,9 +1150,9 @@ int Matrix3D::Is_Orthogonal() const if (Vector3::Dot_Product(y,z) > WWMATH_EPSILON) return 0; if (Vector3::Dot_Product(z,x) > WWMATH_EPSILON) return 0; - if (WWMath::Fabs(x.Length2() - 1.0f) > WWMATH_EPSILON) return 0; - if (WWMath::Fabs(y.Length2() - 1.0f) > WWMATH_EPSILON) return 0; - if (WWMath::Fabs(z.Length2() - 1.0f) > WWMATH_EPSILON) return 0; + if (WWMath::Fabsf_Legacy(x.Length2() - 1.0f) > WWMATH_EPSILON) return 0; + if (WWMath::Fabsf_Legacy(y.Length2() - 1.0f) > WWMATH_EPSILON) return 0; + if (WWMath::Fabsf_Legacy(z.Length2() - 1.0f) > WWMATH_EPSILON) return 0; return 1; } diff --git a/Core/Libraries/Source/WWVegas/WWMath/matrix3d.h b/Core/Libraries/Source/WWVegas/WWMath/matrix3d.h index f5ab7d2e2ef..369ddafefa6 100644 --- a/Core/Libraries/Source/WWVegas/WWMath/matrix3d.h +++ b/Core/Libraries/Source/WWVegas/WWMath/matrix3d.h @@ -566,8 +566,8 @@ WWINLINE void Matrix3D::Set( const Vector3 &x, // x-axis unit vector *=============================================================================================*/ WWINLINE void Matrix3D::Set(const Vector3 & axis,float angle) { - float c = cosf(angle); - float s = sinf(angle); + float c = WWMath::Cosf(angle); + float s = WWMath::Sinf(angle); Set(axis,s,c); } @@ -586,7 +586,7 @@ WWINLINE void Matrix3D::Set(const Vector3 & axis,float angle) *=============================================================================================*/ WWINLINE void Matrix3D::Set(const Vector3 & axis,float s,float c) { - assert(WWMath::Fabs(axis.Length2() - 1.0f) < 0.001f); + assert(WWMath::Fabsf_Legacy(axis.Length2() - 1.0f) < 0.001f); Row[0].Set( (float)(axis[0]*axis[0] + c*(1.0f - axis[0]*axis[0])), @@ -768,8 +768,8 @@ WWINLINE void Matrix3D::Rotate_X(float theta) float tmp1,tmp2; float s,c; - s = sinf(theta); - c = cosf(theta); + s = WWMath::Sinf(theta); + c = WWMath::Cosf(theta); tmp1 = Row[0][1]; tmp2 = Row[0][2]; Row[0][1] = (float)( c*tmp1 + s*tmp2); @@ -836,8 +836,8 @@ WWINLINE void Matrix3D::Rotate_Y(float theta) float tmp1,tmp2; float s,c; - s = sinf(theta); - c = cosf(theta); + s = WWMath::Sinf(theta); + c = WWMath::Cosf(theta); tmp1 = Row[0][0]; tmp2 = Row[0][2]; Row[0][0] = (float)(c*tmp1 - s*tmp2); @@ -903,8 +903,8 @@ WWINLINE void Matrix3D::Rotate_Z(float theta) float tmp1,tmp2; float c,s; - c = cosf(theta); - s = sinf(theta); + c = WWMath::Cosf(theta); + s = WWMath::Sinf(theta); tmp1 = Row[0][0]; tmp2 = Row[0][1]; Row[0][0] = (float)( c*tmp1 + s*tmp2); @@ -1055,8 +1055,8 @@ WWINLINE void Matrix3D::Pre_Rotate_X(float theta) float tmp1,tmp2; float c,s; - c = cosf(theta); - s = sinf(theta); + c = WWMath::Cosf(theta); + s = WWMath::Sinf(theta); tmp1 = Row[1][0]; tmp2 = Row[2][0]; Row[1][0] = (float)(c*tmp1 - s*tmp2); @@ -1093,8 +1093,8 @@ WWINLINE void Matrix3D::Pre_Rotate_Y(float theta) float tmp1,tmp2; float c,s; - c = cosf(theta); - s = sinf(theta); + c = WWMath::Cosf(theta); + s = WWMath::Sinf(theta); tmp1 = Row[0][0]; tmp2 = Row[2][0]; Row[0][0] = (float)( c*tmp1 + s*tmp2); @@ -1131,8 +1131,8 @@ WWINLINE void Matrix3D::Pre_Rotate_Z(float theta) float tmp1,tmp2; float c,s; - c = cosf(theta); - s = sinf(theta); + c = WWMath::Cosf(theta); + s = WWMath::Sinf(theta); tmp1 = Row[0][0]; tmp2 = Row[1][0]; Row[0][0] = (float)(c*tmp1 - s*tmp2); @@ -1274,8 +1274,8 @@ WWINLINE void Matrix3D::In_Place_Pre_Rotate_X(float theta) float tmp1,tmp2; float c,s; - c = cosf(theta); - s = sinf(theta); + c = WWMath::Cosf(theta); + s = WWMath::Sinf(theta); tmp1 = Row[1][0]; tmp2 = Row[2][0]; Row[1][0] = (float)(c*tmp1 - s*tmp2); @@ -1308,8 +1308,8 @@ WWINLINE void Matrix3D::In_Place_Pre_Rotate_Y(float theta) float tmp1,tmp2; float c,s; - c = cosf(theta); - s = sinf(theta); + c = WWMath::Cosf(theta); + s = WWMath::Sinf(theta); tmp1 = Row[0][0]; tmp2 = Row[2][0]; Row[0][0] = (float)( c*tmp1 + s*tmp2); @@ -1342,8 +1342,8 @@ WWINLINE void Matrix3D::In_Place_Pre_Rotate_Z(float theta) float tmp1,tmp2; float c,s; - c = cosf(theta); - s = sinf(theta); + c = WWMath::Cosf(theta); + s = WWMath::Sinf(theta); tmp1 = Row[0][0]; tmp2 = Row[1][0]; Row[0][0] = (float)(c*tmp1 - s*tmp2); diff --git a/Core/Libraries/Source/WWVegas/WWMath/matrix4.h b/Core/Libraries/Source/WWVegas/WWMath/matrix4.h index 54d89395cc9..fa3406ebcd5 100644 --- a/Core/Libraries/Source/WWVegas/WWMath/matrix4.h +++ b/Core/Libraries/Source/WWVegas/WWMath/matrix4.h @@ -574,7 +574,7 @@ WWINLINE Matrix4x4* Matrix4x4::Inverse(Matrix4x4* out, float* detOut, const Matr if (detOut) *detOut = det; - if (fabsf(det) < 1e-8f) + if (WWMath::Fabsf(det) < 1e-8f) return NULL; const float invDet = 1.0f / det; diff --git a/Core/Libraries/Source/WWVegas/WWMath/obbox.cpp b/Core/Libraries/Source/WWVegas/WWMath/obbox.cpp index 68aa7c48456..b6f82984c17 100644 --- a/Core/Libraries/Source/WWVegas/WWMath/obbox.cpp +++ b/Core/Libraries/Source/WWVegas/WWMath/obbox.cpp @@ -161,13 +161,13 @@ OBBoxClass::OBBoxClass(const Vector3 * /*points*/, int /*n*/) float dx = pt[i].x - box.center.x; float dy = pt[i].y - box.center.y; float dz = pt[i].z - box.center.z; - float absdot = float(WWMath::Fabs(U.x*dx+U.y*dy+U.z*dz)); + float absdot = float(WWMath::Fabsf(U.x*dx+U.y*dy+U.z*dz)); if ( absdot > amax ) amax = absdot; - absdot = float(WWMath::Fabs(V.x*dx+V.y*dy+V.z*dz)); + absdot = float(WWMath::Fabsf(V.x*dx+V.y*dy+V.z*dz)); if ( absdot > bmax ) bmax = absdot; - absdot = float(WWMath::Fabs(W.x*dx+W.y*dy+W.z*dz)); + absdot = float(WWMath::Fabsf(W.x*dx+W.y*dy+W.z*dz)); if ( absdot > cmax ) cmax = absdot; } @@ -264,13 +264,13 @@ void OBBoxClass::Init_From_Box_Points(Vector3 * points,int num) float dy = points[i].Y - Center.Y; float dz = points[i].Z - Center.Z; - float xprj = float(WWMath::Fabs(axis0.X * dx + axis0.Y * dy + axis0.Z * dz)); + float xprj = float(WWMath::Fabsf_Legacy(axis0.X * dx + axis0.Y * dy + axis0.Z * dz)); if (xprj > Extent.X) Extent.X = xprj; - float yprj = float(WWMath::Fabs(axis1.X * dx + axis1.Y * dy + axis1.Z * dz)); + float yprj = float(WWMath::Fabsf_Legacy(axis1.X * dx + axis1.Y * dy + axis1.Z * dz)); if (yprj > Extent.Y) Extent.Y = yprj; - float zprj = float(WWMath::Fabs(axis2.X * dx + axis2.Y * dy + axis2.Z * dz)); + float zprj = float(WWMath::Fabsf_Legacy(axis2.X * dx + axis2.Y * dy + axis2.Z * dz)); if (zprj > Extent.Z) Extent.Z = zprj; } } @@ -334,7 +334,7 @@ bool Oriented_Boxes_Intersect_On_Axis ra = box0.Project_To_Axis(axis); rb = box1.Project_To_Axis(axis); - rsum = WWMath::Fabs(ra) + WWMath::Fabs(rb); + rsum = WWMath::Fabsf_Legacy(ra) + WWMath::Fabsf_Legacy(rb); // project the center distance onto the line: Vector3 C = box1.Center - box0.Center; @@ -456,7 +456,7 @@ bool Oriented_Boxes_Collide_On_Axis ra = box0.Project_To_Axis(axis); rb = box1.Project_To_Axis(axis); - rsum = WWMath::Fabs(ra) + WWMath::Fabs(rb); + rsum = WWMath::Fabsf_Legacy(ra) + WWMath::Fabsf_Legacy(rb); // project the center distance onto the line: Vector3 C = box1.Center - box0.Center; diff --git a/Core/Libraries/Source/WWVegas/WWMath/obbox.h b/Core/Libraries/Source/WWVegas/WWMath/obbox.h index 69625f9b056..22508bc5d3c 100644 --- a/Core/Libraries/Source/WWVegas/WWMath/obbox.h +++ b/Core/Libraries/Source/WWVegas/WWMath/obbox.h @@ -136,7 +136,7 @@ inline float OBBoxClass::Project_To_Axis(const Vector3 & axis) const float z = Extent[2] * Vector3::Dot_Product(axis,Vector3(Basis[0][2],Basis[1][2],Basis[2][2])); // projection is the sum of the absolute values of the projections of the three extents - return (WWMath::Fabs(x) + WWMath::Fabs(y) + WWMath::Fabs(z)); + return (WWMath::Fabsf_Legacy(x) + WWMath::Fabsf_Legacy(y) + WWMath::Fabsf_Legacy(z)); } @@ -214,17 +214,17 @@ inline void OBBoxClass::Compute_Axis_Aligned_Extent(Vector3 * set_extent) const WWASSERT(set_extent != nullptr); // x extent is the box projected onto the x axis - set_extent->X = WWMath::Fabs(Extent[0] * Basis[0][0]) + - WWMath::Fabs(Extent[1] * Basis[0][1]) + - WWMath::Fabs(Extent[2] * Basis[0][2]); + set_extent->X = WWMath::Fabsf_Legacy(Extent[0] * Basis[0][0]) + + WWMath::Fabsf_Legacy(Extent[1] * Basis[0][1]) + + WWMath::Fabsf_Legacy(Extent[2] * Basis[0][2]); - set_extent->Y = WWMath::Fabs(Extent[0] * Basis[1][0]) + - WWMath::Fabs(Extent[1] * Basis[1][1]) + - WWMath::Fabs(Extent[2] * Basis[1][2]); + set_extent->Y = WWMath::Fabsf_Legacy(Extent[0] * Basis[1][0]) + + WWMath::Fabsf_Legacy(Extent[1] * Basis[1][1]) + + WWMath::Fabsf_Legacy(Extent[2] * Basis[1][2]); - set_extent->Z = WWMath::Fabs(Extent[0] * Basis[2][0]) + - WWMath::Fabs(Extent[1] * Basis[2][1]) + - WWMath::Fabs(Extent[2] * Basis[2][2]); + set_extent->Z = WWMath::Fabsf_Legacy(Extent[0] * Basis[2][0]) + + WWMath::Fabsf_Legacy(Extent[1] * Basis[2][1]) + + WWMath::Fabsf_Legacy(Extent[2] * Basis[2][2]); } diff --git a/Core/Libraries/Source/WWVegas/WWMath/quat.cpp b/Core/Libraries/Source/WWVegas/WWMath/quat.cpp index d262891f412..cc119ac72d6 100644 --- a/Core/Libraries/Source/WWVegas/WWMath/quat.cpp +++ b/Core/Libraries/Source/WWVegas/WWMath/quat.cpp @@ -87,8 +87,8 @@ static float project_to_sphere(float,float,float); *=============================================================================================*/ Quaternion::Quaternion(const Vector3 & axis,float angle) { - float s = WWMath::Sin(angle/2); - float c = WWMath::Cos(angle/2); + float s = WWMath::Sinf_Legacy(angle/2); + float c = WWMath::Cosf_Legacy(angle/2); X = s * axis.X; Y = s * axis.Y; Z = s * axis.Z; @@ -114,7 +114,7 @@ void Quaternion::Normalize() if (0.0f == len2) { return; } else { - float inv_mag = WWMath::Inv_Sqrt(len2); + float inv_mag = WWMath::Inv_Sqrt_Legacy(len2); X *= inv_mag; Y *= inv_mag; @@ -200,7 +200,7 @@ Quaternion Trackball(float x0, float y0, float x1, float y1, float sphsize) // Avoid problems with out of control values if (t > 1.0f) t = 1.0f; if (t < -1.0f) t = -1.0f; - phi = 2.0f * WWMath::Asin(t); + phi = 2.0f * WWMath::Asin_Legacy(t); return Axis_To_Quat(a, phi); } @@ -228,8 +228,8 @@ Quaternion Axis_To_Quat(const Vector3 &a, float phi) q[1] = tmp[1]; q[2] = tmp[2]; - q.Scale(WWMath::Sin(phi / 2.0f)); - q[3] = WWMath::Cos(phi / 2.0f); + q.Scale(WWMath::Sinf_Legacy(phi / 2.0f)); + q[3] = WWMath::Cosf_Legacy(phi / 2.0f); return q; } @@ -324,11 +324,11 @@ void __cdecl Fast_Slerp(Quaternion& res, const Quaternion & p,const Quaternion & // ---------------------------------------------------------------------------- // normal slerp! // else { -// theta = WWMath::Acos(cos_t); -// sin_t = WWMath::Sin(theta); +// theta = WWMath::Acos_Legacy(cos_t); +// sin_t = WWMath::Sinf_Legacy(theta); // oo_sin_t = 1.0 / sin_t; -// beta = WWMath::Sin(theta - alpha*theta) * oo_sin_t; -// alpha = WWMath::Sin(alpha*theta) * oo_sin_t; +// beta = WWMath::Sinf_Legacy(theta - alpha*theta) * oo_sin_t; +// alpha = WWMath::Sinf_Legacy(alpha*theta) * oo_sin_t; // } // if (qflip) { // alpha = -alpha; @@ -512,11 +512,11 @@ void Slerp(Quaternion& res, const Quaternion & p,const Quaternion & q,float alph } else { // normal slerp! - theta = WWMath::Acos(cos_t); - float sin_t = WWMath::Sin(theta); + theta = WWMath::Acos_Legacy(cos_t); + float sin_t = WWMath::Sinf_Legacy(theta); oo_sin_t = 1.0f / sin_t; - beta = WWMath::Sin(theta - alpha*theta) * oo_sin_t; - alpha = WWMath::Sin(alpha*theta) * oo_sin_t; + beta = WWMath::Sinf_Legacy(theta - alpha*theta) * oo_sin_t; + alpha = WWMath::Sinf_Legacy(alpha*theta) * oo_sin_t; } if (qflip) { @@ -567,8 +567,8 @@ void Slerp_Setup(const Quaternion & p,const Quaternion & q,SlerpInfoStruct * sle } else { slerpinfo->Linear = false; - slerpinfo->Theta = WWMath::Acos(cos_t); - slerpinfo->SinT = WWMath::Sin(slerpinfo->Theta); + slerpinfo->Theta = WWMath::Acos_Legacy(cos_t); + slerpinfo->SinT = WWMath::Sinf_Legacy(slerpinfo->Theta); } } @@ -600,8 +600,8 @@ Quaternion Cached_Slerp(const Quaternion & p,const Quaternion & q,float alpha,Sl // normal slerp! oo_sin_t = 1.0f / slerpinfo->Theta; - beta = WWMath::Sin(slerpinfo->Theta - alpha*slerpinfo->Theta) * oo_sin_t; - alpha = WWMath::Sin(alpha*slerpinfo->Theta) * oo_sin_t; + beta = WWMath::Sinf_Legacy(slerpinfo->Theta - alpha*slerpinfo->Theta) * oo_sin_t; + alpha = WWMath::Sinf_Legacy(alpha*slerpinfo->Theta) * oo_sin_t; } if (slerpinfo->Flip) { @@ -632,8 +632,8 @@ void Cached_Slerp(const Quaternion & p,const Quaternion & q,float alpha,SlerpInf // normal slerp! oo_sin_t = 1.0f / slerpinfo->Theta; - beta = WWMath::Sin(slerpinfo->Theta - alpha*slerpinfo->Theta) * oo_sin_t; - alpha = WWMath::Sin(alpha*slerpinfo->Theta) * oo_sin_t; + beta = WWMath::Sinf_Legacy(slerpinfo->Theta - alpha*slerpinfo->Theta) * oo_sin_t; + alpha = WWMath::Sinf_Legacy(alpha*slerpinfo->Theta) * oo_sin_t; } if (slerpinfo->Flip) { @@ -670,7 +670,7 @@ Quaternion Build_Quaternion(const Matrix3D & mat) if (tr > 0.0f) { - s = sqrt(tr + 1.0); + s = WWMath::Sqrt(tr + 1.0); q[3] = s * 0.5; s = 0.5 / s; @@ -686,7 +686,7 @@ Quaternion Build_Quaternion(const Matrix3D & mat) j = _nxt[i]; k = _nxt[j]; - s = sqrt((mat[i][i] - (mat[j][j] + mat[k][k])) + 1.0); + s = WWMath::Sqrt((mat[i][i] - (mat[j][j] + mat[k][k])) + 1.0); q[i] = s * 0.5; if (s != 0.0) { @@ -713,7 +713,7 @@ Quaternion Build_Quaternion(const Matrix3x3 & mat) if (tr > 0.0) { - s = sqrt(tr + 1.0); + s = WWMath::Sqrt(tr + 1.0); q[3] = s * 0.5; s = 0.5 / s; @@ -730,7 +730,7 @@ Quaternion Build_Quaternion(const Matrix3x3 & mat) j = _nxt[i]; k = _nxt[j]; - s = sqrt( (mat[i][i] - (mat[j][j]+mat[k][k])) + 1.0); + s = WWMath::Sqrt( (mat[i][i] - (mat[j][j]+mat[k][k])) + 1.0); q[i] = s * 0.5; @@ -757,7 +757,7 @@ Quaternion Build_Quaternion(const Matrix4x4 & mat) if (tr > 0.0) { - s = sqrt(tr + 1.0); + s = WWMath::Sqrt(tr + 1.0); q[3] = s * 0.5; s = 0.5 / s; @@ -774,7 +774,7 @@ Quaternion Build_Quaternion(const Matrix4x4 & mat) j = _nxt[i]; k = _nxt[j]; - s = sqrt( (mat[i][i] - (mat[j][j]+mat[k][k])) + 1.0); + s = WWMath::Sqrt( (mat[i][i] - (mat[j][j]+mat[k][k])) + 1.0); q[i] = s * 0.5; if (s != 0.0) { @@ -868,10 +868,10 @@ float project_to_sphere(float r, float x, float y) { const float SQRT2 = 1.41421356f; float t, z; - float d = WWMath::Sqrt(x * x + y * y); + float d = WWMath::Sqrt_Legacy(x * x + y * y); if (d < r * (SQRT2/(2.0f))) // inside sphere - z = WWMath::Sqrt(r * r - d * d); + z = WWMath::Sqrt_Legacy(r * r - d * d); else { // on hyperbola t = r / SQRT2; z = t * t / d; diff --git a/Core/Libraries/Source/WWVegas/WWMath/quat.h b/Core/Libraries/Source/WWVegas/WWMath/quat.h index 8cfad3e4c1a..5efb5a6f620 100644 --- a/Core/Libraries/Source/WWVegas/WWMath/quat.h +++ b/Core/Libraries/Source/WWVegas/WWMath/quat.h @@ -87,7 +87,7 @@ class Quaternion WWINLINE float Length2() const { return (X*X + Y*Y + Z*Z + W*W); } // Magnitude of the quaternion - WWINLINE float Length() const { return WWMath::Sqrt(Length2()); } + WWINLINE float Length() const { return WWMath::Sqrt_Legacy(Length2()); } // Make the quaternion unit length void Normalize(); @@ -277,10 +277,10 @@ WWINLINE bool Quaternion::Is_Valid() const WWINLINE bool Equal_Within_Epsilon(const Quaternion &a, const Quaternion &b, float epsilon) { - return( (WWMath::Fabs(a.X - b.X) < epsilon) && - (WWMath::Fabs(a.Y - b.Y) < epsilon) && - (WWMath::Fabs(a.Z - b.Z) < epsilon) && - (WWMath::Fabs(a.W - b.W) < epsilon) ); + return( (WWMath::Fabsf_Legacy(a.X - b.X) < epsilon) && + (WWMath::Fabsf_Legacy(a.Y - b.Y) < epsilon) && + (WWMath::Fabsf_Legacy(a.Z - b.Z) < epsilon) && + (WWMath::Fabsf_Legacy(a.W - b.W) < epsilon) ); } /*********************************************************************************************** diff --git a/Core/Libraries/Source/WWVegas/WWMath/sphere.h b/Core/Libraries/Source/WWVegas/WWMath/sphere.h index 0bb7eaca11b..030d8f56a35 100644 --- a/Core/Libraries/Source/WWVegas/WWMath/sphere.h +++ b/Core/Libraries/Source/WWVegas/WWMath/sphere.h @@ -192,7 +192,7 @@ inline SphereClass::SphereClass(const Vector3 *Position,const int VertCount) dz = dia2.Z - center.Z; double radsqr = dx*dx + dy*dy + dz*dz; - double radius = sqrt(radsqr); + double radius = WWMath::Sqrt(radsqr); // SECOND PASS: @@ -209,7 +209,7 @@ inline SphereClass::SphereClass(const Vector3 *Position,const int VertCount) // this point was outside the old sphere, compute a new // center point and radius which contains this point - double testrad = sqrt(testrad2); + double testrad = WWMath::Sqrt(testrad2); // adjust center and radius radius = (radius + testrad) / 2.0; diff --git a/Core/Libraries/Source/WWVegas/WWMath/tri.cpp b/Core/Libraries/Source/WWVegas/WWMath/tri.cpp index 854991cf587..5f8d1449306 100644 --- a/Core/Libraries/Source/WWVegas/WWMath/tri.cpp +++ b/Core/Libraries/Source/WWVegas/WWMath/tri.cpp @@ -59,9 +59,9 @@ static inline void find_dominant_plane_fast(const TriClass & tri, FDPRec& info) /* ** Find the largest component of the normal */ - float x = WWMath::Fabs(tri.N->X); - float y = WWMath::Fabs(tri.N->Y); - float z = WWMath::Fabs(tri.N->Z); + float x = WWMath::Fabsf_Legacy(tri.N->X); + float y = WWMath::Fabsf_Legacy(tri.N->Y); + float z = WWMath::Fabsf_Legacy(tri.N->Z); float val = x; int ni = 0; @@ -86,9 +86,9 @@ static inline void find_dominant_plane(const TriClass & tri, int * axis1,int * a ** Find the largest component of the normal */ int ni = 0; - float x = WWMath::Fabs(tri.N->X); - float y = WWMath::Fabs(tri.N->Y); - float z = WWMath::Fabs(tri.N->Z); + float x = WWMath::Fabsf_Legacy(tri.N->X); + float y = WWMath::Fabsf_Legacy(tri.N->Y); + float z = WWMath::Fabsf_Legacy(tri.N->Z); float val = x; if (y > val) { @@ -146,9 +146,9 @@ void TriClass::Find_Dominant_Plane(int * axis1,int * axis2) const ** Find the largest component of the normal */ int ni = 0; - float x = WWMath::Fabs(N->X); - float y = WWMath::Fabs(N->Y); - float z = WWMath::Fabs(N->Z); + float x = WWMath::Fabsf_Legacy(N->X); + float y = WWMath::Fabsf_Legacy(N->Y); + float z = WWMath::Fabsf_Legacy(N->Z); float val = x; if (y > val) { diff --git a/Core/Libraries/Source/WWVegas/WWMath/v3_rnd.cpp b/Core/Libraries/Source/WWVegas/WWMath/v3_rnd.cpp index ebbd9bf572c..3b8e235fdd1 100644 --- a/Core/Libraries/Source/WWVegas/WWMath/v3_rnd.cpp +++ b/Core/Libraries/Source/WWVegas/WWMath/v3_rnd.cpp @@ -118,7 +118,7 @@ void Vector3HollowSphereRandomizer::Get_Vector(Vector3 &vector) if (v_l2 <= 1.0f && v_l2 > 0.0f) break; } - float scale = Radius * WWMath::Inv_Sqrt(v_l2); + float scale = Radius * WWMath::Inv_Sqrt_Legacy(v_l2); vector.X *= scale; vector.Y *= scale; diff --git a/Core/Libraries/Source/WWVegas/WWMath/vector2.h b/Core/Libraries/Source/WWVegas/WWMath/vector2.h index 0d0035c73da..3a3ff28f4f1 100644 --- a/Core/Libraries/Source/WWVegas/WWMath/vector2.h +++ b/Core/Libraries/Source/WWVegas/WWMath/vector2.h @@ -309,7 +309,7 @@ WWINLINE bool operator != (const Vector2 &a,const Vector2 &b) *========================================================================*/ WWINLINE bool Equal_Within_Epsilon(const Vector2 &a,const Vector2 &b,float epsilon) { - return( (WWMath::Fabs(a.X - b.X) < epsilon) && (WWMath::Fabs(a.Y - b.Y) < epsilon) ); + return( (WWMath::Fabsf_Legacy(a.X - b.X) < epsilon) && (WWMath::Fabsf_Legacy(a.Y - b.Y) < epsilon) ); } /************************************************************************** @@ -327,7 +327,7 @@ WWINLINE void Vector2::Normalize() { float len2 = Length2(); if (len2 != 0.0f) { - float oolen = WWMath::Inv_Sqrt(len2); + float oolen = WWMath::Inv_Sqrt_Legacy(len2); X *= oolen; Y *= oolen; } @@ -337,7 +337,7 @@ WWINLINE Vector2 Normalize(const Vector2 & vec) { float len2 = vec.Length2(); if (len2 != 0.0f) { - float oolen = WWMath::Inv_Sqrt(len2); + float oolen = WWMath::Inv_Sqrt_Legacy(len2); return vec / oolen; } return Vector2(0.0f,0.0f); @@ -356,7 +356,7 @@ WWINLINE Vector2 Normalize(const Vector2 & vec) *========================================================================*/ WWINLINE float Vector2::Length() const { - return (float)WWMath::Sqrt(Length2()); + return (float)WWMath::Sqrt_Legacy(Length2()); } /************************************************************************** @@ -389,7 +389,7 @@ WWINLINE float Vector2::Length2() const *========================================================================*/ WWINLINE void Vector2::Rotate(float theta) { - Rotate(WWMath::Sin(theta), WWMath::Cos(theta)); + Rotate(WWMath::Sinf_Legacy(theta), WWMath::Cosf_Legacy(theta)); } /************************************************************************** @@ -429,7 +429,7 @@ WWINLINE void Vector2::Rotate(float s, float c) *========================================================================*/ WWINLINE bool Vector2::Rotate_Towards_Vector(Vector2 &target, float max_theta, bool & positive_turn) { - return Rotate_Towards_Vector(target, WWMath::Sin(max_theta), WWMath::Cos(max_theta), positive_turn); + return Rotate_Towards_Vector(target, WWMath::Sinf_Legacy(max_theta), WWMath::Cosf_Legacy(max_theta), positive_turn); } /************************************************************************** @@ -597,8 +597,8 @@ WWINLINE float Quick_Distance(float x1, float y1, float x2, float y2) float x_diff = x1 - x2; float y_diff = y1 - y2; - WWMath::Fabs(x_diff); - WWMath::Fabs(y_diff); + WWMath::Fabsf_Legacy(x_diff); + WWMath::Fabsf_Legacy(y_diff); if (x_diff > y_diff) { @@ -638,7 +638,7 @@ WWINLINE float Distance(float x1, float y1, float x2, float y2) float x_diff = x1 - x2; float y_diff = y1 - y2; - return (WWMath::Sqrt((x_diff * x_diff) + (y_diff * y_diff))); + return (WWMath::Sqrt_Legacy((x_diff * x_diff) + (y_diff * y_diff))); } diff --git a/Core/Libraries/Source/WWVegas/WWMath/vector3.h b/Core/Libraries/Source/WWVegas/WWMath/vector3.h index a4f584df75b..df5f851ef70 100644 --- a/Core/Libraries/Source/WWVegas/WWMath/vector3.h +++ b/Core/Libraries/Source/WWVegas/WWMath/vector3.h @@ -343,9 +343,9 @@ WWINLINE bool operator != (const Vector3 &a,const Vector3 &b) *========================================================================*/ WWINLINE bool Equal_Within_Epsilon(const Vector3 &a,const Vector3 &b,float epsilon) { - return( (WWMath::Fabs(a.X - b.X) < epsilon) && - (WWMath::Fabs(a.Y - b.Y) < epsilon) && - (WWMath::Fabs(a.Z - b.Z) < epsilon) ); + return( (WWMath::Fabsf_Legacy(a.X - b.X) < epsilon) && + (WWMath::Fabsf_Legacy(a.Y - b.Y) < epsilon) && + (WWMath::Fabsf_Legacy(a.Z - b.Z) < epsilon) ); } @@ -419,7 +419,7 @@ WWINLINE void Vector3::Normalize() float len2 = Length2(); if (len2 != 0.0f) { - float oolen = WWMath::Inv_Sqrt(len2); + float oolen = WWMath::Inv_Sqrt_Legacy(len2); X *= oolen; Y *= oolen; Z *= oolen; @@ -432,7 +432,7 @@ WWINLINE Vector3 Normalize(const Vector3 & vec) float len2 = vec.Length2(); if (len2 != 0.0f) { - float oolen = WWMath::Inv_Sqrt(len2); + float oolen = WWMath::Inv_Sqrt_Legacy(len2); return vec * oolen; } return vec; @@ -452,7 +452,7 @@ WWINLINE Vector3 Normalize(const Vector3 & vec) *========================================================================*/ WWINLINE float Vector3::Length() const { - return WWMath::Sqrt(Length2()); + return WWMath::Sqrt_Legacy(Length2()); } /************************************************************************** @@ -488,9 +488,9 @@ WWINLINE float Vector3::Quick_Length() const { // this method of approximating the length comes from Graphics Gems 1 and // supposedly gives an error of +/- 8% - float max = WWMath::Fabs(X); - float mid = WWMath::Fabs(Y); - float min = WWMath::Fabs(Z); + float max = WWMath::Fabsf_Legacy(X); + float mid = WWMath::Fabsf_Legacy(Y); + float min = WWMath::Fabsf_Legacy(Z); float tmp; if (max < mid) { tmp = max; max = mid; mid = tmp; } @@ -708,7 +708,7 @@ WWINLINE void Vector3::Scale(const Vector3 & scale) *=============================================================================================*/ WWINLINE void Vector3::Rotate_X(float angle) { - Rotate_X(sinf(angle),cosf(angle)); + Rotate_X(WWMath::Sinf(angle),WWMath::Cosf(angle)); } @@ -748,7 +748,7 @@ WWINLINE void Vector3::Rotate_X(float s_angle,float c_angle) *=============================================================================================*/ WWINLINE void Vector3::Rotate_Y(float angle) { - Rotate_Y(sinf(angle),cosf(angle)); + Rotate_Y(WWMath::Sinf(angle),WWMath::Cosf(angle)); } @@ -788,7 +788,7 @@ WWINLINE void Vector3::Rotate_Y(float s_angle,float c_angle) *=============================================================================================*/ WWINLINE void Vector3::Rotate_Z(float angle) { - Rotate_Z(sinf(angle),cosf(angle)); + Rotate_Z(WWMath::Sinf(angle),WWMath::Cosf(angle)); } diff --git a/Core/Libraries/Source/WWVegas/WWMath/vector4.h b/Core/Libraries/Source/WWVegas/WWMath/vector4.h index e6dc70b4abd..02effa73fac 100644 --- a/Core/Libraries/Source/WWVegas/WWMath/vector4.h +++ b/Core/Libraries/Source/WWVegas/WWMath/vector4.h @@ -272,7 +272,7 @@ WWINLINE void Vector4::Normalize() { float len2 = Length2(); if (len2 != 0.0f) { - float oolen = WWMath::Inv_Sqrt(len2); + float oolen = WWMath::Inv_Sqrt_Legacy(len2); X *= oolen; Y *= oolen; Z *= oolen; @@ -284,7 +284,7 @@ WWINLINE Vector4 Normalize(const Vector4 & vec) { float len2 = vec.Length2(); if (len2 != 0.0f) { - float oolen = WWMath::Inv_Sqrt(len2); + float oolen = WWMath::Inv_Sqrt_Legacy(len2); return vec * oolen; } return Vector4(0.0f,0.0f,0.0f,0.0f); @@ -303,7 +303,7 @@ WWINLINE Vector4 Normalize(const Vector4 & vec) *========================================================================*/ WWINLINE float Vector4::Length() const { - return WWMath::Sqrt(Length2()); + return WWMath::Sqrt_Legacy(Length2()); } /************************************************************************** diff --git a/Core/Libraries/Source/WWVegas/WWMath/vehiclecurve.cpp b/Core/Libraries/Source/WWVegas/WWMath/vehiclecurve.cpp index a671ca700c5..6105be232d2 100644 --- a/Core/Libraries/Source/WWVegas/WWMath/vehiclecurve.cpp +++ b/Core/Libraries/Source/WWVegas/WWMath/vehiclecurve.cpp @@ -95,15 +95,15 @@ Find_Tangent // float delta_x = point.X - center.X; float delta_y = point.Y - center.Y; - float dist = ::sqrt (delta_x * delta_x + delta_y * delta_y); + float dist = WWMath::Sqrt(delta_x * delta_x + delta_y * delta_y); if (dist >= radius) { // // Determine the offset angle (from the line between the point and center) // where the 2 tangent points lie. // - float angle_offset = WWMath::Acos (radius / dist); - float base_angle = WWMath::Atan2 (delta_x, -delta_y); + float angle_offset = WWMath::Acos_Legacy (radius / dist); + float base_angle = WWMath::Atan2_Legacy (delta_x, -delta_y); base_angle = WWMath::Wrap (base_angle, 0, DEG_TO_RADF (360)); // @@ -185,10 +185,10 @@ Find_Turn_Arc // the point halfway between the angles formed by the (prev-curr) and // (next-curr) vectors. // - float angle1 = ::WWMath::Atan2 ((prev_pt.Y - curr_pt.Y), prev_pt.X - curr_pt.X); + float angle1 = ::WWMath::Atan2_Legacy ((prev_pt.Y - curr_pt.Y), prev_pt.X - curr_pt.X); angle1 = WWMath::Wrap (angle1, 0, DEG_TO_RADF (360)); - float angle2 = ::WWMath::Atan2 ((next_pt.Y - curr_pt.Y), next_pt.X - curr_pt.X); + float angle2 = ::WWMath::Atan2_Legacy ((next_pt.Y - curr_pt.Y), next_pt.X - curr_pt.X); angle2 = WWMath::Wrap (angle2, 0, DEG_TO_RADF (360)); float avg_angle = (angle1 + angle2) * 0.5F; @@ -197,8 +197,8 @@ Find_Turn_Arc // Find the shortest delta between the two angles (either clockwise or // counterclockwise). // - float delta1 = WWMath::Fabs (::Get_Angle_Delta (angle1, angle2, true)); - float delta2 = WWMath::Fabs (::Get_Angle_Delta (angle1, angle2, false)); + float delta1 = WWMath::Fabsf_Legacy (::Get_Angle_Delta (angle1, angle2, true)); + float delta2 = WWMath::Fabsf_Legacy (::Get_Angle_Delta (angle1, angle2, false)); if (delta1 < delta2) { avg_angle = angle1 - (delta1 * 0.5F); } else { @@ -208,8 +208,8 @@ Find_Turn_Arc // // Find the point on the circle at this angle // - arc_center->X = curr_pt.X + (radius * ::WWMath::Cos (avg_angle)); - arc_center->Y = curr_pt.Y + (radius * ::WWMath::Sin (avg_angle)); + arc_center->X = curr_pt.X + (radius * ::WWMath::Cosf_Legacy (avg_angle)); + arc_center->Y = curr_pt.Y + (radius * ::WWMath::Sinf_Legacy (avg_angle)); arc_center->Z = curr_pt.Z; // @@ -252,7 +252,7 @@ Find_Tangents // // Find the angle where the current position lies on the turn arc // - (*point_angle) = ::WWMath::Atan2 (curr_pt.X - arc_center.X, -(curr_pt.Y - arc_center.Y)); + (*point_angle) = ::WWMath::Atan2_Legacy (curr_pt.X - arc_center.X, -(curr_pt.Y - arc_center.Y)); (*point_angle) = WWMath::Wrap ((*point_angle), 0, DEG_TO_RADF (360)); // @@ -378,12 +378,12 @@ VehicleCurveClass::Update_Arc_List () // Determine at what points these angles intersect the arc // Vector3 point_in (0, 0, 0); - point_in.X = arc_center.X + (m_Radius * ::WWMath::Sin (point_angle + angle_in_delta)); - point_in.Y = arc_center.Y + (m_Radius * -::WWMath::Cos (point_angle + angle_in_delta)); + point_in.X = arc_center.X + (m_Radius * ::WWMath::Sinf_Legacy (point_angle + angle_in_delta)); + point_in.Y = arc_center.Y + (m_Radius * -::WWMath::Cosf_Legacy (point_angle + angle_in_delta)); Vector3 point_out (0, 0, 0); - point_out.X = arc_center.X + (m_Radius * ::WWMath::Sin (point_angle + angle_out_delta)); - point_out.Y = arc_center.Y + (m_Radius * -::WWMath::Cos (point_angle + angle_out_delta)); + point_out.X = arc_center.X + (m_Radius * ::WWMath::Sinf_Legacy (point_angle + angle_out_delta)); + point_out.Y = arc_center.Y + (m_Radius * -::WWMath::Cosf_Legacy (point_angle + angle_out_delta)); // // Sanity check to ensure the vehicle doesn't try to go the long way around the @@ -489,8 +489,8 @@ VehicleCurveClass::Evaluate (float time, Vector3 *set_val) // - Straight line from exit of last curve to enter of this curve // - Enter curve for the current point // - float arc_length0 = arc_info0.radius * WWMath::Fabs (arc_info0.angle_out_delta); - float arc_length1 = arc_info1.radius * WWMath::Fabs (arc_info1.angle_in_delta); + float arc_length0 = arc_info0.radius * WWMath::Fabsf_Legacy (arc_info0.angle_out_delta); + float arc_length1 = arc_info1.radius * WWMath::Fabsf_Legacy (arc_info1.angle_in_delta); float other_length = ((arc_info1.point_in - arc_info0.point_out).Length ()) / 2; float total_length = arc_length0 + arc_length1 + other_length; @@ -513,10 +513,10 @@ VehicleCurveClass::Evaluate (float time, Vector3 *set_val) //float angle = arc_info0.point_angle + (arc_info0.angle_out_delta) * percent; float angle = arc_info0.point_angle + arc_info0.angle_out_delta; - set_val->X = arc_info0.center.X + (arc_info0.radius * ::WWMath::Sin (angle)); - set_val->Y = arc_info0.center.Y + (arc_info0.radius * -::WWMath::Cos (angle)); + set_val->X = arc_info0.center.X + (arc_info0.radius * ::WWMath::Sinf_Legacy (angle)); + set_val->Y = arc_info0.center.Y + (arc_info0.radius * -::WWMath::Cosf_Legacy (angle)); - m_Sharpness = WWMath::Clamp (WWMath::Fabs (arc_info0.angle_out_delta) / DEG_TO_RADF (15), 0, 1.0F); + m_Sharpness = WWMath::Clamp (WWMath::Fabsf_Legacy (arc_info0.angle_out_delta) / DEG_TO_RADF (15), 0, 1.0F); m_SharpnessPos.X = set_val->X; m_SharpnessPos.Y = set_val->Y; m_SharpnessPos.Z = Keys[index0].Point.Z + (Keys[index1].Point.Z - Keys[index0].Point.Z) * seg_time; @@ -542,7 +542,7 @@ VehicleCurveClass::Evaluate (float time, Vector3 *set_val) //set_val->X = arc_info0.point_out.X + (arc_info1.point_in.X - arc_info0.point_out.X) * percent; //set_val->Y = arc_info0.point_out.Y + (arc_info1.point_in.Y - arc_info0.point_out.Y) * percent; - m_Sharpness = WWMath::Clamp (WWMath::Fabs (arc_info1.angle_out_delta) / DEG_TO_RADF (15), 0, 1.0F); + m_Sharpness = WWMath::Clamp (WWMath::Fabsf_Legacy (arc_info1.angle_out_delta) / DEG_TO_RADF (15), 0, 1.0F); m_SharpnessPos = arc_info1.point_in; m_LastTime = Keys[index0].Time + (Keys[index1].Time - Keys[index0].Time) * time2; @@ -556,15 +556,15 @@ VehicleCurveClass::Evaluate (float time, Vector3 *set_val) /*float percent = 1.0F - ((seg_time - time2) / (1.0F - time2)); float angle = arc_info1.point_angle + (arc_info1.angle_in_delta * percent); - set_val->X = arc_info1.center.X + (arc_info1.radius * ::WWMath::Sin (angle)); - set_val->Y = arc_info1.center.Y + (arc_info1.radius * -::WWMath::Cos (angle)); */ + set_val->X = arc_info1.center.X + (arc_info1.radius * ::WWMath::Sinf_Legacy (angle)); + set_val->Y = arc_info1.center.Y + (arc_info1.radius * -::WWMath::Cosf_Legacy (angle)); */ float angle = arc_info1.point_angle + (arc_info1.angle_out_delta); - set_val->X = arc_info1.center.X + (arc_info1.radius * ::WWMath::Sin (angle)); - set_val->Y = arc_info1.center.Y + (arc_info1.radius * -::WWMath::Cos (angle)); + set_val->X = arc_info1.center.X + (arc_info1.radius * ::WWMath::Sinf_Legacy (angle)); + set_val->Y = arc_info1.center.Y + (arc_info1.radius * -::WWMath::Cosf_Legacy (angle)); - m_Sharpness = WWMath::Clamp (WWMath::Fabs (arc_info1.angle_out_delta) / DEG_TO_RADF (15), 0, 1.0F); + m_Sharpness = WWMath::Clamp (WWMath::Fabsf_Legacy (arc_info1.angle_out_delta) / DEG_TO_RADF (15), 0, 1.0F); m_SharpnessPos.X = set_val->X; m_SharpnessPos.Y = set_val->Y; m_SharpnessPos.Z = Keys[index0].Point.Z + (Keys[index1].Point.Z - Keys[index0].Point.Z) * seg_time; diff --git a/Core/Libraries/Source/WWVegas/WWMath/wwmath.cpp b/Core/Libraries/Source/WWVegas/WWMath/wwmath.cpp index ab5c0f91276..2c15adb47eb 100644 --- a/Core/Libraries/Source/WWVegas/WWMath/wwmath.cpp +++ b/Core/Libraries/Source/WWVegas/WWMath/wwmath.cpp @@ -55,13 +55,22 @@ void WWMath::Init() int a=0; for (;a0) { _FastInvSinTable[a]=1.0f/_FastSinTable[a]; diff --git a/Core/Libraries/Source/WWVegas/WWMath/wwmath.h b/Core/Libraries/Source/WWVegas/WWMath/wwmath.h index 07833b5225c..70ce1ca9dcb 100644 --- a/Core/Libraries/Source/WWVegas/WWMath/wwmath.h +++ b/Core/Libraries/Source/WWVegas/WWMath/wwmath.h @@ -40,12 +40,18 @@ #include #include #include +#include "Lib/BaseDefines.h" + +#if USE_DETERMINISTIC_MATH +#include "gmath.h" +#endif /* ** Some global constants. */ #define WWMATH_EPSILON 0.0001f #define WWMATH_EPSILON2 WWMATH_EPSILON * WWMATH_EPSILON +#define WWMATH_HALF_PI 1.570796327f #define WWMATH_PI 3.141592654f #define WWMATH_TWO_PI 6.283185308f #define WWMATH_FLOAT_MAX (FLT_MAX) @@ -74,7 +80,6 @@ #define DEG_TO_RADF(x) (((float)x)*WWMATH_PI/180.0f) #endif - const int ARC_TABLE_SIZE=1024; const int SIN_TABLE_SIZE=1024; extern float _FastAcosTable[ARC_TABLE_SIZE]; @@ -87,6 +92,7 @@ extern float _FastInvSinTable[SIN_TABLE_SIZE]; ** Include the various other header files in the WWMATH library ** in order to get matrices, quaternions, etc. */ +// TheSuperHackers @todo The Legacy functions can be removed when retail compatibility is abandoned. class WWMath { public: @@ -96,65 +102,95 @@ class WWMath static void Init(); static void Shutdown(); -// These are meant to be a collection of small math utility functions to be optimized at some point. -static WWINLINE float Fabs(float val) -{ - int value=*(int*)&val; - value&=0x7fffffff; - return *(float*)&value; -} - -static WWINLINE int Float_To_Int_Chop(const float& f); -static WWINLINE int Float_To_Int_Floor(const float& f); - -#if defined(_MSC_VER) && defined(_M_IX86) -static WWINLINE float Cos(float val); -static WWINLINE float Sin(float val); -static WWINLINE float Sqrt(float val); -static WWINLINE float Inv_Sqrt(float a); // Some 30% faster inverse square root than regular C++ compiled, from Intel's math library -static WWINLINE long Float_To_Long(float f); -#else -static WWINLINE float Cos(float val); -static WWINLINE float Sin(float val); -static WWINLINE float Sqrt(float val); -static WWINLINE float Inv_Sqrt(float a); -static WWINLINE long Float_To_Long(float f); -#endif - - -static WWINLINE float Fast_Sin(float val); -static WWINLINE float Fast_Inv_Sin(float val); -static WWINLINE float Fast_Cos(float val); -static WWINLINE float Fast_Inv_Cos(float val); - -static WWINLINE float Fast_Acos(float val); -static WWINLINE float Acos(float val); -static WWINLINE float Fast_Asin(float val); -static WWINLINE float Asin(float val); - - -static WWINLINE float Atan(float x) { return static_cast(atan(x)); } -static WWINLINE float Atan2(float y,float x) { return static_cast(atan2(y,x)); } -static WWINLINE float Sign(float val); -static WWINLINE float Ceil(float val) { return ceilf(val); } -static WWINLINE float Floor(float val) { return floorf(val); } -static WWINLINE float Round(float val) { return floorf(val + 0.5f); } -static WWINLINE bool Fast_Is_Float_Positive(const float & val); -static WWINLINE bool Is_Power_Of_2(const unsigned int val); +static WWINLINE double Pow(double x, double y); +static WWINLINE float Powf(float x, float y); +static WWINLINE float Sqrt_Legacy(float val); +static WWINLINE float Sqrt(float x); + static WWINLINE float Sqrt(int x); + static WWINLINE double Sqrt(double x); +static WWINLINE float Sqrtf(float x); +static WWINLINE float Inv_Sqrt_Legacy(float a); +static WWINLINE double Inv_Sqrt(double x); +static WWINLINE float Inv_Sqrtf(float x); + +static WWINLINE float Fast_Acos(float val); +static WWINLINE float Fast_Asin(float val); +static WWINLINE float Acos_Legacy(float val); +static WWINLINE float Acos(float x); + static WWINLINE double Acos(double x); +static WWINLINE float Acosf(float x); +static WWINLINE float Asin_Legacy(float val); +static WWINLINE float Asin(float x); + static WWINLINE double Asin(double x); +static WWINLINE float Asinf(float x); +static WWINLINE float Atan_Legacy(float x); +static WWINLINE float Atan(float x); + static WWINLINE double Atan(double x); +static WWINLINE float Atanf(float x); +static WWINLINE float Atan2_Legacy(float x, float y); +static WWINLINE float Atan2(float x, float y); + static WWINLINE double Atan2(double x, double y); +static WWINLINE float Atan2f(float x, float y); + +static WWINLINE float Fast_Cos(float val); +static WWINLINE float Fast_Inv_Cos(float val); +static WWINLINE float Fast_Sin(float val); +static WWINLINE float Fast_Inv_Sin(float val); +static WWINLINE float Cos(float val); + static WWINLINE double Cos(double val); +static WWINLINE float Cosf(float val); +static WWINLINE float Cosf_Legacy(float val); +// Prevent automatic compiler promotion of float arguments to double-precision variants. + // Single-precision math in GameMath (gm_*f) is guaranteed to be cross-platform bit-identical, + // whereas double-precision math (gm_*) can diverge by 1 ULP due to FPU precision differences (x87 vs NEON). + static WWINLINE float Sin(float val); + static WWINLINE double Sin(double val); +static WWINLINE float Sinf(float val); +static WWINLINE float Sinf_Legacy(float val); +static WWINLINE float Tan(float x); + static WWINLINE double Tan(double x); +static WWINLINE float Tanf(float x); + +static WWINLINE double Cosh(double x); +static WWINLINE float Coshf(float x); +static WWINLINE double Sinh(double x); +static WWINLINE float Sinhf(float x); +static WWINLINE double Tanh(double x); +static WWINLINE float Tanhf(float x); + +static WWINLINE float Fabs(float x); + static WWINLINE double Fabs(double x); +static WWINLINE float Fabsf(float x); +static WWINLINE float Fabsf_Legacy(float val); + +static WWINLINE double Ceil(double x); +static WWINLINE float Ceilf(float x); +static WWINLINE double Floor(double x); +static WWINLINE float Floorf(float x); +static WWINLINE double Round(double x) { return Floor(x + 0.5); } +static WWINLINE float Roundf(float x) { return Floorf(x + 0.5f); } + +static WWINLINE double Exp(double x); +static WWINLINE float Expf(float x); +static WWINLINE double Log10(double x); +static WWINLINE float Log10f(float x); +static WWINLINE double Log(double x); +static WWINLINE float Logf(float x); + +static WWINLINE bool Fast_Is_Float_Positive(const float & val); +static WWINLINE bool Is_Power_Of_2(const unsigned int val); static float Random_Float(); static WWINLINE float Random_Float(float min,float max); static WWINLINE float Clamp(float val, float min = 0.0f, float max = 1.0f); -static WWINLINE double Clamp(double val, double min = 0.0f, double max = 1.0f); +static WWINLINE double Clamp(double val, double min = 0.0f, double max = 1.0f); static WWINLINE int Clamp_Int(int val, int min_val, int max_val); static WWINLINE float Wrap(float val, float min = 0.0f, float max = 1.0f); -static WWINLINE double Wrap(double val, double min = 0.0f, double max = 1.0f); +static WWINLINE double Wrap(double val, double min = 0.0f, double max = 1.0f); static WWINLINE float Min(float a, float b); static WWINLINE float Max(float a, float b); -static WWINLINE int Float_As_Int(const float f) { return *((int*)&f); } - // Linearly interpolates between a and b using parameter t in [0, 1]. // t = 0 returns a, t = 1 returns b, values in between return a proportionate blend. static WWINLINE float Lerp(float a, float b, float t); @@ -165,27 +201,735 @@ static WWINLINE double Lerp(double a, double b, float t); static WWINLINE float Inverse_Lerp(float a, float b, float v); static WWINLINE double Inverse_Lerp(double a, double b, float v); -static WWINLINE long Float_To_Long(double f); - -static WWINLINE unsigned char Unit_Float_To_Byte(float f) { return (unsigned char)(f*255.0f); } -static WWINLINE float Byte_To_Unit_Float(unsigned char byte) { return ((float)byte) / 255.0f; } - static WWINLINE bool Is_Valid_Float(float x); static WWINLINE bool Is_Valid_Double(double x); +static WWINLINE int Float_To_Int_Chop(float f); +static WWINLINE int Float_To_Int_Floor(float f); +static WWINLINE long Float_To_Long(float f); +static WWINLINE long Float_To_Long(double f); +static WWINLINE int Float_As_Int(const float f) { return *((int*)&f); } +static WWINLINE unsigned char Unit_Float_To_Byte(float f) { return (unsigned char)(f*255.0f); } +static WWINLINE float Byte_To_Unit_Float(unsigned char byte) { return ((float)byte) / 255.0f; } + static WWINLINE float Normalize_Angle(float angle); // Normalizes the angle to the range -PI..PI }; -WWINLINE float WWMath::Sign(float val) +WWINLINE double WWMath::Pow(double x, double y) +{ +#if USE_DETERMINISTIC_MATH + return gm_pow(x, y); +#else + return pow(x, y); +#endif +} + +WWINLINE float WWMath::Powf(float x, float y) +{ +#if USE_DETERMINISTIC_MATH + return gm_powf(x, y); +#else + return powf(x, y); +#endif +} + +WWINLINE float WWMath::Sqrt_Legacy(float val) +{ +#if USE_DETERMINISTIC_MATH + return gm_sqrtf(val); + +#elif defined(_MSC_VER) && defined(_M_IX86) + float retval; + __asm { + fld [val] + fsqrt + fstp [retval] + } + return retval; + +#else + return (float)sqrt((double)val); +#endif +} + +WWINLINE float WWMath::Sqrt(float x) +{ +#if USE_DETERMINISTIC_MATH + return gm_sqrtf(x); +#else + return (float)Sqrt((double)x); +#endif +} + +WWINLINE float WWMath::Sqrt(int x) +{ +#if USE_DETERMINISTIC_MATH + return gm_sqrtf((float)x); +#else + return (float)Sqrt((double)x); +#endif +} + +WWINLINE double WWMath::Sqrt(double x) +{ +#if USE_DETERMINISTIC_MATH + return gm_sqrt(x); +#else + return sqrt(x); +#endif +} + +WWINLINE float WWMath::Sqrtf(float x) +{ +#if USE_DETERMINISTIC_MATH + return gm_sqrtf(x); +#else + return sqrtf(x); +#endif +} + +WWINLINE float WWMath::Inv_Sqrt_Legacy(float a) +{ +#if USE_DETERMINISTIC_MATH + return 1.0f / gm_sqrtf(a); + +#elif defined(_MSC_VER) && defined(_M_IX86) + // Some 30% faster inverse square root than regular C++ compiled, from Intel's math library + float retval; + + __asm { + mov eax, 0be6eb508h + mov DWORD PTR [esp-12],03fc00000h ; 1.5 on the stack + sub eax, DWORD PTR [a]; a + sub DWORD PTR [a], 800000h ; a/2 a=Y0 + shr eax, 1 ; firs approx in eax=R0 + mov DWORD PTR [esp-8], eax + + fld DWORD PTR [esp-8] ;r + fmul st, st ;r*r + fld DWORD PTR [esp-8] ;r + fxch st(1) + fmul DWORD PTR [a];a ;r*r*y0 + fld DWORD PTR [esp-12];load 1.5 + fld st(0) + fsub st,st(2) ;r1 = 1.5 - y1 + ;x1 = st(3) + ;y1 = st(2) + ;1.5 = st(1) + ;r1 = st(0) + + fld st(1) + fxch st(1) + fmul st(3),st ; y2=y1*r1*... + fmul st(3),st ; y2=y1*r1*r1 + fmulp st(4),st ; x2=x1*r1 + fsub st,st(2) ; r2=1.5-y2 + ;x2=st(3) + ;y2=st(2) + ;1.5=st(1) + ;r2 = st(0) + + fmul st(2),st ;y3=y2*r2*... + fmul st(3),st ;x3=x2*r2 + fmulp st(2),st ;y3=y2*r2*r2 + fxch st(1) + fsubp st(1),st ;r3= 1.5 - y3 + ;x3 = st(1) + ;r3 = st(0) + fmulp st(1), st + + fstp retval + } + + return retval; + +#else + return 1.0f / (float)sqrt((double)a); +#endif +} + +WWINLINE double WWMath::Inv_Sqrt(double x) +{ + return 1.0 / Sqrt(x); +} + +WWINLINE float WWMath::Inv_Sqrtf(float x) +{ + return 1.0f / Sqrtf(x); +} + +WWINLINE float WWMath::Fast_Acos(float val) +{ + // Near -1 and +1, the table becomes too inaccurate + if (Fabsf_Legacy(val) > 0.975f) { + return Acos_Legacy(val); + } + + val*=float(ARC_TABLE_SIZE/2); + + int idx0=Float_To_Int_Floor(val); + int idx1=idx0+1; + float frac=val-(float)idx0; + + idx0+=ARC_TABLE_SIZE/2; + idx1+=ARC_TABLE_SIZE/2; + + // we dont even get close to the edge of the table... + assert((idx0 >= 0) && (idx0 < ARC_TABLE_SIZE)); + assert((idx1 >= 0) && (idx1 < ARC_TABLE_SIZE)); + + // compute and return the interpolated value + return (1.0f - frac) * _FastAcosTable[idx0] + frac * _FastAcosTable[idx1]; +} + +WWINLINE float WWMath::Fast_Asin(float val) +{ + // Near -1 and +1, the table becomes too inaccurate + if (Fabsf_Legacy(val) > 0.975f) { + return Asin_Legacy(val); + } + + val*=float(ARC_TABLE_SIZE/2); + + int idx0=Float_To_Int_Floor(val); + int idx1=idx0+1; + float frac=val-(float)idx0; + + idx0+=ARC_TABLE_SIZE/2; + idx1+=ARC_TABLE_SIZE/2; + + // we dont even get close to the edge of the table... + assert((idx0 >= 0) && (idx0 < ARC_TABLE_SIZE)); + assert((idx1 >= 0) && (idx1 < ARC_TABLE_SIZE)); + + // compute and return the interpolated value + return (1.0f - frac) * _FastAsinTable[idx0] + frac * _FastAsinTable[idx1]; +} + +WWINLINE float WWMath::Acos_Legacy(float val) +{ +#if USE_DETERMINISTIC_MATH + return gm_acosf(val); +#else + return (float)acos((double)val); +#endif +} + +WWINLINE float WWMath::Acos(float x) +{ +#if USE_DETERMINISTIC_MATH + return gm_acosf(x); +#else + return (float)Acos((double)x); +#endif +} + +WWINLINE double WWMath::Acos(double x) +{ +#if USE_DETERMINISTIC_MATH + return gm_acos(x); +#else + return acos(x); +#endif +} + +WWINLINE float WWMath::Acosf(float x) +{ +#if USE_DETERMINISTIC_MATH + return gm_acosf(x); +#else + return acosf(x); +#endif +} + +WWINLINE float WWMath::Asin_Legacy(float val) +{ +#if USE_DETERMINISTIC_MATH + return gm_asinf(val); +#else + return (float)asin((double)val); +#endif +} + +WWINLINE float WWMath::Asin(float x) +{ +#if USE_DETERMINISTIC_MATH + return gm_asinf(x); +#else + return (float)Asin((double)x); +#endif +} + +WWINLINE double WWMath::Asin(double x) +{ +#if USE_DETERMINISTIC_MATH + return gm_asin(x); +#else + return asin(x); +#endif +} +WWINLINE float WWMath::Asinf(float x) +{ +#if USE_DETERMINISTIC_MATH + return gm_asinf(x); +#else + return asinf(x); +#endif +} + +WWINLINE float WWMath::Atan_Legacy(float x) +{ +#if USE_DETERMINISTIC_MATH + return gm_atanf(x); +#else + return (float)atan((double)x); +#endif +} + +WWINLINE float WWMath::Atan(float x) +{ +#if USE_DETERMINISTIC_MATH + return gm_atanf(x); +#else + return (float)Atan((double)x); +#endif +} + +WWINLINE double WWMath::Atan(double x) +{ +#if USE_DETERMINISTIC_MATH + return gm_atan(x); +#else + return atan(x); +#endif +} + +WWINLINE float WWMath::Atanf(float x) +{ +#if USE_DETERMINISTIC_MATH + return gm_atanf(x); +#else + return atanf(x); +#endif +} + +WWINLINE float WWMath::Atan2_Legacy(float x, float y) +{ +#if USE_DETERMINISTIC_MATH + return gm_atan2f(x, y); +#else + return (float)atan2((double)x, (double)y); +#endif +} + +WWINLINE float WWMath::Atan2(float x, float y) +{ +#if USE_DETERMINISTIC_MATH + return gm_atan2f(x, y); +#else + return (float)Atan2((double)x, (double)y); +#endif +} + +WWINLINE double WWMath::Atan2(double x, double y) +{ +#if USE_DETERMINISTIC_MATH + return gm_atan2(x, y); +#else + return atan2(x, y); +#endif +} + +WWINLINE float WWMath::Atan2f(float x, float y) +{ +#if USE_DETERMINISTIC_MATH + return gm_atan2f(x, y); +#else + return atan2f(x, y); +#endif +} + +WWINLINE float WWMath::Fast_Cos(float val) +{ + val+=(WWMATH_PI * 0.5f); + val*=float(SIN_TABLE_SIZE) / (2.0f * WWMATH_PI); + + int idx0=Float_To_Int_Floor(val); + int idx1=idx0+1; + float frac=val-(float)idx0; + + idx0 = ((unsigned)idx0) & (SIN_TABLE_SIZE-1); + idx1 = ((unsigned)idx1) & (SIN_TABLE_SIZE-1); + + return (1.0f - frac) * _FastSinTable[idx0] + frac * _FastSinTable[idx1]; +} + +WWINLINE float WWMath::Fast_Inv_Cos(float val) +{ +#if 0 // TODO: more testing, not reliable! + float index = val + (WWMATH_PI * 0.5f); + index *= float(SIN_TABLE_SIZE) / (2.0f * WWMATH_PI); + + int idx0=Float_To_Int_Chop(index); + int idx1=idx0+1; + float frac=val-(float)idx0; + + idx0 = ((unsigned)idx0) & (SIN_TABLE_SIZE-1); + idx1 = ((unsigned)idx1) & (SIN_TABLE_SIZE-1); + + // The table becomes inaccurate near 0 and 2pi so fall back to doing a divide. + if ((idx0 <= 2) || (idx0 >= SIN_TABLE_SIZE-3)) { + return 1.0f / Fast_Cos(val); + } else { + return (1.0f - frac) * _FastInvSinTable[idx0] + frac * _FastInvSinTable[idx1]; + } +#else + return 1.0f / Fast_Cos(val); +#endif +} + +WWINLINE float WWMath::Fast_Sin(float val) +{ + val*=float(SIN_TABLE_SIZE) / (2.0f * WWMATH_PI); + + int idx0=Float_To_Int_Floor(val); + int idx1=idx0+1; + float frac=val-(float)idx0; + + idx0 = ((unsigned)idx0) & (SIN_TABLE_SIZE-1); + idx1 = ((unsigned)idx1) & (SIN_TABLE_SIZE-1); + + return (1.0f - frac) * _FastSinTable[idx0] + frac * _FastSinTable[idx1]; +} + +WWINLINE float WWMath::Fast_Inv_Sin(float val) +{ +#if 0 // TODO: more testing, not reliable! + float index = val * float(SIN_TABLE_SIZE) / (2.0f * WWMATH_PI); + + int idx0=Float_To_Int_Floor(index); + int idx1=idx0+1; + float frac=val-(float)idx0; + + idx0 = ((unsigned)idx0) & (SIN_TABLE_SIZE-1); + idx1 = ((unsigned)idx1) & (SIN_TABLE_SIZE-1); + + // The table becomes inaccurate near 0 and 2pi so fall back to doing a divide. + const int BUFFER = 16; + if ((idx0 <= BUFFER) || (idx0 >= SIN_TABLE_SIZE-BUFFER-1)) { + return 1.0f / Fast_Sin(val); + } else { + return (1.0f - frac) * _FastInvSinTable[idx0] + frac * _FastInvSinTable[idx1]; + } +#else + return 1.0f / Fast_Sin(val); +#endif +} + +WWINLINE float WWMath::Cos(float val) +{ +#if USE_DETERMINISTIC_MATH + return gm_cosf(val); +#else + return (float)Cos((double)val); +#endif +} + +WWINLINE double WWMath::Cos(double val) +{ +#if USE_DETERMINISTIC_MATH + return gm_cos(val); +#else + return cos(val); +#endif +} + +WWINLINE float WWMath::Cosf(float val) +{ +#if USE_DETERMINISTIC_MATH + return gm_cosf(val); +#else + return cosf(val); +#endif +} + +WWINLINE float WWMath::Cosf_Legacy(float val) +{ +#if USE_DETERMINISTIC_MATH + return gm_cosf(val); + +#elif defined(_MSC_VER) && defined(_M_IX86) + float retval; + __asm { + fld [val] + fcos + fstp [retval] + } + return retval; + +#else + return cosf(val); +#endif +} + +WWINLINE float WWMath::Sin(float val) +{ +#if USE_DETERMINISTIC_MATH + return gm_sinf(val); +#else + return (float)Sin((double)val); +#endif +} + +WWINLINE double WWMath::Sin(double val) +{ +#if USE_DETERMINISTIC_MATH + return gm_sin(val); +#else + return sin(val); +#endif +} + +WWINLINE float WWMath::Sinf(float val) +{ +#if USE_DETERMINISTIC_MATH + return gm_sinf(val); +#else + return sinf(val); +#endif +} + +WWINLINE float WWMath::Sinf_Legacy(float val) +{ +#if USE_DETERMINISTIC_MATH + return gm_sinf(val); + +#elif defined(_MSC_VER) && defined(_M_IX86) + float retval; + __asm { + fld [val] + fsin + fstp [retval] + } + return retval; + +#else + return sinf(val); +#endif +} + +WWINLINE float WWMath::Tan(float x) +{ +#if USE_DETERMINISTIC_MATH + return gm_tanf(x); +#else + return (float)Tan((double)x); +#endif +} + +WWINLINE double WWMath::Tan(double x) +{ +#if USE_DETERMINISTIC_MATH + return gm_tan(x); +#else + return tan(x); +#endif +} + +WWINLINE float WWMath::Tanf(float x) +{ +#if USE_DETERMINISTIC_MATH + return gm_tanf(x); +#else + return tanf(x); +#endif +} + +WWINLINE double WWMath::Cosh(double x) +{ +#if USE_DETERMINISTIC_MATH + return gm_cosh(x); +#else + return cosh(x); +#endif +} + +WWINLINE float WWMath::Coshf(float x) +{ +#if USE_DETERMINISTIC_MATH + return gm_coshf(x); +#else + return coshf(x); +#endif +} + +WWINLINE double WWMath::Sinh(double x) +{ +#if USE_DETERMINISTIC_MATH + return gm_sinh(x); +#else + return sinh(x); +#endif +} + +WWINLINE float WWMath::Sinhf(float x) +{ +#if USE_DETERMINISTIC_MATH + return gm_sinhf(x); +#else + return sinhf(x); +#endif +} + +WWINLINE double WWMath::Tanh(double x) +{ +#if USE_DETERMINISTIC_MATH + return gm_tanh(x); +#else + return tanh(x); +#endif +} + +WWINLINE float WWMath::Tanhf(float x) +{ +#if USE_DETERMINISTIC_MATH + return gm_tanhf(x); +#else + return tanhf(x); +#endif +} + +WWINLINE float WWMath::Fabs(float x) +{ +#if USE_DETERMINISTIC_MATH + return gm_fabsf(x); +#else + return (float)Fabs((double)x); +#endif +} + +WWINLINE double WWMath::Fabs(double x) +{ +#if USE_DETERMINISTIC_MATH + return gm_fabs(x); +#else + return fabs(x); +#endif +} + +WWINLINE float WWMath::Fabsf(float x) +{ +#if USE_DETERMINISTIC_MATH + return gm_fabsf(x); +#else + return fabsf(x); +#endif +} + +WWINLINE float WWMath::Fabsf_Legacy(float val) +{ +#if USE_DETERMINISTIC_MATH + return gm_fabsf(val); + +#elif defined(_MSC_VER) && defined(_M_IX86) + int value=*(int*)&val; + value&=0x7fffffff; + return *(float*)&value; + +#else + return fabsf(val); +#endif +} + +WWINLINE double WWMath::Ceil(double x) +{ +#if USE_DETERMINISTIC_MATH + return gm_ceil(x); +#else + return ceil(x); +#endif +} + +WWINLINE float WWMath::Ceilf(float x) +{ +#if USE_DETERMINISTIC_MATH + return gm_ceilf(x); +#else + return ceilf(x); +#endif +} + +WWINLINE double WWMath::Floor(double x) +{ +#if USE_DETERMINISTIC_MATH + return gm_floor(x); +#else + return floor(x); +#endif +} + +WWINLINE float WWMath::Floorf(float x) +{ +#if USE_DETERMINISTIC_MATH + return gm_floorf(x); +#else + return floorf(x); +#endif +} + +WWINLINE double WWMath::Exp(double x) +{ +#if USE_DETERMINISTIC_MATH + return gm_exp(x); +#else + return exp(x); +#endif +} + +WWINLINE float WWMath::Expf(float x) +{ +#if USE_DETERMINISTIC_MATH + return gm_expf(x); +#else + return expf(x); +#endif +} + +WWINLINE double WWMath::Log10(double x) +{ +#if USE_DETERMINISTIC_MATH + return gm_log10(x); +#else + return log10(x); +#endif +} + +WWINLINE float WWMath::Log10f(float x) +{ +#if USE_DETERMINISTIC_MATH + return gm_log10f(x); +#else + return log10f(x); +#endif +} + +WWINLINE double WWMath::Log(double x) +{ +#if USE_DETERMINISTIC_MATH + return gm_log(x); +#else + return log(x); +#endif +} + +WWINLINE float WWMath::Logf(float x) { - if (val > 0.0f) { - return +1.0f; - } - if (val < 0.0f) { - return -1.0f; - } - return 0.0f; +#if USE_DETERMINISTIC_MATH + return gm_logf(x); +#else + return logf(x); +#endif } WWINLINE bool WWMath::Fast_Is_Float_Positive(const float & val) @@ -309,278 +1053,43 @@ WWINLINE bool WWMath::Is_Valid_Double(double x) return true; } -// ---------------------------------------------------------------------------- -// Float to long -// ---------------------------------------------------------------------------- - -#if defined(_MSC_VER) && defined(_M_IX86) WWINLINE long WWMath::Float_To_Long(float f) { - long i; +#if USE_DETERMINISTIC_MATH + return gm_lrintf(f); +#elif defined(_MSC_VER) && defined(_M_IX86) + long i; __asm { fld [f] fistp [i] } - return i; -} + #else -WWINLINE long WWMath::Float_To_Long(float f) -{ - return (long) f; -} + return (long)f; #endif +} WWINLINE long WWMath::Float_To_Long(double f) { -#if defined(_MSC_VER) && defined(_M_IX86) +#if USE_DETERMINISTIC_MATH + return gm_lrint(f); + +#elif defined(_MSC_VER) && defined(_M_IX86) long retval; __asm { fld qword ptr [f] fistp dword ptr [retval] } return retval; -#else - return (long) f; -#endif -} - -// ---------------------------------------------------------------------------- -// Cos -// ---------------------------------------------------------------------------- - -#if defined(_MSC_VER) && defined(_M_IX86) -WWINLINE float WWMath::Cos(float val) -{ - float retval; - __asm { - fld [val] - fcos - fstp [retval] - } - return retval; -} -#else -WWINLINE float WWMath::Cos(float val) -{ - return cosf(val); -} -#endif - -// ---------------------------------------------------------------------------- -// Sin -// ---------------------------------------------------------------------------- - -#if defined(_MSC_VER) && defined(_M_IX86) -WWINLINE float WWMath::Sin(float val) -{ - float retval; - __asm { - fld [val] - fsin - fstp [retval] - } - return retval; -} -#else -WWINLINE float WWMath::Sin(float val) -{ - return sinf(val); -} -#endif - -// ---------------------------------------------------------------------------- -// Fast, table based sin -// ---------------------------------------------------------------------------- - -WWINLINE float WWMath::Fast_Sin(float val) -{ - val*=float(SIN_TABLE_SIZE) / (2.0f * WWMATH_PI); - - int idx0=Float_To_Int_Floor(val); - int idx1=idx0+1; - float frac=val-(float)idx0; - - idx0 = ((unsigned)idx0) & (SIN_TABLE_SIZE-1); - idx1 = ((unsigned)idx1) & (SIN_TABLE_SIZE-1); - - return (1.0f - frac) * _FastSinTable[idx0] + frac * _FastSinTable[idx1]; -} - -// ---------------------------------------------------------------------------- -// Fast, table based 1.0f/sin -// ---------------------------------------------------------------------------- - -WWINLINE float WWMath::Fast_Inv_Sin(float val) -{ -#if 0 // TODO: more testing, not reliable! - float index = val * float(SIN_TABLE_SIZE) / (2.0f * WWMATH_PI); - - int idx0=Float_To_Int_Floor(index); - int idx1=idx0+1; - float frac=val-(float)idx0; - - idx0 = ((unsigned)idx0) & (SIN_TABLE_SIZE-1); - idx1 = ((unsigned)idx1) & (SIN_TABLE_SIZE-1); - - // The table becomes inaccurate near 0 and 2pi so fall back to doing a divide. - const int BUFFER = 16; - if ((idx0 <= BUFFER) || (idx0 >= SIN_TABLE_SIZE-BUFFER-1)) { - return 1.0f / WWMath::Fast_Sin(val); - } else { - return (1.0f - frac) * _FastInvSinTable[idx0] + frac * _FastInvSinTable[idx1]; - } -#else - return 1.0f / WWMath::Fast_Sin(val); -#endif -} - -// ---------------------------------------------------------------------------- -// Fast, table based cos -// ---------------------------------------------------------------------------- - -WWINLINE float WWMath::Fast_Cos(float val) -{ - val+=(WWMATH_PI * 0.5f); - val*=float(SIN_TABLE_SIZE) / (2.0f * WWMATH_PI); - - int idx0=Float_To_Int_Floor(val); - int idx1=idx0+1; - float frac=val-(float)idx0; - - idx0 = ((unsigned)idx0) & (SIN_TABLE_SIZE-1); - idx1 = ((unsigned)idx1) & (SIN_TABLE_SIZE-1); - - return (1.0f - frac) * _FastSinTable[idx0] + frac * _FastSinTable[idx1]; -} - -// ---------------------------------------------------------------------------- -// Fast, table based 1.0f/cos -// ---------------------------------------------------------------------------- - -WWINLINE float WWMath::Fast_Inv_Cos(float val) -{ -#if 0 // TODO: more testing, not reliable! - float index = val + (WWMATH_PI * 0.5f); - index *= float(SIN_TABLE_SIZE) / (2.0f * WWMATH_PI); - - int idx0=Float_To_Int_Chop(index); - int idx1=idx0+1; - float frac=val-(float)idx0; - - idx0 = ((unsigned)idx0) & (SIN_TABLE_SIZE-1); - idx1 = ((unsigned)idx1) & (SIN_TABLE_SIZE-1); - - // The table becomes inaccurate near 0 and 2pi so fall back to doing a divide. - if ((idx0 <= 2) || (idx0 >= SIN_TABLE_SIZE-3)) { - return 1.0f / WWMath::Fast_Cos(val); - } else { - return (1.0f - frac) * _FastInvSinTable[idx0] + frac * _FastInvSinTable[idx1]; - } #else - return 1.0f / WWMath::Fast_Cos(val); + return (long)f; #endif } -// ---------------------------------------------------------------------------- -// Fast, table based arc cos -// ---------------------------------------------------------------------------- - -WWINLINE float WWMath::Fast_Acos(float val) -{ - // Near -1 and +1, the table becomes too inaccurate - if (WWMath::Fabs(val) > 0.975f) { - return WWMath::Acos(val); - } - - val*=float(ARC_TABLE_SIZE/2); - - int idx0=Float_To_Int_Floor(val); - int idx1=idx0+1; - float frac=val-(float)idx0; - - idx0+=ARC_TABLE_SIZE/2; - idx1+=ARC_TABLE_SIZE/2; - - // we dont even get close to the edge of the table... - assert((idx0 >= 0) && (idx0 < ARC_TABLE_SIZE)); - assert((idx1 >= 0) && (idx1 < ARC_TABLE_SIZE)); - - // compute and return the interpolated value - return (1.0f - frac) * _FastAcosTable[idx0] + frac * _FastAcosTable[idx1]; -} - -// ---------------------------------------------------------------------------- -// Arc cos -// ---------------------------------------------------------------------------- - -WWINLINE float WWMath::Acos(float val) -{ - return (float)acos(val); -} - -// ---------------------------------------------------------------------------- -// Fast, table based arc sin -// ---------------------------------------------------------------------------- - -WWINLINE float WWMath::Fast_Asin(float val) -{ - // Near -1 and +1, the table becomes too inaccurate - if (WWMath::Fabs(val) > 0.975f) { - return WWMath::Asin(val); - } - - val*=float(ARC_TABLE_SIZE/2); - - int idx0=Float_To_Int_Floor(val); - int idx1=idx0+1; - float frac=val-(float)idx0; - - idx0+=ARC_TABLE_SIZE/2; - idx1+=ARC_TABLE_SIZE/2; - - // we dont even get close to the edge of the table... - assert((idx0 >= 0) && (idx0 < ARC_TABLE_SIZE)); - assert((idx1 >= 0) && (idx1 < ARC_TABLE_SIZE)); - - // compute and return the interpolated value - return (1.0f - frac) * _FastAsinTable[idx0] + frac * _FastAsinTable[idx1]; -} - -// ---------------------------------------------------------------------------- -// Arc sin -// ---------------------------------------------------------------------------- - -WWINLINE float WWMath::Asin(float val) -{ - return (float)asin(val); -} - -// ---------------------------------------------------------------------------- -// Sqrt -// ---------------------------------------------------------------------------- - -#if defined(_MSC_VER) && defined(_M_IX86) -WWINLINE float WWMath::Sqrt(float val) -{ - float retval; - __asm { - fld [val] - fsqrt - fstp [retval] - } - return retval; -} -#else -WWINLINE float WWMath::Sqrt(float val) -{ - return (float)sqrt(val); -} -#endif - -WWINLINE int WWMath::Float_To_Int_Chop(const float& f) +WWINLINE int WWMath::Float_To_Int_Chop(float f) { int a = *reinterpret_cast(&f); // take bit pattern of float into a register int sign = (a>>31); // sign = 0xFFFFFFFF if original value is negative, 0 if positive @@ -590,7 +1099,7 @@ WWINLINE int WWMath::Float_To_Int_Chop(const float& f) return ((r ^ (sign)) - sign ) &~ (exponent>>31); // add original sign. If exponent was negative, make return value 0. } -WWINLINE int WWMath::Float_To_Int_Floor (const float& f) +WWINLINE int WWMath::Float_To_Int_Floor(float f) { int a = *reinterpret_cast(&f); // take bit pattern of float into a register int sign = (a>>31); // sign = 0xFFFFFFFF if original value is negative, 0 if positive @@ -606,68 +1115,6 @@ WWINLINE int WWMath::Float_To_Int_Floor (const float& f) return r; } -// ---------------------------------------------------------------------------- -// Inverse square root -// ---------------------------------------------------------------------------- - -#if defined(_MSC_VER) && defined(_M_IX86) -WWINLINE float WWMath::Inv_Sqrt(float a) -{ - float retval; - - __asm { - mov eax, 0be6eb508h - mov DWORD PTR [esp-12],03fc00000h ; 1.5 on the stack - sub eax, DWORD PTR [a]; a - sub DWORD PTR [a], 800000h ; a/2 a=Y0 - shr eax, 1 ; firs approx in eax=R0 - mov DWORD PTR [esp-8], eax - - fld DWORD PTR [esp-8] ;r - fmul st, st ;r*r - fld DWORD PTR [esp-8] ;r - fxch st(1) - fmul DWORD PTR [a];a ;r*r*y0 - fld DWORD PTR [esp-12];load 1.5 - fld st(0) - fsub st,st(2) ;r1 = 1.5 - y1 - ;x1 = st(3) - ;y1 = st(2) - ;1.5 = st(1) - ;r1 = st(0) - - fld st(1) - fxch st(1) - fmul st(3),st ; y2=y1*r1*... - fmul st(3),st ; y2=y1*r1*r1 - fmulp st(4),st ; x2=x1*r1 - fsub st,st(2) ; r2=1.5-y2 - ;x2=st(3) - ;y2=st(2) - ;1.5=st(1) - ;r2 = st(0) - - fmul st(2),st ;y3=y2*r2*... - fmul st(3),st ;x3=x2*r2 - fmulp st(2),st ;y3=y2*r2*r2 - fxch st(1) - fsubp st(1),st ;r3= 1.5 - y3 - ;x3 = st(1) - ;r3 = st(0) - fmulp st(1), st - - fstp retval - } - - return retval; -} -#else -WWINLINE float WWMath::Inv_Sqrt(float val) -{ - return 1.0f / (float)sqrt(val); -} -#endif - WWINLINE float WWMath::Normalize_Angle(float angle) { return angle - (WWMATH_TWO_PI * Floor((angle + WWMATH_PI) / WWMATH_TWO_PI)); diff --git a/Core/Tools/W3DView/RingSizePropPage.cpp b/Core/Tools/W3DView/RingSizePropPage.cpp index bd7c6e32e63..5d7e7b35e84 100644 --- a/Core/Tools/W3DView/RingSizePropPage.cpp +++ b/Core/Tools/W3DView/RingSizePropPage.cpp @@ -735,5 +735,5 @@ Is_LERP { float percent = (curr_time - last_time) / (next_time - last_time); float interpolated_value = last_value + ((next_value-last_value) * percent); - return bool(WWMath::Fabs (interpolated_value - curr_value) < WWMATH_EPSILON); + return bool(WWMath::Fabsf (interpolated_value - curr_value) < WWMATH_EPSILON); } diff --git a/Core/Tools/W3DView/SphereSizePropPage.cpp b/Core/Tools/W3DView/SphereSizePropPage.cpp index f46f07455d0..54648574745 100644 --- a/Core/Tools/W3DView/SphereSizePropPage.cpp +++ b/Core/Tools/W3DView/SphereSizePropPage.cpp @@ -555,5 +555,5 @@ Is_LERP { float percent = (curr_time - last_time) / (next_time - last_time); float interpolated_value = last_value + ((next_value-last_value) * percent); - return bool(WWMath::Fabs (interpolated_value - curr_value) < WWMATH_EPSILON); + return bool(WWMath::Fabsf (interpolated_value - curr_value) < WWMATH_EPSILON); } diff --git a/Generals/Code/GameEngine/Source/Common/RTS/Player.cpp b/Generals/Code/GameEngine/Source/Common/RTS/Player.cpp index 0024c0c95cc..0a7f4457429 100644 --- a/Generals/Code/GameEngine/Source/Common/RTS/Player.cpp +++ b/Generals/Code/GameEngine/Source/Common/RTS/Player.cpp @@ -2367,7 +2367,7 @@ void Player::doBountyForKill(const Object* killer, const Object* victim) Int bounty = REAL_TO_INT_CEIL(costToBuild * m_cashBountyPercent); #else // TheSuperHackers @bugfix Stubbjax 20/02/2026 Subtract epsilon to ensure bounty is rounded up correctly. - Int bounty = ceil((costToBuild * m_cashBountyPercent) - WWMATH_EPSILON); + Int bounty = WWMath::Ceil((costToBuild * m_cashBountyPercent) - WWMATH_EPSILON); #endif if( bounty ) diff --git a/Generals/Code/GameEngine/Source/Common/System/BuildAssistant.cpp b/Generals/Code/GameEngine/Source/Common/System/BuildAssistant.cpp index 6f362160d5c..944d639315c 100644 --- a/Generals/Code/GameEngine/Source/Common/System/BuildAssistant.cpp +++ b/Generals/Code/GameEngine/Source/Common/System/BuildAssistant.cpp @@ -752,8 +752,8 @@ Bool BuildAssistant::isLocationClearOfObjects( const Coord3D *worldPos, if (myFactoryExitWidth>0) { myExitPos = *worldPos; checkMyExit = true; - Real c = (Real)cos(angle); - Real s = (Real)sin(angle); + Real c = (Real)WWMath::Cos(angle); + Real s = (Real)WWMath::Sin(angle); Real offset = build->getTemplateGeometryInfo().getMajorRadius() + myFactoryExitWidth/2.0f; myExitPos.x += c*offset; myExitPos.y += s*offset; @@ -787,8 +787,8 @@ Bool BuildAssistant::isLocationClearOfObjects( const Coord3D *worldPos, if (themFactoryExitWidth>0) { hisExitPos = *them->getPosition(); checkHisExit = true; - Real c = (Real)cos(them->getOrientation()); - Real s = (Real)sin(them->getOrientation()); + Real c = (Real)WWMath::Cos(them->getOrientation()); + Real s = (Real)WWMath::Sin(them->getOrientation()); Real offset = them->getGeometryInfo().getMajorRadius() + themFactoryExitWidth/2.0f; hisExitPos.x += c*offset; hisExitPos.y += s*offset; @@ -1405,7 +1405,7 @@ Bool BuildAssistant::moveObjectsForConstruction( const ThingTemplate *whatToBuil Bool anyUnmovables = false; MemoryPoolObjectHolder hold( iter ); - Real radius = sqrt(pow(gi.getMajorRadius(), 2) + pow(gi.getMinorRadius(), 2)); + Real radius = WWMath::Sqrt(WWMath::Pow(gi.getMajorRadius(), 2) + WWMath::Pow(gi.getMinorRadius(), 2)); radius *= 1.4f; // Fudge the distance, for( Object *them = iter->first(); them; them = iter->next() ) diff --git a/Generals/Code/GameEngine/Source/Common/System/Geometry.cpp b/Generals/Code/GameEngine/Source/Common/System/Geometry.cpp index 2e4c35a2421..66b04f57ea4 100644 --- a/Generals/Code/GameEngine/Source/Common/System/Geometry.cpp +++ b/Generals/Code/GameEngine/Source/Common/System/Geometry.cpp @@ -173,17 +173,17 @@ void GeometryInfo::calcPitches(const Coord3D& thisPos, const GeometryInfo& that, Coord3D thisCenter; getCenterPosition(thisPos, thisCenter); - Real dxy = sqrt(sqr(thatPos.x - thisCenter.x) + sqr(thatPos.y - thisCenter.y)); + Real dxy = WWMath::Sqrt(sqr(thatPos.x - thisCenter.x) + sqr(thatPos.y - thisCenter.y)); Real dz; /** @todo srj -- this could be better, by calcing it for all the corners, not just top-center and bottom-center... oh well */ dz = (thatPos.z + that.getMaxHeightAbovePosition()) - thisCenter.z; - maxPitch = atan2(dz, dxy); + maxPitch = WWMath::Atan2(dz, dxy); dz = (thatPos.z - that.getMaxHeightBelowPosition()) - thisCenter.z; - minPitch = atan2(dz, dxy); + minPitch = WWMath::Atan2(dz, dxy); } //============================================================================= @@ -279,8 +279,8 @@ void GeometryInfo::get2DBounds(const Coord3D& geomCenter, Real angle, Region2D& case GEOMETRY_BOX: { - Real c = (Real)cos(angle); - Real s = (Real)sin(angle); + Real c = (Real)WWMath::Cos(angle); + Real s = (Real)WWMath::Sin(angle); Real exc = m_majorRadius*c; Real eyc = m_minorRadius*c; Real exs = m_majorRadius*s; @@ -329,7 +329,7 @@ void GeometryInfo::clipPointToFootprint(const Coord3D& geomCenter, Coord3D& ptTo { Real dx = ptToClip.x - geomCenter.x; Real dy = ptToClip.y - geomCenter.y; - Real radius = sqrt(sqr(dx) + sqr(dy)); + Real radius = WWMath::Sqrt(sqr(dx) + sqr(dy)); if (radius > m_majorRadius) { Real ratio = m_majorRadius / radius; @@ -361,7 +361,7 @@ Bool GeometryInfo::isPointInFootprint(const Coord3D& geomCenter, const Coord3D& { Real dx = pt.x - geomCenter.x; Real dy = pt.y - geomCenter.y; - Real radius = sqrt(sqr(dx) + sqr(dy)); + Real radius = WWMath::Sqrt(sqr(dx) + sqr(dy)); return (radius <= m_majorRadius); break; } @@ -506,8 +506,8 @@ void GeometryInfo::calcBoundingStuff() case GEOMETRY_BOX: { - m_boundingCircleRadius = sqrt(sqr(m_majorRadius) + sqr(m_minorRadius)); - m_boundingSphereRadius = sqrt(sqr(m_majorRadius) + sqr(m_minorRadius) + sqr(m_height*0.5)); + m_boundingCircleRadius = WWMath::Sqrt(sqr(m_majorRadius) + sqr(m_minorRadius)); + m_boundingSphereRadius = WWMath::Sqrt(sqr(m_majorRadius) + sqr(m_minorRadius) + sqr(m_height*0.5)); break; } }; diff --git a/Generals/Code/GameEngine/Source/Common/System/Trig.cpp b/Generals/Code/GameEngine/Source/Common/System/Trig.cpp index b09c4cb55d8..7cd4808f1a2 100644 --- a/Generals/Code/GameEngine/Source/Common/System/Trig.cpp +++ b/Generals/Code/GameEngine/Source/Common/System/Trig.cpp @@ -29,117 +29,24 @@ #include "PreRTS.h" -#include -#include - #include "Lib/BaseType.h" #include "Lib/trig.h" -#define TWOPI 6.28318530718f -#define DEG2RAD 0.0174532925199f -#define TRIG_RES 4096 - -// the following are for fixed point ints with 12 fractional bits -#define INT_ONE 4096 -#define INT_TWOPI 25736 -#define INT_THREEPIOVERTWO 19302 -#define INT_PI 12868 -#define INT_HALFPI 6434 - -Real Sin(Real x) -{ - return sinf(x); -} - -Real Cos(Real x) -{ - return cosf(x); -} - -Real Tan(Real x) -{ - return tanf(x); -} - -Real ACos(Real x) -{ - return acosf(x); -} - -Real ASin(Real x) -{ - return asinf(x); -} +#if USE_DETERMINISTIC_MATH +#include "gmath.h" +#endif -#ifdef REGENERATE_TRIG_TABLES -void initTrig() +Real Sin(Real x) { return WWMath::Sinf(x); } +Real Cos(Real x) { return WWMath::Cosf(x); } +Real Tan(Real x) { return WWMath::Tanf(x); } +Real ACos(Real x) { return WWMath::Acosf(x); } +Real ASin(Real x) { return WWMath::Asinf(x); } +Real Sqrt(Real x) { - static Byte inited = FALSE; - Real angle, r; - int i; - - if (inited) - return; - - inited = TRUE; - - static int columns = 8; - int column = 0; - FILE *fp = fopen("trig.txt", "w"); - fprintf(fp, "static Int sinLookup[TRIG_RES] = {\n"); - for( i=0; igetDistanceSquared(me, theEnemy, FROM_BOUNDINGSPHERE_2D); - Real dist = sqrt(distSqr); + Real dist = WWMath::Sqrt(distSqr); Int modifier = dist/getAiData()->m_attackPriorityDistanceModifier; Int modPriority = curPriority-modifier; if (modPriority < 1) diff --git a/Generals/Code/GameEngine/Source/GameLogic/AI/AIGroup.cpp b/Generals/Code/GameEngine/Source/GameLogic/AI/AIGroup.cpp index c91139780ea..676e45df147 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/AI/AIGroup.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/AI/AIGroup.cpp @@ -1839,8 +1839,8 @@ void getHelicopterOffset( Coord3D& posOut, Int idx ) } Coord3D tempCtr = posOut; - posOut.x = tempCtr.x + (sin(angle) * radius); - posOut.y = tempCtr.y + (cos(angle) * radius); + posOut.x = tempCtr.x + (WWMath::Sin(angle) * radius); + posOut.y = tempCtr.y + (WWMath::Cos(angle) * radius); } diff --git a/Generals/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp b/Generals/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp index 2472c2ffefc..f4e026bad3d 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp @@ -488,7 +488,7 @@ Object *AIPlayer::buildStructureNow(const ThingTemplate *bldgPlan, BuildListInfo { Coord3D rallyPoint; Bool gotOffset = false; - if (fabs(info->getRallyOffset()->x) > 1.0f || fabs(info->getRallyOffset()->y)>1.0f) { + if (WWMath::Fabs(info->getRallyOffset()->x) > 1.0f || WWMath::Fabs(info->getRallyOffset()->y)>1.0f) { gotOffset; } if (!exitInterface->getNaturalRallyPoint(rallyPoint)) { @@ -646,7 +646,7 @@ Object *AIPlayer::buildStructureWithDozer(const ThingTemplate *bldgPlan, BuildLi dx = dozer->getPosition()->x - pos.x; dy = dozer->getPosition()->y - pos.y; - Int count = sqrt(dx*dx+dy*dy)/(PATHFIND_CELL_SIZE_F/2); + Int count = WWMath::Sqrt(dx*dx+dy*dy)/(PATHFIND_CELL_SIZE_F/2); if (count<2) count = 2; Int i; color.green = 1; @@ -668,7 +668,7 @@ Object *AIPlayer::buildStructureWithDozer(const ThingTemplate *bldgPlan, BuildLi { Coord3D rallyPoint; Bool gotOffset = false; - if (fabs(info->getRallyOffset()->x) > 1.0f || fabs(info->getRallyOffset()->y)>1.0f) { + if (WWMath::Fabs(info->getRallyOffset()->x) > 1.0f || WWMath::Fabs(info->getRallyOffset()->y)>1.0f) { gotOffset; } if (!exitInterface->getNaturalRallyPoint(rallyPoint)) { @@ -1251,7 +1251,7 @@ Int AIPlayer::getPlayerSuperweaponValue(Coord3D *center, Int playerNdx, Real rad Real dx = center->x - pos.x; Real dy = center->y - pos.y; if (dx*dx+dy*dygetTemplate()->calcCostToBuild(pPlayer); if (pObj->isKindOf(KINDOF_COMMANDCENTER)) { @@ -2812,7 +2812,7 @@ void AIPlayer::computeCenterAndRadiusOfBase(Coord3D *center, Real *radius) Real radSqr = dx*dx+dy*dy; if (radSqr>maxRadSqr) maxRadSqr=radSqr; } - *radius = sqrt(maxRadSqr); + *radius = WWMath::Sqrt(maxRadSqr); } //---------------------------------------------------------------------------------------------------------- diff --git a/Generals/Code/GameEngine/Source/GameLogic/AI/AISkirmishPlayer.cpp b/Generals/Code/GameEngine/Source/GameLogic/AI/AISkirmishPlayer.cpp index afb876af064..382237663b9 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/AI/AISkirmishPlayer.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/AI/AISkirmishPlayer.cpp @@ -663,8 +663,8 @@ void AISkirmishPlayer::buildAIBaseDefenseStructure(const AsciiString &thingName, } if (angle > PI/3) break; - Real s = sin(angle); - Real c = cos(angle); + Real s = WWMath::Sin(angle); + Real c = WWMath::Cos(angle); // TheSuperHackers @info helmutbuhler 21/04/2025 This debug mutates the code to become CRC incompatible #if defined(RTS_DEBUG) || !RETAIL_COMPATIBLE_CRC @@ -1029,8 +1029,8 @@ void AISkirmishPlayer::adjustBuildList(BuildListInfo *list) angle += 3*PI/4; - Real s = sin(angle); - Real c = cos(angle); + Real s = WWMath::Sin(angle); + Real c = WWMath::Cos(angle); cur = list; while (cur) { diff --git a/Generals/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp b/Generals/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp index 7ce23ef377e..ccb6c616a28 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp @@ -524,7 +524,7 @@ StateReturnType AIRappelState::onEnter() obj->setLayer(layerAtDest); AIUpdateInterface *ai = obj->getAI(); - Real MAX_RAPPEL_RATE = fabs(TheGlobalData->m_gravity) * LOGICFRAMES_PER_SECOND * 2.5f; + Real MAX_RAPPEL_RATE = WWMath::Fabs(TheGlobalData->m_gravity) * LOGICFRAMES_PER_SECOND * 2.5f; m_rappelRate = -min(ai->getDesiredSpeed(), MAX_RAPPEL_RATE); return STATE_CONTINUE; @@ -3572,7 +3572,7 @@ StateReturnType AIAttackMoveToState::update() if (distSqr < sqr(ATTACK_CLOSE_ENOUGH_CELLS*PATHFIND_CELL_SIZE_F)) { return ret; } - DEBUG_LOG(("AIAttackMoveToState::update Distance from goal %f, retrying.", sqrt(distSqr))); + DEBUG_LOG(("AIAttackMoveToState::update Distance from goal %f, retrying.", WWMath::Sqrt(distSqr))); ret = STATE_CONTINUE; m_retryCount--; @@ -3802,16 +3802,16 @@ void AIFollowWaypointPathState::computeGoal(Bool useGroupOffsets) if (m_priorWaypoint) { dx = dest.x - m_priorWaypoint->getLocation()->x; dy = dest.y - m_priorWaypoint->getLocation()->y; - angle = atan2(dy, dx); + angle = WWMath::Atan2(dy, dx); Real deltaAngle = angle - m_angle; - Real s = sin(deltaAngle); - Real c = cos(deltaAngle); + Real s = WWMath::Sin(deltaAngle); + Real c = WWMath::Cos(deltaAngle); Real x = m_groupOffset.x * c - m_groupOffset.y * s; Real y = m_groupOffset.y * c + m_groupOffset.x * s; m_groupOffset.x = x; m_groupOffset.y = y; } else { - angle = atan2(dy, dx); + angle = WWMath::Atan2(dy, dx); } m_angle = angle; #endif @@ -4933,7 +4933,7 @@ StateReturnType AIAttackAimAtTargetState::update() //DEBUG_LOG(("AIM: desired %f, actual %f, delta %f, aimDelta %f, goalpos %f %f",rad2deg(obj->getOrientation() + relAngle),rad2deg(obj->getOrientation()),rad2deg(relAngle),rad2deg(aimDelta),victim->getPosition()->x,victim->getPosition()->y)); if (m_canTurnInPlace) { - if (fabs(relAngle) > aimDelta) + if (WWMath::Fabs(relAngle) > aimDelta) { Real desiredAngle = source->getOrientation() + relAngle; sourceAI->setLocomotorGoalOrientation(desiredAngle); @@ -4945,7 +4945,7 @@ StateReturnType AIAttackAimAtTargetState::update() sourceAI->setLocomotorGoalPositionExplicit(m_isAttackingObject ? *victim->getPosition() : *getMachineGoalPosition()); } - if (fabs(relAngle) < aimDelta /*&& !m_preAttackFrames*/ ) + if (WWMath::Fabs(relAngle) < aimDelta /*&& !m_preAttackFrames*/ ) { AIUpdateInterface* victimAI = victim ? victim->getAI() : nullptr; // add ourself as a targeter BEFORE calling isTemporarilyPreventingAimSuccess(). @@ -6989,7 +6989,7 @@ StateReturnType AIFaceState::update() Real relAngle = ThePartitionManager->getRelativeAngle2D( obj, pos ); const Real REL_THRESH = 0.035f; // about 2 degrees. (getRelativeAngle2D is current only accurate to about 1.25 degrees) - if( fabs( relAngle ) < REL_THRESH ) + if( WWMath::Fabs( relAngle ) < REL_THRESH ) { return STATE_SUCCESS; } diff --git a/Generals/Code/GameEngine/Source/GameLogic/AI/TurretAI.cpp b/Generals/Code/GameEngine/Source/GameLogic/AI/TurretAI.cpp index 651e2c4f2f0..92ed666cfe0 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/AI/TurretAI.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/AI/TurretAI.cpp @@ -386,7 +386,7 @@ Bool TurretAI::friend_turnTowardsAngle(Real desiredAngle, Real rateModifier, Rea Real angleDiff = normalizeAngle(desiredAngle - actualAngle); // Are we close enough to the desired angle to just snap there? - if (fabs(angleDiff) < turnRate) + if (WWMath::Fabs(angleDiff) < turnRate) { // we are centered actualAngle = desiredAngle; @@ -409,7 +409,7 @@ Bool TurretAI::friend_turnTowardsAngle(Real desiredAngle, Real rateModifier, Rea if( m_angle != origAngle ) getOwner()->reactToTurretChange( m_whichTurret, origAngle, m_pitch ); - Bool aligned = fabs(m_angle - desiredAngle) <= relThresh; + Bool aligned = WWMath::Fabs(m_angle - desiredAngle) <= relThresh; return aligned; } @@ -427,7 +427,7 @@ Bool TurretAI::friend_turnTowardsPitch(Real desiredPitch, Real rateModifier) Real pitchRate = getPitchRate() * rateModifier; Real pitchDiff = normalizeAngle(desiredPitch - actualPitch); - if (fabs(pitchDiff) < pitchRate) + if (WWMath::Fabs(pitchDiff) < pitchRate) { // we are centered actualPitch = desiredPitch; @@ -1070,7 +1070,7 @@ StateReturnType TurretAIAimTurretState::update() turret->friend_setPositiveSweep(!turret->friend_getPositiveSweep()); Real angleDiff = normalizeAngle(relAngle - turret->getTurretAngle()); - turnAlignedToNemesis = (fabs(angleDiff) < sweep); + turnAlignedToNemesis = (WWMath::Fabs(angleDiff) < sweep); } Bool pitchAlignedToNemesis = true; diff --git a/Generals/Code/GameEngine/Source/GameLogic/Map/PolygonTrigger.cpp b/Generals/Code/GameEngine/Source/GameLogic/Map/PolygonTrigger.cpp index 6cea7c6227a..c17f6f8315a 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Map/PolygonTrigger.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Map/PolygonTrigger.cpp @@ -270,7 +270,7 @@ void PolygonTrigger::updateBounds() const Real halfWidth = (m_bounds.hi.x - m_bounds.lo.x) / 2.0f; Real halfHeight = (m_bounds.hi.y + m_bounds.lo.y) / 2.0f; - m_radius = sqrt(halfHeight*halfHeight + halfWidth*halfWidth); + m_radius = WWMath::Sqrt(halfHeight*halfHeight + halfWidth*halfWidth); } diff --git a/Generals/Code/GameEngine/Source/GameLogic/Map/TerrainLogic.cpp b/Generals/Code/GameEngine/Source/GameLogic/Map/TerrainLogic.cpp index d5eff4130f6..22f8439b3b7 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Map/TerrainLogic.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Map/TerrainLogic.cpp @@ -1468,7 +1468,7 @@ void makeAlignToNormalMatrix( Real angle, const Coord3D& pos, const Coord3D& nor /* It is extremely important that the resulting matrix is such that the xvector points in the angle we specified; specifically, - that atan2(xvec.y, xvec.x) == angle. So we must construct + that WWMath::Atan2(xvec.y, xvec.x) == angle. So we must construct the matrix carefully to ensure this! */ x.x = Cos( angle ); @@ -1489,7 +1489,7 @@ void makeAlignToNormalMatrix( Real angle, const Coord3D& pos, const Coord3D& nor x.normalize(); } - DEBUG_ASSERTCRASH(fabs(x.x*z.x + x.y*z.y + x.z*z.z)<0.0001,("dot is not zero (%f)",fabs(x.x*z.x + x.y*z.y + x.z*z.z))); + DEBUG_ASSERTCRASH(WWMath::Fabs(x.x*z.x + x.y*z.y + x.z*z.z)<0.0001,("dot is not zero (%f)",WWMath::Fabs(x.x*z.x + x.y*z.y + x.z*z.z))); // now computing the y vector is trivial. y.crossProduct( z, x, y ); @@ -1685,12 +1685,12 @@ PathfindLayerEnum TerrainLogic::getLayerForDestination(const Coord3D *pos) { Bridge *pBridge = getFirstBridge(); PathfindLayerEnum bestLayer = LAYER_GROUND; - Real bestDistance = fabs(pos->z - getGroundHeight(pos->x, pos->y)); + Real bestDistance = WWMath::Fabs(pos->z - getGroundHeight(pos->x, pos->y)); if (bestDistance > TheAI->pathfinder()->getWallHeight()/2) { // check wall. if (TheAI->pathfinder()->isPointOnWall(pos)) { - Real delta = fabs(pos->z-TheAI->pathfinder()->getWallHeight()); + Real delta = WWMath::Fabs(pos->z-TheAI->pathfinder()->getWallHeight()); if (deltaisPointOnBridge(pos) ) { - Real delta = fabs(pos->z-pBridge->getBridgeHeight(pos, nullptr)); + Real delta = WWMath::Fabs(pos->z-pBridge->getBridgeHeight(pos, nullptr)); if (deltagetLayer(); bestDistance = delta; @@ -1724,7 +1724,7 @@ PathfindLayerEnum TerrainLogic::getHighestLayerForDestination(const Coord3D *pos if (TheAI->pathfinder()->isPointOnWall(pos)) { Real delta = pos->z - TheAI->pathfinder()->getWallHeight(); // must be ABOVE (or on) the wall for this call. (srj) - if (delta >= 0 && fabs(delta) < fabs(bestDistance)) { + if (delta >= 0 && WWMath::Fabs(delta) < WWMath::Fabs(bestDistance)) { bestLayer = (PathfindLayerEnum)LAYER_WALL; bestDistance = delta; } @@ -1739,7 +1739,7 @@ PathfindLayerEnum TerrainLogic::getHighestLayerForDestination(const Coord3D *pos if (pBridge->isPointOnBridge(pos) ) { Real delta = pos->z - pBridge->getBridgeHeight(pos, nullptr); // must be ABOVE (or on) the bridge for this call. (srj) - if (delta >= 0 && fabs(delta) < fabs(bestDistance)) { + if (delta >= 0 && WWMath::Fabs(delta) < WWMath::Fabs(bestDistance)) { bestLayer = pBridge->getLayer(); bestDistance = delta; } @@ -1788,7 +1788,7 @@ Bool TerrainLogic::objectInteractsWithBridgeLayer(Object *obj, Int layer, Bool c if (match) { Real bridgeHeight = pBridge->getBridgeHeight(obj->getPosition(), nullptr); - Real delta = fabs(obj->getPosition()->z-bridgeHeight); + Real delta = WWMath::Fabs(obj->getPosition()->z-bridgeHeight); if (delta>LAYER_Z_CLOSE_ENOUGH_F) { return false; } @@ -1837,7 +1837,7 @@ Bool TerrainLogic::objectInteractsWithBridgeEnd(Object *obj, Int layer) const if (match) { Real bridgeHeight = pBridge->getBridgeHeight(obj->getPosition(), nullptr); - Real delta = fabs(obj->getPosition()->z-bridgeHeight); + Real delta = WWMath::Fabs(obj->getPosition()->z-bridgeHeight); if (delta>LAYER_Z_CLOSE_ENOUGH_F) { return false; @@ -2055,10 +2055,10 @@ Coord3D TerrainLogic::findClosestEdgePoint ( const Coord3D *closestTo ) const getExtent( &mapExtent ); Real distances[4]; - distances[0] = fabs( closestTo->y - mapExtent.lo.y );//top - distances[1] = fabs( closestTo->x - mapExtent.hi.x );//right - distances[2] = fabs( closestTo->y - mapExtent.hi.y );//bottom - distances[3] = fabs( closestTo->x - mapExtent.lo.x );//left + distances[0] = WWMath::Fabs( closestTo->y - mapExtent.lo.y );//top + distances[1] = WWMath::Fabs( closestTo->x - mapExtent.hi.x );//right + distances[2] = WWMath::Fabs( closestTo->y - mapExtent.hi.y );//bottom + distances[3] = WWMath::Fabs( closestTo->x - mapExtent.lo.x );//left Real bestDistance = distances[0]; Int bestDistanceIndex = 0; for( Int lameIndex = 1; lameIndex < 4; lameIndex++ ) @@ -2369,7 +2369,7 @@ void TerrainLogic::setWaterHeight( const WaterHandle *water, Real height, Real d center.z = 0.0f; // irrelavant // the max radius to scan around us is the diagonal of the bounding region - Real maxDist = sqrt( affectedRegion.width() * affectedRegion.width() + + Real maxDist = WWMath::Sqrt( affectedRegion.width() * affectedRegion.width() + affectedRegion.height() * affectedRegion.height() ); // scan the objects in the area of the water affected diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/DumbProjectileBehavior.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/DumbProjectileBehavior.cpp index 7c4bc633863..66e57aa0036 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/DumbProjectileBehavior.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/DumbProjectileBehavior.cpp @@ -169,24 +169,24 @@ static Bool calcTrajectory( Real dz = end.z - start.z; // calculating the angle is trivial. - angle = atan2(dy, dx); + angle = WWMath::Atan2(dy, dx); // calculating the pitch requires a bit more effort. Real horizDistSqr = sqr(dx) + sqr(dy); - Real horizDist = sqrt(horizDistSqr); + Real horizDist = WWMath::Sqrt(horizDistSqr); // calc the two possible pitches that will cover the given horizontal range. // (this is actually only true if dz==0, but is a good first guess) - Real gravity = fabs(TheGlobalData->m_gravity); + Real gravity = WWMath::Fabs(TheGlobalData->m_gravity); Real gravityTwoDZ = gravity * 2.0f * dz; // let's start by aiming directly for it. we know this isn't right (unless gravity // is zero, which it's not) but is a good starting point... - Real theta = atan2(dz, horizDist); + Real theta = WWMath::Atan2(dz, horizDist); // if the angle isn't pretty shallow, we can get a better initial guess by using // the code below... const Real SHALLOW_ANGLE = 0.5f * PI / 180.0f; - if (fabs(theta) > SHALLOW_ANGLE) + if (WWMath::Fabs(theta) > SHALLOW_ANGLE) { Real t = horizDist / velocity; Real vz = (dz/t + 0.5f*gravity*t); @@ -287,7 +287,7 @@ static Bool calcTrajectory( #endif vx = velocity*cosPitches[preferred]; - Real actualRange = (vx*(vz + sqrt(root)))/gravity; + Real actualRange = (vx*(vz + WWMath::Sqrt(root)))/gravity; const Real CLOSE_ENOUGH_RANGE = 5.0f; if (tooClose || (actualRange < horizDist - CLOSE_ENOUGH_RANGE)) { @@ -366,7 +366,7 @@ void DumbProjectileBehavior::projectileFireAtObjectOrPosition( const Object *vic // Some weapons want to scale their start speed to the range Real minRange = detWeap->getMinimumAttackRange(); Real maxRange = detWeap->getUnmodifiedAttackRange(); - Real range = sqrt(ThePartitionManager->getDistanceSquared( projectile, &victimPosToUse, FROM_CENTER_2D ) ); + Real range = WWMath::Sqrt(ThePartitionManager->getDistanceSquared( projectile, &victimPosToUse, FROM_CENTER_2D ) ); Real rangeRatio = (range - minRange) / (maxRange - minRange); m_flightPathSpeed = (rangeRatio * (weaponSpeed - minWeaponSpeed)) + minWeaponSpeed; } @@ -441,7 +441,7 @@ Bool DumbProjectileBehavior::calcFlightPath(Bool recalcNumSegments) if (recalcNumSegments) { Real flightDistance = flightCurve.getApproximateLength(); - m_flightPathSegments = ceil( flightDistance / m_flightPathSpeed ); + m_flightPathSegments = WWMath::Ceil( flightDistance / m_flightPathSpeed ); } flightCurve.getSegmentPoints( m_flightPathSegments, &m_flightPath ); DEBUG_ASSERTCRASH(m_flightPathSegments == m_flightPath.size(), ("m_flightPathSegments mismatch")); @@ -596,7 +596,7 @@ UpdateSleepTime DumbProjectileBehavior::update() Real distVictimMovedSqr = sqr(delta.x) + sqr(delta.y) + sqr(delta.z); if (distVictimMovedSqr > 0.1f) { - Real distVictimMoved = sqrtf(distVictimMovedSqr); + Real distVictimMoved = WWMath::Sqrtf(distVictimMovedSqr); if (distVictimMoved > d->m_flightPathAdjustDistPerFrame) distVictimMoved = d->m_flightPathAdjustDistPerFrame; delta.normalize(); diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/GenerateMinefieldBehavior.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/GenerateMinefieldBehavior.cpp index b37cf0f2ab3..335e4bc02de 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/GenerateMinefieldBehavior.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/GenerateMinefieldBehavior.cpp @@ -232,7 +232,7 @@ void GenerateMinefieldBehavior::placeMinesAlongLine(const Coord3D& posStart, con Real dx = posEnd.x - posStart.x; Real dy = posEnd.y - posStart.y; - Real len = sqrt(sqr(dx) + sqr(dy)); + Real len = WWMath::Sqrt(sqr(dx) + sqr(dy)); Real mineRadius = mineTemplate->getTemplateGeometryInfo().getBoundingCircleRadius(); Real mineDiameter = mineRadius * 2.0f; Real mineJitter = mineRadius*d->m_randomJitter; diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/MinefieldBehavior.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/MinefieldBehavior.cpp index 5a4b2727060..f0d474ebb35 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/MinefieldBehavior.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/MinefieldBehavior.cpp @@ -562,7 +562,7 @@ void MinefieldBehavior::setScootParms(const Coord3D& start, const Coord3D& end) if (start.z > endOnGround.z) { // figure out how long it will take to fall, and replace scoot time with that - UnsignedInt fallingTime = REAL_TO_INT_CEIL(sqrtf(2.0f * (start.z - endOnGround.z) / fabs(TheGlobalData->m_gravity))); + UnsignedInt fallingTime = REAL_TO_INT_CEIL(WWMath::Sqrtf(2.0f * (start.z - endOnGround.z) / WWMath::Fabs(TheGlobalData->m_gravity))); // we can scoot after we land, but don't want to stop scooting before we land if (scootFromStartingPointTime < fallingTime) scootFromStartingPointTime = fallingTime; @@ -580,8 +580,8 @@ void MinefieldBehavior::setScootParms(const Coord3D& start, const Coord3D& end) Real dx = endOnGround.x - start.x; Real dy = endOnGround.y - start.y; Real dz = endOnGround.z - start.z; - Real dist = sqrt(sqr(dx) + sqr(dy)); - if (dist <= 0.1f && fabs(dz) <= 0.1f) + Real dist = WWMath::Sqrt(sqr(dx) + sqr(dy)); + if (dist <= 0.1f && WWMath::Fabs(dz) <= 0.1f) { obj->setPosition(&endOnGround); m_scootFramesLeft = 0; @@ -590,7 +590,7 @@ void MinefieldBehavior::setScootParms(const Coord3D& start, const Coord3D& end) { Real t = (Real)scootFromStartingPointTime; Real scootFromStartingPointSpeed = dist / t; - Real accelMag = fabs(2.0f * (dist - scootFromStartingPointSpeed*t)/sqr(t)); + Real accelMag = WWMath::Fabs(2.0f * (dist - scootFromStartingPointSpeed*t)/sqr(t)); Real dxNorm = (dist <= 0.1f) ? 0.0f : (dx / dist); Real dyNorm = (dist <= 0.1f) ? 0.0f : (dy / dist); m_scootVel.x = dxNorm * scootFromStartingPointSpeed; diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/SlowDeathBehavior.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/SlowDeathBehavior.cpp index 20bdea05e43..9a2c8f66c29 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/SlowDeathBehavior.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/SlowDeathBehavior.cpp @@ -299,7 +299,7 @@ void SlowDeathBehavior::beginSlowDeath(const DamageInfo *damageInfo) physics->setExtraBounciness(-1.0); // we don't want this guy to bounce at all physics->setExtraFriction(-3 * SECONDS_PER_LOGICFRAME_REAL); // reduce his ground friction a bit physics->setAllowBouncing(true); - Real orientation = atan2(force.y, force.x); + Real orientation = WWMath::Atan2(force.y, force.x); physics->setAngles(orientation, 0, 0); obj->getDrawable()->setModelConditionState(MODELCONDITION_EXPLODED_FLAILING); m_flags |= (1<getPosition()->z) >= d->m_paraOpenDist) + if (WWMath::Fabs(m_startZ - parachute->getPosition()->z) >= d->m_paraOpenDist) { m_opened = true; parachute->clearAndSetModelConditionState(MODELCONDITION_FREEFALL, MODELCONDITION_PARACHUTING); diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp index d751f77dc73..ca49b168ea1 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp @@ -84,7 +84,7 @@ static Real calcSlowDownDist(Real curSpeed, Real desiredSpeed, Real maxBraking) if (delta <= 0) return 0.0f; - Real dist = (sqr(delta) / fabs(maxBraking)) * 0.5f; + Real dist = (sqr(delta) / WWMath::Fabs(maxBraking)) * 0.5f; // use a little fudge so that things can stop "on a dime" more easily... const Real FUDGE = 1.05f; @@ -95,14 +95,14 @@ static Real calcSlowDownDist(Real curSpeed, Real desiredSpeed, Real maxBraking) inline Bool isNearlyZero(Real a) { const Real TINY_EPSILON = 0.001f; - return fabs(a) < TINY_EPSILON; + return WWMath::Fabs(a) < TINY_EPSILON; } //----------------------------------------------------------------------------- inline Bool isNearly(Real a, Real val) { const Real TINY_EPSILON = 0.001f; - return fabs(a - val) < TINY_EPSILON; + return WWMath::Fabs(a - val) < TINY_EPSILON; } //----------------------------------------------------------------------------- @@ -141,7 +141,7 @@ static Real tryToRotateVector3D( } } - if (fabs(angleBetween) <= maxAngle) + if (WWMath::Fabs(angleBetween) <= maxAngle) { // close enough actualDir = goalDir; @@ -231,9 +231,9 @@ static void calcDirectionToApplyThrust( Bool foundSolution = false; Real distToGoalSqr = vecToGoal.Length2(); - Real distToGoal = sqrt(distToGoalSqr); + Real distToGoal = WWMath::Sqrt(distToGoalSqr); Real curVelMagSqr = curVel.Length2(); - Real curVelMag = sqrt(curVelMagSqr); + Real curVelMag = WWMath::Sqrt(curVelMagSqr); Real maxAccelSqr = sqr(maxAccel); Real denom = curVelMagSqr - maxAccelSqr; @@ -971,7 +971,7 @@ void Locomotor::locoUpdate_moveTowardsPosition(Object* obj, const Coord3D& goalP Real dx = goalPos.x - obj->getPosition()->x; Real dy = goalPos.y - obj->getPosition()->y; Real dz = goalPos.z - obj->getPosition()->z; - Real dist = sqrt(dx*dx+dy*dy); + Real dist = WWMath::Sqrt(dx*dx+dy*dy); if (dist>onPathDistToGoal) { if (!obj->isKindOf(KINDOF_PROJECTILE) && dist>2*onPathDistToGoal) @@ -1083,7 +1083,7 @@ void Locomotor::locoUpdate_moveTowardsPosition(Object* obj, const Coord3D& goalP // Projectiles never stop braking once they start. jba. obj->setStatus( MAKE_OBJECT_STATUS_MASK( OBJECT_STATUS_BRAKING ) ); // Projectiles cheat in 3 dimensions. - dist = sqrt(dx*dx+dy*dy+dz*dz); + dist = WWMath::Sqrt(dx*dx+dy*dy+dz*dz); Real vel = physics->getVelocityMagnitude(); if (vel < MIN_VEL) vel = MIN_VEL; @@ -1107,7 +1107,7 @@ void Locomotor::locoUpdate_moveTowardsPosition(Object* obj, const Coord3D& goalP // Normalize. if (dist > 0.001f) { - Real vel = fabs(physics->getForwardSpeed2D()); + Real vel = WWMath::Fabs(physics->getForwardSpeed2D()); if (vel < MIN_VEL) vel = MIN_VEL; if (vel > dist) @@ -1152,7 +1152,7 @@ void Locomotor::moveTowardsPositionTreads(Object* obj, PhysicsBehavior *physics, // Modulate speed according to turning. The more we have to turn, the slower we go // const Real QUAETERPI = PI / 4.0f; - Real angleCoeff = (Real)fabs( relAngle ) / QUAETERPI; + Real angleCoeff = (Real)WWMath::Fabs( relAngle ) / QUAETERPI; if (angleCoeff > 1.0f) angleCoeff = 1.0; @@ -1223,7 +1223,7 @@ void Locomotor::moveTowardsPositionTreads(Object* obj, PhysicsBehavior *physics, see how much force we really need to achieve our goal speed... */ Real maxForceNeeded = mass * speedDelta; - if (fabs(accelForce) > fabs(maxForceNeeded)) + if (WWMath::Fabs(accelForce) > WWMath::Fabs(maxForceNeeded)) accelForce = maxForceNeeded; const Coord3D *dir = obj->getUnitDirectionVector2D(); @@ -1258,7 +1258,7 @@ void Locomotor::moveTowardsPositionWheels(Object* obj, PhysicsBehavior *physics, Real angle = obj->getOrientation(); // Real relAngle = ThePartitionManager->getRelativeAngle2D( obj, &goalPos ); // Real desiredAngle = angle + relAngle; - Real desiredAngle = atan2(goalPos.y - obj->getPosition()->y, goalPos.x - obj->getPosition()->x); + Real desiredAngle = WWMath::Atan2(goalPos.y - obj->getPosition()->y, goalPos.x - obj->getPosition()->x); Real relAngle = stdAngleDiff(desiredAngle, angle); Bool moveBackwards = false; @@ -1275,14 +1275,14 @@ void Locomotor::moveTowardsPositionWheels(Object* obj, PhysicsBehavior *physics, #if 1 if (actualSpeed==0.0f) { setFlag(MOVING_BACKWARDS, false); - if (m_template->m_canMoveBackward && fabs(relAngle) > PI/2) { + if (m_template->m_canMoveBackward && WWMath::Fabs(relAngle) > PI/2) { setFlag(MOVING_BACKWARDS, true ); setFlag(DOING_THREE_POINT_TURN, onPathDistToGoal>5*obj->getGeometryInfo().getMajorRadius()); } } if (getFlag(MOVING_BACKWARDS)) { - if (fabs(relAngle) < PI/2) { + if (WWMath::Fabs(relAngle) < PI/2) { moveBackwards = false; setFlag(MOVING_BACKWARDS, false); } else { @@ -1298,7 +1298,7 @@ void Locomotor::moveTowardsPositionWheels(Object* obj, PhysicsBehavior *physics, #endif const Real SMALL_TURN = PI / 20.0f; - if ((Real)fabs( relAngle ) > SMALL_TURN) + if ((Real)WWMath::Fabs( relAngle ) > SMALL_TURN) { if (desiredSpeed>turnSpeed) { @@ -1323,7 +1323,7 @@ void Locomotor::moveTowardsPositionWheels(Object* obj, PhysicsBehavior *physics, const Real FIFTEEN_DEGREES = PI / 12.0f; const Real PROJECT_FRAMES = LOGICFRAMES_PER_SECOND/2; // Project out 1/2 second. - if (fabs( relAngle ) > FIFTEEN_DEGREES) + if (WWMath::Fabs( relAngle ) > FIFTEEN_DEGREES) { // If we're turning more than 10 degrees, check & see if we're moving into "impassable territory" Real distance = PROJECT_FRAMES * (goalSpeed+actualSpeed)/2.0f; @@ -1462,7 +1462,7 @@ void Locomotor::moveTowardsPositionWheels(Object* obj, PhysicsBehavior *physics, see how much force we really need to achieve our goal speed... */ Real maxForceNeeded = mass * speedDelta; - if (fabs(accelForce) > fabs(maxForceNeeded)) + if (WWMath::Fabs(accelForce) > WWMath::Fabs(maxForceNeeded)) accelForce = maxForceNeeded; //DEBUG_LOG(("Braking %d, actualSpeed %f, goalSpeed %f, delta %f, accel %f", getFlag(IS_BRAKING), @@ -1533,7 +1533,7 @@ Bool Locomotor::fixInvalidPosition(Object* obj, PhysicsBehavior *physics) //physics->clearAcceleration(); if (dot<0) { - dot = sqrt(-dot); + dot = WWMath::Sqrt(-dot); correctionNormalized.x *= dot*physics->getMass(); correctionNormalized.y *= dot*physics->getMass(); physics->applyMotiveForce(&correctionNormalized); @@ -1597,7 +1597,7 @@ void Locomotor::moveTowardsPositionLegs(Object* obj, PhysicsBehavior *physics, c Real angle = obj->getOrientation(); // Real relAngle = ThePartitionManager->getRelativeAngle2D( obj, &goalPos ); // Real desiredAngle = angle + relAngle; - Real desiredAngle = atan2(goalPos.y - obj->getPosition()->y, goalPos.x - obj->getPosition()->x); + Real desiredAngle = WWMath::Atan2(goalPos.y - obj->getPosition()->y, goalPos.x - obj->getPosition()->x); if (m_template->m_wanderWidthFactor != 0.0f) { Real angleLimit = PI/8 * m_template->m_wanderWidthFactor; @@ -1623,7 +1623,7 @@ void Locomotor::moveTowardsPositionLegs(Object* obj, PhysicsBehavior *physics, c // Modulate speed according to turning. The more we have to turn, the slower we go // const Real QUARTERPI = PI / 4.0f; - Real angleCoeff = (Real)fabs( relAngle ) / (QUARTERPI); + Real angleCoeff = (Real)WWMath::Fabs( relAngle ) / (QUARTERPI); if (angleCoeff > 1.0f) angleCoeff = 1.0; @@ -1653,7 +1653,7 @@ void Locomotor::moveTowardsPositionLegs(Object* obj, PhysicsBehavior *physics, c see how much force we really need to achieve our goal speed... */ Real maxForceNeeded = mass * speedDelta; - if (fabs(accelForce) > fabs(maxForceNeeded)) + if (WWMath::Fabs(accelForce) > WWMath::Fabs(maxForceNeeded)) accelForce = maxForceNeeded; const Coord3D *dir = obj->getUnitDirectionVector2D(); @@ -1695,7 +1695,7 @@ void Locomotor::moveTowardsPositionClimb(Object* obj, PhysicsBehavior *physics, if (dz*dz > sqr(PATHFIND_CELL_SIZE_F)) { setFlag(CLIMBING, true); } - if (fabs(dz)<1) { + if (WWMath::Fabs(dz)<1) { setFlag(CLIMBING, false); } @@ -1715,7 +1715,7 @@ void Locomotor::moveTowardsPositionClimb(Object* obj, PhysicsBehavior *physics, moveBackwards = true; } - Real groundSlope = fabs(delta.z - pos.z); + Real groundSlope = WWMath::Fabs(delta.z - pos.z); if (groundSlope<1.0f) groundSlope = 1.0f; if (groundSlope>1.0f) { @@ -1730,7 +1730,7 @@ void Locomotor::moveTowardsPositionClimb(Object* obj, PhysicsBehavior *physics, Real angle = obj->getOrientation(); // Real relAngle = ThePartitionManager->getRelativeAngle2D( obj, &goalPos ); // Real desiredAngle = angle + relAngle; - Real desiredAngle = atan2(goalPos.y - obj->getPosition()->y, goalPos.x - obj->getPosition()->x); + Real desiredAngle = WWMath::Atan2(goalPos.y - obj->getPosition()->y, goalPos.x - obj->getPosition()->x); Real relAngle = stdAngleDiff(desiredAngle, angle); if (moveBackwards) { @@ -1744,7 +1744,7 @@ void Locomotor::moveTowardsPositionClimb(Object* obj, PhysicsBehavior *physics, // Modulate speed according to turning. The more we have to turn, the slower we go // const Real QUARTERPI = PI / 4.0f; - Real angleCoeff = (Real)fabs( relAngle ) / (QUARTERPI); + Real angleCoeff = (Real)WWMath::Fabs( relAngle ) / (QUARTERPI); if (angleCoeff > 1.0f) angleCoeff = 1.0; @@ -1786,7 +1786,7 @@ void Locomotor::moveTowardsPositionClimb(Object* obj, PhysicsBehavior *physics, see how much force we really need to achieve our goal speed... */ Real maxForceNeeded = mass * speedDelta; - if (fabs(accelForce) > fabs(maxForceNeeded)) + if (WWMath::Fabs(accelForce) > WWMath::Fabs(maxForceNeeded)) accelForce = maxForceNeeded; const Coord3D *dir = obj->getUnitDirectionVector2D(); @@ -1813,7 +1813,7 @@ void Locomotor::moveTowardsPositionWings(Object* obj, PhysicsBehavior *physics, Real dx = goalPos.x - pos->x; Real dy = goalPos.y - pos->y; Real dz = goalPos.z - pos->z; - if (fabs(dz) > m_circleThresh) + if (WWMath::Fabs(dz) > m_circleThresh) { // aim for the spot on the opposite side of the circle. @@ -1821,7 +1821,7 @@ void Locomotor::moveTowardsPositionWings(Object* obj, PhysicsBehavior *physics, Real angleTowardPos = (isNearlyZero(dx) && isNearlyZero(dy)) ? obj->getOrientation() : - atan2(dy, dx); + WWMath::Atan2(dy, dx); Real aimDir = (PI - PI/8); angleTowardPos += aimDir; @@ -1910,7 +1910,7 @@ void Locomotor::moveTowardsPositionThrust(Object* obj, PhysicsBehavior *physics, // so we tend to "level out" at that height. we don't use this till // below, but go ahead and calc it now... Real MAX_VERTICAL_DAMP_RANGE = m_preferredHeight * 0.5; - delta = fabs(delta); + delta = WWMath::Fabs(delta); if (delta > MAX_VERTICAL_DAMP_RANGE) delta = MAX_VERTICAL_DAMP_RANGE; zDirDamping = 1.0f - (delta / MAX_VERTICAL_DAMP_RANGE); @@ -2027,7 +2027,7 @@ Real Locomotor::calcLiftToUseAtPt(Object* obj, PhysicsBehavior *physics, Real cu // see how far we need to slow to dead stop, given max braking Real desiredAccel; const Real TINY_ACCEL = 0.001f; - if (fabs(maxAccel) > TINY_ACCEL) + if (WWMath::Fabs(maxAccel) > TINY_ACCEL) { Real deltaZ = preferredHeight - curZ; // calc how far it will take for us to go from cur speed to zero speed, at max accel. @@ -2035,14 +2035,14 @@ Real Locomotor::calcLiftToUseAtPt(Object* obj, PhysicsBehavior *physics, Real cu // in theory, the above is the correct calculation, but in practice, // doesn't work in some situations (eg, opening of USA01 map). Why, I dunno. // But for now I have gone back to the old, looks-incorrect-to-me-but-works calc. (srj) - Real brakeDist = (sqr(curVelZ) / fabs(maxAccel)); - if (fabs(brakeDist) > fabs(deltaZ)) + Real brakeDist = (sqr(curVelZ) / WWMath::Fabs(maxAccel)); + if (WWMath::Fabs(brakeDist) > WWMath::Fabs(deltaZ)) { // if the dist-to-accel (or dist-to-brake) is further than the dist-to-go, // use the max accel. desiredAccel = maxAccel; } - else if (fabs(curVelZ) > m_template->m_speedLimitZ) + else if (WWMath::Fabs(curVelZ) > m_template->m_speedLimitZ) { // or, if we're going too fast, limit it here. desiredAccel = m_template->m_speedLimitZ - curVelZ; @@ -2116,8 +2116,8 @@ PhysicsTurningType Locomotor::rotateObjAroundLocoPivot(Object* obj, const Coord3 Real dx =goalPos.x - turnPos.x; Real dy = goalPos.y - turnPos.y; // If we are very close to the goal, we twitch due to rounding error. So just return. jba. - if (fabs(dx)<0.1f && fabs(dy)<0.1f) return TURN_NONE; - Real desiredAngle = atan2(dy, dx); + if (WWMath::Fabs(dx)<0.1f && WWMath::Fabs(dy)<0.1f) return TURN_NONE; + Real desiredAngle = WWMath::Atan2(dy, dx); Real amount = stdAngleDiff(desiredAngle, angle); if (relAngle) *relAngle = amount; if (amount>maxTurnRate) { @@ -2139,7 +2139,7 @@ PhysicsTurningType Locomotor::rotateObjAroundLocoPivot(Object* obj, const Coord3 // so, the thing is, we want to rotate ourselves so that our *center* is rotated // by the given amount, but the rotation must be around turnPos. so do a little // back-calculation. - Real angleDesiredForTurnPos = atan2(desiredPos.y - turnPos.y, desiredPos.x - turnPos.x); + Real angleDesiredForTurnPos = WWMath::Atan2(desiredPos.y - turnPos.y, desiredPos.x - turnPos.x); amount = angleDesiredForTurnPos - angle; #endif /// @todo srj -- there's probably a more efficient & more direct way to do this. find it. @@ -2155,7 +2155,7 @@ PhysicsTurningType Locomotor::rotateObjAroundLocoPivot(Object* obj, const Coord3 } else { - Real desiredAngle = atan2(goalPos.y - obj->getPosition()->y, goalPos.x - obj->getPosition()->x); + Real desiredAngle = WWMath::Atan2(goalPos.y - obj->getPosition()->y, goalPos.x - obj->getPosition()->x); Real amount = stdAngleDiff(desiredAngle, angle); if (relAngle) *relAngle = amount; if (amount>maxTurnRate) { @@ -2333,8 +2333,8 @@ void Locomotor::moveTowardsPositionOther(Object* obj, PhysicsBehavior *physics, //fabs(goalPos.y - pos->y),fabs(goalPos.x - pos->x), //fabs(goalPos.y - pos->y)/goalSpeed,fabs(goalPos.x - pos->x)/goalSpeed)); if (getFlag(ULTRA_ACCURATE) && - fabs(goalPos.y - pos->y) <= goalSpeed * m_template->m_ultraAccurateSlideIntoPlaceFactor && - fabs(goalPos.x - pos->x) <= goalSpeed * m_template->m_ultraAccurateSlideIntoPlaceFactor) + WWMath::Fabs(goalPos.y - pos->y) <= goalSpeed * m_template->m_ultraAccurateSlideIntoPlaceFactor && + WWMath::Fabs(goalPos.x - pos->x) <= goalSpeed * m_template->m_ultraAccurateSlideIntoPlaceFactor) { // don't turn, just slide in the right direction physics->setTurning(TURN_NONE); @@ -2373,7 +2373,7 @@ void Locomotor::moveTowardsPositionOther(Object* obj, PhysicsBehavior *physics, see how much force we really need to achieve our goal speed... */ Real maxForceNeeded = mass * speedDelta; - if (fabs(accelForce) > fabs(maxForceNeeded)) + if (WWMath::Fabs(accelForce) > WWMath::Fabs(maxForceNeeded)) accelForce = maxForceNeeded; Coord3D force; @@ -2488,7 +2488,7 @@ void Locomotor::maintainCurrentPositionWings(Object* obj, PhysicsBehavior *physi Real angleTowardMaintainPos = (isNearlyZero(dx) && isNearlyZero(dy)) ? obj->getOrientation() : - atan2(dy, dx); + WWMath::Atan2(dy, dx); Real aimDir = (PI - PI/8); if (turnRadius < 0) @@ -2522,7 +2522,7 @@ void Locomotor::maintainCurrentPositionHover(Object* obj, PhysicsBehavior *physi // Real minSpeed = max( 1.0E-10f, m_template->m_minSpeed ); Real speedDelta = minSpeed - actualSpeed; - if (fabs(speedDelta) > minSpeed) + if (WWMath::Fabs(speedDelta) > minSpeed) { Real mass = physics->getMass(); Real acceleration = (speedDelta > 0.0f) ? maxAcceleration : -getBraking(); @@ -2533,7 +2533,7 @@ void Locomotor::maintainCurrentPositionHover(Object* obj, PhysicsBehavior *physi see how much force we really need to achieve our goal speed... */ Real maxForceNeeded = mass * speedDelta; - if (fabs(accelForce) > fabs(maxForceNeeded)) + if (WWMath::Fabs(accelForce) > WWMath::Fabs(maxForceNeeded)) accelForce = maxForceNeeded; const Coord3D *dir = obj->getUnitDirectionVector2D(); diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Object.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Object.cpp index 461e3495539..b922bf551a5 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Object.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Object.cpp @@ -1638,13 +1638,13 @@ inline Bool isPosDifferent(const Coord3D* a, const Coord3D* b) // so we must put in some cleverness... const Real THRESH = 0.01f; - if (fabs(a->x - b->x) > THRESH) + if (WWMath::Fabs(a->x - b->x) > THRESH) return true; - if (fabs(a->y - b->y) > THRESH) + if (WWMath::Fabs(a->y - b->y) > THRESH) return true; - if (fabs(a->z - b->z) > THRESH) + if (WWMath::Fabs(a->z - b->z) > THRESH) return true; return false; @@ -1660,7 +1660,7 @@ inline Bool isAngleDifferent(Real a, Real b) const Real THRESH = 0.01f; // in radians, this is approx 1/2 degree. - if (fabs(a - b) > THRESH) + if (WWMath::Fabs(a - b) > THRESH) return true; return false; diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/ObjectCreationList.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/ObjectCreationList.cpp index 78a6d2b531b..0eb83a744f4 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/ObjectCreationList.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/ObjectCreationList.cpp @@ -281,7 +281,7 @@ class DeliverPayloadNugget : public ObjectCreationNugget Real dy = primary->y - secondary->y; //Calc length - Real length = sqrt( dx*dx + dy*dy ); + Real length = WWMath::Sqrt( dx*dx + dy*dy ); //Normalize length dx /= length; @@ -348,7 +348,7 @@ class DeliverPayloadNugget : public ObjectCreationNugget } - Real orient = atan2( moveToPos.y - startPos.y, moveToPos.x - startPos.x); + Real orient = WWMath::Atan2( moveToPos.y - startPos.y, moveToPos.x - startPos.x); if( m_data.m_distToTarget > 0 ) { const Real SLOP = 1.5f; @@ -1070,7 +1070,7 @@ class GenericObjectCreationNugget : public ObjectCreationNugget objUp->applyForce(&force); if (m_orientInForceDirection) - orientation = atan2(force.y, force.x); + orientation = WWMath::Atan2(force.y, force.x); } } @@ -1158,7 +1158,7 @@ class GenericObjectCreationNugget : public ObjectCreationNugget objUp->applyForce(&force); if (m_orientInForceDirection) { - orientation = atan2(force.y, force.x); + orientation = WWMath::Atan2(force.y, force.x); } DUMPREAL(orientation); objUp->setAngles(orientation, 0, 0); diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cpp index f9b464c58bd..7108f28c08d 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cpp @@ -411,13 +411,13 @@ static void testRotatedPointsAgainstRect( Real pty = pts->y - a->position.y; // inverse-rotate it to the right coord system - Real ptx_new = (Real)fabs(ptx*c - pty*s); - Real pty_new = (Real)fabs(ptx*s + pty*c); + Real ptx_new = (Real)WWMath::Fabs(ptx*c - pty*s); + Real pty_new = (Real)WWMath::Fabs(ptx*s + pty*c); #ifdef INTENSE_DEBUG Real mag_a = sqr(ptx)+sqr(pty); Real mag_b = sqr(ptx_new)+sqr(pty_new); - DEBUG_ASSERTCRASH(fabs(mag_a - mag_b) <= 1.0, ("hmm, unlikely")); + DEBUG_ASSERTCRASH(WWMath::Fabs(mag_a - mag_b) <= 1.0, ("hmm, unlikely")); #endif if (ptx_new <= major && pty_new <= minor) @@ -617,7 +617,7 @@ inline Bool z_collideTest_Sphere_Nonsphere(CollideTestProc xyproc, const Collide // find the radius of the slice of the sphere that is at b_bot CollideInfo amod = *a; amod.position.z = b_bot; - amod.geom.setMajorRadius((Real)sqrtf(sqr(a->geom.getMajorRadius()) - sqr(b_bot - a->position.z))); + amod.geom.setMajorRadius((Real)WWMath::Sqrtf(sqr(a->geom.getMajorRadius()) - sqr(b_bot - a->position.z))); if (xyproc(&amod, b, cinfo)) { // if you want to have 'end' collisions, you should add something like: @@ -635,7 +635,7 @@ inline Bool z_collideTest_Sphere_Nonsphere(CollideTestProc xyproc, const Collide { CollideInfo amod = *a; amod.position.z = b_top; - amod.geom.setMajorRadius((Real)sqrtf(sqr(a->geom.getMajorRadius()) - sqr(a->position.z - b_top))); + amod.geom.setMajorRadius((Real)WWMath::Sqrtf(sqr(a->geom.getMajorRadius()) - sqr(a->position.z - b_top))); if (xyproc(&amod, b, cinfo)) { // if you want to have 'end' collisions, you should add something like: @@ -823,7 +823,7 @@ static Bool distCalcProc_BoundaryAndBoundary_2D( if (totalRad > 0.0f) { - Real actualDist = sqrtf(actualDistSqr); + Real actualDist = WWMath::Sqrtf(actualDistSqr); Real shrunkenDist = actualDist - totalRad; if (shrunkenDist <= 0.0f) { @@ -911,7 +911,7 @@ static Bool distCalcProc_BoundaryAndBoundary_3D( Real totalRad = (geomA?geomA->getBoundingSphereRadius():0) + (geomB?geomB->getBoundingSphereRadius():0); if (totalRad > 0.0f) { - Real actualDist = sqrtf(actualDistSqr); + Real actualDist = WWMath::Sqrtf(actualDistSqr); Real shrunkenDist = actualDist - totalRad; if (shrunkenDist <= 0.0f) { @@ -2219,7 +2219,7 @@ Int PartitionData::calcMaxCoiForShape(GeometryType geom, Real majorRadius, Real } case GEOMETRY_BOX: { - Real diagonal = (Real)(sqrtf(majorRadius*majorRadius + minorRadius*minorRadius)); + Real diagonal = (Real)(WWMath::Sqrtf(majorRadius*majorRadius + minorRadius*minorRadius)); Int cells = ThePartitionManager->worldToCellDist(diagonal*2) + 1; result = cells * cells; break; @@ -2636,7 +2636,7 @@ static void calcHeights(const Region3D& world, Real cellSize, Int x, Int y, Real Real xbase = world.lo.x + (x * cellSize); Real ybase = world.lo.y + (y * cellSize); const Real ROUGH_STEP_SIZE = 2; // roughly every 2 ft, please - Real numSteps = ceilf(cellSize / ROUGH_STEP_SIZE); + Real numSteps = WWMath::Ceilf(cellSize / ROUGH_STEP_SIZE); Real step = cellSize / numSteps; loZ = HUGE_DIST; // huge positive hiZ = -HUGE_DIST; // huge negative @@ -3210,7 +3210,7 @@ Int PartitionManager::calcMinRadius(const ICoord2D& cur) } // double, not real - double dist = sqrtf(minDistSqr); + double dist = WWMath::Sqrtf(minDistSqr); Int minRadius = REAL_TO_INT_CEIL( dist / m_cellSize ); return minRadius; @@ -3228,7 +3228,7 @@ void PartitionManager::calcRadiusVec() // double, not real double dx = (double)cx * (double)cellSize; double dy = (double)cy * (double)cellSize; - double maxPossibleDist = sqrt(dx*dx + dy*dy); + double maxPossibleDist = WWMath::Sqrt(dx*dx + dy*dy); m_maxGcoRadius = REAL_TO_INT_CEIL(maxPossibleDist / cellSize); @@ -3498,7 +3498,7 @@ Object *PartitionManager::getClosestObjects( } if (closestDistArg) { - *closestDistArg = (Real)sqrtf(closestDistSqr); + *closestDistArg = (Real)WWMath::Sqrtf(closestDistSqr); } #ifdef RTS_DEBUG @@ -3625,7 +3625,7 @@ Real PartitionManager::getRelativeAngle2D( const Object *obj, const Coord3D *pos v.y = pos->y - objPos.y; v.z = 0.0f; - Real dist = (Real)sqrtf(sqr(v.x) + sqr(v.y)); + Real dist = (Real)WWMath::Sqrtf(sqr(v.x) + sqr(v.y)); // normalize if (dist == 0.0f) @@ -3803,7 +3803,7 @@ Bool PartitionManager::tryPosition( const Coord3D *center, pos.z = TheTerrainLogic->getGroundHeight( pos.x, pos.y ); } - if (fabs(pos.z - center->z) > options->maxZDelta) + if (WWMath::Fabs(pos.z - center->z) > options->maxZDelta) return FALSE; // @@ -4556,7 +4556,7 @@ Int PartitionManager::iterateCellsBreadthFirst(const Coord3D *pos, CellBreadthFi //----------------------------------------------------------------------------- static Real calcDist2D(Real x1, Real y1, Real x2, Real y2) { - return sqrtf(sqr(x1-x2) + sqr(y1-y2)); + return WWMath::Sqrtf(sqr(x1-x2) + sqr(y1-y2)); } //----------------------------------------------------------------------------- @@ -5715,7 +5715,7 @@ void hLineAddThreat(Int x1, Int x2, Int y, void *threatValueParms) if (x < 0 || x >= ThePartitionManager->m_cellCountX) continue; - distance = sqrt( pow(x - parms->xCenter, 2) + pow(y - parms->yCenter, 2) ); + distance = WWMath::Sqrt( WWMath::Pow(x - parms->xCenter, 2) + WWMath::Pow(y - parms->yCenter, 2) ); mulVal = 1 - distance / parms->radius; if (mulVal < 0.0f) mulVal = 0.0f; @@ -5743,7 +5743,7 @@ void hLineRemoveThreat(Int x1, Int x2, Int y, void *threatValueParms) if (x < 0 || x >= ThePartitionManager->m_cellCountX) continue; - distance = sqrt( pow(x - parms->xCenter, 2) + pow(y - parms->yCenter, 2) ); + distance = WWMath::Sqrt( WWMath::Pow(x - parms->xCenter, 2) + WWMath::Pow(y - parms->yCenter, 2) ); mulVal = 1 - distance / parms->radius; if (mulVal < 0.0f) mulVal = 0.0f; @@ -5771,7 +5771,7 @@ void hLineAddValue(Int x1, Int x2, Int y, void *threatValueParms) if (x < 0 || x >= ThePartitionManager->m_cellCountX) continue; - distance = sqrt( pow(x - parms->xCenter, 2) + pow(y - parms->yCenter, 2) ); + distance = WWMath::Sqrt( WWMath::Pow(x - parms->xCenter, 2) + WWMath::Pow(y - parms->yCenter, 2) ); mulVal = 1 - distance / parms->radius; if (mulVal < 0.0f) mulVal = 0.0f; @@ -5799,7 +5799,7 @@ void hLineRemoveValue(Int x1, Int x2, Int y, void *threatValueParms) if (x < 0 || x >= ThePartitionManager->m_cellCountX) continue; - distance = sqrt( pow(x - parms->xCenter, 2) + pow(y - parms->yCenter, 2) ); + distance = WWMath::Sqrt( WWMath::Pow(x - parms->xCenter, 2) + WWMath::Pow(y - parms->yCenter, 2) ); mulVal = 1 - distance / parms->radius; if (mulVal < 0.0f) mulVal = 0.0f; diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp index c8fcd2f3221..b04ddb64bc4 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp @@ -1282,8 +1282,8 @@ Bool AIUpdateInterface::blockedBy(Object *other) // If we are near our final goal, don't get stuck. if (goalCell.x>0 && goalCell.y>0) { - Real dx = fabs(goalPos.x-pos.x); - Real dy = fabs(goalPos.y-pos.y); + Real dx = WWMath::Fabs(goalPos.x-pos.x); + Real dy = WWMath::Fabs(goalPos.y-pos.y); if (dxgetRelativeAngle2D( getObject(), &info.posOnPath ); } - if (fabs(deltaAngle)>PI/30) + if (WWMath::Fabs(deltaAngle)>PI/30) { return TRUE; } @@ -2230,7 +2230,7 @@ UpdateSleepTime AIUpdateInterface::doLocomotor() } else { - Real dist = sqrtf(dSqr); + Real dist = WWMath::Sqrtf(dSqr); if (dist<1) dist = 1; pos.x += 2*PATHFIND_CELL_SIZE_F*dx/(dist*LOGICFRAMES_PER_SECOND); pos.y += 2*PATHFIND_CELL_SIZE_F*dy/(dist*LOGICFRAMES_PER_SECOND); @@ -2424,7 +2424,7 @@ Real AIUpdateInterface::getLocomotorDistanceToGoal() dest = m_path->getLastNode()->getPosition(); } Real distance = ThePartitionManager->getDistanceSquared( me, dest, FROM_CENTER_3D ); - return sqrt( distance );// Other paths return dots of normalized vectors, so one sqrt ain't so bad + return WWMath::Sqrt( distance );// Other paths return dots of normalized vectors, so one sqrt ain't so bad } else { @@ -2456,7 +2456,7 @@ Real AIUpdateInterface::getLocomotorDistanceToGoal() { if (sqr(dist) > distSqr) { - return sqrt(distSqr); + return WWMath::Sqrt(distSqr); } else { @@ -2465,7 +2465,7 @@ Real AIUpdateInterface::getLocomotorDistanceToGoal() } if (distgetExtent( &terrainExtent ); const Real FUDGE = 1.2f; - Real HUGE_DIST = FUDGE * sqrt(sqr(terrainExtent.hi.x - terrainExtent.lo.x) + sqr(terrainExtent.hi.y - terrainExtent.lo.y)); + Real HUGE_DIST = FUDGE * WWMath::Sqrt(sqr(terrainExtent.hi.x - terrainExtent.lo.x) + sqr(terrainExtent.hi.y - terrainExtent.lo.y)); exitCoord.x += dir->x * HUGE_DIST; exitCoord.y += dir->y * HUGE_DIST; @@ -569,7 +569,7 @@ class ChinookCombatDropState : public State { if (it->ropeLen < it->ropeLenMax) { - it->ropeSpeed += fabs(TheGlobalData->m_gravity); + it->ropeSpeed += WWMath::Fabs(TheGlobalData->m_gravity); if (it->ropeSpeed > d->m_ropeDropSpeed) it->ropeSpeed = d->m_ropeDropSpeed; it->ropeLen += it->ropeSpeed; @@ -761,7 +761,7 @@ class ChinookMoveToBldgState : public AIMoveToState StateReturnType status = AIMoveToState::update(); const Real THRESH = 3.0f; - if (status != STATE_CONTINUE && fabs(obj->getPosition()->z - m_destZ) > THRESH) + if (status != STATE_CONTINUE && WWMath::Fabs(obj->getPosition()->z - m_destZ) > THRESH) status = STATE_CONTINUE; return status; @@ -840,7 +840,7 @@ ChinookAIUpdateModuleData::ChinookAIUpdateModuleData() m_minDropHeight = 30.0f; m_ropeFinalHeight = 0.0f; m_ropeDropSpeed = 1e10f; // um, fast. - m_rappelSpeed = fabs(TheGlobalData->m_gravity) * LOGICFRAMES_PER_SECOND * 0.5f; + m_rappelSpeed = WWMath::Fabs(TheGlobalData->m_gravity) * LOGICFRAMES_PER_SECOND * 0.5f; m_ropeWobbleLen = 10.0f; m_ropeWobbleAmp = 1.0f; m_ropeWobbleRate = 0.1f; diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/DeliverPayloadAIUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/DeliverPayloadAIUpdate.cpp index e053a0d4b55..1d8fce44416 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/DeliverPayloadAIUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/DeliverPayloadAIUpdate.cpp @@ -201,8 +201,8 @@ UpdateSleepTime DeliverPayloadAIUpdate::update() { //Calc strafe ratio Real startDiveDistance = getData()->m_diveStartDistance; - Real endDiveDistance = sqrt( endDiveDistanceSquared ); - Real currentDistance = sqrt( currentDistanceSquared ); + Real endDiveDistance = WWMath::Sqrt( endDiveDistanceSquared ); + Real currentDistance = WWMath::Sqrt( currentDistanceSquared ); Real diveRatio = (startDiveDistance - currentDistance) / (startDiveDistance - endDiveDistance); @@ -1081,7 +1081,7 @@ StateReturnType RecoverFromOffMapState::update() // Success if we should try aga enterCoord.z = owner->getPosition()->z; owner->setPosition(&enterCoord); - Real enterAngle = atan2(ai->getMoveToPos()->y - enterCoord.y, ai->getMoveToPos()->x - enterCoord.x); + Real enterAngle = WWMath::Atan2(ai->getMoveToPos()->y - enterCoord.y, ai->getMoveToPos()->x - enterCoord.x); owner->setOrientation(enterAngle); PhysicsBehavior* physics = owner->getPhysics(); @@ -1121,7 +1121,7 @@ StateReturnType HeadOffMapState::onEnter() // Give move order out of town Region3D terrainExtent; TheTerrainLogic->getExtent( &terrainExtent ); const Real FUDGE = 1.2f; - Real HUGE_DIST = FUDGE * sqrt(sqr(terrainExtent.hi.x - terrainExtent.lo.x) + sqr(terrainExtent.hi.y - terrainExtent.lo.y)); + Real HUGE_DIST = FUDGE * WWMath::Sqrt(sqr(terrainExtent.hi.x - terrainExtent.lo.x) + sqr(terrainExtent.hi.y - terrainExtent.lo.y)); exitCoord.x += dir->x * HUGE_DIST; exitCoord.y += dir->y * HUGE_DIST; diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/JetAIUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/JetAIUpdate.cpp index 483cf6b45f7..d64461da9e1 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/JetAIUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/JetAIUpdate.cpp @@ -457,8 +457,8 @@ class JetOrHeliTaxiState : public AIMoveOutOfTheWayState Coord3D intermedPt; Bool intermed = false; - Real orient = atan2(ppinfo.runwayPrep.y - ppinfo.parkingSpace.y, ppinfo.runwayPrep.x - ppinfo.parkingSpace.x); - if (fabs(stdAngleDiff(orient, ppinfo.parkingOrientation)) > PI/128) + Real orient = WWMath::Atan2(ppinfo.runwayPrep.y - ppinfo.parkingSpace.y, ppinfo.runwayPrep.x - ppinfo.parkingSpace.x); + if (WWMath::Fabs(stdAngleDiff(orient, ppinfo.parkingOrientation)) > PI/128) { intermedPt.z = (ppinfo.parkingSpace.z + ppinfo.runwayPrep.z) * 0.5f; intermed = intersectInfiniteLine2D( @@ -884,7 +884,7 @@ class HeliTakeoffOrLandingState : public State } else { - Real dist = sqrtf(dSqr); + Real dist = WWMath::Sqrtf(dSqr); if (dist<1) dist = 1; pos.x += PATHFIND_CELL_SIZE_F*dx/(dist*LOGICFRAMES_PER_SECOND); pos.y += PATHFIND_CELL_SIZE_F*dy/(dist*LOGICFRAMES_PER_SECOND); @@ -1012,7 +1012,7 @@ class JetOrHeliParkOrientState : public State return STATE_FAILURE; const Real THRESH = 0.001f; - if (fabs(stdAngleDiff(jet->getOrientation(), ppinfo.parkingOrientation)) <= THRESH) + if (WWMath::Fabs(stdAngleDiff(jet->getOrientation(), ppinfo.parkingOrientation)) <= THRESH) return STATE_SUCCESS; // magically position it correctly. @@ -2070,7 +2070,7 @@ void JetAIUpdate::positionLockon() Real dx = getObject()->getPosition()->x - pos.x; Real dy = getObject()->getPosition()->y - pos.y; if (dx || dy) - m_lockonDrawable->setOrientation(atan2(dy, dx)); + m_lockonDrawable->setOrientation(WWMath::Atan2(dy, dx)); // the Gaussian sum, to avoid keeping a running total: // diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/MissileAIUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/MissileAIUpdate.cpp index 688a0918a5a..5d6f623b2c7 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/MissileAIUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/MissileAIUpdate.cpp @@ -223,7 +223,7 @@ void MissileAIUpdate::projectileFireAtObjectOrPosition( const Object *victim, co Real deltaZ = victimPos->z - obj->getPosition()->z; Real dx = victimPos->x - obj->getPosition()->x; Real dy = victimPos->y - obj->getPosition()->y; - Real xyDist = sqrt(sqr(dx)+sqr(dy)); + Real xyDist = WWMath::Sqrt(sqr(dx)+sqr(dy)); if (xyDist<1) xyDist = 1; Real zFactor = 0; if (deltaZ>0) { @@ -619,7 +619,7 @@ UpdateSleepTime MissileAIUpdate::update() Coord3D newPos = *getObject()->getPosition(); if (m_noTurnDistLeft > 0.0f && m_state >= IGNITION) { - Real distThisTurn = sqrtf(sqr(newPos.x-m_prevPos.x) + sqr(newPos.y-m_prevPos.y) + sqr(newPos.z-m_prevPos.z)); + Real distThisTurn = WWMath::Sqrtf(sqr(newPos.x-m_prevPos.x) + sqr(newPos.y-m_prevPos.y) + sqr(newPos.z-m_prevPos.z)); m_noTurnDistLeft -= distThisTurn; m_prevPos = newPos; } diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/POWTruckAIUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/POWTruckAIUpdate.cpp index dc83acdf5db..52333f5c8b5 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/POWTruckAIUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/POWTruckAIUpdate.cpp @@ -480,7 +480,7 @@ void POWTruckAIUpdate::updateCollectingTarget() { // are we close enough to tell them to start moving to us - Real distSq = pow( us->getGeometryInfo().getBoundingSphereRadius() * 2.0f, 2 ); + Real distSq = WWMath::Pow( us->getGeometryInfo().getBoundingSphereRadius() * 2.0f, 2 ); if( ThePartitionManager->getDistanceSquared( us, target, FROM_CENTER_2D ) <= distSq ) { diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/RailroadGuideAIUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/RailroadGuideAIUpdate.cpp index 24d9d6498ed..b74afb4dd9e 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/RailroadGuideAIUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/RailroadGuideAIUpdate.cpp @@ -315,7 +315,7 @@ void RailroadBehavior::onCollide( Object *other, const Coord3D *loc, const Coord m_whistleSound.setPlayingHandle(TheAudio->addAudioEvent( &m_whistleSound )); - Real dist = (Real)sqrtf( dlt.x*dlt.x + dlt.y*dlt.y + dlt.z*dlt.z); + Real dist = (Real)WWMath::Sqrtf( dlt.x*dlt.x + dlt.y*dlt.y + dlt.z*dlt.z); Real usRadius = obj->getGeometryInfo().getMajorRadius(); Real themRadius = other->getGeometryInfo().getMajorRadius(); Real overlap = ((usRadius + themRadius) - dist) + 1;// the plus 1 makes them go just outside of me. @@ -472,8 +472,8 @@ void RailroadBehavior::playImpactSound(Object *victim, const Coord3D *impactPosi impact.setPosition(impactPosition); if ( theirPhys ) { - vel += fabs(theirPhys->getVelocity()->length()); - mass += fabs(theirPhys->getMass()); + vel += WWMath::Fabs(theirPhys->getVelocity()->length()); + mass += WWMath::Fabs(theirPhys->getMass()); vel /= 2; mass /= 2;//average of him and me @@ -675,7 +675,7 @@ UpdateSleepTime RailroadBehavior::update() if ( m_conductorState == APPLY_BRAKES ) { conductorPullInfo.speed *= modData->m_braking; - if (fabs(conductorPullInfo.speed) < 0.01f) + if (WWMath::Fabs(conductorPullInfo.speed) < 0.01f) { conductorPullInfo.speed = 0; ///////////////////////////////////////( &m_hissySteamSound ); @@ -1193,7 +1193,7 @@ void alignToTerrain( Real angle, const Coord3D& pos, const Coord3D& normal, Matr x.normalize(); } - DEBUG_ASSERTCRASH(fabs(x.x*z.x + x.y*z.y + x.z*z.z)<0.0001,("dot is not zero")); + DEBUG_ASSERTCRASH(WWMath::Fabs(x.x*z.x + x.y*z.y + x.z*z.z)<0.0001,("dot is not zero")); // now computing the y vector is trivial. y.crossProduct( z, x, y ); @@ -1259,7 +1259,7 @@ void RailroadBehavior::updatePositionTrackDistance( PullInfo *pullerInfo, PullIn trackPosDelta.z = 0; Real dx = pullerInfo->towHitchPosition.x - turnPos.x; Real dy = pullerInfo->towHitchPosition.y - turnPos.y; - Real desiredAngle = atan2(dy, dx); + Real desiredAngle = WWMath::Atan2(dy, dx); Real relAngle = stdAngleDiff(desiredAngle, obj->getTransformMatrix()->Get_Z_Rotation()); diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/CleanupHazardUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/CleanupHazardUpdate.cpp index 8a23910d7d3..57cc8f8211a 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/CleanupHazardUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/CleanupHazardUpdate.cpp @@ -172,7 +172,7 @@ UpdateSleepTime CleanupHazardUpdate::update() AIUpdateInterface *ai = obj->getAI(); if( ai && (ai->isIdle() || ai->isBusy()) ) { - Real fDist = sqrt( ThePartitionManager->getDistanceSquared( obj, &m_pos, FROM_CENTER_2D ) ); + Real fDist = WWMath::Sqrt( ThePartitionManager->getDistanceSquared( obj, &m_pos, FROM_CENTER_2D ) ); if( fDist < 25.0f ) { //Abort clean area because there's nothing left to clean! @@ -204,7 +204,7 @@ void CleanupHazardUpdate::fireWhenReady() bonus.clear(); Real fireRange = m_weaponTemplate->getAttackRange( bonus ); Object *me = getObject(); - Real fDist = sqrt( ThePartitionManager->getDistanceSquared( me, target, FROM_CENTER_2D ) ); + Real fDist = WWMath::Sqrt( ThePartitionManager->getDistanceSquared( me, target, FROM_CENTER_2D ) ); if( fDist < fireRange ) { //We are currently in range! diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/CommandButtonHuntUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/CommandButtonHuntUpdate.cpp index e7df932630c..936da747afe 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/CommandButtonHuntUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/CommandButtonHuntUpdate.cpp @@ -290,7 +290,7 @@ Object* CommandButtonHuntUpdate::scanClosestTarget() } } Real distSqr = ThePartitionManager->getDistanceSquared(me, other, FROM_BOUNDINGSPHERE_2D); - Real dist = sqrt(distSqr); + Real dist = WWMath::Sqrt(distSqr); Int curPriority = data->m_scanRange - dist; if (info) curPriority = info->getPriority(other->getTemplate()); if (curPriority == 0) diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/DockUpdate/SupplyWarehouseDockUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/DockUpdate/SupplyWarehouseDockUpdate.cpp index 62ac01c158a..faac75b83d4 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/DockUpdate/SupplyWarehouseDockUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/DockUpdate/SupplyWarehouseDockUpdate.cpp @@ -95,7 +95,7 @@ Bool SupplyWarehouseDockUpdate::action( Object* docker, Object *drone ) Real closeEnoughSqr = sqr(docker->getGeometryInfo().getBoundingCircleRadius()*2); Real curDistSqr = ThePartitionManager->getDistanceSquared(docker, getObject(), FROM_BOUNDINGSPHERE_2D); if (curDistSqr > closeEnoughSqr) { - DEBUG_LOG(("Failing dock, dist %f, not close enough(%f).", sqrt(curDistSqr), sqrt(closeEnoughSqr))); + DEBUG_LOG(("Failing dock, dist %f, not close enough(%f).", WWMath::Sqrt(curDistSqr), WWMath::Sqrt(closeEnoughSqr))); // Make it twitch a little. Coord3D newPos = *docker->getPosition(); Real range = 0.4*PATHFIND_CELL_SIZE_F; @@ -170,7 +170,7 @@ void SupplyWarehouseDockUpdate::setDockCrippled( Bool setting ) void SupplyWarehouseDockUpdate::setCashValue( Int cashValue ) { // A script can tell us our set value, and we need to figure out the boxes needed to provide that. - m_boxesStored = ceil(cashValue / (float)TheGlobalData->m_baseValuePerSupplyBox); + m_boxesStored = WWMath::Ceil(cashValue / (float)TheGlobalData->m_baseValuePerSupplyBox); Drawable *draw = getObject()->getDrawable(); if( draw ) { diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/DynamicShroudClearingRangeUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/DynamicShroudClearingRangeUpdate.cpp index 5ad5b511a23..5d919cfbb31 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/DynamicShroudClearingRangeUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/DynamicShroudClearingRangeUpdate.cpp @@ -166,8 +166,8 @@ void DynamicShroudClearingRangeUpdate::animateGridDecals() for (int d = 0; d < GRID_FX_DECAL_COUNT; ++d) { - pos.x = ctr->x + (sinf(angle) * radius); - pos.y = ctr->y + (cosf(angle) * radius); + pos.x = ctr->x + (WWMath::Sinf(angle) * radius); + pos.y = ctr->y + (WWMath::Cosf(angle) * radius); pos.x -= ((Int)pos.x)%23; pos.y -= ((Int)pos.y)%23; diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/FloatUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/FloatUpdate.cpp index 29f256c4801..40d350662bd 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/FloatUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/FloatUpdate.cpp @@ -119,8 +119,8 @@ UpdateSleepTime FloatUpdate::update() { Real angle = INT_TO_REAL(TheGameLogic->getFrame()); - Real yaw = sin(angle * 0.0291f) * 0.05f; - Real pitch = sin(angle * 0.0515f) * 0.05f; + Real yaw = WWMath::Sin(angle * 0.0291f) * 0.05f; + Real pitch = WWMath::Sin(angle * 0.0515f) * 0.05f; Matrix3D mx = *draw->getInstanceMatrix(); diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/NeutronMissileUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/NeutronMissileUpdate.cpp index 9bf55521dde..172b323e01b 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/NeutronMissileUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/NeutronMissileUpdate.cpp @@ -297,7 +297,7 @@ static Real calcTransform(const Object* obj, const Coord3D *pos, Real maxTurnRat Real angle = (Real)ACos( c ); Vector3 newDir; - if (fabs(angle) < maxTurnRate) + if (WWMath::Fabs(angle) < maxTurnRate) { // close enough -- point exactly in the right dir newDir = otherDir; @@ -355,7 +355,7 @@ void NeutronMissileUpdate::doAttack() // // Modulate speed according to turning. The more we have to turn, the slower we go // - Real angleCoeff = (Real)fabs( relAngle ) / (PI / 2.0f); + Real angleCoeff = (Real)WWMath::Fabs( relAngle ) / (PI / 2.0f); if (angleCoeff > 1.0f) angleCoeff = 1.0; } @@ -512,7 +512,7 @@ UpdateSleepTime NeutronMissileUpdate::update() if (m_noTurnDistLeft > 0.0f && oldPosValid) { Coord3D newPos = *getObject()->getPosition(); - Real distThisTurn = sqrt(sqr(newPos.x-oldPos.x) + sqr(newPos.y-oldPos.y) + sqr(newPos.z-oldPos.z)); + Real distThisTurn = WWMath::Sqrt(sqr(newPos.x-oldPos.x) + sqr(newPos.y-oldPos.y) + sqr(newPos.z-oldPos.z)); //DEBUG_LOG(("noTurnDist goes from %f to %f",m_noTurnDistLeft,m_noTurnDistLeft-distThisTurn)); m_noTurnDistLeft -= distThisTurn; } diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/ParticleUplinkCannonUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/ParticleUplinkCannonUpdate.cpp index 44c344ff071..1ac10d290e3 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/ParticleUplinkCannonUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/ParticleUplinkCannonUpdate.cpp @@ -479,7 +479,7 @@ UpdateSleepTime ParticleUplinkCannonUpdate::update() Real cxDistance = (factor * data->m_swathOfDeathDistance ) - (data->m_swathOfDeathDistance * 0.5f); //cx is cartesian x //Now calculate the amplitude value. - Real height = sin( radians ); + Real height = WWMath::Sin( radians ); Real cxHeight = height * data->m_swathOfDeathAmplitude; Coord3D buildingToInitialTargetVector; diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp index b20d43f7259..954159bca8f 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp @@ -95,7 +95,7 @@ static Real heightToSpeed(Real height) { // don't bother trying to remember how far we've fallen; instead, // back-calc it from our speed & gravity... v = sqrt(2*g*h) - return sqrt(fabs(2.0f * TheGlobalData->m_gravity * height)); + return WWMath::Sqrt(WWMath::Fabs(2.0f * TheGlobalData->m_gravity * height)); } //------------------------------------------------------------------------------------------------- @@ -440,7 +440,7 @@ Bool PhysicsBehavior::handleBounce(Real oldZ, Real newZ, Real groundZ, Coord3D* Real vz = getVelocity()->z; if (oldZ > groundZ && vz < 0.0f) { - desiredAccelZ = fabs(vz) * stiffness; + desiredAccelZ = WWMath::Fabs(vz) * stiffness; } bounceForce->x = 0.0f; @@ -472,7 +472,7 @@ Bool PhysicsBehavior::handleBounce(Real oldZ, Real newZ, Real groundZ, Coord3D* inline Bool isVerySmall3D(const Coord3D& v) { const Real THRESH = 0.01f; - return (fabs(v.x) < THRESH && fabs(v.y) < THRESH && fabs(v.z) < THRESH); + return (WWMath::Fabs(v.x) < THRESH && WWMath::Fabs(v.y) < THRESH && WWMath::Fabs(v.z) < THRESH); } //------------------------------------------------------------------------------------------------- @@ -571,9 +571,9 @@ UpdateSleepTime PhysicsBehavior::update() // when vel gets tiny, just clamp to zero const Real THRESH = 0.001f; - if (fabsf(m_vel.x) < THRESH) m_vel.x = 0.0f; - if (fabsf(m_vel.y) < THRESH) m_vel.y = 0.0f; - if (fabsf(m_vel.z) < THRESH) m_vel.z = 0.0f; + if (WWMath::Fabsf(m_vel.x) < THRESH) m_vel.x = 0.0f; + if (WWMath::Fabsf(m_vel.y) < THRESH) m_vel.y = 0.0f; + if (WWMath::Fabsf(m_vel.z) < THRESH) m_vel.z = 0.0f; m_velMag = INVALID_VEL_MAG; @@ -638,8 +638,8 @@ UpdateSleepTime PhysicsBehavior::update() if (offset != 0.0f) { Vector3 xvec = mtx.Get_X_Vector(); - Real xy = sqrtf(sqr(xvec.X) + sqr(xvec.Y)); - Real pitchAngle = atan2(xvec.Z, xy); + Real xy = WWMath::Sqrtf(sqr(xvec.X) + sqr(xvec.Y)); + Real pitchAngle = WWMath::Atan2(xvec.Z, xy); Real remainingAngle = (offset > 0) ? ((PI/2) - pitchAngle) : (-(PI/2) + pitchAngle); Real s = Sin(remainingAngle); pitchRateToUse *= s; @@ -739,8 +739,8 @@ UpdateSleepTime PhysicsBehavior::update() // going down hills don't injure themselves (unless the hill is really steep) const Real MIN_ANGLE_TAN = 3.0f; // roughly 71 degrees const Real TINY_DELTA = 0.01f; - if ((fabs(m_vel.x) <= TINY_DELTA || fabs(activeVelZ / m_vel.x) >= MIN_ANGLE_TAN) && - (fabs(m_vel.y) <= TINY_DELTA || fabs(activeVelZ / m_vel.y) >= MIN_ANGLE_TAN)) + if ((WWMath::Fabs(m_vel.x) <= TINY_DELTA || WWMath::Fabs(activeVelZ / m_vel.x) >= MIN_ANGLE_TAN) && + (WWMath::Fabs(m_vel.y) <= TINY_DELTA || WWMath::Fabs(activeVelZ / m_vel.y) >= MIN_ANGLE_TAN)) { Real damageAmt = netSpeed * getMass() * d->m_fallHeightDamageFactor; @@ -819,7 +819,7 @@ Real PhysicsBehavior::getVelocityMagnitude() const { if (m_velMag == INVALID_VEL_MAG) { - m_velMag = (Real)sqrtf( sqr(m_vel.x) + sqr(m_vel.y) + sqr(m_vel.z) ); + m_velMag = (Real)WWMath::Sqrtf( sqr(m_vel.x) + sqr(m_vel.y) + sqr(m_vel.z) ); } return m_velMag; } @@ -841,7 +841,7 @@ Real PhysicsBehavior::getForwardSpeed2D() const Real speedSquared = vx*vx + vy*vy; // DEBUG_ASSERTCRASH( speedSquared != 0, ("zero speedSquared will overflow sqrtf()!") );// lorenzen... sanity check - Real speed = (Real)sqrtf( speedSquared ); + Real speed = (Real)WWMath::Sqrtf( speedSquared ); if (dot >= 0.0f) return speed; @@ -864,7 +864,7 @@ Real PhysicsBehavior::getForwardSpeed3D() const Real dot = vx + vy + vz; - Real speed = (Real)sqrtf( vx*vx + vy*vy + vz*vz ); + Real speed = (Real)WWMath::Sqrtf( vx*vx + vy*vy + vz*vz ); if (dot >= 0.0f) return speed; @@ -887,7 +887,7 @@ Bool PhysicsBehavior::wasPreviouslyOverlapped(Object *obj) const //------------------------------------------------------------------------------------------------- void PhysicsBehavior::scrubVelocityZ( Real desiredVelocity ) { - if (fabs(desiredVelocity) < 0.001f) + if (WWMath::Fabs(desiredVelocity) < 0.001f) { m_vel.z = 0; } @@ -911,7 +911,7 @@ void PhysicsBehavior::scrubVelocity2D( Real desiredVelocity ) } else { - Real curVelocity = sqrtf(m_vel.x*m_vel.x + m_vel.y*m_vel.y); + Real curVelocity = WWMath::Sqrtf(m_vel.x*m_vel.x + m_vel.y*m_vel.y); if (desiredVelocity > curVelocity) { return; @@ -994,9 +994,9 @@ void PhysicsBehavior::doBounceSound(const Coord3D& prevPos) //Real vel = fabs(getVelocity()->z); // can't use velocity, because it's already been updated this frame, and will be zero... (srj) - Real vel = fabs(prevPos.z - getObject()->getPosition()->z); + Real vel = WWMath::Fabs(prevPos.z - getObject()->getPosition()->z); - Real mass = fabs(getMass()); + Real mass = WWMath::Fabs(getMass()); if (vel > NORMAL_VEL_Z) { vel = NORMAL_VEL_Z; } @@ -1196,7 +1196,7 @@ void PhysicsBehavior::onCollide( Object *other, const Coord3D *loc, const Coord3 m_lastCollidee = other->getID(); - Real dist = sqrtf(distSqr); + Real dist = WWMath::Sqrtf(distSqr); Real overlap = usRadius + themRadius - dist; // if objects are coincident, dist is zero, so force would be infinite -- clearly @@ -1337,7 +1337,7 @@ static Bool perpsLogicallyEqual( Real perpOne, Real perpTwo ) { // Equality with a wiggle fudge. const Real PERP_RANGE = 0.15f; - return fabs( perpOne - perpTwo ) <= PERP_RANGE; + return WWMath::Fabs( perpOne - perpTwo ) <= PERP_RANGE; } //------------------------------------------------------------------------------------------------- diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/PointDefenseLaserUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/PointDefenseLaserUpdate.cpp index 7c12ee6fd36..6546c004c3d 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/PointDefenseLaserUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/PointDefenseLaserUpdate.cpp @@ -167,7 +167,7 @@ void PointDefenseLaserUpdate::fireWhenReady() bonus.clear(); Real fireRange = data->m_weaponTemplate->getAttackRange( bonus ); Object *me = getObject(); - Real fDist = sqrt( ThePartitionManager->getDistanceSquared( me, target, FROM_CENTER_2D ) ); + Real fDist = WWMath::Sqrt( ThePartitionManager->getDistanceSquared( me, target, FROM_CENTER_2D ) ); if( fDist < fireRange ) { //We are currently in range! @@ -285,7 +285,7 @@ Object* PointDefenseLaserUpdate::scanClosestTarget() continue; } - Real fDist = sqrt( ThePartitionManager->getDistanceSquared( me, other, FROM_CENTER_2D ) ); + Real fDist = WWMath::Sqrt( ThePartitionManager->getDistanceSquared( me, other, FROM_CENTER_2D ) ); if( fDist <= fireRange ) { @@ -312,7 +312,7 @@ Object* PointDefenseLaserUpdate::scanClosestTarget() pos.add( *other->getPosition() ); //Recalculate the distance. - fDist = sqrt( ThePartitionManager->getDistanceSquared( me, other, FROM_CENTER_2D ) ); + fDist = WWMath::Sqrt( ThePartitionManager->getDistanceSquared( me, other, FROM_CENTER_2D ) ); } } diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/StealthUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/StealthUpdate.cpp index a653701eca8..b92d9743a34 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/StealthUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/StealthUpdate.cpp @@ -411,7 +411,7 @@ UpdateSleepTime StealthUpdate::update() m_disguiseHalfpointReached = true; } //Opacity ranges from full to none at midpoint and full again at the end - Real opacity = fabs( 1.0f - (factor * 2.0f) ); + Real opacity = WWMath::Fabs( 1.0f - (factor * 2.0f) ); Real overrideOpacity = opacity < 1.0f ? 0.0f : 1.0f; draw->setEffectiveOpacity( opacity, overrideOpacity ); if( !m_disguiseTransitionFrames && !m_transitioningToDisguise ) diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/TensileFormationUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/TensileFormationUpdate.cpp index 30b216a4484..f6e7b05ee8d 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/TensileFormationUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/TensileFormationUpdate.cpp @@ -348,7 +348,7 @@ UpdateSleepTime TensileFormationUpdate::update() else draw->clearModelConditionFlags(MAKE_MODELCONDITION_MASK(MODELCONDITION_MOVING)); - if ( fabs( pos->z - newPos.z ) > 0.2f && m_life < 100) + if ( WWMath::Fabs( pos->z - newPos.z ) > 0.2f && m_life < 100) draw->setModelConditionFlags(MAKE_MODELCONDITION_MASK(MODELCONDITION_FREEFALL)); else draw->clearModelConditionFlags(MAKE_MODELCONDITION_MASK(MODELCONDITION_FREEFALL)); diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/ToppleUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/ToppleUpdate.cpp index bd725493a58..335d8f39e33 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/ToppleUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/ToppleUpdate.cpp @@ -130,7 +130,7 @@ static Real angleClosestTo(Real a1, Real a2, Real desired) { a1 = normalizeAngle(a1); a2 = normalizeAngle(a2); - return (fabs(stdAngleDiff(desired, a1)) < fabs(stdAngleDiff(desired, a2))) ? a1 : a2; + return (WWMath::Fabs(stdAngleDiff(desired, a1)) < WWMath::Fabs(stdAngleDiff(desired, a2))) ? a1 : a2; } //------------------------------------------------------------------------------------------------- @@ -185,7 +185,7 @@ void ToppleUpdate::applyTopplingForce( const Coord3D* toppleDirection, Real topp // yeah, it assumes the models are constructed appropriately, but is a cheap way // of minimizing the problem. (srj) Real curAngleX = normalizeAngle(getObject()->getOrientation()); - Real toppleAngle = normalizeAngle(atan2(m_toppleDirection.y, m_toppleDirection.x)); + Real toppleAngle = normalizeAngle(WWMath::Atan2(m_toppleDirection.y, m_toppleDirection.x)); if (d->m_toppleLeftOrRightOnly) { // it's a fence or such, and can only topple left or right, so pick the closest @@ -298,7 +298,7 @@ UpdateSleepTime ToppleUpdate::update() m_angularVelocity *= -d->m_bounceVelocityPercent; if( BitIsSet( m_options, TOPPLE_OPTIONS_NO_BOUNCE ) == TRUE || - fabs(m_angularVelocity) < VELOCITY_BOUNCE_LIMIT ) + WWMath::Fabs(m_angularVelocity) < VELOCITY_BOUNCE_LIMIT ) { // too slow, just stop m_angularVelocity = 0; @@ -338,7 +338,7 @@ UpdateSleepTime ToppleUpdate::update() } } } - else if( fabs(m_angularVelocity) >= VELOCITY_BOUNCE_SOUND_LIMIT ) + else if( WWMath::Fabs(m_angularVelocity) >= VELOCITY_BOUNCE_SOUND_LIMIT ) { // fast enough bounce to warrant the bounce fx if( BitIsSet( m_options, TOPPLE_OPTIONS_NO_FX ) == FALSE ) diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp index d4f6bf29828..3fca46f7e1e 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp @@ -383,8 +383,8 @@ void WeaponTemplate::reset() // No matter what we have now, we want to convert it to frames from msec. // ShotDelay used to use parseDurationUnsignedInt, and we are expanding on that. - self->m_minDelayBetweenShots = ceilf(ConvertDurationFromMsecsToFrames((Real)self->m_minDelayBetweenShots)); - self->m_maxDelayBetweenShots = ceilf(ConvertDurationFromMsecsToFrames((Real)self->m_maxDelayBetweenShots)); + self->m_minDelayBetweenShots = WWMath::Ceilf(ConvertDurationFromMsecsToFrames((Real)self->m_minDelayBetweenShots)); + self->m_maxDelayBetweenShots = WWMath::Ceilf(ConvertDurationFromMsecsToFrames((Real)self->m_maxDelayBetweenShots)); } @@ -847,7 +847,7 @@ UnsignedInt WeaponTemplate::fireWeaponTemplate if (distSqr < minAttackRangeSqr-0.5f && !isProjectileDetonation) #endif { - DEBUG_ASSERTCRASH(distSqr > minAttackRangeSqr*0.8f, ("*** victim is closer than min attack range (%f vs %f) of this weapon -- why did we attempt to fire?",sqrtf(distSqr),sqrtf(minAttackRangeSqr))); + DEBUG_ASSERTCRASH(distSqr > minAttackRangeSqr*0.8f, ("*** victim is closer than min attack range (%f vs %f) of this weapon -- why did we attempt to fire?",WWMath::Sqrtf(distSqr),WWMath::Sqrtf(minAttackRangeSqr))); //-extraLogging #if defined(RTS_DEBUG) @@ -873,7 +873,7 @@ UnsignedInt WeaponTemplate::fireWeaponTemplate targetPos.set( *victimPos ); } Real reAngle = getWeaponRecoilAmount(); - Real reDir = reAngle != 0.0f ? (atan2(victimPos->y - sourcePos->y, victimPos->x - sourcePos->x)) : 0.0f; + Real reDir = reAngle != 0.0f ? (WWMath::Atan2(victimPos->y - sourcePos->y, victimPos->x - sourcePos->x)) : 0.0f; VeterancyLevel v = sourceObj->getVeterancyLevel(); const FXList* fx = isProjectileDetonation ? getProjectileDetonateFX(v) : getFireFX(v); @@ -1920,11 +1920,11 @@ Bool Weapon::computeApproachTarget(const Object *source, const Object *target, c if (source->isAboveTerrain()) { // Don't do a 180 degree turn. - Real angle = atan2(-dir.y, -dir.x); + Real angle = WWMath::Atan2(-dir.y, -dir.x); Real relAngle = source->getOrientation()- angle; if (relAngle>2*PI) relAngle -= 2*PI; if (relAngle<-2*PI) relAngle += 2*PI; - if (fabs(relAngle)getPosition(); const Real ACCEPTABLE_DZ = 10.0f; - if (fabs(dst->z - src->z) < ACCEPTABLE_DZ) + if (WWMath::Fabs(dst->z - src->z) < ACCEPTABLE_DZ) return true; // always good enough if dz is small, regardless of pitch Real minPitch, maxPitch; diff --git a/Generals/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp b/Generals/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp index 6d6f57487bc..211f6a59c22 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp @@ -808,7 +808,7 @@ static void populateRandomStartPosition( GameInfo *game ) { Coord3D p1 = c1->second; Coord3D p2 = c2->second; - startSpotDistance[i][j] = sqrt( sqr(p1.x-p2.x) + sqr(p1.y-p2.y) ); + startSpotDistance[i][j] = WWMath::Sqrt( sqr(p1.x-p2.x) + sqr(p1.y-p2.y) ); } } else diff --git a/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cpp b/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cpp index 7a140b6fd8f..d553ce0cbd6 100644 --- a/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cpp +++ b/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cpp @@ -1686,9 +1686,9 @@ void W3DVolumetricShadow::Update() if (fabs(pos.Z - groundHeight) >= AIRBORNE_UNIT_GROUND_DELTA) { Real extent = MAX_SHADOW_LENGTH_EXTRA_AIRBORNE_SCALE_FACTOR * m_robjExtent; - if (WWMath::Fabs(pos.X - bcX) > (beX + extent) || - WWMath::Fabs(pos.Y - bcY) > (beY + extent) || - WWMath::Fabs(pos.Z - bcZ) > (beZ + extent)) + if (WWMath::Fabsf_Legacy(pos.X - bcX) > (beX + extent) || + WWMath::Fabsf_Legacy(pos.Y - bcY) > (beY + extent) || + WWMath::Fabsf_Legacy(pos.Z - bcZ) > (beZ + extent)) return; //shadow can't be visible so no point in updating. //this unit is above ground, extend shadow volume to reach lowest point on the terrain plus extra bit to make @@ -1699,9 +1699,9 @@ void W3DVolumetricShadow::Update() { //normal object that is not floating above ground so we don't need to extend the shadow lower than the object's //base since it should be sitting directly at ground level. - if (WWMath::Fabs(pos.X - bcX) > (beX + m_robjExtent) || - WWMath::Fabs(pos.Y - bcY) > (beY + m_robjExtent) || - WWMath::Fabs(pos.Z - bcZ) > (beZ + m_robjExtent)) + if (WWMath::Fabsf_Legacy(pos.X - bcX) > (beX + m_robjExtent) || + WWMath::Fabsf_Legacy(pos.Y - bcY) > (beY + m_robjExtent) || + WWMath::Fabsf_Legacy(pos.Z - bcZ) > (beZ + m_robjExtent)) return; //shadow can't be visible so no point in updating. //check if this object has never had it's extrusion length updated. Will only be true for diff --git a/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DAssetManager.cpp b/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DAssetManager.cpp index a2a8267bb35..cc7a5240a94 100644 --- a/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DAssetManager.cpp +++ b/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DAssetManager.cpp @@ -688,7 +688,7 @@ RenderObjClass * W3DAssetManager::Create_Render_Obj( GetPrecisionTimer(&startTime64); #endif - Bool reallyscale = (WWMath::Fabs(scale - ident_scale) > scale_epsilon); + Bool reallyscale = (WWMath::Fabsf_Legacy(scale - ident_scale) > scale_epsilon); Bool reallycolor = (color & 0xFFFFFF) != 0; //black is not a valid color and assumes no custom coloring. Bool reallytexture = (oldTexture != nullptr && newTexture != nullptr); @@ -1303,9 +1303,9 @@ static inline void Munge_Texture_Name(char *newname, const char *oldname, const RenderObjClass * W3DAssetManager::Create_Render_Obj(const char * name,float scale, const Vector3 &hsv_shift) { Bool isGranny = false; - Bool reallyscale = (WWMath::Fabs(scale - ident_scale) > scale_epsilon); - Bool reallyhsv_shift = (WWMath::Fabs(hsv_shift.X - ident_HSV.X) > H_epsilon || - WWMath::Fabs(hsv_shift.Y - ident_HSV.Y) > S_epsilon || WWMath::Fabs(hsv_shift.Z - ident_HSV.Z) > V_epsilon); + Bool reallyscale = (WWMath::Fabsf(scale - ident_scale) > scale_epsilon); + Bool reallyhsv_shift = (WWMath::Fabsf(hsv_shift.X - ident_HSV.X) > H_epsilon || + WWMath::Fabsf(hsv_shift.Y - ident_HSV.Y) > S_epsilon || WWMath::Fabsf(hsv_shift.Z - ident_HSV.Z) > V_epsilon); // base case, no scale or hue shifting if (!reallyscale && !reallyhsv_shift) return WW3DAssetManager::Create_Render_Obj(name); @@ -1402,8 +1402,8 @@ TextureClass * W3DAssetManager::Get_Texture_With_HSV_Shift(const char * filename { WWPROFILE( "W3DAssetManager::Get_Texture with HSV shift" ); - Bool is_hsv_shift = (WWMath::Fabs(hsv_shift.X - ident_HSV.X) > H_epsilon || - WWMath::Fabs(hsv_shift.Y - ident_HSV.Y) > S_epsilon || WWMath::Fabs(hsv_shift.Z - ident_HSV.Z) > V_epsilon); + Bool is_hsv_shift = (WWMath::Fabsf(hsv_shift.X - ident_HSV.X) > H_epsilon || + WWMath::Fabsf(hsv_shift.Y - ident_HSV.Y) > S_epsilon || WWMath::Fabsf(hsv_shift.Z - ident_HSV.Z) > V_epsilon); if (!is_hsv_shift) { diff --git a/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DParticleSys.cpp b/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DParticleSys.cpp index adb44f0d3b3..fd9a9c0f69e 100644 --- a/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DParticleSys.cpp +++ b/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DParticleSys.cpp @@ -172,13 +172,13 @@ void W3DParticleSystemManager::doParticles(RenderInfoClass &rinfo) psize = p->getSize(); //Cull particle to edges of screen and terrain. - if (WWMath::Fabs(pos->x - bcX) > (beX + psize)) + if (WWMath::Fabsf_Legacy(pos->x - bcX) > (beX + psize)) continue; - if (WWMath::Fabs(pos->y - bcY) > (beY + psize)) + if (WWMath::Fabsf_Legacy(pos->y - bcY) > (beY + psize)) continue; - if (WWMath::Fabs(pos->z - bcZ) > (beZ + psize)) + if (WWMath::Fabsf_Legacy(pos->z - bcZ) > (beZ + psize)) continue; m_fieldParticleCount += ( sys->getPriority() == AREA_EFFECT && sys->m_isGroundAligned != FALSE ); diff --git a/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DRoadBuffer.cpp b/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DRoadBuffer.cpp index 7945336c727..3f607455eca 100644 --- a/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DRoadBuffer.cpp +++ b/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DRoadBuffer.cpp @@ -2872,7 +2872,7 @@ void W3DRoadBuffer::insertCurveSegmentAt(Int ndx1, Int ndx2) line1.Set(Vector3(pr1->X, pr1->Y, 0), Vector3(pr2->X, pr2->Y, 0)); line2.Set(Vector3(pr3->X, pr3->Y, 0), Vector3(pr4->X, pr4->Y, 0)); } - Real angle = WWMath::Acos(curSin); + Real angle = WWMath::Acos_Legacy(curSin); Real count = angle / (PI/6.0f); // number of 30 degree steps. if (count<0.9 || m_roads[ndx1].m_pt1.isAngled) { miter(ndx1, ndx2); diff --git a/Generals/Code/Libraries/Source/WWVegas/WW3D2/camera.cpp b/Generals/Code/Libraries/Source/WWVegas/WW3D2/camera.cpp index 530d16f90d0..01d58ba38fd 100644 --- a/Generals/Code/Libraries/Source/WWVegas/WW3D2/camera.cpp +++ b/Generals/Code/Libraries/Source/WWVegas/WW3D2/camera.cpp @@ -769,13 +769,13 @@ void CameraClass::Get_Clip_Planes(float & znear,float & zfar) const float CameraClass::Get_Horizontal_FOV() const { float width = ViewPlane.Max.X - ViewPlane.Min.X; - return 2*WWMath::Atan2(width,2.0); + return 2*WWMath::Atan2_Legacy(width,2.0); } float CameraClass::Get_Vertical_FOV() const { float height = ViewPlane.Max.Y - ViewPlane.Min.Y; - return 2*WWMath::Atan2(height,2.0); + return 2*WWMath::Atan2_Legacy(height,2.0); } float CameraClass::Get_Aspect_Ratio() const diff --git a/Generals/Code/Libraries/Source/WWVegas/WW3D2/mapper.cpp b/Generals/Code/Libraries/Source/WWVegas/WW3D2/mapper.cpp index 9d788db893d..bed4d324ec7 100644 --- a/Generals/Code/Libraries/Source/WWVegas/WW3D2/mapper.cpp +++ b/Generals/Code/Libraries/Source/WWVegas/WW3D2/mapper.cpp @@ -102,8 +102,8 @@ void LinearOffsetTextureMapperClass::Apply(int uv_array_index) float offset_v = CurrentUVOffset.Y + UVOffsetDeltaPerMS.Y * del; // ensure both coordinates of offset are in [0, 1] range: - offset_u = offset_u - WWMath::Floor(offset_u); - offset_v = offset_v - WWMath::Floor(offset_v); + offset_u = offset_u - WWMath::Floorf(offset_u); + offset_v = offset_v - WWMath::Floorf(offset_v); // Set up the offset matrix Matrix3D m(true); @@ -326,8 +326,8 @@ void RotateTextureMapperClass::Apply(int uv_array_index) // Set up the rotation matrix float c,s; - c=WWMath::Cos(CurrentAngle); - s=WWMath::Sin(CurrentAngle); + c=WWMath::Cosf_Legacy(CurrentAngle); + s=WWMath::Sinf_Legacy(CurrentAngle); Matrix4x4 m(true); // subtract center @@ -392,8 +392,8 @@ void SineLinearOffsetTextureMapperClass::Apply(int uv_array_index) float offset_v=VAFP.X*sin(VAFP.Y*CurrentAngle+VAFP.Z*WWMATH_PI); // ensure both coordinates of offset are in [0, 1] range: - offset_u = offset_u - WWMath::Floor(offset_u); - offset_v = offset_v - WWMath::Floor(offset_v); + offset_u = offset_u - WWMath::Floorf(offset_u); + offset_v = offset_v - WWMath::Floorf(offset_v); // Set up the offset matrix Matrix3D m(true); @@ -455,8 +455,8 @@ void StepLinearOffsetTextureMapperClass::Apply(int uv_array_index) } // ensure both coordinates of offset are in [0, 1] range: - CurrentStep.U -= WWMath::Floor(CurrentStep.U); - CurrentStep.V -= WWMath::Floor(CurrentStep.V); + CurrentStep.U -= WWMath::Floorf(CurrentStep.U); + CurrentStep.V -= WWMath::Floorf(CurrentStep.V); // Set up the offset matrix Matrix3D m(true); @@ -533,8 +533,8 @@ void ZigZagLinearOffsetTextureMapperClass::Apply(int uv_array_index) } // ensure both coordinates of offset are in [0, 1] range: - offset_u = offset_u - WWMath::Floor(offset_u); - offset_v = offset_v - WWMath::Floor(offset_v); + offset_u = offset_u - WWMath::Floorf(offset_u); + offset_v = offset_v - WWMath::Floorf(offset_v); // Set up the offset matrix Matrix3D m(true); @@ -642,7 +642,7 @@ void EdgeMapperClass::Apply(int uv_array_index) LastUsedSyncTime=now; VOffset+=delta*VSpeed; - VOffset-=WWMath::Floor(VOffset); + VOffset-=WWMath::Floorf(VOffset); // takes the Z component and // uses it to index the texture @@ -740,8 +740,8 @@ void ScreenMapperClass::Apply(int uv_array_index) float offset_v = CurrentUVOffset.Y + UVOffsetDeltaPerMS.Y * del; // ensure both coordinates of offset are in [0, 1] range: - offset_u = offset_u - WWMath::Floor(offset_u); - offset_v = offset_v - WWMath::Floor(offset_v); + offset_u = offset_u - WWMath::Floorf(offset_u); + offset_v = offset_v - WWMath::Floorf(offset_v); // multiply by projection matrix // followed by scale and translation diff --git a/Generals/Code/Libraries/Source/WWVegas/WW3D2/motchan.cpp b/Generals/Code/Libraries/Source/WWVegas/WW3D2/motchan.cpp index 71d4c6d7ad6..91be43940ee 100644 --- a/Generals/Code/Libraries/Source/WWVegas/WW3D2/motchan.cpp +++ b/Generals/Code/Libraries/Source/WWVegas/WW3D2/motchan.cpp @@ -846,7 +846,7 @@ AdaptiveDeltaMotionChannelClass::AdaptiveDeltaMotionChannelClass() : //ratio = ((ratio + 1.0f) / 128.0f); ratio/=((float) FILTER_TABLE_GEN_SIZE); - filtertable[i + FILTER_TABLE_GEN_START] = 1.0f - WWMath::Sin( DEG_TO_RAD(90.0f * ratio)); + filtertable[i + FILTER_TABLE_GEN_START] = 1.0f - WWMath::Sinf_Legacy( DEG_TO_RAD(90.0f * ratio)); } table_valid = true; diff --git a/Generals/Code/Libraries/Source/WWVegas/WW3D2/part_emt.cpp b/Generals/Code/Libraries/Source/WWVegas/WW3D2/part_emt.cpp index 5d22f490310..3d0fc9fab7b 100644 --- a/Generals/Code/Libraries/Source/WWVegas/WW3D2/part_emt.cpp +++ b/Generals/Code/Libraries/Source/WWVegas/WW3D2/part_emt.cpp @@ -661,7 +661,7 @@ void ParticleEmitterClass::Initialize_Particle(NewParticleStruct * newpart, Vector3 outwards; float pos_l2 = rand_pos.Length2(); if (pos_l2) { - outwards = rand_pos * (OutwardVel * WWMath::Inv_Sqrt(pos_l2)); + outwards = rand_pos * (OutwardVel * WWMath::Inv_Sqrt_Legacy(pos_l2)); } else { outwards.X = OutwardVel; outwards.Y = 0.0f; diff --git a/Generals/Code/Libraries/Source/WWVegas/WW3D2/render2d.cpp b/Generals/Code/Libraries/Source/WWVegas/WW3D2/render2d.cpp index 8a48ccba1a7..8ddc60a7ef5 100644 --- a/Generals/Code/Libraries/Source/WWVegas/WW3D2/render2d.cpp +++ b/Generals/Code/Libraries/Source/WWVegas/WW3D2/render2d.cpp @@ -198,8 +198,8 @@ Vector2 Render2DClass::Convert_Vert( const Vector2 & v ) out.Y = (out.Y - 1.0f) * (Get_Screen_Resolution().Height() * -0.5f); // Round to nearest pixel - out.X = WWMath::Floor( out.X + 0.5f ); - out.Y = WWMath::Floor( out.Y + 0.5f ); + out.X = WWMath::Floorf( out.X + 0.5f ); + out.Y = WWMath::Floorf( out.Y + 0.5f ); // Bias if ( WW3D::Is_Screen_UV_Biased() ) { // Global bais setting diff --git a/Generals/Code/Tools/WorldBuilder/src/GlobalLightOptions.cpp b/Generals/Code/Tools/WorldBuilder/src/GlobalLightOptions.cpp index 1eaa4ba4f2c..daccb868e94 100644 --- a/Generals/Code/Tools/WorldBuilder/src/GlobalLightOptions.cpp +++ b/Generals/Code/Tools/WorldBuilder/src/GlobalLightOptions.cpp @@ -54,8 +54,8 @@ static void calcNewLight(Int lr, Int fb, Vector3 *newLight) newLight->Set(0,0,-1); Real yAngle = PI*(lr-90)/180; Real xAngle = PI*(fb-90)/180; - Real zAngle = xAngle * WWMath::Sin(yAngle); - xAngle *= WWMath::Cos(yAngle); + Real zAngle = xAngle * WWMath::Sinf(yAngle); + xAngle *= WWMath::Cosf(yAngle); newLight->Rotate_Y(yAngle); newLight->Rotate_X(xAngle); newLight->Rotate_Z(zAngle); @@ -94,8 +94,8 @@ void GlobalLightOptions::updateEditFields() void GlobalLightOptions::showLightFeedback(Int lightIndex) { Vector3 light(0,0,0); - light.X = sin(PI/2.0f+m_angleElevation[lightIndex]/180.0f*PI)*cos(m_angleAzimuth[lightIndex]/180.0f*PI);// -WWMath::Sin(PI*(m_angleLR[lightIndex]-90)/180); - light.Y = sin(PI/2.0f+m_angleElevation[lightIndex]/180.0f*PI)*sin(m_angleAzimuth[lightIndex]/180.0f*PI);//-WWMath::Sin(PI*(m_angleFB[lightIndex]-90)/180); + light.X = sin(PI/2.0f+m_angleElevation[lightIndex]/180.0f*PI)*cos(m_angleAzimuth[lightIndex]/180.0f*PI);// -WWMath::Sinf(PI*(m_angleLR[lightIndex]-90)/180); + light.Y = sin(PI/2.0f+m_angleElevation[lightIndex]/180.0f*PI)*sin(m_angleAzimuth[lightIndex]/180.0f*PI);//-WWMath::Sinf(PI*(m_angleFB[lightIndex]-90)/180); light.Z = cos (PI/2.0f+m_angleElevation[lightIndex]/180.0f*PI); WbView3d * pView = CWorldBuilderDoc::GetActive3DView(); @@ -109,8 +109,8 @@ void GlobalLightOptions::showLightFeedback(Int lightIndex) void GlobalLightOptions::applyAngle(Int lightIndex) { Vector3 light(0,0,0); - light.X = sin(PI/2.0f+m_angleElevation[lightIndex]/180.0f*PI)*cos(m_angleAzimuth[lightIndex]/180.0f*PI);// -WWMath::Sin(PI*(m_angleLR[lightIndex]-90)/180); - light.Y = sin(PI/2.0f+m_angleElevation[lightIndex]/180.0f*PI)*sin(m_angleAzimuth[lightIndex]/180.0f*PI);//-WWMath::Sin(PI*(m_angleFB[lightIndex]-90)/180); + light.X = sin(PI/2.0f+m_angleElevation[lightIndex]/180.0f*PI)*cos(m_angleAzimuth[lightIndex]/180.0f*PI);// -WWMath::Sinf(PI*(m_angleLR[lightIndex]-90)/180); + light.Y = sin(PI/2.0f+m_angleElevation[lightIndex]/180.0f*PI)*sin(m_angleAzimuth[lightIndex]/180.0f*PI);//-WWMath::Sinf(PI*(m_angleFB[lightIndex]-90)/180); light.Z = cos (PI/2.0f+m_angleElevation[lightIndex]/180.0f*PI); CString str; diff --git a/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp b/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp index 8286128c090..7ff08293bac 100644 --- a/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp +++ b/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp @@ -2469,7 +2469,7 @@ void Player::doBountyForKill(const Object* killer, const Object* victim) Int bounty = REAL_TO_INT_CEIL(costToBuild * m_cashBountyPercent); #else // TheSuperHackers @bugfix Stubbjax 20/02/2026 Subtract epsilon to ensure bounty is rounded up correctly. - Int bounty = ceil((costToBuild * m_cashBountyPercent) - WWMATH_EPSILON); + Int bounty = WWMath::Ceil((costToBuild * m_cashBountyPercent) - WWMATH_EPSILON); #endif if( bounty ) diff --git a/GeneralsMD/Code/GameEngine/Source/Common/System/BuildAssistant.cpp b/GeneralsMD/Code/GameEngine/Source/Common/System/BuildAssistant.cpp index 138d4e3430b..54dd7c3ee6f 100644 --- a/GeneralsMD/Code/GameEngine/Source/Common/System/BuildAssistant.cpp +++ b/GeneralsMD/Code/GameEngine/Source/Common/System/BuildAssistant.cpp @@ -806,8 +806,8 @@ LegalBuildCode BuildAssistant::isLocationClearOfObjects( const Coord3D *worldPos if (myFactoryExitWidth>0) { myExitPos = *worldPos; checkMyExit = true; - Real c = (Real)cos(angle); - Real s = (Real)sin(angle); + Real c = (Real)WWMath::Cos(angle); + Real s = (Real)WWMath::Sin(angle); Real offset = build->getTemplateGeometryInfo().getMajorRadius() + myFactoryExitWidth/2.0f; myExitPos.x += c*offset; myExitPos.y += s*offset; @@ -854,8 +854,8 @@ LegalBuildCode BuildAssistant::isLocationClearOfObjects( const Coord3D *worldPos if (themFactoryExitWidth>0) { hisExitPos = *them->getPosition(); checkHisExit = true; - Real c = (Real)cos(them->getOrientation()); - Real s = (Real)sin(them->getOrientation()); + Real c = (Real)WWMath::Cos(them->getOrientation()); + Real s = (Real)WWMath::Sin(them->getOrientation()); Real offset = them->getGeometryInfo().getMajorRadius() + themFactoryExitWidth/2.0f; hisExitPos.x += c*offset; hisExitPos.y += s*offset; @@ -1435,7 +1435,7 @@ Bool BuildAssistant::moveObjectsForConstruction( const ThingTemplate *whatToBuil Bool anyUnmovables = false; MemoryPoolObjectHolder hold( iter ); - Real radius = sqrt(pow(gi.getMajorRadius(), 2) + pow(gi.getMinorRadius(), 2)); + Real radius = WWMath::Sqrt(WWMath::Pow(gi.getMajorRadius(), 2) + WWMath::Pow(gi.getMinorRadius(), 2)); radius *= 1.4f; // Fudge the distance, for( Object *them = iter->first(); them; them = iter->next() ) diff --git a/GeneralsMD/Code/GameEngine/Source/Common/System/Geometry.cpp b/GeneralsMD/Code/GameEngine/Source/Common/System/Geometry.cpp index 1f927ae2615..16f47f2e951 100644 --- a/GeneralsMD/Code/GameEngine/Source/Common/System/Geometry.cpp +++ b/GeneralsMD/Code/GameEngine/Source/Common/System/Geometry.cpp @@ -173,17 +173,17 @@ void GeometryInfo::calcPitches(const Coord3D& thisPos, const GeometryInfo& that, Coord3D thisCenter; getCenterPosition(thisPos, thisCenter); - Real dxy = sqrt(sqr(thatPos.x - thisCenter.x) + sqr(thatPos.y - thisCenter.y)); + Real dxy = WWMath::Sqrt(sqr(thatPos.x - thisCenter.x) + sqr(thatPos.y - thisCenter.y)); Real dz; /** @todo srj -- this could be better, by calcing it for all the corners, not just top-center and bottom-center... oh well */ dz = (thatPos.z + that.getMaxHeightAbovePosition()) - thisCenter.z; - maxPitch = atan2(dz, dxy); + maxPitch = WWMath::Atan2(dz, dxy); dz = (thatPos.z - that.getMaxHeightBelowPosition()) - thisCenter.z; - minPitch = atan2(dz, dxy); + minPitch = WWMath::Atan2(dz, dxy); } //============================================================================= @@ -279,8 +279,8 @@ void GeometryInfo::get2DBounds(const Coord3D& geomCenter, Real angle, Region2D& case GEOMETRY_BOX: { - Real c = (Real)cos(angle); - Real s = (Real)sin(angle); + Real c = (Real)WWMath::Cos(angle); + Real s = (Real)WWMath::Sin(angle); Real exc = m_majorRadius*c; Real eyc = m_minorRadius*c; Real exs = m_majorRadius*s; @@ -329,7 +329,7 @@ void GeometryInfo::clipPointToFootprint(const Coord3D& geomCenter, Coord3D& ptTo { Real dx = ptToClip.x - geomCenter.x; Real dy = ptToClip.y - geomCenter.y; - Real radius = sqrt(sqr(dx) + sqr(dy)); + Real radius = WWMath::Sqrt(sqr(dx) + sqr(dy)); if (radius > m_majorRadius) { Real ratio = m_majorRadius / radius; @@ -361,7 +361,7 @@ Bool GeometryInfo::isPointInFootprint(const Coord3D& geomCenter, const Coord3D& { Real dx = pt.x - geomCenter.x; Real dy = pt.y - geomCenter.y; - Real radius = sqrt(sqr(dx) + sqr(dy)); + Real radius = WWMath::Sqrt(sqr(dx) + sqr(dy)); return (radius <= m_majorRadius); break; } @@ -506,8 +506,8 @@ void GeometryInfo::calcBoundingStuff() case GEOMETRY_BOX: { - m_boundingCircleRadius = sqrt(sqr(m_majorRadius) + sqr(m_minorRadius)); - m_boundingSphereRadius = sqrt(sqr(m_majorRadius) + sqr(m_minorRadius) + sqr(m_height*0.5)); + m_boundingCircleRadius = WWMath::Sqrt(sqr(m_majorRadius) + sqr(m_minorRadius)); + m_boundingSphereRadius = WWMath::Sqrt(sqr(m_majorRadius) + sqr(m_minorRadius) + sqr(m_height*0.5)); break; } }; diff --git a/GeneralsMD/Code/GameEngine/Source/Common/System/Trig.cpp b/GeneralsMD/Code/GameEngine/Source/Common/System/Trig.cpp index 2ffb79bbae2..bfedd93bd5a 100644 --- a/GeneralsMD/Code/GameEngine/Source/Common/System/Trig.cpp +++ b/GeneralsMD/Code/GameEngine/Source/Common/System/Trig.cpp @@ -29,117 +29,24 @@ #include "PreRTS.h" -#include -#include - #include "Lib/BaseType.h" #include "Lib/trig.h" -#define TWOPI 6.28318530718f -#define DEG2RAD 0.0174532925199f -#define TRIG_RES 4096 - -// the following are for fixed point ints with 12 fractional bits -#define INT_ONE 4096 -#define INT_TWOPI 25736 -#define INT_THREEPIOVERTWO 19302 -#define INT_PI 12868 -#define INT_HALFPI 6434 - -Real Sin(Real x) -{ - return sinf(x); -} - -Real Cos(Real x) -{ - return cosf(x); -} - -Real Tan(Real x) -{ - return tanf(x); -} - -Real ACos(Real x) -{ - return acosf(x); -} - -Real ASin(Real x) -{ - return asinf(x); -} +#if USE_DETERMINISTIC_MATH +#include "gmath.h" +#endif -#ifdef REGENERATE_TRIG_TABLES -void initTrig() +Real Sin(Real x) { return WWMath::Sinf(x); } +Real Cos(Real x) { return WWMath::Cosf(x); } +Real Tan(Real x) { return WWMath::Tanf(x); } +Real ACos(Real x) { return WWMath::Acosf(x); } +Real ASin(Real x) { return WWMath::Asinf(x); } +Real Sqrt(Real x) { - static Byte inited = FALSE; - Real angle, r; - int i; - - if (inited) - return; - - inited = TRUE; - - static int columns = 8; - int column = 0; - FILE *fp = fopen("trig.txt", "w"); - fprintf(fp, "static Int sinLookup[TRIG_RES] = {\n"); - for( i=0; igetDistanceSquared(me, theEnemy, FROM_BOUNDINGSPHERE_2D); - Real dist = sqrt(distSqr); + Real dist = WWMath::Sqrt(distSqr); Int modifier = dist/getAiData()->m_attackPriorityDistanceModifier; Int modPriority = curPriority-modifier; if (modPriority < 1) diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIGroup.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIGroup.cpp index dfc65a9c666..f2c0f9ac3e4 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIGroup.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIGroup.cpp @@ -1883,8 +1883,8 @@ void getHelicopterOffset( Coord3D& posOut, Int idx ) } Coord3D tempCtr = posOut; - posOut.x = tempCtr.x + (sin(angle) * radius); - posOut.y = tempCtr.y + (cos(angle) * radius); + posOut.x = tempCtr.x + (WWMath::Sin(angle) * radius); + posOut.y = tempCtr.y + (WWMath::Cos(angle) * radius); } diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp index 330969a65ed..104d3c5487a 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp @@ -495,7 +495,7 @@ Object *AIPlayer::buildStructureNow(const ThingTemplate *bldgPlan, BuildListInfo { Coord3D rallyPoint; Bool gotOffset = false; - if (fabs(info->getRallyOffset()->x) > 1.0f || fabs(info->getRallyOffset()->y)>1.0f) { + if (WWMath::Fabs(info->getRallyOffset()->x) > 1.0f || WWMath::Fabs(info->getRallyOffset()->y)>1.0f) { gotOffset; } if (!exitInterface->getNaturalRallyPoint(rallyPoint)) { @@ -653,7 +653,7 @@ Object *AIPlayer::buildStructureWithDozer(const ThingTemplate *bldgPlan, BuildLi dx = dozer->getPosition()->x - pos.x; dy = dozer->getPosition()->y - pos.y; - Int count = sqrt(dx*dx+dy*dy)/(PATHFIND_CELL_SIZE_F/2); + Int count = WWMath::Sqrt(dx*dx+dy*dy)/(PATHFIND_CELL_SIZE_F/2); if (count<2) count = 2; Int i; color.green = 1; @@ -675,7 +675,7 @@ Object *AIPlayer::buildStructureWithDozer(const ThingTemplate *bldgPlan, BuildLi { Coord3D rallyPoint; Bool gotOffset = false; - if (fabs(info->getRallyOffset()->x) > 1.0f || fabs(info->getRallyOffset()->y)>1.0f) { + if (WWMath::Fabs(info->getRallyOffset()->x) > 1.0f || WWMath::Fabs(info->getRallyOffset()->y)>1.0f) { gotOffset; } if (!exitInterface->getNaturalRallyPoint(rallyPoint)) { @@ -1360,7 +1360,7 @@ Int AIPlayer::getPlayerSuperweaponValue(Coord3D *center, Int playerNdx, Real rad Real dy = center->y - pos.y; if (dx*dx+dy*dygetTemplate()->calcCostToBuild(pPlayer); if (pObj->isKindOf(KINDOF_COMMANDCENTER)) @@ -3145,7 +3145,7 @@ void AIPlayer::computeCenterAndRadiusOfBase(Coord3D *center, Real *radius) Real radSqr = dx*dx+dy*dy; if (radSqr>maxRadSqr) maxRadSqr=radSqr; } - *radius = sqrt(maxRadSqr); + *radius = WWMath::Sqrt(maxRadSqr); } //---------------------------------------------------------------------------------------------------------- diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AISkirmishPlayer.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AISkirmishPlayer.cpp index 0a1a7ea64da..51774077f5b 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AISkirmishPlayer.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AISkirmishPlayer.cpp @@ -672,8 +672,8 @@ void AISkirmishPlayer::buildAIBaseDefenseStructure(const AsciiString &thingName, } if (angle > PI/3) break; - Real s = sin(angle); - Real c = cos(angle); + Real s = WWMath::Sin(angle); + Real c = WWMath::Cos(angle); // TheSuperHackers @info helmutbuhler 21/04/2025 This debug mutates the code to become CRC incompatible #if defined(RTS_DEBUG) || !RETAIL_COMPATIBLE_CRC @@ -1038,8 +1038,8 @@ void AISkirmishPlayer::adjustBuildList(BuildListInfo *list) angle += 3*PI/4; - Real s = sin(angle); - Real c = cos(angle); + Real s = WWMath::Sin(angle); + Real c = WWMath::Cos(angle); cur = list; while (cur) { diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp index f78e882cc0c..7bfed05db72 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp @@ -527,7 +527,7 @@ StateReturnType AIRappelState::onEnter() obj->setLayer(layerAtDest); AIUpdateInterface *ai = obj->getAI(); - Real MAX_RAPPEL_RATE = fabs(TheGlobalData->m_gravity) * LOGICFRAMES_PER_SECOND * 2.5f; + Real MAX_RAPPEL_RATE = WWMath::Fabs(TheGlobalData->m_gravity) * LOGICFRAMES_PER_SECOND * 2.5f; m_rappelRate = -min(ai->getDesiredSpeed(), MAX_RAPPEL_RATE); return STATE_CONTINUE; @@ -3674,7 +3674,7 @@ StateReturnType AIAttackMoveToState::update() if (distSqr < sqr(ATTACK_CLOSE_ENOUGH_CELLS*PATHFIND_CELL_SIZE_F)) { return ret; } - DEBUG_LOG(("AIAttackMoveToState::update Distance from goal %f, retrying.", sqrt(distSqr))); + DEBUG_LOG(("AIAttackMoveToState::update Distance from goal %f, retrying.", WWMath::Sqrt(distSqr))); ret = STATE_CONTINUE; m_retryCount--; @@ -3904,16 +3904,16 @@ void AIFollowWaypointPathState::computeGoal(Bool useGroupOffsets) if (m_priorWaypoint) { dx = dest.x - m_priorWaypoint->getLocation()->x; dy = dest.y - m_priorWaypoint->getLocation()->y; - angle = atan2(dy, dx); + angle = WWMath::Atan2(dy, dx); Real deltaAngle = angle - m_angle; - Real s = sin(deltaAngle); - Real c = cos(deltaAngle); + Real s = WWMath::Sin(deltaAngle); + Real c = WWMath::Cos(deltaAngle); Real x = m_groupOffset.x * c - m_groupOffset.y * s; Real y = m_groupOffset.y * c + m_groupOffset.x * s; m_groupOffset.x = x; m_groupOffset.y = y; } else { - angle = atan2(dy, dx); + angle = WWMath::Atan2(dy, dx); } m_angle = angle; #endif @@ -5078,7 +5078,7 @@ StateReturnType AIAttackAimAtTargetState::update() //DEBUG_LOG(("AIM: desired %f, actual %f, delta %f, aimDelta %f, goalpos %f %f",rad2deg(obj->getOrientation() + relAngle),rad2deg(obj->getOrientation()),rad2deg(relAngle),rad2deg(aimDelta),victim->getPosition()->x,victim->getPosition()->y)); if (m_canTurnInPlace) { - if (fabs(relAngle) > aimDelta) + if (WWMath::Fabs(relAngle) > aimDelta) { Real desiredAngle = source->getOrientation() + relAngle; sourceAI->setLocomotorGoalOrientation(desiredAngle); @@ -5090,7 +5090,7 @@ StateReturnType AIAttackAimAtTargetState::update() sourceAI->setLocomotorGoalPositionExplicit(m_isAttackingObject ? *victim->getPosition() : *getMachineGoalPosition()); } - if (fabs(relAngle) < aimDelta /*&& !m_preAttackFrames*/ ) + if (WWMath::Fabs(relAngle) < aimDelta /*&& !m_preAttackFrames*/ ) { AIUpdateInterface* victimAI = victim ? victim->getAI() : nullptr; // add ourself as a targeter BEFORE calling isTemporarilyPreventingAimSuccess(). @@ -7490,7 +7490,7 @@ StateReturnType AIFaceState::update() Real relAngle = ThePartitionManager->getRelativeAngle2D( obj, pos ); const Real REL_THRESH = 0.035f; // about 2 degrees. (getRelativeAngle2D is current only accurate to about 1.25 degrees) - if( fabs( relAngle ) < REL_THRESH ) + if( WWMath::Fabs( relAngle ) < REL_THRESH ) { return STATE_SUCCESS; } diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/TurretAI.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/TurretAI.cpp index 78395baf998..030a0a5c3be 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/TurretAI.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/TurretAI.cpp @@ -386,7 +386,7 @@ Bool TurretAI::friend_turnTowardsAngle(Real desiredAngle, Real rateModifier, Rea Real angleDiff = normalizeAngle(desiredAngle - actualAngle); // Are we close enough to the desired angle to just snap there? - if (fabs(angleDiff) < turnRate) + if (WWMath::Fabs(angleDiff) < turnRate) { // we are centered actualAngle = desiredAngle; @@ -409,7 +409,7 @@ Bool TurretAI::friend_turnTowardsAngle(Real desiredAngle, Real rateModifier, Rea if( m_angle != origAngle ) getOwner()->reactToTurretChange( m_whichTurret, origAngle, m_pitch ); - Bool aligned = fabs(m_angle - desiredAngle) <= relThresh; + Bool aligned = WWMath::Fabs(m_angle - desiredAngle) <= relThresh; return aligned; } @@ -427,7 +427,7 @@ Bool TurretAI::friend_turnTowardsPitch(Real desiredPitch, Real rateModifier) Real pitchRate = getPitchRate() * rateModifier; Real pitchDiff = normalizeAngle(desiredPitch - actualPitch); - if (fabs(pitchDiff) < pitchRate) + if (WWMath::Fabs(pitchDiff) < pitchRate) { // we are centered actualPitch = desiredPitch; @@ -1087,7 +1087,7 @@ StateReturnType TurretAIAimTurretState::update() turret->friend_setPositiveSweep(!turret->friend_getPositiveSweep()); Real angleDiff = normalizeAngle(relAngle - turret->getTurretAngle()); - turnAlignedToNemesis = (fabs(angleDiff) < sweep); + turnAlignedToNemesis = (WWMath::Fabs(angleDiff) < sweep); } Bool pitchAlignedToNemesis = true; diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Map/PolygonTrigger.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Map/PolygonTrigger.cpp index 4f19ee9cfc2..69791c9fd76 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Map/PolygonTrigger.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Map/PolygonTrigger.cpp @@ -286,7 +286,7 @@ void PolygonTrigger::updateBounds() const Real halfWidth = (m_bounds.hi.x - m_bounds.lo.x) / 2.0f; Real halfHeight = (m_bounds.hi.y + m_bounds.lo.y) / 2.0f; - m_radius = sqrt(halfHeight*halfHeight + halfWidth*halfWidth); + m_radius = WWMath::Sqrt(halfHeight*halfHeight + halfWidth*halfWidth); } diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Map/TerrainLogic.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Map/TerrainLogic.cpp index db2aa8d2200..be9c457352e 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Map/TerrainLogic.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Map/TerrainLogic.cpp @@ -1468,7 +1468,7 @@ void makeAlignToNormalMatrix( Real angle, const Coord3D& pos, const Coord3D& nor /* It is extremely important that the resulting matrix is such that the xvector points in the angle we specified; specifically, - that atan2(xvec.y, xvec.x) == angle. So we must construct + that WWMath::Atan2(xvec.y, xvec.x) == angle. So we must construct the matrix carefully to ensure this! */ x.x = Cos( angle ); @@ -1489,7 +1489,7 @@ void makeAlignToNormalMatrix( Real angle, const Coord3D& pos, const Coord3D& nor x.normalize(); } - DEBUG_ASSERTCRASH(fabs(x.x*z.x + x.y*z.y + x.z*z.z)<0.0001,("dot is not zero (%f)",fabs(x.x*z.x + x.y*z.y + x.z*z.z))); + DEBUG_ASSERTCRASH(WWMath::Fabs(x.x*z.x + x.y*z.y + x.z*z.z)<0.0001,("dot is not zero (%f)",WWMath::Fabs(x.x*z.x + x.y*z.y + x.z*z.z))); // now computing the y vector is trivial. y.crossProduct( z, x, y ); @@ -1685,12 +1685,12 @@ PathfindLayerEnum TerrainLogic::getLayerForDestination(const Coord3D *pos) { Bridge *pBridge = getFirstBridge(); PathfindLayerEnum bestLayer = LAYER_GROUND; - Real bestDistance = fabs(pos->z - getGroundHeight(pos->x, pos->y)); + Real bestDistance = WWMath::Fabs(pos->z - getGroundHeight(pos->x, pos->y)); if (bestDistance > TheAI->pathfinder()->getWallHeight()/2) { // check wall. if (TheAI->pathfinder()->isPointOnWall(pos)) { - Real delta = fabs(pos->z-TheAI->pathfinder()->getWallHeight()); + Real delta = WWMath::Fabs(pos->z-TheAI->pathfinder()->getWallHeight()); if (deltaisPointOnBridge(pos) ) { - Real delta = fabs(pos->z-pBridge->getBridgeHeight(pos, nullptr)); + Real delta = WWMath::Fabs(pos->z-pBridge->getBridgeHeight(pos, nullptr)); if (deltagetLayer(); bestDistance = delta; @@ -1724,7 +1724,7 @@ PathfindLayerEnum TerrainLogic::getHighestLayerForDestination(const Coord3D *pos if (TheAI->pathfinder()->isPointOnWall(pos)) { Real delta = pos->z - TheAI->pathfinder()->getWallHeight(); // must be ABOVE (or on) the wall for this call. (srj) - if (delta >= 0 && fabs(delta) < fabs(bestDistance)) { + if (delta >= 0 && WWMath::Fabs(delta) < WWMath::Fabs(bestDistance)) { bestLayer = (PathfindLayerEnum)LAYER_WALL; bestDistance = delta; } @@ -1739,7 +1739,7 @@ PathfindLayerEnum TerrainLogic::getHighestLayerForDestination(const Coord3D *pos if (pBridge->isPointOnBridge(pos) ) { Real delta = pos->z - pBridge->getBridgeHeight(pos, nullptr); // must be ABOVE (or on) the bridge for this call. (srj) - if (delta >= 0 && fabs(delta) < fabs(bestDistance)) { + if (delta >= 0 && WWMath::Fabs(delta) < WWMath::Fabs(bestDistance)) { bestLayer = pBridge->getLayer(); bestDistance = delta; } @@ -1788,7 +1788,7 @@ Bool TerrainLogic::objectInteractsWithBridgeLayer(Object *obj, Int layer, Bool c if (match) { Real bridgeHeight = pBridge->getBridgeHeight(obj->getPosition(), nullptr); - Real delta = fabs(obj->getPosition()->z-bridgeHeight); + Real delta = WWMath::Fabs(obj->getPosition()->z-bridgeHeight); if (delta>LAYER_Z_CLOSE_ENOUGH_F) { return false; } @@ -1837,7 +1837,7 @@ Bool TerrainLogic::objectInteractsWithBridgeEnd(Object *obj, Int layer) const if (match) { Real bridgeHeight = pBridge->getBridgeHeight(obj->getPosition(), nullptr); - Real delta = fabs(obj->getPosition()->z-bridgeHeight); + Real delta = WWMath::Fabs(obj->getPosition()->z-bridgeHeight); if (delta>LAYER_Z_CLOSE_ENOUGH_F) { return false; @@ -2055,10 +2055,10 @@ Coord3D TerrainLogic::findClosestEdgePoint ( const Coord3D *closestTo ) const getExtent( &mapExtent ); Real distances[4]; - distances[0] = fabs( closestTo->y - mapExtent.lo.y );//top - distances[1] = fabs( closestTo->x - mapExtent.hi.x );//right - distances[2] = fabs( closestTo->y - mapExtent.hi.y );//bottom - distances[3] = fabs( closestTo->x - mapExtent.lo.x );//left + distances[0] = WWMath::Fabs( closestTo->y - mapExtent.lo.y );//top + distances[1] = WWMath::Fabs( closestTo->x - mapExtent.hi.x );//right + distances[2] = WWMath::Fabs( closestTo->y - mapExtent.hi.y );//bottom + distances[3] = WWMath::Fabs( closestTo->x - mapExtent.lo.x );//left Real bestDistance = distances[0]; Int bestDistanceIndex = 0; for( Int lameIndex = 1; lameIndex < 4; lameIndex++ ) @@ -2369,7 +2369,7 @@ void TerrainLogic::setWaterHeight( const WaterHandle *water, Real height, Real d center.z = 0.0f; // irrelevant // the max radius to scan around us is the diagonal of the bounding region - Real maxDist = sqrt( affectedRegion.width() * affectedRegion.width() + + Real maxDist = WWMath::Sqrt( affectedRegion.width() * affectedRegion.width() + affectedRegion.height() * affectedRegion.height() ); // scan the objects in the area of the water affected @@ -2879,7 +2879,7 @@ void TerrainLogic::createCraterInTerrain(Object *obj) deltaX = ( i * MAP_XY_FACTOR ) - pos->x; deltaY = ( j * MAP_XY_FACTOR ) - pos->y; - Real distance = sqrt( sqr( deltaX ) + sqr( deltaY ) ); + Real distance = WWMath::Sqrt( sqr( deltaX ) + sqr( deltaY ) ); if ( distance < radius ) //inside circle { diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/DumbProjectileBehavior.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/DumbProjectileBehavior.cpp index 9b782240938..c4aa9f0ff0a 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/DumbProjectileBehavior.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/DumbProjectileBehavior.cpp @@ -172,24 +172,24 @@ static Bool calcTrajectory( Real dz = end.z - start.z; // calculating the angle is trivial. - angle = atan2(dy, dx); + angle = WWMath::Atan2(dy, dx); // calculating the pitch requires a bit more effort. Real horizDistSqr = sqr(dx) + sqr(dy); - Real horizDist = sqrt(horizDistSqr); + Real horizDist = WWMath::Sqrt(horizDistSqr); // calc the two possible pitches that will cover the given horizontal range. // (this is actually only true if dz==0, but is a good first guess) - Real gravity = fabs(TheGlobalData->m_gravity); + Real gravity = WWMath::Fabs(TheGlobalData->m_gravity); Real gravityTwoDZ = gravity * 2.0f * dz; // let's start by aiming directly for it. we know this isn't right (unless gravity // is zero, which it's not) but is a good starting point... - Real theta = atan2(dz, horizDist); + Real theta = WWMath::Atan2(dz, horizDist); // if the angle isn't pretty shallow, we can get a better initial guess by using // the code below... const Real SHALLOW_ANGLE = 0.5f * PI / 180.0f; - if (fabs(theta) > SHALLOW_ANGLE) + if (WWMath::Fabs(theta) > SHALLOW_ANGLE) { Real t = horizDist / velocity; Real vz = (dz/t + 0.5f*gravity*t); @@ -290,7 +290,7 @@ static Bool calcTrajectory( #endif vx = velocity*cosPitches[preferred]; - Real actualRange = (vx*(vz + sqrt(root)))/gravity; + Real actualRange = (vx*(vz + WWMath::Sqrt(root)))/gravity; const Real CLOSE_ENOUGH_RANGE = 5.0f; if (tooClose || (actualRange < horizDist - CLOSE_ENOUGH_RANGE)) { @@ -369,7 +369,7 @@ void DumbProjectileBehavior::projectileFireAtObjectOrPosition( const Object *vic // Some weapons want to scale their start speed to the range Real minRange = detWeap->getMinimumAttackRange(); Real maxRange = detWeap->getUnmodifiedAttackRange(); - Real range = sqrt(ThePartitionManager->getDistanceSquared( projectile, &victimPosToUse, FROM_CENTER_2D ) ); + Real range = WWMath::Sqrt(ThePartitionManager->getDistanceSquared( projectile, &victimPosToUse, FROM_CENTER_2D ) ); Real rangeRatio = (range - minRange) / (maxRange - minRange); m_flightPathSpeed = (rangeRatio * (weaponSpeed - minWeaponSpeed)) + minWeaponSpeed; } @@ -444,7 +444,7 @@ Bool DumbProjectileBehavior::calcFlightPath(Bool recalcNumSegments) if (recalcNumSegments) { Real flightDistance = flightCurve.getApproximateLength(); - m_flightPathSegments = ceil( flightDistance / m_flightPathSpeed ); + m_flightPathSegments = WWMath::Ceil( flightDistance / m_flightPathSpeed ); } // TheSuperHackers @info The way flight paths are used requires at least two curve points. @@ -611,7 +611,7 @@ UpdateSleepTime DumbProjectileBehavior::update() Real distVictimMovedSqr = sqr(delta.x) + sqr(delta.y) + sqr(delta.z); if (distVictimMovedSqr > 0.1f) { - Real distVictimMoved = sqrtf(distVictimMovedSqr); + Real distVictimMoved = WWMath::Sqrtf(distVictimMovedSqr); if (distVictimMoved > d->m_flightPathAdjustDistPerFrame) distVictimMoved = d->m_flightPathAdjustDistPerFrame; delta.normalize(); diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/GenerateMinefieldBehavior.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/GenerateMinefieldBehavior.cpp index 03194dc1981..32ceef36a87 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/GenerateMinefieldBehavior.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/GenerateMinefieldBehavior.cpp @@ -248,7 +248,7 @@ void GenerateMinefieldBehavior::placeMinesAlongLine(const Coord3D& posStart, con Real dx = posEnd.x - posStart.x; Real dy = posEnd.y - posStart.y; - Real len = sqrt(sqr(dx) + sqr(dy)); + Real len = WWMath::Sqrt(sqr(dx) + sqr(dy)); Real mineRadius = mineTemplate->getTemplateGeometryInfo().getBoundingCircleRadius(); Real mineDiameter = mineRadius * 2.0f; Real mineJitter = mineRadius*d->m_randomJitter; diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/MinefieldBehavior.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/MinefieldBehavior.cpp index 7bdecb3be0d..629e25c45a6 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/MinefieldBehavior.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/MinefieldBehavior.cpp @@ -570,7 +570,7 @@ void MinefieldBehavior::setScootParms(const Coord3D& start, const Coord3D& end) if (start.z > endOnGround.z) { // figure out how long it will take to fall, and replace scoot time with that - UnsignedInt fallingTime = REAL_TO_INT_CEIL(sqrtf(2.0f * (start.z - endOnGround.z) / fabs(TheGlobalData->m_gravity))); + UnsignedInt fallingTime = REAL_TO_INT_CEIL(WWMath::Sqrtf(2.0f * (start.z - endOnGround.z) / WWMath::Fabs(TheGlobalData->m_gravity))); // we can scoot after we land, but don't want to stop scooting before we land if (scootFromStartingPointTime < fallingTime) scootFromStartingPointTime = fallingTime; @@ -588,8 +588,8 @@ void MinefieldBehavior::setScootParms(const Coord3D& start, const Coord3D& end) Real dx = endOnGround.x - start.x; Real dy = endOnGround.y - start.y; Real dz = endOnGround.z - start.z; - Real dist = sqrt(sqr(dx) + sqr(dy)); - if (dist <= 0.1f && fabs(dz) <= 0.1f) + Real dist = WWMath::Sqrt(sqr(dx) + sqr(dy)); + if (dist <= 0.1f && WWMath::Fabs(dz) <= 0.1f) { obj->setPosition(&endOnGround); m_scootFramesLeft = 0; @@ -598,7 +598,7 @@ void MinefieldBehavior::setScootParms(const Coord3D& start, const Coord3D& end) { Real t = (Real)scootFromStartingPointTime; Real scootFromStartingPointSpeed = dist / t; - Real accelMag = fabs(2.0f * (dist - scootFromStartingPointSpeed*t)/sqr(t)); + Real accelMag = WWMath::Fabs(2.0f * (dist - scootFromStartingPointSpeed*t)/sqr(t)); Real dxNorm = (dist <= 0.1f) ? 0.0f : (dx / dist); Real dyNorm = (dist <= 0.1f) ? 0.0f : (dy / dist); m_scootVel.x = dxNorm * scootFromStartingPointSpeed; diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/SlowDeathBehavior.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/SlowDeathBehavior.cpp index f2942322f9a..90fa97a5a29 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/SlowDeathBehavior.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/SlowDeathBehavior.cpp @@ -299,7 +299,7 @@ void SlowDeathBehavior::beginSlowDeath(const DamageInfo *damageInfo) physics->setExtraBounciness(-1.0); // we don't want this guy to bounce at all physics->setExtraFriction(-3 * SECONDS_PER_LOGICFRAME_REAL); // reduce his ground friction a bit physics->setAllowBouncing(true); - Real orientation = atan2(force.y, force.x); + Real orientation = WWMath::Atan2(force.y, force.x); physics->setAngles(orientation, 0, 0); obj->getDrawable()->setModelConditionState(MODELCONDITION_EXPLODED_FLAILING); m_flags |= (1<getPosition()->z) >= d->m_paraOpenDist) + if (WWMath::Fabs(m_startZ - parachute->getPosition()->z) >= d->m_paraOpenDist) { m_opened = true; parachute->clearAndSetModelConditionState(MODELCONDITION_FREEFALL, MODELCONDITION_PARACHUTING); diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp index 57392ff6db5..f3d9595a94a 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp @@ -84,7 +84,7 @@ static Real calcSlowDownDist(Real curSpeed, Real desiredSpeed, Real maxBraking) if (delta <= 0) return 0.0f; - Real dist = (sqr(delta) / fabs(maxBraking)) * 0.5f; + Real dist = (sqr(delta) / WWMath::Fabs(maxBraking)) * 0.5f; // use a little fudge so that things can stop "on a dime" more easily... const Real FUDGE = 1.05f; @@ -95,14 +95,14 @@ static Real calcSlowDownDist(Real curSpeed, Real desiredSpeed, Real maxBraking) inline Bool isNearlyZero(Real a) { const Real TINY_EPSILON = 0.001f; - return fabs(a) < TINY_EPSILON; + return WWMath::Fabs(a) < TINY_EPSILON; } //----------------------------------------------------------------------------- inline Bool isNearly(Real a, Real val) { const Real TINY_EPSILON = 0.001f; - return fabs(a - val) < TINY_EPSILON; + return WWMath::Fabs(a - val) < TINY_EPSILON; } //----------------------------------------------------------------------------- @@ -141,7 +141,7 @@ static Real tryToRotateVector3D( } } - if (fabs(angleBetween) <= maxAngle) + if (WWMath::Fabs(angleBetween) <= maxAngle) { // close enough actualDir = goalDir; @@ -231,9 +231,9 @@ static void calcDirectionToApplyThrust( Bool foundSolution = false; Real distToGoalSqr = vecToGoal.Length2(); - Real distToGoal = sqrt(distToGoalSqr); + Real distToGoal = WWMath::Sqrt(distToGoalSqr); Real curVelMagSqr = curVel.Length2(); - Real curVelMag = sqrt(curVelMagSqr); + Real curVelMag = WWMath::Sqrt(curVelMagSqr); Real maxAccelSqr = sqr(maxAccel); Real denom = curVelMagSqr - maxAccelSqr; @@ -995,7 +995,7 @@ void Locomotor::locoUpdate_moveTowardsPosition(Object* obj, const Coord3D& goalP Real dx = goalPos.x - obj->getPosition()->x; Real dy = goalPos.y - obj->getPosition()->y; Real dz = goalPos.z - obj->getPosition()->z; - Real dist = sqrt(dx*dx+dy*dy); + Real dist = WWMath::Sqrt(dx*dx+dy*dy); if (dist>onPathDistToGoal) { if (!obj->isKindOf(KINDOF_PROJECTILE) && dist>2*onPathDistToGoal) @@ -1113,7 +1113,7 @@ void Locomotor::locoUpdate_moveTowardsPosition(Object* obj, const Coord3D& goalP // Projectiles never stop braking once they start. jba. obj->setStatus( MAKE_OBJECT_STATUS_MASK( OBJECT_STATUS_BRAKING ) ); // Projectiles cheat in 3 dimensions. - dist = sqrt(dx*dx+dy*dy+dz*dz); + dist = WWMath::Sqrt(dx*dx+dy*dy+dz*dz); Real vel = physics->getVelocityMagnitude(); if (vel < MIN_VEL) vel = MIN_VEL; @@ -1137,7 +1137,7 @@ void Locomotor::locoUpdate_moveTowardsPosition(Object* obj, const Coord3D& goalP // Normalize. if (dist > 0.001f) { - Real vel = fabs(physics->getForwardSpeed2D()); + Real vel = WWMath::Fabs(physics->getForwardSpeed2D()); if (vel < MIN_VEL) vel = MIN_VEL; if (vel > dist) @@ -1182,7 +1182,7 @@ void Locomotor::moveTowardsPositionTreads(Object* obj, PhysicsBehavior *physics, // Modulate speed according to turning. The more we have to turn, the slower we go // const Real QUAETERPI = PI / 4.0f; - Real angleCoeff = (Real)fabs( relAngle ) / QUAETERPI; + Real angleCoeff = (Real)WWMath::Fabs( relAngle ) / QUAETERPI; if (angleCoeff > 1.0f) angleCoeff = 1.0; @@ -1253,7 +1253,7 @@ void Locomotor::moveTowardsPositionTreads(Object* obj, PhysicsBehavior *physics, see how much force we really need to achieve our goal speed... */ Real maxForceNeeded = mass * speedDelta; - if (fabs(accelForce) > fabs(maxForceNeeded)) + if (WWMath::Fabs(accelForce) > WWMath::Fabs(maxForceNeeded)) accelForce = maxForceNeeded; const Coord3D *dir = obj->getUnitDirectionVector2D(); @@ -1288,7 +1288,7 @@ void Locomotor::moveTowardsPositionWheels(Object* obj, PhysicsBehavior *physics, Real angle = obj->getOrientation(); // Real relAngle = ThePartitionManager->getRelativeAngle2D( obj, &goalPos ); // Real desiredAngle = angle + relAngle; - Real desiredAngle = atan2(goalPos.y - obj->getPosition()->y, goalPos.x - obj->getPosition()->x); + Real desiredAngle = WWMath::Atan2(goalPos.y - obj->getPosition()->y, goalPos.x - obj->getPosition()->x); Real relAngle = stdAngleDiff(desiredAngle, angle); Bool moveBackwards = false; @@ -1305,14 +1305,14 @@ void Locomotor::moveTowardsPositionWheels(Object* obj, PhysicsBehavior *physics, #if 1 if (actualSpeed==0.0f) { setFlag(MOVING_BACKWARDS, false); - if (m_template->m_canMoveBackward && fabs(relAngle) > PI/2) { + if (m_template->m_canMoveBackward && WWMath::Fabs(relAngle) > PI/2) { setFlag(MOVING_BACKWARDS, true ); setFlag(DOING_THREE_POINT_TURN, onPathDistToGoal>5*obj->getGeometryInfo().getMajorRadius()); } } if (getFlag(MOVING_BACKWARDS)) { - if (fabs(relAngle) < PI/2) { + if (WWMath::Fabs(relAngle) < PI/2) { moveBackwards = false; setFlag(MOVING_BACKWARDS, false); } else { @@ -1328,7 +1328,7 @@ void Locomotor::moveTowardsPositionWheels(Object* obj, PhysicsBehavior *physics, #endif const Real SMALL_TURN = PI / 20.0f; - if ((Real)fabs( relAngle ) > SMALL_TURN) + if ((Real)WWMath::Fabs( relAngle ) > SMALL_TURN) { if (desiredSpeed>turnSpeed) { @@ -1353,7 +1353,7 @@ void Locomotor::moveTowardsPositionWheels(Object* obj, PhysicsBehavior *physics, const Real FIFTEEN_DEGREES = PI / 12.0f; const Real PROJECT_FRAMES = LOGICFRAMES_PER_SECOND/2; // Project out 1/2 second. - if (fabs( relAngle ) > FIFTEEN_DEGREES) + if (WWMath::Fabs( relAngle ) > FIFTEEN_DEGREES) { // If we're turning more than 10 degrees, check & see if we're moving into "impassable territory" Real distance = PROJECT_FRAMES * (goalSpeed+actualSpeed)/2.0f; @@ -1492,7 +1492,7 @@ void Locomotor::moveTowardsPositionWheels(Object* obj, PhysicsBehavior *physics, see how much force we really need to achieve our goal speed... */ Real maxForceNeeded = mass * speedDelta; - if (fabs(accelForce) > fabs(maxForceNeeded)) + if (WWMath::Fabs(accelForce) > WWMath::Fabs(maxForceNeeded)) accelForce = maxForceNeeded; //DEBUG_LOG(("Braking %d, actualSpeed %f, goalSpeed %f, delta %f, accel %f", getFlag(IS_BRAKING), @@ -1563,7 +1563,7 @@ Bool Locomotor::fixInvalidPosition(Object* obj, PhysicsBehavior *physics) //physics->clearAcceleration(); if (dot<0) { - dot = sqrt(-dot); + dot = WWMath::Sqrt(-dot); correctionNormalized.x *= dot*physics->getMass(); correctionNormalized.y *= dot*physics->getMass(); physics->applyMotiveForce(&correctionNormalized); @@ -1627,7 +1627,7 @@ void Locomotor::moveTowardsPositionLegs(Object* obj, PhysicsBehavior *physics, c Real angle = obj->getOrientation(); // Real relAngle = ThePartitionManager->getRelativeAngle2D( obj, &goalPos ); // Real desiredAngle = angle + relAngle; - Real desiredAngle = atan2(goalPos.y - obj->getPosition()->y, goalPos.x - obj->getPosition()->x); + Real desiredAngle = WWMath::Atan2(goalPos.y - obj->getPosition()->y, goalPos.x - obj->getPosition()->x); if (m_template->m_wanderWidthFactor != 0.0f) { Real angleLimit = PI/8 * m_template->m_wanderWidthFactor; @@ -1653,7 +1653,7 @@ void Locomotor::moveTowardsPositionLegs(Object* obj, PhysicsBehavior *physics, c // Modulate speed according to turning. The more we have to turn, the slower we go // const Real QUARTERPI = PI / 4.0f; - Real angleCoeff = (Real)fabs( relAngle ) / (QUARTERPI); + Real angleCoeff = (Real)WWMath::Fabs( relAngle ) / (QUARTERPI); if (angleCoeff > 1.0f) angleCoeff = 1.0; @@ -1683,7 +1683,7 @@ void Locomotor::moveTowardsPositionLegs(Object* obj, PhysicsBehavior *physics, c see how much force we really need to achieve our goal speed... */ Real maxForceNeeded = mass * speedDelta; - if (fabs(accelForce) > fabs(maxForceNeeded)) + if (WWMath::Fabs(accelForce) > WWMath::Fabs(maxForceNeeded)) accelForce = maxForceNeeded; const Coord3D *dir = obj->getUnitDirectionVector2D(); @@ -1725,7 +1725,7 @@ void Locomotor::moveTowardsPositionClimb(Object* obj, PhysicsBehavior *physics, if (dz*dz > sqr(PATHFIND_CELL_SIZE_F)) { setFlag(CLIMBING, true); } - if (fabs(dz)<1) { + if (WWMath::Fabs(dz)<1) { setFlag(CLIMBING, false); } @@ -1745,7 +1745,7 @@ void Locomotor::moveTowardsPositionClimb(Object* obj, PhysicsBehavior *physics, moveBackwards = true; } - Real groundSlope = fabs(delta.z - pos.z); + Real groundSlope = WWMath::Fabs(delta.z - pos.z); if (groundSlope<1.0f) groundSlope = 1.0f; if (groundSlope>1.0f) { @@ -1760,7 +1760,7 @@ void Locomotor::moveTowardsPositionClimb(Object* obj, PhysicsBehavior *physics, Real angle = obj->getOrientation(); // Real relAngle = ThePartitionManager->getRelativeAngle2D( obj, &goalPos ); // Real desiredAngle = angle + relAngle; - Real desiredAngle = atan2(goalPos.y - obj->getPosition()->y, goalPos.x - obj->getPosition()->x); + Real desiredAngle = WWMath::Atan2(goalPos.y - obj->getPosition()->y, goalPos.x - obj->getPosition()->x); Real relAngle = stdAngleDiff(desiredAngle, angle); if (moveBackwards) { @@ -1774,7 +1774,7 @@ void Locomotor::moveTowardsPositionClimb(Object* obj, PhysicsBehavior *physics, // Modulate speed according to turning. The more we have to turn, the slower we go // const Real QUARTERPI = PI / 4.0f; - Real angleCoeff = (Real)fabs( relAngle ) / (QUARTERPI); + Real angleCoeff = (Real)WWMath::Fabs( relAngle ) / (QUARTERPI); if (angleCoeff > 1.0f) angleCoeff = 1.0; @@ -1816,7 +1816,7 @@ void Locomotor::moveTowardsPositionClimb(Object* obj, PhysicsBehavior *physics, see how much force we really need to achieve our goal speed... */ Real maxForceNeeded = mass * speedDelta; - if (fabs(accelForce) > fabs(maxForceNeeded)) + if (WWMath::Fabs(accelForce) > WWMath::Fabs(maxForceNeeded)) accelForce = maxForceNeeded; const Coord3D *dir = obj->getUnitDirectionVector2D(); @@ -1843,7 +1843,7 @@ void Locomotor::moveTowardsPositionWings(Object* obj, PhysicsBehavior *physics, Real dx = goalPos.x - pos->x; Real dy = goalPos.y - pos->y; Real dz = goalPos.z - pos->z; - if (fabs(dz) > m_circleThresh) + if (WWMath::Fabs(dz) > m_circleThresh) { // aim for the spot on the opposite side of the circle. @@ -1851,7 +1851,7 @@ void Locomotor::moveTowardsPositionWings(Object* obj, PhysicsBehavior *physics, Real angleTowardPos = (isNearlyZero(dx) && isNearlyZero(dy)) ? obj->getOrientation() : - atan2(dy, dx); + WWMath::Atan2(dy, dx); Real aimDir = (PI - PI/8); angleTowardPos += aimDir; @@ -1940,7 +1940,7 @@ void Locomotor::moveTowardsPositionThrust(Object* obj, PhysicsBehavior *physics, // so we tend to "level out" at that height. we don't use this till // below, but go ahead and calc it now... Real MAX_VERTICAL_DAMP_RANGE = m_preferredHeight * 0.5; - delta = fabs(delta); + delta = WWMath::Fabs(delta); if (delta > MAX_VERTICAL_DAMP_RANGE) delta = MAX_VERTICAL_DAMP_RANGE; zDirDamping = 1.0f - (delta / MAX_VERTICAL_DAMP_RANGE); @@ -2057,7 +2057,7 @@ Real Locomotor::calcLiftToUseAtPt(Object* obj, PhysicsBehavior *physics, Real cu // see how far we need to slow to dead stop, given max braking Real desiredAccel; const Real TINY_ACCEL = 0.001f; - if (fabs(maxAccel) > TINY_ACCEL) + if (WWMath::Fabs(maxAccel) > TINY_ACCEL) { Real deltaZ = preferredHeight - curZ; // calc how far it will take for us to go from cur speed to zero speed, at max accel. @@ -2065,14 +2065,14 @@ Real Locomotor::calcLiftToUseAtPt(Object* obj, PhysicsBehavior *physics, Real cu // in theory, the above is the correct calculation, but in practice, // doesn't work in some situations (eg, opening of USA01 map). Why, I dunno. // But for now I have gone back to the old, looks-incorrect-to-me-but-works calc. (srj) - Real brakeDist = (sqr(curVelZ) / fabs(maxAccel)); - if (fabs(brakeDist) > fabs(deltaZ)) + Real brakeDist = (sqr(curVelZ) / WWMath::Fabs(maxAccel)); + if (WWMath::Fabs(brakeDist) > WWMath::Fabs(deltaZ)) { // if the dist-to-accel (or dist-to-brake) is further than the dist-to-go, // use the max accel. desiredAccel = maxAccel; } - else if (fabs(curVelZ) > m_template->m_speedLimitZ) + else if (WWMath::Fabs(curVelZ) > m_template->m_speedLimitZ) { // or, if we're going too fast, limit it here. desiredAccel = m_template->m_speedLimitZ - curVelZ; @@ -2146,8 +2146,8 @@ PhysicsTurningType Locomotor::rotateObjAroundLocoPivot(Object* obj, const Coord3 Real dx =goalPos.x - turnPos.x; Real dy = goalPos.y - turnPos.y; // If we are very close to the goal, we twitch due to rounding error. So just return. jba. - if (fabs(dx)<0.1f && fabs(dy)<0.1f) return TURN_NONE; - Real desiredAngle = atan2(dy, dx); + if (WWMath::Fabs(dx)<0.1f && WWMath::Fabs(dy)<0.1f) return TURN_NONE; + Real desiredAngle = WWMath::Atan2(dy, dx); Real amount = stdAngleDiff(desiredAngle, angle); if (relAngle) *relAngle = amount; if (amount>maxTurnRate) { @@ -2169,7 +2169,7 @@ PhysicsTurningType Locomotor::rotateObjAroundLocoPivot(Object* obj, const Coord3 // so, the thing is, we want to rotate ourselves so that our *center* is rotated // by the given amount, but the rotation must be around turnPos. so do a little // back-calculation. - Real angleDesiredForTurnPos = atan2(desiredPos.y - turnPos.y, desiredPos.x - turnPos.x); + Real angleDesiredForTurnPos = WWMath::Atan2(desiredPos.y - turnPos.y, desiredPos.x - turnPos.x); amount = angleDesiredForTurnPos - angle; #endif /// @todo srj -- there's probably a more efficient & more direct way to do this. find it. @@ -2185,7 +2185,7 @@ PhysicsTurningType Locomotor::rotateObjAroundLocoPivot(Object* obj, const Coord3 } else { - Real desiredAngle = atan2(goalPos.y - obj->getPosition()->y, goalPos.x - obj->getPosition()->x); + Real desiredAngle = WWMath::Atan2(goalPos.y - obj->getPosition()->y, goalPos.x - obj->getPosition()->x); Real amount = stdAngleDiff(desiredAngle, angle); if (relAngle) *relAngle = amount; if (amount>maxTurnRate) { @@ -2363,8 +2363,8 @@ void Locomotor::moveTowardsPositionOther(Object* obj, PhysicsBehavior *physics, //fabs(goalPos.y - pos->y),fabs(goalPos.x - pos->x), //fabs(goalPos.y - pos->y)/goalSpeed,fabs(goalPos.x - pos->x)/goalSpeed)); if (getFlag(ULTRA_ACCURATE) && - fabs(goalPos.y - pos->y) <= goalSpeed * m_template->m_ultraAccurateSlideIntoPlaceFactor && - fabs(goalPos.x - pos->x) <= goalSpeed * m_template->m_ultraAccurateSlideIntoPlaceFactor) + WWMath::Fabs(goalPos.y - pos->y) <= goalSpeed * m_template->m_ultraAccurateSlideIntoPlaceFactor && + WWMath::Fabs(goalPos.x - pos->x) <= goalSpeed * m_template->m_ultraAccurateSlideIntoPlaceFactor) { // don't turn, just slide in the right direction physics->setTurning(TURN_NONE); @@ -2403,7 +2403,7 @@ void Locomotor::moveTowardsPositionOther(Object* obj, PhysicsBehavior *physics, see how much force we really need to achieve our goal speed... */ Real maxForceNeeded = mass * speedDelta; - if (fabs(accelForce) > fabs(maxForceNeeded)) + if (WWMath::Fabs(accelForce) > WWMath::Fabs(maxForceNeeded)) accelForce = maxForceNeeded; Coord3D force; @@ -2519,7 +2519,7 @@ void Locomotor::maintainCurrentPositionWings(Object* obj, PhysicsBehavior *physi Real angleTowardMaintainPos = (isNearlyZero(dx) && isNearlyZero(dy)) ? obj->getOrientation() : - atan2(dy, dx); + WWMath::Atan2(dy, dx); Real aimDir = (PI - PI/8); if (turnRadius < 0) @@ -2553,7 +2553,7 @@ void Locomotor::maintainCurrentPositionHover(Object* obj, PhysicsBehavior *physi // Real minSpeed = max( 1.0E-10f, m_template->m_minSpeed ); Real speedDelta = minSpeed - actualSpeed; - if (fabs(speedDelta) > minSpeed) + if (WWMath::Fabs(speedDelta) > minSpeed) { Real mass = physics->getMass(); Real acceleration = (speedDelta > 0.0f) ? maxAcceleration : -getBraking(); @@ -2564,7 +2564,7 @@ void Locomotor::maintainCurrentPositionHover(Object* obj, PhysicsBehavior *physi see how much force we really need to achieve our goal speed... */ Real maxForceNeeded = mass * speedDelta; - if (fabs(accelForce) > fabs(maxForceNeeded)) + if (WWMath::Fabs(accelForce) > WWMath::Fabs(maxForceNeeded)) accelForce = maxForceNeeded; const Coord3D *dir = obj->getUnitDirectionVector2D(); diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp index 0bd898aae75..0fac8dad145 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp @@ -1798,13 +1798,13 @@ inline Bool isPosDifferent(const Coord3D* a, const Coord3D* b) // so we must put in some cleverness... const Real THRESH = 0.01f; - if (fabs(a->x - b->x) > THRESH) + if (WWMath::Fabs(a->x - b->x) > THRESH) return true; - if (fabs(a->y - b->y) > THRESH) + if (WWMath::Fabs(a->y - b->y) > THRESH) return true; - if (fabs(a->z - b->z) > THRESH) + if (WWMath::Fabs(a->z - b->z) > THRESH) return true; return false; @@ -1820,7 +1820,7 @@ inline Bool isAngleDifferent(Real a, Real b) const Real THRESH = 0.01f; // in radians, this is approx 1/2 degree. - if (fabs(a - b) > THRESH) + if (WWMath::Fabs(a - b) > THRESH) return true; return false; diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/ObjectCreationList.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/ObjectCreationList.cpp index 175ca7e2375..b72f009d215 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/ObjectCreationList.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/ObjectCreationList.cpp @@ -290,7 +290,7 @@ class DeliverPayloadNugget : public ObjectCreationNugget Real dy = primary->y - secondary->y; //Calc length - Real length = sqrt( dx*dx + dy*dy ); + Real length = WWMath::Sqrt( dx*dx + dy*dy ); //Normalize length dx /= length; @@ -357,7 +357,7 @@ class DeliverPayloadNugget : public ObjectCreationNugget } - Real orient = atan2( moveToPos.y - startPos.y, moveToPos.x - startPos.x); + Real orient = WWMath::Atan2( moveToPos.y - startPos.y, moveToPos.x - startPos.x); if( m_data.m_distToTarget > 0 ) { const Real SLOP = 1.5f; @@ -1108,7 +1108,7 @@ class GenericObjectCreationNugget : public ObjectCreationNugget objUp->applyForce(&force); if (m_orientInForceDirection) - orientation = atan2(force.y, force.x); + orientation = WWMath::Atan2(force.y, force.x); } } @@ -1196,7 +1196,7 @@ class GenericObjectCreationNugget : public ObjectCreationNugget objUp->applyForce(&force); if (m_orientInForceDirection) { - orientation = atan2(force.y, force.x); + orientation = WWMath::Atan2(force.y, force.x); } DUMPREAL(orientation); objUp->setAngles(orientation, 0, 0); diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cpp index a5f0a55128c..cb9574c239e 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cpp @@ -415,13 +415,13 @@ static void testRotatedPointsAgainstRect( Real pty = pts->y - a->position.y; // inverse-rotate it to the right coord system - Real ptx_new = (Real)fabs(ptx*c - pty*s); - Real pty_new = (Real)fabs(ptx*s + pty*c); + Real ptx_new = (Real)WWMath::Fabs(ptx*c - pty*s); + Real pty_new = (Real)WWMath::Fabs(ptx*s + pty*c); #ifdef INTENSE_DEBUG Real mag_a = sqr(ptx)+sqr(pty); Real mag_b = sqr(ptx_new)+sqr(pty_new); - DEBUG_ASSERTCRASH(fabs(mag_a - mag_b) <= 1.0, ("hmm, unlikely")); + DEBUG_ASSERTCRASH(WWMath::Fabs(mag_a - mag_b) <= 1.0, ("hmm, unlikely")); #endif if (ptx_new <= major && pty_new <= minor) @@ -621,7 +621,7 @@ inline Bool z_collideTest_Sphere_Nonsphere(CollideTestProc xyproc, const Collide // find the radius of the slice of the sphere that is at b_bot CollideInfo amod = *a; amod.position.z = b_bot; - amod.geom.setMajorRadius((Real)sqrtf(sqr(a->geom.getMajorRadius()) - sqr(b_bot - a->position.z))); + amod.geom.setMajorRadius((Real)WWMath::Sqrtf(sqr(a->geom.getMajorRadius()) - sqr(b_bot - a->position.z))); if (xyproc(&amod, b, cinfo)) { // if you want to have 'end' collisions, you should add something like: @@ -639,7 +639,7 @@ inline Bool z_collideTest_Sphere_Nonsphere(CollideTestProc xyproc, const Collide { CollideInfo amod = *a; amod.position.z = b_top; - amod.geom.setMajorRadius((Real)sqrtf(sqr(a->geom.getMajorRadius()) - sqr(a->position.z - b_top))); + amod.geom.setMajorRadius((Real)WWMath::Sqrtf(sqr(a->geom.getMajorRadius()) - sqr(a->position.z - b_top))); if (xyproc(&amod, b, cinfo)) { // if you want to have 'end' collisions, you should add something like: @@ -827,7 +827,7 @@ static Bool distCalcProc_BoundaryAndBoundary_2D( if (totalRad > 0.0f) { - Real actualDist = sqrtf(actualDistSqr); + Real actualDist = WWMath::Sqrtf(actualDistSqr); Real shrunkenDist = actualDist - totalRad; if (shrunkenDist <= 0.0f) { @@ -915,7 +915,7 @@ static Bool distCalcProc_BoundaryAndBoundary_3D( Real totalRad = (geomA?geomA->getBoundingSphereRadius():0) + (geomB?geomB->getBoundingSphereRadius():0); if (totalRad > 0.0f) { - Real actualDist = sqrtf(actualDistSqr); + Real actualDist = WWMath::Sqrtf(actualDistSqr); Real shrunkenDist = actualDist - totalRad; if (shrunkenDist <= 0.0f) { @@ -2226,7 +2226,7 @@ Int PartitionData::calcMaxCoiForShape(GeometryType geom, Real majorRadius, Real } case GEOMETRY_BOX: { - Real diagonal = (Real)(sqrtf(majorRadius*majorRadius + minorRadius*minorRadius)); + Real diagonal = (Real)(WWMath::Sqrtf(majorRadius*majorRadius + minorRadius*minorRadius)); Int cells = ThePartitionManager->worldToCellDist(diagonal*2) + 1; result = cells * cells; break; @@ -2643,7 +2643,7 @@ static void calcHeights(const Region3D& world, Real cellSize, Int x, Int y, Real Real xbase = world.lo.x + (x * cellSize); Real ybase = world.lo.y + (y * cellSize); const Real ROUGH_STEP_SIZE = MAP_XY_FACTOR; // no point in stepping smaller than grid scale - Real numSteps = ceilf(cellSize / ROUGH_STEP_SIZE); + Real numSteps = WWMath::Ceilf(cellSize / ROUGH_STEP_SIZE); Real step = cellSize / numSteps; loZ = HUGE_DIST; // huge positive hiZ = -HUGE_DIST; // huge negative @@ -3217,7 +3217,7 @@ Int PartitionManager::calcMinRadius(const ICoord2D& cur) } // double, not real - double dist = sqrtf(minDistSqr); + double dist = WWMath::Sqrtf(minDistSqr); Int minRadius = REAL_TO_INT_CEIL( dist / m_cellSize ); return minRadius; @@ -3235,7 +3235,7 @@ void PartitionManager::calcRadiusVec() // double, not real double dx = (double)cx * (double)cellSize; double dy = (double)cy * (double)cellSize; - double maxPossibleDist = sqrt(dx*dx + dy*dy); + double maxPossibleDist = WWMath::Sqrt(dx*dx + dy*dy); m_maxGcoRadius = REAL_TO_INT_CEIL(maxPossibleDist / cellSize); @@ -3505,7 +3505,7 @@ Object *PartitionManager::getClosestObjects( } if (closestDistArg) { - *closestDistArg = (Real)sqrtf(closestDistSqr); + *closestDistArg = (Real)WWMath::Sqrtf(closestDistSqr); } #ifdef RTS_DEBUG @@ -3632,7 +3632,7 @@ Real PartitionManager::getRelativeAngle2D( const Object *obj, const Coord3D *pos v.y = pos->y - objPos.y; v.z = 0.0f; - Real dist = (Real)sqrtf(sqr(v.x) + sqr(v.y)); + Real dist = (Real)WWMath::Sqrtf(sqr(v.x) + sqr(v.y)); // normalize if (dist == 0.0f) @@ -3810,7 +3810,7 @@ Bool PartitionManager::tryPosition( const Coord3D *center, pos.z = TheTerrainLogic->getGroundHeight( pos.x, pos.y ); } - if (fabs(pos.z - center->z) > options->maxZDelta) + if (WWMath::Fabs(pos.z - center->z) > options->maxZDelta) return FALSE; // @@ -4566,7 +4566,7 @@ Int PartitionManager::iterateCellsBreadthFirst(const Coord3D *pos, CellBreadthFi //----------------------------------------------------------------------------- static Real calcDist2D(Real x1, Real y1, Real x2, Real y2) { - return sqrtf(sqr(x1-x2) + sqr(y1-y2)); + return WWMath::Sqrtf(sqr(x1-x2) + sqr(y1-y2)); } //----------------------------------------------------------------------------- @@ -5757,7 +5757,7 @@ void hLineAddThreat(Int x1, Int x2, Int y, void *threatValueParms) if (x < 0 || x >= ThePartitionManager->m_cellCountX) continue; - distance = sqrt( pow(x - parms->xCenter, 2) + pow(y - parms->yCenter, 2) ); + distance = WWMath::Sqrt( WWMath::Pow(x - parms->xCenter, 2) + WWMath::Pow(y - parms->yCenter, 2) ); mulVal = 1 - distance / parms->radius; if (mulVal < 0.0f) mulVal = 0.0f; @@ -5785,7 +5785,7 @@ void hLineRemoveThreat(Int x1, Int x2, Int y, void *threatValueParms) if (x < 0 || x >= ThePartitionManager->m_cellCountX) continue; - distance = sqrt( pow(x - parms->xCenter, 2) + pow(y - parms->yCenter, 2) ); + distance = WWMath::Sqrt( WWMath::Pow(x - parms->xCenter, 2) + WWMath::Pow(y - parms->yCenter, 2) ); mulVal = 1 - distance / parms->radius; if (mulVal < 0.0f) mulVal = 0.0f; @@ -5813,7 +5813,7 @@ void hLineAddValue(Int x1, Int x2, Int y, void *threatValueParms) if (x < 0 || x >= ThePartitionManager->m_cellCountX) continue; - distance = sqrt( pow(x - parms->xCenter, 2) + pow(y - parms->yCenter, 2) ); + distance = WWMath::Sqrt( WWMath::Pow(x - parms->xCenter, 2) + WWMath::Pow(y - parms->yCenter, 2) ); mulVal = 1 - distance / parms->radius; if (mulVal < 0.0f) mulVal = 0.0f; @@ -5841,7 +5841,7 @@ void hLineRemoveValue(Int x1, Int x2, Int y, void *threatValueParms) if (x < 0 || x >= ThePartitionManager->m_cellCountX) continue; - distance = sqrt( pow(x - parms->xCenter, 2) + pow(y - parms->yCenter, 2) ); + distance = WWMath::Sqrt( WWMath::Pow(x - parms->xCenter, 2) + WWMath::Pow(y - parms->yCenter, 2) ); mulVal = 1 - distance / parms->radius; if (mulVal < 0.0f) mulVal = 0.0f; diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp index 2eed5b09878..a3532047ec0 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp @@ -1296,8 +1296,8 @@ Bool AIUpdateInterface::blockedBy(Object *other) // If we are near our final goal, don't get stuck. if (goalCell.x>0 && goalCell.y>0) { - Real dx = fabs(goalPos.x-pos.x); - Real dy = fabs(goalPos.y-pos.y); + Real dx = WWMath::Fabs(goalPos.x-pos.x); + Real dy = WWMath::Fabs(goalPos.y-pos.y); if (dxgetRelativeAngle2D( getObject(), &info.posOnPath ); } - if (fabs(deltaAngle)>PI/30) + if (WWMath::Fabs(deltaAngle)>PI/30) { return TRUE; } @@ -2272,7 +2272,7 @@ UpdateSleepTime AIUpdateInterface::doLocomotor() } else { - Real dist = sqrtf(dSqr); + Real dist = WWMath::Sqrtf(dSqr); if (dist<1) dist = 1; pos.x += 2*PATHFIND_CELL_SIZE_F*dx/(dist*LOGICFRAMES_PER_SECOND); pos.y += 2*PATHFIND_CELL_SIZE_F*dy/(dist*LOGICFRAMES_PER_SECOND); @@ -2473,7 +2473,7 @@ Real AIUpdateInterface::getLocomotorDistanceToGoal() dest = m_path->getLastNode()->getPosition(); } Real distance = ThePartitionManager->getDistanceSquared( me, dest, FROM_CENTER_3D ); - return sqrt( distance );// Other paths return dots of normalized vectors, so one sqrt ain't so bad + return WWMath::Sqrt( distance );// Other paths return dots of normalized vectors, so one sqrt ain't so bad } else { @@ -2505,7 +2505,7 @@ Real AIUpdateInterface::getLocomotorDistanceToGoal() { if (sqr(dist) > distSqr) { - return sqrt(distSqr); + return WWMath::Sqrt(distSqr); } else { @@ -2514,7 +2514,7 @@ Real AIUpdateInterface::getLocomotorDistanceToGoal() } if (distropeLen < it->ropeLenMax) { - it->ropeSpeed += fabs(TheGlobalData->m_gravity); + it->ropeSpeed += WWMath::Fabs(TheGlobalData->m_gravity); if (it->ropeSpeed > d->m_ropeDropSpeed) it->ropeSpeed = d->m_ropeDropSpeed; it->ropeLen += it->ropeSpeed; @@ -762,7 +762,7 @@ class ChinookMoveToBldgState : public AIMoveToState StateReturnType status = AIMoveToState::update(); const Real THRESH = 3.0f; - if (status != STATE_CONTINUE && fabs(obj->getPosition()->z - m_destZ) > THRESH) + if (status != STATE_CONTINUE && WWMath::Fabs(obj->getPosition()->z - m_destZ) > THRESH) status = STATE_CONTINUE; return status; @@ -891,7 +891,7 @@ ChinookAIUpdateModuleData::ChinookAIUpdateModuleData() m_minDropHeight = 30.0f; m_ropeFinalHeight = 0.0f; m_ropeDropSpeed = 1e10f; // um, fast. - m_rappelSpeed = fabs(TheGlobalData->m_gravity) * LOGICFRAMES_PER_SECOND * 0.5f; + m_rappelSpeed = WWMath::Fabs(TheGlobalData->m_gravity) * LOGICFRAMES_PER_SECOND * 0.5f; m_ropeWobbleLen = 10.0f; m_ropeWobbleAmp = 1.0f; m_ropeWobbleRate = 0.1f; diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/DeliverPayloadAIUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/DeliverPayloadAIUpdate.cpp index ca618b60a80..0e988d2b80b 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/DeliverPayloadAIUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/DeliverPayloadAIUpdate.cpp @@ -202,8 +202,8 @@ UpdateSleepTime DeliverPayloadAIUpdate::update() { //Calc strafe ratio Real startDiveDistance = getData()->m_diveStartDistance; - Real endDiveDistance = sqrt( endDiveDistanceSquared ); - Real currentDistance = sqrt( currentDistanceSquared ); + Real endDiveDistance = WWMath::Sqrt( endDiveDistanceSquared ); + Real currentDistance = WWMath::Sqrt( currentDistanceSquared ); Real diveRatio = (startDiveDistance - currentDistance) / (startDiveDistance - endDiveDistance); @@ -1108,7 +1108,7 @@ StateReturnType RecoverFromOffMapState::update() // Success if we should try aga enterCoord.z = owner->getPosition()->z; owner->setPosition(&enterCoord); - Real enterAngle = atan2(ai->getMoveToPos()->y - enterCoord.y, ai->getMoveToPos()->x - enterCoord.x); + Real enterAngle = WWMath::Atan2(ai->getMoveToPos()->y - enterCoord.y, ai->getMoveToPos()->x - enterCoord.x); owner->setOrientation(enterAngle); PhysicsBehavior* physics = owner->getPhysics(); @@ -1148,7 +1148,7 @@ StateReturnType HeadOffMapState::onEnter() // Give move order out of town Region3D terrainExtent; TheTerrainLogic->getExtent( &terrainExtent ); const Real FUDGE = 1.2f; - Real HUGE_DIST = FUDGE * sqrt(sqr(terrainExtent.hi.x - terrainExtent.lo.x) + sqr(terrainExtent.hi.y - terrainExtent.lo.y)); + Real HUGE_DIST = FUDGE * WWMath::Sqrt(sqr(terrainExtent.hi.x - terrainExtent.lo.x) + sqr(terrainExtent.hi.y - terrainExtent.lo.y)); exitCoord.x += dir->x * HUGE_DIST; exitCoord.y += dir->y * HUGE_DIST; diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/JetAIUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/JetAIUpdate.cpp index 7bf9abfdd6a..d7f4cb3a9f2 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/JetAIUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/JetAIUpdate.cpp @@ -516,8 +516,8 @@ class JetOrHeliTaxiState : public AIMoveOutOfTheWayState Coord3D intermedPt; Bool intermed = false; - Real orient = atan2(ppinfo.runwayPrep.y - ppinfo.parkingSpace.y, ppinfo.runwayPrep.x - ppinfo.parkingSpace.x); - if (fabs(stdAngleDiff(orient, ppinfo.parkingOrientation)) > PI/128) + Real orient = WWMath::Atan2(ppinfo.runwayPrep.y - ppinfo.parkingSpace.y, ppinfo.runwayPrep.x - ppinfo.parkingSpace.x); + if (WWMath::Fabs(stdAngleDiff(orient, ppinfo.parkingOrientation)) > PI/128) { intermedPt.z = (ppinfo.parkingSpace.z + ppinfo.runwayPrep.z) * 0.5f; intermed = intersectInfiniteLine2D( @@ -1071,7 +1071,7 @@ class HeliTakeoffOrLandingState : public State } else { - Real dist = sqrtf(dSqr); + Real dist = WWMath::Sqrtf(dSqr); if (dist<1) dist = 1; pos.x += PATHFIND_CELL_SIZE_F*dx/(dist*LOGICFRAMES_PER_SECOND); pos.y += PATHFIND_CELL_SIZE_F*dy/(dist*LOGICFRAMES_PER_SECOND); @@ -1199,7 +1199,7 @@ class JetOrHeliParkOrientState : public State return STATE_FAILURE; const Real THRESH = 0.001f; - if (fabs(stdAngleDiff(jet->getOrientation(), ppinfo.parkingOrientation)) <= THRESH) + if (WWMath::Fabs(stdAngleDiff(jet->getOrientation(), ppinfo.parkingOrientation)) <= THRESH) return STATE_SUCCESS; // magically position it correctly. @@ -2297,7 +2297,7 @@ void JetAIUpdate::positionLockon() Real dx = getObject()->getPosition()->x - pos.x; Real dy = getObject()->getPosition()->y - pos.y; if (dx || dy) - m_lockonDrawable->setOrientation(atan2(dy, dx)); + m_lockonDrawable->setOrientation(WWMath::Atan2(dy, dx)); // the Gaussian sum, to avoid keeping a running total: // diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/MissileAIUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/MissileAIUpdate.cpp index 78b44dc99ca..e136a2ec0e0 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/MissileAIUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/MissileAIUpdate.cpp @@ -232,7 +232,7 @@ void MissileAIUpdate::projectileFireAtObjectOrPosition( const Object *victim, co Real deltaZ = victimPos->z - obj->getPosition()->z; Real dx = victimPos->x - obj->getPosition()->x; Real dy = victimPos->y - obj->getPosition()->y; - Real xyDist = sqrt(sqr(dx)+sqr(dy)); + Real xyDist = WWMath::Sqrt(sqr(dx)+sqr(dy)); if (xyDist<1) xyDist = 1; Real zFactor = 0; if (deltaZ>0) { @@ -649,7 +649,7 @@ UpdateSleepTime MissileAIUpdate::update() Coord3D newPos = *getObject()->getPosition(); if (m_noTurnDistLeft > 0.0f && m_state >= IGNITION) { - Real distThisTurn = sqrtf(sqr(newPos.x-m_prevPos.x) + sqr(newPos.y-m_prevPos.y) + sqr(newPos.z-m_prevPos.z)); + Real distThisTurn = WWMath::Sqrtf(sqr(newPos.x-m_prevPos.x) + sqr(newPos.y-m_prevPos.y) + sqr(newPos.z-m_prevPos.z)); m_noTurnDistLeft -= distThisTurn; m_prevPos = newPos; } diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/POWTruckAIUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/POWTruckAIUpdate.cpp index cfe716f8440..b4ef88d8bed 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/POWTruckAIUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/POWTruckAIUpdate.cpp @@ -480,7 +480,7 @@ void POWTruckAIUpdate::updateCollectingTarget() { // are we close enough to tell them to start moving to us - Real distSq = pow( us->getGeometryInfo().getBoundingSphereRadius() * 2.0f, 2 ); + Real distSq = WWMath::Pow( us->getGeometryInfo().getBoundingSphereRadius() * 2.0f, 2 ); if( ThePartitionManager->getDistanceSquared( us, target, FROM_CENTER_2D ) <= distSq ) { diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/RailroadGuideAIUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/RailroadGuideAIUpdate.cpp index 1ece8505529..4d3fad6131b 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/RailroadGuideAIUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/RailroadGuideAIUpdate.cpp @@ -320,7 +320,7 @@ void RailroadBehavior::onCollide( Object *other, const Coord3D *loc, const Coord m_whistleSound.setPlayingHandle(TheAudio->addAudioEvent( &m_whistleSound )); - Real dist = (Real)sqrtf( dlt.x*dlt.x + dlt.y*dlt.y + dlt.z*dlt.z); + Real dist = (Real)WWMath::Sqrtf( dlt.x*dlt.x + dlt.y*dlt.y + dlt.z*dlt.z); Real usRadius = obj->getGeometryInfo().getMajorRadius(); Real themRadius = other->getGeometryInfo().getMajorRadius(); Real overlap = ((usRadius + themRadius) - dist) + 1;// the plus 1 makes them go just outside of me. @@ -467,8 +467,8 @@ void RailroadBehavior::playImpactSound(Object *victim, const Coord3D *impactPosi impact.setPosition(impactPosition); if ( theirPhys ) { - vel += fabs(theirPhys->getVelocity()->length()); - mass += fabs(theirPhys->getMass()); + vel += WWMath::Fabs(theirPhys->getVelocity()->length()); + mass += WWMath::Fabs(theirPhys->getMass()); vel /= 2; mass /= 2;//average of him and me @@ -700,7 +700,7 @@ UpdateSleepTime RailroadBehavior::update() if ( m_conductorState == APPLY_BRAKES ) { conductorPullInfo.speed *= modData->m_braking; - if (fabs(conductorPullInfo.speed) < 0.1f) + if (WWMath::Fabs(conductorPullInfo.speed) < 0.1f) { conductorPullInfo.speed = 0; ///////////////////////////////////////( &m_hissySteamSound ); @@ -1233,7 +1233,7 @@ void alignToTerrain( Real angle, const Coord3D& pos, const Coord3D& normal, Matr x.normalize(); } - DEBUG_ASSERTCRASH(fabs(x.x*z.x + x.y*z.y + x.z*z.z)<0.0001,("dot is not zero")); + DEBUG_ASSERTCRASH(WWMath::Fabs(x.x*z.x + x.y*z.y + x.z*z.z)<0.0001,("dot is not zero")); // now computing the y vector is trivial. y.crossProduct( z, x, y ); @@ -1299,7 +1299,7 @@ void RailroadBehavior::updatePositionTrackDistance( PullInfo *pullerInfo, PullIn trackPosDelta.z = 0; Real dx = pullerInfo->towHitchPosition.x - turnPos.x; Real dy = pullerInfo->towHitchPosition.y - turnPos.y; - Real desiredAngle = atan2(dy, dx); + Real desiredAngle = WWMath::Atan2(dy, dx); Real relAngle = stdAngleDiff(desiredAngle, obj->getTransformMatrix()->Get_Z_Rotation()); diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/CleanupHazardUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/CleanupHazardUpdate.cpp index 0d40b8eb230..2a14009633a 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/CleanupHazardUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/CleanupHazardUpdate.cpp @@ -172,7 +172,7 @@ UpdateSleepTime CleanupHazardUpdate::update() AIUpdateInterface *ai = obj->getAI(); if( ai && (ai->isIdle() || ai->isBusy()) ) { - Real fDist = sqrt( ThePartitionManager->getDistanceSquared( obj, &m_pos, FROM_CENTER_2D ) ); + Real fDist = WWMath::Sqrt( ThePartitionManager->getDistanceSquared( obj, &m_pos, FROM_CENTER_2D ) ); if( fDist < 25.0f ) { //Abort clean area because there's nothing left to clean! @@ -204,7 +204,7 @@ void CleanupHazardUpdate::fireWhenReady() bonus.clear(); Real fireRange = m_weaponTemplate->getAttackRange( bonus ); Object *me = getObject(); - Real fDist = sqrt( ThePartitionManager->getDistanceSquared( me, target, FROM_CENTER_2D ) ); + Real fDist = WWMath::Sqrt( ThePartitionManager->getDistanceSquared( me, target, FROM_CENTER_2D ) ); if( fDist < fireRange ) { //We are currently in range! diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/CommandButtonHuntUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/CommandButtonHuntUpdate.cpp index 344f3e882ae..8eac2411461 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/CommandButtonHuntUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/CommandButtonHuntUpdate.cpp @@ -338,7 +338,7 @@ Object* CommandButtonHuntUpdate::scanClosestTarget() } } Real distSqr = ThePartitionManager->getDistanceSquared(me, other, FROM_BOUNDINGSPHERE_2D); - Real dist = sqrt(distSqr); + Real dist = WWMath::Sqrt(distSqr); Int curPriority = data->m_scanRange - dist; if (info) curPriority = info->getPriority(other->getTemplate()); if (curPriority == 0) diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/DockUpdate/SupplyWarehouseDockUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/DockUpdate/SupplyWarehouseDockUpdate.cpp index 51a9913c933..6937e3ea3be 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/DockUpdate/SupplyWarehouseDockUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/DockUpdate/SupplyWarehouseDockUpdate.cpp @@ -95,7 +95,7 @@ Bool SupplyWarehouseDockUpdate::action( Object* docker, Object *drone ) Real closeEnoughSqr = sqr(docker->getGeometryInfo().getBoundingCircleRadius()*2); Real curDistSqr = ThePartitionManager->getDistanceSquared(docker, getObject(), FROM_BOUNDINGSPHERE_2D); if (curDistSqr > closeEnoughSqr) { - DEBUG_LOG(("Failing dock, dist %f, not close enough(%f).", sqrt(curDistSqr), sqrt(closeEnoughSqr))); + DEBUG_LOG(("Failing dock, dist %f, not close enough(%f).", WWMath::Sqrt(curDistSqr), WWMath::Sqrt(closeEnoughSqr))); // Make it twitch a little. Coord3D newPos = *docker->getPosition(); Real range = 0.4*PATHFIND_CELL_SIZE_F; @@ -170,7 +170,7 @@ void SupplyWarehouseDockUpdate::setDockCrippled( Bool setting ) void SupplyWarehouseDockUpdate::setCashValue( Int cashValue ) { // A script can tell us our set value, and we need to figure out the boxes needed to provide that. - m_boxesStored = ceil(cashValue / (float)TheGlobalData->m_baseValuePerSupplyBox); + m_boxesStored = WWMath::Ceil(cashValue / (float)TheGlobalData->m_baseValuePerSupplyBox); Drawable *draw = getObject()->getDrawable(); if( draw ) { diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/DynamicShroudClearingRangeUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/DynamicShroudClearingRangeUpdate.cpp index e7100955fb6..d29b6055388 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/DynamicShroudClearingRangeUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/DynamicShroudClearingRangeUpdate.cpp @@ -166,8 +166,8 @@ void DynamicShroudClearingRangeUpdate::animateGridDecals() for (int d = 0; d < GRID_FX_DECAL_COUNT; ++d) { - pos.x = ctr->x + (sinf(angle) * radius); - pos.y = ctr->y + (cosf(angle) * radius); + pos.x = ctr->x + (WWMath::Sinf(angle) * radius); + pos.y = ctr->y + (WWMath::Cosf(angle) * radius); pos.x -= ((Int)pos.x)%23; pos.y -= ((Int)pos.y)%23; diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/FloatUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/FloatUpdate.cpp index 8959c3a4db6..0fd8ed5c2c3 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/FloatUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/FloatUpdate.cpp @@ -119,8 +119,8 @@ UpdateSleepTime FloatUpdate::update() { Real angle = INT_TO_REAL(TheGameLogic->getFrame()); - Real yaw = sin(angle * 0.0291f) * 0.05f; - Real pitch = sin(angle * 0.0515f) * 0.05f; + Real yaw = WWMath::Sin(angle * 0.0291f) * 0.05f; + Real pitch = WWMath::Sin(angle * 0.0515f) * 0.05f; Matrix3D mx = *draw->getInstanceMatrix(); diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/NeutronMissileUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/NeutronMissileUpdate.cpp index 62de8b3f53c..0955b8a078d 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/NeutronMissileUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/NeutronMissileUpdate.cpp @@ -297,7 +297,7 @@ static Real calcTransform(const Object* obj, const Coord3D *pos, Real maxTurnRat Real angle = (Real)ACos( c ); Vector3 newDir; - if (fabs(angle) < maxTurnRate) + if (WWMath::Fabs(angle) < maxTurnRate) { // close enough -- point exactly in the right dir newDir = otherDir; @@ -355,7 +355,7 @@ void NeutronMissileUpdate::doAttack() // // Modulate speed according to turning. The more we have to turn, the slower we go // - Real angleCoeff = (Real)fabs( relAngle ) / (PI / 2.0f); + Real angleCoeff = (Real)WWMath::Fabs( relAngle ) / (PI / 2.0f); if (angleCoeff > 1.0f) angleCoeff = 1.0; } @@ -512,7 +512,7 @@ UpdateSleepTime NeutronMissileUpdate::update() if (m_noTurnDistLeft > 0.0f && oldPosValid) { Coord3D newPos = *getObject()->getPosition(); - Real distThisTurn = sqrt(sqr(newPos.x-oldPos.x) + sqr(newPos.y-oldPos.y) + sqr(newPos.z-oldPos.z)); + Real distThisTurn = WWMath::Sqrt(sqr(newPos.x-oldPos.x) + sqr(newPos.y-oldPos.y) + sqr(newPos.z-oldPos.z)); //DEBUG_LOG(("noTurnDist goes from %f to %f",m_noTurnDistLeft,m_noTurnDistLeft-distThisTurn)); m_noTurnDistLeft -= distThisTurn; } diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ParticleUplinkCannonUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ParticleUplinkCannonUpdate.cpp index f8452289f2d..950d34336c5 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ParticleUplinkCannonUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ParticleUplinkCannonUpdate.cpp @@ -531,7 +531,7 @@ UpdateSleepTime ParticleUplinkCannonUpdate::update() Real cxDistance = (factor * data->m_swathOfDeathDistance ) - (data->m_swathOfDeathDistance * 0.5f); //cx is cartesian x //Now calculate the amplitude value. - Real height = sin( radians ); + Real height = WWMath::Sin( radians ); Real cxHeight = height * data->m_swathOfDeathAmplitude; Coord3D buildingToInitialTargetVector; diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp index 78b256e5b88..387b9e79fe0 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp @@ -103,7 +103,7 @@ static Real heightToSpeed(Real height) { // don't bother trying to remember how far we've fallen; instead, // back-calc it from our speed & gravity... v = sqrt(2*g*h) - return sqrt(fabs(2.0f * TheGlobalData->m_gravity * height)); + return WWMath::Sqrt(WWMath::Fabs(2.0f * TheGlobalData->m_gravity * height)); } //------------------------------------------------------------------------------------------------- @@ -513,7 +513,7 @@ Bool PhysicsBehavior::handleBounce(Real oldZ, Real newZ, Real groundZ, Coord3D* Real vz = getVelocity()->z; if (oldZ > groundZ && vz < 0.0f) { - desiredAccelZ = fabs(vz) * stiffness; + desiredAccelZ = WWMath::Fabs(vz) * stiffness; } bounceForce->x = 0.0f; @@ -555,7 +555,7 @@ Bool PhysicsBehavior::handleBounce(Real oldZ, Real newZ, Real groundZ, Coord3D* inline Bool isVerySmall3D(const Coord3D& v) { const Real THRESH = 0.01f; - return (fabs(v.x) < THRESH && fabs(v.y) < THRESH && fabs(v.z) < THRESH); + return (WWMath::Fabs(v.x) < THRESH && WWMath::Fabs(v.y) < THRESH && WWMath::Fabs(v.z) < THRESH); } //------------------------------------------------------------------------------------------------- @@ -655,9 +655,9 @@ UpdateSleepTime PhysicsBehavior::update() // when vel gets tiny, just clamp to zero const Real THRESH = 0.001f; - if (fabsf(m_vel.x) < THRESH) m_vel.x = 0.0f; - if (fabsf(m_vel.y) < THRESH) m_vel.y = 0.0f; - if (fabsf(m_vel.z) < THRESH) m_vel.z = 0.0f; + if (WWMath::Fabsf(m_vel.x) < THRESH) m_vel.x = 0.0f; + if (WWMath::Fabsf(m_vel.y) < THRESH) m_vel.y = 0.0f; + if (WWMath::Fabsf(m_vel.z) < THRESH) m_vel.z = 0.0f; m_velMag = INVALID_VEL_MAG; @@ -689,9 +689,9 @@ UpdateSleepTime PhysicsBehavior::update() // Check when to clear the stunned status if (getIsStunned()) { - if ( (fabs(m_vel.x) < STUN_RELIEF_EPSILON && - fabs(m_vel.y) < STUN_RELIEF_EPSILON && - fabs(m_vel.z) < STUN_RELIEF_EPSILON) + if ( (WWMath::Fabs(m_vel.x) < STUN_RELIEF_EPSILON && + WWMath::Fabs(m_vel.y) < STUN_RELIEF_EPSILON && + WWMath::Fabs(m_vel.z) < STUN_RELIEF_EPSILON) || obj->isSignificantlyAboveTerrain() == FALSE ) { @@ -737,8 +737,8 @@ UpdateSleepTime PhysicsBehavior::update() if (offset != 0.0f) { Vector3 xvec = mtx.Get_X_Vector(); - Real xy = sqrtf(sqr(xvec.X) + sqr(xvec.Y)); - Real pitchAngle = atan2(xvec.Z, xy); + Real xy = WWMath::Sqrtf(sqr(xvec.X) + sqr(xvec.Y)); + Real pitchAngle = WWMath::Atan2(xvec.Z, xy); Real remainingAngle = (offset > 0) ? ((PI/2) - pitchAngle) : (-(PI/2) + pitchAngle); Real s = Sin(remainingAngle); pitchRateToUse *= s; @@ -864,8 +864,8 @@ UpdateSleepTime PhysicsBehavior::update() // going down hills don't injure themselves (unless the hill is really steep) const Real MIN_ANGLE_TAN = 3.0f; // roughly 71 degrees const Real TINY_DELTA = 0.01f; - if ((fabs(m_vel.x) <= TINY_DELTA || fabs(activeVelZ / m_vel.x) >= MIN_ANGLE_TAN) && - (fabs(m_vel.y) <= TINY_DELTA || fabs(activeVelZ / m_vel.y) >= MIN_ANGLE_TAN)) + if ((WWMath::Fabs(m_vel.x) <= TINY_DELTA || WWMath::Fabs(activeVelZ / m_vel.x) >= MIN_ANGLE_TAN) && + (WWMath::Fabs(m_vel.y) <= TINY_DELTA || WWMath::Fabs(activeVelZ / m_vel.y) >= MIN_ANGLE_TAN)) { Real damageAmt = netSpeed * getMass() * d->m_fallHeightDamageFactor; @@ -944,7 +944,7 @@ Real PhysicsBehavior::getVelocityMagnitude() const { if (m_velMag == INVALID_VEL_MAG) { - m_velMag = (Real)sqrtf( sqr(m_vel.x) + sqr(m_vel.y) + sqr(m_vel.z) ); + m_velMag = (Real)WWMath::Sqrtf( sqr(m_vel.x) + sqr(m_vel.y) + sqr(m_vel.z) ); } return m_velMag; } @@ -966,7 +966,7 @@ Real PhysicsBehavior::getForwardSpeed2D() const Real speedSquared = vx*vx + vy*vy; // DEBUG_ASSERTCRASH( speedSquared != 0, ("zero speedSquared will overflow sqrtf()!") );// lorenzen... sanity check - Real speed = (Real)sqrtf( speedSquared ); + Real speed = (Real)WWMath::Sqrtf( speedSquared ); if (dot >= 0.0f) return speed; @@ -989,7 +989,7 @@ Real PhysicsBehavior::getForwardSpeed3D() const Real dot = vx + vy + vz; - Real speed = (Real)sqrtf( vx*vx + vy*vy + vz*vz ); + Real speed = (Real)WWMath::Sqrtf( vx*vx + vy*vy + vz*vz ); if (dot >= 0.0f) return speed; @@ -1012,7 +1012,7 @@ Bool PhysicsBehavior::wasPreviouslyOverlapped(Object *obj) const //------------------------------------------------------------------------------------------------- void PhysicsBehavior::scrubVelocityZ( Real desiredVelocity ) { - if (fabs(desiredVelocity) < 0.001f) + if (WWMath::Fabs(desiredVelocity) < 0.001f) { m_vel.z = 0; } @@ -1036,7 +1036,7 @@ void PhysicsBehavior::scrubVelocity2D( Real desiredVelocity ) } else { - Real curVelocity = sqrtf(m_vel.x*m_vel.x + m_vel.y*m_vel.y); + Real curVelocity = WWMath::Sqrtf(m_vel.x*m_vel.x + m_vel.y*m_vel.y); if (desiredVelocity > curVelocity) { return; @@ -1119,9 +1119,9 @@ void PhysicsBehavior::doBounceSound(const Coord3D& prevPos) //Real vel = fabs(getVelocity()->z); // can't use velocity, because it's already been updated this frame, and will be zero... (srj) - Real vel = fabs(prevPos.z - getObject()->getPosition()->z); + Real vel = WWMath::Fabs(prevPos.z - getObject()->getPosition()->z); - Real mass = fabs(getMass()); + Real mass = WWMath::Fabs(getMass()); if (vel > NORMAL_VEL_Z) { vel = NORMAL_VEL_Z; } @@ -1321,7 +1321,7 @@ void PhysicsBehavior::onCollide( Object *other, const Coord3D *loc, const Coord3 m_lastCollidee = other->getID(); - Real dist = sqrtf(distSqr); + Real dist = WWMath::Sqrtf(distSqr); Real overlap = usRadius + themRadius - dist; // if objects are coincident, dist is zero, so force would be infinite -- clearly @@ -1462,7 +1462,7 @@ static Bool perpsLogicallyEqual( Real perpOne, Real perpTwo ) { // Equality with a wiggle fudge. const Real PERP_RANGE = 0.15f; - return fabs( perpOne - perpTwo ) <= PERP_RANGE; + return WWMath::Fabs( perpOne - perpTwo ) <= PERP_RANGE; } //------------------------------------------------------------------------------------------------- diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/PointDefenseLaserUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/PointDefenseLaserUpdate.cpp index 0bbe34ac99b..33560cd0fd2 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/PointDefenseLaserUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/PointDefenseLaserUpdate.cpp @@ -167,7 +167,7 @@ void PointDefenseLaserUpdate::fireWhenReady() bonus.clear(); Real fireRange = data->m_weaponTemplate->getAttackRange( bonus ); Object *me = getObject(); - Real fDist = sqrt( ThePartitionManager->getDistanceSquared( me, target, FROM_CENTER_2D ) ); + Real fDist = WWMath::Sqrt( ThePartitionManager->getDistanceSquared( me, target, FROM_CENTER_2D ) ); if( fDist < fireRange ) { //We are currently in range! @@ -290,7 +290,7 @@ Object* PointDefenseLaserUpdate::scanClosestTarget() continue; } - Real fDist = sqrt( ThePartitionManager->getDistanceSquared( me, other, FROM_CENTER_2D ) ); + Real fDist = WWMath::Sqrt( ThePartitionManager->getDistanceSquared( me, other, FROM_CENTER_2D ) ); if( fDist <= fireRange ) { @@ -317,7 +317,7 @@ Object* PointDefenseLaserUpdate::scanClosestTarget() pos.add( *other->getPosition() ); //Recalculate the distance. - fDist = sqrt( ThePartitionManager->getDistanceSquared( me, other, FROM_CENTER_2D ) ); + fDist = WWMath::Sqrt( ThePartitionManager->getDistanceSquared( me, other, FROM_CENTER_2D ) ); } } diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/SpectreGunshipDeploymentUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/SpectreGunshipDeploymentUpdate.cpp index c23caf3d715..e6e0ab6fad5 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/SpectreGunshipDeploymentUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/SpectreGunshipDeploymentUpdate.cpp @@ -218,7 +218,7 @@ Bool SpectreGunshipDeploymentUpdate::initiateIntentToDoSpecialPower(const Specia newGunship->setPosition( &creationCoord ); //ORIENTATION - Real orient = atan2( m_initialTargetPosition.y - creationCoord.y, m_initialTargetPosition.x - creationCoord.x); + Real orient = WWMath::Atan2( m_initialTargetPosition.y - creationCoord.y, m_initialTargetPosition.x - creationCoord.x); newGunship->setOrientation( orient ); // ID diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/StealthUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/StealthUpdate.cpp index 8f09c707af2..c1de266f811 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/StealthUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/StealthUpdate.cpp @@ -670,7 +670,7 @@ UpdateSleepTime StealthUpdate::update() m_disguiseHalfpointReached = true; } //Opacity ranges from full to none at midpoint and full again at the end - Real opacity = fabs( 1.0f - (factor * 2.0f) ); + Real opacity = WWMath::Fabs( 1.0f - (factor * 2.0f) ); Real overrideOpacity = opacity < 1.0f ? 0.0f : 1.0f; draw->setEffectiveOpacity( opacity, overrideOpacity ); if( !m_disguiseTransitionFrames && !m_transitioningToDisguise ) diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/TensileFormationUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/TensileFormationUpdate.cpp index 08b1e976360..4c6192c6ba8 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/TensileFormationUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/TensileFormationUpdate.cpp @@ -348,7 +348,7 @@ UpdateSleepTime TensileFormationUpdate::update() else draw->clearModelConditionFlags(MAKE_MODELCONDITION_MASK(MODELCONDITION_MOVING)); - if ( fabs( pos->z - newPos.z ) > 0.2f && m_life < 100) + if ( WWMath::Fabs( pos->z - newPos.z ) > 0.2f && m_life < 100) draw->setModelConditionFlags(MAKE_MODELCONDITION_MASK(MODELCONDITION_FREEFALL)); else draw->clearModelConditionFlags(MAKE_MODELCONDITION_MASK(MODELCONDITION_FREEFALL)); diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ToppleUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ToppleUpdate.cpp index 137521dcf9b..605a10260d4 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ToppleUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ToppleUpdate.cpp @@ -130,7 +130,7 @@ static Real angleClosestTo(Real a1, Real a2, Real desired) { a1 = normalizeAngle(a1); a2 = normalizeAngle(a2); - return (fabs(stdAngleDiff(desired, a1)) < fabs(stdAngleDiff(desired, a2))) ? a1 : a2; + return (WWMath::Fabs(stdAngleDiff(desired, a1)) < WWMath::Fabs(stdAngleDiff(desired, a2))) ? a1 : a2; } //------------------------------------------------------------------------------------------------- @@ -185,7 +185,7 @@ void ToppleUpdate::applyTopplingForce( const Coord3D* toppleDirection, Real topp // yeah, it assumes the models are constructed appropriately, but is a cheap way // of minimizing the problem. (srj) Real curAngleX = normalizeAngle(getObject()->getOrientation()); - Real toppleAngle = normalizeAngle(atan2(m_toppleDirection.y, m_toppleDirection.x)); + Real toppleAngle = normalizeAngle(WWMath::Atan2(m_toppleDirection.y, m_toppleDirection.x)); if (d->m_toppleLeftOrRightOnly) { // it's a fence or such, and can only topple left or right, so pick the closest @@ -298,7 +298,7 @@ UpdateSleepTime ToppleUpdate::update() m_angularVelocity *= -d->m_bounceVelocityPercent; if( BitIsSet( m_options, TOPPLE_OPTIONS_NO_BOUNCE ) == TRUE || - fabs(m_angularVelocity) < VELOCITY_BOUNCE_LIMIT ) + WWMath::Fabs(m_angularVelocity) < VELOCITY_BOUNCE_LIMIT ) { // too slow, just stop m_angularVelocity = 0; @@ -338,7 +338,7 @@ UpdateSleepTime ToppleUpdate::update() } } } - else if( fabs(m_angularVelocity) >= VELOCITY_BOUNCE_SOUND_LIMIT ) + else if( WWMath::Fabs(m_angularVelocity) >= VELOCITY_BOUNCE_SOUND_LIMIT ) { // fast enough bounce to warrant the bounce fx if( BitIsSet( m_options, TOPPLE_OPTIONS_NO_FX ) == FALSE ) diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp index 8ac49d2033c..f32a25852cb 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp @@ -397,8 +397,8 @@ void WeaponTemplate::reset() // No matter what we have now, we want to convert it to frames from msec. // ShotDelay used to use parseDurationUnsignedInt, and we are expanding on that. - self->m_minDelayBetweenShots = ceilf(ConvertDurationFromMsecsToFrames((Real)self->m_minDelayBetweenShots)); - self->m_maxDelayBetweenShots = ceilf(ConvertDurationFromMsecsToFrames((Real)self->m_maxDelayBetweenShots)); + self->m_minDelayBetweenShots = WWMath::Ceilf(ConvertDurationFromMsecsToFrames((Real)self->m_minDelayBetweenShots)); + self->m_maxDelayBetweenShots = WWMath::Ceilf(ConvertDurationFromMsecsToFrames((Real)self->m_maxDelayBetweenShots)); } @@ -879,7 +879,7 @@ UnsignedInt WeaponTemplate::fireWeaponTemplate if (distSqr < minAttackRangeSqr-0.5f && !isProjectileDetonation) #endif { - DEBUG_ASSERTCRASH(distSqr > minAttackRangeSqr*0.8f, ("*** victim is closer than min attack range (%f vs %f) of this weapon -- why did we attempt to fire?",sqrtf(distSqr),sqrtf(minAttackRangeSqr))); + DEBUG_ASSERTCRASH(distSqr > minAttackRangeSqr*0.8f, ("*** victim is closer than min attack range (%f vs %f) of this weapon -- why did we attempt to fire?",WWMath::Sqrtf(distSqr),WWMath::Sqrtf(minAttackRangeSqr))); //-extraLogging #if defined(RTS_DEBUG) @@ -905,7 +905,7 @@ UnsignedInt WeaponTemplate::fireWeaponTemplate targetPos.set( *victimPos ); } Real reAngle = getWeaponRecoilAmount(); - Real reDir = reAngle != 0.0f ? (atan2(victimPos->y - sourcePos->y, victimPos->x - sourcePos->x)) : 0.0f; + Real reDir = reAngle != 0.0f ? (WWMath::Atan2(victimPos->y - sourcePos->y, victimPos->x - sourcePos->x)) : 0.0f; VeterancyLevel v = sourceObj->getVeterancyLevel(); const FXList* fx = isProjectileDetonation ? getProjectileDetonateFX(v) : getFireFX(v); @@ -1502,9 +1502,9 @@ void WeaponTemplate::dealDamageInternal(ObjectID sourceID, ObjectID victimID, co Coord3D shockWaveVector = damageDirection; // Guard against zero vector. Make vector straight up if that is the case - if (fabs(shockWaveVector.x) < WWMATH_EPSILON && - fabs(shockWaveVector.y) < WWMATH_EPSILON && - fabs(shockWaveVector.z) < WWMATH_EPSILON) + if (WWMath::Fabs(shockWaveVector.x) < WWMATH_EPSILON && + WWMath::Fabs(shockWaveVector.y) < WWMATH_EPSILON && + WWMath::Fabs(shockWaveVector.z) < WWMATH_EPSILON) { shockWaveVector.z = 1.0f; } @@ -2117,11 +2117,11 @@ Bool Weapon::computeApproachTarget(const Object *source, const Object *target, c if (source->isAboveTerrain()) { // Don't do a 180 degree turn. - Real angle = atan2(-dir.y, -dir.x); + Real angle = WWMath::Atan2(-dir.y, -dir.x); Real relAngle = source->getOrientation()- angle; if (relAngle>2*PI) relAngle -= 2*PI; if (relAngle<-2*PI) relAngle += 2*PI; - if (fabs(relAngle)getPosition(); const Real ACCEPTABLE_DZ = 10.0f; - if (fabs(dst->z - src->z) < ACCEPTABLE_DZ) + if (WWMath::Fabs(dst->z - src->z) < ACCEPTABLE_DZ) return true; // always good enough if dz is small, regardless of pitch Real minPitch, maxPitch; diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp index 16cfc933662..d35d9b5610d 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp @@ -33,6 +33,7 @@ #include "Common/AudioHandleSpecialValues.h" #include "Common/BuildAssistant.h" #include "Common/CRCDebug.h" +#include "Common/Diagnostic/SimulationMathCrc.h" #include "Common/FramePacer.h" #include "Common/GameAudio.h" #include "Common/GameEngine.h" @@ -848,7 +849,7 @@ static void populateRandomStartPosition( GameInfo *game ) { Coord3D p1 = c1->second; Coord3D p2 = c2->second; - startSpotDistance[i][j] = sqrt( sqr(p1.x-p2.x) + sqr(p1.y-p2.y) ); + startSpotDistance[i][j] = WWMath::Sqrt( sqr(p1.x-p2.x) + sqr(p1.y-p2.y) ); } } else @@ -3755,6 +3756,16 @@ void GameLogic::update() TheTerrainLogic->UPDATE(); } +#if RUN_MATH_BENCHMARK_REPLAY400_FLAG + static bool s_benchmarkRun = false; + + if (!s_benchmarkRun && m_frame == 400) + { + SimulationMathCrc::runBenchmark(10000); + s_benchmarkRun = true; + } +#endif + // force CRC calculation, so we can keep a cache of the last N CRCs. We do this right where the recorder // would be getting the CRC anyway, so replays can get the CRCs from the exact instant in time as the original. Bool isMPGameOrReplay = (TheRecorder && TheRecorder->isMultiplayer() && getGameMode() != GAME_SHELL && getGameMode() != GAME_NONE); diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cpp index 4d12971edb7..2921c2ad3db 100644 --- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cpp +++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cpp @@ -1792,9 +1792,9 @@ void W3DVolumetricShadow::Update() if (fabs(pos.Z - groundHeight) >= AIRBORNE_UNIT_GROUND_DELTA) { Real extent = MAX_SHADOW_LENGTH_EXTRA_AIRBORNE_SCALE_FACTOR * m_robjExtent; - if (WWMath::Fabs(pos.X - bcX) > (beX + extent) || - WWMath::Fabs(pos.Y - bcY) > (beY + extent) || - WWMath::Fabs(pos.Z - bcZ) > (beZ + extent)) + if (WWMath::Fabsf_Legacy(pos.X - bcX) > (beX + extent) || + WWMath::Fabsf_Legacy(pos.Y - bcY) > (beY + extent) || + WWMath::Fabsf_Legacy(pos.Z - bcZ) > (beZ + extent)) return; //shadow can't be visible so no point in updating. //this unit is above ground, extend shadow volume to reach lowest point on the terrain plus extra bit to make @@ -1805,9 +1805,9 @@ void W3DVolumetricShadow::Update() { //normal object that is not floating above ground so we don't need to extend the shadow lower than the object's //base since it should be sitting directly at ground level. - if (WWMath::Fabs(pos.X - bcX) > (beX + m_robjExtent) || - WWMath::Fabs(pos.Y - bcY) > (beY + m_robjExtent) || - WWMath::Fabs(pos.Z - bcZ) > (beZ + m_robjExtent)) + if (WWMath::Fabsf_Legacy(pos.X - bcX) > (beX + m_robjExtent) || + WWMath::Fabsf_Legacy(pos.Y - bcY) > (beY + m_robjExtent) || + WWMath::Fabsf_Legacy(pos.Z - bcZ) > (beZ + m_robjExtent)) return; //shadow can't be visible so no point in updating. //check if this object has never had it's extrusion length updated. Will only be true for @@ -1948,7 +1948,7 @@ void W3DVolumetricShadow::updateMeshVolume(Int meshIndex, Int lightIndex, const Vector3 vb = (Vector3 &)objectToWorld[0]; va.Normalize(); vb.Normalize(); - Real cosAngle = WWMath::Fabs(Vector3::Dot_Product(va,vb)); + Real cosAngle = WWMath::Fabsf_Legacy(Vector3::Dot_Product(va,vb)); if (cosAngle >= cosAngleToCare) { @@ -1957,7 +1957,7 @@ void W3DVolumetricShadow::updateMeshVolume(Int meshIndex, Int lightIndex, const vb = (Vector3 &)objectToWorld[1]; va.Normalize(); vb.Normalize(); - cosAngle = WWMath::Fabs(Vector3::Dot_Product(va,vb)); + cosAngle = WWMath::Fabsf_Legacy(Vector3::Dot_Product(va,vb)); if (cosAngle >= cosAngleToCare) { @@ -1965,7 +1965,7 @@ void W3DVolumetricShadow::updateMeshVolume(Int meshIndex, Int lightIndex, const vb = (Vector3 &)objectToWorld[2]; va.Normalize(); vb.Normalize(); - cosAngle = WWMath::Fabs(Vector3::Dot_Product(va,vb)); + cosAngle = WWMath::Fabsf_Legacy(Vector3::Dot_Product(va,vb)); if (cosAngle < cosAngleToCare) isMeshRotating=true; } diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DAssetManager.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DAssetManager.cpp index 376912975d7..7e512ebfc42 100644 --- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DAssetManager.cpp +++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DAssetManager.cpp @@ -718,7 +718,7 @@ RenderObjClass * W3DAssetManager::Create_Render_Obj( GetPrecisionTimer(&startTime64); #endif - Bool reallyscale = (WWMath::Fabs(scale - ident_scale) > scale_epsilon); + Bool reallyscale = (WWMath::Fabsf_Legacy(scale - ident_scale) > scale_epsilon); Bool reallycolor = (color & 0xFFFFFF) != 0; //black is not a valid color and assumes no custom coloring. Bool reallytexture = (oldTexture != nullptr && newTexture != nullptr); @@ -1330,9 +1330,9 @@ static inline void Munge_Texture_Name(char *newname, const char *oldname, const RenderObjClass * W3DAssetManager::Create_Render_Obj(const char * name,float scale, const Vector3 &hsv_shift) { Bool isGranny = false; - Bool reallyscale = (WWMath::Fabs(scale - ident_scale) > scale_epsilon); - Bool reallyhsv_shift = (WWMath::Fabs(hsv_shift.X - ident_HSV.X) > H_epsilon || - WWMath::Fabs(hsv_shift.Y - ident_HSV.Y) > S_epsilon || WWMath::Fabs(hsv_shift.Z - ident_HSV.Z) > V_epsilon); + Bool reallyscale = (WWMath::Fabsf(scale - ident_scale) > scale_epsilon); + Bool reallyhsv_shift = (WWMath::Fabsf(hsv_shift.X - ident_HSV.X) > H_epsilon || + WWMath::Fabsf(hsv_shift.Y - ident_HSV.Y) > S_epsilon || WWMath::Fabsf(hsv_shift.Z - ident_HSV.Z) > V_epsilon); // base case, no scale or hue shifting if (!reallyscale && !reallyhsv_shift) return WW3DAssetManager::Create_Render_Obj(name); @@ -1429,8 +1429,8 @@ TextureClass * W3DAssetManager::Get_Texture_With_HSV_Shift(const char * filename { WWPROFILE( "W3DAssetManager::Get_Texture with HSV shift" ); - Bool is_hsv_shift = (WWMath::Fabs(hsv_shift.X - ident_HSV.X) > H_epsilon || - WWMath::Fabs(hsv_shift.Y - ident_HSV.Y) > S_epsilon || WWMath::Fabs(hsv_shift.Z - ident_HSV.Z) > V_epsilon); + Bool is_hsv_shift = (WWMath::Fabsf(hsv_shift.X - ident_HSV.X) > H_epsilon || + WWMath::Fabsf(hsv_shift.Y - ident_HSV.Y) > S_epsilon || WWMath::Fabsf(hsv_shift.Z - ident_HSV.Z) > V_epsilon); if (!is_hsv_shift) { diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DParticleSys.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DParticleSys.cpp index b1b792b3ac9..0ef7e307eb0 100644 --- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DParticleSys.cpp +++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DParticleSys.cpp @@ -167,13 +167,13 @@ void W3DParticleSystemManager::doParticles(RenderInfoClass &rinfo) Real psize = p->getSize(); //Cull particle to edges of screen and terrain. - if (WWMath::Fabs( pos->x - bcX ) > ( beX + psize ) ) + if (WWMath::Fabsf_Legacy( pos->x - bcX ) > ( beX + psize ) ) continue; - if (WWMath::Fabs( pos->y - bcY ) > ( beY + psize ) ) + if (WWMath::Fabsf_Legacy( pos->y - bcY ) > ( beY + psize ) ) continue; - if (WWMath::Fabs( pos->z - bcZ ) > ( beZ + psize ) ) + if (WWMath::Fabsf_Legacy( pos->z - bcZ ) > ( beZ + psize ) ) continue; if (Smudge *smudge = TheSmudgeManager->findSmudge(p)) @@ -207,13 +207,13 @@ void W3DParticleSystemManager::doParticles(RenderInfoClass &rinfo) psize = p->getSize(); //Cull particle to edges of screen and terrain. - if (WWMath::Fabs(pos->x - bcX) > (beX + psize)) + if (WWMath::Fabsf_Legacy(pos->x - bcX) > (beX + psize)) continue; - if (WWMath::Fabs(pos->y - bcY) > (beY + psize)) + if (WWMath::Fabsf_Legacy(pos->y - bcY) > (beY + psize)) continue; - if (WWMath::Fabs(pos->z - bcZ) > (beZ + psize)) + if (WWMath::Fabsf_Legacy(pos->z - bcZ) > (beZ + psize)) continue; m_fieldParticleCount += ( sys->getPriority() == AREA_EFFECT && sys->m_isGroundAligned != FALSE ); diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DRoadBuffer.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DRoadBuffer.cpp index 37bacee4a77..902910213e5 100644 --- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DRoadBuffer.cpp +++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DRoadBuffer.cpp @@ -2896,7 +2896,7 @@ void W3DRoadBuffer::insertCurveSegmentAt(Int ndx1, Int ndx2) line1.Set(Vector3(pr1->X, pr1->Y, 0), Vector3(pr2->X, pr2->Y, 0)); line2.Set(Vector3(pr3->X, pr3->Y, 0), Vector3(pr4->X, pr4->Y, 0)); } - Real angle = WWMath::Acos(curSin); + Real angle = WWMath::Acos_Legacy(curSin); Real count = angle / (PI/6.0f); // number of 30 degree steps. if (count<0.9 || m_roads[ndx1].m_pt1.isAngled) { miter(ndx1, ndx2); diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/camera.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/camera.cpp index 0f736808bb3..c0a30164572 100644 --- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/camera.cpp +++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/camera.cpp @@ -769,13 +769,13 @@ void CameraClass::Get_Clip_Planes(float & znear,float & zfar) const float CameraClass::Get_Horizontal_FOV() const { float width = ViewPlane.Max.X - ViewPlane.Min.X; - return 2*WWMath::Atan2(width,2.0); + return 2*WWMath::Atan2_Legacy(width,2.0); } float CameraClass::Get_Vertical_FOV() const { float height = ViewPlane.Max.Y - ViewPlane.Min.Y; - return 2*WWMath::Atan2(height,2.0); + return 2*WWMath::Atan2_Legacy(height,2.0); } float CameraClass::Get_Aspect_Ratio() const diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/lightenvironment.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/lightenvironment.cpp index 0c789cbf46f..6b57e4e9490 100644 --- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/lightenvironment.cpp +++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/lightenvironment.cpp @@ -107,7 +107,7 @@ void LightEnvironmentClass::InputLightStruct::Init_From_Point_Or_Spot_Light if (light.Get_Flag(LightClass::FAR_ATTENUATION)) { - if (WWMath::Fabs(atten_end - atten_start) < WWMATH_EPSILON) { + if (WWMath::Fabsf_Legacy(atten_end - atten_start) < WWMATH_EPSILON) { /* ** Start and end are equal, attenuation is a "step" function diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/linegrp.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/linegrp.cpp index bea618de82a..fbb4822914b 100644 --- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/linegrp.cpp +++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/linegrp.cpp @@ -269,9 +269,9 @@ void LineGroupClass::Render(RenderInfoClass &rinfo) const bool sort = (Shader.Get_Dst_Blend_Func() != ShaderClass::DSTBLEND_ZERO) && (Shader.Get_Alpha_Test() == ShaderClass::ALPHATEST_DISABLE) && (WW3D::Is_Sorting_Enabled()); // the 3 offsets in view space - const static Vector3 offset_a = Vector3(WWMath::Cos(WWMATH_PI / 2), WWMath::Sin(WWMATH_PI /2 ), 0); - const static Vector3 offset_b = Vector3(WWMath::Cos(7 * WWMATH_PI / 6), WWMath::Sin(7 * WWMATH_PI / 6), 0); - const static Vector3 offset_c = Vector3(WWMath::Cos(11 * WWMATH_PI / 6), WWMath::Sin(11 * WWMATH_PI / 6), 0); + const static Vector3 offset_a = Vector3(WWMath::Cosf_Legacy(WWMATH_PI / 2), WWMath::Sinf_Legacy(WWMATH_PI /2 ), 0); + const static Vector3 offset_b = Vector3(WWMath::Cosf_Legacy(7 * WWMATH_PI / 6), WWMath::Sinf_Legacy(7 * WWMATH_PI / 6), 0); + const static Vector3 offset_c = Vector3(WWMath::Cosf_Legacy(11 * WWMATH_PI / 6), WWMath::Sinf_Legacy(11 * WWMATH_PI / 6), 0); static Vector3 offset[3]; diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/mapper.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/mapper.cpp index fa182a696da..5883aedec7e 100644 --- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/mapper.cpp +++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/mapper.cpp @@ -168,8 +168,8 @@ void LinearOffsetTextureMapperClass::Calculate_Texture_Matrix(Matrix4x4 &tex_mat // If ClampFix is TRUE we clamp the offsets between -Scale and +Scale with no wraparound. // This works well for clamped textures. if (!ClampFix) { - offset_u = offset_u - WWMath::Floor(offset_u); - offset_v = offset_v - WWMath::Floor(offset_v); + offset_u = offset_u - WWMath::Floorf(offset_u); + offset_v = offset_v - WWMath::Floorf(offset_v); } else { offset_u = WWMath::Clamp(offset_u, -Scale.X, Scale.X); offset_v = WWMath::Clamp(offset_v, -Scale.Y, Scale.Y); @@ -372,8 +372,8 @@ void RotateTextureMapperClass::Calculate_Texture_Matrix(Matrix4x4 &tex_matrix) // Set up the rotation matrix float c,s; - c=WWMath::Cos(CurrentAngle); - s=WWMath::Sin(CurrentAngle); + c=WWMath::Cosf_Legacy(CurrentAngle); + s=WWMath::Sinf_Legacy(CurrentAngle); tex_matrix.Make_Identity(); // subtract center @@ -514,8 +514,8 @@ void StepLinearOffsetTextureMapperClass::Calculate_Texture_Matrix(Matrix4x4 &tex // If ClampFix is TRUE we clamp the offsets between -Scale and +Scale with no wraparound. // This works well for clamped textures. if (!ClampFix) { - CurrentStep.U -= WWMath::Floor(CurrentStep.U); - CurrentStep.V -= WWMath::Floor(CurrentStep.V); + CurrentStep.U -= WWMath::Floorf(CurrentStep.U); + CurrentStep.V -= WWMath::Floorf(CurrentStep.V); } else { CurrentStep.U = WWMath::Clamp(CurrentStep.U, -Scale.X, Scale.X); CurrentStep.V = WWMath::Clamp(CurrentStep.V, -Scale.Y, Scale.Y); @@ -732,7 +732,7 @@ void EdgeMapperClass::Calculate_Texture_Matrix(Matrix4x4 &tex_matrix) LastUsedSyncTime=now; VOffset+=delta*VSpeed; - VOffset-=WWMath::Floor(VOffset); + VOffset-=WWMath::Floorf(VOffset); // takes the Z component and // uses it to index the texture @@ -918,8 +918,8 @@ void ScreenMapperClass::Calculate_Texture_Matrix(Matrix4x4 &tex_matrix) // If ClampFix is TRUE we clamp the offsets between -Scale and +Scale with no wraparound. // This works well for clamped textures. if (!ClampFix) { - offset_u = offset_u - WWMath::Floor(offset_u); - offset_v = offset_v - WWMath::Floor(offset_v); + offset_u = offset_u - WWMath::Floorf(offset_u); + offset_v = offset_v - WWMath::Floorf(offset_v); } else { offset_u = WWMath::Clamp(offset_u, -Scale.X, Scale.X); offset_v = WWMath::Clamp(offset_v, -Scale.Y, Scale.Y); diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/motchan.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/motchan.cpp index 4d1a41da450..53908f0f927 100644 --- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/motchan.cpp +++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/motchan.cpp @@ -861,7 +861,7 @@ AdaptiveDeltaMotionChannelClass::AdaptiveDeltaMotionChannelClass() : //ratio = ((ratio + 1.0f) / 128.0f); ratio/=((float) FILTER_TABLE_GEN_SIZE); - filtertable[i + FILTER_TABLE_GEN_START] = 1.0f - WWMath::Sin( DEG_TO_RAD(90.0f * ratio)); + filtertable[i + FILTER_TABLE_GEN_START] = 1.0f - WWMath::Sinf_Legacy( DEG_TO_RAD(90.0f * ratio)); } table_valid = true; diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/part_emt.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/part_emt.cpp index 0064a85f2ea..d037033e451 100644 --- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/part_emt.cpp +++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/part_emt.cpp @@ -670,7 +670,7 @@ void ParticleEmitterClass::Initialize_Particle(NewParticleStruct * newpart, Vector3 outwards; float pos_l2 = rand_pos.Length2(); if (pos_l2) { - outwards = rand_pos * (OutwardVel * WWMath::Inv_Sqrt(pos_l2)); + outwards = rand_pos * (OutwardVel * WWMath::Inv_Sqrt_Legacy(pos_l2)); } else { outwards.X = OutwardVel; outwards.Y = 0.0f; diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/render2d.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/render2d.cpp index 350ff50b1fc..ee37d3c266a 100644 --- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/render2d.cpp +++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/render2d.cpp @@ -222,8 +222,8 @@ Vector2 Render2DClass::Convert_Vert( const Vector2 & v ) out.Y = (out.Y - 1.0f) * (Get_Screen_Resolution().Height() * -0.5f); // Round to nearest pixel - out.X = WWMath::Floor( out.X + 0.5f ); - out.Y = WWMath::Floor( out.Y + 0.5f ); + out.X = WWMath::Floorf( out.X + 0.5f ); + out.Y = WWMath::Floorf( out.Y + 0.5f ); // Bias if ( WW3D::Is_Screen_UV_Biased() ) { // Global bais setting diff --git a/GeneralsMD/Code/Tools/WorldBuilder/src/GlobalLightOptions.cpp b/GeneralsMD/Code/Tools/WorldBuilder/src/GlobalLightOptions.cpp index 02b654bcf9d..929638d6b31 100644 --- a/GeneralsMD/Code/Tools/WorldBuilder/src/GlobalLightOptions.cpp +++ b/GeneralsMD/Code/Tools/WorldBuilder/src/GlobalLightOptions.cpp @@ -54,8 +54,8 @@ static void calcNewLight(Int lr, Int fb, Vector3 *newLight) newLight->Set(0,0,-1); Real yAngle = PI*(lr-90)/180; Real xAngle = PI*(fb-90)/180; - Real zAngle = xAngle * WWMath::Sin(yAngle); - xAngle *= WWMath::Cos(yAngle); + Real zAngle = xAngle * WWMath::Sinf(yAngle); + xAngle *= WWMath::Cosf(yAngle); newLight->Rotate_Y(yAngle); newLight->Rotate_X(xAngle); newLight->Rotate_Z(zAngle); @@ -94,8 +94,8 @@ void GlobalLightOptions::updateEditFields() void GlobalLightOptions::showLightFeedback(Int lightIndex) { Vector3 light(0,0,0); - light.X = sin(PI/2.0f+m_angleElevation[lightIndex]/180.0f*PI)*cos(m_angleAzimuth[lightIndex]/180.0f*PI);// -WWMath::Sin(PI*(m_angleLR[lightIndex]-90)/180); - light.Y = sin(PI/2.0f+m_angleElevation[lightIndex]/180.0f*PI)*sin(m_angleAzimuth[lightIndex]/180.0f*PI);//-WWMath::Sin(PI*(m_angleFB[lightIndex]-90)/180); + light.X = sin(PI/2.0f+m_angleElevation[lightIndex]/180.0f*PI)*cos(m_angleAzimuth[lightIndex]/180.0f*PI);// -WWMath::Sinf(PI*(m_angleLR[lightIndex]-90)/180); + light.Y = sin(PI/2.0f+m_angleElevation[lightIndex]/180.0f*PI)*sin(m_angleAzimuth[lightIndex]/180.0f*PI);//-WWMath::Sinf(PI*(m_angleFB[lightIndex]-90)/180); light.Z = cos (PI/2.0f+m_angleElevation[lightIndex]/180.0f*PI); WbView3d * pView = CWorldBuilderDoc::GetActive3DView(); @@ -109,8 +109,8 @@ void GlobalLightOptions::showLightFeedback(Int lightIndex) void GlobalLightOptions::applyAngle(Int lightIndex) { Vector3 light(0,0,0); - light.X = sin(PI/2.0f+m_angleElevation[lightIndex]/180.0f*PI)*cos(m_angleAzimuth[lightIndex]/180.0f*PI);// -WWMath::Sin(PI*(m_angleLR[lightIndex]-90)/180); - light.Y = sin(PI/2.0f+m_angleElevation[lightIndex]/180.0f*PI)*sin(m_angleAzimuth[lightIndex]/180.0f*PI);//-WWMath::Sin(PI*(m_angleFB[lightIndex]-90)/180); + light.X = sin(PI/2.0f+m_angleElevation[lightIndex]/180.0f*PI)*cos(m_angleAzimuth[lightIndex]/180.0f*PI);// -WWMath::Sinf(PI*(m_angleLR[lightIndex]-90)/180); + light.Y = sin(PI/2.0f+m_angleElevation[lightIndex]/180.0f*PI)*sin(m_angleAzimuth[lightIndex]/180.0f*PI);//-WWMath::Sinf(PI*(m_angleFB[lightIndex]-90)/180); light.Z = cos (PI/2.0f+m_angleElevation[lightIndex]/180.0f*PI); CString str; diff --git a/cmake/compilers.cmake b/cmake/compilers.cmake index c5c4d5118c2..cd047333108 100644 --- a/cmake/compilers.cmake +++ b/cmake/compilers.cmake @@ -51,6 +51,9 @@ if (NOT IS_VS6_BUILD) add_compile_options(/Zc:__cplusplus) else() add_compile_options(-Wsuggest-override) + # Prevent FMA contraction (a*b+c -> fmadd) which skips intermediate + # rounding and breaks cross-platform deterministic math parity with MSVC (/fp:precise). + add_compile_options(-ffp-contract=off) endif() else() if(RTS_BUILD_OPTION_VC6_FULL_DEBUG) diff --git a/cmake/gamemath.cmake b/cmake/gamemath.cmake new file mode 100644 index 00000000000..57dfaf4adfc --- /dev/null +++ b/cmake/gamemath.cmake @@ -0,0 +1,16 @@ +# FORCE is required to guarantee cross-platform bit-exact determinism. +# Intrinsics would use platform-specific SIMD, breaking CRC parity between architectures. +set(GM_ENABLE_INTRINSICS OFF CACHE BOOL "Disable intrinsics for cross-arch determinism" FORCE) +set(GM_ENABLE_TESTS OFF CACHE BOOL "Disable GameMath tests" FORCE) + +FetchContent_Declare( + gamemath + GIT_REPOSITORY https://github.com/TheSuperHackers/GameMath.git + GIT_TAG 59f7ccd494f7e7c916a784ac26ef266f9f09d78d +) + +FetchContent_MakeAvailable(gamemath) + +# Ensure GameMath includes are available to ALL targets +# to prevent one-definition-rule violations and ensure USE_DETERMINISTIC_MATH activates consistently. +include_directories(${gamemath_SOURCE_DIR}/include)