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 7c1269d1db9..5926f8fb084 100644 --- a/Core/CMakeLists.txt +++ b/Core/CMakeLists.txt @@ -8,7 +8,10 @@ add_library(corei_always INTERFACE) add_library(corei_always_no_pch INTERFACE) # Use this for Shared Libs with MFC AFX target_include_directories(corei_gameengine_include INTERFACE "GameEngine/Include") -target_include_directories(corei_libraries_include INTERFACE "Libraries/Include") +target_include_directories(corei_libraries_include INTERFACE "Libraries/Include" "Libraries/Source/WWVegas/WWMath") +if (NOT IS_VS6_BUILD) + target_link_libraries(corei_libraries_include INTERFACE gamemath) +endif() target_include_directories(corei_libraries_source_wwvegas INTERFACE "Libraries/Source/WWVegas") target_include_directories(corei_libraries_source_wwvegas_wwlib INTERFACE "Libraries/Source/WWVegas/WWLib") target_include_directories(corei_main INTERFACE "Main") @@ -16,7 +19,7 @@ target_include_directories(corei_main INTERFACE "Main") target_sources(corei_libraries_include PRIVATE Libraries/Include/Lib/BaseType.h Libraries/Include/Lib/BaseTypeCore.h - Libraries/Include/Lib/trig.h + Libraries/Include/rts/debug.h Libraries/Include/rts/profile.h ) diff --git a/Core/GameEngine/Include/GameClient/View.h b/Core/GameEngine/Include/GameClient/View.h index 7180b907f25..09f357b9d46 100644 --- a/Core/GameEngine/Include/GameClient/View.h +++ b/Core/GameEngine/Include/GameClient/View.h @@ -34,7 +34,7 @@ #include "Common/Snapshot.h" #include "Lib/BaseType.h" #include "WW3D2/coltype.h" ///< we don't generally do this, but we need the W3D collision types -#include "WWMath/wwmath.h" +#include "wwmath.h" #define DEFAULT_VIEW_WIDTH 640 #define DEFAULT_VIEW_HEIGHT 480 diff --git a/Core/GameEngine/Source/Common/Diagnostic/SimulationMathCrc.cpp b/Core/GameEngine/Source/Common/Diagnostic/SimulationMathCrc.cpp index 1b062f44e34..8f1e62917a3 100644 --- a/Core/GameEngine/Source/Common/Diagnostic/SimulationMathCrc.cpp +++ b/Core/GameEngine/Source/Common/Diagnostic/SimulationMathCrc.cpp @@ -21,7 +21,7 @@ #include "Common/Diagnostic/SimulationMathCrc.h" #include "Common/XferCRC.h" #include "WWMath/matrix3d.h" -#include "WWMath/wwmath.h" +#include "wwmath.h" #include "GameLogic/FPUControl.h" #include diff --git a/Core/GameEngine/Source/GameClient/RadiusDecal.cpp b/Core/GameEngine/Source/GameClient/RadiusDecal.cpp index c7863220aaf..8c5afd3d30a 100644 --- a/Core/GameEngine/Source/GameClient/RadiusDecal.cpp +++ b/Core/GameEngine/Source/GameClient/RadiusDecal.cpp @@ -194,7 +194,7 @@ void RadiusDecal::update() { UnsignedInt now = TheGameLogic->getFrame(); Real theta = (2*PI) * (Real)(now % m_template->m_opacityThrobTime) / (Real)m_template->m_opacityThrobTime; - Real percent = 0.5f * (Sin(theta) + 1.0f); + Real percent = 0.5f * (WWMath::Sin(theta) + 1.0f); Int opac; if( TheGameLogic->getDrawIconUI() ) { diff --git a/Core/GameEngine/Source/GameClient/System/ParticleSys.cpp b/Core/GameEngine/Source/GameClient/System/ParticleSys.cpp index b516a335000..c4c706314cb 100644 --- a/Core/GameEngine/Source/GameClient/System/ParticleSys.cpp +++ b/Core/GameEngine/Source/GameClient/System/ParticleSys.cpp @@ -584,8 +584,8 @@ void Particle::doWindMotion() (noForceDistance - fullForceDistance))); // integrate the wind motion into the position - m_pos.x += (Cos( windAngle ) * windForceStrength); - m_pos.y += (Sin( windAngle ) * windForceStrength); + m_pos.x += (WWMath::Cos( windAngle ) * windForceStrength); + m_pos.y += (WWMath::Sin( windAngle ) * windForceStrength); } @@ -3520,7 +3520,7 @@ static Real angleBetween(const Coord2D *vecA, const Coord2D *vecB) return 0.0f; } - Real theta = ACos( cosTheta ); + Real theta = WWMath::Acos( cosTheta ); if (vecB->x > 0) { return theta; diff --git a/Core/GameEngine/Source/GameLogic/AI/AIPathfind.cpp b/Core/GameEngine/Source/GameLogic/AI/AIPathfind.cpp index 09886bb0a7b..8ae1b7faa31 100644 --- a/Core/GameEngine/Source/GameLogic/AI/AIPathfind.cpp +++ b/Core/GameEngine/Source/GameLogic/AI/AIPathfind.cpp @@ -3955,8 +3955,8 @@ Bool PathfindLayer::isPointOnWall(ObjectID *wallPieces, Int numPieces, const Coo Real major = obj->getGeometryInfo().getMajorRadius(); Real minor = (obj->getGeometryInfo().getGeomType() == GEOMETRY_SPHERE) ? obj->getGeometryInfo().getMajorRadius() : obj->getGeometryInfo().getMinorRadius(); - Real c = (Real)Cos(-obj->getOrientation()); - Real s = (Real)Sin(-obj->getOrientation()); + Real c = (Real)WWMath::CosTrig(-obj->getOrientation()); + Real s = (Real)WWMath::SinTrig(-obj->getOrientation()); // convert to a delta relative to rect ctr Real ptx = pt->x - obj->getPosition()->x; @@ -4223,8 +4223,8 @@ void Pathfinder::classifyFence( Object *obj, Bool insert ) Real halfsizeY = PATHFIND_CELL_SIZE_F/10.0f; Real fenceOffset = obj->getTemplate()->getFenceXOffset(); - Real c = (Real)Cos(angle); - Real s = (Real)Sin(angle); + Real c = (Real)WWMath::CosTrig(angle); + Real s = (Real)WWMath::SinTrig(angle); const Real STEP_SIZE = PATHFIND_CELL_SIZE_F * 0.5f; // in theory, should be PATHFIND_CELL_SIZE_F exactly, but needs to be smaller to avoid aliasing problems Real ydx = s * STEP_SIZE; @@ -4431,8 +4431,8 @@ void Pathfinder::internal_classifyObjectFootprint( Object *obj, Bool insert ) Real halfsizeX = obj->getGeometryInfo().getMajorRadius(); Real halfsizeY = obj->getGeometryInfo().getMinorRadius(); - Real c = (Real)Cos(angle); - Real s = (Real)Sin(angle); + Real c = (Real)WWMath::CosTrig(angle); + Real s = (Real)WWMath::SinTrig(angle); const Real STEP_SIZE = PATHFIND_CELL_SIZE_F * 0.5f; // in theory, should be PATHFIND_CELL_SIZE_F exactly, but needs to be smaller to avoid aliasing problems Real ydx = s * STEP_SIZE; diff --git a/Core/GameEngineDevice/Source/W3DDevice/Common/System/W3DRadar.cpp b/Core/GameEngineDevice/Source/W3DDevice/Common/System/W3DRadar.cpp index 53a5299f152..aa2240cc405 100644 --- a/Core/GameEngineDevice/Source/W3DDevice/Common/System/W3DRadar.cpp +++ b/Core/GameEngineDevice/Source/W3DDevice/Common/System/W3DRadar.cpp @@ -403,16 +403,16 @@ void W3DRadar::drawSingleBeaconEvent( Int pixelX, Int pixelY, Int width, Int hei // create a triangle around the event angle = 0.0f - addAngle; - tri[ 0 ].x = REAL_TO_INT( (DOUBLE_TO_REAL( Cos( angle ) ) * eventSize) + event->radarLoc.x ); - tri[ 0 ].y = REAL_TO_INT( (DOUBLE_TO_REAL( Sin( angle ) ) * eventSize) + event->radarLoc.y ); + tri[ 0 ].x = REAL_TO_INT( (DOUBLE_TO_REAL( WWMath::Cos( angle ) ) * eventSize) + event->radarLoc.x ); + tri[ 0 ].y = REAL_TO_INT( (DOUBLE_TO_REAL( WWMath::Sin( angle ) ) * eventSize) + event->radarLoc.y ); angle = 2.0f * PI / 3.0f - addAngle; - tri[ 1 ].x = REAL_TO_INT( (DOUBLE_TO_REAL( Cos( angle ) ) * eventSize) + event->radarLoc.x ); - tri[ 1 ].y = REAL_TO_INT( (DOUBLE_TO_REAL( Sin( angle ) ) * eventSize) + event->radarLoc.y ); + tri[ 1 ].x = REAL_TO_INT( (DOUBLE_TO_REAL( WWMath::Cos( angle ) ) * eventSize) + event->radarLoc.x ); + tri[ 1 ].y = REAL_TO_INT( (DOUBLE_TO_REAL( WWMath::Sin( angle ) ) * eventSize) + event->radarLoc.y ); angle = -2.0f * PI / 3.0f - addAngle; - tri[ 2 ].x = REAL_TO_INT( (DOUBLE_TO_REAL( Cos( angle ) ) * eventSize) + event->radarLoc.x ); - tri[ 2 ].y = REAL_TO_INT( (DOUBLE_TO_REAL( Sin( angle ) ) * eventSize) + event->radarLoc.y ); + tri[ 2 ].x = REAL_TO_INT( (DOUBLE_TO_REAL( WWMath::Cos( angle ) ) * eventSize) + event->radarLoc.x ); + tri[ 2 ].y = REAL_TO_INT( (DOUBLE_TO_REAL( WWMath::Sin( angle ) ) * eventSize) + event->radarLoc.y ); // translate radar coords to screen coords radarToPixel( &tri[ 0 ], &tri[ 0 ], pixelX, pixelY, width, height ); @@ -502,16 +502,16 @@ void W3DRadar::drawSingleGenericEvent( Int pixelX, Int pixelY, Int width, Int he // create a triangle around the event angle = 0.0f - addAngle; - tri[ 0 ].x = REAL_TO_INT( (DOUBLE_TO_REAL( Cos( angle ) ) * eventSize) + event->radarLoc.x ); - tri[ 0 ].y = REAL_TO_INT( (DOUBLE_TO_REAL( Sin( angle ) ) * eventSize) + event->radarLoc.y ); + tri[ 0 ].x = REAL_TO_INT( (DOUBLE_TO_REAL( WWMath::Cos( angle ) ) * eventSize) + event->radarLoc.x ); + tri[ 0 ].y = REAL_TO_INT( (DOUBLE_TO_REAL( WWMath::Sin( angle ) ) * eventSize) + event->radarLoc.y ); angle = 2.0f * PI / 3.0f - addAngle; - tri[ 1 ].x = REAL_TO_INT( (DOUBLE_TO_REAL( Cos( angle ) ) * eventSize) + event->radarLoc.x ); - tri[ 1 ].y = REAL_TO_INT( (DOUBLE_TO_REAL( Sin( angle ) ) * eventSize) + event->radarLoc.y ); + tri[ 1 ].x = REAL_TO_INT( (DOUBLE_TO_REAL( WWMath::Cos( angle ) ) * eventSize) + event->radarLoc.x ); + tri[ 1 ].y = REAL_TO_INT( (DOUBLE_TO_REAL( WWMath::Sin( angle ) ) * eventSize) + event->radarLoc.y ); angle = -2.0f * PI / 3.0f - addAngle; - tri[ 2 ].x = REAL_TO_INT( (DOUBLE_TO_REAL( Cos( angle ) ) * eventSize) + event->radarLoc.x ); - tri[ 2 ].y = REAL_TO_INT( (DOUBLE_TO_REAL( Sin( angle ) ) * eventSize) + event->radarLoc.y ); + tri[ 2 ].x = REAL_TO_INT( (DOUBLE_TO_REAL( WWMath::Cos( angle ) ) * eventSize) + event->radarLoc.x ); + tri[ 2 ].y = REAL_TO_INT( (DOUBLE_TO_REAL( WWMath::Sin( angle ) ) * eventSize) + event->radarLoc.y ); // translate radar coords to screen coords radarToPixel( &tri[ 0 ], &tri[ 0 ], pixelX, pixelY, width, height ); diff --git a/Core/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DRopeDraw.cpp b/Core/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DRopeDraw.cpp index 11221d6a0b5..83d03677252 100644 --- a/Core/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DRopeDraw.cpp +++ b/Core/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DRopeDraw.cpp @@ -84,8 +84,8 @@ void W3DRopeDraw::buildSegments() SegInfo info; Real axis = GameClientRandomValueReal(0, 2*PI); - info.wobbleAxisX = Cos(axis); - info.wobbleAxisY = Sin(axis); + info.wobbleAxisX = WWMath::Cos(axis); + info.wobbleAxisY = WWMath::Sin(axis); info.line = NEW Line3DClass( Vector3(pos.x,pos.y,pos.z), Vector3(pos.x,pos.y,pos.z+eachLen), m_width * 0.5f, // width @@ -186,7 +186,7 @@ void W3DRopeDraw::doDrawModule(const Matrix3D* transformMtx) if (!m_segments.empty()) { - Real deflection = Sin(m_curWobblePhase) * m_wobbleAmp; + Real deflection = WWMath::Sin(m_curWobblePhase) * m_wobbleAmp; const Coord3D* pos = getDrawable()->getPosition(); Vector3 start(pos->x, pos->y, pos->z + m_curZOffset); Real eachLen = m_curLen / m_segments.size(); diff --git a/Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DTreeBuffer.cpp b/Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DTreeBuffer.cpp index aa86abc5f2a..a59b50fab53 100644 --- a/Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DTreeBuffer.cpp +++ b/Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DTreeBuffer.cpp @@ -351,10 +351,10 @@ void W3DTreeBuffer::updateSway(const BreezeInfo& info) { Int i; for (i=0; i 1.0) c = 1.0; - Real value = (Real)ACos( (Real)c ); + Real value = (Real)WWMath::Acos( (Real)c ); // Determine sign by checking Z component of dir cross vector // Note this is assumes 2D, and is identical to dotting the perpendicular of v with dir @@ -295,7 +295,7 @@ inline Real Coord2D::toAngle() const else if (c > 1.0f) c = 1.0f; - return y < 0.0f ? -ACos(c) : ACos(c); + return y < 0.0f ? -WWMath::Acos(c) : WWMath::Acos(c); #endif } diff --git a/Core/Libraries/Include/Lib/trig.h b/Core/Libraries/Include/Lib/trig.h deleted file mode 100644 index d6f3fa22cd8..00000000000 --- a/Core/Libraries/Include/Lib/trig.h +++ /dev/null @@ -1,30 +0,0 @@ -/* -** Command & Conquer Generals Zero Hour(tm) -** Copyright 2025 Electronic Arts Inc. -** -** 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 . -*/ - -// Trig.h -// fast trig functions -// Author: Sondra Iverson, March 1998 -// Converted to Generals by Matthew D. Campbell, February 2002 - -#pragma once - -Real Sin(Real); -Real Cos(Real); -Real Tan(Real); -Real ACos(Real); -Real ASin(Real x); diff --git a/Core/Libraries/Source/WWVegas/WW3D2/CMakeLists.txt b/Core/Libraries/Source/WWVegas/WW3D2/CMakeLists.txt index 9ff4754aec9..5bc8a2f9582 100644 --- a/Core/Libraries/Source/WWVegas/WW3D2/CMakeLists.txt +++ b/Core/Libraries/Source/WWVegas/WW3D2/CMakeLists.txt @@ -230,7 +230,7 @@ set(WW3D2_SRC ww3dformat.cpp ww3dformat.h ww3dids.h - ww3dtrig.h + ) add_library(corei_ww3d2 INTERFACE) diff --git a/Core/Libraries/Source/WWVegas/WW3D2/ww3dtrig.h b/Core/Libraries/Source/WWVegas/WW3D2/ww3dtrig.h deleted file mode 100644 index 2720d320ca2..00000000000 --- a/Core/Libraries/Source/WWVegas/WW3D2/ww3dtrig.h +++ /dev/null @@ -1,52 +0,0 @@ -/* -** Command & Conquer Generals Zero Hour(tm) -** Copyright 2025 Electronic Arts Inc. -** -** 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 . -*/ - -/*********************************************************************************************** - *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S *** - *********************************************************************************************** - * * - * Project Name : WW3D * - * * - * $Archive:: /Commando/Code/ww3d2/ww3dtrig.h $* - * * - * $Author:: Greg_h $* - * * - * $Modtime:: 1/08/01 10:04a $* - * * - * $Revision:: 1 $* - * * - *---------------------------------------------------------------------------------------------* - * Functions: * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - -#pragma once - -/* -** The WW3D Library will check for debugging triggers using the following ID's -** Your application may install a trigger handler into the WWDebug library and then -** watch for these ID's coming through. Then if you wish to "trigger" one, then -** assign a key or something to the trigger and when your trigger handler is called, -** check if the key is down. The trigger can be enabled in any way you want but -** in practice, most things will probably be tied to keys. -*/ -enum -{ - WW3D_TRIGGER_RENDER_STATS = 0x100, // display render stats in the debug window - WW3D_TRIGGER_SURFACE_CACHE_STATS = 0x101, // display surface cache info in the debug window - WW3D_TRIGGER_PROCESS_STATS = 0x102 // render stats for last frame only -}; diff --git a/Core/Libraries/Source/WWVegas/WWMath/CMakeLists.txt b/Core/Libraries/Source/WWVegas/WWMath/CMakeLists.txt index dca9eb68fef..f388a7ea0e4 100644 --- a/Core/Libraries/Source/WWVegas/WWMath/CMakeLists.txt +++ b/Core/Libraries/Source/WWVegas/WWMath/CMakeLists.txt @@ -91,5 +91,9 @@ 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/wwmath.cpp b/Core/Libraries/Source/WWVegas/WWMath/wwmath.cpp index ab5c0f91276..9bbf8a076b8 100644 --- a/Core/Libraries/Source/WWVegas/WWMath/wwmath.cpp +++ b/Core/Libraries/Source/WWVegas/WWMath/wwmath.cpp @@ -35,6 +35,7 @@ * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ +#include "always.h" #include "wwmath.h" #include "wwhack.h" #include "lookuptable.h" diff --git a/Core/Libraries/Source/WWVegas/WWMath/wwmath.h b/Core/Libraries/Source/WWVegas/WWMath/wwmath.h index 8adda21a796..0aa46915a30 100644 --- a/Core/Libraries/Source/WWVegas/WWMath/wwmath.h +++ b/Core/Libraries/Source/WWVegas/WWMath/wwmath.h @@ -36,11 +36,24 @@ #pragma once -#include "always.h" +#if defined(_MSC_VER) +#define WWINLINE __forceinline +#else +#define WWINLINE inline +#endif + #include #include #include +// TheSuperHackers @fix VC6 does not support long long or required by GameMath (gmath.h). +#if !(defined(_MSC_VER) && _MSC_VER < 1300) +#include "gmath.h" +#ifdef RETAIL_COMPATIBLE_CRC +#define USE_DETERMINISTIC_MATH +#endif +#endif + /* ** Some global constants. */ @@ -133,8 +146,31 @@ 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)); } +#ifdef USE_DETERMINISTIC_MATH + static WWINLINE float Atan(float x) { return gm_atanf(x); } + static WWINLINE float Atan2(float y, float x) { return gm_atan2f(y, x); } + static WWINLINE float Tan(float x) { return gm_tanf(x); } + static WWINLINE float Sinh(float x) { return gm_sinhf(x); } + static WWINLINE float Cosh(float x) { return gm_coshf(x); } + static WWINLINE float Tanh(float x) { return gm_tanhf(x); } + static WWINLINE float Exp(float x) { return gm_expf(x); } + static WWINLINE float Log(float x) { return gm_logf(x); } + static WWINLINE float Log10(float x) { return gm_log10f(x); } + static WWINLINE float Pow(float x, float y) { return gm_powf(x, y); } + static WWINLINE float SinTrig(float x) { return gm_sinf(x); } + static WWINLINE float CosTrig(float x) { return gm_cosf(x); } + static WWINLINE float TanTrig(float x) { return gm_tanf(x); } + static WWINLINE float ACosTrig(float x) { return gm_acosf(x); } + static WWINLINE float ASinTrig(float x) { return gm_asinf(x); } +#else + 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 SinTrig(float x) { return sinf(x); } + static WWINLINE float CosTrig(float x) { return cosf(x); } + static WWINLINE float TanTrig(float x) { return tanf(x); } + static WWINLINE float ACosTrig(float x) { return acosf(x); } + static WWINLINE float ASinTrig(float x) { return asinf(x); } +#endif static WWINLINE float Sign(float val); static WWINLINE float Ceil(float val) { return ceilf(val); } static WWINLINE float Floor(float val) { return floorf(val); } @@ -348,6 +384,12 @@ WWINLINE long WWMath::Float_To_Long(double f) // Cos // ---------------------------------------------------------------------------- +#ifdef USE_DETERMINISTIC_MATH +WWINLINE float WWMath::Cos(float val) +{ + return gm_cosf(val); +} +#else #if defined(_MSC_VER) && defined(_M_IX86) WWINLINE float WWMath::Cos(float val) { @@ -365,11 +407,18 @@ WWINLINE float WWMath::Cos(float val) return cosf(val); } #endif +#endif // ---------------------------------------------------------------------------- // Sin // ---------------------------------------------------------------------------- +#ifdef USE_DETERMINISTIC_MATH +WWINLINE float WWMath::Sin(float val) +{ + return gm_sinf(val); +} +#else #if defined(_MSC_VER) && defined(_M_IX86) WWINLINE float WWMath::Sin(float val) { @@ -387,6 +436,7 @@ WWINLINE float WWMath::Sin(float val) return sinf(val); } #endif +#endif // ---------------------------------------------------------------------------- // Fast, table based sin @@ -514,10 +564,17 @@ WWINLINE float WWMath::Fast_Acos(float val) // Arc cos // ---------------------------------------------------------------------------- +#ifdef USE_DETERMINISTIC_MATH +WWINLINE float WWMath::Acos(float val) +{ + return gm_acosf(val); +} +#else WWINLINE float WWMath::Acos(float val) { return (float)acos(val); } +#endif // ---------------------------------------------------------------------------- // Fast, table based arc sin @@ -551,15 +608,28 @@ WWINLINE float WWMath::Fast_Asin(float val) // Arc sin // ---------------------------------------------------------------------------- +#ifdef USE_DETERMINISTIC_MATH +WWINLINE float WWMath::Asin(float val) +{ + return gm_asinf(val); +} +#else WWINLINE float WWMath::Asin(float val) { return (float)asin(val); } +#endif // ---------------------------------------------------------------------------- // Sqrt // ---------------------------------------------------------------------------- +#ifdef USE_DETERMINISTIC_MATH +WWINLINE float WWMath::Sqrt(float val) +{ + return gm_sqrtf(val); +} +#else #if defined(_MSC_VER) && defined(_M_IX86) WWINLINE float WWMath::Sqrt(float val) { @@ -577,6 +647,7 @@ WWINLINE float WWMath::Sqrt(float val) return (float)sqrt(val); } #endif +#endif WWINLINE int WWMath::Float_To_Int_Chop(const float& f) { @@ -608,6 +679,12 @@ WWINLINE int WWMath::Float_To_Int_Floor (const float& f) // Inverse square root // ---------------------------------------------------------------------------- +#ifdef USE_DETERMINISTIC_MATH +WWINLINE float WWMath::Inv_Sqrt(float number) +{ + return 1.0f / WWMath::Sqrt(number); +} +#else #if defined(_MSC_VER) && defined(_M_IX86) WWINLINE float WWMath::Inv_Sqrt(float a) { @@ -665,6 +742,7 @@ WWINLINE float WWMath::Inv_Sqrt(float val) return 1.0f / (float)sqrt(val); } #endif +#endif WWINLINE float WWMath::Normalize_Angle(float angle) { diff --git a/Generals/Code/GameEngine/CMakeLists.txt b/Generals/Code/GameEngine/CMakeLists.txt index 73b6cc223bf..034cd391c76 100644 --- a/Generals/Code/GameEngine/CMakeLists.txt +++ b/Generals/Code/GameEngine/CMakeLists.txt @@ -618,7 +618,7 @@ set(GAMEENGINE_SRC Source/Common/System/StackDump.cpp # Source/Common/System/StreamingArchiveFile.cpp # Source/Common/System/SubsystemInterface.cpp - Source/Common/System/Trig.cpp + # Source/Common/System/UnicodeString.cpp Source/Common/System/Upgrade.cpp # Source/Common/System/Xfer.cpp diff --git a/Generals/Code/GameEngine/Source/Common/System/BuildAssistant.cpp b/Generals/Code/GameEngine/Source/Common/System/BuildAssistant.cpp index ccb32fa1bf6..b49a06389a2 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::CosTrig(angle); + Real s = (Real)WWMath::SinTrig(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::CosTrig(them->getOrientation()); + Real s = (Real)WWMath::SinTrig(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(pow(gi.getMajorRadius(), 2) + 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 f33da731b42..b658d5a4b04 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::CosTrig(angle); + Real s = (Real)WWMath::SinTrig(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; } @@ -398,8 +398,8 @@ void GeometryInfo::makeRandomOffsetWithinFootprint(Coord3D& pt) const #else Real radius = GameLogicRandomValueReal(0.0f, m_boundingCircleRadius); Real angle = GameLogicRandomValueReal(-PI, PI); - pt.x = radius * Cos(angle); - pt.y = radius * Sin(angle); + pt.x = radius * WWMath::CosTrig(angle); + pt.y = radius * WWMath::SinTrig(angle); pt.z = 0.0f; #endif 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 deleted file mode 100644 index b09c4cb55d8..00000000000 --- a/Generals/Code/GameEngine/Source/Common/System/Trig.cpp +++ /dev/null @@ -1,145 +0,0 @@ -/* -** Command & Conquer Generals(tm) -** Copyright 2025 Electronic Arts Inc. -** -** 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 . -*/ - -//////////////////////////////////////////////////////////////////////////////// -// // -// (c) 2001-2003 Electronic Arts Inc. // -// // -//////////////////////////////////////////////////////////////////////////////// - -// Trig.cpp -// fast trig functions -// Author: Michael S. Booth, March 1994 -// Converted to Generals by Matthew D. Campbell, February 2002 - -#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); -} - -#ifdef REGENERATE_TRIG_TABLES -void initTrig() -{ - 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; igetGeometryInfo().getMajorRadius(); Real width = obj->getGeometryInfo().getMinorRadius(); - Real pitchHeight = length*Sin(m_locoInfo->m_pitch + m_locoInfo->m_accelerationPitch - groundPitch); - Real rollHeight = width*Sin(m_locoInfo->m_roll + m_locoInfo->m_accelerationRoll - groundRoll); + Real pitchHeight = length*WWMath::Sin(m_locoInfo->m_pitch + m_locoInfo->m_accelerationPitch - groundPitch); + Real rollHeight = width*WWMath::Sin(m_locoInfo->m_roll + m_locoInfo->m_accelerationRoll - groundRoll); info.m_totalZ = fabs(pitchHeight)/4 + fabs(rollHeight)/4; return; // maintain the same orientation while we fly through the air. } @@ -1899,8 +1899,8 @@ void Drawable::calcPhysicsXformWheels( const Locomotor *locomotor, PhysicsXformI // Calculate suspension info. Real length = obj->getGeometryInfo().getMajorRadius(); Real width = obj->getGeometryInfo().getMinorRadius(); - Real pitchHeight = length*Sin(info.m_totalPitch-groundPitch); - Real rollHeight = width*Sin(info.m_totalRoll-groundRoll); + Real pitchHeight = length*WWMath::Sin(info.m_totalPitch-groundPitch); + Real rollHeight = width*WWMath::Sin(info.m_totalRoll-groundRoll); if (DO_WHEELS) { // calculate each wheel position @@ -3705,8 +3705,8 @@ Bool Drawable::handleWeaponFireFX(WeaponSlotType wslot, Int specificBarrelToUse, recoilAngle += PI; if (m_locoInfo) { - m_locoInfo->m_accelerationPitchRate += recoilAmount * Cos(recoilAngle); - m_locoInfo->m_accelerationRollRate += recoilAmount * Sin(recoilAngle); + m_locoInfo->m_accelerationPitchRate += recoilAmount * WWMath::Cos(recoilAngle); + m_locoInfo->m_accelerationRollRate += recoilAmount * WWMath::Sin(recoilAngle); } } diff --git a/Generals/Code/GameEngine/Source/GameClient/Drawable/Update/SwayClientUpdate.cpp b/Generals/Code/GameEngine/Source/GameClient/Drawable/Update/SwayClientUpdate.cpp index 11b449b635c..da4e4122b76 100644 --- a/Generals/Code/GameEngine/Source/GameClient/Drawable/Update/SwayClientUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameClient/Drawable/Update/SwayClientUpdate.cpp @@ -121,7 +121,7 @@ void SwayClientUpdate::clientUpdate() m_curValue += m_curDelta * timeScale; if (m_curValue > 2*PI) m_curValue -= 2*PI; - Real cosine = Cos(m_curValue); + Real cosine = WWMath::Cos(m_curValue); Real targetAngle = cosine * m_curAngleLimit + m_leanAngle; Real deltaAngle = targetAngle - m_curAngle; diff --git a/Generals/Code/GameEngine/Source/GameLogic/AI/AI.cpp b/Generals/Code/GameEngine/Source/GameLogic/AI/AI.cpp index e3c879cf3a1..172cdd49083 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/AI/AI.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/AI/AI.cpp @@ -706,7 +706,7 @@ Object *AI::findClosestEnemy( const Object *me, Real range, UnsignedInt qualifie } Real distSqr = ThePartitionManager->getDistanceSquared(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 39f78bc9a4a..e401be036d1 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::SinTrig(angle) * radius); + posOut.y = tempCtr.y + (WWMath::CosTrig(angle) * radius); } diff --git a/Generals/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp b/Generals/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp index bac316191b1..c15c4dae329 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp @@ -640,7 +640,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; @@ -1245,7 +1245,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)) { @@ -2806,7 +2806,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..3e08d7b7f9d 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::SinTrig(angle); + Real c = WWMath::CosTrig(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::SinTrig(angle); + Real c = WWMath::CosTrig(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 3ac19981a52..51f498ff8e6 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp @@ -604,8 +604,8 @@ StateReturnType AIRappelState::update() bldg->getGeometryInfo().getBoundingCircleRadius()); Real angle = GameLogicRandomValueReal( PI, 2*PI );//Downish. Coord3D startPosition = *bldg->getPosition(); - startPosition.x += offset * Cos( angle ); - startPosition.y += offset * Sin( angle ); + startPosition.x += offset * WWMath::CosTrig( angle ); + startPosition.y += offset * WWMath::SinTrig( angle ); startPosition.z = TheTerrainLogic->getGroundHeight( startPosition.x, startPosition.y ); obj->setPosition( &startPosition ); @@ -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::SinTrig(deltaAngle); + Real c = WWMath::CosTrig(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 diff --git a/Generals/Code/GameEngine/Source/GameLogic/AI/TurretAI.cpp b/Generals/Code/GameEngine/Source/GameLogic/AI/TurretAI.cpp index 651e2c4f2f0..600432d14d9 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/AI/TurretAI.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/AI/TurretAI.cpp @@ -1098,7 +1098,7 @@ StateReturnType TurretAIAimTurretState::update() Real actualPitch; if( v.length() > 0 ) - actualPitch = ASin( v.z / v.length() ); + actualPitch = WWMath::Asin( v.z / v.length() ); else actualPitch = 0;// Don't point at NAN, just point at 0 if they are right on us 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 aa5e8887434..6885b0c6450 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Map/TerrainLogic.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Map/TerrainLogic.cpp @@ -339,8 +339,8 @@ Bridge::Bridge(Object *bridgeObj) Real halfsizeY = bridgeObj->getGeometryInfo().getMinorRadius(); m_bridgeInfo.bridgeWidth = 2*halfsizeY; - Real c = (Real)Cos(angle); - Real s = (Real)Sin(angle); + Real c = (Real)WWMath::CosTrig(angle); + Real s = (Real)WWMath::SinTrig(angle); m_bridgeInfo.fromLeft.set(pos->x-halfsizeX*c-halfsizeY*s, pos->y + halfsizeY*c - halfsizeX*s, pos->z); m_bridgeInfo.toLeft.set(pos->x+halfsizeX*c-halfsizeY*s, pos->y + halfsizeY*c + halfsizeX*s, pos->z); @@ -1468,11 +1468,11 @@ 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 ); - x.y = Sin( angle ); + x.x = WWMath::CosTrig( angle ); + x.y = WWMath::SinTrig( angle ); x.z = 0.0f; //x.normalize(); -- redundant; is normalized by definition @@ -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 @@ -2652,8 +2652,8 @@ void TerrainLogic::flattenTerrain(Object *obj) Real halfsizeY = obj->getGeometryInfo().getMinorRadius(); - Real c = (Real)Cos(angle); - Real s = (Real)Sin(angle); + Real c = (Real)WWMath::CosTrig(angle); + Real s = (Real)WWMath::SinTrig(angle); Vector3 topLeft(pos->x-halfsizeX*c-halfsizeY*s, pos->y + halfsizeY*c - halfsizeX*s, 0); Vector3 topRight(pos->x+halfsizeX*c-halfsizeY*s, pos->y + halfsizeY*c + halfsizeX*s, 0); diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/DumbProjectileBehavior.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/DumbProjectileBehavior.cpp index 7c4bc633863..cbfd9263c97 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/DumbProjectileBehavior.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/DumbProjectileBehavior.cpp @@ -169,11 +169,11 @@ 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) @@ -182,7 +182,7 @@ static Bool calcTrajectory( // 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; @@ -191,7 +191,7 @@ static Bool calcTrajectory( Real t = horizDist / velocity; Real vz = (dz/t + 0.5f*gravity*t); Real sineOfAngle = clamp(-1.0f, vz / velocity, 1.0f); - theta = ASin(sineOfAngle)*0.5f; + theta = WWMath::Asin(sineOfAngle)*0.5f; } /* @@ -203,7 +203,7 @@ static Bool calcTrajectory( { return false; } - Real theta = ASin(sineOfAngle)*0.5f; + Real theta = WWMath::Asin(sineOfAngle)*0.5f; */ Real pitches[2]; @@ -225,10 +225,10 @@ static Bool calcTrajectory( // calc the horiz-speed & time for each. // note that time can only be negative for 90getMinimumAttackRange(); 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; } @@ -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::Sqrt(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..ece1f983462 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; @@ -304,8 +304,8 @@ void GenerateMinefieldBehavior::placeMinesAroundCircle(const Coord3D& pos, Real for (Real angle = 0; angle < angleLim; angle += angleInc) { Coord3D pt; - pt.x = pos.x + radius * Cos(angle); - pt.y = pos.y + radius * Sin(angle); + pt.x = pos.x + radius * WWMath::CosTrig(angle); + pt.y = pos.y + radius * WWMath::SinTrig(angle); pt.z = TheTerrainLogic->getGroundHeight( pt.x, pt.y ); offsetBySmallRandomAmount(pt, mineJitter); placeMineAt(pt, mineTemplate, team, obj); diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/MinefieldBehavior.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/MinefieldBehavior.cpp index 5a4b2727060..c0f5ea9c665 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::Sqrt(2.0f * (start.z - endOnGround.z) / 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,7 +580,7 @@ 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)); + Real dist = WWMath::Sqrt(sqr(dx) + sqr(dy)); if (dist <= 0.1f && fabs(dz) <= 0.1f) { obj->setPosition(&endOnGround); diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/ParkingPlaceBehavior.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/ParkingPlaceBehavior.cpp index 4b472d1ce53..2549a869ae4 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/ParkingPlaceBehavior.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/ParkingPlaceBehavior.cpp @@ -327,8 +327,8 @@ Bool ParkingPlaceBehavior::reserveSpace(ObjectID id, Real parkingOffset, Parking info->parkingSpace = d->m_parkInHangars ? ppi->m_hangarStart : ppi->m_location; if (parkingOffset != 0.0f) { - info->parkingSpace.x += parkingOffset * Cos(ppi->m_orientation); - info->parkingSpace.y += parkingOffset * Sin(ppi->m_orientation); + info->parkingSpace.x += parkingOffset * WWMath::CosTrig(ppi->m_orientation); + info->parkingSpace.y += parkingOffset * WWMath::SinTrig(ppi->m_orientation); } info->runwayPrep = ppi->m_prep; info->parkingOrientation = d->m_parkInHangars ? ppi->m_hangarStartOrient : ppi->m_orientation; 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<pathfinder()->validMovementTerrain( LAYER_GROUND, loco, &startPosition)) { // try front & back. Real offset = getObject()->getGeometryInfo().getMajorRadius(); - startPosition.x -= offset*Cos(exitAngle); - startPosition.y -= offset*Sin(exitAngle); + startPosition.x -= offset*WWMath::CosTrig(exitAngle); + startPosition.y -= offset*WWMath::SinTrig(exitAngle); if (!TheAI->pathfinder()->validMovementTerrain(LAYER_GROUND, loco, &startPosition)) { - startPosition.x += 2*offset*Cos(exitAngle); - startPosition.y += 2*offset*Sin(exitAngle); + startPosition.x += 2*offset*WWMath::CosTrig(exitAngle); + startPosition.y += 2*offset*WWMath::SinTrig(exitAngle); if (!TheAI->pathfinder()->validMovementTerrain(LAYER_GROUND, loco, &startPosition)) { startPosition = *getObject()->getPosition(); } diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Contain/OpenContain.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Contain/OpenContain.cpp index 92dc77b2889..339b841126c 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Contain/OpenContain.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Contain/OpenContain.cpp @@ -611,8 +611,8 @@ void OpenContain::scatterToNearbyPosition(Object* rider) Real dist = GameLogicRandomValueReal( minRadius, maxRadius ); Coord3D pos; - pos.x = dist * Cos( angle ) + containerPos->x; - pos.y = dist * Sin( angle ) + containerPos->y; + pos.x = dist * WWMath::CosTrig( angle ) + containerPos->x; + pos.y = dist * WWMath::SinTrig( angle ) + containerPos->y; pos.z = TheTerrainLogic->getLayerHeight( pos.x, pos.y, theContainer->getLayer() ); // set orientation diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Contain/TunnelContain.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Contain/TunnelContain.cpp index bef8b3fc454..c827b321ac1 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Contain/TunnelContain.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Contain/TunnelContain.cpp @@ -295,8 +295,8 @@ void TunnelContain::scatterToNearbyPosition(Object* obj) Real dist = GameLogicRandomValueReal( minRadius, maxRadius ); Coord3D pos; - pos.x = dist * Cos( angle ) + containerPos->x; - pos.y = dist * Sin( angle ) + containerPos->y; + pos.x = dist * WWMath::CosTrig( angle ) + containerPos->x; + pos.y = dist * WWMath::SinTrig( angle ) + containerPos->y; pos.z = TheTerrainLogic->getGroundHeight( pos.x, pos.y ); // set orientation diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp index d751f77dc73..697eabd8c7d 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp @@ -129,7 +129,7 @@ static Real tryToRotateVector3D( // dot of two unit vectors is cos of angle between them. Real cosine = Vector3::Dot_Product(curDir, goalDir); // bound it in case of numerical error - Real angleBetween = (Real)ACos(clamp(-1.0f, cosine, 1.0f)); + Real angleBetween = (Real)WWMath::Acos(clamp(-1.0f, cosine, 1.0f)); if (maxAngle < 0) { @@ -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; @@ -869,8 +869,8 @@ void Locomotor::locoUpdate_moveTowardsAngle(Object* obj, Real goalAngle) { // can't stay in one place; move in the desired direction at min speed. Coord3D desiredPos = *obj->getPosition(); - desiredPos.x += Cos(goalAngle) * minSpeed * 2; - desiredPos.y += Sin(goalAngle) * minSpeed * 2; + desiredPos.x += WWMath::CosTrig(goalAngle) * minSpeed * 2; + desiredPos.y += WWMath::SinTrig(goalAngle) * minSpeed * 2; // pass a huge num for "dist to goal", so that we don't think we're nearing // our destination and thus slow down... const Real onPathDistToGoal = 99999.0f; @@ -884,8 +884,8 @@ void Locomotor::locoUpdate_moveTowardsAngle(Object* obj, Real goalAngle) { DEBUG_ASSERTCRASH(m_template->m_appearance != LOCO_THRUST, ("THRUST should always have minspeeds!")); Coord3D desiredPos = *obj->getPosition(); - desiredPos.x += Cos(goalAngle) * 1000.0f; - desiredPos.y += Sin(goalAngle) * 1000.0f; + desiredPos.x += WWMath::CosTrig(goalAngle) * 1000.0f; + desiredPos.y += WWMath::SinTrig(goalAngle) * 1000.0f; PhysicsTurningType rotating = rotateTowardsPosition(obj, desiredPos); physics->setTurning(rotating); handleBehaviorZ(obj, physics, *obj->getPosition()); @@ -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; @@ -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; @@ -1341,8 +1341,8 @@ void Locomotor::moveTowardsPositionWheels(Object* obj, PhysicsBehavior *physics, targetAngle += turnAmount; } Coord3D offset; - offset.x = Cos(targetAngle)*distance; - offset.y = Sin(targetAngle)*distance; + offset.x = WWMath::CosTrig(targetAngle)*distance; + offset.y = WWMath::SinTrig(targetAngle)*distance; offset.z = 0; const Coord3D* pos = obj->getPosition(); @@ -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; @@ -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) { @@ -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; @@ -1831,8 +1831,8 @@ void Locomotor::moveTowardsPositionWings(Object* obj, PhysicsBehavior *physics, // project a spot "radius" dist away from it, in that dir Coord3D desiredPos = goalPos; - desiredPos.x += Cos(angleTowardPos) * turnRadius; - desiredPos.y += Sin(angleTowardPos) * turnRadius; + desiredPos.x += WWMath::CosTrig(angleTowardPos) * turnRadius; + desiredPos.y += WWMath::SinTrig(angleTowardPos) * turnRadius; moveTowardsPositionOther(obj, physics, desiredPos, 0, desiredSpeed); return; } @@ -2055,7 +2055,7 @@ Real Locomotor::calcLiftToUseAtPt(Object* obj, PhysicsBehavior *physics, Real cu // thus // a = 2(dz - v t)/t^2 // and - // t = (-v +- sqrt(v*v + 2*a*dz))/a + // t = (-v +- WWMath::Sqrt(v*v + 2*a*dz))/a // // but if we assume t=1, then // a=2(dz-v) @@ -2117,7 +2117,7 @@ PhysicsTurningType Locomotor::rotateObjAroundLocoPivot(Object* obj, const Coord3 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); + Real desiredAngle = WWMath::Atan2(dy, dx); Real amount = stdAngleDiff(desiredAngle, angle); if (relAngle) *relAngle = amount; if (amount>maxTurnRate) { @@ -2132,14 +2132,14 @@ PhysicsTurningType Locomotor::rotateObjAroundLocoPivot(Object* obj, const Coord3 #if 0 Coord3D desiredPos = *obj->getPosition(); // well, desired Dir, anyway - desiredPos.x += Cos(angle + amount) * radius; - desiredPos.y += Sin(angle + amount) * radius; + desiredPos.x += WWMath::CosTrig(angle + amount) * radius; + desiredPos.y += WWMath::SinTrig(angle + amount) * radius; // 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) { @@ -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) @@ -2500,8 +2500,8 @@ void Locomotor::maintainCurrentPositionWings(Object* obj, PhysicsBehavior *physi // project a spot "radius" dist away from it, in that dir Coord3D desiredPos = m_maintainPos; - desiredPos.x += Cos(angleTowardMaintainPos) * turnRadius; - desiredPos.y += Sin(angleTowardMaintainPos) * turnRadius; + desiredPos.x += WWMath::CosTrig(angleTowardMaintainPos) * turnRadius; + desiredPos.y += WWMath::SinTrig(angleTowardMaintainPos) * turnRadius; moveTowardsPositionWings(obj, physics, desiredPos, 0, m_template->m_minSpeed); } } diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/ObjectCreationList.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/ObjectCreationList.cpp index f1ec13163f4..d493afe4066 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; @@ -289,14 +289,14 @@ class DeliverPayloadNugget : public ObjectCreationNugget //Rotate 90 degrees CCW. Real radians = 90.0f * PI / 180.0f; - Real s = Sin( radians ); - Real c = Cos( radians ); + Real s = WWMath::SinTrig( radians ); + Real c = WWMath::CosTrig( radians ); CCWx = dx * c + dy * -s + dx; CCWy = dx * s + dy * c + dy; //Rotate 90 degrees CW - s = Sin( -radians ); - c = Cos( -radians ); + s = WWMath::SinTrig( -radians ); + c = WWMath::CosTrig( -radians ); CWx = dx * c + dy * -s + dx; CWy = dx * s + dy * c + dy; } @@ -343,17 +343,17 @@ class DeliverPayloadNugget : public ObjectCreationNugget { Real randomRadius = GameLogicRandomValueReal(0, m_errorRadius ); Real randomAngle = GameLogicRandomValueReal(0, PI*2 ); - targetPos.x += randomRadius * Cos( randomAngle ); - targetPos.y += randomRadius * Sin( randomAngle ); + targetPos.x += randomRadius * WWMath::CosTrig( randomAngle ); + targetPos.y += randomRadius * WWMath::SinTrig( randomAngle ); } - 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; - startPos.x -= Cos(orient) * m_data.m_distToTarget * SLOP; - startPos.y -= Sin(orient) * m_data.m_distToTarget * SLOP; + startPos.x -= WWMath::CosTrig(orient) * m_data.m_distToTarget * SLOP; + startPos.y -= WWMath::SinTrig(orient) * m_data.m_distToTarget * SLOP; } Object *transport; @@ -1067,7 +1067,7 @@ class GenericObjectCreationNugget : public ObjectCreationNugget objUp->applyForce(&force); if (m_orientInForceDirection) - orientation = atan2(force.y, force.x); + orientation = WWMath::Atan2(force.y, force.x); } } @@ -1155,7 +1155,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 2bb86292763..74d9f414aac 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cpp @@ -401,8 +401,8 @@ static void testRotatedPointsAgainstRect( Real major = a->geom.getMajorRadius(); Real minor = (a->geom.getGeomType() == GEOMETRY_SPHERE) ? a->geom.getMajorRadius() : a->geom.getMinorRadius(); - Real c = (Real)Cos(-a->angle); - Real s = (Real)Sin(-a->angle); + Real c = (Real)WWMath::CosTrig(-a->angle); + Real s = (Real)WWMath::SinTrig(-a->angle); for (Int i = 0; i < 4; ++i, ++pts) { @@ -435,8 +435,8 @@ static void rectToFourPoints( Coord2D pts[] ) { - Real c = (Real)Cos(a->angle); - Real s = (Real)Sin(a->angle); + Real c = (Real)WWMath::CosTrig(a->angle); + Real s = (Real)WWMath::SinTrig(a->angle); Real exc = a->geom.getMajorRadius()*c; Real eyc = a->geom.getMinorRadius()*c; @@ -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::Sqrt(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::Sqrt(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::Sqrt(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::Sqrt(actualDistSqr); Real shrunkenDist = actualDist - totalRad; if (shrunkenDist <= 0.0f) { @@ -1774,8 +1774,8 @@ void PartitionData::doRectFill( Real angle ) { - Real c = (Real)Cos(angle); - Real s = (Real)Sin(angle); + Real c = (Real)WWMath::CosTrig(angle); + Real s = (Real)WWMath::SinTrig(angle); Real actualCellSize = ThePartitionManager->getCellSize(); Real stepSize = actualCellSize * 0.5f; // in theory, should be getCellSize() exactly, but needs to be smaller to avoid aliasing problems @@ -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::Sqrt(majorRadius*majorRadius + minorRadius*minorRadius)); Int cells = ThePartitionManager->worldToCellDist(diagonal*2) + 1; result = cells * cells; break; @@ -3210,7 +3210,7 @@ Int PartitionManager::calcMinRadius(const ICoord2D& cur) } // double, not real - double dist = sqrtf(minDistSqr); + double dist = WWMath::Sqrt(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::Sqrt(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::Sqrt(sqr(v.x) + sqr(v.y)); // normalize if (dist == 0.0f) @@ -3648,7 +3648,7 @@ Real PartitionManager::getRelativeAngle2D( const Object *obj, const Coord3D *pos else if (c > 1.0) c = 1.0; - Real value = (Real)ACos( c ); + Real value = (Real)WWMath::Acos( c ); // Determine sign by checking Z component of dir cross v // Note this is assumes 2D, and is identical to dotting the perpendicular of v with dir @@ -3785,8 +3785,8 @@ Bool PartitionManager::tryPosition( const Coord3D *center, // compute the spot on the terrain we've picked Coord3D pos; - pos.x = dist * Cos( angle ) + center->x; - pos.y = dist * Sin( angle ) + center->y; + pos.x = dist * WWMath::CosTrig( angle ) + center->x; + pos.y = dist * WWMath::SinTrig( angle ) + center->y; PathfindLayerEnum layer = LAYER_GROUND; if ((options->flags & FPF_USE_HIGHEST_LAYER) != 0) @@ -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::Sqrt(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( pow(x - parms->xCenter, 2) + 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( pow(x - parms->xCenter, 2) + 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( pow(x - parms->xCenter, 2) + 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( pow(x - parms->xCenter, 2) + 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 f75f965f68f..50774683a8e 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp @@ -2230,7 +2230,7 @@ UpdateSleepTime AIUpdateInterface::doLocomotor() } else { - Real dist = sqrtf(dSqr); + Real dist = WWMath::Sqrt(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; 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 a6f15066955..c42730f3201 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); @@ -367,7 +367,7 @@ Bool DeliverPayloadAIUpdate::isCloseEnoughToTarget() if ( inBound ) allowedDistanceSqr = sqr(getAllowedDistanceToTarget() + getPreOpenDistance()); - //DEBUG_LOG(("Dist to target is %f (allowed %f)",sqrt(currentDistanceSqr),sqrt(allowedDistanceSqr))); + //DEBUG_LOG(("Dist to target is %f (allowed %f)",WWMath::Sqrt(currentDistanceSqr),WWMath::Sqrt(allowedDistanceSqr))); if ( allowedDistanceSqr > currentDistanceSqr ) @@ -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 6693caf829d..4bb1a02e6d1 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/JetAIUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/JetAIUpdate.cpp @@ -398,10 +398,10 @@ static Bool intersectInfiniteLine2D Real& ix, Real& iy ) { - Real bx = ax + Cos(ao); - Real by = ay + Sin(ao); - Real dx = cx + Cos(co); - Real dy = cy + Sin(co); + Real bx = ax + WWMath::CosTrig(ao); + Real by = ay + WWMath::SinTrig(ao); + Real dx = cx + WWMath::CosTrig(co); + Real dy = cy + WWMath::SinTrig(co); Real denom = ((bx - ax) * (dy - cy) - (by - ay) * (dx - cx)); if (denom == 0.0f) @@ -457,7 +457,7 @@ class JetOrHeliTaxiState : public AIMoveOutOfTheWayState Coord3D intermedPt; Bool intermed = false; - Real orient = atan2(ppinfo.runwayPrep.y - ppinfo.parkingSpace.y, ppinfo.runwayPrep.x - ppinfo.parkingSpace.x); + Real orient = WWMath::Atan2(ppinfo.runwayPrep.y - ppinfo.parkingSpace.y, ppinfo.runwayPrep.x - ppinfo.parkingSpace.x); if (fabs(stdAngleDiff(orient, ppinfo.parkingOrientation)) > PI/128) { intermedPt.z = (ppinfo.parkingSpace.z + ppinfo.runwayPrep.z) * 0.5f; @@ -884,7 +884,7 @@ class HeliTakeoffOrLandingState : public State } else { - Real dist = sqrtf(dSqr); + Real dist = WWMath::Sqrt(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); @@ -2062,15 +2062,15 @@ void JetAIUpdate::positionLockon() Real dist = finalDist + (d->m_lockonInitialDist - finalDist) * frac; Real angle = d->m_lockonAngleSpin * frac; - pos.x += Cos(angle) * dist; - pos.y += Sin(angle) * dist; + pos.x += WWMath::CosTrig(angle) * dist; + pos.y += WWMath::SinTrig(angle) * dist; // pos.z is untouched m_lockonDrawable->setPosition(&pos); 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..4686ed58bda 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) { @@ -581,7 +581,7 @@ void MissileAIUpdate::doKillState() closeEnough = curLoco->getMaxSpeedForCondition(BODY_PRISTINE); } Real distanceToTargetSq = ThePartitionManager->getDistanceSquared( getObject(), getGoalObject(), FROM_CENTER_3D); - //DEBUG_LOG(("Distance to target %f, closeEnough %f", sqrt(distanceToTargetSq), closeEnough)); + //DEBUG_LOG(("Distance to target %f, closeEnough %f", WWMath::Sqrt(distanceToTargetSq), closeEnough)); if (distanceToTargetSq < closeEnough*closeEnough) { Coord3D pos = *getGoalObject()->getPosition(); getObject()->setPosition(&pos); @@ -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::Sqrt(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/RailroadGuideAIUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/RailroadGuideAIUpdate.cpp index 283d7926a9d..f957460fcc0 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::Sqrt( 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. @@ -1184,8 +1184,8 @@ void alignToTerrain( Real angle, const Coord3D& pos, const Coord3D& normal, Matr z = normal; - x.x = Cos( angle ); - x.y = Sin( angle ); + x.x = WWMath::CosTrig( angle ); + x.y = WWMath::SinTrig( angle ); x.z = 0.0f; if (z.z != 0.0f) { @@ -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..1f2b5f080c1 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; diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/DynamicShroudClearingRangeUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/DynamicShroudClearingRangeUpdate.cpp index 5ad5b511a23..43823442874 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::SinTrig(angle) * radius); + pos.y = ctr->y + (WWMath::CosTrig(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..85362f8bc63 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::SinTrig(angle * 0.0291f) * 0.05f; + Real pitch = WWMath::SinTrig(angle * 0.0515f) * 0.05f; Matrix3D mx = *draw->getInstanceMatrix(); diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/HelicopterSlowDeathUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/HelicopterSlowDeathUpdate.cpp index b8c2be438f5..c9caabae992 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/HelicopterSlowDeathUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/HelicopterSlowDeathUpdate.cpp @@ -359,8 +359,8 @@ UpdateSleepTime HelicopterSlowDeathBehavior::update() // is *NOT* the angle the object is facing // Coord3D force; - force.x = DOUBLE_TO_REAL( Cos( m_forwardAngle ) ) * m_forwardSpeed; - force.y = DOUBLE_TO_REAL( Sin( m_forwardAngle ) ) * m_forwardSpeed; + force.x = DOUBLE_TO_REAL( WWMath::CosTrig( m_forwardAngle ) ) * m_forwardSpeed; + force.y = DOUBLE_TO_REAL( WWMath::SinTrig( m_forwardAngle ) ) * m_forwardSpeed; force.z = 0.0f; physics->applyMotiveForce( &force ); diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/MobMemberSlavedUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/MobMemberSlavedUpdate.cpp index c92f144f5b9..28906a069e0 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/MobMemberSlavedUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/MobMemberSlavedUpdate.cpp @@ -358,8 +358,8 @@ void MobMemberSlavedUpdate::doCatchUpLogic( Coord3D *pos ) Real randomDirection = GameLogicRandomValue( 0, 2*PI ); Real randomRadius = GameLogicRandomValue( 0, data->m_noNeedToCatchUpRadius ); nuPos.set(pos); - nuPos.x += randomRadius * Cos( randomDirection ); - nuPos.y += randomRadius * Sin( randomDirection ); + nuPos.x += randomRadius * WWMath::CosTrig( randomDirection ); + nuPos.y += randomRadius * WWMath::SinTrig( randomDirection ); nuPos.z = TheTerrainLogic->getGroundHeight( nuPos.x, nuPos.y ); AIUpdateInterface *ai = getObject()->getAIUpdateInterface(); diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/NeutronMissileUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/NeutronMissileUpdate.cpp index 9bf55521dde..0489077e0a7 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/NeutronMissileUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/NeutronMissileUpdate.cpp @@ -294,7 +294,7 @@ static Real calcTransform(const Object* obj, const Coord3D *pos, Real maxTurnRat else if (c > 1.0) c = 1.0; - Real angle = (Real)ACos( c ); + Real angle = (Real)WWMath::Acos( c ); Vector3 newDir; if (fabs(angle) < maxTurnRate) @@ -418,7 +418,7 @@ void NeutronMissileUpdate::doAttack() pos.z += m_vel.z; //DEBUG_LOG(("vel %f accel %f z %f",m_vel.length(),m_accel.length(), pos.z)); -//Real vm = sqrt(m_vel.x*m_vel.x+m_vel.y*m_vel.y+m_vel.z*m_vel.z); +//Real vm = WWMath::Sqrt(m_vel.x*m_vel.x+m_vel.y*m_vel.y+m_vel.z*m_vel.z); //DEBUG_LOG(("vel is %f %f %f (%f)",m_vel.x,m_vel.y,m_vel.z,vm)); getObject()->setTransformMatrix( &mx ); getObject()->setPosition( &pos ); @@ -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 980a9c525af..b0a1ba18fb4 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/ParticleUplinkCannonUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/ParticleUplinkCannonUpdate.cpp @@ -474,12 +474,12 @@ UpdateSleepTime ParticleUplinkCannonUpdate::update() //First determine the factor of time completed (ranges between 0.0 and 1.0) Real factor = (Real)(now - orbitalBirthFrame) / (Real)(orbitalDeathFrame - orbitalBirthFrame); - //We're generating a swath that travels the points between sin( -1PI ) and sin( 1PI ) + //We're generating a swath that travels the points between WWMath::SinTrig( -1PI ) and WWMath::SinTrig( 1PI ) Real radians = (factor * TWO_PI) - PI; 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::SinTrig( radians ); Real cxHeight = height * data->m_swathOfDeathAmplitude; Coord3D buildingToInitialTargetVector; @@ -501,9 +501,9 @@ UpdateSleepTime ParticleUplinkCannonUpdate::update() cartesianTargetVector.Normalize(); Real dotProduct = Vector2::Dot_Product( buildingToTargetVector, cartesianTargetVector ); - dotProduct = __min( 0.99999f, __max( -0.99999f, dotProduct ) ); //Account for numerical errors. Also, acos(-1.00000) is coming out QNAN on the superweapon general map. Heh. + dotProduct = __min( 0.99999f, __max( -0.99999f, dotProduct ) ); //Account for numerical errors. Also, WWMath::Acos(-1.00000) is coming out QNAN on the superweapon general map. Heh. - Real angle = (Real)ACos( dotProduct ); + Real angle = (Real)WWMath::Acos( dotProduct ); if( buildingToTargetVector.Y >= 0 ) { diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp index a56790b941f..40f656815ef 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp @@ -83,7 +83,7 @@ static Real angleBetweenVectors(const Coord3D& inCurDir, const Coord3D& inGoalDi Real cosine = Vector3::Dot_Product(curDir, goalDir); // bound it in case of numerical error - Real angleBetween = (Real)ACos(clamp(-1.0f, cosine, 1.0f)); + Real angleBetween = (Real)WWMath::Acos(clamp(-1.0f, cosine, 1.0f)); return angleBetween; } @@ -92,8 +92,8 @@ static Real angleBetweenVectors(const Coord3D& inCurDir, const Coord3D& inGoalDi 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)); + // back-calc it from our speed & gravity... v = WWMath::Sqrt(2*g*h) + return WWMath::Sqrt(fabs(2.0f * TheGlobalData->m_gravity * height)); } //------------------------------------------------------------------------------------------------- @@ -129,7 +129,7 @@ PhysicsBehaviorModuleData::PhysicsBehaviorModuleData() static void parseHeightToSpeed( INI* ini, void * /*instance*/, void *store, const void* /*userData*/ ) { // don't bother trying to remember how far we've fallen; instead, - // back-calc it from our speed & gravity... v = sqrt(2*g*h) + // back-calc it from our speed & gravity... v = WWMath::Sqrt(2*g*h) Real height = INI::scanReal(ini->getNextToken()); *(Real *)store = heightToSpeed(height); } @@ -636,10 +636,10 @@ 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::Sqrt(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); + Real s = WWMath::SinTrig(remainingAngle); pitchRateToUse *= s; } @@ -723,7 +723,7 @@ UpdateSleepTime PhysicsBehavior::update() // // don't bother trying to remember how far we've fallen; instead, - // we back-calc it from our speed & gravity... v = sqrt(2*g*h). + // we back-calc it from our speed & gravity... v = WWMath::Sqrt(2*g*h). // (note that m_minFallSpeedForDamage is always POSITIVE.) // // also note: since projectiles are immune to falling damage, don't @@ -817,7 +817,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::Sqrt( sqr(m_vel.x) + sqr(m_vel.y) + sqr(m_vel.z) ); } return m_velMag; } @@ -837,9 +837,9 @@ Real PhysicsBehavior::getForwardSpeed2D() const Real dot = vx + vy; Real speedSquared = vx*vx + vy*vy; -// DEBUG_ASSERTCRASH( speedSquared != 0, ("zero speedSquared will overflow sqrtf()!") );// lorenzen... sanity check +// DEBUG_ASSERTCRASH( speedSquared != 0, ("zero speedSquared will overflow WWMath::Sqrt()!") );// lorenzen... sanity check - Real speed = (Real)sqrtf( speedSquared ); + Real speed = (Real)WWMath::Sqrt( speedSquared ); if (dot >= 0.0f) return speed; @@ -862,7 +862,7 @@ Real PhysicsBehavior::getForwardSpeed3D() const Real dot = vx + vy + vz; - Real speed = (Real)sqrtf( vx*vx + vy*vy + vz*vz ); + Real speed = (Real)WWMath::Sqrt( vx*vx + vy*vy + vz*vz ); if (dot >= 0.0f) return speed; @@ -909,7 +909,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::Sqrt(m_vel.x*m_vel.x + m_vel.y*m_vel.y); if (desiredVelocity > curVelocity) { return; @@ -1194,7 +1194,7 @@ void PhysicsBehavior::onCollide( Object *other, const Coord3D *loc, const Coord3 m_lastCollidee = other->getID(); - Real dist = sqrtf(distSqr); + Real dist = WWMath::Sqrt(distSqr); Real overlap = usRadius + themRadius - dist; // if objects are coincident, dist is zero, so force would be infinite -- clearly diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/PointDefenseLaserUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/PointDefenseLaserUpdate.cpp index 1e9302a3327..c774dd264cc 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/SlavedUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/SlavedUpdate.cpp index 6ffef8dc861..7d3427c2a48 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/SlavedUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/SlavedUpdate.cpp @@ -314,8 +314,8 @@ void SlavedUpdate::doAttackLogic( const Object *target ) //Allow me to wander away from the pinnedPosition. Real randomDirection = GameLogicRandomValue( 0, 2*PI ); m_guardPointOffset.zero(); - m_guardPointOffset.x += data->m_attackWanderRange * Cos( randomDirection ); - m_guardPointOffset.y += data->m_attackWanderRange * Sin( randomDirection ); + m_guardPointOffset.x += data->m_attackWanderRange * WWMath::CosTrig( randomDirection ); + m_guardPointOffset.y += data->m_attackWanderRange * WWMath::SinTrig( randomDirection ); //Offset our pinned position by our random offset. attackPosition.x += m_guardPointOffset.x; @@ -377,8 +377,8 @@ void SlavedUpdate::doScoutLogic( const Coord3D *mastersDestination ) //Allow me to wander away from the pinnedPosition. Real randomDirection = GameLogicRandomValue( 0, 2*PI ); m_guardPointOffset.zero(); - m_guardPointOffset.x += data->m_scoutWanderRange * Cos( randomDirection ); - m_guardPointOffset.y += data->m_scoutWanderRange * Sin( randomDirection ); + m_guardPointOffset.x += data->m_scoutWanderRange * WWMath::CosTrig( randomDirection ); + m_guardPointOffset.y += data->m_scoutWanderRange * WWMath::SinTrig( randomDirection ); //Offset our pinned position by our random offset. scoutPosition.x += m_guardPointOffset.x; @@ -407,8 +407,8 @@ void SlavedUpdate::doGuardLogic( Coord3D *pinnedPosition ) // recalc where we want to be if we wander around Real randomDirection = GameLogicRandomValue( 0, 2*PI ); m_guardPointOffset.zero(); - m_guardPointOffset.x += data->m_guardMaxRange * Cos( randomDirection ); - m_guardPointOffset.y += data->m_guardMaxRange * Sin( randomDirection ); + m_guardPointOffset.x += data->m_guardMaxRange * WWMath::CosTrig( randomDirection ); + m_guardPointOffset.y += data->m_guardMaxRange * WWMath::SinTrig( randomDirection ); pinnedPosition->x += m_guardPointOffset.x; pinnedPosition->y += m_guardPointOffset.y; @@ -674,8 +674,8 @@ void SlavedUpdate::moveToNewRepairSpot() //Allow me to wander away from the pinnedPosition. Real randomDirection = GameLogicRandomValue( 0, 2*PI ); m_guardPointOffset.set( master->getPosition() ); - m_guardPointOffset.x += data->m_repairRange * Cos( randomDirection ); - m_guardPointOffset.y += data->m_repairRange * Sin( randomDirection ); + m_guardPointOffset.x += data->m_repairRange * WWMath::CosTrig( randomDirection ); + m_guardPointOffset.y += data->m_repairRange * WWMath::SinTrig( randomDirection ); m_guardPointOffset.z = TheTerrainLogic->getGroundHeight( m_guardPointOffset.x, m_guardPointOffset.y ); Real altitude = GameLogicRandomValueReal( data->m_repairMinAltitude, data->m_repairMaxAltitude ); m_guardPointOffset.z += altitude; @@ -708,8 +708,8 @@ void SlavedUpdate::startSlavedEffects( const Object *slaver ) // Decide where our pinned stray point is Real randomDirection = GameLogicRandomValue( 0, 2*PI ); m_guardPointOffset.zero(); - m_guardPointOffset.x += data->m_guardMaxRange * Cos( randomDirection ); - m_guardPointOffset.y += data->m_guardMaxRange * Sin( randomDirection ); + m_guardPointOffset.x += data->m_guardMaxRange * WWMath::CosTrig( randomDirection ); + m_guardPointOffset.y += data->m_guardMaxRange * WWMath::SinTrig( randomDirection ); // mark selves as not selectable getObject()->setStatus( MAKE_OBJECT_STATUS_MASK( OBJECT_STATUS_UNSELECTABLE ) ); diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/StealthUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/StealthUpdate.cpp index ca2af15e7dc..861b443b9be 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/StealthUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/StealthUpdate.cpp @@ -425,7 +425,7 @@ UpdateSleepTime StealthUpdate::update() } else { - draw->setEffectiveOpacity( 0.5f + ( Sin( m_pulsePhase ) * 0.5f ) ); + draw->setEffectiveOpacity( 0.5f + ( WWMath::SinTrig( m_pulsePhase ) * 0.5f ) ); // between one half and full opacity m_pulsePhase += m_pulsePhaseRate; } diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/StructureToppleUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/StructureToppleUpdate.cpp index 9b847243839..6d4dd6fca96 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/StructureToppleUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/StructureToppleUpdate.cpp @@ -158,15 +158,15 @@ void StructureToppleUpdate::beginStructureTopple(const DamageInfo *damageInfo) toppleAngle = m_toppleDirection.toAngle(); toppleAngle += GameLogicRandomValueReal(-PI/8, PI/8); } - m_toppleDirection.x = Cos(toppleAngle); - m_toppleDirection.y = Sin(toppleAngle); + m_toppleDirection.x = WWMath::CosTrig(toppleAngle); + m_toppleDirection.y = WWMath::SinTrig(toppleAngle); TheScriptEngine->adjustToppleDirection(getObject(), &m_toppleDirection); Real averageRadius = (building->getGeometryInfo().getMajorRadius() + building->getGeometryInfo().getMinorRadius()) / 2; Real explosionRadius = averageRadius * 0.90; - m_delayBurstLocation.x = building->getPosition()->x + explosionRadius * Cos(toppleAngle); - m_delayBurstLocation.y = building->getPosition()->y + explosionRadius * Sin(toppleAngle); + m_delayBurstLocation.x = building->getPosition()->x + explosionRadius * WWMath::CosTrig(toppleAngle); + m_delayBurstLocation.y = building->getPosition()->y + explosionRadius * WWMath::SinTrig(toppleAngle); m_delayBurstLocation.z = TheTerrainLogic->getGroundHeight(m_delayBurstLocation.x, m_delayBurstLocation.y); doToppleStartFX(building, damageInfo); @@ -231,7 +231,7 @@ UpdateSleepTime StructureToppleUpdate::update() // The building is in the process of falling over. if (m_toppleState == TOPPLESTATE_TOPPLING) { UnsignedInt now = TheGameLogic->getFrame(); - Real toppleAcceleration = TOPPLE_ACCELERATION_FACTOR * (Sin(m_accumulatedAngle) * (1.0 - m_structuralIntegrity)); + Real toppleAcceleration = TOPPLE_ACCELERATION_FACTOR * (WWMath::SinTrig(m_accumulatedAngle) * (1.0 - m_structuralIntegrity)); // DEBUG_LOG(("toppleAcceleration = %f", toppleAcceleration)); m_toppleVelocity += toppleAcceleration; // DEBUG_LOG(("m_toppleVelocity = %f", m_toppleVelocity)); @@ -368,8 +368,8 @@ void StructureToppleUpdate::applyCrushingDamage(Real theta) // Do this because the amount of ground that is affected will be different if the building falls // in different orientations. Real angle = orientationAngle - toppleAngle; - Real minorComponent = building->getGeometryInfo().getMinorRadius() * Cos(angle); - Real majorComponent = building->getGeometryInfo().getMajorRadius() * Sin(angle); + Real minorComponent = building->getGeometryInfo().getMinorRadius() * WWMath::CosTrig(angle); + Real majorComponent = building->getGeometryInfo().getMajorRadius() * WWMath::SinTrig(angle); Coord3D temp3D; temp3D.x = majorComponent; @@ -385,7 +385,7 @@ void StructureToppleUpdate::applyCrushingDamage(Real theta) } // The furthest away from the base of the building to explode on. - Real maxDistance = m_buildingHeight * (1.0 - Sin(theta)); + Real maxDistance = m_buildingHeight * (1.0 - WWMath::SinTrig(theta)); /* * Fire explosions at regular intervals across the area that the building is currently @@ -396,14 +396,14 @@ void StructureToppleUpdate::applyCrushingDamage(Real theta) // Coord3D target; Real j = m_lastCrushedLocation; for (; j < maxDistance; j += WEAPON_SPACING_PERPENDICULAR) { - jcos = j * Cos(toppleAngle); - jsin = j * Sin(toppleAngle); + jcos = j * WWMath::CosTrig(toppleAngle); + jsin = j * WWMath::SinTrig(toppleAngle); doDamageLine(building, wt, jcos, jsin, facingWidth, toppleAngle); } - jcos = maxDistance * Cos(toppleAngle); - jsin = maxDistance * Sin(toppleAngle); + jcos = maxDistance * WWMath::CosTrig(toppleAngle); + jsin = maxDistance * WWMath::SinTrig(toppleAngle); doDamageLine(building, wt, jcos, jsin, facingWidth, toppleAngle); m_lastCrushedLocation = j; @@ -424,8 +424,8 @@ void StructureToppleUpdate::doDamageLine(Object *building, const WeaponTemplate* for (Real i = -facingWidth; i < facingWidth; i += WEAPON_SPACING_PARALLEL) { - target.x = building->getPosition()->x + jcos + (i * Sin(toppleAngle)); - target.y = building->getPosition()->y + jsin + (i * Cos(toppleAngle)); + target.x = building->getPosition()->x + jcos + (i * WWMath::SinTrig(toppleAngle)); + target.y = building->getPosition()->y + jsin + (i * WWMath::CosTrig(toppleAngle)); target.z = TheTerrainLogic->getGroundHeight(target.x, target.y); TheWeaponStore->createAndFireTempWeapon(wt, building, &target); @@ -436,8 +436,8 @@ void StructureToppleUpdate::doDamageLine(Object *building, const WeaponTemplate* } // Make sure there are weapons fired and FX done on the edge of the building. - target.x = building->getPosition()->x + jcos + (facingWidth * Sin(toppleAngle)); - target.y = building->getPosition()->y + jsin + (facingWidth * Cos(toppleAngle)); + target.x = building->getPosition()->x + jcos + (facingWidth * WWMath::SinTrig(toppleAngle)); + target.y = building->getPosition()->y + jsin + (facingWidth * WWMath::CosTrig(toppleAngle)); target.z = TheTerrainLogic->getGroundHeight(target.x, target.y); TheWeaponStore->createAndFireTempWeapon(wt, building, &target); diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/ToppleUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/ToppleUpdate.cpp index bd725493a58..860ae339cec 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/ToppleUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/ToppleUpdate.cpp @@ -185,13 +185,13 @@ 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 toppleAngle = angleClosestTo(curAngleX + PI/2, curAngleX - PI/2, toppleAngle); - m_toppleDirection.x = Cos(toppleAngle); - m_toppleDirection.y = Sin(toppleAngle); + m_toppleDirection.x = WWMath::CosTrig(toppleAngle); + m_toppleDirection.y = WWMath::SinTrig(toppleAngle); // go ahead and remove it from the pathfinder now, rather than waiting for the topple to // finish.... since we might be in a slightly different position when toppled, which can diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/WaveGuideUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/WaveGuideUpdate.cpp index 9ee80c51bee..2ae049b6bc6 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/WaveGuideUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/WaveGuideUpdate.cpp @@ -718,8 +718,8 @@ void WaveGuideUpdate::doDamage() // angle is rotated, because we computed from 'from' and 'to' points of // the bridge going *across* the valley, not pointing *down* it // - u.x = Cos( angle + modData->m_bridgeParticleAngleFudge ); - u.y = Sin( angle + modData->m_bridgeParticleAngleFudge ); + u.x = WWMath::CosTrig( angle + modData->m_bridgeParticleAngleFudge ); + u.y = WWMath::SinTrig( angle + modData->m_bridgeParticleAngleFudge ); u.z = 0.0f; y.crossProduct( &z, &u, &y ); diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp index 2fdd9fa4dbf..404069b1fce 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp @@ -825,7 +825,7 @@ UnsignedInt WeaponTemplate::fireWeaponTemplate Real attackRangeSqr = sqr(getAttackRange(bonus)); if (distSqr > attackRangeSqr) { - //DEBUG_ASSERTCRASH(distSqr < 5*5 || distSqr < attackRangeSqr*1.2f, ("*** victim is out of range (%f vs %f) of this weapon -- why did we attempt to fire?",sqrtf(distSqr),sqrtf(attackRangeSqr))); + //DEBUG_ASSERTCRASH(distSqr < 5*5 || distSqr < attackRangeSqr*1.2f, ("*** victim is out of range (%f vs %f) of this weapon -- why did we attempt to fire?",WWMath::Sqrt(distSqr),WWMath::Sqrt(attackRangeSqr))); //-extraLogging #if defined(RTS_DEBUG) @@ -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::Sqrt(distSqr),WWMath::Sqrt(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); @@ -1051,8 +1051,8 @@ UnsignedInt WeaponTemplate::fireWeaponTemplate Coord3D firingOffset; firingOffset.zero(); - firingOffset.x = scatterRadius * Cos( scatterAngleRadian ); - firingOffset.y = scatterRadius * Sin( scatterAngleRadian ); + firingOffset.x = scatterRadius * WWMath::CosTrig( scatterAngleRadian ); + firingOffset.y = scatterRadius * WWMath::SinTrig( scatterAngleRadian ); projectileDestination.x += firingOffset.x; projectileDestination.y += firingOffset.y; @@ -1920,7 +1920,7 @@ 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; @@ -1933,9 +1933,9 @@ Bool Weapon::computeApproachTarget(const Object *source, const Object *target, c if (angleOffset != 0.0f) { - Real angle = atan2(dir.y, dir.x); - dir.x = (Real)Cos(angle + angleOffset); - dir.y = (Real)Sin(angle + angleOffset); + Real angle = WWMath::Atan2(dir.y, dir.x); + dir.x = (Real)WWMath::CosTrig(angle + angleOffset); + dir.y = (Real)WWMath::SinTrig(angle + angleOffset); } // select a spot along the line between us, halfway between the min & max range. @@ -1980,9 +1980,9 @@ Bool Weapon::computeApproachTarget(const Object *source, const Object *target, c if (angleOffset != 0.0f) { - Real angle = atan2(dir.y, dir.x); - dir.x = (Real)Cos(angle + angleOffset); - dir.y = (Real)Sin(angle + angleOffset); + Real angle = WWMath::Atan2(dir.y, dir.x); + dir.x = (Real)WWMath::CosTrig(angle + angleOffset); + dir.y = (Real)WWMath::SinTrig(angle + angleOffset); } // select a spot along the line between us, in range of our weapon diff --git a/Generals/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptEngine.cpp b/Generals/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptEngine.cpp index 7775245e531..cc9783611da 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptEngine.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptEngine.cpp @@ -4584,8 +4584,8 @@ void ScriptEngine::reset() } m_breezeInfo.m_direction = PI/3; - m_breezeInfo.m_directionVec.x = Sin(m_breezeInfo.m_direction); - m_breezeInfo.m_directionVec.y = Cos(m_breezeInfo.m_direction); + m_breezeInfo.m_directionVec.x = WWMath::SinTrig(m_breezeInfo.m_direction); + m_breezeInfo.m_directionVec.y = WWMath::CosTrig(m_breezeInfo.m_direction); m_breezeInfo.m_intensity = 0.07f*PI/4; m_breezeInfo.m_lean = 0.07f*PI/4; m_breezeInfo.m_breezePeriod = LOGICFRAMES_PER_SECOND * 5; @@ -5707,8 +5707,8 @@ void ScriptEngine::setSway( ScriptAction *pAction ) DEBUG_ASSERTCRASH(pAction->getNumParameters() >= 5, ("Not enough parameters.")); ++m_breezeInfo.m_breezeVersion; m_breezeInfo.m_direction = pAction->getParameter(0)->getReal(); - m_breezeInfo.m_directionVec.x = Sin(m_breezeInfo.m_direction); - m_breezeInfo.m_directionVec.y = Cos(m_breezeInfo.m_direction); + m_breezeInfo.m_directionVec.x = WWMath::SinTrig(m_breezeInfo.m_direction); + m_breezeInfo.m_directionVec.y = WWMath::CosTrig(m_breezeInfo.m_direction); m_breezeInfo.m_intensity = pAction->getParameter(1)->getReal(); m_breezeInfo.m_lean = pAction->getParameter(2)->getReal(); m_breezeInfo.m_breezePeriod = pAction->getParameter(3)->getInt(); diff --git a/Generals/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp b/Generals/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp index 780bdfff8a2..8cb922c2862 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp @@ -805,7 +805,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/W3DDisplay.cpp b/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp index 97770f6ab10..75eef81659d 100644 --- a/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp +++ b/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp @@ -80,7 +80,7 @@ static void drawFramerateBar(); #include "W3DDevice/GameClient/W3DDebugDisplay.h" #include "W3DDevice/GameClient/W3DProjectedShadow.h" #include "W3DDevice/GameClient/W3DShroud.h" -#include "WWMath/wwmath.h" +#include "wwmath.h" #include "WWLib/registry.h" #include "WW3D2/ww3d.h" #include "WW3D2/predlod.h" diff --git a/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DParticleSys.cpp b/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DParticleSys.cpp index adb44f0d3b3..b2096866ce6 100644 --- a/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DParticleSys.cpp +++ b/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DParticleSys.cpp @@ -313,8 +313,8 @@ void W3DParticleSystemManager::doParticles(RenderInfoClass &rinfo) Coord3D worldStart, worldEnd; ICoord2D pixelStart, pixelEnd; sys->getPosition( &worldStart ); - worldEnd.x = Cos( sys->getWindAngle() ) * 50.0f + worldStart.x; - worldEnd.y = Sin( sys->getWindAngle() ) * 50.0f + worldStart.y; + worldEnd.x = WWMath::Cos( sys->getWindAngle() ) * 50.0f + worldStart.x; + worldEnd.y = WWMath::Sin( sys->getWindAngle() ) * 50.0f + worldStart.y; worldEnd.z = worldStart.z; TheTacticalView->worldToScreen( &worldStart, &pixelStart ); TheTacticalView->worldToScreen( &worldEnd, &pixelEnd ); diff --git a/Generals/Code/Tools/GUIEdit/Source/Dialog Procedures/TabControlProperties.cpp b/Generals/Code/Tools/GUIEdit/Source/Dialog Procedures/TabControlProperties.cpp index 10790580990..a47b6ddaabe 100644 --- a/Generals/Code/Tools/GUIEdit/Source/Dialog Procedures/TabControlProperties.cpp +++ b/Generals/Code/Tools/GUIEdit/Source/Dialog Procedures/TabControlProperties.cpp @@ -334,8 +334,8 @@ static LRESULT CALLBACK tabControlPropertiesCallback( HWND hWndDialog, tabData->tabEdge = TP_BOTTOM_SIDE; //safeties - tabData->tabCount = max( tabData->tabCount, 1 ); - tabData->tabCount = min( tabData->tabCount, NUM_TAB_PANES ); + tabData->tabCount = max( tabData->tabCount, (Int)1 ); + tabData->tabCount = min( tabData->tabCount, (Int)NUM_TAB_PANES ); GadgetTabControlComputeTabRegion( tabControl ); GadgetTabControlResizeSubPanes( tabControl ); diff --git a/GeneralsMD/Code/GameEngine/CMakeLists.txt b/GeneralsMD/Code/GameEngine/CMakeLists.txt index 3b6d674c2b4..6d939511d5d 100644 --- a/GeneralsMD/Code/GameEngine/CMakeLists.txt +++ b/GeneralsMD/Code/GameEngine/CMakeLists.txt @@ -659,7 +659,7 @@ set(GAMEENGINE_SRC Source/Common/System/StackDump.cpp # Source/Common/System/StreamingArchiveFile.cpp # Source/Common/System/SubsystemInterface.cpp - Source/Common/System/Trig.cpp + # Source/Common/System/UnicodeString.cpp Source/Common/System/Upgrade.cpp # Source/Common/System/Xfer.cpp diff --git a/GeneralsMD/Code/GameEngine/Source/Common/System/BuildAssistant.cpp b/GeneralsMD/Code/GameEngine/Source/Common/System/BuildAssistant.cpp index 725e921edda..bede536e6f5 100644 --- a/GeneralsMD/Code/GameEngine/Source/Common/System/BuildAssistant.cpp +++ b/GeneralsMD/Code/GameEngine/Source/Common/System/BuildAssistant.cpp @@ -31,6 +31,8 @@ // USER INCLUDES ////////////////////////////////////////////////////////////////////////////////// #include "PreRTS.h" // This must go first in EVERY cpp file in the GameEngine +#include "wwmath.h" + #include "Common/BuildAssistant.h" #include "Common/GlobalData.h" #include "Common/Player.h" @@ -806,8 +808,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 = WWMath::CosTrig(angle); + Real s = WWMath::SinTrig(angle); Real offset = build->getTemplateGeometryInfo().getMajorRadius() + myFactoryExitWidth/2.0f; myExitPos.x += c*offset; myExitPos.y += s*offset; @@ -854,8 +856,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 = WWMath::CosTrig(them->getOrientation()); + Real s = WWMath::SinTrig(them->getOrientation()); Real offset = them->getGeometryInfo().getMajorRadius() + themFactoryExitWidth/2.0f; hisExitPos.x += c*offset; hisExitPos.y += s*offset; @@ -1435,7 +1437,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(gi.getMajorRadius() * gi.getMajorRadius() + gi.getMinorRadius() * gi.getMinorRadius()); 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 b69c01de560..11c844e6209 100644 --- a/GeneralsMD/Code/GameEngine/Source/Common/System/Geometry.cpp +++ b/GeneralsMD/Code/GameEngine/Source/Common/System/Geometry.cpp @@ -31,6 +31,7 @@ #define DEFINE_GEOMETRY_NAMES // USER INCLUDES ////////////////////////////////////////////////////////////////////////////////// +#include "wwmath.h" #include "Common/Geometry.h" #include "Common/INI.h" #include "Common/RandomValue.h" @@ -173,17 +174,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 +280,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 = WWMath::CosTrig(angle); + Real s = WWMath::SinTrig(angle); Real exc = m_majorRadius*c; Real eyc = m_minorRadius*c; Real exs = m_majorRadius*s; @@ -329,7 +330,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 +362,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; } @@ -398,8 +399,8 @@ void GeometryInfo::makeRandomOffsetWithinFootprint(Coord3D& pt) const #else Real radius = GameLogicRandomValueReal(0.0f, m_boundingCircleRadius); Real angle = GameLogicRandomValueReal(-PI, PI); - pt.x = radius * Cos(angle); - pt.y = radius * Sin(angle); + pt.x = radius * WWMath::CosTrig(angle); + pt.y = radius * WWMath::SinTrig(angle); pt.z = 0.0f; #endif break; @@ -506,8 +507,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 deleted file mode 100644 index 2ffb79bbae2..00000000000 --- a/GeneralsMD/Code/GameEngine/Source/Common/System/Trig.cpp +++ /dev/null @@ -1,145 +0,0 @@ -/* -** Command & Conquer Generals Zero Hour(tm) -** Copyright 2025 Electronic Arts Inc. -** -** 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 . -*/ - -//////////////////////////////////////////////////////////////////////////////// -// // -// (c) 2001-2003 Electronic Arts Inc. // -// // -//////////////////////////////////////////////////////////////////////////////// - -// Trig.cpp -// fast trig functions -// Author: Michael S. Booth, March 1994 -// Converted to Generals by Matthew D. Campbell, February 2002 - -#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); -} - -#ifdef REGENERATE_TRIG_TABLES -void initTrig() -{ - 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; igetGeometryInfo().getMajorRadius(); Real width = obj->getGeometryInfo().getMinorRadius(); - Real pitchHeight = length*Sin(m_locoInfo->m_pitch + m_locoInfo->m_accelerationPitch - groundPitch); - Real rollHeight = width*Sin(m_locoInfo->m_roll + m_locoInfo->m_accelerationRoll - groundRoll); + Real pitchHeight = length*WWMath::Sin(m_locoInfo->m_pitch + m_locoInfo->m_accelerationPitch - groundPitch); + Real rollHeight = width*WWMath::Sin(m_locoInfo->m_roll + m_locoInfo->m_accelerationRoll - groundRoll); info.m_totalZ = fabs(pitchHeight)/4 + fabs(rollHeight)/4; return; // maintain the same orientation while we fly through the air. } @@ -2056,8 +2056,8 @@ void Drawable::calcPhysicsXformWheels( const Locomotor *locomotor, PhysicsXformI // Calculate suspension info. Real length = obj->getGeometryInfo().getMajorRadius(); Real width = obj->getGeometryInfo().getMinorRadius(); - Real pitchHeight = length*Sin(info.m_totalPitch-groundPitch); - Real rollHeight = width*Sin(info.m_totalRoll-groundRoll); + Real pitchHeight = length*WWMath::Sin(info.m_totalPitch-groundPitch); + Real rollHeight = width*WWMath::Sin(info.m_totalRoll-groundRoll); if (DO_WHEELS) { // calculate each wheel position @@ -2257,8 +2257,8 @@ void Drawable::calcPhysicsXformMotorcycle( const Locomotor *locomotor, PhysicsXf // Calculate suspension info. Real length = obj->getGeometryInfo().getMajorRadius(); //Real width = obj->getGeometryInfo().getMinorRadius(); - Real pitchHeight = length*Sin(m_locoInfo->m_pitch + m_locoInfo->m_accelerationPitch - groundPitch); - //Real rollHeight = width*Sin(m_locoInfo->m_roll + m_locoInfo->m_accelerationRoll - groundRoll); + Real pitchHeight = length*WWMath::Sin(m_locoInfo->m_pitch + m_locoInfo->m_accelerationPitch - groundPitch); + //Real rollHeight = width*WWMath::Sin(m_locoInfo->m_roll + m_locoInfo->m_accelerationRoll - groundRoll); info.m_totalZ = fabs(pitchHeight)/4;// + fabs(rollHeight)/4; //return; // maintain the same orientation while we fly through the air. } @@ -2363,8 +2363,8 @@ void Drawable::calcPhysicsXformMotorcycle( const Locomotor *locomotor, PhysicsXf // Calculate suspension info. Real length = obj->getGeometryInfo().getMajorRadius(); Real width = obj->getGeometryInfo().getMinorRadius(); - Real pitchHeight = length*Sin(info.m_totalPitch-groundPitch); - Real rollHeight = width*Sin(info.m_totalRoll-groundRoll); + Real pitchHeight = length*WWMath::Sin(info.m_totalPitch-groundPitch); + Real rollHeight = width*WWMath::Sin(info.m_totalRoll-groundRoll); if (DO_WHEELS) { // calculate each wheel position @@ -4195,8 +4195,8 @@ Bool Drawable::handleWeaponFireFX(WeaponSlotType wslot, Int specificBarrelToUse, recoilAngle += PI; if (m_locoInfo) { - m_locoInfo->m_accelerationPitchRate += recoilAmount * Cos(recoilAngle); - m_locoInfo->m_accelerationRollRate += recoilAmount * Sin(recoilAngle); + m_locoInfo->m_accelerationPitchRate += recoilAmount * WWMath::Cos(recoilAngle); + m_locoInfo->m_accelerationRollRate += recoilAmount * WWMath::Sin(recoilAngle); } } diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable/Update/SwayClientUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable/Update/SwayClientUpdate.cpp index 874b6f74548..fafafc4e380 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable/Update/SwayClientUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable/Update/SwayClientUpdate.cpp @@ -121,7 +121,7 @@ void SwayClientUpdate::clientUpdate() m_curValue += m_curDelta * timeScale; if (m_curValue > 2*PI) m_curValue -= 2*PI; - Real cosine = Cos(m_curValue); + Real cosine = WWMath::Cos(m_curValue); Real targetAngle = cosine * m_curAngleLimit + m_leanAngle; Real deltaAngle = targetAngle - m_curAngle; diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AI.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AI.cpp index 24b9a999ef7..e5a9dd3188b 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AI.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AI.cpp @@ -709,7 +709,7 @@ Object *AI::findClosestEnemy( const Object *me, Real range, UnsignedInt qualifie } Real distSqr = ThePartitionManager->getDistanceSquared(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 fbcc7cf02fb..fac9a55a86a 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIGroup.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIGroup.cpp @@ -27,6 +27,7 @@ // Author: Michael S. Booth, January 2002 #include "PreRTS.h" // This must go first in EVERY cpp file in the GameEngine +#include "wwmath.h" #include "Common/ActionManager.h" #include "Common/BuildAssistant.h" @@ -1883,8 +1884,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::SinTrig(angle) * radius); + posOut.y = tempCtr.y + (WWMath::CosTrig(angle) * radius); } diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp index ad587dd12fe..724a4a9c6c0 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp @@ -647,7 +647,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; @@ -1354,7 +1354,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)) @@ -3139,7 +3139,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..10b9b113fb7 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AISkirmishPlayer.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AISkirmishPlayer.cpp @@ -28,6 +28,7 @@ #include "PreRTS.h" // This must go first in EVERY cpp file in the GameEngine +#include "wwmath.h" #include "Common/GameMemory.h" #include "Common/GlobalData.h" @@ -672,8 +673,8 @@ void AISkirmishPlayer::buildAIBaseDefenseStructure(const AsciiString &thingName, } if (angle > PI/3) break; - Real s = sin(angle); - Real c = cos(angle); + Real s = WWMath::SinTrig(angle); + Real c = WWMath::CosTrig(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 +1039,8 @@ void AISkirmishPlayer::adjustBuildList(BuildListInfo *list) angle += 3*PI/4; - Real s = sin(angle); - Real c = cos(angle); + Real s = WWMath::SinTrig(angle); + Real c = WWMath::CosTrig(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 ed72618ea52..ca567913d1d 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp @@ -27,6 +27,7 @@ // Author: Michael S. Booth, January 2002 #include "PreRTS.h" // This must go first in EVERY cpp file in the GameEngine +#include "wwmath.h" #include "Common/ActionManager.h" #include "Common/AudioHandleSpecialValues.h" @@ -607,8 +608,8 @@ StateReturnType AIRappelState::update() bldg->getGeometryInfo().getBoundingCircleRadius()); Real angle = GameLogicRandomValueReal( PI, 2*PI );//Downish. Coord3D startPosition = *bldg->getPosition(); - startPosition.x += offset * Cos( angle ); - startPosition.y += offset * Sin( angle ); + startPosition.x += offset * WWMath::CosTrig( angle ); + startPosition.y += offset * WWMath::SinTrig( angle ); startPosition.z = TheTerrainLogic->getGroundHeight( startPosition.x, startPosition.y ); obj->setPosition( &startPosition ); @@ -3674,7 +3675,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 +3905,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::SinTrig(deltaAngle); + Real c = WWMath::CosTrig(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 diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/TurretAI.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/TurretAI.cpp index 78395baf998..6514b1a23ac 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/TurretAI.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/TurretAI.cpp @@ -1115,7 +1115,7 @@ StateReturnType TurretAIAimTurretState::update() Real actualPitch; if( v.length() > 0 ) - actualPitch = ASin( v.z / v.length() ); + actualPitch = WWMath::Asin( v.z / v.length() ); else actualPitch = 0;// Don't point at NAN, just point at 0 if they are right on us 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 d6144eb2bdb..2cb9302f411 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Map/TerrainLogic.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Map/TerrainLogic.cpp @@ -339,8 +339,8 @@ Bridge::Bridge(Object *bridgeObj) Real halfsizeY = bridgeObj->getGeometryInfo().getMinorRadius(); m_bridgeInfo.bridgeWidth = 2*halfsizeY; - Real c = (Real)Cos(angle); - Real s = (Real)Sin(angle); + Real c = (Real)WWMath::CosTrig(angle); + Real s = (Real)WWMath::SinTrig(angle); m_bridgeInfo.fromLeft.set(pos->x-halfsizeX*c-halfsizeY*s, pos->y + halfsizeY*c - halfsizeX*s, pos->z); m_bridgeInfo.toLeft.set(pos->x+halfsizeX*c-halfsizeY*s, pos->y + halfsizeY*c + halfsizeX*s, pos->z); @@ -1468,11 +1468,11 @@ 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 ); - x.y = Sin( angle ); + x.x = WWMath::CosTrig( angle ); + x.y = WWMath::SinTrig( angle ); x.z = 0.0f; //x.normalize(); -- redundant; is normalized by definition @@ -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 @@ -2652,8 +2652,8 @@ void TerrainLogic::flattenTerrain(Object *obj) Real halfsizeY = obj->getGeometryInfo().getMinorRadius(); - Real c = (Real)Cos(angle); - Real s = (Real)Sin(angle); + Real c = (Real)WWMath::CosTrig(angle); + Real s = (Real)WWMath::SinTrig(angle); Vector3 topLeft(pos->x-halfsizeX*c-halfsizeY*s, pos->y + halfsizeY*c - halfsizeX*s, 0); Vector3 topRight(pos->x+halfsizeX*c-halfsizeY*s, pos->y + halfsizeY*c + halfsizeX*s, 0); @@ -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..f4682aef1f0 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/DumbProjectileBehavior.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/DumbProjectileBehavior.cpp @@ -172,11 +172,11 @@ 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) @@ -185,7 +185,7 @@ static Bool calcTrajectory( // 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; @@ -194,7 +194,7 @@ static Bool calcTrajectory( Real t = horizDist / velocity; Real vz = (dz/t + 0.5f*gravity*t); Real sineOfAngle = clamp(-1.0f, vz / velocity, 1.0f); - theta = ASin(sineOfAngle)*0.5f; + theta = WWMath::Asin(sineOfAngle)*0.5f; } /* @@ -206,7 +206,7 @@ static Bool calcTrajectory( { return false; } - Real theta = ASin(sineOfAngle)*0.5f; + Real theta = WWMath::Asin(sineOfAngle)*0.5f; */ Real pitches[2]; @@ -228,10 +228,10 @@ static Bool calcTrajectory( // calc the horiz-speed & time for each. // note that time can only be negative for 90getMinimumAttackRange(); 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; } @@ -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::Sqrt(distVictimMovedSqr); if (distVictimMoved > d->m_flightPathAdjustDistPerFrame) distVictimMoved = d->m_flightPathAdjustDistPerFrame; delta.normalize(); diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/FlightDeckBehavior.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/FlightDeckBehavior.cpp index 07714caafff..3e74324901b 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/FlightDeckBehavior.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/FlightDeckBehavior.cpp @@ -494,8 +494,8 @@ Bool FlightDeckBehavior::reserveSpace(ObjectID id, Real parkingOffset, ParkingPl calcPPInfo( id, info ); if (parkingOffset != 0.0f) { - info->parkingSpace.x += parkingOffset * Cos(ppi->m_orientation); - info->parkingSpace.y += parkingOffset * Sin(ppi->m_orientation); + info->parkingSpace.x += parkingOffset * WWMath::CosTrig(ppi->m_orientation); + info->parkingSpace.y += parkingOffset * WWMath::SinTrig(ppi->m_orientation); } } diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/GenerateMinefieldBehavior.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/GenerateMinefieldBehavior.cpp index 03194dc1981..cde2478cf06 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; @@ -320,8 +320,8 @@ void GenerateMinefieldBehavior::placeMinesAroundCircle(const Coord3D& pos, Real for (Real angle = 0; angle < angleLim; angle += angleInc) { Coord3D pt; - pt.x = pos.x + radius * Cos(angle); - pt.y = pos.y + radius * Sin(angle); + pt.x = pos.x + radius * WWMath::CosTrig(angle); + pt.y = pos.y + radius * WWMath::SinTrig(angle); pt.z = TheTerrainLogic->getGroundHeight( pt.x, pt.y ); offsetBySmallRandomAmount(pt, mineJitter); placeMineAt(pt, mineTemplate, team, obj); diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/MinefieldBehavior.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/MinefieldBehavior.cpp index 7bdecb3be0d..7ffc6e7d3bc 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::Sqrt(2.0f * (start.z - endOnGround.z) / 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,7 +588,7 @@ 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)); + Real dist = WWMath::Sqrt(sqr(dx) + sqr(dy)); if (dist <= 0.1f && fabs(dz) <= 0.1f) { obj->setPosition(&endOnGround); diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/ParkingPlaceBehavior.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/ParkingPlaceBehavior.cpp index 64338846eef..2d74564acd5 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/ParkingPlaceBehavior.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/ParkingPlaceBehavior.cpp @@ -354,8 +354,8 @@ Bool ParkingPlaceBehavior::reserveSpace(ObjectID id, Real parkingOffset, Parking calcPPInfo( id, info ); if (parkingOffset != 0.0f) { - info->parkingSpace.x += parkingOffset * Cos(ppi->m_orientation); - info->parkingSpace.y += parkingOffset * Sin(ppi->m_orientation); + info->parkingSpace.x += parkingOffset * WWMath::CosTrig(ppi->m_orientation); + info->parkingSpace.y += parkingOffset * WWMath::SinTrig(ppi->m_orientation); } } 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<pathfinder()->validMovementTerrain( LAYER_GROUND, loco, &startPosition)) { // try front & back. Real offset = getObject()->getGeometryInfo().getMajorRadius(); - startPosition.x -= offset*Cos(exitAngle); - startPosition.y -= offset*Sin(exitAngle); + startPosition.x -= offset*WWMath::CosTrig(exitAngle); + startPosition.y -= offset*WWMath::SinTrig(exitAngle); if (!TheAI->pathfinder()->validMovementTerrain(LAYER_GROUND, loco, &startPosition)) { - startPosition.x += 2*offset*Cos(exitAngle); - startPosition.y += 2*offset*Sin(exitAngle); + startPosition.x += 2*offset*WWMath::CosTrig(exitAngle); + startPosition.y += 2*offset*WWMath::SinTrig(exitAngle); if (!TheAI->pathfinder()->validMovementTerrain(LAYER_GROUND, loco, &startPosition)) { startPosition = *getObject()->getPosition(); } diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Contain/OpenContain.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Contain/OpenContain.cpp index 0da2deb1da7..9935e137d7d 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Contain/OpenContain.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Contain/OpenContain.cpp @@ -737,8 +737,8 @@ void OpenContain::scatterToNearbyPosition(Object* rider) Real dist = GameLogicRandomValueReal( minRadius, maxRadius ); Coord3D pos; - pos.x = dist * Cos( angle ) + containerPos->x; - pos.y = dist * Sin( angle ) + containerPos->y; + pos.x = dist * WWMath::CosTrig( angle ) + containerPos->x; + pos.y = dist * WWMath::SinTrig( angle ) + containerPos->y; pos.z = TheTerrainLogic->getLayerHeight( pos.x, pos.y, theContainer->getLayer() ); // set orientation diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Contain/TunnelContain.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Contain/TunnelContain.cpp index c15eefa1712..1770947121a 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Contain/TunnelContain.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Contain/TunnelContain.cpp @@ -372,8 +372,8 @@ void TunnelContain::scatterToNearbyPosition(Object* obj) Real dist = GameLogicRandomValueReal( minRadius, maxRadius ); Coord3D pos; - pos.x = dist * Cos( angle ) + containerPos->x; - pos.y = dist * Sin( angle ) + containerPos->y; + pos.x = dist * WWMath::CosTrig( angle ) + containerPos->x; + pos.y = dist * WWMath::SinTrig( angle ) + containerPos->y; pos.z = TheTerrainLogic->getGroundHeight( pos.x, pos.y ); // set orientation diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp index 57392ff6db5..6832834ceed 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp @@ -35,6 +35,8 @@ #define DEFINE_LOCO_Z_NAMES #define DEFINE_LOCO_APPEARANCE_NAMES +#include "wwmath.h" + #include "Common/INI.h" #include "GameLogic/GameLogic.h" #include "GameLogic/PartitionManager.h" @@ -129,7 +131,7 @@ static Real tryToRotateVector3D( // dot of two unit vectors is cos of angle between them. Real cosine = Vector3::Dot_Product(curDir, goalDir); // bound it in case of numerical error - Real angleBetween = (Real)ACos(clamp(-1.0f, cosine, 1.0f)); + Real angleBetween = (Real)WWMath::Acos(clamp(-1.0f, cosine, 1.0f)); if (maxAngle < 0) { @@ -231,9 +233,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; @@ -887,8 +889,8 @@ void Locomotor::locoUpdate_moveTowardsAngle(Object* obj, Real goalAngle) { // can't stay in one place; move in the desired direction at min speed. Coord3D desiredPos = *obj->getPosition(); - desiredPos.x += Cos(goalAngle) * minSpeed * 2; - desiredPos.y += Sin(goalAngle) * minSpeed * 2; + desiredPos.x += WWMath::CosTrig(goalAngle) * minSpeed * 2; + desiredPos.y += WWMath::SinTrig(goalAngle) * minSpeed * 2; // pass a huge num for "dist to goal", so that we don't think we're nearing // our destination and thus slow down... const Real onPathDistToGoal = 99999.0f; @@ -902,8 +904,8 @@ void Locomotor::locoUpdate_moveTowardsAngle(Object* obj, Real goalAngle) { DEBUG_ASSERTCRASH(m_template->m_appearance != LOCO_THRUST, ("THRUST should always have minspeeds!")); Coord3D desiredPos = *obj->getPosition(); - desiredPos.x += Cos(goalAngle) * 1000.0f; - desiredPos.y += Sin(goalAngle) * 1000.0f; + desiredPos.x += WWMath::CosTrig(goalAngle) * 1000.0f; + desiredPos.y += WWMath::SinTrig(goalAngle) * 1000.0f; PhysicsTurningType rotating = rotateTowardsPosition(obj, desiredPos); physics->setTurning(rotating); handleBehaviorZ(obj, physics, *obj->getPosition()); @@ -995,7 +997,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 +1115,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; @@ -1288,7 +1290,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; @@ -1371,8 +1373,8 @@ void Locomotor::moveTowardsPositionWheels(Object* obj, PhysicsBehavior *physics, targetAngle += turnAmount; } Coord3D offset; - offset.x = Cos(targetAngle)*distance; - offset.y = Sin(targetAngle)*distance; + offset.x = WWMath::CosTrig(targetAngle)*distance; + offset.y = WWMath::SinTrig(targetAngle)*distance; offset.z = 0; const Coord3D* pos = obj->getPosition(); @@ -1563,7 +1565,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 +1629,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; @@ -1760,7 +1762,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) { @@ -1851,7 +1853,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; @@ -1861,8 +1863,8 @@ void Locomotor::moveTowardsPositionWings(Object* obj, PhysicsBehavior *physics, // project a spot "radius" dist away from it, in that dir Coord3D desiredPos = goalPos; - desiredPos.x += Cos(angleTowardPos) * turnRadius; - desiredPos.y += Sin(angleTowardPos) * turnRadius; + desiredPos.x += WWMath::CosTrig(angleTowardPos) * turnRadius; + desiredPos.y += WWMath::SinTrig(angleTowardPos) * turnRadius; moveTowardsPositionOther(obj, physics, desiredPos, 0, desiredSpeed); return; } @@ -2085,7 +2087,7 @@ Real Locomotor::calcLiftToUseAtPt(Object* obj, PhysicsBehavior *physics, Real cu // thus // a = 2(dz - v t)/t^2 // and - // t = (-v +- sqrt(v*v + 2*a*dz))/a + // t = (-v +- WWMath::Sqrt(v*v + 2*a*dz))/a // // but if we assume t=1, then // a=2(dz-v) @@ -2147,7 +2149,7 @@ PhysicsTurningType Locomotor::rotateObjAroundLocoPivot(Object* obj, const Coord3 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); + Real desiredAngle = WWMath::Atan2(dy, dx); Real amount = stdAngleDiff(desiredAngle, angle); if (relAngle) *relAngle = amount; if (amount>maxTurnRate) { @@ -2162,14 +2164,14 @@ PhysicsTurningType Locomotor::rotateObjAroundLocoPivot(Object* obj, const Coord3 #if 0 Coord3D desiredPos = *obj->getPosition(); // well, desired Dir, anyway - desiredPos.x += Cos(angle + amount) * radius; - desiredPos.y += Sin(angle + amount) * radius; + desiredPos.x += WWMath::CosTrig(angle + amount) * radius; + desiredPos.y += WWMath::SinTrig(angle + amount) * radius; // 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 +2187,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) { @@ -2519,7 +2521,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) @@ -2531,8 +2533,8 @@ void Locomotor::maintainCurrentPositionWings(Object* obj, PhysicsBehavior *physi // project a spot "radius" dist away from it, in that dir Coord3D desiredPos = m_maintainPos; - desiredPos.x += Cos(angleTowardMaintainPos) * turnRadius; - desiredPos.y += Sin(angleTowardMaintainPos) * turnRadius; + desiredPos.x += WWMath::CosTrig(angleTowardMaintainPos) * turnRadius; + desiredPos.y += WWMath::SinTrig(angleTowardMaintainPos) * turnRadius; moveTowardsPositionWings(obj, physics, desiredPos, 0, m_template->m_minSpeed); } } diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/ObjectCreationList.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/ObjectCreationList.cpp index b23d6c603ae..a6af6ae20f1 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; @@ -298,14 +298,14 @@ class DeliverPayloadNugget : public ObjectCreationNugget //Rotate 90 degrees CCW. Real radians = 90.0f * PI / 180.0f; - Real s = Sin( radians ); - Real c = Cos( radians ); + Real s = WWMath::SinTrig( radians ); + Real c = WWMath::CosTrig( radians ); CCWx = dx * c + dy * -s + dx; CCWy = dx * s + dy * c + dy; //Rotate 90 degrees CW - s = Sin( -radians ); - c = Cos( -radians ); + s = WWMath::SinTrig( -radians ); + c = WWMath::CosTrig( -radians ); CWx = dx * c + dy * -s + dx; CWy = dx * s + dy * c + dy; } @@ -352,17 +352,17 @@ class DeliverPayloadNugget : public ObjectCreationNugget { Real randomRadius = GameLogicRandomValueReal(0, m_errorRadius ); Real randomAngle = GameLogicRandomValueReal(0, PI*2 ); - targetPos.x += randomRadius * Cos( randomAngle ); - targetPos.y += randomRadius * Sin( randomAngle ); + targetPos.x += randomRadius * WWMath::CosTrig( randomAngle ); + targetPos.y += randomRadius * WWMath::SinTrig( randomAngle ); } - 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; - startPos.x -= Cos(orient) * m_data.m_distToTarget * SLOP; - startPos.y -= Sin(orient) * m_data.m_distToTarget * SLOP; + startPos.x -= WWMath::CosTrig(orient) * m_data.m_distToTarget * SLOP; + startPos.y -= WWMath::SinTrig(orient) * m_data.m_distToTarget * SLOP; } Object *transport; @@ -1105,7 +1105,7 @@ class GenericObjectCreationNugget : public ObjectCreationNugget objUp->applyForce(&force); if (m_orientInForceDirection) - orientation = atan2(force.y, force.x); + orientation = WWMath::Atan2(force.y, force.x); } } @@ -1193,7 +1193,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 8d7c8402e3a..7be52d19a44 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cpp @@ -49,6 +49,8 @@ //----------------------------------------------------------------------------- #include "PreRTS.h" // This must go first in EVERY cpp file in the GameEngine +#include "wwmath.h" + #include "Common/ActionManager.h" #include "Common/DiscreteCircle.h" #include "Common/GameEngine.h" @@ -405,8 +407,8 @@ static void testRotatedPointsAgainstRect( Real major = a->geom.getMajorRadius(); Real minor = (a->geom.getGeomType() == GEOMETRY_SPHERE) ? a->geom.getMajorRadius() : a->geom.getMinorRadius(); - Real c = (Real)Cos(-a->angle); - Real s = (Real)Sin(-a->angle); + Real c = (Real)WWMath::CosTrig(-a->angle); + Real s = (Real)WWMath::SinTrig(-a->angle); for (Int i = 0; i < 4; ++i, ++pts) { @@ -439,8 +441,8 @@ static void rectToFourPoints( Coord2D pts[] ) { - Real c = (Real)Cos(a->angle); - Real s = (Real)Sin(a->angle); + Real c = (Real)WWMath::CosTrig(a->angle); + Real s = (Real)WWMath::SinTrig(a->angle); Real exc = a->geom.getMajorRadius()*c; Real eyc = a->geom.getMinorRadius()*c; @@ -621,7 +623,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::Sqrt(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 +641,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::Sqrt(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 +829,7 @@ static Bool distCalcProc_BoundaryAndBoundary_2D( if (totalRad > 0.0f) { - Real actualDist = sqrtf(actualDistSqr); + Real actualDist = WWMath::Sqrt(actualDistSqr); Real shrunkenDist = actualDist - totalRad; if (shrunkenDist <= 0.0f) { @@ -915,7 +917,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::Sqrt(actualDistSqr); Real shrunkenDist = actualDist - totalRad; if (shrunkenDist <= 0.0f) { @@ -1778,8 +1780,8 @@ void PartitionData::doRectFill( Real angle ) { - Real c = (Real)Cos(angle); - Real s = (Real)Sin(angle); + Real c = (Real)WWMath::CosTrig(angle); + Real s = (Real)WWMath::SinTrig(angle); Real actualCellSize = ThePartitionManager->getCellSize(); Real stepSize = actualCellSize * 0.5f; // in theory, should be getCellSize() exactly, but needs to be smaller to avoid aliasing problems @@ -2226,7 +2228,7 @@ Int PartitionData::calcMaxCoiForShape(GeometryType geom, Real majorRadius, Real } case GEOMETRY_BOX: { - Real diagonal = (Real)(sqrtf(majorRadius*majorRadius + minorRadius*minorRadius)); + Real diagonal = (Real)(WWMath::Sqrt(majorRadius*majorRadius + minorRadius*minorRadius)); Int cells = ThePartitionManager->worldToCellDist(diagonal*2) + 1; result = cells * cells; break; @@ -3217,7 +3219,7 @@ Int PartitionManager::calcMinRadius(const ICoord2D& cur) } // double, not real - double dist = sqrtf(minDistSqr); + double dist = WWMath::Sqrt(minDistSqr); Int minRadius = REAL_TO_INT_CEIL( dist / m_cellSize ); return minRadius; @@ -3235,7 +3237,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 +3507,7 @@ Object *PartitionManager::getClosestObjects( } if (closestDistArg) { - *closestDistArg = (Real)sqrtf(closestDistSqr); + *closestDistArg = (Real)WWMath::Sqrt(closestDistSqr); } #ifdef RTS_DEBUG @@ -3632,7 +3634,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::Sqrt(sqr(v.x) + sqr(v.y)); // normalize if (dist == 0.0f) @@ -3655,7 +3657,7 @@ Real PartitionManager::getRelativeAngle2D( const Object *obj, const Coord3D *pos else if (c > 1.0) c = 1.0; - Real value = (Real)ACos( c ); + Real value = (Real)WWMath::Acos( c ); // Determine sign by checking Z component of dir cross v // Note this is assumes 2D, and is identical to dotting the perpendicular of v with dir @@ -3792,8 +3794,8 @@ Bool PartitionManager::tryPosition( const Coord3D *center, // compute the spot on the terrain we've picked Coord3D pos; - pos.x = dist * Cos( angle ) + center->x; - pos.y = dist * Sin( angle ) + center->y; + pos.x = dist * WWMath::CosTrig( angle ) + center->x; + pos.y = dist * WWMath::SinTrig( angle ) + center->y; PathfindLayerEnum layer = LAYER_GROUND; if ((options->flags & FPF_USE_HIGHEST_LAYER) != 0) @@ -4566,7 +4568,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::Sqrt(sqr(x1-x2) + sqr(y1-y2)); } //----------------------------------------------------------------------------- @@ -5757,7 +5759,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( (x - parms->xCenter) * (x - parms->xCenter) + (y - parms->yCenter) * (y - parms->yCenter) ); mulVal = 1 - distance / parms->radius; if (mulVal < 0.0f) mulVal = 0.0f; @@ -5785,7 +5787,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( (x - parms->xCenter) * (x - parms->xCenter) + (y - parms->yCenter) * (y - parms->yCenter) ); mulVal = 1 - distance / parms->radius; if (mulVal < 0.0f) mulVal = 0.0f; @@ -5813,7 +5815,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( (x - parms->xCenter) * (x - parms->xCenter) + (y - parms->yCenter) * (y - parms->yCenter) ); mulVal = 1 - distance / parms->radius; if (mulVal < 0.0f) mulVal = 0.0f; @@ -5841,7 +5843,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( (x - parms->xCenter) * (x - parms->xCenter) + (y - parms->yCenter) * (y - parms->yCenter) ); 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 5243446c6be..458388abe05 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp @@ -2272,7 +2272,7 @@ UpdateSleepTime AIUpdateInterface::doLocomotor() } else { - Real dist = sqrtf(dSqr); + Real dist = WWMath::Sqrt(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 (distm_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); @@ -368,7 +368,7 @@ Bool DeliverPayloadAIUpdate::isCloseEnoughToTarget() if ( inBound ) allowedDistanceSqr = sqr(getAllowedDistanceToTarget() + getPreOpenDistance()); - //DEBUG_LOG(("Dist to target is %f (allowed %f)",sqrt(currentDistanceSqr),sqrt(allowedDistanceSqr))); + //DEBUG_LOG(("Dist to target is %f (allowed %f)",WWMath::Sqrt(currentDistanceSqr),WWMath::Sqrt(allowedDistanceSqr))); if ( allowedDistanceSqr > currentDistanceSqr ) @@ -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 4aa23123c4d..54fab10ec06 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/JetAIUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/JetAIUpdate.cpp @@ -447,10 +447,10 @@ static Bool intersectInfiniteLine2D Real& ix, Real& iy ) { - Real bx = ax + Cos(ao); - Real by = ay + Sin(ao); - Real dx = cx + Cos(co); - Real dy = cy + Sin(co); + Real bx = ax + WWMath::CosTrig(ao); + Real by = ay + WWMath::SinTrig(ao); + Real dx = cx + WWMath::CosTrig(co); + Real dy = cy + WWMath::SinTrig(co); Real denom = ((bx - ax) * (dy - cy) - (by - ay) * (dx - cx)); if (denom == 0.0f) @@ -516,7 +516,7 @@ class JetOrHeliTaxiState : public AIMoveOutOfTheWayState Coord3D intermedPt; Bool intermed = false; - Real orient = atan2(ppinfo.runwayPrep.y - ppinfo.parkingSpace.y, ppinfo.runwayPrep.x - ppinfo.parkingSpace.x); + Real orient = WWMath::Atan2(ppinfo.runwayPrep.y - ppinfo.parkingSpace.y, ppinfo.runwayPrep.x - ppinfo.parkingSpace.x); if (fabs(stdAngleDiff(orient, ppinfo.parkingOrientation)) > PI/128) { intermedPt.z = (ppinfo.parkingSpace.z + ppinfo.runwayPrep.z) * 0.5f; @@ -1071,7 +1071,7 @@ class HeliTakeoffOrLandingState : public State } else { - Real dist = sqrtf(dSqr); + Real dist = WWMath::Sqrt(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); @@ -2289,15 +2289,15 @@ void JetAIUpdate::positionLockon() Real dist = finalDist + (d->m_lockonInitialDist - finalDist) * frac; Real angle = d->m_lockonAngleSpin * frac; - pos.x += Cos(angle) * dist; - pos.y += Sin(angle) * dist; + pos.x += WWMath::CosTrig(angle) * dist; + pos.y += WWMath::SinTrig(angle) * dist; // pos.z is untouched m_lockonDrawable->setPosition(&pos); 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..8e678b33ea1 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) { @@ -611,7 +611,7 @@ void MissileAIUpdate::doKillState() closeEnough = curLoco->getMaxSpeedForCondition(BODY_PRISTINE); } Real distanceToTargetSq = ThePartitionManager->getDistanceSquared( getObject(), getGoalObject(), FROM_BOUNDINGSPHERE_3D); - //DEBUG_LOG(("Distance to target %f, closeEnough %f", sqrt(distanceToTargetSq), closeEnough)); + //DEBUG_LOG(("Distance to target %f, closeEnough %f", WWMath::Sqrt(distanceToTargetSq), closeEnough)); if (distanceToTargetSq < closeEnough*closeEnough) { Coord3D pos = *getGoalObject()->getPosition(); getObject()->setPosition(&pos); @@ -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::Sqrt(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/RailroadGuideAIUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/RailroadGuideAIUpdate.cpp index 19bdbdd01d7..84b88e6ede7 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::Sqrt( 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. @@ -1224,8 +1224,8 @@ void alignToTerrain( Real angle, const Coord3D& pos, const Coord3D& normal, Matr z = normal; - x.x = Cos( angle ); - x.y = Sin( angle ); + x.x = WWMath::CosTrig( angle ); + x.y = WWMath::SinTrig( angle ); x.z = 0.0f; if (z.z != 0.0f) { @@ -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..272d2895255 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; diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/DynamicShroudClearingRangeUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/DynamicShroudClearingRangeUpdate.cpp index e7100955fb6..f361c955638 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::SinTrig(angle) * radius); + pos.y = ctr->y + (WWMath::CosTrig(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..9151d70ed42 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::SinTrig(angle * 0.0291f) * 0.05f; + Real pitch = WWMath::SinTrig(angle * 0.0515f) * 0.05f; Matrix3D mx = *draw->getInstanceMatrix(); diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/HelicopterSlowDeathUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/HelicopterSlowDeathUpdate.cpp index e3a86fb24b4..07cb00b98f7 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/HelicopterSlowDeathUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/HelicopterSlowDeathUpdate.cpp @@ -359,8 +359,8 @@ UpdateSleepTime HelicopterSlowDeathBehavior::update() // is *NOT* the angle the object is facing // Coord3D force; - force.x = DOUBLE_TO_REAL( Cos( m_forwardAngle ) ) * m_forwardSpeed; - force.y = DOUBLE_TO_REAL( Sin( m_forwardAngle ) ) * m_forwardSpeed; + force.x = DOUBLE_TO_REAL( WWMath::CosTrig( m_forwardAngle ) ) * m_forwardSpeed; + force.y = DOUBLE_TO_REAL( WWMath::SinTrig( m_forwardAngle ) ) * m_forwardSpeed; force.z = 0.0f; physics->applyMotiveForce( &force ); diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/MobMemberSlavedUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/MobMemberSlavedUpdate.cpp index c864b5e413f..95137d7f71b 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/MobMemberSlavedUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/MobMemberSlavedUpdate.cpp @@ -358,8 +358,8 @@ void MobMemberSlavedUpdate::doCatchUpLogic( Coord3D *pos ) Real randomDirection = GameLogicRandomValue( 0, 2*PI ); Real randomRadius = GameLogicRandomValue( 0, data->m_noNeedToCatchUpRadius ); nuPos.set(pos); - nuPos.x += randomRadius * Cos( randomDirection ); - nuPos.y += randomRadius * Sin( randomDirection ); + nuPos.x += randomRadius * WWMath::CosTrig( randomDirection ); + nuPos.y += randomRadius * WWMath::SinTrig( randomDirection ); nuPos.z = TheTerrainLogic->getGroundHeight( nuPos.x, nuPos.y ); AIUpdateInterface *ai = getObject()->getAIUpdateInterface(); diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/NeutronMissileUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/NeutronMissileUpdate.cpp index 62de8b3f53c..54f75a9f838 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/NeutronMissileUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/NeutronMissileUpdate.cpp @@ -294,7 +294,7 @@ static Real calcTransform(const Object* obj, const Coord3D *pos, Real maxTurnRat else if (c > 1.0) c = 1.0; - Real angle = (Real)ACos( c ); + Real angle = (Real)WWMath::Acos( c ); Vector3 newDir; if (fabs(angle) < maxTurnRate) @@ -418,7 +418,7 @@ void NeutronMissileUpdate::doAttack() pos.z += m_vel.z; //DEBUG_LOG(("vel %f accel %f z %f",m_vel.length(),m_accel.length(), pos.z)); -//Real vm = sqrt(m_vel.x*m_vel.x+m_vel.y*m_vel.y+m_vel.z*m_vel.z); +//Real vm = WWMath::Sqrt(m_vel.x*m_vel.x+m_vel.y*m_vel.y+m_vel.z*m_vel.z); //DEBUG_LOG(("vel is %f %f %f (%f)",m_vel.x,m_vel.y,m_vel.z,vm)); getObject()->setTransformMatrix( &mx ); getObject()->setPosition( &pos ); @@ -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 9b9f5275b38..0b2819bd03a 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ParticleUplinkCannonUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ParticleUplinkCannonUpdate.cpp @@ -526,12 +526,12 @@ UpdateSleepTime ParticleUplinkCannonUpdate::update() //First determine the factor of time completed (ranges between 0.0 and 1.0) Real factor = (Real)(now - orbitalBirthFrame) / (Real)(orbitalDeathFrame - orbitalBirthFrame); - //We're generating a swath that travels the points between sin( -1PI ) and sin( 1PI ) + //We're generating a swath that travels the points between WWMath::SinTrig( -1PI ) and WWMath::SinTrig( 1PI ) Real radians = (factor * TWO_PI) - PI; 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::SinTrig( radians ); Real cxHeight = height * data->m_swathOfDeathAmplitude; Coord3D buildingToInitialTargetVector; @@ -553,8 +553,8 @@ UpdateSleepTime ParticleUplinkCannonUpdate::update() cartesianTargetVector.Normalize(); Real dotProduct = Vector2::Dot_Product( buildingToTargetVector, cartesianTargetVector ); - dotProduct = __min( 0.99999f, __max( -0.99999f, dotProduct ) ); //Account for numerical errors. Also, acos(-1.00000) is coming out QNAN on the superweapon general map. Heh. - Real angle = (Real)ACos( dotProduct ); + dotProduct = __min( 0.99999f, __max( -0.99999f, dotProduct ) ); //Account for numerical errors. Also, WWMath::Acos(-1.00000) is coming out QNAN on the superweapon general map. Heh. + Real angle = (Real)WWMath::Acos( dotProduct ); if( buildingToTargetVector.Y >= 0 ) { diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp index ccc57226348..3f1bffa2176 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp @@ -28,6 +28,8 @@ #include "PreRTS.h" // This must go first in EVERY cpp file in the GameEngine +#include "wwmath.h" + // please talk to MDC (x36804) before taking this out #define NO_DEBUG_CRC @@ -91,7 +93,7 @@ static Real angleBetweenVectors(const Coord3D& inCurDir, const Coord3D& inGoalDi Real cosine = Vector3::Dot_Product(curDir, goalDir); // bound it in case of numerical error - Real angleBetween = (Real)ACos(clamp(-1.0f, cosine, 1.0f)); + Real angleBetween = (Real)WWMath::Acos(clamp(-1.0f, cosine, 1.0f)); return angleBetween; } @@ -100,8 +102,8 @@ static Real angleBetweenVectors(const Coord3D& inCurDir, const Coord3D& inGoalDi 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)); + // back-calc it from our speed & gravity... v = WWMath::Sqrt(2*g*h) + return WWMath::Sqrt(fabs(2.0f * TheGlobalData->m_gravity * height)); } //------------------------------------------------------------------------------------------------- @@ -142,7 +144,7 @@ PhysicsBehaviorModuleData::PhysicsBehaviorModuleData() static void parseHeightToSpeed( INI* ini, void * /*instance*/, void *store, const void* /*userData*/ ) { // don't bother trying to remember how far we've fallen; instead, - // back-calc it from our speed & gravity... v = sqrt(2*g*h) + // back-calc it from our speed & gravity... v = WWMath::Sqrt(2*g*h) Real height = INI::scanReal(ini->getNextToken()); *(Real *)store = heightToSpeed(height); } @@ -735,10 +737,10 @@ 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::Sqrt(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); + Real s = WWMath::SinTrig(remainingAngle); pitchRateToUse *= s; } @@ -848,7 +850,7 @@ UpdateSleepTime PhysicsBehavior::update() // // don't bother trying to remember how far we've fallen; instead, - // we back-calc it from our speed & gravity... v = sqrt(2*g*h). + // we back-calc it from our speed & gravity... v = WWMath::Sqrt(2*g*h). // (note that m_minFallSpeedForDamage is always POSITIVE.) // // also note: since projectiles are immune to falling damage, don't @@ -942,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::Sqrt( sqr(m_vel.x) + sqr(m_vel.y) + sqr(m_vel.z) ); } return m_velMag; } @@ -962,9 +964,9 @@ Real PhysicsBehavior::getForwardSpeed2D() const Real dot = vx + vy; Real speedSquared = vx*vx + vy*vy; -// DEBUG_ASSERTCRASH( speedSquared != 0, ("zero speedSquared will overflow sqrtf()!") );// lorenzen... sanity check +// DEBUG_ASSERTCRASH( speedSquared != 0, ("zero speedSquared will overflow WWMath::Sqrt()!") );// lorenzen... sanity check - Real speed = (Real)sqrtf( speedSquared ); + Real speed = (Real)WWMath::Sqrt( speedSquared ); if (dot >= 0.0f) return speed; @@ -987,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::Sqrt( vx*vx + vy*vy + vz*vz ); if (dot >= 0.0f) return speed; @@ -1034,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::Sqrt(m_vel.x*m_vel.x + m_vel.y*m_vel.y); if (desiredVelocity > curVelocity) { return; @@ -1319,7 +1321,7 @@ void PhysicsBehavior::onCollide( Object *other, const Coord3D *loc, const Coord3 m_lastCollidee = other->getID(); - Real dist = sqrtf(distSqr); + Real dist = WWMath::Sqrt(distSqr); Real overlap = usRadius + themRadius - dist; // if objects are coincident, dist is zero, so force would be infinite -- clearly diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/PointDefenseLaserUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/PointDefenseLaserUpdate.cpp index 643aa40a5b4..86fd7667c6e 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/SlavedUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/SlavedUpdate.cpp index 27303efcc5b..4c1abc6992c 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/SlavedUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/SlavedUpdate.cpp @@ -319,8 +319,8 @@ void SlavedUpdate::doAttackLogic( const Object *target ) //Allow me to wander away from the pinnedPosition. Real randomDirection = GameLogicRandomValue( 0, 2*PI ); m_guardPointOffset.zero(); - m_guardPointOffset.x += data->m_attackWanderRange * Cos( randomDirection ); - m_guardPointOffset.y += data->m_attackWanderRange * Sin( randomDirection ); + m_guardPointOffset.x += data->m_attackWanderRange * WWMath::CosTrig( randomDirection ); + m_guardPointOffset.y += data->m_attackWanderRange * WWMath::SinTrig( randomDirection ); //Offset our pinned position by our random offset. attackPosition.x += m_guardPointOffset.x; @@ -382,8 +382,8 @@ void SlavedUpdate::doScoutLogic( const Coord3D *mastersDestination ) //Allow me to wander away from the pinnedPosition. Real randomDirection = GameLogicRandomValue( 0, 2*PI ); m_guardPointOffset.zero(); - m_guardPointOffset.x += data->m_scoutWanderRange * Cos( randomDirection ); - m_guardPointOffset.y += data->m_scoutWanderRange * Sin( randomDirection ); + m_guardPointOffset.x += data->m_scoutWanderRange * WWMath::CosTrig( randomDirection ); + m_guardPointOffset.y += data->m_scoutWanderRange * WWMath::SinTrig( randomDirection ); //Offset our pinned position by our random offset. scoutPosition.x += m_guardPointOffset.x; @@ -412,8 +412,8 @@ void SlavedUpdate::doGuardLogic( Coord3D *pinnedPosition ) // recalc where we want to be if we wander around Real randomDirection = GameLogicRandomValue( 0, 2*PI ); m_guardPointOffset.zero(); - m_guardPointOffset.x += data->m_guardMaxRange * Cos( randomDirection ); - m_guardPointOffset.y += data->m_guardMaxRange * Sin( randomDirection ); + m_guardPointOffset.x += data->m_guardMaxRange * WWMath::CosTrig( randomDirection ); + m_guardPointOffset.y += data->m_guardMaxRange * WWMath::SinTrig( randomDirection ); pinnedPosition->x += m_guardPointOffset.x; pinnedPosition->y += m_guardPointOffset.y; @@ -679,8 +679,8 @@ void SlavedUpdate::moveToNewRepairSpot() //Allow me to wander away from the pinnedPosition. Real randomDirection = GameLogicRandomValue( 0, 2*PI ); m_guardPointOffset.set( master->getPosition() ); - m_guardPointOffset.x += data->m_repairRange * Cos( randomDirection ); - m_guardPointOffset.y += data->m_repairRange * Sin( randomDirection ); + m_guardPointOffset.x += data->m_repairRange * WWMath::CosTrig( randomDirection ); + m_guardPointOffset.y += data->m_repairRange * WWMath::SinTrig( randomDirection ); m_guardPointOffset.z = TheTerrainLogic->getGroundHeight( m_guardPointOffset.x, m_guardPointOffset.y ); Real altitude = GameLogicRandomValueReal( data->m_repairMinAltitude, data->m_repairMaxAltitude ); m_guardPointOffset.z += altitude; @@ -713,8 +713,8 @@ void SlavedUpdate::startSlavedEffects( const Object *slaver ) // Decide where our pinned stray point is Real randomDirection = GameLogicRandomValue( 0, 2*PI ); m_guardPointOffset.zero(); - m_guardPointOffset.x += data->m_guardMaxRange * Cos( randomDirection ); - m_guardPointOffset.y += data->m_guardMaxRange * Sin( randomDirection ); + m_guardPointOffset.x += data->m_guardMaxRange * WWMath::CosTrig( randomDirection ); + m_guardPointOffset.y += data->m_guardMaxRange * WWMath::SinTrig( randomDirection ); // mark selves as not selectable getObject()->setStatus( MAKE_OBJECT_STATUS_MASK( OBJECT_STATUS_UNSELECTABLE ) ); diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/SpectreGunshipDeploymentUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/SpectreGunshipDeploymentUpdate.cpp index d22a61a9bf8..e1cadfceef6 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 4a2f3625093..5fafdd8e308 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/StealthUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/StealthUpdate.cpp @@ -684,7 +684,7 @@ UpdateSleepTime StealthUpdate::update() } else { - draw->setEffectiveOpacity( 0.5f + ( Sin( m_pulsePhase ) * 0.5f ) ); + draw->setEffectiveOpacity( 0.5f + ( WWMath::SinTrig( m_pulsePhase ) * 0.5f ) ); // between one half and full opacity m_pulsePhase += m_pulsePhaseRate; } diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/StructureToppleUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/StructureToppleUpdate.cpp index 0bd5891192f..3c8b244130a 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/StructureToppleUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/StructureToppleUpdate.cpp @@ -158,15 +158,15 @@ void StructureToppleUpdate::beginStructureTopple(const DamageInfo *damageInfo) toppleAngle = m_toppleDirection.toAngle(); toppleAngle += GameLogicRandomValueReal(-PI/8, PI/8); } - m_toppleDirection.x = Cos(toppleAngle); - m_toppleDirection.y = Sin(toppleAngle); + m_toppleDirection.x = WWMath::CosTrig(toppleAngle); + m_toppleDirection.y = WWMath::SinTrig(toppleAngle); TheScriptEngine->adjustToppleDirection(getObject(), &m_toppleDirection); Real averageRadius = (building->getGeometryInfo().getMajorRadius() + building->getGeometryInfo().getMinorRadius()) / 2; Real explosionRadius = averageRadius * 0.90; - m_delayBurstLocation.x = building->getPosition()->x + explosionRadius * Cos(toppleAngle); - m_delayBurstLocation.y = building->getPosition()->y + explosionRadius * Sin(toppleAngle); + m_delayBurstLocation.x = building->getPosition()->x + explosionRadius * WWMath::CosTrig(toppleAngle); + m_delayBurstLocation.y = building->getPosition()->y + explosionRadius * WWMath::SinTrig(toppleAngle); m_delayBurstLocation.z = TheTerrainLogic->getGroundHeight(m_delayBurstLocation.x, m_delayBurstLocation.y); doToppleStartFX(building, damageInfo); @@ -231,7 +231,7 @@ UpdateSleepTime StructureToppleUpdate::update() // The building is in the process of falling over. if (m_toppleState == TOPPLESTATE_TOPPLING) { UnsignedInt now = TheGameLogic->getFrame(); - Real toppleAcceleration = TOPPLE_ACCELERATION_FACTOR * (Sin(m_accumulatedAngle) * (1.0 - m_structuralIntegrity)); + Real toppleAcceleration = TOPPLE_ACCELERATION_FACTOR * (WWMath::SinTrig(m_accumulatedAngle) * (1.0 - m_structuralIntegrity)); // DEBUG_LOG(("toppleAcceleration = %f", toppleAcceleration)); m_toppleVelocity += toppleAcceleration; // DEBUG_LOG(("m_toppleVelocity = %f", m_toppleVelocity)); @@ -368,8 +368,8 @@ void StructureToppleUpdate::applyCrushingDamage(Real theta) // Do this because the amount of ground that is affected will be different if the building falls // in different orientations. Real angle = orientationAngle - toppleAngle; - Real minorComponent = building->getGeometryInfo().getMinorRadius() * Cos(angle); - Real majorComponent = building->getGeometryInfo().getMajorRadius() * Sin(angle); + Real minorComponent = building->getGeometryInfo().getMinorRadius() * WWMath::CosTrig(angle); + Real majorComponent = building->getGeometryInfo().getMajorRadius() * WWMath::SinTrig(angle); Coord3D temp3D; temp3D.x = majorComponent; @@ -385,7 +385,7 @@ void StructureToppleUpdate::applyCrushingDamage(Real theta) } // The furthest away from the base of the building to explode on. - Real maxDistance = m_buildingHeight * (1.0 - Sin(theta)); + Real maxDistance = m_buildingHeight * (1.0 - WWMath::SinTrig(theta)); /* * Fire explosions at regular intervals across the area that the building is currently @@ -396,14 +396,14 @@ void StructureToppleUpdate::applyCrushingDamage(Real theta) // Coord3D target; Real j = m_lastCrushedLocation; for (; j < maxDistance; j += WEAPON_SPACING_PERPENDICULAR) { - jcos = j * Cos(toppleAngle); - jsin = j * Sin(toppleAngle); + jcos = j * WWMath::CosTrig(toppleAngle); + jsin = j * WWMath::SinTrig(toppleAngle); doDamageLine(building, wt, jcos, jsin, facingWidth, toppleAngle); } - jcos = maxDistance * Cos(toppleAngle); - jsin = maxDistance * Sin(toppleAngle); + jcos = maxDistance * WWMath::CosTrig(toppleAngle); + jsin = maxDistance * WWMath::SinTrig(toppleAngle); doDamageLine(building, wt, jcos, jsin, facingWidth, toppleAngle); m_lastCrushedLocation = j; @@ -424,8 +424,8 @@ void StructureToppleUpdate::doDamageLine(Object *building, const WeaponTemplate* for (Real i = -facingWidth; i < facingWidth; i += WEAPON_SPACING_PARALLEL) { - target.x = building->getPosition()->x + jcos + (i * Sin(toppleAngle)); - target.y = building->getPosition()->y + jsin + (i * Cos(toppleAngle)); + target.x = building->getPosition()->x + jcos + (i * WWMath::SinTrig(toppleAngle)); + target.y = building->getPosition()->y + jsin + (i * WWMath::CosTrig(toppleAngle)); target.z = TheTerrainLogic->getGroundHeight(target.x, target.y); TheWeaponStore->createAndFireTempWeapon(wt, building, &target); @@ -436,8 +436,8 @@ void StructureToppleUpdate::doDamageLine(Object *building, const WeaponTemplate* } // Make sure there are weapons fired and FX done on the edge of the building. - target.x = building->getPosition()->x + jcos + (facingWidth * Sin(toppleAngle)); - target.y = building->getPosition()->y + jsin + (facingWidth * Cos(toppleAngle)); + target.x = building->getPosition()->x + jcos + (facingWidth * WWMath::SinTrig(toppleAngle)); + target.y = building->getPosition()->y + jsin + (facingWidth * WWMath::CosTrig(toppleAngle)); target.z = TheTerrainLogic->getGroundHeight(target.x, target.y); TheWeaponStore->createAndFireTempWeapon(wt, building, &target); diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ToppleUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ToppleUpdate.cpp index 137521dcf9b..df2e7c00512 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ToppleUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ToppleUpdate.cpp @@ -185,13 +185,13 @@ 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 toppleAngle = angleClosestTo(curAngleX + PI/2, curAngleX - PI/2, toppleAngle); - m_toppleDirection.x = Cos(toppleAngle); - m_toppleDirection.y = Sin(toppleAngle); + m_toppleDirection.x = WWMath::CosTrig(toppleAngle); + m_toppleDirection.y = WWMath::SinTrig(toppleAngle); // go ahead and remove it from the pathfinder now, rather than waiting for the topple to // finish.... since we might be in a slightly different position when toppled, which can diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/WaveGuideUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/WaveGuideUpdate.cpp index 9350b0914cb..44b9b5bc424 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/WaveGuideUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/WaveGuideUpdate.cpp @@ -718,8 +718,8 @@ void WaveGuideUpdate::doDamage() // angle is rotated, because we computed from 'from' and 'to' points of // the bridge going *across* the valley, not pointing *down* it // - u.x = Cos( angle + modData->m_bridgeParticleAngleFudge ); - u.y = Sin( angle + modData->m_bridgeParticleAngleFudge ); + u.x = WWMath::CosTrig( angle + modData->m_bridgeParticleAngleFudge ); + u.y = WWMath::SinTrig( angle + modData->m_bridgeParticleAngleFudge ); u.z = 0.0f; y.crossProduct( &z, &u, &y ); diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp index da4ef34b952..287199851e1 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp @@ -30,6 +30,8 @@ // INCLUDES /////////////////////////////////////////////////////////////////////////////////////// #include "PreRTS.h" // This must go first in EVERY cpp file in the GameEngine +#include "wwmath.h" + #define DEFINE_DEATH_NAMES #define DEFINE_WEAPONBONUSCONDITION_NAMES #define DEFINE_WEAPONBONUSFIELD_NAMES @@ -857,7 +859,7 @@ UnsignedInt WeaponTemplate::fireWeaponTemplate Real attackRangeSqr = sqr(getAttackRange(bonus)); if (distSqr > attackRangeSqr) { - //DEBUG_ASSERTCRASH(distSqr < 5*5 || distSqr < attackRangeSqr*1.2f, ("*** victim is out of range (%f vs %f) of this weapon -- why did we attempt to fire?",sqrtf(distSqr),sqrtf(attackRangeSqr))); + //DEBUG_ASSERTCRASH(distSqr < 5*5 || distSqr < attackRangeSqr*1.2f, ("*** victim is out of range (%f vs %f) of this weapon -- why did we attempt to fire?",WWMath::Sqrt(distSqr),WWMath::Sqrt(attackRangeSqr))); //-extraLogging #if defined(RTS_DEBUG) @@ -879,7 +881,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::Sqrt(distSqr),WWMath::Sqrt(minAttackRangeSqr))); //-extraLogging #if defined(RTS_DEBUG) @@ -905,7 +907,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); @@ -987,8 +989,8 @@ UnsignedInt WeaponTemplate::fireWeaponTemplate Coord3D firingOffset; firingOffset.zero(); - firingOffset.x = scatterRadius * Cos( scatterAngleRadian ); - firingOffset.y = scatterRadius * Sin( scatterAngleRadian ); + firingOffset.x = scatterRadius * WWMath::CosTrig( scatterAngleRadian ); + firingOffset.y = scatterRadius * WWMath::SinTrig( scatterAngleRadian ); projectileDestination.x += firingOffset.x; projectileDestination.y += firingOffset.y; @@ -1489,7 +1491,7 @@ void WeaponTemplate::dealDamageInternal(ObjectID sourceID, ObjectID victimID, co // These are now normalized, so the dot productis actually the Cos of the angle they form // A smaller Cos would mean a more obtuse angle - if( Vector3::Dot_Product(sourceVector, damageVector) < Cos(allowedAngle) ) + if( Vector3::Dot_Product(sourceVector, damageVector) < WWMath::CosTrig(allowedAngle) ) continue;// Too far to the side, can't hurt them. } @@ -2117,7 +2119,7 @@ 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; @@ -2130,9 +2132,9 @@ Bool Weapon::computeApproachTarget(const Object *source, const Object *target, c if (angleOffset != 0.0f) { - Real angle = atan2(dir.y, dir.x); - dir.x = (Real)Cos(angle + angleOffset); - dir.y = (Real)Sin(angle + angleOffset); + Real angle = WWMath::Atan2(dir.y, dir.x); + dir.x = (Real)WWMath::CosTrig(angle + angleOffset); + dir.y = (Real)WWMath::SinTrig(angle + angleOffset); } // select a spot along the line between us, halfway between the min & max range. @@ -2177,9 +2179,9 @@ Bool Weapon::computeApproachTarget(const Object *source, const Object *target, c if (angleOffset != 0.0f) { - Real angle = atan2(dir.y, dir.x); - dir.x = (Real)Cos(angle + angleOffset); - dir.y = (Real)Sin(angle + angleOffset); + Real angle = WWMath::Atan2(dir.y, dir.x); + dir.x = (Real)WWMath::CosTrig(angle + angleOffset); + dir.y = (Real)WWMath::SinTrig(angle + angleOffset); } // select a spot along the line between us, in range of our weapon diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptEngine.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptEngine.cpp index 7c9c612245c..073b744b769 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptEngine.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptEngine.cpp @@ -5299,8 +5299,8 @@ void ScriptEngine::reset() } m_breezeInfo.m_direction = PI/3; - m_breezeInfo.m_directionVec.x = Sin(m_breezeInfo.m_direction); - m_breezeInfo.m_directionVec.y = Cos(m_breezeInfo.m_direction); + m_breezeInfo.m_directionVec.x = WWMath::SinTrig(m_breezeInfo.m_direction); + m_breezeInfo.m_directionVec.y = WWMath::CosTrig(m_breezeInfo.m_direction); m_breezeInfo.m_intensity = 0.07f*PI/4; m_breezeInfo.m_lean = 0.07f*PI/4; m_breezeInfo.m_breezePeriod = LOGICFRAMES_PER_SECOND * 5; @@ -6408,8 +6408,8 @@ void ScriptEngine::setSway( ScriptAction *pAction ) DEBUG_ASSERTCRASH(pAction->getNumParameters() >= 5, ("Not enough parameters.")); ++m_breezeInfo.m_breezeVersion; m_breezeInfo.m_direction = pAction->getParameter(0)->getReal(); - m_breezeInfo.m_directionVec.x = Sin(m_breezeInfo.m_direction); - m_breezeInfo.m_directionVec.y = Cos(m_breezeInfo.m_direction); + m_breezeInfo.m_directionVec.x = WWMath::SinTrig(m_breezeInfo.m_direction); + m_breezeInfo.m_directionVec.y = WWMath::CosTrig(m_breezeInfo.m_direction); m_breezeInfo.m_intensity = pAction->getParameter(1)->getReal(); m_breezeInfo.m_lean = pAction->getParameter(2)->getReal(); m_breezeInfo.m_breezePeriod = pAction->getParameter(3)->getInt(); diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp index b4e678aa1d6..790f8ed6ef1 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp @@ -845,7 +845,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/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp index 6a17841b0fa..c31f0a62488 100644 --- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp +++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp @@ -81,7 +81,7 @@ static void drawFramerateBar(); #include "W3DDevice/GameClient/W3DDebugDisplay.h" #include "W3DDevice/GameClient/W3DProjectedShadow.h" #include "W3DDevice/GameClient/W3DShroud.h" -#include "WWMath/wwmath.h" +#include "wwmath.h" #include "WWLib/registry.h" #include "WW3D2/ww3d.h" #include "WW3D2/predlod.h" diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DParticleSys.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DParticleSys.cpp index b1b792b3ac9..975999d99ea 100644 --- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DParticleSys.cpp +++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DParticleSys.cpp @@ -348,8 +348,8 @@ void W3DParticleSystemManager::doParticles(RenderInfoClass &rinfo) Coord3D worldStart, worldEnd; ICoord2D pixelStart, pixelEnd; sys->getPosition( &worldStart ); - worldEnd.x = Cos( sys->getWindAngle() ) * 50.0f + worldStart.x; - worldEnd.y = Sin( sys->getWindAngle() ) * 50.0f + worldStart.y; + worldEnd.x = WWMath::Cos( sys->getWindAngle() ) * 50.0f + worldStart.x; + worldEnd.y = WWMath::Sin( sys->getWindAngle() ) * 50.0f + worldStart.y; worldEnd.z = worldStart.z; TheTacticalView->worldToScreen( &worldStart, &pixelStart ); TheTacticalView->worldToScreen( &worldEnd, &pixelEnd ); diff --git a/GeneralsMD/Code/Tools/GUIEdit/Source/Dialog Procedures/TabControlProperties.cpp b/GeneralsMD/Code/Tools/GUIEdit/Source/Dialog Procedures/TabControlProperties.cpp index 97fe8fd9887..e7ffae8d5fe 100644 --- a/GeneralsMD/Code/Tools/GUIEdit/Source/Dialog Procedures/TabControlProperties.cpp +++ b/GeneralsMD/Code/Tools/GUIEdit/Source/Dialog Procedures/TabControlProperties.cpp @@ -334,8 +334,8 @@ static LRESULT CALLBACK tabControlPropertiesCallback( HWND hWndDialog, tabData->tabEdge = TP_BOTTOM_SIDE; //safeties - tabData->tabCount = max( tabData->tabCount, 1 ); - tabData->tabCount = min( tabData->tabCount, NUM_TAB_PANES ); + tabData->tabCount = max( tabData->tabCount, (Int)1 ); + tabData->tabCount = min( tabData->tabCount, (Int)NUM_TAB_PANES ); GadgetTabControlComputeTabRegion( tabControl ); GadgetTabControlResizeSubPanes( tabControl ); diff --git a/cmake/gamemath.cmake b/cmake/gamemath.cmake new file mode 100644 index 00000000000..1761f842698 --- /dev/null +++ b/cmake/gamemath.cmake @@ -0,0 +1,11 @@ +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) +