diff --git a/Core/Libraries/Source/WWVegas/CMakeLists.txt b/Core/Libraries/Source/WWVegas/CMakeLists.txt index 10f27ff41cd..df2e04d8d32 100644 --- a/Core/Libraries/Source/WWVegas/CMakeLists.txt +++ b/Core/Libraries/Source/WWVegas/CMakeLists.txt @@ -18,14 +18,16 @@ target_include_directories(core_wwcommon INTERFACE . WWDebug WWLib + WWMath + WWSaveLoad ) # add_subdirectory(WWAudio) add_subdirectory(WWDebug) add_subdirectory(WWLib) -# add_subdirectory(WWMath) +add_subdirectory(WWMath) # add_subdirectory(Wwutil) -# add_subdirectory(WWSaveLoad) +add_subdirectory(WWSaveLoad) add_subdirectory(WWStub) # add_subdirectory(WW3D2) # add_subdirectory(WWDownload) @@ -40,8 +42,8 @@ target_include_directories(core_wwvegas INTERFACE WWDebug #WWDownload WWLib - #WWMath - #WWSaveLoad + WWMath + WWSaveLoad #Wwutil #wwshade ) @@ -51,8 +53,8 @@ target_link_libraries(core_wwvegas INTERFACE core_wwdebug # core_wwdownload core_wwlib - # core_wwmath - # core_wwsaveload + core_wwmath + core_wwsaveload # core_wwshade # core_wwutil ) diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/CMakeLists.txt b/Core/Libraries/Source/WWVegas/WWMath/CMakeLists.txt similarity index 81% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/CMakeLists.txt rename to Core/Libraries/Source/WWVegas/WWMath/CMakeLists.txt index e86bb8f58c2..d248f6af817 100644 --- a/GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/CMakeLists.txt +++ b/Core/Libraries/Source/WWVegas/WWMath/CMakeLists.txt @@ -81,14 +81,14 @@ set(WWMATH_SRC ) # Targets to build. -add_library(z_wwmath STATIC) -set_target_properties(z_wwmath PROPERTIES OUTPUT_NAME wwmath) +add_library(core_wwmath STATIC) +set_target_properties(core_wwmath PROPERTIES OUTPUT_NAME wwmath) -target_sources(z_wwmath PRIVATE ${WWMATH_SRC}) +target_sources(core_wwmath PRIVATE ${WWMATH_SRC}) -target_link_libraries(z_wwmath PRIVATE - z_wwcommon +target_link_libraries(core_wwmath PRIVATE + core_wwcommon ) # @todo Test its impact and see what to do with the legacy functions. -#add_compile_definitions(z_wwmath PUBLIC ALLOW_TEMPORARIES) # Enables legacy math with "temporaries" +#add_compile_definitions(core_wwmath PUBLIC ALLOW_TEMPORARIES) # Enables legacy math with "temporaries" diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/Vector3i.h b/Core/Libraries/Source/WWVegas/WWMath/Vector3i.h similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/Vector3i.h rename to Core/Libraries/Source/WWVegas/WWMath/Vector3i.h diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/aabox.cpp b/Core/Libraries/Source/WWVegas/WWMath/aabox.cpp similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/aabox.cpp rename to Core/Libraries/Source/WWVegas/WWMath/aabox.cpp diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/aabox.h b/Core/Libraries/Source/WWVegas/WWMath/aabox.h similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/aabox.h rename to Core/Libraries/Source/WWVegas/WWMath/aabox.h diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/aabtreecull.cpp b/Core/Libraries/Source/WWVegas/WWMath/aabtreecull.cpp similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/aabtreecull.cpp rename to Core/Libraries/Source/WWVegas/WWMath/aabtreecull.cpp diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/aabtreecull.h b/Core/Libraries/Source/WWVegas/WWMath/aabtreecull.h similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/aabtreecull.h rename to Core/Libraries/Source/WWVegas/WWMath/aabtreecull.h diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/aaplane.h b/Core/Libraries/Source/WWVegas/WWMath/aaplane.h similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/aaplane.h rename to Core/Libraries/Source/WWVegas/WWMath/aaplane.h diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/cardinalspline.cpp b/Core/Libraries/Source/WWVegas/WWMath/cardinalspline.cpp similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/cardinalspline.cpp rename to Core/Libraries/Source/WWVegas/WWMath/cardinalspline.cpp diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/cardinalspline.h b/Core/Libraries/Source/WWVegas/WWMath/cardinalspline.h similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/cardinalspline.h rename to Core/Libraries/Source/WWVegas/WWMath/cardinalspline.h diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/castres.h b/Core/Libraries/Source/WWVegas/WWMath/castres.h similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/castres.h rename to Core/Libraries/Source/WWVegas/WWMath/castres.h diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/catmullromspline.cpp b/Core/Libraries/Source/WWVegas/WWMath/catmullromspline.cpp similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/catmullromspline.cpp rename to Core/Libraries/Source/WWVegas/WWMath/catmullromspline.cpp diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/catmullromspline.h b/Core/Libraries/Source/WWVegas/WWMath/catmullromspline.h similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/catmullromspline.h rename to Core/Libraries/Source/WWVegas/WWMath/catmullromspline.h diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/colmath.cpp b/Core/Libraries/Source/WWVegas/WWMath/colmath.cpp similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/colmath.cpp rename to Core/Libraries/Source/WWVegas/WWMath/colmath.cpp diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/colmath.h b/Core/Libraries/Source/WWVegas/WWMath/colmath.h similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/colmath.h rename to Core/Libraries/Source/WWVegas/WWMath/colmath.h diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/colmathaabox.cpp b/Core/Libraries/Source/WWVegas/WWMath/colmathaabox.cpp similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/colmathaabox.cpp rename to Core/Libraries/Source/WWVegas/WWMath/colmathaabox.cpp diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/colmathaabox.h b/Core/Libraries/Source/WWVegas/WWMath/colmathaabox.h similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/colmathaabox.h rename to Core/Libraries/Source/WWVegas/WWMath/colmathaabox.h diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/colmathaabtri.cpp b/Core/Libraries/Source/WWVegas/WWMath/colmathaabtri.cpp similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/colmathaabtri.cpp rename to Core/Libraries/Source/WWVegas/WWMath/colmathaabtri.cpp diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/colmathfrustum.cpp b/Core/Libraries/Source/WWVegas/WWMath/colmathfrustum.cpp similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/colmathfrustum.cpp rename to Core/Libraries/Source/WWVegas/WWMath/colmathfrustum.cpp diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/colmathfrustum.h b/Core/Libraries/Source/WWVegas/WWMath/colmathfrustum.h similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/colmathfrustum.h rename to Core/Libraries/Source/WWVegas/WWMath/colmathfrustum.h diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/colmathinlines.h b/Core/Libraries/Source/WWVegas/WWMath/colmathinlines.h similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/colmathinlines.h rename to Core/Libraries/Source/WWVegas/WWMath/colmathinlines.h diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/colmathline.cpp b/Core/Libraries/Source/WWVegas/WWMath/colmathline.cpp similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/colmathline.cpp rename to Core/Libraries/Source/WWVegas/WWMath/colmathline.cpp diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/colmathline.h b/Core/Libraries/Source/WWVegas/WWMath/colmathline.h similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/colmathline.h rename to Core/Libraries/Source/WWVegas/WWMath/colmathline.h diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/colmathobbobb.cpp b/Core/Libraries/Source/WWVegas/WWMath/colmathobbobb.cpp similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/colmathobbobb.cpp rename to Core/Libraries/Source/WWVegas/WWMath/colmathobbobb.cpp diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/colmathobbox.cpp b/Core/Libraries/Source/WWVegas/WWMath/colmathobbox.cpp similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/colmathobbox.cpp rename to Core/Libraries/Source/WWVegas/WWMath/colmathobbox.cpp diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/colmathobbtri.cpp b/Core/Libraries/Source/WWVegas/WWMath/colmathobbtri.cpp similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/colmathobbtri.cpp rename to Core/Libraries/Source/WWVegas/WWMath/colmathobbtri.cpp diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/colmathplane.cpp b/Core/Libraries/Source/WWVegas/WWMath/colmathplane.cpp similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/colmathplane.cpp rename to Core/Libraries/Source/WWVegas/WWMath/colmathplane.cpp diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/colmathplane.h b/Core/Libraries/Source/WWVegas/WWMath/colmathplane.h similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/colmathplane.h rename to Core/Libraries/Source/WWVegas/WWMath/colmathplane.h diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/colmathsphere.cpp b/Core/Libraries/Source/WWVegas/WWMath/colmathsphere.cpp similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/colmathsphere.cpp rename to Core/Libraries/Source/WWVegas/WWMath/colmathsphere.cpp diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/cullsys.cpp b/Core/Libraries/Source/WWVegas/WWMath/cullsys.cpp similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/cullsys.cpp rename to Core/Libraries/Source/WWVegas/WWMath/cullsys.cpp diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/cullsys.h b/Core/Libraries/Source/WWVegas/WWMath/cullsys.h similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/cullsys.h rename to Core/Libraries/Source/WWVegas/WWMath/cullsys.h diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/culltype.h b/Core/Libraries/Source/WWVegas/WWMath/culltype.h similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/culltype.h rename to Core/Libraries/Source/WWVegas/WWMath/culltype.h diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/curve.cpp b/Core/Libraries/Source/WWVegas/WWMath/curve.cpp similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/curve.cpp rename to Core/Libraries/Source/WWVegas/WWMath/curve.cpp diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/curve.h b/Core/Libraries/Source/WWVegas/WWMath/curve.h similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/curve.h rename to Core/Libraries/Source/WWVegas/WWMath/curve.h diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/euler.cpp b/Core/Libraries/Source/WWVegas/WWMath/euler.cpp similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/euler.cpp rename to Core/Libraries/Source/WWVegas/WWMath/euler.cpp diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/euler.h b/Core/Libraries/Source/WWVegas/WWMath/euler.h similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/euler.h rename to Core/Libraries/Source/WWVegas/WWMath/euler.h diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/frustum.cpp b/Core/Libraries/Source/WWVegas/WWMath/frustum.cpp similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/frustum.cpp rename to Core/Libraries/Source/WWVegas/WWMath/frustum.cpp diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/frustum.h b/Core/Libraries/Source/WWVegas/WWMath/frustum.h similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/frustum.h rename to Core/Libraries/Source/WWVegas/WWMath/frustum.h diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/gridcull.cpp b/Core/Libraries/Source/WWVegas/WWMath/gridcull.cpp similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/gridcull.cpp rename to Core/Libraries/Source/WWVegas/WWMath/gridcull.cpp diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/gridcull.h b/Core/Libraries/Source/WWVegas/WWMath/gridcull.h similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/gridcull.h rename to Core/Libraries/Source/WWVegas/WWMath/gridcull.h diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/hermitespline.cpp b/Core/Libraries/Source/WWVegas/WWMath/hermitespline.cpp similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/hermitespline.cpp rename to Core/Libraries/Source/WWVegas/WWMath/hermitespline.cpp diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/hermitespline.h b/Core/Libraries/Source/WWVegas/WWMath/hermitespline.h similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/hermitespline.h rename to Core/Libraries/Source/WWVegas/WWMath/hermitespline.h diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/lineseg.cpp b/Core/Libraries/Source/WWVegas/WWMath/lineseg.cpp similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/lineseg.cpp rename to Core/Libraries/Source/WWVegas/WWMath/lineseg.cpp diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/lineseg.h b/Core/Libraries/Source/WWVegas/WWMath/lineseg.h similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/lineseg.h rename to Core/Libraries/Source/WWVegas/WWMath/lineseg.h diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/lookuptable.cpp b/Core/Libraries/Source/WWVegas/WWMath/lookuptable.cpp similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/lookuptable.cpp rename to Core/Libraries/Source/WWVegas/WWMath/lookuptable.cpp diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/lookuptable.h b/Core/Libraries/Source/WWVegas/WWMath/lookuptable.h similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/lookuptable.h rename to Core/Libraries/Source/WWVegas/WWMath/lookuptable.h diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/matrix3.cpp b/Core/Libraries/Source/WWVegas/WWMath/matrix3.cpp similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/matrix3.cpp rename to Core/Libraries/Source/WWVegas/WWMath/matrix3.cpp diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/matrix3.h b/Core/Libraries/Source/WWVegas/WWMath/matrix3.h similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/matrix3.h rename to Core/Libraries/Source/WWVegas/WWMath/matrix3.h diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/matrix3d.cpp b/Core/Libraries/Source/WWVegas/WWMath/matrix3d.cpp similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/matrix3d.cpp rename to Core/Libraries/Source/WWVegas/WWMath/matrix3d.cpp diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/matrix3d.h b/Core/Libraries/Source/WWVegas/WWMath/matrix3d.h similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/matrix3d.h rename to Core/Libraries/Source/WWVegas/WWMath/matrix3d.h diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/matrix4.cpp b/Core/Libraries/Source/WWVegas/WWMath/matrix4.cpp similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/matrix4.cpp rename to Core/Libraries/Source/WWVegas/WWMath/matrix4.cpp diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/matrix4.h b/Core/Libraries/Source/WWVegas/WWMath/matrix4.h similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/matrix4.h rename to Core/Libraries/Source/WWVegas/WWMath/matrix4.h diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/normalcone.h b/Core/Libraries/Source/WWVegas/WWMath/normalcone.h similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/normalcone.h rename to Core/Libraries/Source/WWVegas/WWMath/normalcone.h diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/obbox.cpp b/Core/Libraries/Source/WWVegas/WWMath/obbox.cpp similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/obbox.cpp rename to Core/Libraries/Source/WWVegas/WWMath/obbox.cpp diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/obbox.h b/Core/Libraries/Source/WWVegas/WWMath/obbox.h similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/obbox.h rename to Core/Libraries/Source/WWVegas/WWMath/obbox.h diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/ode.cpp b/Core/Libraries/Source/WWVegas/WWMath/ode.cpp similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/ode.cpp rename to Core/Libraries/Source/WWVegas/WWMath/ode.cpp diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/ode.h b/Core/Libraries/Source/WWVegas/WWMath/ode.h similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/ode.h rename to Core/Libraries/Source/WWVegas/WWMath/ode.h diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/plane.h b/Core/Libraries/Source/WWVegas/WWMath/plane.h similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/plane.h rename to Core/Libraries/Source/WWVegas/WWMath/plane.h diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/pot.cpp b/Core/Libraries/Source/WWVegas/WWMath/pot.cpp similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/pot.cpp rename to Core/Libraries/Source/WWVegas/WWMath/pot.cpp diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/pot.h b/Core/Libraries/Source/WWVegas/WWMath/pot.h similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/pot.h rename to Core/Libraries/Source/WWVegas/WWMath/pot.h diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/quat.cpp b/Core/Libraries/Source/WWVegas/WWMath/quat.cpp similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/quat.cpp rename to Core/Libraries/Source/WWVegas/WWMath/quat.cpp diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/quat.h b/Core/Libraries/Source/WWVegas/WWMath/quat.h similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/quat.h rename to Core/Libraries/Source/WWVegas/WWMath/quat.h diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/rect.h b/Core/Libraries/Source/WWVegas/WWMath/rect.h similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/rect.h rename to Core/Libraries/Source/WWVegas/WWMath/rect.h diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/sphere.h b/Core/Libraries/Source/WWVegas/WWMath/sphere.h similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/sphere.h rename to Core/Libraries/Source/WWVegas/WWMath/sphere.h diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/tcbspline.cpp b/Core/Libraries/Source/WWVegas/WWMath/tcbspline.cpp similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/tcbspline.cpp rename to Core/Libraries/Source/WWVegas/WWMath/tcbspline.cpp diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/tcbspline.h b/Core/Libraries/Source/WWVegas/WWMath/tcbspline.h similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/tcbspline.h rename to Core/Libraries/Source/WWVegas/WWMath/tcbspline.h diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/tri.cpp b/Core/Libraries/Source/WWVegas/WWMath/tri.cpp similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/tri.cpp rename to Core/Libraries/Source/WWVegas/WWMath/tri.cpp diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/tri.h b/Core/Libraries/Source/WWVegas/WWMath/tri.h similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/tri.h rename to Core/Libraries/Source/WWVegas/WWMath/tri.h diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/v3_rnd.cpp b/Core/Libraries/Source/WWVegas/WWMath/v3_rnd.cpp similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/v3_rnd.cpp rename to Core/Libraries/Source/WWVegas/WWMath/v3_rnd.cpp diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/v3_rnd.h b/Core/Libraries/Source/WWVegas/WWMath/v3_rnd.h similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/v3_rnd.h rename to Core/Libraries/Source/WWVegas/WWMath/v3_rnd.h diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/vector2.h b/Core/Libraries/Source/WWVegas/WWMath/vector2.h similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/vector2.h rename to Core/Libraries/Source/WWVegas/WWMath/vector2.h diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/vector2i.h b/Core/Libraries/Source/WWVegas/WWMath/vector2i.h similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/vector2i.h rename to Core/Libraries/Source/WWVegas/WWMath/vector2i.h diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/vector3.h b/Core/Libraries/Source/WWVegas/WWMath/vector3.h similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/vector3.h rename to Core/Libraries/Source/WWVegas/WWMath/vector3.h diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/vector4.h b/Core/Libraries/Source/WWVegas/WWMath/vector4.h similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/vector4.h rename to Core/Libraries/Source/WWVegas/WWMath/vector4.h diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/vehiclecurve.cpp b/Core/Libraries/Source/WWVegas/WWMath/vehiclecurve.cpp similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/vehiclecurve.cpp rename to Core/Libraries/Source/WWVegas/WWMath/vehiclecurve.cpp diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/vehiclecurve.h b/Core/Libraries/Source/WWVegas/WWMath/vehiclecurve.h similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/vehiclecurve.h rename to Core/Libraries/Source/WWVegas/WWMath/vehiclecurve.h diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/vp.cpp b/Core/Libraries/Source/WWVegas/WWMath/vp.cpp similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/vp.cpp rename to Core/Libraries/Source/WWVegas/WWMath/vp.cpp diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/vp.h b/Core/Libraries/Source/WWVegas/WWMath/vp.h similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/vp.h rename to Core/Libraries/Source/WWVegas/WWMath/vp.h diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/wwmath.cpp b/Core/Libraries/Source/WWVegas/WWMath/wwmath.cpp similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/wwmath.cpp rename to Core/Libraries/Source/WWVegas/WWMath/wwmath.cpp diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/wwmath.h b/Core/Libraries/Source/WWVegas/WWMath/wwmath.h similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/wwmath.h rename to Core/Libraries/Source/WWVegas/WWMath/wwmath.h diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/wwmathids.h b/Core/Libraries/Source/WWVegas/WWMath/wwmathids.h similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/wwmathids.h rename to Core/Libraries/Source/WWVegas/WWMath/wwmathids.h diff --git a/Generals/Code/Libraries/Source/WWVegas/WWSaveLoad/CMakeLists.txt b/Core/Libraries/Source/WWVegas/WWSaveLoad/CMakeLists.txt similarity index 76% rename from Generals/Code/Libraries/Source/WWVegas/WWSaveLoad/CMakeLists.txt rename to Core/Libraries/Source/WWVegas/WWSaveLoad/CMakeLists.txt index b0c9c99e405..f6875832bee 100644 --- a/Generals/Code/Libraries/Source/WWVegas/WWSaveLoad/CMakeLists.txt +++ b/Core/Libraries/Source/WWVegas/WWSaveLoad/CMakeLists.txt @@ -37,11 +37,11 @@ set(WWSAVELOAD_SRC ) # Targets to build. -add_library(g_wwsaveload STATIC) -set_target_properties(g_wwsaveload PROPERTIES OUTPUT_NAME wwsaveload) +add_library(core_wwsaveload STATIC) +set_target_properties(core_wwsaveload PROPERTIES OUTPUT_NAME wwsaveload) -target_sources(g_wwsaveload PRIVATE ${WWSAVELOAD_SRC}) +target_sources(core_wwsaveload PRIVATE ${WWSAVELOAD_SRC}) -target_link_libraries(g_wwsaveload PRIVATE - g_wwcommon +target_link_libraries(core_wwsaveload PRIVATE + core_wwcommon ) diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWSaveLoad/definition.cpp b/Core/Libraries/Source/WWVegas/WWSaveLoad/definition.cpp similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWSaveLoad/definition.cpp rename to Core/Libraries/Source/WWVegas/WWSaveLoad/definition.cpp diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWSaveLoad/definition.h b/Core/Libraries/Source/WWVegas/WWSaveLoad/definition.h similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWSaveLoad/definition.h rename to Core/Libraries/Source/WWVegas/WWSaveLoad/definition.h diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWSaveLoad/definitionclassids.h b/Core/Libraries/Source/WWVegas/WWSaveLoad/definitionclassids.h similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWSaveLoad/definitionclassids.h rename to Core/Libraries/Source/WWVegas/WWSaveLoad/definitionclassids.h diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWSaveLoad/definitionfactory.cpp b/Core/Libraries/Source/WWVegas/WWSaveLoad/definitionfactory.cpp similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWSaveLoad/definitionfactory.cpp rename to Core/Libraries/Source/WWVegas/WWSaveLoad/definitionfactory.cpp diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWSaveLoad/definitionfactory.h b/Core/Libraries/Source/WWVegas/WWSaveLoad/definitionfactory.h similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWSaveLoad/definitionfactory.h rename to Core/Libraries/Source/WWVegas/WWSaveLoad/definitionfactory.h diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWSaveLoad/definitionfactorymgr.cpp b/Core/Libraries/Source/WWVegas/WWSaveLoad/definitionfactorymgr.cpp similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWSaveLoad/definitionfactorymgr.cpp rename to Core/Libraries/Source/WWVegas/WWSaveLoad/definitionfactorymgr.cpp diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWSaveLoad/definitionfactorymgr.h b/Core/Libraries/Source/WWVegas/WWSaveLoad/definitionfactorymgr.h similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWSaveLoad/definitionfactorymgr.h rename to Core/Libraries/Source/WWVegas/WWSaveLoad/definitionfactorymgr.h diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWSaveLoad/definitionmgr.cpp b/Core/Libraries/Source/WWVegas/WWSaveLoad/definitionmgr.cpp similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWSaveLoad/definitionmgr.cpp rename to Core/Libraries/Source/WWVegas/WWSaveLoad/definitionmgr.cpp diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWSaveLoad/definitionmgr.h b/Core/Libraries/Source/WWVegas/WWSaveLoad/definitionmgr.h similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWSaveLoad/definitionmgr.h rename to Core/Libraries/Source/WWVegas/WWSaveLoad/definitionmgr.h diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWSaveLoad/editable.h b/Core/Libraries/Source/WWVegas/WWSaveLoad/editable.h similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWSaveLoad/editable.h rename to Core/Libraries/Source/WWVegas/WWSaveLoad/editable.h diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWSaveLoad/parameter.cpp b/Core/Libraries/Source/WWVegas/WWSaveLoad/parameter.cpp similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWSaveLoad/parameter.cpp rename to Core/Libraries/Source/WWVegas/WWSaveLoad/parameter.cpp diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWSaveLoad/parameter.h b/Core/Libraries/Source/WWVegas/WWSaveLoad/parameter.h similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWSaveLoad/parameter.h rename to Core/Libraries/Source/WWVegas/WWSaveLoad/parameter.h diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWSaveLoad/parameterlist.h b/Core/Libraries/Source/WWVegas/WWSaveLoad/parameterlist.h similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWSaveLoad/parameterlist.h rename to Core/Libraries/Source/WWVegas/WWSaveLoad/parameterlist.h diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWSaveLoad/parametertypes.h b/Core/Libraries/Source/WWVegas/WWSaveLoad/parametertypes.h similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWSaveLoad/parametertypes.h rename to Core/Libraries/Source/WWVegas/WWSaveLoad/parametertypes.h diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWSaveLoad/persist.h b/Core/Libraries/Source/WWVegas/WWSaveLoad/persist.h similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWSaveLoad/persist.h rename to Core/Libraries/Source/WWVegas/WWSaveLoad/persist.h diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWSaveLoad/persistfactory.cpp b/Core/Libraries/Source/WWVegas/WWSaveLoad/persistfactory.cpp similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWSaveLoad/persistfactory.cpp rename to Core/Libraries/Source/WWVegas/WWSaveLoad/persistfactory.cpp diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWSaveLoad/persistfactory.h b/Core/Libraries/Source/WWVegas/WWSaveLoad/persistfactory.h similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWSaveLoad/persistfactory.h rename to Core/Libraries/Source/WWVegas/WWSaveLoad/persistfactory.h diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWSaveLoad/pointerremap.cpp b/Core/Libraries/Source/WWVegas/WWSaveLoad/pointerremap.cpp similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWSaveLoad/pointerremap.cpp rename to Core/Libraries/Source/WWVegas/WWSaveLoad/pointerremap.cpp diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWSaveLoad/pointerremap.h b/Core/Libraries/Source/WWVegas/WWSaveLoad/pointerremap.h similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWSaveLoad/pointerremap.h rename to Core/Libraries/Source/WWVegas/WWSaveLoad/pointerremap.h diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWSaveLoad/postloadable.h b/Core/Libraries/Source/WWVegas/WWSaveLoad/postloadable.h similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWSaveLoad/postloadable.h rename to Core/Libraries/Source/WWVegas/WWSaveLoad/postloadable.h diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWSaveLoad/saveload.cpp b/Core/Libraries/Source/WWVegas/WWSaveLoad/saveload.cpp similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWSaveLoad/saveload.cpp rename to Core/Libraries/Source/WWVegas/WWSaveLoad/saveload.cpp diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWSaveLoad/saveload.h b/Core/Libraries/Source/WWVegas/WWSaveLoad/saveload.h similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWSaveLoad/saveload.h rename to Core/Libraries/Source/WWVegas/WWSaveLoad/saveload.h diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWSaveLoad/saveloadids.h b/Core/Libraries/Source/WWVegas/WWSaveLoad/saveloadids.h similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWSaveLoad/saveloadids.h rename to Core/Libraries/Source/WWVegas/WWSaveLoad/saveloadids.h diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWSaveLoad/saveloadstatus.cpp b/Core/Libraries/Source/WWVegas/WWSaveLoad/saveloadstatus.cpp similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWSaveLoad/saveloadstatus.cpp rename to Core/Libraries/Source/WWVegas/WWSaveLoad/saveloadstatus.cpp diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWSaveLoad/saveloadstatus.h b/Core/Libraries/Source/WWVegas/WWSaveLoad/saveloadstatus.h similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWSaveLoad/saveloadstatus.h rename to Core/Libraries/Source/WWVegas/WWSaveLoad/saveloadstatus.h diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWSaveLoad/saveloadsubsystem.cpp b/Core/Libraries/Source/WWVegas/WWSaveLoad/saveloadsubsystem.cpp similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWSaveLoad/saveloadsubsystem.cpp rename to Core/Libraries/Source/WWVegas/WWSaveLoad/saveloadsubsystem.cpp diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWSaveLoad/saveloadsubsystem.h b/Core/Libraries/Source/WWVegas/WWSaveLoad/saveloadsubsystem.h similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWSaveLoad/saveloadsubsystem.h rename to Core/Libraries/Source/WWVegas/WWSaveLoad/saveloadsubsystem.h diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWSaveLoad/simpledefinitionfactory.h b/Core/Libraries/Source/WWVegas/WWSaveLoad/simpledefinitionfactory.h similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWSaveLoad/simpledefinitionfactory.h rename to Core/Libraries/Source/WWVegas/WWSaveLoad/simpledefinitionfactory.h diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWSaveLoad/simpleparameter.h b/Core/Libraries/Source/WWVegas/WWSaveLoad/simpleparameter.h similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWSaveLoad/simpleparameter.h rename to Core/Libraries/Source/WWVegas/WWSaveLoad/simpleparameter.h diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWSaveLoad/twiddler.cpp b/Core/Libraries/Source/WWVegas/WWSaveLoad/twiddler.cpp similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWSaveLoad/twiddler.cpp rename to Core/Libraries/Source/WWVegas/WWSaveLoad/twiddler.cpp diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWSaveLoad/twiddler.h b/Core/Libraries/Source/WWVegas/WWSaveLoad/twiddler.h similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWSaveLoad/twiddler.h rename to Core/Libraries/Source/WWVegas/WWSaveLoad/twiddler.h diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWSaveLoad/wwsaveload.cpp b/Core/Libraries/Source/WWVegas/WWSaveLoad/wwsaveload.cpp similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWSaveLoad/wwsaveload.cpp rename to Core/Libraries/Source/WWVegas/WWSaveLoad/wwsaveload.cpp diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWSaveLoad/wwsaveload.h b/Core/Libraries/Source/WWVegas/WWSaveLoad/wwsaveload.h similarity index 100% rename from GeneralsMD/Code/Libraries/Source/WWVegas/WWSaveLoad/wwsaveload.h rename to Core/Libraries/Source/WWVegas/WWSaveLoad/wwsaveload.h diff --git a/Generals/Code/Libraries/Source/WWVegas/CMakeLists.txt b/Generals/Code/Libraries/Source/WWVegas/CMakeLists.txt index 38082f3ffdf..241d8b780b3 100644 --- a/Generals/Code/Libraries/Source/WWVegas/CMakeLists.txt +++ b/Generals/Code/Libraries/Source/WWVegas/CMakeLists.txt @@ -14,14 +14,10 @@ target_include_directories(g_wwcommon INTERFACE . WW3D2 WWAudio - WWMath - WWSaveLoad Wwutil ) -add_subdirectory(WWMath) add_subdirectory(Wwutil) -add_subdirectory(WWSaveLoad) add_subdirectory(WW3D2) add_subdirectory(WWDownload) @@ -32,8 +28,6 @@ target_include_directories(g_wwvegas INTERFACE . WW3D2 WWDownload - WWMath - WWSaveLoad Wwutil ) @@ -41,7 +35,5 @@ target_link_libraries(g_wwvegas INTERFACE core_wwvegas g_ww3d2 g_wwdownload - g_wwmath - g_wwsaveload g_wwutil ) diff --git a/Generals/Code/Libraries/Source/WWVegas/WWMath/CMakeLists.txt b/Generals/Code/Libraries/Source/WWVegas/WWMath/CMakeLists.txt deleted file mode 100644 index 1c4833f1e87..00000000000 --- a/Generals/Code/Libraries/Source/WWVegas/WWMath/CMakeLists.txt +++ /dev/null @@ -1,93 +0,0 @@ -set(WWMATH_SRC - aabox.cpp - aabox.h - aabtreecull.cpp - aabtreecull.h - aaplane.h - cardinalspline.cpp - cardinalspline.h - castres.h - catmullromspline.cpp - catmullromspline.h - colmath.cpp - colmath.h - colmathaabox.cpp - colmathaabox.h - colmathaabtri.cpp - colmathfrustum.cpp - colmathfrustum.h - colmathinlines.h - colmathline.cpp - colmathline.h - colmathobbobb.cpp - colmathobbox.cpp - colmathobbtri.cpp - colmathplane.cpp - colmathplane.h - colmathsphere.cpp - cullsys.cpp - cullsys.h - culltype.h - curve.cpp - curve.h - euler.cpp - euler.h - frustum.cpp - frustum.h - gridcull.cpp - gridcull.h - hermitespline.cpp - hermitespline.h - lineseg.cpp - lineseg.h - lookuptable.cpp - lookuptable.h - matrix3.cpp - matrix3.h - matrix3d.cpp - matrix3d.h - matrix4.cpp - matrix4.h - obbox.cpp - obbox.h - ode.cpp - ode.h - plane.h - pot.cpp - pot.h - quat.cpp - quat.h - rect.h - sphere.h - tcbspline.cpp - tcbspline.h - tri.cpp - tri.h - v3_rnd.cpp - v3_rnd.h - vector2.h - vector2i.h - vector3.h - Vector3i.h - vector4.h - vehiclecurve.cpp - vehiclecurve.h - vp.cpp - vp.h - wwmath.cpp - wwmath.h - wwmathids.h -) - -# Targets to build. -add_library(g_wwmath STATIC) -set_target_properties(g_wwmath PROPERTIES OUTPUT_NAME wwmath) - -target_sources(g_wwmath PRIVATE ${WWMATH_SRC}) - -target_link_libraries(g_wwmath PRIVATE - g_wwcommon -) - -# @todo Test its impact and see what to do with the legacy functions. -#add_compile_definitions(z_wwmath PUBLIC ALLOW_TEMPORARIES) # Enables legacy math with "temporaries" diff --git a/Generals/Code/Libraries/Source/WWVegas/WWMath/Vector3i.h b/Generals/Code/Libraries/Source/WWVegas/WWMath/Vector3i.h deleted file mode 100644 index c6628801566..00000000000 --- a/Generals/Code/Libraries/Source/WWVegas/WWMath/Vector3i.h +++ /dev/null @@ -1,143 +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 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 : WWMath * - * * - * $Archive:: /Commando/Code/wwmath/vector3i.h $* - * * - * Author:: Greg Hjelstrom * - * * - * $Modtime:: 11/24/01 5:24p $* - * * - * $Revision:: 5 $* - * * - *---------------------------------------------------------------------------------------------* - * Functions: * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - - -#if defined(_MSC_VER) -#pragma once -#endif - -#ifndef VECTOR3I_H -#define VECTOR3I_H - -#include "always.h" - -class Vector3i -{ -public: - - int I; - int J; - int K; - - WWINLINE Vector3i(void); - WWINLINE Vector3i(int i,int j,int k); - - WWINLINE bool operator== (const Vector3i & v) const; - WWINLINE bool operator!= (const Vector3i& v) const; - WWINLINE const int& operator[] (int n) const; - WWINLINE int& operator[] (int n); -}; - - -WWINLINE Vector3i::Vector3i(void) -{ -} - -WWINLINE Vector3i::Vector3i(int i,int j,int k) -{ - I = i; J = j; K = k; -} - -WWINLINE bool Vector3i::operator == (const Vector3i & v) const -{ - return (I == v.I && J == v.J && K == v.K); -} - -WWINLINE bool Vector3i::operator != (const Vector3i& v) const -{ - return !(I == v.I && J == v.J && K == v.K); -} - -WWINLINE const int& Vector3i::operator[] (int n) const -{ - return ((int*)this)[n]; -} - -WWINLINE int& Vector3i::operator[] (int n) -{ - return ((int*)this)[n]; -} - -// ---------------------------------------------------------------------------- - -class Vector3i16 -{ -public: - - unsigned short I; - unsigned short J; - unsigned short K; - - WWINLINE Vector3i16(void); - WWINLINE Vector3i16(unsigned short i,unsigned short j,unsigned short k); - - WWINLINE bool operator== (const Vector3i & v) const; - WWINLINE bool operator!= (const Vector3i& v) const; - WWINLINE const unsigned short & operator[] (int n) const; - WWINLINE unsigned short & operator[] (int n); -}; - - -WWINLINE Vector3i16::Vector3i16(void) -{ -} - -WWINLINE Vector3i16::Vector3i16(unsigned short i,unsigned short j,unsigned short k) -{ - I = i; J = j; K = k; -} - -WWINLINE bool Vector3i16::operator == (const Vector3i & v) const -{ - return (I == v.I && J == v.J && K == v.K); -} - -WWINLINE bool Vector3i16::operator != (const Vector3i& v) const -{ - return !(I == v.I && J == v.J && K == v.K); -} - -WWINLINE const unsigned short & Vector3i16::operator[] (int n) const -{ - return ((unsigned short *)this)[n]; -} - -WWINLINE unsigned short & Vector3i16::operator[] (int n) -{ - return ((unsigned short *)this)[n]; -} - -#endif \ No newline at end of file diff --git a/Generals/Code/Libraries/Source/WWVegas/WWMath/aabox.cpp b/Generals/Code/Libraries/Source/WWVegas/WWMath/aabox.cpp deleted file mode 100644 index fe90beff7a9..00000000000 --- a/Generals/Code/Libraries/Source/WWVegas/WWMath/aabox.cpp +++ /dev/null @@ -1,79 +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 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 : WWMath * - * * - * $Archive:: /Commando/Code/wwmath/aabox.cpp $* - * * - * Author:: Greg_h * - * * - * $Modtime:: 5/08/01 6:33p $* - * * - * $Revision:: 18 $* - * * - *---------------------------------------------------------------------------------------------* - * Functions: * - * AABoxClass::Init_Random -- initializes this box to a random state * - * AABoxClass::Contains -- test whether this box contains the given point * - * AABoxClass::Contains -- Test whether this box contains the given box * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - -#include "aabox.h" -#include "colmath.h" -#include "colmathinlines.h" -#include - - -/*********************************************************************************************** - * AABoxClass::Init_Random -- initializes this box to a random state * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 3/17/2000 gth : Created. * - *=============================================================================================*/ -void AABoxClass::Init_Random(float min_center,float max_center,float min_extent,float max_extent) -{ - Center.X = min_center + WWMath::Random_Float() * (max_center - min_center); - Center.Y = min_center + WWMath::Random_Float() * (max_center - min_center); - Center.Z = min_center + WWMath::Random_Float() * (max_center - min_center); - - Extent.X = min_extent + WWMath::Random_Float() * (max_extent - min_extent); - Extent.Y = min_extent + WWMath::Random_Float() * (max_extent - min_extent); - Extent.Z = min_extent + WWMath::Random_Float() * (max_extent - min_extent); -} - - -void AABoxClass::Transform(const Matrix3D & tm,const AABoxClass & in,AABoxClass * out) -{ - tm.Transform_Center_Extent_AABox(in.Center,in.Extent,&(out->Center),&(out->Extent)); -} - -void MinMaxAABoxClass::Init_Empty(void) -{ - MinCorner.Set(FLT_MAX,FLT_MAX,FLT_MAX); - MaxCorner.Set(-FLT_MAX,-FLT_MAX,-FLT_MAX); -} diff --git a/Generals/Code/Libraries/Source/WWVegas/WWMath/aabox.h b/Generals/Code/Libraries/Source/WWVegas/WWMath/aabox.h deleted file mode 100644 index c12f00742ee..00000000000 --- a/Generals/Code/Libraries/Source/WWVegas/WWMath/aabox.h +++ /dev/null @@ -1,679 +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 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 : WWMath * - * * - * $Archive:: /Commando/Code/wwmath/aabox.h $* - * * - * Author:: Greg_h * - * * - * $Modtime:: 5/08/01 6:35p $* - * * - * $Revision:: 30 $* - * * - *---------------------------------------------------------------------------------------------* - * Functions: * - * AABoxClass::Transform -- transform an aabox * - * AABoxClass::Translate -- transform an aabox * - * AABoxClass::Init -- create a box which bounds the given points * - * AABoxClass::Init -- initialize from a min-max form of a box * - * AABoxClass::Init_Min_Max -- init the box from a min and max vector * - * AABoxClass::Add_Point -- expand the box to contain the given point * - * AABoxClass::Project_To_Axis -- compute projection onto the given axis * - * AABoxClass::Intersects -- test for intersection with another static aabox * - * AABoxClass::Add_Box -- expand this box to enclose the passed box * - * AABoxClass::Add_Box -- Expand this box to enclose the passed box * - * MinMaxAABoxClass::Init -- init the box from an array of points * - * MinMaxAABoxClass::Init -- initializes this box from a center-extent box * - * MinMaxAABoxClass::Add_Point -- updates this box so it encloses the given point * - * MinMaxAABoxClass::Add_Box -- update this box to enclose the given box * - * MinMaxAABoxClass::Add_Box -- Updates this box to enclose the specified box * - * MinMaxAABoxClass::Transform -- Updates this box to enclose its transformed version * - * MinMaxAABoxClass::Translate -- translates the box * - * AABoxClass::Init -- Init from a line segment * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - -#if defined(_MSC_VER) -#pragma once -#endif - -#ifndef AABOX_H -#define AABOX_H - -#include "always.h" -#include "matrix3d.h" -#include "lineseg.h" -#include "colmath.h" - -class AABoxClass; -class MinMaxAABoxClass; -class OBBoxClass; -class TriClass; -class PlaneClass; -struct CastResultStruct; - - -/* -** AABoxClass -** -** Axis-Aligned Boxes. I've coded these similar to the OrientedBoxClass only -** without a rotation matrix. A similar algorithm is used to test the box -** for intersection. -*/ -class AABoxClass -{ - -public: - - WWINLINE AABoxClass(void) { } - - WWINLINE AABoxClass(const Vector3 & center,const Vector3 & extent) : - Center(center), - Extent(extent) - { } - - AABoxClass(const MinMaxAABoxClass & minmaxbox) { Init(minmaxbox); } - - AABoxClass(Vector3 * points,int num) { Init(points,num); } - - bool operator== (const AABoxClass &src); - bool operator!= (const AABoxClass &src); - - WWINLINE void Init(const Vector3& center,const Vector3 & extent) { Center = center; Extent = extent; } - WWINLINE void Init(Vector3 * points,int num); - WWINLINE void Init(const MinMaxAABoxClass & minmaxbox); - void Init(const LineSegClass & line); - void Init_Min_Max(const Vector3 & min,const Vector3 & max); - void Init_Random(float min_center = -1.0f,float max_center = 1.0f,float min_extent = 0.5f,float max_extent = 1.0f); - - void Add_Point(const Vector3 & point); - void Add_Box(const AABoxClass & b); - void Add_Box(const MinMaxAABoxClass & b); - float Project_To_Axis(const Vector3 & axis) const; - - void Transform(const Matrix3D & tm); - void Translate(const Vector3 & pos); - - WWINLINE float Volume(void) const { return 2.0*Extent.X * 2.0*Extent.Y * 2.0*Extent.Z; } - WWINLINE bool Contains(const Vector3 & point) const; - WWINLINE bool Contains(const AABoxClass & other_box) const; - WWINLINE bool Contains(const MinMaxAABoxClass & other_box) const; - - static void Transform(const Matrix3D & tm,const AABoxClass & in,AABoxClass * out); - - Vector3 Center; // world space center - Vector3 Extent; // size of the box in the three directions - -}; - -/* -** MinMaxAABoxClass -** This is another form of an AABox. It can be faster to build one of these -** and then convert it into a center-extent AABox in some cases. Its purpose -** is basically that. -*/ -class MinMaxAABoxClass -{ -public: - - WWINLINE MinMaxAABoxClass(void) { } - - WWINLINE MinMaxAABoxClass(const Vector3 & min_corner,const Vector3 & max_corner) : - MinCorner(min_corner), - MaxCorner(max_corner) - { - } - - WWINLINE MinMaxAABoxClass(Vector3 * points,int num) { Init(points,num); } - - WWINLINE MinMaxAABoxClass(const AABoxClass & that) { Init(that); } - - WWINLINE void Init(Vector3 * points,int num); - WWINLINE void Init(const AABoxClass & box); - void Init_Empty(void); - - void Add_Point(const Vector3 & point); - void Add_Box(const MinMaxAABoxClass & box); - void Add_Box(const AABoxClass & box); - void Add_Box(const Vector3 & min_corner,const Vector3 & max_corner); - - void Transform(const Matrix3D & tm); - void Translate(const Vector3 & pos); - - WWINLINE float Volume(void) const { Vector3 size = MaxCorner - MinCorner; return size.X*size.Y*size.Z; } - - Vector3 MinCorner; - Vector3 MaxCorner; -}; - - - - -/*********************************************************************************************** - * AABoxClass::Transform -- transform an aabox * - * * - * Note that this function expands the box to enclose its transformed form. * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 2/24/98 GTH : Created. * - *=============================================================================================*/ -WWINLINE void AABoxClass::Transform(const Matrix3D & tm) -{ - Vector3 oldcenter = Center; - Vector3 oldextent = Extent; - tm.Transform_Center_Extent_AABox(oldcenter,oldextent,&Center,&Extent); -} - - -/*********************************************************************************************** - * AABoxClass::Translate -- translate an aabox * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 2/24/98 GTH : Created. * - *=============================================================================================*/ -WWINLINE void AABoxClass::Translate(const Vector3 & trans) -{ - Center += trans; -} - - -/*********************************************************************************************** - * AABoxClass::operator== -- Comparison operator * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 6/21/00 PDS : Created. * - *=============================================================================================*/ -WWINLINE bool AABoxClass::operator== (const AABoxClass &src) -{ - return (Center == src.Center) && (Extent == src.Extent); -} - - -/*********************************************************************************************** - * AABoxClass::operator!= -- Comparison operator * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 6/21/00 PDS : Created. * - *=============================================================================================*/ -WWINLINE bool AABoxClass::operator!= (const AABoxClass &src) -{ - return (Center != src.Center) || (Extent != src.Extent); -} - - -/*********************************************************************************************** - * AABoxClass::Init -- create a box which bounds the given points * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 2/24/98 GTH : Created. * - *=============================================================================================*/ -WWINLINE void AABoxClass::Init(Vector3 * points,int num) -{ - Vector3 Min = points[0]; - Vector3 Max = points[0]; - - for (int i=1; i points[i].X) Min.X = points[i].X; - if (Min.Y > points[i].Y) Min.Y = points[i].Y; - if (Min.Z > points[i].Z) Min.Z = points[i].Z; - - if (Max.X < points[i].X) Max.X = points[i].X; - if (Max.Y < points[i].Y) Max.Y = points[i].Y; - if (Max.Z < points[i].Z) Max.Z = points[i].Z; - } - - Center = (Max + Min) * 0.5f; - Extent = (Max - Min) * 0.5f; -} - - -/*********************************************************************************************** - * AABoxClass::Init -- initialize from a min-max form of a box * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 7/31/98 GTH : Created. * - *=============================================================================================*/ -WWINLINE void AABoxClass::Init(const MinMaxAABoxClass & mmbox) -{ - Center = (mmbox.MaxCorner + mmbox.MinCorner) * 0.5f; - Extent = (mmbox.MaxCorner - mmbox.MinCorner) * 0.5f; -} - - -/*********************************************************************************************** - * AABoxClass::Init -- Init from a line segment * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 4/27/2000 gth : Created. * - *=============================================================================================*/ -WWINLINE void AABoxClass::Init(const LineSegClass & line) -{ - Vector3 min_corner = line.Get_P0(); - Vector3 max_corner = line.Get_P0(); - - if (min_corner.X > line.Get_P1().X) min_corner.X = line.Get_P1().X; - if (min_corner.Y > line.Get_P1().Y) min_corner.Y = line.Get_P1().Y; - if (min_corner.Z > line.Get_P1().Z) min_corner.Z = line.Get_P1().Z; - - if (max_corner.X < line.Get_P1().X) max_corner.X = line.Get_P1().X; - if (max_corner.Y < line.Get_P1().Y) max_corner.Y = line.Get_P1().Y; - if (max_corner.Z < line.Get_P1().Z) max_corner.Z = line.Get_P1().Z; - - Center = (max_corner + min_corner) * 0.5f; - Extent = (max_corner - min_corner) * 0.5f; -} - -/*********************************************************************************************** - * AABoxClass::Init_Min_Max -- init the box from a min and max vector * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 4/9/99 GTH : Created. * - *=============================================================================================*/ -WWINLINE void AABoxClass::Init_Min_Max(const Vector3 & min,const Vector3 & max) -{ - Center = (max + min) * 0.5f; - Extent = (max - min) * 0.5f; -} - - -/*********************************************************************************************** - * AABoxClass::Add_Point -- expand the box to contain the given point * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 2/24/98 GTH : Created. * - *=============================================================================================*/ -WWINLINE void AABoxClass::Add_Point(const Vector3 & point) -{ - Vector3 Min = Center - Extent; - Vector3 Max = Center + Extent; - - if (Min.X > point.X) Min.X = point.X; - if (Min.Y > point.Y) Min.Y = point.Y; - if (Min.Z > point.Z) Min.Z = point.Z; - - if (Max.X < point.X) Max.X = point.X; - if (Max.Y < point.Y) Max.Y = point.Y; - if (Max.Z < point.Z) Max.Z = point.Z; - - Center = (Max + Min) / 2.0f; - Extent = (Max - Min) / 2.0f; -} - - -/*********************************************************************************************** - * AABoxClass::Add_Box -- expand this box to enclose the passed box * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 7/31/98 GTH : Created. * - * 9/29/2000 gth : Ok to add boxes with zero extent * - *=============================================================================================*/ -WWINLINE void AABoxClass::Add_Box(const AABoxClass & b) -{ - Vector3 newmin = Center - Extent; - Vector3 newmax = Center + Extent; - newmin.Update_Min(b.Center - b.Extent); - newmax.Update_Max(b.Center + b.Extent); - - Center = (newmax + newmin) * 0.5f; - Extent = (newmax - newmin) * 0.5f; -} - - -/*********************************************************************************************** - * AABoxClass::Add_Box -- Expand this box to enclose the passed box * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 7/31/98 GTH : Created. * - * 9/29/2000 gth : Ok to add boxes with zero extent * - *=============================================================================================*/ -WWINLINE void AABoxClass::Add_Box(const MinMaxAABoxClass & b) -{ - Vector3 newmin = Center - Extent; - Vector3 newmax = Center + Extent; - newmin.Update_Min(b.MinCorner); - newmax.Update_Max(b.MaxCorner); - - Center = (newmax + newmin) * 0.5f; - Extent = (newmax - newmin) * 0.5f; -} - -/*********************************************************************************************** - * AABoxClass::Project_To_Axis -- compute projection onto the given axis * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 2/24/98 GTH : Created. * - *=============================================================================================*/ -WWINLINE float AABoxClass::Project_To_Axis(const Vector3 & axis) const -{ - float x = Extent[0] * axis[0]; - float y = Extent[1] * axis[1]; - float z = Extent[2] * axis[2]; - - // projection is the sum of the absolute values of the projections of the three extents - return (WWMath::Fabs(x) + WWMath::Fabs(y) + WWMath::Fabs(z)); -} - -/*********************************************************************************************** - * AABoxClass::Contains -- Test whether this box contains the given box * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 9/2/98 GTH : Created. * - *=============================================================================================*/ -WWINLINE bool AABoxClass::Contains(const AABoxClass & other_box) const -{ - return CollisionMath::Overlap_Test(*this,other_box) == CollisionMath::INSIDE; -} - -/*********************************************************************************************** - * AABoxClass::Contains -- Test whether this box contains the given box * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 9/2/98 GTH : Created. * - *=============================================================================================*/ -WWINLINE bool AABoxClass::Contains(const MinMaxAABoxClass & other_box) const -{ - Vector3 bmin = Center - Extent; - Vector3 bmax = Center + Extent; - - if (other_box.MinCorner.X < bmin.X) return false; - if (other_box.MinCorner.Y < bmin.Y) return false; - if (other_box.MinCorner.Z < bmin.Z) return false; - - if (other_box.MaxCorner.X > bmax.X) return false; - if (other_box.MaxCorner.Y > bmax.Y) return false; - if (other_box.MaxCorner.Z > bmax.Z) return false; - - return true; -} - -/*********************************************************************************************** - * AABoxClass::Contains -- test whether this box contains the given point * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 9/2/98 GTH : Created. * - *=============================================================================================*/ -WWINLINE bool AABoxClass::Contains(const Vector3 & point) const -{ - return CollisionMath::Overlap_Test(*this,point) == CollisionMath::INSIDE; -} - -/*********************************************************************************************** - * MinMaxAABoxClass::Init -- init the box from an array of points * - * * - * Makes a box which encloses the given array of points * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 7/31/98 GTH : Created. * - *=============================================================================================*/ -WWINLINE void MinMaxAABoxClass::Init(Vector3 * points,int num) -{ - assert(num > 0); - assert(points != NULL); - MinCorner = points[0]; - MaxCorner = points[0]; - for (int i=0; i= min_corner.X); - assert(max_corner.Y >= min_corner.Y); - assert(max_corner.Z >= min_corner.Z); - - if (min_corner == max_corner) return; - - MinCorner.Update_Min(min_corner); - MaxCorner.Update_Max(max_corner); -} - - -/*********************************************************************************************** - * MinMaxAABoxClass::Transform -- Updates this box to enclose its transformed version * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 7/31/98 GTH : Created. * - *=============================================================================================*/ -WWINLINE void MinMaxAABoxClass::Transform(const Matrix3D & tm) -{ - Vector3 oldmin = MinCorner; - Vector3 oldmax = MaxCorner; - tm.Transform_Min_Max_AABox(oldmin,oldmax,&MinCorner,&MaxCorner); -} - - -/*********************************************************************************************** - * MinMaxAABoxClass::Translate -- translates the box * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 7/31/98 GTH : Created. * - *=============================================================================================*/ -WWINLINE void MinMaxAABoxClass::Translate(const Vector3 & pos) -{ - MinCorner+=pos; - MaxCorner+=pos; -} - - -#endif diff --git a/Generals/Code/Libraries/Source/WWVegas/WWMath/aabtreecull.cpp b/Generals/Code/Libraries/Source/WWVegas/WWMath/aabtreecull.cpp deleted file mode 100644 index af8a4213d58..00000000000 --- a/Generals/Code/Libraries/Source/WWVegas/WWMath/aabtreecull.cpp +++ /dev/null @@ -1,1616 +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 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 : WWMath * - * * - * $Archive:: /Commando/Code/wwmath/aabtreecull.cpp $* - * * - * Author:: Greg Hjelstrom * - * * - * $Modtime:: 8/26/01 2:18p $* - * * - * $Revision:: 25 $* - * * - *---------------------------------------------------------------------------------------------* - * Functions: * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - - -#include "aabtreecull.h" -#include "chunkio.h" -#include "iostruct.h" -#include -#include "sphere.h" -#include "colmath.h" -#include "colmathinlines.h" - - - -/* -** Declare the pools -*/ -DEFINE_AUTO_POOL(AABTreeLinkClass,256); -DEFINE_AUTO_POOL(AABTreeNodeClass,256); - - -/* -** Current version of the file format -*/ -const uint32 AABTREE_CURRENT_VERSION = 0x00010000; - - -/* -** Chunk Id's used by the aabtree code to save itself into a file -*/ -enum -{ - AABTREE_CHUNK_VERSION = 0x00000001, // version wrapper, contains 32bit version # - AABTREE_CHUNK_AABNODE = 0x00000101, // generic aab-node wrapper - AABTREE_CHUNK_AABNODE_INFO, // OBSOLETE! generic aab-node definition (IOAABNodeStruct) - AABTREE_CHUNK_AABNODE_CONTENTS, // wrapper around contents of the node - AABTREE_CHUNK_AABNODE_VARIABLES, // wrapper around variables for a node - - AABTREE_CHUNK_NODE_INDEX = 0x00000200, // wrapper around the node index for an object - - AABTREE_VARIABLE_NODESTRUCT = 0x00, - AABTREE_VARIABLE_USERDATA -}; - - -/* -** IOAABNodeStruct -** Data structure for the contents of a node in the AAB-Tree -*/ -#define AABNODE_ATTRIBUTE_FRONT_CHILD 0x00000001 -#define AABNODE_ATTRIBUTE_BACK_CHILD 0x00000002 - -struct IOAABNodeStruct -{ - IOVector3Struct Center; - IOVector3Struct Extent; - uint32 Attributes; -}; - - -/************************************************************************* -** -** Utility functions for walking the object list in an AABTree Node -** -*************************************************************************/ -static inline CullableClass * get_first_object(AABTreeNodeClass * node) -{ - return node->Object; -} - -static inline CullableClass * get_next_object(CullableClass * obj) -{ - return ((AABTreeLinkClass *)obj->Get_Cull_Link())->NextObject; -} - - -/************************************************************************* -** -** AABTreeCullSystemClass Implementation -** -*************************************************************************/ -AABTreeCullSystemClass::AABTreeCullSystemClass(void) : - ObjectCount(0), - NodeCount(0), - IndexedNodes(NULL) -{ - RootNode = new AABTreeNodeClass; - Re_Index_Nodes(); -} - -AABTreeCullSystemClass::~AABTreeCullSystemClass(void) -{ - // Delete all links and release-ref all cullables: - int nidx; - for (nidx = 0; nidx < NodeCount; nidx++) { - while(IndexedNodes[nidx]->Object) Remove_Object_Internal(IndexedNodes[nidx]->Object); - } - - // Delete node tree (deleting the root recursively deletes all nodes) - delete RootNode; - - // Delete indexed node pointer array - if (IndexedNodes) { - delete[] IndexedNodes; - IndexedNodes = NULL; - } -} - - -void AABTreeCullSystemClass::Add_Object_Internal(CullableClass * obj,int node_index) -{ - WWASSERT_PRINT - ( - (obj->Get_Culling_System() == NULL), - "AABTreeCullSystemClass::Add -- Object is already in another culling system!\n" - ); - - AABTreeLinkClass * new_link = new AABTreeLinkClass(this); - obj->Set_Cull_Link(new_link); - - if (node_index == -1) { - Add_Object_Recursive(RootNode,obj); - } else { - WWASSERT(node_index < NodeCount); - IndexedNodes[node_index]->Add_Object(obj,false); - ObjectCount++; - } - - obj->Add_Ref(); -} - - -void AABTreeCullSystemClass::Remove_Object_Internal(CullableClass * obj) -{ - WWASSERT(obj); - WWASSERT(obj->Get_Culling_System() == this); - - AABTreeLinkClass * link = (AABTreeLinkClass *)obj->Get_Cull_Link(); - WWASSERT(link); - - AABTreeNodeClass * node = link->Node; - WWASSERT(node); - - node->Remove_Object(obj); - link->Set_Culling_System(NULL); - delete link; - obj->Set_Cull_Link(NULL); - - ObjectCount--; - WWASSERT(ObjectCount >= 0); - obj->Release_Ref(); -} - -void AABTreeCullSystemClass::Update_Culling(CullableClass * obj) -{ - WWASSERT(obj); - WWASSERT(obj->Get_Culling_System() == this); - - // unlink it from the node it is currently in - AABTreeLinkClass * link = (AABTreeLinkClass *)obj->Get_Cull_Link(); - WWASSERT(link); - AABTreeNodeClass * node = link->Node; - WWASSERT(node); - node->Remove_Object(obj); - // decrement the object counter, the node can't - // decrement it for us... - ObjectCount--; - - // drop it into the tree again - Add_Object_Recursive(RootNode,obj); -} - -void AABTreeCullSystemClass::Collect_Objects(const Vector3 & point) -{ - Collect_Objects_Recursive(RootNode,point); -} - -void AABTreeCullSystemClass::Collect_Objects(const AABoxClass & box) -{ - Collect_Objects_Recursive(RootNode,box); -} - -void AABTreeCullSystemClass::Collect_Objects(const OBBoxClass & box) -{ - Collect_Objects_Recursive(RootNode,box); -} - -void AABTreeCullSystemClass::Collect_Objects(const FrustumClass & frustum) -{ - Collect_Objects_Recursive(RootNode,frustum,0); -} - -void AABTreeCullSystemClass::Collect_Objects(const SphereClass & sphere) -{ - Collect_Objects_Recursive(RootNode,sphere); -} - -int AABTreeCullSystemClass::Partition_Node_Count(void) const -{ - return Partition_Node_Count_Recursive(RootNode); -} - -int AABTreeCullSystemClass::Partition_Tree_Depth(void) const -{ - int get_max_depth = 0; - Partition_Tree_Depth_Recursive(RootNode,0,get_max_depth); - return get_max_depth; -} - -int AABTreeCullSystemClass::Object_Count(void) const -{ - return ObjectCount; -} - -int AABTreeCullSystemClass::Partition_Node_Count_Recursive(AABTreeNodeClass * node) const -{ - int curcount = 1; - if (node->Front) { - curcount += Partition_Node_Count_Recursive(node->Front); - } - if (node->Back) { - curcount += Partition_Node_Count_Recursive(node->Back); - } - return curcount; -} - -void AABTreeCullSystemClass::Partition_Tree_Depth_Recursive(AABTreeNodeClass * node,int cur_depth,int & max_depth) const -{ - cur_depth++; - if (cur_depth > max_depth) { - max_depth = cur_depth; - } - if (node->Front) { - Partition_Tree_Depth_Recursive(node->Front,cur_depth,max_depth); - } - if (node->Back) { - Partition_Tree_Depth_Recursive(node->Back,cur_depth,max_depth); - } -} - -void AABTreeCullSystemClass::Add_Object_Recursive(AABTreeNodeClass * node,CullableClass * obj) -{ - // order the children in terms of size - AABTreeNodeClass * big_child = node->Front; - AABTreeNodeClass * small_child = node->Back; - - if (big_child && small_child && (big_child->Compute_Volume() < small_child->Compute_Volume())) { - AABTreeNodeClass * tmp = big_child; - big_child = small_child; - small_child = tmp; - } - - // Can we fit in the smaller child? - if (small_child && small_child->Box.Contains(obj->Get_Cull_Box())) { - Add_Object_Recursive(small_child,obj); - return; - } - - // Can we fit in the bigger child? - if (big_child && big_child->Box.Contains(obj->Get_Cull_Box())) { - Add_Object_Recursive(big_child,obj); - return; - } - - // Ok, we have to fit in this node. - node->Add_Object(obj); - ObjectCount++; -} - -void AABTreeCullSystemClass::Add_Loaded_Object(AABTreeNodeClass * node,CullableClass * obj) -{ - WWASSERT(node); - WWASSERT(obj); - - WWASSERT_PRINT - ( - (obj->Get_Culling_System() == NULL), - "AABTreeCullSystemClass::Add_Loaded_Object -- Object is already in another culling system!\n" - ); - - AABTreeLinkClass * new_link = new AABTreeLinkClass(this); - obj->Set_Cull_Link(new_link); - - node->Add_Object(obj); - ObjectCount++; - obj->Add_Ref(); -} - -void AABTreeCullSystemClass::Re_Partition(void) -{ - /* - ** transfer all objects to a temporary node - */ - AABTreeNodeClass * dummy_node = new AABTreeNodeClass; - RootNode->Transfer_Objects(dummy_node); - - /* - ** delete the old tree and make the dummy node the new root - */ - delete RootNode; - RootNode = dummy_node; - - /* - ** partition the objects - */ - RootNode->Partition(); - - /* - ** re-index the nodes - */ - Re_Index_Nodes(); - - /* - ** reset the statistics - */ - Reset_Statistics(); - -} - -void AABTreeCullSystemClass::Re_Partition(const AABoxClass & bounds,SimpleDynVecClass & boxes) -{ - /* - ** transfer all objects to a temporary node - */ - AABTreeNodeClass * dummy_node = new AABTreeNodeClass; - RootNode->Transfer_Objects(dummy_node); - - /* - ** delete the old tree - */ - delete RootNode; - - /* - ** allocate a new root node and tell it to partition the given array of boxes - */ - RootNode = new AABTreeNodeClass; - RootNode->Partition(bounds,boxes); - - /* - ** re-index the nodes - */ - Re_Index_Nodes(); - - /* - ** reset statistics - */ - Reset_Statistics(); - - /* - ** re-insert all objects and delete the temporary node - */ - dummy_node->Box.Extent.Set(0,0,0); - CullableClass * obj = get_first_object(dummy_node); - while (obj != NULL) { - Update_Culling(obj); - obj = get_first_object(dummy_node); - } - - delete dummy_node; - - /* - ** Modify the root node so that any object can be added into the tree - */ - RootNode->Box.Extent.Set(FLT_MAX,FLT_MAX,FLT_MAX); -} - -void AABTreeCullSystemClass::Update_Bounding_Boxes(void) -{ - Update_Bounding_Boxes_Recursive(RootNode); -} - -const AABoxClass & AABTreeCullSystemClass::Get_Bounding_Box(void) -{ - WWASSERT(RootNode); - return RootNode->Box; -} - -void AABTreeCullSystemClass::Get_Node_Bounds(int node_id,AABoxClass * set_bounds) -{ - if ((node_id >= 0) && (node_id < NodeCount)) { - *set_bounds = IndexedNodes[node_id]->Box; - } else { - *set_bounds = IndexedNodes[0]->Box; - } -} - -void AABTreeCullSystemClass::Reset_Statistics(void) -{ - Stats.NodeCount = NodeCount; - Stats.NodesAccepted = 0; - Stats.NodesTriviallyAccepted = 0; - Stats.NodesRejected = 0; -} - -const AABTreeCullSystemClass::StatsStruct & AABTreeCullSystemClass::Get_Statistics(void) -{ - return Stats; -} - -void AABTreeCullSystemClass::Collect_Objects_Recursive(AABTreeNodeClass * node) -{ - /* - ** Collect any objects in this node - */ - if (node->Object) { - CullableClass * obj = get_first_object(node); - while (obj) { - Add_To_Collection(obj); - obj = get_next_object(obj); - } - } - - /* - ** Statistics - */ - NODE_TRIVIALLY_ACCEPTED(); - - /* - ** Descend into the children - */ - if (node->Back) { - Collect_Objects_Recursive(node->Back); - } - if (node->Front) { - Collect_Objects_Recursive(node->Front); - } -} - - -void AABTreeCullSystemClass::Collect_Objects_Recursive(AABTreeNodeClass * node,const Vector3 & point) -{ - /* - ** Is the point inside this volume? - */ - if (node->Box.Contains(point) == false) { - NODE_REJECTED(); - return; - } - - NODE_ACCEPTED(); - - /* - ** Collect any objects in this node - */ - if (node->Object) { - CullableClass * obj = get_first_object(node); - while (obj) { - if (obj->Get_Cull_Box().Contains(point)) { - Add_To_Collection(obj); - } - obj = get_next_object(obj); - } - } - - /* - ** Descend into the children - */ - if (node->Back) { - Collect_Objects_Recursive(node->Back,point); - } - if (node->Front) { - Collect_Objects_Recursive(node->Front,point); - } -} - -void AABTreeCullSystemClass::Collect_Objects_Recursive(AABTreeNodeClass * node,const AABoxClass & box) -{ - /* - ** Cull the given box against the bounding volume of this node - ** If it is culled, stop descending the tree. If the current node is - ** completely contained inside the given box, jump into the collection function - ** that doesn't do any more volume checking... - */ - CollisionMath::OverlapType overlap = CollisionMath::Overlap_Test(box,node->Box); - if (overlap == CollisionMath::OUTSIDE) { - NODE_REJECTED(); - return; - } else if (overlap == CollisionMath::INSIDE) { - Collect_Objects_Recursive(node); - return; - } - - NODE_ACCEPTED(); - - /* - ** Test any objects in this node - */ - if (node->Object) { - CullableClass * obj = get_first_object(node); - while (obj) { - if (CollisionMath::Overlap_Test(box,obj->Get_Cull_Box()) != CollisionMath::OUTSIDE) { - Add_To_Collection(obj); - } - obj = get_next_object(obj); - } - } - - /* - ** Recurse into any children - */ - if (node->Back) { - Collect_Objects_Recursive(node->Back,box); - } - if (node->Front) { - Collect_Objects_Recursive(node->Front,box); - } -} - - -void AABTreeCullSystemClass::Collect_Objects_Recursive(AABTreeNodeClass * node,const OBBoxClass & box) -{ - /* - ** Cull the given box against the bounding volume of this node - ** If it is culled, stop descending the tree. If the current node is - ** completely contained inside the given box, jump into the collection function - ** that doesn't do any more volume checking... - */ - CollisionMath::OverlapType overlap = CollisionMath::Overlap_Test(box,node->Box); - if (overlap == CollisionMath::OUTSIDE) { - NODE_REJECTED(); - return; - } else if (overlap == CollisionMath::INSIDE) { - Collect_Objects_Recursive(node); - return; - } - - NODE_ACCEPTED(); - - /* - ** Test any objects in this node - */ - if (node->Object) { - CullableClass * obj = get_first_object(node); - while (obj) { - if (CollisionMath::Overlap_Test(box,obj->Get_Cull_Box()) != CollisionMath::OUTSIDE) { - Add_To_Collection(obj); - } - obj = get_next_object(obj); - } - } - - /* - ** Recurse into any children - */ - if (node->Back) { - Collect_Objects_Recursive(node->Back,box); - } - if (node->Front) { - Collect_Objects_Recursive(node->Front,box); - } -} - -void AABTreeCullSystemClass::Collect_Objects_Recursive -( - AABTreeNodeClass * node, - const FrustumClass & frustum, - int planes_passed -) -{ - /* - ** Cull the bounding volume of this node against the frustum. - ** If it is culled, stop descending the tree. - */ - CollisionMath::OverlapType overlap = CollisionMath::Overlap_Test(frustum,node->Box,planes_passed); - if (overlap == CollisionMath::OUTSIDE) { - NODE_REJECTED(); - return; - } else if (overlap == CollisionMath::INSIDE) { - Collect_Objects_Recursive(node); - return; - } - - NODE_ACCEPTED(); - - /* - ** Test any objects in this node - */ - if (node->Object) { - CullableClass * obj = get_first_object(node); - while (obj) { - if (CollisionMath::Overlap_Test(frustum,obj->Get_Cull_Box()) != CollisionMath::OUTSIDE) { - Add_To_Collection(obj); - } - obj = get_next_object(obj); - } - } - - /* - ** Recurse into any children - */ - if (node->Back) { - Collect_Objects_Recursive(node->Back,frustum,planes_passed); - } - if (node->Front) { - Collect_Objects_Recursive(node->Front,frustum,planes_passed); - } -} - - -void AABTreeCullSystemClass::Collect_Objects_Recursive(AABTreeNodeClass * node,const SphereClass & sphere) -{ - /* - ** Is the point inside this volume? - */ - if (CollisionMath::Overlap_Test (node->Box, sphere) == CollisionMath::OUTSIDE) { - NODE_REJECTED(); - return; - } - NODE_ACCEPTED(); - - /* - ** Collect any objects in this node - */ - if (node->Object) { - CullableClass * obj = get_first_object(node); - while (obj) { - if (CollisionMath::Overlap_Test (obj->Get_Cull_Box(), sphere) != CollisionMath::OUTSIDE) { - Add_To_Collection(obj); - } - obj = get_next_object(obj); - } - } - - /* - ** Descend into the children - */ - if (node->Back) { - Collect_Objects_Recursive(node->Back,sphere); - } - if (node->Front) { - Collect_Objects_Recursive(node->Front,sphere); - } -} - -void AABTreeCullSystemClass::Update_Bounding_Boxes_Recursive(AABTreeNodeClass * node) -{ - MinMaxAABoxClass minmaxbox(node->Box); - - /* - ** Update child boxes first and ensure that we bound them - */ - if (node->Front) { - Update_Bounding_Boxes_Recursive(node->Front); - minmaxbox.Add_Box(node->Front->Box); - } - if (node->Back) { - Update_Bounding_Boxes_Recursive(node->Back); - minmaxbox.Add_Box(node->Back->Box); - } - - /* - ** Make sure we bound our contained objects - */ - if (node->Object) { - CullableClass * obj = get_first_object(node); - while (obj) { - minmaxbox.Add_Box(obj->Get_Cull_Box()); - obj = get_next_object(obj); - } - } - - node->Box.Init_Min_Max(minmaxbox.MinCorner,minmaxbox.MaxCorner); -} - - -void AABTreeCullSystemClass::Load(ChunkLoadClass & cload) -{ - WWASSERT_PRINT(Object_Count() == 0, "Remove all objects from AAB-Culling system before loading!\n"); - - delete RootNode; - RootNode = new AABTreeNodeClass; - - // The first chunk should be a version chunk - cload.Open_Chunk(); - if (cload.Cur_Chunk_ID() != AABTREE_CHUNK_VERSION) { - WWDEBUG_SAY(("Attempting to read an obsolete AAB-Tree!")); - cload.Close_Chunk(); - return; - } - - // read in the version and verify that it is the current version - uint32 version; - cload.Read(&version,sizeof(version)); - if (version != AABTREE_CURRENT_VERSION) { - WWDEBUG_SAY(("Attempting to read an obsolete AAB-Tree!")); - cload.Close_Chunk(); - return; - } - cload.Close_Chunk(); - - // read in the tree - Load_Nodes(RootNode,cload); - - // re-index all nodes - Re_Index_Nodes(); - - // reset the statistics - Reset_Statistics(); -} - -void AABTreeCullSystemClass::Load_Nodes(AABTreeNodeClass * node,ChunkLoadClass & cload) -{ - // Open the node description - cload.Open_Chunk(); - WWASSERT(cload.Cur_Chunk_ID() == AABTREE_CHUNK_AABNODE); - - // Load the node description. - // Older files will contain a chunk named AABTREE_CHUNK_AABNODE_INFO while newer - // files will contain AABTREE_CHUNK_AABNODE_VARIABLES which contains the IOAABNodeStruct - // in a micro-chunk. - IOAABNodeStruct node_desc; - memset(&node_desc,0,sizeof(IOAABNodeStruct)); - - cload.Open_Chunk(); - if (cload.Cur_Chunk_ID() == AABTREE_CHUNK_AABNODE_INFO) { - - // Loading the legacy format... - WWASSERT(cload.Cur_Chunk_ID() == AABTREE_CHUNK_AABNODE_INFO); - cload.Read(&node_desc,sizeof(node_desc)); - - } else if (cload.Cur_Chunk_ID() == AABTREE_CHUNK_AABNODE_VARIABLES) { - - // Loading the new format, contains micro chunks... - while (cload.Open_Micro_Chunk()) { - switch(cload.Cur_Micro_Chunk_ID()) { - READ_MICRO_CHUNK(cload,AABTREE_VARIABLE_NODESTRUCT,node_desc); - READ_MICRO_CHUNK(cload,AABTREE_VARIABLE_USERDATA,node->UserData); - } - cload.Close_Micro_Chunk(); - } - } - cload.Close_Chunk(); - - // Initialize the node bounds. - node->Box.Center.X = node_desc.Center.X; - node->Box.Center.Y = node_desc.Center.Y; - node->Box.Center.Z = node_desc.Center.Z; - - node->Box.Extent.X = node_desc.Extent.X; - node->Box.Extent.Y = node_desc.Extent.Y; - node->Box.Extent.Z = node_desc.Extent.Z; - - // Load the contents of the node. - cload.Open_Chunk(); - WWASSERT(cload.Cur_Chunk_ID() == AABTREE_CHUNK_AABNODE_CONTENTS); - Load_Node_Contents(node,cload); - cload.Close_Chunk(); - - // Close the node description - cload.Close_Chunk(); - - // if we are supposed to have a front child, load it - if (node_desc.Attributes & AABNODE_ATTRIBUTE_FRONT_CHILD) { - WWASSERT(node->Front == NULL); - node->Front = new AABTreeNodeClass(); - node->Front->Parent = node; - Load_Nodes(node->Front,cload); - } - - // if we have a back child, load it - if (node_desc.Attributes & AABNODE_ATTRIBUTE_BACK_CHILD) { - WWASSERT(node->Back == NULL); - node->Back = new AABTreeNodeClass(); - node->Back->Parent = node; - Load_Nodes(node->Back,cload); - } -} - -void AABTreeCullSystemClass::Save(ChunkSaveClass & csave) -{ - csave.Begin_Chunk(AABTREE_CHUNK_VERSION); - uint32 version = AABTREE_CURRENT_VERSION; - csave.Write(&version,sizeof(uint32)); - csave.End_Chunk(); - - Save_Nodes(RootNode,csave); -} - -void AABTreeCullSystemClass::Save_Nodes(AABTreeNodeClass * node,ChunkSaveClass & csave) -{ - WWASSERT(node); - csave.Begin_Chunk(AABTREE_CHUNK_AABNODE); - - csave.Begin_Chunk(AABTREE_CHUNK_AABNODE_VARIABLES); - IOAABNodeStruct node_desc; - memset(&node_desc,0,sizeof(node_desc)); - - node_desc.Center.X = node->Box.Center.X; - node_desc.Center.Y = node->Box.Center.Y; - node_desc.Center.Z = node->Box.Center.Z; - - node_desc.Extent.X = node->Box.Extent.X; - node_desc.Extent.Y = node->Box.Extent.Y; - node_desc.Extent.Z = node->Box.Extent.Z; - - if (node->Front) { - node_desc.Attributes |= AABNODE_ATTRIBUTE_FRONT_CHILD; - } - - if (node->Back) { - node_desc.Attributes |= AABNODE_ATTRIBUTE_BACK_CHILD; - } - - WRITE_MICRO_CHUNK(csave,AABTREE_VARIABLE_NODESTRUCT,node_desc); - WRITE_MICRO_CHUNK(csave,AABTREE_VARIABLE_USERDATA,node->UserData); - csave.End_Chunk(); - - csave.Begin_Chunk(AABTREE_CHUNK_AABNODE_CONTENTS); - Save_Node_Contents(node,csave); - csave.End_Chunk(); - - csave.End_Chunk(); - - if (node->Front) { - Save_Nodes(node->Front,csave); - } - - if (node->Back) { - Save_Nodes(node->Back,csave); - } -} - -void AABTreeCullSystemClass::Load_Object_Linkage(ChunkLoadClass & cload,CullableClass * obj) -{ - uint32 index; - cload.Open_Chunk(); - WWASSERT(cload.Cur_Chunk_ID() == AABTREE_CHUNK_NODE_INDEX); - cload.Read(&index,sizeof(index)); - cload.Close_Chunk(); - - Add_Object_Internal(obj,index); -} - -void AABTreeCullSystemClass::Save_Object_Linkage(ChunkSaveClass & csave,CullableClass * obj) -{ - WWASSERT(obj); - WWASSERT(obj->Get_Culling_System() == this); - - AABTreeLinkClass * link = (AABTreeLinkClass *)obj->Get_Cull_Link(); - WWASSERT(link); - - AABTreeNodeClass * node = link->Node; - WWASSERT(node); - - uint32 index = node->Index; - csave.Begin_Chunk(AABTREE_CHUNK_NODE_INDEX); - csave.Write(&index,sizeof(index)); - csave.End_Chunk(); -} - - -void AABTreeCullSystemClass::Re_Index_Nodes(void) -{ - if (IndexedNodes != NULL) { - delete[] IndexedNodes; - IndexedNodes = NULL; - } - NodeCount = Partition_Node_Count(); - WWASSERT(NodeCount > 0); - IndexedNodes = new AABTreeNodeClass *[NodeCount]; - - int counter = 0; - Re_Index_Nodes_Recursive(RootNode,counter); - WWASSERT(counter == NodeCount); -} - - -void AABTreeCullSystemClass::Re_Index_Nodes_Recursive(AABTreeNodeClass * node,int & counter) -{ - node->Index = counter; - IndexedNodes[counter] = node; - counter++; - - if (node->Front) { - Re_Index_Nodes_Recursive(node->Front,counter); - } - if (node->Back) { - Re_Index_Nodes_Recursive(node->Back,counter); - } -} - - - -/************************************************************************* -** -** AABTreeNodeClass Implementation -** -*************************************************************************/ -AABTreeNodeClass::AABTreeNodeClass(void) : - Index(0), - Box(Vector3(0,0,0),Vector3(0,0,0)), - Parent(NULL), - Front(NULL), - Back(NULL), - Object(NULL), - UserData(0) -{ -} - -AABTreeNodeClass::~AABTreeNodeClass(void) -{ - // objects should be removed before deleting the partition tree - WWASSERT(Object == NULL); - - // delete our children - if (Front) { - delete Front; - Front = NULL; - } - if (Back) { - delete Back; - Back = NULL; - } -} - -void AABTreeNodeClass::Compute_Bounding_Box(void) -{ - /* - ** make the children update their boxes first - */ - if (Front) { - Front->Compute_Bounding_Box(); - } - - if (Back) { - Back->Compute_Bounding_Box(); - } - - Compute_Local_Bounding_Box(); -} - -void AABTreeNodeClass::Compute_Local_Bounding_Box(void) -{ - /* - ** Now make sure we bound our children - */ - MinMaxAABoxClass box(Vector3(FLT_MAX,FLT_MAX,FLT_MAX),Vector3(-FLT_MAX,-FLT_MAX,-FLT_MAX)); - - if (Front) { - box.Add_Box(Front->Box); - } - - if (Back) { - box.Add_Box(Back->Box); - } - - /* - ** bound the objects in this node - */ - CullableClass * obj = Object; - while (obj) { - box.Add_Box(obj->Get_Cull_Box()); - AABTreeLinkClass * link = (AABTreeLinkClass *)obj->Get_Cull_Link(); - obj = link->NextObject; - } - - Box.Init(box); -} - -float AABTreeNodeClass::Compute_Volume(void) -{ - return Box.Volume(); -} - -void AABTreeNodeClass::Add_Object(CullableClass * obj,bool update_bounds) -{ - AABTreeLinkClass * link = (AABTreeLinkClass *)obj->Get_Cull_Link(); - WWASSERT(link); - - link->Node = this; - link->NextObject = Object; - Object = obj; - - if (update_bounds) { - // if this is the only object and we have no children, just copy - // the object's bounding box, otherwise, add it to what we have - if ((Object_Count() == 1) && (Front == NULL) && (Back == NULL)) { - Box = obj->Get_Cull_Box(); - } else { - Box.Add_Box(obj->Get_Cull_Box()); - } - } -} - -void AABTreeNodeClass::Remove_Object(CullableClass * obj) -{ - WWASSERT(obj); - - // find the given object in our linked list - CullableClass * prevobj = NULL; - CullableClass * curobj = Object; - - while (curobj) { - - AABTreeLinkClass * link = (AABTreeLinkClass *)curobj->Get_Cull_Link(); - - if (curobj == obj) { - // found the object, unlink it. - if (prevobj) { - AABTreeLinkClass * prevlink = (AABTreeLinkClass *)prevobj->Get_Cull_Link(); - prevlink->NextObject = link->NextObject; - } else { - Object = link->NextObject; - } - - link->NextObject = NULL; - link->Node = NULL; - return; - } - - // move to the next object - prevobj = curobj; - curobj = link->NextObject; - } -} - -void AABTreeNodeClass::Transfer_Objects(AABTreeNodeClass * dummy_node) -{ - // unlink all of our objects, relinking them to the dummy_node - while (Object) { - CullableClass * obj = Object; - Remove_Object(obj); - dummy_node->Add_Object(obj); - } - - // do the same with our children - if (Front) { - Front->Transfer_Objects(dummy_node); - } - - if (Back) { - Back->Transfer_Objects(dummy_node); - } -} - -int AABTreeNodeClass::Object_Count(void) -{ - CullableClass * obj = Object; - int count = 0; - - while (obj) { - count++; - obj = ((AABTreeLinkClass *)obj->Get_Cull_Link())->NextObject; - } - - return count; -} - -CullableClass * AABTreeNodeClass::Peek_Object(int index) -{ - int count = 0; - CullableClass * obj = Object; - WWASSERT(obj != NULL); - - while (obj && (count != index)) { - count++; - obj = ((AABTreeLinkClass *)obj->Get_Cull_Link())->NextObject; - } - WWASSERT(count == index); - return obj; -} - - -/****************************************************************************************** -** -** Partitioning code which partitions the objects in the tree and passes them into -** the new children -** -******************************************************************************************/ - -void AABTreeNodeClass::Partition(void) -{ - /* - ** if we're down to only 2 objects, we're done - */ - int obj_count = Object_Count(); - if (obj_count <= 2) return; - - /* - ** Create an array of the bounding boxes of our objects - */ - SimpleDynVecClass boxes(obj_count); - CullableClass * obj = Object; - while (obj != NULL) { - boxes.Add(obj->Get_Cull_Box()); - obj = get_next_object(obj); - } - - /* - ** Select and assign the splitting plane - ** De-allocate the array of boxes to conserve memory - */ - SplitChoiceStruct sc; - Select_Splitting_Plane(&sc,boxes); - boxes.Resize(0); - - /* - ** If there was no good split, just leave all of - ** the objects in this node - */ - if (sc.Cost == FLT_MAX) { - return; - } - - /* - ** Split the tiles - */ - AABTreeNodeClass * front = new AABTreeNodeClass; - AABTreeNodeClass * back = new AABTreeNodeClass; - Split_Objects(sc,front,back); - - /* - ** Build a front tree if necessary. - */ - if (front->Object_Count() > 0) { - Front = front; - Front->Parent = this; - Front->Partition(); - } else { - delete front; - front = NULL; - } - - /* - ** Build a back tree if necessary. - */ - if (back->Object_Count() > 0) { - Back = back; - Back->Parent = this; - Back->Partition(); - } else { - delete back; - back = NULL; - } -} - - - -void AABTreeNodeClass::Split_Objects(const AABTreeNodeClass::SplitChoiceStruct & sc,AABTreeNodeClass * front,AABTreeNodeClass * back) -{ - // This function assumes that this node is a leaf - WWASSERT(Front == NULL); - WWASSERT(Back == NULL); - WWASSERT(Object_Count() == sc.FrontCount + sc.BackCount); - - int fcount = 0; - int bcount = 0; - - // unlink all of our objects, relinking them to the appropriate node - while (Object) { - - // pull the object out of this node - CullableClass * obj = Object; - Remove_Object(Object); - - // decide which node to add the object to, - // NOTE: we have to use the same convention as Compute_Score! - const AABoxClass & box = obj->Get_Cull_Box(); - - if (CollisionMath::Overlap_Test(sc.Plane,box.Center) == CollisionMath::FRONT) { - - front->Add_Object(obj); - fcount++; - - } else { - - back->Add_Object(obj); - bcount++; - - } - } - - // copy the bounding boxes - front->Box = sc.FrontBox; - front->Box.Extent += Vector3(WWMATH_EPSILON,WWMATH_EPSILON,WWMATH_EPSILON); - back->Box = sc.BackBox; - back->Box.Extent += Vector3(WWMATH_EPSILON,WWMATH_EPSILON,WWMATH_EPSILON); - - // when we are all done, the counts should match. - WWASSERT(fcount == sc.FrontCount); - WWASSERT(bcount == sc.BackCount); -} - - - - -/****************************************************************************************** -** -** Partitioning code which generates the tree based on a set of input boxes -** -******************************************************************************************/ -void AABTreeNodeClass::Partition(const AABoxClass & bounds,SimpleDynVecClass & boxes) -{ - Box = bounds; - - /* - ** if we're down to only 1 box, we're done - */ - if (boxes.Count() <= 1) return; - - /* - ** Select and assign the splitting plane - */ - SplitChoiceStruct sc; - Select_Splitting_Plane(&sc,boxes); - - /* - ** If there was no good split, just leave all of - ** the objects in this node - */ - if (sc.Cost == FLT_MAX) { - return; - } - - /* - ** Split the boxes - ** Deallocate the input box array to conserve RAM - */ - SimpleDynVecClass frontboxes(sc.FrontCount); - SimpleDynVecClass backboxes(sc.BackCount); - Split_Boxes(sc,boxes,frontboxes,backboxes); - boxes.Delete_All(); - - /* - ** Build a front tree if necessary. - */ - if (frontboxes.Count() > 0) { - Front = new AABTreeNodeClass; - Front->Parent = this; - Front->Partition(sc.FrontBox,frontboxes); - } else { - Front = NULL; - } - - /* - ** Build a back tree if necessary. - */ - if (backboxes.Count() > 0) { - Back = new AABTreeNodeClass; - Back->Parent = this; - Back->Partition(sc.BackBox,backboxes); - } else { - Back = NULL; - } -} - -void AABTreeNodeClass::Split_Boxes -( - const AABTreeNodeClass::SplitChoiceStruct & sc, - SimpleDynVecClass & boxes, - SimpleDynVecClass & frontboxes, - SimpleDynVecClass & backboxes -) -{ - WWASSERT(boxes.Count() == sc.FrontCount + sc.BackCount); - - // copy each box in the input array into the appropriate output array - for (int i=0; i & boxes -) -{ - const int NUM_TRYS = 300; - - /* - ** Try putting axis-aligned planes through some random vertices - */ - int objcount = boxes.Count(); - int trys = 0; - for (trys = 0; trys < MIN(NUM_TRYS,objcount); trys++) { - - int obj_index; - SplitChoiceStruct test; - - /* - ** Select a random object - */ - obj_index = rand() % objcount; - const AABoxClass & box = boxes[obj_index]; - - /* - ** Select a random plane which co-incides with one of the faces - ** of the object's bounding box - */ - switch(rand() % 6) { - case 0: test.Plane.Set(AAPlaneClass::XNORMAL,box.Center.X + box.Extent.X); break; - case 1: test.Plane.Set(AAPlaneClass::XNORMAL,box.Center.X - box.Extent.X); break; - case 2: test.Plane.Set(AAPlaneClass::YNORMAL,box.Center.Y + box.Extent.Y); break; - case 3: test.Plane.Set(AAPlaneClass::YNORMAL,box.Center.Y - box.Extent.Y); break; - case 4: test.Plane.Set(AAPlaneClass::ZNORMAL,box.Center.Z + box.Extent.Z); break; - case 5: test.Plane.Set(AAPlaneClass::ZNORMAL,box.Center.Z - box.Extent.Z); break; - }; - - /* - ** Get the score for this plane - */ - Compute_Score(&test,boxes); - if (test.Cost < sc->Cost) { - *sc = test; - } - - } - - /* - ** Still haven't found a valid splitting plane, uh-oh. - */ - if ((trys >= MIN(NUM_TRYS,objcount)) && (sc->Cost == FLT_MAX)) { - Select_Splitting_Plane_Brute_Force(sc,boxes); - return; - } -} - -void AABTreeNodeClass::Select_Splitting_Plane_Brute_Force -( - AABTreeNodeClass::SplitChoiceStruct * sc, - SimpleDynVecClass & boxes -) -{ - /* - ** Try putting axis-aligned planes along each face of each box - */ - int objcount = boxes.Count(); - for (int obj_index = 0; obj_index < objcount; obj_index++) { - - AAPlaneClass plane; - const AABoxClass & box = boxes[obj_index]; - - /* - ** Try each face of this box - */ - for (int plane_index = 0; plane_index < 6; plane_index++) { - SplitChoiceStruct test; - switch(plane_index % 6) { - case 0: test.Plane.Set(AAPlaneClass::XNORMAL,box.Center.X + box.Extent.X); break; - case 1: test.Plane.Set(AAPlaneClass::XNORMAL,box.Center.X - box.Center.Y); break; - case 2: test.Plane.Set(AAPlaneClass::YNORMAL,box.Center.Y + box.Center.Y); break; - case 3: test.Plane.Set(AAPlaneClass::YNORMAL,box.Center.Y - box.Center.Y); break; - case 4: test.Plane.Set(AAPlaneClass::ZNORMAL,box.Center.Z + box.Center.Z); break; - case 5: test.Plane.Set(AAPlaneClass::ZNORMAL,box.Center.Z - box.Center.Z); break; - }; - - test.FrontBox.Init_Empty(); - test.BackBox.Init_Empty(); - - /* - ** Get the score for this plane - */ - Compute_Score(&test,boxes); - if (test.Cost < sc->Cost) { - *sc = test; - } - } - } - - /* - ** Notify user that we couldn't split this node - */ -#ifdef WWDEBUG - if (sc->Cost == FLT_MAX) { - WWDEBUG_SAY(("Unable to split node! objcount = %d. (%.2f,%.2f,%.2f)\r\n",objcount,Box.Center.X, Box.Center.Y, Box.Center.Z)); - } -#endif -} - - -void AABTreeNodeClass::Compute_Score -( - AABTreeNodeClass::SplitChoiceStruct * sc, - SimpleDynVecClass & boxes -) -{ - /* - ** Suitability of a plane as a partition plane is based on the following factors: - ** - How many "tiles" are on each side of the plane, - */ - for (int i=0; iPlane,box.Center) == CollisionMath::FRONT) { - - sc->FrontCount++; - sc->FrontBox.Add_Box(box); - - } else { - - sc->BackCount++; - sc->BackBox.Add_Box(box); - - } - } - - /* - ** Compute the cost. - */ - float back_cost = sc->BackBox.Volume() * sc->BackCount; - float front_cost = sc->FrontBox.Volume() * sc->FrontCount; - - sc->Cost = front_cost + back_cost; - - if ((sc->FrontCount == 0) || (sc->BackCount == 0)) { - sc->Cost = FLT_MAX; - } -} - - - -/************************************************************************************** - - AABTreeIterator Implemenation - -**************************************************************************************/ - - -AABTreeIterator::AABTreeIterator(AABTreeCullSystemClass * tree) : - Tree(tree), - CurNodeIndex(0) -{ - WWASSERT(Tree != NULL); -} - -void AABTreeIterator::Reset(void) -{ - CurNodeIndex = 0; -} - -bool AABTreeIterator::Enter_Parent(void) -{ - validate(); - if (CurNodeIndex != 0) { - CurNodeIndex = Tree->IndexedNodes[CurNodeIndex]->Parent->Index; - return true; - } else { - return false; - } -} - -bool AABTreeIterator::Enter_Sibling(void) -{ - validate(); - if (CurNodeIndex != 0) { - - /* - ** find which child of our parent we are - */ - AABTreeNodeClass * parent = Tree->IndexedNodes[CurNodeIndex]->Parent; - AABTreeNodeClass * parent_front = parent->Front; - AABTreeNodeClass * parent_back = parent->Back; - - /* - ** if our parent doesn't have two children, we don't have a sibling - */ - if ((parent_front == NULL) || (parent_back == NULL)) { - return false; - } - - /* - ** if we our our parent's front child, go to its back child - */ - if ((int)parent_front->Index == CurNodeIndex) { - CurNodeIndex = parent_back->Index; - return true; - } - - /* - ** if we our our parent's back child, go to its front child - */ - if ((int)parent_back->Index == (int)CurNodeIndex) { - CurNodeIndex = parent_front->Index; - return true; - } - } - return false; -} - -bool AABTreeIterator::Has_Front_Child(void) -{ - validate(); - return (Tree->IndexedNodes[CurNodeIndex]->Front != NULL); -} - -bool AABTreeIterator::Enter_Front_Child(void) -{ - validate(); - if (Has_Front_Child()) { - CurNodeIndex = Tree->IndexedNodes[CurNodeIndex]->Front->Index; - return true; - } - return false; -} - -bool AABTreeIterator::Has_Back_Child(void) -{ - validate(); - return (Tree->IndexedNodes[CurNodeIndex]->Back != NULL); -} - -bool AABTreeIterator::Enter_Back_Child(void) -{ - if (Has_Back_Child()) { - CurNodeIndex = Tree->IndexedNodes[CurNodeIndex]->Back->Index; - return true; - } - return false; -} - -int AABTreeIterator::Get_Current_Node_Index(void) -{ - return CurNodeIndex; -} - -void AABTreeIterator::Get_Current_Box(AABoxClass * set_box) -{ - Tree->Get_Node_Bounds(CurNodeIndex,set_box); -} - -void AABTreeIterator::validate(void) -{ - if ((CurNodeIndex < 0) || (CurNodeIndex >= Tree->NodeCount)) { - CurNodeIndex = 0; - } -} - -/* - - Can we make a more compact AABTree? - - Here is the existing data in each Node: - - uint32 Index; // Index of this node - AABoxClass Box; // Bounding box of the node - AABTreeNodeClass * Parent; // parent of this node - AABTreeNodeClass * Front; // front node - AABTreeNodeClass * Back; // back node - CullableClass * Object; // objects in this node - uint32 UserData; // 32bit field for the user, initialized to 0 - - Total Size: 48 bytes - - Here is a possible replacement: - - uint16 Index; - short x,y,z,w,l,h; // Need origin and scale factors for the boxes stored in tree - uint16 ParentIndex; - uint16 FrontIndex; - uint16 BackIndex; - CullableClass * Object; - uint32 UserData; - - Total Size: 28 bytes - -*/ \ No newline at end of file diff --git a/Generals/Code/Libraries/Source/WWVegas/WWMath/aabtreecull.h b/Generals/Code/Libraries/Source/WWVegas/WWMath/aabtreecull.h deleted file mode 100644 index 14f0f7d0792..00000000000 --- a/Generals/Code/Libraries/Source/WWVegas/WWMath/aabtreecull.h +++ /dev/null @@ -1,344 +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 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 : WWMath * - * * - * $Archive:: /Commando/Code/wwmath/aabtreecull.h $* - * * - * Author:: Greg Hjelstrom * - * * - * $Modtime:: 7/24/01 10:00a $* - * * - * $Revision:: 15 $* - * * - *---------------------------------------------------------------------------------------------* - * Functions: * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - - -#if defined(_MSC_VER) -#pragma once -#endif - -#ifndef AABTREECULL_H -#define AABTREECULL_H - -#include "cullsys.h" -#include "aaplane.h" -#include "wwmath.h" -#include "mempool.h" -#include "simplevec.h" -#include -#include - -class AABTreeNodeClass; -class ChunkLoadClass; -class ChunkSaveClass; -class SphereClass; - -/** -** AABTreeCullSystemClass -** Derived culling system that uses an Axis-Aligned Bounding Box Tree -*/ -class AABTreeCullSystemClass : public CullSystemClass -{ -public: - - AABTreeCullSystemClass(void); - virtual ~AABTreeCullSystemClass(void); - - /* - ** Re-partition the tree. Two methods can be used to accomplish this. The - ** first re-partitions the tree based on the objects contained within, the second - ** re-partitions the tree based solely on a set of input "seed" boxes. Each seed - ** box will become a leaf; then the objects will be re-inserted in the new tree. - */ - void Re_Partition(void); - void Re_Partition(const AABoxClass & bounds,SimpleDynVecClass & boxes); - - /* - ** Update_Bounding_Boxes. This function causes all bounding boxes in the tree to update themselves. - ** If any box is found to not bound the objects it is supposed to contain, the box is updated - ** Note that this is normally not necessary, the reason this function existsis due to the fact - ** that the renegade level editor tries to do everything possible to not discard the precalculated - ** visibilty data for a level. In some cases, we want to load geometry that has been edited back - ** into the same AABTree without re-partitioning. - */ - void Update_Bounding_Boxes(void); - - /* - ** Re-insert an object into the tree - */ - virtual void Update_Culling(CullableClass * obj); - - /* - ** Statistics about the AAB-Tree - */ - int Partition_Node_Count(void) const; - int Partition_Tree_Depth(void) const; - int Object_Count(void) const; - - /* - ** Collect objects which overlap the given primitive - */ - virtual void Collect_Objects(const Vector3 & point); - virtual void Collect_Objects(const AABoxClass & box); - virtual void Collect_Objects(const OBBoxClass & box); - virtual void Collect_Objects(const FrustumClass & frustum); - virtual void Collect_Objects(const SphereClass & sphere); - - /* - ** Load and Save a description of this AAB-Tree and its contents - */ - virtual void Load(ChunkLoadClass & cload); - virtual void Save(ChunkSaveClass & csave); - - /* - ** Save an objects linkage, load the linkage and re-link the object - */ - void Load_Object_Linkage(ChunkLoadClass & cload,CullableClass * obj); - void Save_Object_Linkage(ChunkSaveClass & csave,CullableClass * obj); - - /* - ** Bounding box of the entire tree - */ - const AABoxClass & Get_Bounding_Box(void); - void Get_Node_Bounds(int node_id,AABoxClass * set_bounds); - - /* - ** Statistics - */ - struct StatsStruct - { - int NodeCount; - int NodesAccepted; - int NodesTriviallyAccepted; - int NodesRejected; - }; - - void Reset_Statistics(void); - const StatsStruct & Get_Statistics(void); - -protected: - - /* - ** Internal stat tracking - */ -#ifdef WWDEBUG - void NODE_ACCEPTED(void) { Stats.NodesAccepted ++; } - void NODE_TRIVIALLY_ACCEPTED(void) { Stats.NodesTriviallyAccepted ++; } - void NODE_REJECTED(void) { Stats.NodesRejected ++; } -#else - void NODE_ACCEPTED(void) { } - void NODE_TRIVIALLY_ACCEPTED(void) { } - void NODE_REJECTED(void) { } -#endif - - /* - ** Internal functions - */ - void Add_Object_Internal(CullableClass * obj,int node_index = -1); - void Remove_Object_Internal(CullableClass * obj); - - void Re_Index_Nodes(void); - void Re_Index_Nodes_Recursive(AABTreeNodeClass * node,int & counter); - - int Partition_Node_Count_Recursive(AABTreeNodeClass * node) const; - void Partition_Tree_Depth_Recursive(AABTreeNodeClass * node,int cur_depth,int & max_depth) const; - void Add_Object_Recursive(AABTreeNodeClass * node,CullableClass * obj); - void Add_Loaded_Object(AABTreeNodeClass * node,CullableClass * obj); - - void Collect_Objects_Recursive(AABTreeNodeClass * node); - void Collect_Objects_Recursive(AABTreeNodeClass * node,const Vector3 & point); - void Collect_Objects_Recursive(AABTreeNodeClass * node,const AABoxClass & box); - void Collect_Objects_Recursive(AABTreeNodeClass * node,const OBBoxClass & box); - void Collect_Objects_Recursive(AABTreeNodeClass * node,const FrustumClass & frustum); - void Collect_Objects_Recursive(AABTreeNodeClass * node,const FrustumClass & frustum,int planes_passed); - void Collect_Objects_Recursive(AABTreeNodeClass * node,const SphereClass & sphere); - - void Update_Bounding_Boxes_Recursive(AABTreeNodeClass * node); - - void Load_Nodes(AABTreeNodeClass * node,ChunkLoadClass & cload); - void Save_Nodes(AABTreeNodeClass * node,ChunkSaveClass & csave); - - virtual void Load_Node_Contents(AABTreeNodeClass * /*node*/,ChunkLoadClass & /*cload*/) { } - virtual void Save_Node_Contents(AABTreeNodeClass * /*node*/,ChunkSaveClass & /*csave*/) { } - - AABTreeNodeClass * RootNode; // root of the AAB-Tree - int ObjectCount; // number of objects in the system - - int NodeCount; // number of nodes - AABTreeNodeClass ** IndexedNodes; // index access to the nodes - - StatsStruct Stats; - - friend class AABTreeIterator; -}; - - -/** -** AABTreeIterator -** This iterator allows the user to walk a tree. It can return the index of the current -** node and the bounds of the current node. -*/ -class AABTreeIterator -{ -public: - AABTreeIterator(AABTreeCullSystemClass * tree); - - void Reset(void); - bool Enter_Parent(void); - bool Enter_Sibling(void); - bool Has_Front_Child(void); - bool Enter_Front_Child(void); - bool Has_Back_Child(void); - bool Enter_Back_Child(void); - - int Get_Current_Node_Index(void); - void Get_Current_Box(AABoxClass * set_box); - -private: - - void validate(void); - - AABTreeCullSystemClass * Tree; - int CurNodeIndex; - -}; - - -/** -** TypedAABTreeCullSystemClass -** This template adds type-safety to an AABTree. It allows you to create trees -** containing a particular type of object (the class must be derived from CullableClass though) -*/ -template class TypedAABTreeCullSystemClass : public AABTreeCullSystemClass -{ -public: - - virtual void Add_Object(T * obj,int node_index=-1) { Add_Object_Internal(obj,node_index); } - virtual void Remove_Object(T * obj) { Remove_Object_Internal(obj); } - - T * Get_First_Collected_Object(void) { return (T*)Get_First_Collected_Object_Internal(); } - T * Get_Next_Collected_Object(T * obj) { return (T*)Get_Next_Collected_Object_Internal(obj); } - T * Peek_First_Collected_Object(void) { return (T*)Peek_First_Collected_Object_Internal(); } - T * Peek_Next_Collected_Object(T * obj) { return (T*)Peek_Next_Collected_Object_Internal(obj); } -}; - - - - -/** -** AABTreeNodeClass - the aab-tree is built out of these objects -** CullableClass's can be linked into any of these nodes. Whenever the -** tree is re-built, all objects will end up in the leaf nodes. Between -** re-builds, as objects are added, they will be placed as deep into the -** tree as possible. -*/ -class AABTreeNodeClass : public AutoPoolClass -{ - -public: - - AABTreeNodeClass(void); - ~AABTreeNodeClass(void); - - void Add_Object(CullableClass * obj,bool update_bounds = true); - void Remove_Object(CullableClass * obj); - int Object_Count(void); - CullableClass * Peek_Object(int index); - - uint32 Index; // Index of this node - AABoxClass Box; // Bounding box of the node - AABTreeNodeClass * Parent; // parent of this node - AABTreeNodeClass * Front; // front node - AABTreeNodeClass * Back; // back node - CullableClass * Object; // objects in this node - uint32 UserData; // 32bit field for the user, initialized to 0 - - /* - ** Construction support: - */ - struct SplitChoiceStruct - { - SplitChoiceStruct(void) : Cost(FLT_MAX),FrontCount(0),BackCount(0),Plane(AAPlaneClass::XNORMAL,0.0f) - { - FrontBox.Init_Empty(); - BackBox.Init_Empty(); - } - - float Cost; - int FrontCount; - int BackCount; - MinMaxAABoxClass FrontBox; - MinMaxAABoxClass BackBox; - AAPlaneClass Plane; - }; - - void Compute_Bounding_Box(void); - void Compute_Local_Bounding_Box(void); - float Compute_Volume(void); - void Transfer_Objects(AABTreeNodeClass * dummy_node); - - /* - ** Partition the tree based on the objects contained. - */ - void Partition(void); - void Split_Objects( const SplitChoiceStruct & sc, - AABTreeNodeClass * front, - AABTreeNodeClass * back); - - /* - ** Partition the tree based on a set of input "seed" boxes. - */ - void Partition(const AABoxClass & bounds,SimpleDynVecClass & boxes); - void Split_Boxes( const SplitChoiceStruct & sc, - SimpleDynVecClass & boxes, - SimpleDynVecClass & frontboxes, - SimpleDynVecClass & backboxes); - - /* - ** Functions used by both partitioning algorithms - */ - void Select_Splitting_Plane(SplitChoiceStruct * sc,SimpleDynVecClass & boxes); - void Select_Splitting_Plane_Brute_Force(SplitChoiceStruct * sc,SimpleDynVecClass & boxes); - void Compute_Score(SplitChoiceStruct * sc,SimpleDynVecClass & boxes); -}; - - -/* -** AABTreeLinkClass -** This structure is used to link objects into an AAB-Tree culling system. -*/ -class AABTreeLinkClass : public CullLinkClass, public AutoPoolClass -{ -public: - AABTreeLinkClass(AABTreeCullSystemClass * system) : CullLinkClass(system),Node(NULL), NextObject(NULL) { } - - AABTreeNodeClass * Node; // partition node containing this object - CullableClass * NextObject; // next object in the node -}; - - - - -#endif // AABTREECULL_H diff --git a/Generals/Code/Libraries/Source/WWVegas/WWMath/aaplane.h b/Generals/Code/Libraries/Source/WWVegas/WWMath/aaplane.h deleted file mode 100644 index 2f52f7633f9..00000000000 --- a/Generals/Code/Libraries/Source/WWVegas/WWMath/aaplane.h +++ /dev/null @@ -1,83 +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 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 : WWMath * - * * - * $Archive:: /Commando/Code/wwmath/aaplane.h $* - * * - * Author:: Greg Hjelstrom * - * * - * $Modtime:: 5/19/00 3:12p $* - * * - * $Revision:: 8 $* - * * - *---------------------------------------------------------------------------------------------* - * Functions: * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - -#if defined(_MSC_VER) -#pragma once -#endif - -#ifndef AAPLANE_H -#define AAPLANE_H - -#include "always.h" -#include "vector3.h" - - -/* -** This class is used to describe an "axis-aligned" plane. I.e, the normal -** of the plane is one of the three coordinate axes. -*/ -class AAPlaneClass -{ -public: - - enum AxisEnum { XNORMAL = 0, YNORMAL = 1, ZNORMAL = 2 }; - - AAPlaneClass(void) { } - AAPlaneClass(AxisEnum normal,float dist) : Normal(normal),Dist(dist) { } - - void Set(AxisEnum normal,float dist); - void Get_Normal(Vector3 * normal) const; - -public: - - AxisEnum Normal; - float Dist; - -}; - -inline void AAPlaneClass::Set(AxisEnum normal,float dist) -{ - Normal = normal; - Dist = dist; -} - -inline void AAPlaneClass::Get_Normal(Vector3 * normal) const -{ - normal->Set(0,0,0); - (*normal)[Normal] = 1.0f; -} - -#endif diff --git a/Generals/Code/Libraries/Source/WWVegas/WWMath/cardinalspline.cpp b/Generals/Code/Libraries/Source/WWVegas/WWMath/cardinalspline.cpp deleted file mode 100644 index 8cee401122e..00000000000 --- a/Generals/Code/Libraries/Source/WWVegas/WWMath/cardinalspline.cpp +++ /dev/null @@ -1,355 +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 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 : WWMath * - * * - * $Archive:: /VSS_Sync/wwmath/cardinalspline.cpp $* - * * - * Author:: Greg Hjelstrom * - * * - * $Modtime:: 6/13/01 2:18p $* - * * - * $Revision:: 5 $* - * * - *---------------------------------------------------------------------------------------------* - * Functions: * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - - -#include "cardinalspline.h" -#include "wwdebug.h" -#include "persistfactory.h" -#include "wwmathids.h" -#include "wwhack.h" - -/* -** Force-Link this module because the linker can't detect that we actually need it... -*/ -DECLARE_FORCE_LINK(cardinalspline); - - -/* -** Save-Load stuff -*/ -SimplePersistFactoryClass _CardinalSpline3DFactory; -SimplePersistFactoryClass _CardinalSpline1DFactory; - -enum -{ - // ID's used by CardinalSpline3D - CARDINAL3D_CHUNK_HERMITE3D = 0x02070957, - CARDINAL3D_CHUNK_TIGHTNESSKEYS, - - // ID's used by CardinalSpline1D - CARDINAL1D_CHUNK_HERMITE1D = 0x02070959, - CARDINAL1D_CHUNK_TIGHTNESSKEYS -}; - - -/* -** CardinalSpline3DClass Implementation -*/ -int CardinalSpline3DClass::Add_Key(const Vector3 & point,float t) -{ - int index = HermiteSpline3DClass::Add_Key(point,t); - float tightness = 0.5f; - Tightness.Insert(index,tightness); - return index; -} - -void CardinalSpline3DClass::Remove_Key(int i) -{ - Tightness.Delete(i); - HermiteSpline3DClass::Remove_Key(i); -} - -void CardinalSpline3DClass::Clear_Keys(void) -{ - Tightness.Clear(); - HermiteSpline3DClass::Clear_Keys(); -} - -void CardinalSpline3DClass::Set_Tightness(int i,float tightness) -{ - WWASSERT(i >= 0); - WWASSERT(i < Tightness.Count()); - Tightness[i] = tightness; - TangentsDirty = true; -} - -float CardinalSpline3DClass::Get_Tightness(int i) -{ - return Tightness[i]; -} - -void CardinalSpline3DClass::Update_Tangents(void) -{ - if (Keys.Count() < 2) { - for (int i=0; i= 0); - WWASSERT(i < Tightness.Count()); - Tightness[i] = tightness; - TangentsDirty = true; -} - -float CardinalSpline1DClass::Get_Tightness(int i) -{ - return Tightness[i]; -} - -void CardinalSpline1DClass::Update_Tangents(void) -{ - if (Keys.Count() < 2) { - for (int i=0; i. -*/ - -/*********************************************************************************************** - *** 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 : WWMath * - * * - * $Archive:: /VSS_Sync/wwmath/cardinalspline.h $* - * * - * Author:: Greg Hjelstrom * - * * - * $Modtime:: 6/13/01 2:18p $* - * * - * $Revision:: 4 $* - * * - *---------------------------------------------------------------------------------------------* - * Functions: * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - - -#if defined(_MSC_VER) -#pragma once -#endif - -#ifndef CARDINALSPLINE_H -#define CARDINALSPLINE_H - -#include "hermitespline.h" - -/** -** CardinalSpline3DClass -** 3-Dimensional cardinal splines -*/ -class CardinalSpline3DClass : public HermiteSpline3DClass -{ -public: - - virtual int Add_Key(const Vector3 & point,float t); - virtual void Remove_Key(int i); - virtual void Clear_Keys(void); - - virtual void Set_Tightness(int i,float tightness); - virtual float Get_Tightness(int i); - - virtual void Update_Tangents(void); - - // save-load support - virtual const PersistFactoryClass & Get_Factory(void) const; - virtual bool Save(ChunkSaveClass &csave); - virtual bool Load(ChunkLoadClass &cload); - -protected: - - DynamicVectorClass Tightness; -}; - - -/** -** CardinalSpline1DClass -** 1-Dimensional cardinal splines -*/ -class CardinalSpline1DClass : public HermiteSpline1DClass -{ -public: - - virtual int Add_Key(float point,float t); - virtual void Remove_Key(int i); - virtual void Clear_Keys(void); - - virtual void Set_Tightness(int i,float tightness); - virtual float Get_Tightness(int i); - - virtual void Update_Tangents(void); - - // save-load support - virtual const PersistFactoryClass & Get_Factory(void) const; - virtual bool Save(ChunkSaveClass &csave); - virtual bool Load(ChunkLoadClass &cload); - -protected: - - DynamicVectorClass Tightness; -}; - - -#endif - diff --git a/Generals/Code/Libraries/Source/WWVegas/WWMath/castres.h b/Generals/Code/Libraries/Source/WWVegas/WWMath/castres.h deleted file mode 100644 index e1bf2169980..00000000000 --- a/Generals/Code/Libraries/Source/WWVegas/WWMath/castres.h +++ /dev/null @@ -1,75 +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 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 : WWMath * - * * - * $Archive:: /Commando/Code/wwmath/castres.h $* - * * - * Author:: Greg_h * - * * - * $Modtime:: 11/14/00 2:59p $* - * * - * $Revision:: 10 $* - * * - *---------------------------------------------------------------------------------------------* - * Functions: * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - -#if defined(_MSC_VER) -#pragma once -#endif - -#ifndef CASTRES_H -#define CASTRES_H - -#include "always.h" -#include "vector3.h" -#include "bittype.h" - - -/** -** CastResultStruct -** Result of a volume or ray cast operation will be stored in the following structure -** NOTE: If you can avoid it, do not enable ComputeContactPoint. When casting rays, it is more -** efficient to use the resulting Fraction to compute the contact point outside of the -** collision detection code. In the case of AABox sweeping for character collision detection, -** you don't usually need the actual point of contact, etc etc. -** -** The default state of ComputeContactPoint is *false* -*/ -struct CastResultStruct -{ - CastResultStruct(void) { Reset(); } - void Reset(void) { StartBad = false; Fraction = 1.0f; Normal.Set(0,0,0); SurfaceType = 0; ComputeContactPoint = false; ContactPoint.Set(0,0,0); } - - bool StartBad; // was the inital configuration interpenetrating something? - float Fraction; // fraction of the move up until collision - Vector3 Normal; // surface normal at the collision point - uint32 SurfaceType; // surface type of polygon at collision point (see W3D_SURFACE_TYPES in w3d_file.h) - - bool ComputeContactPoint; // This signals the collision code to compute the point of collision - Vector3 ContactPoint; // This will be set to the point of collision if ComputeContactPoint is true - -}; - - -#endif diff --git a/Generals/Code/Libraries/Source/WWVegas/WWMath/catmullromspline.cpp b/Generals/Code/Libraries/Source/WWVegas/WWMath/catmullromspline.cpp deleted file mode 100644 index e6e70b983fc..00000000000 --- a/Generals/Code/Libraries/Source/WWVegas/WWMath/catmullromspline.cpp +++ /dev/null @@ -1,354 +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 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 : WWMath * - * * - * $Archive:: /Commando/Code/wwmath/catmullromspline.cpp $* - * * - * Author:: Greg Hjelstrom * - * * - * $Modtime:: 3/08/00 8:50p $* - * * - * $Revision:: 6 $* - * * - *---------------------------------------------------------------------------------------------* - * Functions: * - * CatmullRomSpline3DClass::Update_Tangents -- computes the tangents at each key * - * CatmullRomSpline3DClass::Get_Factory -- returns the factory for CatmullRomSpline3D * - * CatmullRomSpline3DClass::Save -- save this curve * - * CatmullRomSpline3DClass::Load -- load this curve * - * CatmullRomSpline1DClass::Update_Tangents -- Computes the tangents at each key * - * CatmullRomSpline1DClass::Get_Factory -- returns the factory for CatmullRomSpline1D * - * CatmullRomSpline1DClass::Save -- Save this curve * - * CatmullRomSpline1DClass::Load -- Load this curve * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - - -#include "catmullromspline.h" -#include "persistfactory.h" -#include "wwmathids.h" -#include "wwhack.h" - -/* -** Force-Link this module because the linker can't detect that we actually need it... -*/ -DECLARE_FORCE_LINK(catmullromspline); - -/* -** Save-Load stuff -*/ -SimplePersistFactoryClass _CatmullRomSpline3DFactory; -SimplePersistFactoryClass _CatmullRomSpline1DFactory; - -enum -{ - // ID's used by CatmullRomSpline3D - CATMULLROM3D_CHUNK_HERMITE3D = 0x00020727, - - // ID's used by CatmullRomSpline1D - CATMULLROM1D_CHUNK_HERMITE1D = 0x00020729, -}; - - -/* -** Catmull-Rom 3D spline implementation -*/ - -/*********************************************************************************************** - * CatmullRomSpline3DClass::Update_Tangents -- computes the tangents at each key * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * I'm not sure about the tangents for the endpoints of the curve. * - * * - * HISTORY: * - * 3/7/2000 gth : Created. * - *=============================================================================================*/ -void CatmullRomSpline3DClass::Update_Tangents(void) -{ - if (Keys.Count() < 2) { - for (int i=0; i. -*/ - -/*********************************************************************************************** - *** 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 : WWMath * - * * - * $Archive:: /Commando/Code/wwmath/catmullromspline.h $* - * * - * Author:: Greg Hjelstrom * - * * - * $Modtime:: 3/07/00 9:51a $* - * * - * $Revision:: 6 $* - * * - *---------------------------------------------------------------------------------------------* - * Functions: * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - - -#if defined(_MSC_VER) -#pragma once -#endif - -#ifndef CATMULLROMSPLINE_H -#define CATMULLROMSPLINE_H - -#include "hermitespline.h" - -/** -** CatmullRomSpline3DClass -** This is is an implementation of 3D catmull-rom splines -*/ -class CatmullRomSpline3DClass : public HermiteSpline3DClass -{ -public: - void Update_Tangents(void); - - // save-load support - virtual const PersistFactoryClass & Get_Factory(void) const; - virtual bool Save(ChunkSaveClass &csave); - virtual bool Load(ChunkLoadClass &cload); -}; - - -/** -** CatmullRomSpline1DClass -** This is is an implementation of 1D catmull-rom splines -*/ -class CatmullRomSpline1DClass : public HermiteSpline1DClass -{ -public: - void Update_Tangents(void); - - // save-load support - virtual const PersistFactoryClass & Get_Factory(void) const; - virtual bool Save(ChunkSaveClass &csave); - virtual bool Load(ChunkLoadClass &cload); -}; - -#endif \ No newline at end of file diff --git a/Generals/Code/Libraries/Source/WWVegas/WWMath/colmath.cpp b/Generals/Code/Libraries/Source/WWVegas/WWMath/colmath.cpp deleted file mode 100644 index 86cae720b20..00000000000 --- a/Generals/Code/Libraries/Source/WWVegas/WWMath/colmath.cpp +++ /dev/null @@ -1,68 +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 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 : WWMath * - * * - * $Archive:: /Commando/Code/wwmath/colmath.cpp $* - * * - * Author:: Greg Hjelstrom * - * * - * $Modtime:: 3/16/00 2:19p $* - * * - * $Revision:: 4 $* - * * - *---------------------------------------------------------------------------------------------* - * Functions: * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - - -#include "colmath.h" - -const float CollisionMath::COINCIDENCE_EPSILON = 0.000001f; -CollisionMath::ColmathStatsStruct CollisionMath::Stats; - -CollisionMath::ColmathStatsStruct::ColmathStatsStruct(void) -{ - Reset(); -} - -void CollisionMath::ColmathStatsStruct::Reset(void) -{ - TotalCollisionCount = 0; - TotalCollisionHitCount = 0; - - CollisionRayTriCount = 0; - CollisionRayTriHitCount = 0; - - CollisionAABoxTriCount = 0; - CollisionAABoxTriHitCount = 0; - CollisionAABoxAABoxCount = 0; - CollisionAABoxAABoxHitCount = 0; - - CollisionOBBoxTriCount = 0; - CollisionOBBoxTriHitCount = 0; - CollisionOBBoxAABoxCount = 0; - CollisionOBBoxAABoxHitCount = 0; - CollisionOBBoxOBBoxCount = 0; - CollisionOBBoxOBBoxHitCount = 0; -} - diff --git a/Generals/Code/Libraries/Source/WWVegas/WWMath/colmath.h b/Generals/Code/Libraries/Source/WWVegas/WWMath/colmath.h deleted file mode 100644 index 41a1c85e0ca..00000000000 --- a/Generals/Code/Libraries/Source/WWVegas/WWMath/colmath.h +++ /dev/null @@ -1,312 +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 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 : WWMath * - * * - * $Archive:: /Commando/Code/wwmath/colmath.h $* - * * - * Author:: Greg Hjelstrom * - * * - * $Modtime:: 5/04/01 8:25p $* - * * - * $Revision:: 19 $* - * * - *---------------------------------------------------------------------------------------------* - * Functions: * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - -#if defined(_MSC_VER) -#pragma once -#endif - -#ifndef COLMATH_H -#define COLMATH_H - -#ifndef ALWAYS_H -#include "always.h" -#endif - -#ifndef VECTOR3_H -#include "vector3.h" -#endif - -#ifndef CASTRES_H -#include "castres.h" -#endif - -class AAPlaneClass; -class PlaneClass; -class LineSegClass; -class TriClass; -class SphereClass; -class AABoxClass; -class OBBoxClass; -class FrustumClass; - -const float COLLISION_EPSILON = 0.001f; - -/* -** #define COLMATH_STAT_TRACKING to enable stat tracking for the collision math functions -*/ -#ifdef WWDEBUG -#define COLMATH_STAT_TRACKING -#endif - - -/** -** CollisionMath -** This is a collection of the low-level math functions for collision detection. -*/ -class CollisionMath -{ -public: - - //////////////////////////////////////////////////////////////////////////////////////// - // Intersect Functions. - // These functions simply return a bool indicating whether the two operands intersect. - //////////////////////////////////////////////////////////////////////////////////////// - static bool Intersection_Test(const AABoxClass & box,const TriClass & tri); - static bool Intersection_Test(const AABoxClass & box,const AABoxClass & box2); - static bool Intersection_Test(const AABoxClass & box,const OBBoxClass & box2); - static bool Intersection_Test(const OBBoxClass & box,const TriClass & tri); - static bool Intersection_Test(const OBBoxClass & box,const AABoxClass & box2); - static bool Intersection_Test(const OBBoxClass & box,const OBBoxClass & box2); - static bool Intersection_Test(const SphereClass & sphere,const AABoxClass & box); - static bool Intersection_Test(const SphereClass & sphere,const OBBoxClass & box); - - //////////////////////////////////////////////////////////////////////////////////////// - // Overlap Functions. - // Classify the second operand with respect to the first operand. - // For example Overlap_Test(plane,point) tests whether 'point' is in front of or - // behind 'plane'. - // OverlapType: This enumeration is the result of an overlap test. - // It indicates whether the the object is in the positive (front/outside) space - // of the volume, the negative (back/inside) space of the volume, or both (overlapping) - //////////////////////////////////////////////////////////////////////////////////////// - enum OverlapType - { - POS = 0x01, - NEG = 0x02, - ON = 0x04, - BOTH = 0x08, - OUTSIDE = POS, - INSIDE = NEG, - OVERLAPPED = BOTH, - FRONT = POS, - BACK = NEG - }; - - // AAPlane functions. Where is operand B with respect to this AAPlane - static OverlapType Overlap_Test(const AAPlaneClass & plane,const Vector3 & point); - static OverlapType Overlap_Test(const AAPlaneClass & plane,const LineSegClass & line); - static OverlapType Overlap_Test(const AAPlaneClass & plane,const TriClass & tri); - static OverlapType Overlap_Test(const AAPlaneClass & plane,const SphereClass & sphere); - static OverlapType Overlap_Test(const AAPlaneClass & plane,const AABoxClass & box); - static OverlapType Overlap_Test(const AAPlaneClass & plane,const OBBoxClass & box); - - // Plane functions. Where is operand B with respect to the plane - static OverlapType Overlap_Test(const PlaneClass & plane,const Vector3 & point); - static OverlapType Overlap_Test(const PlaneClass & plane,const LineSegClass & line); - static OverlapType Overlap_Test(const PlaneClass & plane,const TriClass & tri); - static OverlapType Overlap_Test(const PlaneClass & plane,const SphereClass & sphere); - static OverlapType Overlap_Test(const PlaneClass & plane,const Vector3 & center,const Vector3 & extent); - inline static OverlapType Overlap_Test(const PlaneClass & plane,const AABoxClass & box); - static OverlapType Overlap_Test(const PlaneClass & plane,const OBBoxClass & box); - - // Sphere functions. Where is operand B with respect to the sphere - static OverlapType Overlap_Test(const SphereClass & sphere,const Vector3 & point); - static OverlapType Overlap_Test(const SphereClass & sphere,const LineSegClass & line); - static OverlapType Overlap_Test(const SphereClass & sphere,const TriClass & tri); - static OverlapType Overlap_Test(const SphereClass & sphere,const SphereClass & sphere2); - static OverlapType Overlap_Test(const SphereClass & sphere,const AABoxClass & aabox); - static OverlapType Overlap_Test(const SphereClass & sphere,const OBBoxClass & obbox); - - // AABox functions. Where is operand B with respect to the AABox - static OverlapType Overlap_Test(const AABoxClass & box,const Vector3 & point); - static OverlapType Overlap_Test(const AABoxClass & box,const LineSegClass & line); - static OverlapType Overlap_Test(const AABoxClass & box,const TriClass & tri); - static OverlapType Overlap_Test(const AABoxClass & box,const AABoxClass & box2); - static OverlapType Overlap_Test(const AABoxClass & box,const OBBoxClass & obbox); - static OverlapType Overlap_Test(const AABoxClass & box,const SphereClass & sphere); - - // OBBox functions, where is operand B with respect to the OBBox - static OverlapType Overlap_Test(const OBBoxClass & box,const Vector3 & point); - static OverlapType Overlap_Test(const OBBoxClass & box,const LineSegClass & line); - static OverlapType Overlap_Test(const OBBoxClass & box,const TriClass & tri); - static OverlapType Overlap_Test(const OBBoxClass & box,const AABoxClass & box2); - static OverlapType Overlap_Test(const OBBoxClass & box,const OBBoxClass & box2); - - // Frustum functions - static OverlapType Overlap_Test(const FrustumClass & frustum,const Vector3 & point); - static OverlapType Overlap_Test(const FrustumClass & frustum,const TriClass & tri); - static OverlapType Overlap_Test(const FrustumClass & frustum,const SphereClass & sphere); - static OverlapType Overlap_Test(const FrustumClass & frustum,const AABoxClass & box); - static OverlapType Overlap_Test(const FrustumClass & frustum,const OBBoxClass & box); - - // Frustum functions for hierachical culling systems. - // At your root node, just pass in planes_passed = 0, then the variable will be modified to - // indicate which planes that volume was inside. You can then pass that value in for the - // test of all child nodes and optimize away some of the tests. See AABTreeCullSystemClass - // for an example usage. - static OverlapType Overlap_Test(const FrustumClass & frustum,const AABoxClass & box,int & planes_passed); - static OverlapType Overlap_Test(const FrustumClass & frustum,const OBBoxClass & box,int & planes_passed); - - // Miscellaneous other Overlap tests - static OverlapType Overlap_Test(const Vector3 & min,const Vector3 & max,const LineSegClass & line); - - //////////////////////////////////////////////////////////////////////////////////////// - // Collision Functions. - // Collide the first operand into the last operand. - // For example Collide(box,move,tri) tests for collision between a box moving into - // a triangle. - //////////////////////////////////////////////////////////////////////////////////////// - - // Line segment functions. Intersect this line segment with the given object - static bool Collide(const LineSegClass & line,const AAPlaneClass & plane,CastResultStruct * result); - static bool Collide(const LineSegClass & line,const PlaneClass & plane,CastResultStruct * result); - static bool Collide(const LineSegClass & line,const TriClass & tri,CastResultStruct * result); - static bool Collide(const LineSegClass & line,const SphereClass & sphere,CastResultStruct * result); - static bool Collide(const LineSegClass & line,const AABoxClass & box,CastResultStruct * result); - static bool Collide(const LineSegClass & line,const OBBoxClass & box,CastResultStruct * result); - - // AABox functions - static bool Collide(const AABoxClass & box,const Vector3 & move,const PlaneClass & plane,CastResultStruct * result); - static bool Collide(const AABoxClass & box,const Vector3 & move,const TriClass & tri,CastResultStruct * result); - static bool Collide(const AABoxClass & box,const Vector3 & move,const AABoxClass & box2,CastResultStruct * result); - static bool Collide(const AABoxClass & box,const Vector3 & move,const OBBoxClass & box2,const Vector3 & move2,CastResultStruct * result); - - // OBBox functions - static bool Collide(const OBBoxClass & box,const Vector3 & move,const PlaneClass & plane,CastResultStruct * result); - static bool Collide(const OBBoxClass & box,const Vector3 & move,const TriClass & tri,const Vector3 & move2,CastResultStruct * result); - static bool Collide(const OBBoxClass & box,const Vector3 & move,const AABoxClass & box2,const Vector3 & move2,CastResultStruct * result); - static bool Collide(const OBBoxClass & box,const Vector3 & move,const OBBoxClass & box2,const Vector3 & move2,CastResultStruct * result); - - //////////////////////////////////////////////////////////////////////////////////////// - // Stats - // Note that these functions will only work if you have stat tracking enabled - //////////////////////////////////////////////////////////////////////////////////////// - struct ColmathStatsStruct - { - ColmathStatsStruct(void); - void Reset(void); - - int TotalCollisionCount; - int TotalCollisionHitCount; - - int CollisionRayTriCount; - int CollisionRayTriHitCount; - - int CollisionAABoxTriCount; - int CollisionAABoxTriHitCount; - int CollisionAABoxAABoxCount; - int CollisionAABoxAABoxHitCount; - - int CollisionOBBoxTriCount; - int CollisionOBBoxTriHitCount; - int CollisionOBBoxAABoxCount; - int CollisionOBBoxAABoxHitCount; - int CollisionOBBoxOBBoxCount; - int CollisionOBBoxOBBoxHitCount; - }; - - static void Reset_Stats(void) { Stats.Reset(); } - static const ColmathStatsStruct & Get_Current_Stats(void) { return Stats; } - -private: - - static OverlapType eval_overlap_mask(int mask); - static OverlapType eval_overlap_collision(const CastResultStruct & res); - - static const float COINCIDENCE_EPSILON; - - static ColmathStatsStruct Stats; -}; - - -inline CollisionMath::OverlapType CollisionMath::eval_overlap_mask(int mask) -{ - // check if all verts are "ON" - if (mask == ON) { - return ON; - } - - // check if all verts are either "ON" or "POS" - if ((mask & ~(POS | ON)) == 0) { - return POS; - } - - // check if all verts are either "ON" or "BACK" - if ((mask & ~(NEG | ON)) == 0) { - return NEG; - } - - // otherwise, poly spans the plane. - return BOTH; -} - - -inline CollisionMath::OverlapType CollisionMath::eval_overlap_collision(const CastResultStruct & res) -{ - if (res.Fraction < 1.0f) { - return BOTH; - } else { - if (res.StartBad) { - return NEG; - } else { - return POS; - } - } -} - - -/* -** Stat tracking Macros -*/ -#ifdef COLMATH_STAT_TRACKING -#define TRACK_COLLISION_RAY_TRI Stats.CollisionRayTriCount++; Stats.TotalCollisionCount++; -#define TRACK_COLLISION_RAY_TRI_HIT Stats.CollisionRayTriHitCount++; Stats.TotalCollisionHitCount; -#define TRACK_COLLISION_AABOX_TRI Stats.CollisionAABoxTriCount++; Stats.TotalCollisionCount++; -#define TRACK_COLLISION_AABOX_TRI_HIT Stats.CollisionAABoxTriHitCount++; Stats.TotalCollisionHitCount++; -#define TRACK_COLLISION_AABOX_AABOX Stats.CollisionAABoxAABoxCount++; Stats.TotalCollisionCount++; -#define TRACK_COLLISION_AABOX_AABOX_HIT Stats.CollisionAABoxAABoxHitCount++; Stats.TotalCollisionHitCount++; -#define TRACK_COLLISION_OBBOX_TRI Stats.CollisionOBBoxTriCount++; Stats.TotalCollisionCount++; -#define TRACK_COLLISION_OBBOX_TRI_HIT Stats.CollisionOBBoxTriHitCount++; Stats.TotalCollisionHitCount++; -#define TRACK_COLLISION_OBBOX_AABOX Stats.CollisionOBBoxAABoxCount++; Stats.TotalCollisionCount++; -#define TRACK_COLLISION_OBBOX_AABOX_HIT Stats.CollisionOBBoxAABoxHitCount++; Stats.TotalCollisionHitCount++; -#define TRACK_COLLISION_OBBOX_OBBOX Stats.CollisionOBBoxOBBoxCount++; Stats.TotalCollisionCount++; -#define TRACK_COLLISION_OBBOX_OBBOX_HIT Stats.CollisionOBBoxOBBoxHitCount++; Stats.TotalCollisionHitCount++; -#else -#define TRACK_COLLISION_RAY_TRI -#define TRACK_COLLISION_RAY_TRI_HIT -#define TRACK_COLLISION_AABOX_TRI -#define TRACK_COLLISION_AABOX_TRI_HIT -#define TRACK_COLLISION_AABOX_AABOX -#define TRACK_COLLISION_AABOX_AABOX_HIT -#define TRACK_COLLISION_OBBOX_TRI -#define TRACK_COLLISION_OBBOX_TRI_HIT -#define TRACK_COLLISION_OBBOX_AABOX -#define TRACK_COLLISION_OBBOX_AABOX_HIT -#define TRACK_COLLISION_OBBOX_OBBOX -#define TRACK_COLLISION_OBBOX_OBBOX_HIT -#endif - -#endif // COLMATH_H diff --git a/Generals/Code/Libraries/Source/WWVegas/WWMath/colmathaabox.cpp b/Generals/Code/Libraries/Source/WWVegas/WWMath/colmathaabox.cpp deleted file mode 100644 index e5e86e4b86a..00000000000 --- a/Generals/Code/Libraries/Source/WWVegas/WWMath/colmathaabox.cpp +++ /dev/null @@ -1,595 +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 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 : WWMath * - * * - * $Archive:: /Commando/Code/wwmath/colmathaabox.cpp $* - * * - * Author:: Greg Hjelstrom * - * * - * $Modtime:: 11/14/00 2:46p $* - * * - * $Revision:: 21 $* - * * - *---------------------------------------------------------------------------------------------* - * Functions: * - * CollisionMath::Intersection_Test -- Test intersection between two AABoxes * - * CollisionMath::Overlap_Test -- Tests overlap between an AABox and a sphere * - * CollisionMath::Overlap_Test -- Tests overlap between an AABox and a triangle * - * CollisionMath::Overlap_Test -- Tests overlap between an AABox and a line segment * - * CollisionMath::Collide -- Collision test for a moving AABox and a plane * - * aab_separation_test -- tests two AAB's for separation on an axis * - * CollisionMath::Collide -- Collision test for two moving AABoxes * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - - -#include "colmath.h" -#include "colmathinlines.h" -#include "aaplane.h" -#include "plane.h" -#include "lineseg.h" -#include "tri.h" -#include "sphere.h" -#include "aabox.h" -#include "obbox.h" -#include "wwdebug.h" - - -/*********************************************************************************************** - * CollisionMath::Intersection_Test -- Test intersection between two AABoxes * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 11/19/99 gth : Created. * - *=============================================================================================*/ -bool CollisionMath::Intersection_Test(const AABoxClass & box,const AABoxClass & box2) -{ - Vector3 dc = box2.Center - box.Center; - - if (box.Extent.X + box2.Extent.X < WWMath::Fabs(dc.X)) return false; - if (box.Extent.Y + box2.Extent.Y < WWMath::Fabs(dc.Y)) return false; - if (box.Extent.Z + box2.Extent.Z < WWMath::Fabs(dc.Z)) return false; - return true; -} - -/*********************************************************************************************** - * CollisionMath::Overlap_Test -- Tests overlap between an AABox and a sphere * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 11/19/99 gth : Created. * - *=============================================================================================*/ -CollisionMath::OverlapType CollisionMath::Overlap_Test(const AABoxClass & box,const SphereClass & sphere) -{ - // TODO: this function seems incorrect. Not currently using it though - Vector3 dist = sphere.Center - box.Center; - - Vector3 extent; - extent.X = box.Extent.X + sphere.Radius; - extent.Y = box.Extent.Y + sphere.Radius; - extent.Z = box.Extent.Z + sphere.Radius; - - // - // Check to see if the sphere is completely outside the box - // - if (WWMath::Fabs(dist.X) > extent.X) return OUTSIDE; - if (WWMath::Fabs(dist.Y) > extent.Y) return OUTSIDE; - if (WWMath::Fabs(dist.Z) > extent.Z) return OUTSIDE; - - return INSIDE; -} - - - -/*********************************************************************************************** - * CollisionMath::Overlap_Test -- Tests overlap between an AABox and a line segment * - * * - * This function uses separating axes to determine whether an AABox and a line segment overlap * - * I wrote it when we found that ray-casting was taking a huge amount of time in Renegade. * - * Here are some statistics comparing this function to the previous function which used the * - * same algorithm that Collide(box,ray) uses. * - * * - * collide algorithm (Gems) separating axis (this one) * - * ----------------------------------------------------------------------------------------- * - * number of tests 10000 10000 * - * avg cycles 641 464 * - * outside cycles 652 390 * - * overlap cycles 610 683 * - * * - * The idea for this test is that it will early-exit when it can while the old test can't. * - * When we are passing a ray down our culling trees, it is common to encounter boxes that * - * are not intersecting the ray. The faster we can reject these, the better! * - * * - * INPUT: * - * box - box to test * - * line - line to test * - * * - * OUTPUT: * - * overlap status of the line with respect to the box, either INSIDE, OUTSIDE, or OVERLAPPED * - * * - * WARNINGS: * - * * - * HISTORY: * - * 11/19/99 gth : Created. * - *=============================================================================================*/ -CollisionMath::OverlapType CollisionMath::Overlap_Test(const AABoxClass & box,const LineSegClass & line) -{ - // If both endpoints are in, return INSIDE - // If either was inside, return OVERLAPPED - int inside_point_count = 0; - if (CollisionMath::Overlap_Test(box,line.Get_P0()) == INSIDE) inside_point_count++; - if (CollisionMath::Overlap_Test(box,line.Get_P1()) == INSIDE) inside_point_count++; - - if (inside_point_count == 2) { - - return INSIDE; - - } else if (inside_point_count == 1) { - - return OVERLAPPED; - - } else { - - // Here I'm using the separating axis theorem to test if the line-segment - // and the box can be separated by a plane. Any two convex objects that are - // not intersecting can be separated by a plane defined by either a - // face normal from one of the objects or the cross-product of an edge from - // each object. In the case of an axis-aligned box and a line-segment, we - // have to check the three coordinate axes and the cross product between - // each and the direction vector of the line segment. - // - // Here is the general test for an arbitrary axis: - // ----------------------------------------------- - // box_proj = fabs(extent.X*axis.X) + fabs(extent.Y*axis.Y) + fabs(extent.Z*axis.Z) - // p0_proj = fabs(dot_product(dp0,axis)) - // dp_proj = fabs(dot_product(dp,axis)) - // if (p0_proj > 0) { - // if (p0_proj > box_proj - WWMath::Min(dp_proj,0.0f)) return OUTSIDE; - // } else { - // if (-p0_proj > box_proj + WWMath::Max(dp_proj,0.0f)) return OUTSIDE; - // } - // - // In practice, there are optimizations you can make on each of the axes that - // we need to test (see below). - - float box_proj,p0_proj,dp_proj; - Vector3 dp0; - Vector3::Subtract(line.Get_P0(),box.Center,&dp0); - - // Project box and line onto the x-axis - // Since I know the axis is the x-axis, just take the x components of each - // vector instead of doing the dot-product. The projection of 'dp' is only - // counted if it points towards the center of the box (i.e. it decreases the - // chances of them being separated...) - box_proj = box.Extent.X; - p0_proj = dp0.X; - dp_proj = line.Get_DP().X; - if (p0_proj > 0) { - if (p0_proj > box_proj - WWMath::Min(dp_proj,0.0f)) return OUTSIDE; - } else { - if (-p0_proj > box_proj + WWMath::Max(dp_proj,0.0f)) return OUTSIDE; - } - - // Project box and line onto the y-axis - box_proj = box.Extent.Y; - p0_proj = dp0.Y; - dp_proj = line.Get_DP().Y; - if (p0_proj > 0) { - if (p0_proj > box_proj - WWMath::Min(dp_proj,0.0f)) return OUTSIDE; - } else { - if (-p0_proj > box_proj + WWMath::Max(dp_proj,0.0f)) return OUTSIDE; - } - - // Project box and line onto the z-axis - box_proj = box.Extent.Z; - p0_proj = dp0.Z; - dp_proj = line.Get_DP().Z; - if (p0_proj > 0) { - if (p0_proj > box_proj - WWMath::Min(dp_proj,0.0f)) return OUTSIDE; - } else { - if (-p0_proj > box_proj + WWMath::Max(dp_proj,0.0f)) return OUTSIDE; - } - - // Project box and line onto (x cross line) - // I'm manually optimizing the cross-product and taking advantage of the fact - // that 'dp' will always project to zero for this axis. - Vector3 axis; - axis.Set(0,-line.Get_Dir().Z,line.Get_Dir().Y); // == (1,0,0) cross (x,y,z) - box_proj = WWMath::Fabs(axis.Y*box.Extent.Y) + WWMath::Fabs(axis.Z*box.Extent.Z); - p0_proj = Vector3::Dot_Product(axis,dp0); - if (WWMath::Fabs(p0_proj) > box_proj) return OUTSIDE; - - // Project box and line onto (y cross line) - axis.Set(line.Get_Dir().Z,0,-line.Get_Dir().X); // == (0,1,0) cross (x,y,z) - box_proj = WWMath::Fabs(axis.X*box.Extent.X) + WWMath::Fabs(axis.Z*box.Extent.Z); - p0_proj = Vector3::Dot_Product(axis,dp0); - if (WWMath::Fabs(p0_proj) > box_proj) return OUTSIDE; - - // Project box and line onto (z cross line) - axis.Set(-line.Get_Dir().Y,line.Get_Dir().X,0); // == (0,0,1) cross (x,y,z) - box_proj = WWMath::Fabs(axis.X*box.Extent.X) + WWMath::Fabs(axis.Y*box.Extent.Y); - p0_proj = Vector3::Dot_Product(axis,dp0); - if (WWMath::Fabs(p0_proj) > box_proj) return OUTSIDE; - - } - return OVERLAPPED; -} - -#if 0 // Alternate Overlap Test for AABox-Ray -CollisionMath::OverlapType CollisionMath::Overlap_Test(const AABoxClass & box,const LineSegClass & line) -{ - // If both endpoints are in, return INSIDE - // If either was inside, return OVERLAPPED - int inside_point_count = 0; - if (CollisionMath::Overlap_Test(box,line.Get_P0()) == INSIDE) inside_point_count++; - if (CollisionMath::Overlap_Test(box,line.Get_P1()) == INSIDE) inside_point_count++; - - if (inside_point_count == 2) { - - return INSIDE; - - } else if (inside_point_count == 1) { - - return OVERLAPPED; - - } else { - - // Now we know that both points are outside of the box so we - // have to detect if the ray penetrates the box. - // I found this algorithm in one of the GEMS books... - Vector3 boxmin,boxmax; - Vector3::Subtract(box.Center,box.Extent,&boxmin); - Vector3::Add(box.Center,box.Extent,&boxmax); - - float candidateplane[3]; // candidate intersection plane distance for each axis - float maxt[3]; // t value along the ray for each axis - Vector3 coord; // intersection point - - const int BOX_SIDE_NEGATIVE = -1; - const int BOX_SIDE_MIDDLE = 0; - const int BOX_SIDE_POSITIVE = 1; - - int quadrant[3]; - for (int i=0; i<3; i++) { - if (line.Get_P0()[i] < boxmin[i]) { - quadrant[i] = BOX_SIDE_NEGATIVE; - candidateplane[i] = boxmin[i]; - } else if (line.Get_P0()[i] > boxmax[i]) { - quadrant[i] = BOX_SIDE_POSITIVE; - candidateplane[i] = boxmax[i]; - } else { - quadrant[i] = BOX_SIDE_MIDDLE; - } - } - - // Calculate the 3 distances to the candidate planes - for (i=0; i<3; i++) { - if (quadrant[i] != BOX_SIDE_MIDDLE && line.Get_DP()[i] != 0.0f) { - maxt[i] = (candidateplane[i] - line.Get_P0()[i]) / line.Get_DP()[i]; - } else { - maxt[i] = -1.0f; - } - } - - // Get the largest of the maxt's for the final choice of intersection - int intersection_plane = 0; - for (i=1; i<3; i++) { - if (maxt[i] > maxt[intersection_plane]) { - intersection_plane = i; - } - } - - // If the ray is "in front" of all of the planes, return - if (maxt[intersection_plane] < 0.0f) { - return OUTSIDE; - } - - // If the intersection is beyond the end of the ray, return - if (maxt[intersection_plane] > 1.0f) { - return OUTSIDE; - } - - // Check if the ray is inside the box, i.e. on the two planes which - // are not the intersection planes, the intersection point should - // be between the min and max of the box. - for (i=0; i<3; i++) { - - if (intersection_plane != i) { - - coord[i] = line.Get_P0()[i] + maxt[intersection_plane] * line.Get_DP()[i]; - if ((coord[i] < boxmin[i]) || (coord[i] > boxmax[i])) { - return OUTSIDE; // ray is outside the box - } - - } else { - - coord[i] = candidateplane[i]; - - } - } - } - return OVERLAPPED; -} -#endif // Alternate Overlap Test for AABox-Ray - - -/*********************************************************************************************** - * CollisionMath::Overlap_Test -- Tests overlap between an AABox and a triangle * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 11/19/99 gth : Created. * - *=============================================================================================*/ -CollisionMath::OverlapType CollisionMath::Overlap_Test(const AABoxClass & box,const TriClass & tri) -{ - CastResultStruct res; - CollisionMath::Collide(box,Vector3(0,0,0),tri,&res); - return eval_overlap_collision(res); -} - - -/*********************************************************************************************** - * CollisionMath::Collide -- Collision test for a moving AABox and a plane * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 11/19/99 gth : Created. * - *=============================================================================================*/ -bool CollisionMath::Collide -( - const AABoxClass & box, - const Vector3 & move_vector, - const PlaneClass & plane, - CastResultStruct * result -) -{ - float frac; - - float extent = box.Project_To_Axis(plane.N); - float dist = Vector3::Dot_Product(plane.N,box.Center) + plane.D; - float move = Vector3::Dot_Product(plane.N,move_vector); - - if (dist > extent) { - if (dist + move > extent) { - // entire move ok! - frac = 1.0f; - } else { - // partial move allowed - frac = (extent - dist) / move; - } - - } else if (dist < -extent) { - if (dist + move < -extent) { - // entire move ok! - frac = 1.0f; - } else { - // partial move allowed - frac = (-extent - dist) / move; - } - - } else { - result->StartBad = true; - result->Normal = plane.N; - return true; - } - - if (frac < result->Fraction) { - result->Fraction = frac; - result->Normal = plane.N; - if (result->ComputeContactPoint) { - Vector3 move_dir(move_vector); - move_dir.Normalize(); - float move_extent = Vector3::Dot_Product(box.Extent,move_dir); - result->ContactPoint = box.Center + result->Fraction * move_vector + move_extent * move_dir; - } - return true; - } - - return false; -} - - - - - -/* -** AABCollisionStruct -** Contains all of the intermediate and temporary values used by -** the set of functions used in detecting collisions for aab's -*/ -struct AABCollisionStruct -{ - AABCollisionStruct(const AABoxClass &box0,const Vector3 &move0,const AABoxClass & box1,const Vector3 &move1) : - StartBad(true), // Startbad is true until one of the axes clears it - AxisId(-1), // AxisId will be the axis that allowed the longest move - MaxFrac(0.0f), // MaxFrac is the longest allowed move so far - Box0(box0), - Box1(box1) - { - Vector3::Subtract(box1.Center,box0.Center,&C); // vector from center of box0 to center of box1 - Vector3::Subtract(move1,move0,&M); // move vector relative to stationary box0 - } - - bool StartBad; // Inital configuration is intersecting? - float MaxFrac; // Longest move allowed so far - int AxisId; // Last separating axis - int Side; // which side of the interval - - Vector3 C; // Vector from the center0 to center1 - Vector3 M; // Move vector relative to stationary box0 - - const AABoxClass & Box0; - const AABoxClass & Box1; - -private: - - //not implemented - AABCollisionStruct(const AABCollisionStruct&); - AABCollisionStruct & operator = (const AABCollisionStruct&); -}; - - -/*********************************************************************************************** - * aab_separation_test -- tests two AAB's for separation on an axis * - * * - * This function is very similar to the obb_separation_test. If a flaw is found in either, * - * we should update the other... * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 11/19/99 gth : Created. * - *=============================================================================================*/ -static inline bool aab_separation_test -( - AABCollisionStruct & context, - int axis -) -{ - // ra = box0 projection onto the axis - // rb = box1 projection onto the axis - // u0 = projected distance between the box centers at t0 - // u1 = projected distance between the box centers at t1 - float ra = context.Box0.Extent[axis]; - float rb = context.Box1.Extent[axis]; - float u0 = context.C[axis]; - float u1 = u0 + context.M[axis]; - - float tmp; - float rsum = ra+rb; - - if ( u0 + WWMATH_EPSILON > rsum ) { - context.StartBad = false; - if ( u1 > rsum ) { - context.MaxFrac = 1.0f; - return true; - } else { - tmp = (rsum-u0)/(u1-u0); - if ( tmp > context.MaxFrac ) { - context.MaxFrac = tmp; - context.AxisId = axis; - context.Side = +1; - } - } - } else if ( u0 - WWMATH_EPSILON < -rsum ) { - context.StartBad = false; - if ( u1 < -rsum ) { - context.MaxFrac = 1.0f; - return true; - } else { - tmp = (-rsum-u0)/(u1-u0); - if ( tmp > context.MaxFrac ) { - context.MaxFrac = tmp; - context.AxisId = axis; - context.Side = -1; - } - } - } - return false; -} - - -/*********************************************************************************************** - * CollisionMath::Collide -- Collision test for two moving AABoxes * - * * - * this function sweeps two AABoxes and finds the first time of collision. * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * currently there is no parateter for the movement of the second box. the internal code * - * can handle it though. * - * * - * HISTORY: * - * 11/19/99 gth : Created. * - *=============================================================================================*/ -bool CollisionMath::Collide(const AABoxClass & box,const Vector3 & move,const AABoxClass & box2,CastResultStruct * result) -{ - /* - ** Test the X-axis - ** ra = box projection onto the axis - ** rb = box2 projection onto the axis - ** u0 = projected distance between the box centers at t0 - ** u1 = projected distance between the box centers at t1 - */ - AABCollisionStruct context(box,move,box2,Vector3(0,0,0)); - - if (aab_separation_test(context,0)) { - goto exit; - } - - if (aab_separation_test(context,1)) { - goto exit; - } - - if (aab_separation_test(context,2)) { - goto exit; - } - -exit: - - if (context.StartBad) { - result->StartBad = true; - result->Fraction = 0.0f; - return true; - } - - if (context.MaxFrac < result->Fraction) { - - result->Fraction = context.MaxFrac; - result->Normal.Set(0,0,0); - result->Normal[context.AxisId] = context.Side; - - if (result->ComputeContactPoint) { - WWASSERT(0); // TODO - } - - return true; - } - return false; -} diff --git a/Generals/Code/Libraries/Source/WWVegas/WWMath/colmathaabox.h b/Generals/Code/Libraries/Source/WWVegas/WWMath/colmathaabox.h deleted file mode 100644 index a37b7aadd7e..00000000000 --- a/Generals/Code/Libraries/Source/WWVegas/WWMath/colmathaabox.h +++ /dev/null @@ -1,110 +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 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 : WWMath * - * * - * $Archive:: /Commando/Code/wwmath/colmathaabox.h $* - * * - * Original Author:: Greg Hjelstrom * - * * - * $Author:: Jani_p $* - * * - * $Modtime:: 5/08/01 5:01p $* - * * - * $Revision:: 8 $* - * * - *---------------------------------------------------------------------------------------------* - * Functions: * - * CollisionMath::Overlap_Test -- test overlap between an AABox and a point * - * CollisionMath::Overlap_Test -- Tests overlap between two AABoxes * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - -#if defined(_MSC_VER) -#pragma once -#endif - -#ifndef COLMATHAABOX_H -#define COLMATHAABOX_H - -#include "always.h" -#include "aabox.h" -#include "vector3.h" -#include "lineseg.h" - - -/*********************************************************************************************** - * CollisionMath::Overlap_Test -- test overlap between an AABox and a point * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 3/14/2000 gth : Created. * - *=============================================================================================*/ -WWINLINE CollisionMath::OverlapType CollisionMath::Overlap_Test(const AABoxClass & box,const Vector3 & point) -{ - if (WWMath::Fabs(point.X - box.Center.X) > box.Extent.X) return POS; - if (WWMath::Fabs(point.Y - box.Center.Y) > box.Extent.Y) return POS; - if (WWMath::Fabs(point.Z - box.Center.Z) > box.Extent.Z) return POS; - - return NEG; -} - -/*********************************************************************************************** - * CollisionMath::Overlap_Test -- Tests overlap between two AABoxes * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 11/19/99 gth : Created. * - *=============================================================================================*/ -WWINLINE CollisionMath::OverlapType CollisionMath::Overlap_Test(const AABoxClass & box,const AABoxClass & box2) -{ - Vector3 dc; - Vector3::Subtract(box2.Center,box.Center,&dc); - - if (box.Extent.X + box2.Extent.X < WWMath::Fabs(dc.X)) return POS; - if (box.Extent.Y + box2.Extent.Y < WWMath::Fabs(dc.Y)) return POS; - if (box.Extent.Z + box2.Extent.Z < WWMath::Fabs(dc.Z)) return POS; - - if ( (dc.X + box2.Extent.X <= box.Extent.X) && - (dc.Y + box2.Extent.Y <= box.Extent.Y) && - (dc.Z + box2.Extent.Z <= box.Extent.Z) && - (dc.X - box2.Extent.X >= -box.Extent.X) && - (dc.Y - box2.Extent.Y >= -box.Extent.Y) && - (dc.Z - box2.Extent.Z >= -box.Extent.Z)) - { - return NEG; // inside; - } - - return BOTH; -} - -#endif - diff --git a/Generals/Code/Libraries/Source/WWVegas/WWMath/colmathaabtri.cpp b/Generals/Code/Libraries/Source/WWVegas/WWMath/colmathaabtri.cpp deleted file mode 100644 index f5d9f1b7bfa..00000000000 --- a/Generals/Code/Libraries/Source/WWVegas/WWMath/colmathaabtri.cpp +++ /dev/null @@ -1,1183 +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 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 : WWMath * - * * - * $Archive:: /Commando/Code/wwmath/colmathaabtri.cpp $* - * * - * Author:: Greg Hjelstrom * - * * - * $Modtime:: 5/08/01 9:52a $* - * * - * $Revision:: 17 $* - * * - *---------------------------------------------------------------------------------------------* - * Functions: * - * aabtri_separation_test -- test the projected extents for separation * - * aabtri_check_axis -- project the aab and tri onto an arbitrary axis * - * aabtri_check_cross_axis -- projects aab and tri onto a "cross" axis * - * aabtri_check_basis_axis -- projects the aab and tri onto a basis axis * - * aabtri_check_normal_axis -- project the box and tri onto the tri-normal * - * eval_side -- returns -1,0,+1 depending on the sign of val and side * - * aabtri_compute_contact_normal -- computes the normal of the collision * - * CollisionMath::Collide -- collide an aabox into a triangle * - * aabtri_intersect_cross_axis -- intersection check for a "cross-product" axis * - * aabtri_intersect_basis_axis -- intersection check for a basis axis * - * aabtri_intersect_normal_axis -- intersection check for the triangle normal * - * CollisionMath::Intersection_Test -- Intersection check for an AABox and a triangle * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - - -#include "colmath.h" -#include "aabox.h" -#include "tri.h" -#include "wwdebug.h" - - -/* -** Separating Axes have to be rejected if their length is smaller than some epsilon. -** Otherwise, erroneous results can be reported. -*/ -#define AXISLEN_EPSILON2 WWMATH_EPSILON * WWMATH_EPSILON // squared length of a separating axis must be larger than this - - -/* -** Axes used in Box-Tri intersection tests -** The axes of the box are A0,A1,A2. N is the normal of the triangle, -** E0,E1,E2 are direction vectors for the edges of the triangle. -** (the box axes are labeled A0,A1,A2 as a holdover from the obbox-obbox -** collision code which this was derived from where there are two boxes -** A and B) -*/ -enum -{ - INTERSECTION = 0, - AXIS_N, // normal of the triangle - AXIS_A0, // first basis vector of the box - AXIS_A1, // second basis vector of the box - AXIS_A2, // third basis vector of the box - - AXIS_A0E0, // box0 x edge0... - AXIS_A1E0, - AXIS_A2E0, - AXIS_A0E1, - AXIS_A1E1, - AXIS_A2E1, - AXIS_A0E2, - AXIS_A1E2, - AXIS_A2E2 -}; - - -/****************************************************************************************** - - AABox->Triangle collision - - This code is basically a special-case optimization of the OBBox->Triangle collision - detection code. There are many dot and cross products that can be simplified due - to the fact that we know the axes of the boxes are always the same and are aligned - with the world coordinate axes. - - Each axis test will use the following logic: - Project D onto the axis being used, it is the separation distance. If the - projection of the extent of the box + the projection of the extent of the - tri is greater than D*axis then the two intersect - - March 13, 2000 - Modified these routines to all use a static instance of - the BTCollisionStruct. The compiler was generating lots of extra code for the - constructor of this object and testing determined that re-using the same static - struct was slightly faster anyway. - NOTE: this makes the code not Thread-Safe!!!! - - -******************************************************************************************/ - -/* -** BoxTriColStruct -** Scratchpad variables for the AABox-Triangle collision detection functions. One instance -** of this structure will be used for all of the local variables and its pointer will be -** handed of to various inline functions for the axis tests. -** Note that much of the code needs the un-normalized triangle normal. For this reason, -** I have to compute N rather than copying it from the triangle. (commenting this to -** avoid re-generating a difficult to find bug that I had) -*/ -struct BTCollisionStruct -{ - BTCollisionStruct(void) {} - - void Init(const AABoxClass &box,const Vector3 &move,const TriClass &tri,const Vector3 &trimove) - { - StartBad = true; // true until an axis clears it - MaxFrac = -0.01f; // maximum move allowed so far - AxisId = INTERSECTION; // axis that allowed the longest move - Point = 0; // index of triangle point that was closest to the box - Side = 0; // side of the interval - Box = &box; - Tri = &tri; - BoxMove = &move; - TriMove = &trimove; - - Vector3::Subtract(*tri.V[0],box.Center,&D); // vector from center of box to vertex 0 - Vector3::Subtract(move,trimove,&Move); // move vector relative to stationary triangle - - Vector3::Subtract(*tri.V[1],*tri.V[0],&E[0]); - Vector3::Subtract(*tri.V[2],*tri.V[0],&E[1]); - Vector3::Subtract(E[1],E[0],&E[2]); - - Vector3::Cross_Product(E[0],E[1],&N); - } - - bool StartBad; // Inital configuration is intersecting? - float MaxFrac; // Longest move allowed so far - - int AxisId; // Last separating axis - int Side; // which side of the interval - int Point; // Index of the "closest" triangle point (or one of them) - - int TestAxisId; // Axis 'id' we're working on - int TestSide; // Was the axis we're working on flipped - int TestPoint; // Index of the closest vertex - Vector3 TestAxis; // Axis we're working on - - Vector3 D; // Vector from the center of the box to v0 - Vector3 Move; // Move vector relative to stationary triangle - float AE[3][3]; // Dot products of the Basis vectors and edges - float AN[3]; // Dot products of the Basis vectors and the normal - Vector3 AxE[3][3]; // Cross products of the Basis vectors and edges - - Vector3 E[3]; // edge vectors for the triangle - Vector3 N; // normal (NOT normalized!!!) - Vector3 FinalD; // Vector from center of box to v0 at end of move - - const AABoxClass * Box; - const TriClass * Tri; - const Vector3 * BoxMove; - const Vector3 * TriMove; - -private: - - // not implemented - BTCollisionStruct(const BTCollisionStruct &); - BTCollisionStruct & operator = (const BTCollisionStruct &); -}; - -static BTCollisionStruct CollisionContext; - -/*********************************************************************************************** - * aabtri_separation_test -- test the projected extents for separation * - * * - * Once the extents are projected onto the axis, this function contains * - * the logic that determines the allowed fraction. * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 4/8/99 GTH : Created. * - * 7/12/99 GTH : Converted original OBBox code to AABox * - *=============================================================================================*/ -static inline bool aabtri_separation_test -( - float lp,float leb0,float leb1 -) -{ - /* - ** - If (I'm no more than 'EPSILON' embedded in the wall) - ** - not startbad - ** - If (I'm moving towards) - ** - fraction = How far I can move before embedding (can be negative if started embedded) - ** - If (I can take entire move) - ** - accept entire move - ** - Else If (I can move more than I could have before; *negative always fails!) - ** - update fraction - ** - Else - ** - Accept entire move since I'm not moving towards - */ - float eps = 0.0f; - if (lp - leb0 <= 0.0f) { - eps = COLLISION_EPSILON * CollisionContext.TestAxis.Length(); // trying to only compute epsilon if I have to - } - - if (lp - leb0 > -eps) { - CollisionContext.StartBad = false; - if (leb1 - leb0 > 0.0f) { - float frac = (lp-leb0)/(leb1-leb0); - if (frac >= 1.0f) { - /* moving toward but not hitting triangle */ - CollisionContext.AxisId = CollisionContext.TestAxisId; - CollisionContext.MaxFrac = 1.0f; - return true; - } else { - /* moving toward, hitting triangle */ - if (frac > CollisionContext.MaxFrac) { - CollisionContext.MaxFrac = frac; - CollisionContext.AxisId = CollisionContext.TestAxisId; - CollisionContext.Side = CollisionContext.TestSide; - CollisionContext.Point = CollisionContext.TestPoint; - } - } - } else { - /* moving away or not moving */ - CollisionContext.AxisId = CollisionContext.TestAxisId; - CollisionContext.MaxFrac = 1.0f; - return true; - } - } - return false; -} - - -/*********************************************************************************************** - * aabtri_check_axis -- project the aab and tri onto an arbitrary axis * - * * - * projects the box and the triangle onto the given axis and calls * - * obbtri_separation_test. return true if separation was detected * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 4/8/99 GTH : Created. * - * 7/12/99 GTH : converted to AABox * - *=============================================================================================*/ -static inline bool aabtri_check_axis(void) -{ - float dist; // separation along the axis - float axismove; // size of the move along the axis. - float leb0; // initial coordinate of the leading edge of the box - float leb1; // final coordinate of the leading edge of the box - float lp; // leading edge of the polygon. - float tmp; // temporary - - dist = Vector3::Dot_Product(CollisionContext.D,CollisionContext.TestAxis); - axismove = Vector3::Dot_Product(CollisionContext.Move,CollisionContext.TestAxis); - - // I want the axis centered at the box, pointing towards the triangle - if (dist < 0) { - dist = -dist; - axismove = -axismove; - CollisionContext.TestAxis = -CollisionContext.TestAxis; - CollisionContext.TestSide = -1.0f; - } else { - CollisionContext.TestSide = 1.0f; - } - - // compute coordinates of the leading edge of the box at t0 and t1 - leb0 = CollisionContext.Box->Extent.X * WWMath::Fabs(CollisionContext.TestAxis.X) + - CollisionContext.Box->Extent.Y * WWMath::Fabs(CollisionContext.TestAxis.Y) + - CollisionContext.Box->Extent.Z * WWMath::Fabs(CollisionContext.TestAxis.Z); - leb1 = leb0 + axismove; - - // compute coordinate of "leading edge of the triangle" relative to the box center. - lp = 0; - tmp = Vector3::Dot_Product(CollisionContext.E[0],CollisionContext.TestAxis); if (tmp < lp) lp = tmp; - tmp = Vector3::Dot_Product(CollisionContext.E[1],CollisionContext.TestAxis); if (tmp < lp) lp = tmp; - lp = dist + lp; - - return aabtri_separation_test(/*CollisionContext,*/lp,leb0,leb1); -} - - -/*********************************************************************************************** - * aabtri_check_cross_axis -- projects aab and tri onto a "cross" axis * - * * - * Assumes that the axis given is one generated from a cross product of one of the edge and * - * basis vectors. In this case, the box extent can be optimized and only two triangle verts * - * need to be checked. * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 4/8/99 GTH : Created. * - *=============================================================================================*/ -static inline bool aabtri_check_cross_axis -( - float dp, - int dpi, - float leb0 -) -{ - float p0; // distance from box center to vertex 0 - float axismove; // size of the move along the axis. - float leb1; // final coordinate of the leading edge of the box - float lp; // leading edge of the polygon. - - p0 = Vector3::Dot_Product(CollisionContext.D,CollisionContext.TestAxis); - axismove = Vector3::Dot_Product(CollisionContext.Move,CollisionContext.TestAxis); - - // I want the axis centered at the box, pointing towards the triangle - if (p0 < 0) { - p0 = -p0; - axismove = -axismove; - dp = -dp; - CollisionContext.TestAxis = -CollisionContext.TestAxis; - CollisionContext.TestSide = -1.0f; - } else { - CollisionContext.TestSide = 1.0f; - } - - // compute coordinates of the leading edge of the box at t1 - leb1 = leb0 + axismove; - - // compute coordinate of "leading edge of the triangle" relative to the box center. - lp = 0; CollisionContext.TestPoint = 0; - if (dp < 0) { lp = dp; CollisionContext.TestPoint = dpi; } - lp = p0 + lp; - - return aabtri_separation_test(/*CollisionContext,*/lp,leb0,leb1); -} - - -/*********************************************************************************************** - * aabtri_check_basis_axis -- projects the aab and tri onto a basis axis * - * * - * Projects the box and triangle onto an axis that is assumed to be a basis * - * vector from the box. In this case, we can skip a dot-product and use the * - * corresponding extent of the box (which is passed in as leb0). * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 4/8/99 GTH : Created. * - *=============================================================================================*/ -static inline bool aabtri_check_basis_axis -( - float leb0, - float dp1, - float dp2 -) -{ - float dist; // separation along the axis - float axismove; // size of the move along the axis. - float leb1; // final coordinate of the leading edge of the box - float lp; // leading edge of the polygon. - - dist = Vector3::Dot_Product(CollisionContext.D,CollisionContext.TestAxis); - axismove = Vector3::Dot_Product(CollisionContext.Move,CollisionContext.TestAxis); - - // we want the axis centered at the box, pointing towards the triangle - if (dist < 0) { - dist = -dist; - axismove = -axismove; - dp1 = -dp1; - dp2 = -dp2; - CollisionContext.TestAxis = -CollisionContext.TestAxis; - CollisionContext.TestSide = -1.0f; - } else { - CollisionContext.TestSide = 1.0f; - } - - // this is the "optimization", leb0 = one of the extents - leb1 = leb0 + axismove; - - // compute coordinate of "leading edge of the polygon" relative to the box center. - lp = 0; CollisionContext.TestPoint = 0; - if (dp1 < lp) { lp = dp1; CollisionContext.TestPoint = 1; } - if (dp2 < lp) { lp = dp2; CollisionContext.TestPoint = 2; } - lp = dist + lp; - - return aabtri_separation_test(/*CollisionContext,*/lp,leb0,leb1); -} - - -/*********************************************************************************************** - * aabtri_check_normal_axis -- project the box and tri onto the tri-normal * - * * - * Projects the box and triangle onto an axis that is assumed to be the normal * - * vector from the triangle. In this case, the triangle extents are zero. * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 4/8/99 GTH : Created. * - *=============================================================================================*/ -static inline bool aabtri_check_normal_axis(void) -{ - float dist; // separation along the axis - float axismove; // size of the move along the axis. - float leb0; // initial coordinate of the leading edge of the box - float leb1; // final coordinate of the leading edge of the box - float lp; // leading edge of the polygon. - - dist = Vector3::Dot_Product(CollisionContext.D,CollisionContext.TestAxis); - axismove = Vector3::Dot_Product(CollisionContext.Move,CollisionContext.TestAxis); - - // we want the axis centered at the box, pointing towards the triangle - if (dist < 0) { - dist = -dist; - axismove = -axismove; - CollisionContext.TestAxis = -CollisionContext.TestAxis; - CollisionContext.TestSide = -1.0f; - } else { - CollisionContext.TestSide = 1.0f; - } - - leb0 = CollisionContext.Box->Extent.X * WWMath::Fabs(CollisionContext.AN[0]) + - CollisionContext.Box->Extent.Y * WWMath::Fabs(CollisionContext.AN[1]) + - CollisionContext.Box->Extent.Z * WWMath::Fabs(CollisionContext.AN[2]); - leb1 = leb0 + axismove; - CollisionContext.TestPoint = 0; - lp = dist; // this is the "optimization", don't have to find lp - - return aabtri_separation_test(/*CollisionContext,*/lp,leb0,leb1); -} - -/*********************************************************************************************** - * eval_side -- returns -1,0,+1 depending on the sign of val and side * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 4/8/99 GTH : Created. * - *=============================================================================================*/ -static inline float eval_side(float val,int side) -{ - if (val > 0.0f) { - return side; - } else if (val < 0.0f) { - return -side; - } else { - return 0.0f; - } -} - -/*********************************************************************************************** - * aabtri_compute_contact_normal -- computes the normal of the collision * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 4/8/99 GTH : Created. * - *=============================================================================================*/ -static inline void aabtri_compute_contact_normal -( - Vector3 & set_norm -) -{ -#if 1 - switch(CollisionContext.AxisId) - { - case INTERSECTION: - set_norm = *CollisionContext.Tri->N; - break; - case AXIS_N: - set_norm = -CollisionContext.Side * *CollisionContext.Tri->N; - set_norm.Normalize(); - break; - case AXIS_A0: - set_norm = -CollisionContext.Side * Vector3(1.0f,0.0f,0.0f); - break; - case AXIS_A1: - set_norm = -CollisionContext.Side * Vector3(0.0f,1.0f,0.0f); - break; - case AXIS_A2: - set_norm = -CollisionContext.Side * Vector3(0.0f,0.0f,1.0f); - break; - case AXIS_A0E0: - set_norm = -CollisionContext.Side * CollisionContext.AxE[0][0]; - set_norm.Normalize(); - break; - case AXIS_A1E0: - set_norm = -CollisionContext.Side * CollisionContext.AxE[1][0]; - set_norm.Normalize(); - break; - case AXIS_A2E0: - set_norm = -CollisionContext.Side * CollisionContext.AxE[2][0]; - set_norm.Normalize(); - break; - case AXIS_A0E1: - set_norm = -CollisionContext.Side * CollisionContext.AxE[0][1]; - set_norm.Normalize(); - break; - case AXIS_A1E1: - set_norm = -CollisionContext.Side * CollisionContext.AxE[1][1]; - set_norm.Normalize(); - break; - case AXIS_A2E1: - set_norm = -CollisionContext.Side * CollisionContext.AxE[2][1]; - set_norm.Normalize(); - break; - case AXIS_A0E2: - set_norm = -CollisionContext.Side * CollisionContext.AxE[0][2]; - set_norm.Normalize(); - break; - case AXIS_A1E2: - set_norm = -CollisionContext.Side * CollisionContext.AxE[1][2]; - set_norm.Normalize(); - break; - case AXIS_A2E2: - set_norm = -CollisionContext.Side * CollisionContext.AxE[2][2]; - set_norm.Normalize(); - break; - } - - WWASSERT(set_norm.Length2() > 0.0f); - -#else - set_norm = *CollisionContext.Tri.N; - if (Vector3::Dot_Product(set_norm,CollisionContext.Move) > 0.0f) { - set_norm = -(set_norm); - } -#endif -} - -inline void VERIFY_CROSS(const Vector3 & a, const Vector3 & b,const Vector3 & cross) -{ -#ifdef WWDEBUG - Vector3 tmp_cross; - Vector3::Cross_Product(a,b,&tmp_cross); - Vector3 diff = cross - tmp_cross; - WWASSERT(WWMath::Fabs(diff.Length()) < 0.0001f); -#endif -} - -/*********************************************************************************************** - * CollisionMath::Collide -- collide an aabox into a triangle * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 4/8/99 GTH : Created. * - *=============================================================================================*/ -bool CollisionMath::Collide -( - const AABoxClass & box, - const Vector3 & move, - const TriClass & tri, - CastResultStruct * result -) -{ - TRACK_COLLISION_AABOX_TRI; - - float dp,leb0; - - CollisionContext.Init(box,move,tri,Vector3(0,0,0)); - - /* - ** AXIS_N - */ - CollisionContext.TestAxis = CollisionContext.N; - CollisionContext.TestAxisId = AXIS_N; - CollisionContext.AN[0] = CollisionContext.N.X; - CollisionContext.AN[1] = CollisionContext.N.Y; - CollisionContext.AN[2] = CollisionContext.N.Z; - if (aabtri_check_normal_axis()) goto exit; - - /* - ** AXIS_A0 - */ - CollisionContext.TestAxis.Set(1,0,0); - CollisionContext.TestAxisId = AXIS_A0; - CollisionContext.AE[0][0] = CollisionContext.E[0].X; - CollisionContext.AE[0][1] = CollisionContext.E[1].X; - if (aabtri_check_basis_axis(box.Extent.X,CollisionContext.AE[0][0],CollisionContext.AE[0][1])) goto exit; - - /* - ** AXIS_A1 - */ - CollisionContext.TestAxis.Set(0,1,0); - CollisionContext.TestAxisId = AXIS_A1; - CollisionContext.AE[1][0] = CollisionContext.E[0].Y; - CollisionContext.AE[1][1] = CollisionContext.E[1].Y; - if (aabtri_check_basis_axis(box.Extent.Y,CollisionContext.AE[1][0],CollisionContext.AE[1][1])) goto exit; - - /* - ** AXIS_A2 - */ - CollisionContext.TestAxis.Set(0,0,1); - CollisionContext.TestAxisId = AXIS_A2; - CollisionContext.AE[2][0] = CollisionContext.E[0].Z; - CollisionContext.AE[2][1] = CollisionContext.E[1].Z; - if (aabtri_check_basis_axis(box.Extent.Z,CollisionContext.AE[2][0],CollisionContext.AE[2][1])) goto exit; - - /* - ** AXIS_A0xE0 - */ - CollisionContext.AxE[0][0].Set(0,-CollisionContext.E[0].Z,CollisionContext.E[0].Y); - VERIFY_CROSS(Vector3(1,0,0),CollisionContext.E[0],CollisionContext.AxE[0][0]); - CollisionContext.TestAxis = CollisionContext.AxE[0][0]; - CollisionContext.TestAxisId = AXIS_A0E0; - if (CollisionContext.TestAxis.Length2() > AXISLEN_EPSILON2) { - dp = CollisionContext.AN[0]; - leb0 = box.Extent[1]*WWMath::Fabs(CollisionContext.AE[2][0]) + box.Extent[2]*WWMath::Fabs(CollisionContext.AE[1][0]); - if (aabtri_check_cross_axis(dp,2,leb0)) goto exit; - } - - /* - ** AXIS_A0xE1 - */ - CollisionContext.AxE[0][1].Set(0,-CollisionContext.E[1].Z,CollisionContext.E[1].Y); - VERIFY_CROSS(Vector3(1,0,0),CollisionContext.E[1],CollisionContext.AxE[0][1]); - CollisionContext.TestAxis = CollisionContext.AxE[0][1]; - CollisionContext.TestAxisId = AXIS_A0E1; - if (CollisionContext.TestAxis.Length2() > AXISLEN_EPSILON2) { - dp = -CollisionContext.AN[0]; - leb0 = box.Extent[1]*WWMath::Fabs(CollisionContext.AE[2][1]) + box.Extent[2]*WWMath::Fabs(CollisionContext.AE[1][1]); - if (aabtri_check_cross_axis(dp,1,leb0)) goto exit; - } - - /* - ** AXIS_A0xE2 - */ - CollisionContext.AE[0][2] = CollisionContext.E[2].X; - CollisionContext.AE[1][2] = CollisionContext.E[2].Y; - CollisionContext.AE[2][2] = CollisionContext.E[2].Z; - - CollisionContext.AxE[0][2].Set(0,-CollisionContext.E[2].Z,CollisionContext.E[2].Y); - VERIFY_CROSS(Vector3(1,0,0),CollisionContext.E[2],CollisionContext.AxE[0][2]); - CollisionContext.TestAxis = CollisionContext.AxE[0][2]; - CollisionContext.TestAxisId = AXIS_A0E2; - - if (CollisionContext.TestAxis.Length2() > AXISLEN_EPSILON2) { - dp = -CollisionContext.AN[0]; - leb0 = box.Extent[1]*WWMath::Fabs(CollisionContext.AE[2][2]) + box.Extent[2]*WWMath::Fabs(CollisionContext.AE[1][2]); - if (aabtri_check_cross_axis(dp,1,leb0)) goto exit; - } - - /* - ** AXIS_A1xE0 - */ - CollisionContext.AxE[1][0].Set(CollisionContext.E[0].Z,0,-CollisionContext.E[0].X); - VERIFY_CROSS(Vector3(0,1,0),CollisionContext.E[0],CollisionContext.AxE[1][0]); - CollisionContext.TestAxis = CollisionContext.AxE[1][0]; - CollisionContext.TestAxisId = AXIS_A1E0; - if (CollisionContext.TestAxis.Length2() > AXISLEN_EPSILON2) { - dp = CollisionContext.AN[1]; - leb0 = box.Extent[0]*WWMath::Fabs(CollisionContext.AE[2][0]) + box.Extent[2]*WWMath::Fabs(CollisionContext.AE[0][0]); - if (aabtri_check_cross_axis(dp,2,leb0)) goto exit; - } - - /* - ** AXIS_A1xE1 - */ - CollisionContext.AxE[1][1].Set(CollisionContext.E[1].Z,0,-CollisionContext.E[1].X); - VERIFY_CROSS(Vector3(0,1,0),CollisionContext.E[1],CollisionContext.AxE[1][1]); - CollisionContext.TestAxis = CollisionContext.AxE[1][1]; - CollisionContext.TestAxisId = AXIS_A1E1; - if (CollisionContext.TestAxis.Length2() > AXISLEN_EPSILON2) { - dp = -CollisionContext.AN[1]; - leb0 = box.Extent[0]*WWMath::Fabs(CollisionContext.AE[2][1]) + box.Extent[2]*WWMath::Fabs(CollisionContext.AE[0][1]); - if (aabtri_check_cross_axis(dp,1,leb0)) goto exit; - } - - /* - ** AXIS_A1xE2 - */ - CollisionContext.AxE[1][2].Set(CollisionContext.E[2].Z,0,-CollisionContext.E[2].X); - VERIFY_CROSS(Vector3(0,1,0),CollisionContext.E[2],CollisionContext.AxE[1][2]); - CollisionContext.TestAxis = CollisionContext.AxE[1][2]; - CollisionContext.TestAxisId = AXIS_A1E2; - if (CollisionContext.TestAxis.Length2() > AXISLEN_EPSILON2) { - dp = -CollisionContext.AN[1]; - leb0 = box.Extent[0]*WWMath::Fabs(CollisionContext.AE[2][2]) + box.Extent[2]*WWMath::Fabs(CollisionContext.AE[0][2]); - if (aabtri_check_cross_axis(dp,1,leb0)) goto exit; - } - - /* - ** AXIS_A2xE0 - */ - CollisionContext.AxE[2][0].Set(-CollisionContext.E[0].Y,CollisionContext.E[0].X,0); - VERIFY_CROSS(Vector3(0,0,1),CollisionContext.E[0],CollisionContext.AxE[2][0]); - CollisionContext.TestAxis = CollisionContext.AxE[2][0]; - CollisionContext.TestAxisId = AXIS_A2E0; - if (CollisionContext.TestAxis.Length2() > AXISLEN_EPSILON2) { - dp = CollisionContext.AN[2]; - leb0 = box.Extent[0]*WWMath::Fabs(CollisionContext.AE[1][0]) + box.Extent[1]*WWMath::Fabs(CollisionContext.AE[0][0]); - if (aabtri_check_cross_axis(dp,2,leb0)) goto exit; - } - - /* - ** AXIS_A2xE1 - */ - CollisionContext.AxE[2][1].Set(-CollisionContext.E[1].Y,CollisionContext.E[1].X,0); - VERIFY_CROSS(Vector3(0,0,1),CollisionContext.E[1],CollisionContext.AxE[2][1]); - CollisionContext.TestAxis = CollisionContext.AxE[2][1]; - CollisionContext.TestAxisId = AXIS_A2E1; - if (CollisionContext.TestAxis.Length2() > AXISLEN_EPSILON2) { - dp = -CollisionContext.AN[2]; - leb0 = box.Extent[0]*WWMath::Fabs(CollisionContext.AE[1][1]) + box.Extent[1]*WWMath::Fabs(CollisionContext.AE[0][1]); - if (aabtri_check_cross_axis(dp,1,leb0)) goto exit; - } - - /* - ** AXIS_A2xE2 - */ - CollisionContext.AxE[2][2].Set(-CollisionContext.E[2].Y,CollisionContext.E[2].X,0); - VERIFY_CROSS(Vector3(0,0,1),CollisionContext.E[2],CollisionContext.AxE[2][2]); - CollisionContext.TestAxis = CollisionContext.AxE[2][2]; - CollisionContext.TestAxisId = AXIS_A2E2; - if (CollisionContext.TestAxis.Length2() > AXISLEN_EPSILON2) { - dp = -CollisionContext.AN[2]; - leb0 = box.Extent[0]*WWMath::Fabs(CollisionContext.AE[1][2]) + box.Extent[1]*WWMath::Fabs(CollisionContext.AE[0][2]); - if (aabtri_check_cross_axis(dp,1,leb0)) goto exit; - } - - /* - ** Last ditch effort, check an axis based on the move vector - */ - if (!CollisionContext.StartBad) { - CollisionContext.TestPoint = CollisionContext.Point; - CollisionContext.TestAxisId = CollisionContext.AxisId; - - CollisionContext.TestAxis.Set(0,-CollisionContext.Move.Z,CollisionContext.Move.Y); // A0 X Move - VERIFY_CROSS(Vector3(1,0,0),CollisionContext.Move,CollisionContext.TestAxis); - if (CollisionContext.TestAxis.Length2() > AXISLEN_EPSILON2) { - if (aabtri_check_axis()) goto exit; - } - CollisionContext.TestAxis.Set(CollisionContext.Move.Z,0,-CollisionContext.Move.X); // A1 X Move - VERIFY_CROSS(Vector3(0,1,0),CollisionContext.Move,CollisionContext.TestAxis); - if (CollisionContext.TestAxis.Length2() > AXISLEN_EPSILON2) { - if (aabtri_check_axis()) goto exit; - } - CollisionContext.TestAxis.Set(-CollisionContext.Move.Y,CollisionContext.Move.X,0); // A2 X Move - VERIFY_CROSS(Vector3(0,0,1),CollisionContext.Move,CollisionContext.TestAxis); - if (CollisionContext.TestAxis.Length2() > AXISLEN_EPSILON2) { - if (aabtri_check_axis()) goto exit; - } - } - -exit: - - /* - ** If MaxFrac is less than zero, clamp it to zero. Negative fractions can - ** leak through this routine due to the epsilon in the separation test. - */ - if (CollisionContext.MaxFrac < 0.0f) { - CollisionContext.MaxFrac = 0.0f; - } - - /* - ** If the triangle and box are intersecting before the move, return that - ** result. - */ - if (CollisionContext.StartBad) { - result->StartBad = true; - result->Fraction = 0.0f; - result->Normal = *tri.N; - TRACK_COLLISION_AABOX_TRI_HIT; - return true; - } - - /* - ** If the fraction allowed is basically equal to the fraction allowed by - ** another polygon, try to pick the polygon which is least "edge-on" to the - ** move. - */ - if ((CollisionContext.MaxFrac <= result->Fraction) && (CollisionContext.MaxFrac < 1.0f)) { - - /* - ** Reflect the normal if it is pointing the same way as our move - ** (probably hitting the back side of a polygon) - */ - Vector3 tmp_norm(0.0f,0.0f,0.0f); - aabtri_compute_contact_normal(tmp_norm); -// if (Vector3::Dot_Product(tmp_norm,move) > 0.0f) { -// tmp_norm = -tmp_norm; -// } - - /* - ** If this polygon cuts off more of the move -OR- this polygon cuts - ** of the same amount but has a "better" normal, then use this normal - */ - if ( (WWMath::Fabs(CollisionContext.MaxFrac - result->Fraction) > WWMATH_EPSILON) || - (Vector3::Dot_Product(tmp_norm,move) < Vector3::Dot_Product(result->Normal,move))) - { - result->Normal = tmp_norm; -#pragma message("fatal assert disabled for demo") - //WWASSERT(WWMath::Fabs(result->Normal.Length() - 1.0f) < WWMATH_EPSILON); - } - - result->Fraction = CollisionContext.MaxFrac; - - TRACK_COLLISION_AABOX_TRI_HIT; - return true; - } - - return false; -} - - - -/* -** AABTIntersectStruct -** Scratchpad variables for the AABox-Triangle intersection functions. One instance -** of this structure will be used for all of the local variables and its pointer will be -** handed of to various inline functions for the axis tests. -** Note that much of the code needs the un-normalized triangle normal. For this reason, -** I have to compute N rather than copying it from the triangle. (commenting this to -** avoid re-generating a difficult to find bug that I had) -*/ -struct AABTIntersectStruct -{ - AABTIntersectStruct(void) : - Box(NULL), - Tri(NULL) - { - } - - void Init(const AABoxClass &box,const TriClass &tri) - { - Box = &box; - Tri = &tri; - Vector3::Subtract(*tri.V[0],box.Center,&D); // vector from center of box to vertex 0 - Vector3::Subtract(*tri.V[1],*tri.V[0],&E[0]); - Vector3::Subtract(*tri.V[2],*tri.V[0],&E[1]); - Vector3::Subtract(E[1],E[0],&E[2]); - - Vector3::Cross_Product(E[0],E[1],&N); - } - - - Vector3 D; // Vector from the center of the box to v0 - float AE[3][3]; // Dot products of the Basis vectors and edges - float AN[3]; // Dot products of the Basis vectors and the normal - Vector3 AxE[3][3]; // Cross produts of the Basis vectors and edges - - Vector3 E[3]; // edge vectors for the triangle - Vector3 N; // normal (NOT normalized!!!) - - const AABoxClass * Box; - const TriClass * Tri; - -private: - - // not implemented - AABTIntersectStruct(const AABTIntersectStruct &); - AABTIntersectStruct & operator = (const AABTIntersectStruct &); -}; - -static AABTIntersectStruct IntersectContext; - - -/*********************************************************************************************** - * aabtri_intersect_cross_axis -- intersection check for a "cross-product" axis * - * * - * axis being checked is a cross product between a triangle edge and a box basis vector * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 5/4/99 GTH : Created. * - *=============================================================================================*/ -static inline bool aabtri_intersect_cross_axis -( - Vector3 & axis, - float dp, - float leb0 -) -{ - float p0; // distance from box center to vertex 0 - float lp; // leading edge of the polygon. - - p0 = Vector3::Dot_Product(IntersectContext.D,axis); - - // I want the axis centered at the box, pointing towards the triangle - if (p0 < 0) { - p0 = -p0; - axis = -axis; - dp = -dp; - } - - // compute coordinate of "leading edge of the triangle" relative to the box center. - lp = 0; - if (dp < 0) { lp = dp; } - lp = p0 + lp; - - return (lp - leb0 > -WWMATH_EPSILON); -} - - -/*********************************************************************************************** - * aabtri_intersect_basis_axis -- intersection check for a basis axis * - * * - * axis being checked is one of the basis vectors for the box * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 5/4/99 GTH : Created. * - *=============================================================================================*/ -static inline bool aabtri_intersect_basis_axis -( - Vector3 & axis, - float leb0, - float dp1, - float dp2 -) -{ - float dist; // separation along the axis - float lp; // leading edge of the polygon. - - dist = Vector3::Dot_Product(IntersectContext.D,axis); - - // we want the axis centered at the box, pointing towards the triangle - if (dist < 0) { - dist = -dist; - axis = -axis; - dp1 = -dp1; - dp2 = -dp2; - } - - // compute coordinate of "leading edge of the polygon" relative to the box center. - lp = 0; - if (dp1 < lp) { lp = dp1; } - if (dp2 < lp) { lp = dp2; } - lp = dist + lp; - - return (lp - leb0 > -WWMATH_EPSILON); -} - - -/*********************************************************************************************** - * aabtri_intersect_normal_axis -- intersection check for the triangle normal * - * * - * axis being checked is the triangle's normal * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 5/4/99 GTH : Created. * - *=============================================================================================*/ -static inline bool aabtri_intersect_normal_axis -( - Vector3 & axis -) -{ - float dist; // separation along the axis - float leb0; // initial coordinate of the leading edge of the box - float lp; // leading edge of the polygon. - - dist = Vector3::Dot_Product(IntersectContext.D,axis); - - // we want the axis centered at the box, pointing towards the triangle - if (dist < 0) { - dist = -dist; - axis = -axis; - } - - leb0 = IntersectContext.Box->Extent.X * WWMath::Fabs(IntersectContext.AN[0]) + - IntersectContext.Box->Extent.Y * WWMath::Fabs(IntersectContext.AN[1]) + - IntersectContext.Box->Extent.Z * WWMath::Fabs(IntersectContext.AN[2]); - lp = dist; // this is the "optimization", don't have to find lp - - return (lp - leb0 > -WWMATH_EPSILON); -} - - -/*********************************************************************************************** - * CollisionMath::Intersection_Test -- Intersection check for an AABox and a triangle * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 1/20/00 gth : copied from OBBox version and removed some Dot-products * - *=============================================================================================*/ -bool CollisionMath::Intersection_Test(const AABoxClass & box,const TriClass & tri) -{ - Vector3 axis; - float dp,leb0; - - IntersectContext.Init(box,tri); - - /* - ** AXIS_N - */ - axis = IntersectContext.N; - IntersectContext.AN[0] = IntersectContext.N.X; - IntersectContext.AN[1] = IntersectContext.N.Y; - IntersectContext.AN[2] = IntersectContext.N.Z; - if (aabtri_intersect_normal_axis(axis)) return false; - - /* - ** AXIS_A0 - */ - axis.Set(1,0,0); - IntersectContext.AE[0][0] = IntersectContext.E[0].X; - IntersectContext.AE[0][1] = IntersectContext.E[1].Y; - if (aabtri_intersect_basis_axis(axis,box.Extent.X,IntersectContext.AE[0][0],IntersectContext.AE[0][1])) return false; - - /* - ** AXIS_A1 - */ - axis.Set(0,1,0); - IntersectContext.AE[1][0] = IntersectContext.E[0].Y; - IntersectContext.AE[1][1] = IntersectContext.E[1].Y; - if (aabtri_intersect_basis_axis(axis,box.Extent.Y,IntersectContext.AE[1][0],IntersectContext.AE[1][1])) return false; - - /* - ** AXIS_A2 - */ - axis.Set(0,0,1); - IntersectContext.AE[2][0] = IntersectContext.E[0].Z; - IntersectContext.AE[2][1] = IntersectContext.E[1].Z; - if (aabtri_intersect_basis_axis(axis,box.Extent.Z,IntersectContext.AE[2][0],IntersectContext.AE[2][1])) return false; - - /* - ** AXIS_A0xE0 - */ - Vector3::Cross_Product(Vector3(1,0,0),IntersectContext.E[0],&IntersectContext.AxE[0][0]); - axis = IntersectContext.AxE[0][0]; - if (axis.Length2() > AXISLEN_EPSILON2) { - dp = IntersectContext.AN[0]; - leb0 = box.Extent[1]*WWMath::Fabs(IntersectContext.AE[2][0]) + box.Extent[2]*WWMath::Fabs(IntersectContext.AE[1][0]); - if (aabtri_intersect_cross_axis(axis,dp,leb0)) return false; - } - - /* - ** AXIS_A0xE1 - */ - Vector3::Cross_Product(Vector3(1,0,0),IntersectContext.E[1],&IntersectContext.AxE[0][1]); - axis = IntersectContext.AxE[0][1]; - if (axis.Length2() > AXISLEN_EPSILON2) { - dp = -IntersectContext.AN[0]; - leb0 = box.Extent[1]*WWMath::Fabs(IntersectContext.AE[2][1]) + box.Extent[2]*WWMath::Fabs(IntersectContext.AE[1][1]); - if (aabtri_intersect_cross_axis(axis,dp,leb0)) return false; - } - - /* - ** AXIS_A0xE2 - */ - Vector3::Cross_Product(Vector3(1,0,0),IntersectContext.E[2],&IntersectContext.AxE[0][2]); - axis = IntersectContext.AxE[0][2]; - IntersectContext.AE[1][2] = IntersectContext.E[2].Y; - IntersectContext.AE[2][2] = IntersectContext.E[2].Z; - if (axis.Length2() > AXISLEN_EPSILON2) { - dp = -IntersectContext.AN[0]; - leb0 = box.Extent[1]*WWMath::Fabs(IntersectContext.AE[2][2]) + box.Extent[2]*WWMath::Fabs(IntersectContext.AE[1][2]); - if (aabtri_intersect_cross_axis(axis,dp,leb0)) return false; - } - - /* - ** AXIS_A1xE0 - */ - Vector3::Cross_Product(Vector3(0,1,0),IntersectContext.E[0],&IntersectContext.AxE[1][0]); - axis = IntersectContext.AxE[1][0]; - if (axis.Length2() > AXISLEN_EPSILON2) { - dp = IntersectContext.AN[1]; - leb0 = box.Extent[0]*WWMath::Fabs(IntersectContext.AE[2][0]) + box.Extent[2]*WWMath::Fabs(IntersectContext.AE[0][0]); - if (aabtri_intersect_cross_axis(axis,dp,leb0)) return false; - } - - /* - ** AXIS_A1xE1 - */ - Vector3::Cross_Product(Vector3(0,1,0),IntersectContext.E[1],&IntersectContext.AxE[1][1]); - axis = IntersectContext.AxE[1][1]; - if (axis.Length2() > AXISLEN_EPSILON2) { - dp = -IntersectContext.AN[1]; - leb0 = box.Extent[0]*WWMath::Fabs(IntersectContext.AE[2][1]) + box.Extent[2]*WWMath::Fabs(IntersectContext.AE[0][1]); - if (aabtri_intersect_cross_axis(axis,dp,leb0)) return false; - } - - /* - ** AXIS_A1xE2 - */ - Vector3::Cross_Product(Vector3(0,1,0),IntersectContext.E[2],&IntersectContext.AxE[1][2]); - axis = IntersectContext.AxE[1][2]; - IntersectContext.AE[0][2] = IntersectContext.E[2].X; - if (axis.Length2() > AXISLEN_EPSILON2) { - dp = -IntersectContext.AN[1]; - leb0 = box.Extent[0]*WWMath::Fabs(IntersectContext.AE[2][2]) + box.Extent[2]*WWMath::Fabs(IntersectContext.AE[0][2]); - if (aabtri_intersect_cross_axis(axis,dp,leb0)) return false; - } - - /* - ** AXIS_A2xE0 - */ - Vector3::Cross_Product(Vector3(0,0,1),IntersectContext.E[0],&IntersectContext.AxE[2][0]); - axis = IntersectContext.AxE[2][0]; - if (axis.Length2() > AXISLEN_EPSILON2) { - dp = IntersectContext.AN[2]; - leb0 = box.Extent[0]*WWMath::Fabs(IntersectContext.AE[1][0]) + box.Extent[1]*WWMath::Fabs(IntersectContext.AE[0][0]); - if (aabtri_intersect_cross_axis(axis,dp,leb0)) return false; - } - - /* - ** AXIS_A2xE1 - */ - Vector3::Cross_Product(Vector3(0,0,1),IntersectContext.E[1],&IntersectContext.AxE[2][1]); - axis = IntersectContext.AxE[2][1]; - if (axis.Length2() > AXISLEN_EPSILON2) { - dp = -IntersectContext.AN[2]; - leb0 = box.Extent[0]*WWMath::Fabs(IntersectContext.AE[1][1]) + box.Extent[1]*WWMath::Fabs(IntersectContext.AE[0][1]); - if (aabtri_intersect_cross_axis(axis,dp,leb0)) return false; - } - - /* - ** AXIS_A2xE2 - */ - Vector3::Cross_Product(Vector3(0,0,1),IntersectContext.E[2],&IntersectContext.AxE[2][2]); - axis = IntersectContext.AxE[2][2]; - if (axis.Length2() > AXISLEN_EPSILON2) { - dp = -IntersectContext.AN[2]; - leb0 = box.Extent[0]*WWMath::Fabs(IntersectContext.AE[1][2]) + box.Extent[1]*WWMath::Fabs(IntersectContext.AE[0][2]); - if (aabtri_intersect_cross_axis(axis,dp,leb0)) return false; - } - - return true; -} diff --git a/Generals/Code/Libraries/Source/WWVegas/WWMath/colmathfrustum.cpp b/Generals/Code/Libraries/Source/WWVegas/WWMath/colmathfrustum.cpp deleted file mode 100644 index bc4853578ea..00000000000 --- a/Generals/Code/Libraries/Source/WWVegas/WWMath/colmathfrustum.cpp +++ /dev/null @@ -1,190 +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 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 : WWMath * - * * - * $Archive:: /Commando/Code/wwmath/colmathfrustum.cpp $* - * * - * Author:: Greg Hjelstrom * - * * - * $Modtime:: 3/29/00 5:40p $* - * * - * $Revision:: 7 $* - * * - *---------------------------------------------------------------------------------------------* - * Functions: * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - - -#include "colmath.h" -#include "colmathinlines.h" -#include "aaplane.h" -#include "plane.h" -#include "lineseg.h" -#include "tri.h" -#include "sphere.h" -#include "aabox.h" -#include "obbox.h" -#include "frustum.h" -#include "wwdebug.h" - - -// TODO: Most of these overlap functions actually do not catch all cases of when -// the primitive is outside of the frustum... - - -// Frustum functions -CollisionMath::OverlapType -CollisionMath::Overlap_Test(const FrustumClass & frustum,const Vector3 & point) -{ - int mask = 0; - - for (int i = 0; i < 6; i++) { - int result = CollisionMath::Overlap_Test(frustum.Planes[i],point); - if (result == OUTSIDE) { - return OUTSIDE; - } - mask |= result; - } - - if (mask == INSIDE) { - return INSIDE; - } - return OVERLAPPED; -} - -CollisionMath::OverlapType -CollisionMath::Overlap_Test(const FrustumClass & frustum,const TriClass & tri) -{ - int mask = 0; - - // TODO: doesn't catch all cases... - for (int i = 0; i < 6; i++) { - int result = CollisionMath::Overlap_Test(frustum.Planes[i],tri); - if (result == OUTSIDE) { - return OUTSIDE; - } - mask |= result; - } - - if (mask == INSIDE) { - return INSIDE; - } - return OVERLAPPED; -} - -CollisionMath::OverlapType -CollisionMath::Overlap_Test(const FrustumClass & frustum,const SphereClass & sphere) -{ - int mask = 0; - - // TODO: doesn't catch all cases... - for (int i = 0; i < 6; i++) { - int result = CollisionMath::Overlap_Test(frustum.Planes[i],sphere); - if (result == OUTSIDE) { - return OUTSIDE; - } - mask |= result; - } - - if (mask == INSIDE) { - return INSIDE; - } - return OVERLAPPED; -} - -CollisionMath::OverlapType -CollisionMath::Overlap_Test(const FrustumClass & frustum,const AABoxClass & box) -{ - int mask = 0; - - // TODO: doesn't catch all cases... - for (int i = 0; i < 6; i++) { - int result = CollisionMath::Overlap_Test(frustum.Planes[i],box); - if (result == OUTSIDE) { - return OUTSIDE; - } - mask |= result; - } - - if (mask == INSIDE) { - return INSIDE; - } - return OVERLAPPED; -} - - -CollisionMath::OverlapType -CollisionMath::Overlap_Test(const FrustumClass & frustum,const OBBoxClass & box) -{ - int mask = 0; - - // TODO: doesn't catch all cases... - for (int i = 0; i < 6; i++) { - int result = CollisionMath::Overlap_Test(frustum.Planes[i],box); - if (result == OUTSIDE) { - return OUTSIDE; - } - mask |= result; - } - - if (mask == INSIDE) { - return INSIDE; - } - return OVERLAPPED; -} - - -CollisionMath::OverlapType -CollisionMath::Overlap_Test(const FrustumClass & frustum,const OBBoxClass & box,int & planes_passed) -{ - int mask = 0; - - // TODO: doesn't catch all cases... - for (int i = 0; i < 6; i++) { - - int plane_bit = (1<. -*/ - -/*********************************************************************************************** - *** 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 : WWMath * - * * - * $Archive:: /Commando/Code/wwmath/colmathfrustum.h $* - * * - * Original Author:: Greg Hjelstrom * - * * - * $Author:: Jani_p $* - * * - * $Modtime:: 5/04/01 8:25p $* - * * - * $Revision:: 3 $* - * * - *---------------------------------------------------------------------------------------------* - * Functions: * - * CollisionMath::Overlap_Test -- test a frustum and an AABox for overlap * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - -#if defined(_MSC_VER) -#pragma once -#endif - -#ifndef COLMATHFRUSTUM_H -#define COLMATHFRUSTUM_H - -#include "always.h" -#include "aabox.h" -#include "vector3.h" -#include "lineseg.h" -#include "frustum.h" - -/* -** Inline collision functions dealing with frustums -*/ - -/*********************************************************************************************** - * CollisionMath::Overlap_Test -- test a frustum and an AABox for overlap * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 3/29/2000 gth : Created. * - *=============================================================================================*/ -inline -CollisionMath::OverlapType -CollisionMath::Overlap_Test(const FrustumClass & frustum,const AABoxClass & box,int & planes_passed) -{ - int mask = 0; - - // TODO: doesn't catch all cases... - for (int i = 0; i < 6; i++) { - - int plane_bit = (1<. -*/ - -/*********************************************************************************************** - *** 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 : WWMath * - * * - * $Archive:: /Commando/Code/wwmath/colmathinlines.h $* - * * - * Original Author:: Greg Hjelstrom * - * * - * $Author:: Greg_h $* - * * - * $Modtime:: 3/29/00 5:36p $* - * * - * $Revision:: 2 $* - * * - *---------------------------------------------------------------------------------------------* - * Functions: * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - -#if defined(_MSC_VER) -#pragma once -#endif - -#ifndef COLMATHINLINES_H -#define COLMATHINLINES_H - -#include "colmathaabox.h" -#include "colmathfrustum.h" -#include "colmathline.h" -#include "colmathplane.h" - -#endif - - diff --git a/Generals/Code/Libraries/Source/WWVegas/WWMath/colmathline.cpp b/Generals/Code/Libraries/Source/WWVegas/WWMath/colmathline.cpp deleted file mode 100644 index 7f255ba487a..00000000000 --- a/Generals/Code/Libraries/Source/WWVegas/WWMath/colmathline.cpp +++ /dev/null @@ -1,484 +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 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 : WWMath * - * * - * $Archive:: /VSS_Sync/wwmath/colmathline.cpp $* - * * - * Author:: Greg Hjelstrom * - * * - * $Modtime:: 8/29/01 10:25p $* - * * - * $Revision:: 10 $* - * * - *---------------------------------------------------------------------------------------------* - * Functions: * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - - -#include "colmath.h" -#include "aaplane.h" -#include "plane.h" -#include "lineseg.h" -#include "tri.h" -#include "sphere.h" -#include "aabox.h" -#include "obbox.h" -#include "wwdebug.h" - - -/* -** Structure used in the line->box test. There was a lot of common code between the axis- -** aligned and oriented box tests so I package all of the truely relevant information into -** this struct and pass it into a function local to this module. In the case of oriented -** boxes, the ray must be transformed into the box's coordinate system prior to the call -** and the normal is calculated slightly differently. -*/ -struct BoxTestStruct -{ - Vector3 Min; - Vector3 Max; - Vector3 P0; - Vector3 DP; - float Fraction; - bool Inside; - int Axis; - int Side; -}; - -/* -** Enumeration which can be used to categorize a point with respect to the projection -** of a box onto an axis. The point will either be to the negative side of the span, in the -** span, or on the positive side of the span. -*/ -enum BoxSideType { - BOX_SIDE_NEGATIVE = 0, - BOX_SIDE_POSITIVE = 1, - BOX_SIDE_MIDDLE = 2 -}; - - -/* -** Table of normals for an axis aligned box. -** access like this: -** -** _box_normal[AXIS][SIDE] -** -** is 0,1,2 meaning x,y,z -** is BOX_SIDE_NEGATIVE or BOX_SIDE_POSITIVE -*/ -static Vector3 _box_normal[3][2] = -{ - // plane = 0 (x axis) - { - Vector3(-1,0,0), // Left - Vector3(1,0,0) // Right - }, - // plane = 1 (y axis) - { - Vector3(0,-1,0), - Vector3(0,1,0) - }, - // plane = 2 (z axis) - { - Vector3(0,0,-1), - Vector3(0,0,1) - } -}; - -/* -** Local function prototypes -*/ -inline bool Test_Aligned_Box(BoxTestStruct * test); - - -bool CollisionMath::Collide(const LineSegClass & line,const AAPlaneClass & plane,CastResultStruct * result) -{ - float num,den,t; - - den = line.Get_DP()[plane.Normal]; - - /* - ** Check if line is parallel to this plane - */ - if (den == 0.0f) { - return false; - } - - num = -(line.Get_P0()[plane.Normal] - plane.Dist); - t = num/den; - - /* - ** If t is not between 0 and 1, the line containing the segment intersects - ** the plane but the segment does not - */ - if ((t < 0.0f) || (t > 1.0f)) { - return false; - } - - /* - ** Ok, we hit the plane! - */ - if (t < result->Fraction) { - result->Fraction = t; - result->Normal.Set(0,0,0); - result->Normal[plane.Normal] = 1.0f; - return true; - } - return false; -} - - -bool CollisionMath::Collide(const LineSegClass & line,const PlaneClass & plane,CastResultStruct * result) -{ - float num,den,t; - den = Vector3::Dot_Product(plane.N,line.Get_DP()); - - /* - ** If the denominator is zero, the ray is parallel to the plane - */ - if (den == 0.0f) { - return false; - } - - num = -(Vector3::Dot_Product(plane.N,line.Get_P0()) - plane.D); - t = num/den; - - /* - ** If t is not between 0 and 1, the line containing the segment intersects - ** the plane but the segment does not - */ - if ((t < 0.0f) || (t > 1.0f)) { - return false; - } - - /* - ** Ok, we hit the plane! - */ - if (t < result->Fraction) { - result->Fraction = t; - result->Normal = plane.N; - - /* - ** if user is asking for the point, compute it. - */ - if (result->ComputeContactPoint) { - result->ContactPoint = line.Get_P0() + result->Fraction * line.Get_DP(); - } - return true; - } - return false; -} - -bool CollisionMath::Collide(const LineSegClass & line,const TriClass & tri,CastResultStruct * res) -{ - TRACK_COLLISION_RAY_TRI; - - /* - ** Compute intersection of the line with the plane of the polygon - */ - PlaneClass plane(*tri.N,*tri.V[0]); - Vector3 ipoint; - float num,den,t; - - den = Vector3::Dot_Product(plane.N,line.Get_DP()); - - /* - ** If the denominator is zero, the ray is parallel to the plane - */ - if (den == 0.0f) { - return false; - } - num = -(Vector3::Dot_Product(plane.N,line.Get_P0()) - plane.D); - t = num/den; - - /* - ** If t is not between 0 and 1, the line containing the segment intersects - ** the plane but the segment does not - */ - if ((t < 0.0f) || (t > 1.0f)) { - return false; - } - - ipoint = line.Get_P0() + t*line.Get_DP(); - - /* - ** Check if this point is inside the triangle - */ - if (!tri.Contains_Point(ipoint)) { - return false; - } - - /* - ** Ok, we hit the triangle, set the collision results - */ - if (t < res->Fraction) { - res->Fraction = t; - res->Normal = plane.N; - if (res->ComputeContactPoint) { - res->ContactPoint = line.Get_P0() + res->Fraction * line.Get_DP(); - } - TRACK_COLLISION_RAY_TRI_HIT; - return true; - } - return false; -} - -bool CollisionMath::Collide(const LineSegClass & line,const SphereClass & sphere,CastResultStruct * res) -{ - // this game from graphics gems 1, page 388 - // intersection of a ray with a sphere - Vector3 dc = sphere.Center - line.Get_P0(); - float clen = Vector3::Dot_Product((dc) , line.Get_Dir()); - float disc = (sphere.Radius * sphere.Radius) - (dc.Length2() - clen*clen); - if (disc < 0.0f) { - return false; - } else { - float d = WWMath::Sqrt(disc); - float frac = (clen - d) / line.Get_Length(); - if (frac<0.0f) - frac = (clen + d) / line.Get_Length(); - if (frac<0.0f) return false; - if (frac < res->Fraction) { - - res->Fraction = frac; - - Vector3 p = line.Get_P0() + (clen - d)*line.Get_Dir(); - Vector3 norm = p - sphere.Center; - norm /= sphere.Radius; - - res->Normal = norm; - if (res->ComputeContactPoint) { - res->ContactPoint = line.Get_P0() + res->Fraction * line.Get_DP(); - } - return true; - } - } - return false; -} - -bool CollisionMath::Collide(const LineSegClass & line,const AABoxClass & box,CastResultStruct * res) -{ - // set up the test struct - BoxTestStruct test; - test.Min = box.Center - box.Extent; - test.Max = box.Center + box.Extent; - test.P0 = line.Get_P0(); - test.DP = line.Get_DP(); - - // check ray against the box, exit if the ray totally missed the box, - if (!Test_Aligned_Box(&test)) { - return false; - } - - // if ray starts inside the box, note that fact and bail. - if (test.Inside) { - res->StartBad = true; - return true; - } - - // Now, if this intersection is before any current intersection - // that we've found, install our intersection - if (test.Fraction < res->Fraction) { - res->Fraction = test.Fraction; - assert(test.Side != BOX_SIDE_MIDDLE); - res->Normal = _box_normal[test.Axis][test.Side]; - if (res->ComputeContactPoint) { - res->ContactPoint = line.Get_P0() + res->Fraction * line.Get_DP(); - } - return true; - } - return false; -} - -bool CollisionMath::Collide(const LineSegClass & line,const OBBoxClass & box,CastResultStruct * result) -{ - // set up the test struct - BoxTestStruct test; - test.Min = box.Center - box.Extent; - test.Max = box.Center + box.Extent; - - test.P0 = (box.Basis.Transpose() * (line.Get_P0() - box.Center)) + box.Center; - test.DP = box.Basis.Transpose() * line.Get_DP(); - - // check ray against the box, exit if the ray totally missed the box, - if (!Test_Aligned_Box(&test)) { - return false; - } - - // if ray starts inside the box, don't collide - if (test.Inside) { - result->StartBad = true; - return true; - } - - // Now, if this intersection is before any current intersection - // that we've found, install our intersection - if (test.Fraction < result->Fraction) { - result->Fraction = test.Fraction; - assert(test.Side != BOX_SIDE_MIDDLE); - - switch (test.Axis) { - case 0: - result->Normal.Set(box.Basis[0][0],box.Basis[1][0],box.Basis[2][0]); - break; - - case 1: - result->Normal.Set(box.Basis[0][1],box.Basis[1][1],box.Basis[2][1]); - break; - - case 2: - result->Normal.Set(box.Basis[0][2],box.Basis[1][2],box.Basis[2][2]); - break; - } - - if (test.Side == BOX_SIDE_NEGATIVE) { - result->Normal = -result->Normal; - } - if (result->ComputeContactPoint) { - result->ContactPoint = line.Get_P0() + result->Fraction * line.Get_DP(); - } - return true; - } - return false; -} - - - -/*********************************************************************************************** - * Test_Aligned_Box -- used as the guts of the Box intersection tests * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 4/20/98 GTH : Created. * - *=============================================================================================*/ -inline bool Test_Aligned_Box(BoxTestStruct * test) -{ - int i; - - // candidate intersection plane distance for each axis - float candidateplane[3]; - - // t value along the ray for each axis - float maxt[3]; - - // intersection point - Vector3 coord; - - // which "side" of the box for each axis - int quadrant[3]; - bool inside = true; - - for (i=0; i<3; i++) { - if (test->P0[i] < test->Min[i]) { - quadrant[i] = BOX_SIDE_NEGATIVE; - candidateplane[i] = test->Min[i]; - inside = false; - } else if (test->P0[i] > test->Max[i]) { - quadrant[i] = BOX_SIDE_POSITIVE; - candidateplane[i] = test->Max[i]; - inside = false; - } else { - quadrant[i] = BOX_SIDE_MIDDLE; - } - } - - /* - ** Ray started out inside the box... - */ - if (inside) { - test->Fraction = 0.0f; - test->Inside = true; - return true; - } - - /* - ** Calculate the 3 distances to the candidate planes - */ - for (i=0; i<3; i++) { - if (quadrant[i] != BOX_SIDE_MIDDLE && test->DP[i] != 0.0f) { - maxt[i] = (candidateplane[i] - test->P0[i]) / test->DP[i]; - } else { - maxt[i] = -1.0f; - } - } - - /* - ** Get the largest of the maxt's for the final choice of intersection - */ - int intersection_plane = 0; - - for (i=1; i<3; i++) { - if (maxt[i] > maxt[intersection_plane]) { - intersection_plane = i; - } - } - - /* - ** If the ray is "in front" of all of the planes, return - */ - if (maxt[intersection_plane] < 0.0f) { - return false; - } - - /* - ** Check if the ray is inside the box, i.e. on the two planes which - ** are not the intersection planes, the intersection point should - ** be between the min and max of the box. - */ - for (i=0; i<3; i++) { - - if (intersection_plane != i) { - - coord[i] = test->P0[i] + maxt[intersection_plane] * test->DP[i]; - - if ((coord[i] < test->Min[i]) || (coord[i] > test->Max[i])) { - - return false; // ray is outside the box - - } - - } else { - - coord[i] = candidateplane[i]; - - } - } - - /* - ** Fill in the intersection values - */ - test->Fraction = maxt[intersection_plane]; - test->Inside = false; - test->Axis = intersection_plane; - test->Side = quadrant[intersection_plane]; - return true; -} - - - - diff --git a/Generals/Code/Libraries/Source/WWVegas/WWMath/colmathline.h b/Generals/Code/Libraries/Source/WWVegas/WWMath/colmathline.h deleted file mode 100644 index e583e014d41..00000000000 --- a/Generals/Code/Libraries/Source/WWVegas/WWMath/colmathline.h +++ /dev/null @@ -1,64 +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 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 : WWMath * - * * - * $Archive:: /Commando/Code/wwmath/colmathline.h $* - * * - * Original Author:: Greg Hjelstrom * - * * - * $Author:: Greg_h $* - * * - * $Modtime:: 3/16/00 3:46p $* - * * - * $Revision:: 1 $* - * * - *---------------------------------------------------------------------------------------------* - * Functions: * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - -#ifndef COLMATHLINE_H -#define COLMATHLINE_H - -/* -** Inline collision functions dealing with line segments -*/ - - -inline CollisionMath::OverlapType CollisionMath::Overlap_Test -( - const Vector3 & min, - const Vector3 & max, - const LineSegClass & line -) -{ - AABoxClass box; - box.Init_Min_Max(min,max); - return CollisionMath::Overlap_Test(box,line); -} - - - - -#endif - - diff --git a/Generals/Code/Libraries/Source/WWVegas/WWMath/colmathobbobb.cpp b/Generals/Code/Libraries/Source/WWVegas/WWMath/colmathobbobb.cpp deleted file mode 100644 index 684cdcb7ccc..00000000000 --- a/Generals/Code/Libraries/Source/WWVegas/WWMath/colmathobbobb.cpp +++ /dev/null @@ -1,1409 +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 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 : WWMath * - * * - * $Archive:: /Commando/Code/wwmath/colmathobbobb.cpp $* - * * - * Author:: Greg Hjelstrom * - * * - * $Modtime:: 5/04/01 8:37p $* - * * - * $Revision:: 14 $* - * * - *---------------------------------------------------------------------------------------------* - * Functions: * - * obb_intersect_box0_basis -- intersection test for a basis vector from box0 * - * obb_intersect_box1_basis -- intersection test for a basis vector from box1 * - * obb_intersect_axis -- intersection test for a axis * - * intersect_obb_obb -- test two OBBoxes for intersection * - * CollisionMath::Intersection_Test -- test two obb's for intersection * - * CollisionMath::Intersection_Test -- test an OBB for intersection with an AAB * - * CollisionMath::Intersection_Test -- Test an AAB for intersection with an OBB * - * obb_separation_test -- test the projections of two obb's for separation * - * obb_check_box0_basis -- projects the boxes onto a basis vector from box0 * - * obb_check_box1_basis -- projects the two obbs onto a basis vector from box1 * - * obb_check_axis -- projects the obbs onto an arbitrary axis * - * obb_compute_projections -- computes projections of two boxes onto an arbitrary axis * - * compute_contact_normal -- computes the contact normal (after contact is detected) * - * eval_side -- returns -1,0,1 depending on ab and side * - * compute_contact_point -- computes the contact point (after contact is detected) * - * collide_obb_obb -- test two obb's for collision * - * CollisionMath::Collide -- collide two OBB's * - * CollisionMath::Collide -- collide an OBB with an AAB * - * CollisionMath::Collide -- collide an AAB with an OBB * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - -#include "colmath.h" -#include "obbox.h" -#include "aabox.h" -#include "wwdebug.h" - - -/* -** Separating Axes have to be rejected if their length is smaller than some epsilon. -** Otherwise, erroneous results can be reported. -*/ -#define AXISLEN_EPSILON2 WWMATH_EPSILON * WWMATH_EPSILON // squared length of a separating axis must be larger than this - - -enum -{ - /* Axes used in Box-Box intersection tests */ - INTERSECTION = 0, - AXIS_A0, - AXIS_A1, - AXIS_A2, - AXIS_B0, - AXIS_B1, - AXIS_B2, - AXIS_A0B0, - AXIS_A0B1, - AXIS_A0B2, - AXIS_A1B0, - AXIS_A1B1, - AXIS_A1B2, - AXIS_A2B0, - AXIS_A2B1, - AXIS_A2B2 -}; - - - -/******************************************************************************** - - OBBox-OBBox intersection detection - - As with most of the collision detection functions, this code is based on the theorem - that given any two non-intersecting convex polyhedra, a separating plane/axis - can be found that will be defined by one of the face normals of one of the polyhedra - or the cross product of an edge from each polyhedra. - - In the case of two oriented 3D boxes, 15 separating axes must be tested. - Each of the basis vectors from box A, each of the basis vectors from box B, and - the cross products of any combination of a basis vector from A and a basis vector - from B. Some of these separating axis tests can be optimized. For example, if - the axis being tested is a basis vector from the first box, then that box's - extent does not need to be projected onto the axis... - - The first batch of functions in this module implement a intersection test. - A boolean is returned indicating whether the two boxes intersect each other - in any way. - - The OBB-ABB and ABB-OBB functions are also implemented in a way that re-uses - the OBB-OBB code. - -********************************************************************************/ - - -/** -** ObbIntersectionStruct -** Contains all of the intermediate and temporary values used by -** the set of functions used in detecting intersection for obb's -*/ -struct ObbIntersectionStruct -{ - ObbIntersectionStruct(const OBBoxClass &box0,const OBBoxClass & box1) : - Box0(box0), - Box1(box1) - { - Vector3::Subtract(box1.Center,box0.Center,&C); // vector from center of box0 to center of box1 - - A[0].Set(box0.Basis[0][0],box0.Basis[1][0],box0.Basis[2][0]); - A[1].Set(box0.Basis[0][1],box0.Basis[1][1],box0.Basis[2][1]); - A[2].Set(box0.Basis[0][2],box0.Basis[1][2],box0.Basis[2][2]); - - B[0].Set(box1.Basis[0][0],box1.Basis[1][0],box1.Basis[2][0]); - B[1].Set(box1.Basis[0][1],box1.Basis[1][1],box1.Basis[2][1]); - B[2].Set(box1.Basis[0][2],box1.Basis[1][2],box1.Basis[2][2]); - } - - Vector3 C; // Vector from the center0 to center1 - Vector3 A[3]; // basis vectors for box0 - Vector3 B[3]; // basis vectors for box1 - float AB[3][3]; // dot products of the basis vectors - - const OBBoxClass & Box0; - const OBBoxClass & Box1; - -private: - //not implemented - ObbIntersectionStruct(const ObbIntersectionStruct&); - ObbIntersectionStruct & operator = (const ObbIntersectionStruct&); -}; - - - -/*********************************************************************************************** - * obb_intersect_box0_basis -- intersection test for a basis vector from box0 * - * * - * The optimization here is that the projection of the first box is known since the axis is * - * one of its basis vectors. * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 5/4/99 GTH : Created. * - *=============================================================================================*/ -static bool obb_intersect_box0_basis -( - ObbIntersectionStruct & context, - int axis_index -) -{ - // ra = box0 projection onto the axis - // rb = box1 projection onto the axis - float ra = context.Box0.Extent[axis_index]; - float rb = WWMath::Fabs(context.Box1.Extent[0]*context.AB[axis_index][0]) + - WWMath::Fabs(context.Box1.Extent[1]*context.AB[axis_index][1]) + - WWMath::Fabs(context.Box1.Extent[2]*context.AB[axis_index][2]); - float rsum = ra+rb; - - // u = projected distance between the box centers - float u = Vector3::Dot_Product(context.C,context.A[axis_index]); - - // (gth) the epsilon here was not scaled to the length of the axis so it - // caused problems when the axis being tested became very small - return ((u /*+ WWMATH_EPSILON*/ > rsum) || (u /*- WWMATH_EPSILON*/ < -rsum)); -} - - -/*********************************************************************************************** - * obb_intersect_box1_basis -- intersection test for a basis vector from box1 * - * * - * The "optimization" here is that the extent for the second box is known since the axis is * - * one of its basis vectors. * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 5/4/99 GTH : Created. * - *=============================================================================================*/ -static bool obb_intersect_box1_basis -( - ObbIntersectionStruct & context, - int axis_index -) -{ - // ra = box0 projection onto the axis - // rb = box1 projection onto the axis - float ra = WWMath::Fabs(context.Box0.Extent[0]*context.AB[0][axis_index]) + - WWMath::Fabs(context.Box0.Extent[1]*context.AB[1][axis_index]) + - WWMath::Fabs(context.Box0.Extent[2]*context.AB[2][axis_index]); - float rb = context.Box1.Extent[axis_index]; - float rsum = ra+rb; - - // u = projected distance between the box centers - float u = Vector3::Dot_Product(context.C,context.B[axis_index]); - - // (gth) the epsilon here was not scaled to the length of the axis so it - // caused problems when the axis being tested became very small - return ((u /*+ WWMATH_EPSILON*/ > rsum) || (u /*- WWMATH_EPSILON*/ < -rsum)); -} - - -/*********************************************************************************************** - * obb_intersect_axis -- intersection test for a axis * - * * - * Checks intersection on an arbitrary axis where you've already computed the projectsions. * - * Many of the later tests in the OBB-OBB algorigthm fall into here since there are * - * optimizations in computing the projections but they are all specific to the axis being used * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 5/4/99 GTH : Created. * - *=============================================================================================*/ -static inline bool obb_intersect_axis -( - ObbIntersectionStruct & context, - const Vector3 & axis, - float ra, - float rb -) -{ - float rsum = ra+rb; - float u = Vector3::Dot_Product(context.C,axis); - - // (gth) the epsilon here was not scaled to the length of the axis so it - // caused problems when the axis being tested became very small - return ((u /*+ WWMATH_EPSILON*/ > rsum) || (u /*- WWMATH_EPSILON*/ < -rsum)); -} - - -/*********************************************************************************************** - * intersect_obb_obb -- test two OBBoxes for intersection * - * * - * This function works in a very similar (but simplified) way as the Collide function. See * - * the comments in that function for more clues regarding the math involved... * - * * - * Due to the re-usage of intermediate calculations, this function is ~2x faster than the * - * equivalent Oriented_Boxes_Intersect. * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 5/4/99 GTH : Created. * - *=============================================================================================*/ -bool intersect_obb_obb -( - ObbIntersectionStruct & context -) -{ - Vector3 axis; - float ra,rb; - - ///////////////////////////////////////////////////////////////////////// - // Axis = A0 - ///////////////////////////////////////////////////////////////////////// - context.AB[0][0] = Vector3::Dot_Product(context.A[0],context.B[0]); - context.AB[0][1] = Vector3::Dot_Product(context.A[0],context.B[1]); - context.AB[0][2] = Vector3::Dot_Product(context.A[0],context.B[2]); - if (context.Box0.Extent[0] > 0.0f) { - if (obb_intersect_box0_basis(context,0)) return false; - } - - ///////////////////////////////////////////////////////////////////////// - // Axsis A1 - ///////////////////////////////////////////////////////////////////////// - context.AB[1][0] = Vector3::Dot_Product(context.A[1],context.B[0]); - context.AB[1][1] = Vector3::Dot_Product(context.A[1],context.B[1]); - context.AB[1][2] = Vector3::Dot_Product(context.A[1],context.B[2]); - if (context.Box0.Extent[1] > 0.0f) { - if (obb_intersect_box0_basis(context,1)) return false; - } - - - ///////////////////////////////////////////////////////////////////////// - // Axis = A2 - ///////////////////////////////////////////////////////////////////////// - context.AB[2][0] = Vector3::Dot_Product(context.A[2],context.B[0]); - context.AB[2][1] = Vector3::Dot_Product(context.A[2],context.B[1]); - context.AB[2][2] = Vector3::Dot_Product(context.A[2],context.B[2]); - if (context.Box0.Extent[2] > 0.0f) { - if (obb_intersect_box0_basis(context,2)) return false; - } - - - ///////////////////////////////////////////////////////////////////////// - // Axis B0,B1,B2 - ///////////////////////////////////////////////////////////////////////// - if (context.Box1.Extent[0] > 0.0f) { - if (obb_intersect_box1_basis(context,0)) return false; - } - - if (context.Box1.Extent[1] > 0.0f) { - if (obb_intersect_box1_basis(context,1)) return false; - } - - if (context.Box1.Extent[2] > 0.0f) { - if (obb_intersect_box1_basis(context,2)) return false; - } - - ///////////////////////////////////////////////////////////////////////// - // Axis = A0xB0 - ///////////////////////////////////////////////////////////////////////// - Vector3::Cross_Product(context.A[0],context.B[0],&axis); - if (axis.Length2() > AXISLEN_EPSILON2) { - ra = WWMath::Fabs(context.Box0.Extent[1]*context.AB[2][0])+WWMath::Fabs(context.Box0.Extent[2]*context.AB[1][0]); - rb = WWMath::Fabs(context.Box1.Extent[1]*context.AB[0][2])+WWMath::Fabs(context.Box1.Extent[2]*context.AB[0][1]); - if (obb_intersect_axis(context,axis,ra,rb)) return false; - } - - ///////////////////////////////////////////////////////////////////////// - // Axis = A0xB1 - ///////////////////////////////////////////////////////////////////////// - Vector3::Cross_Product(context.A[0],context.B[1],&axis); - if (axis.Length2() > AXISLEN_EPSILON2) { - ra = WWMath::Fabs(context.Box0.Extent[1]*context.AB[2][1])+WWMath::Fabs(context.Box0.Extent[2]*context.AB[1][1]); - rb = WWMath::Fabs(context.Box1.Extent[0]*context.AB[0][2])+WWMath::Fabs(context.Box1.Extent[2]*context.AB[0][0]); - if (obb_intersect_axis(context,axis,ra,rb)) return false; - } - - ///////////////////////////////////////////////////////////////////////// - // Axis = A0xB2 - ///////////////////////////////////////////////////////////////////////// - Vector3::Cross_Product(context.A[0],context.B[2],&axis); - if (axis.Length2() > AXISLEN_EPSILON2) { - ra = WWMath::Fabs(context.Box0.Extent[1]*context.AB[2][2])+WWMath::Fabs(context.Box0.Extent[2]*context.AB[1][2]); - rb = WWMath::Fabs(context.Box1.Extent[0]*context.AB[0][1])+WWMath::Fabs(context.Box1.Extent[1]*context.AB[0][0]); - if (obb_intersect_axis(context,axis,ra,rb)) return false; - } - - ///////////////////////////////////////////////////////////////////////// - // Axis = A1xB0 - ///////////////////////////////////////////////////////////////////////// - Vector3::Cross_Product(context.A[1],context.B[0],&axis); - if (axis.Length2() > AXISLEN_EPSILON2) { - ra = WWMath::Fabs(context.Box0.Extent[0]*context.AB[2][0])+WWMath::Fabs(context.Box0.Extent[2]*context.AB[0][0]); - rb = WWMath::Fabs(context.Box1.Extent[1]*context.AB[1][2])+WWMath::Fabs(context.Box1.Extent[2]*context.AB[1][1]); - if (obb_intersect_axis(context,axis,ra,rb)) return false; - } - - ///////////////////////////////////////////////////////////////////////// - // Axis = A1xB1 - ///////////////////////////////////////////////////////////////////////// - Vector3::Cross_Product(context.A[1],context.B[1],&axis); - if (axis.Length2() > AXISLEN_EPSILON2) { - ra = WWMath::Fabs(context.Box0.Extent[0]*context.AB[2][1])+WWMath::Fabs(context.Box0.Extent[2]*context.AB[0][1]); - rb = WWMath::Fabs(context.Box1.Extent[0]*context.AB[1][2])+WWMath::Fabs(context.Box1.Extent[2]*context.AB[1][0]); - if (obb_intersect_axis(context,axis,ra,rb)) return false; - } - - ///////////////////////////////////////////////////////////////////////// - // Axis = A1xB2 - ///////////////////////////////////////////////////////////////////////// - Vector3::Cross_Product(context.A[1],context.B[2],&axis); - if (axis.Length2() > AXISLEN_EPSILON2) { - ra = WWMath::Fabs(context.Box0.Extent[0]*context.AB[2][2])+WWMath::Fabs(context.Box0.Extent[2]*context.AB[0][2]); - rb = WWMath::Fabs(context.Box1.Extent[0]*context.AB[1][1])+WWMath::Fabs(context.Box1.Extent[1]*context.AB[1][0]); - if (obb_intersect_axis(context,axis,ra,rb)) return false; - } - - ///////////////////////////////////////////////////////////////////////// - // Axis = A2xB0 - ///////////////////////////////////////////////////////////////////////// - Vector3::Cross_Product(context.A[2],context.B[0],&axis); - if (axis.Length2() > AXISLEN_EPSILON2) { - ra = WWMath::Fabs(context.Box0.Extent[0]*context.AB[1][0])+WWMath::Fabs(context.Box0.Extent[1]*context.AB[0][0]); - rb = WWMath::Fabs(context.Box1.Extent[1]*context.AB[2][2])+WWMath::Fabs(context.Box1.Extent[2]*context.AB[2][1]); - if (obb_intersect_axis(context,axis,ra,rb)) return false; - } - - ///////////////////////////////////////////////////////////////////////// - // Axis = A2xB1 - ///////////////////////////////////////////////////////////////////////// - Vector3::Cross_Product(context.A[2],context.B[1],&axis); - if (axis.Length2() > AXISLEN_EPSILON2) { - ra = WWMath::Fabs(context.Box0.Extent[0]*context.AB[1][1])+WWMath::Fabs(context.Box0.Extent[1]*context.AB[0][1]); - rb = WWMath::Fabs(context.Box1.Extent[0]*context.AB[2][2])+WWMath::Fabs(context.Box1.Extent[2]*context.AB[2][0]); - if (obb_intersect_axis(context,axis,ra,rb)) return false; - } - - ///////////////////////////////////////////////////////////////////////// - // Axis = A2xB2 - ///////////////////////////////////////////////////////////////////////// - Vector3::Cross_Product(context.A[2],context.B[2],&axis); - if (axis.Length2() > AXISLEN_EPSILON2) { - ra = WWMath::Fabs(context.Box0.Extent[0]*context.AB[1][2])+WWMath::Fabs(context.Box0.Extent[1]*context.AB[0][2]); - rb = WWMath::Fabs(context.Box1.Extent[0]*context.AB[2][1])+WWMath::Fabs(context.Box1.Extent[1]*context.AB[2][0]); - if (obb_intersect_axis(context,axis,ra,rb)) return false; - } - - return true; -} - - -/*********************************************************************************************** - * CollisionMath::Intersection_Test -- test two obb's for intersection * - * * - * Simply sets up the context and calls intersect_obb_obb * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 5/25/99 GTH : Created. * - *=============================================================================================*/ -bool CollisionMath::Intersection_Test(const OBBoxClass & box0,const OBBoxClass & box1) -{ - ObbIntersectionStruct context(box0,box1); - return intersect_obb_obb(context); -} - - -/*********************************************************************************************** - * CollisionMath::Intersection_Test -- test an OBB for intersection with an AAB * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 5/25/99 GTH : Created. * - *=============================================================================================*/ -bool CollisionMath::Intersection_Test(const OBBoxClass & box0,const AABoxClass & box1) -{ - OBBoxClass obbox1(box1.Center,box1.Extent); - ObbIntersectionStruct context(box0,obbox1); - return intersect_obb_obb(context); -} - - -/*********************************************************************************************** - * CollisionMath::Intersection_Test -- Test an AAB for intersection with an OBB * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 5/25/99 GTH : Created. * - *=============================================================================================*/ -bool CollisionMath::Intersection_Test(const AABoxClass & box0,const OBBoxClass & box1) -{ - OBBoxClass obbox0(box0.Center,box0.Extent); - ObbIntersectionStruct context(obbox0,box1); - return intersect_obb_obb(context); -} - - -/******************************************************************************** - - OBBox-OBBox collision detection - - This batch of functions implement collision detection for moving oriented - boxes. Assuming that the two arbitrarily oriented boxes are moving at a constant - velocity along a path and not rotating, the time of collision can be found. - The OBB-ABB and ABB-OBB functions are also implemented in a way that re-uses - the OBB-OBB code. - - For the code which computes the point of collision and collision normal, you'll - have to refer to the paper by Dave Eberly on oriented bounding boxes. The - formulas for the collision point are the only part of this I was unable to - derive myself (they are pretty nasty...) - -********************************************************************************/ - - -/** -** ObbCollisionStruct -** Contains all of the intermediate and temporary values used by -** the set of functions used in detecting collisions for obb's -*/ -struct ObbCollisionStruct -{ - ObbCollisionStruct(const OBBoxClass &box0,const Vector3 &move0,const OBBoxClass & box1,const Vector3 &move1) : - StartBad(true), // Startbad is true until one of the axes clears it - AxisId(INTERSECTION), // AxisId will be the axis that allowed the longest move - MaxFrac(0.0f), // MaxFrac is the longest allowed move so far - Box0(box0), - Move0(move0), - Box1(box1), - Move1(move1) - { - Vector3::Subtract(box1.Center,box0.Center,&C); // vector from center of box0 to center of box1 - Vector3::Subtract(move1,move0,&M); // move vector relative to stationary box0 - - A[0].Set(box0.Basis[0][0],box0.Basis[1][0],box0.Basis[2][0]); - A[1].Set(box0.Basis[0][1],box0.Basis[1][1],box0.Basis[2][1]); - A[2].Set(box0.Basis[0][2],box0.Basis[1][2],box0.Basis[2][2]); - - B[0].Set(box1.Basis[0][0],box1.Basis[1][0],box1.Basis[2][0]); - B[1].Set(box1.Basis[0][1],box1.Basis[1][1],box1.Basis[2][1]); - B[2].Set(box1.Basis[0][2],box1.Basis[1][2],box1.Basis[2][2]); - } - - bool StartBad; // Inital configuration is intersecting? - float MaxFrac; // Longest move allowed so far - int AxisId; // Last separating axis - int Side; // which side of the interval - - int TestAxisId; // Axis 'id' we're working on - Vector3 TestAxis; // Axis that we're working on - - Vector3 C; // Vector from the center0 to center1 - Vector3 M; // Move vector relative to stationary box0 - - Vector3 A[3]; // basis vectors for box0 - Vector3 B[3]; // basis vectors for box1 - float AB[3][3]; // dot products of the basis vectors - - const OBBoxClass & Box0; - const Vector3 & Move0; - const OBBoxClass & Box1; - const Vector3 & Move1; - -private: - //not implemented - ObbCollisionStruct(const ObbCollisionStruct&); - ObbCollisionStruct & operator = (const ObbCollisionStruct&); -}; - - - -/*********************************************************************************************** - * obb_separation_test -- test the projections of two obb's for separation * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 4/8/99 GTH : Created. * - *=============================================================================================*/ -static inline bool obb_separation_test -( - ObbCollisionStruct & context, - float ra, - float rb, - float u0, - float u1 -) -{ - float tmp; - float rsum = ra+rb; - - if ( u0 + WWMATH_EPSILON > rsum ) { - context.StartBad = false; - if ( u1 > rsum ) { - context.MaxFrac = 1.0f; - return true; - } else { - tmp = (rsum-u0)/(u1-u0); - if ( tmp > context.MaxFrac ) { - context.MaxFrac = tmp; - context.AxisId = context.TestAxisId; - context.Side = +1; - } - } - } else if ( u0 - WWMATH_EPSILON < -rsum ) { - context.StartBad = false; - if ( u1 < -rsum ) { - context.MaxFrac = 1.0f; - return true; - } else { - tmp = (-rsum-u0)/(u1-u0); - if ( tmp > context.MaxFrac ) { - context.MaxFrac = tmp; - context.AxisId = context.TestAxisId; - context.Side = -1; - } - } - } - return false; -} - - -/*********************************************************************************************** - * obb_check_box0_basis -- projects the boxes onto a basis vector from box0 * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 4/8/99 GTH : Created. * - *=============================================================================================*/ -static bool obb_check_box0_basis -( - ObbCollisionStruct & context, - int axis_index -) -{ - // ra = box0 projection onto the axis - // rb = box1 projection onto the axis - float ra = context.Box0.Extent[axis_index]; - float rb = WWMath::Fabs(context.Box1.Extent[0]*context.AB[axis_index][0]) + - WWMath::Fabs(context.Box1.Extent[1]*context.AB[axis_index][1]) + - WWMath::Fabs(context.Box1.Extent[2]*context.AB[axis_index][2]); - - // u0 = projected distance between the box centers at t0 - // u1 = projected distance between the box centers at t1 - float u0 = Vector3::Dot_Product(context.C,context.A[axis_index]); - float u1 = u0 + Vector3::Dot_Product(context.M,context.A[axis_index]); - - return obb_separation_test(context,ra,rb,u0,u1); -} - - -/*********************************************************************************************** - * obb_check_box1_basis -- projects the two obbs onto a basis vector from box1 * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 4/8/99 GTH : Created. * - *=============================================================================================*/ -static bool obb_check_box1_basis -( - ObbCollisionStruct & context, - int axis_index -) -{ - // ra = box0 projection onto the axis - // rb = box1 projection onto the axis - float ra = WWMath::Fabs(context.Box0.Extent[0]*context.AB[0][axis_index]) + - WWMath::Fabs(context.Box0.Extent[1]*context.AB[1][axis_index]) + - WWMath::Fabs(context.Box0.Extent[2]*context.AB[2][axis_index]); - float rb = context.Box1.Extent[axis_index]; - - // u0 = projected distance between the box centers at t0 - // u1 = projected distance between the box centers at t1 - float u0 = Vector3::Dot_Product(context.C,context.B[axis_index]); - float u1 = u0 + Vector3::Dot_Product(context.M,context.B[axis_index]); - return obb_separation_test(context,ra,rb,u0,u1); -} - - -/*********************************************************************************************** - * obb_check_axis -- projects the obbs onto an arbitrary axis * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 4/8/99 GTH : Created. * - *=============================================================================================*/ -static inline bool obb_check_axis -( - ObbCollisionStruct & context, - float ra, - float rb -) -{ - float u0 = Vector3::Dot_Product(context.C,context.TestAxis); - float u1 = u0 + Vector3::Dot_Product(context.M,context.TestAxis); - return obb_separation_test(context,ra,rb,u0,u1); -} - - -/*********************************************************************************************** - * obb_compute_projections -- computes projections of two boxes onto an arbitrary axis * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 4/8/99 GTH : Created. * - *=============================================================================================*/ -static inline void obb_compute_projections -( - const ObbCollisionStruct & context, - float * ra, - float * rb -) -{ - *ra = context.Box0.Extent.X * WWMath::Fabs(Vector3::Dot_Product(context.A[0],context.TestAxis)) + - context.Box0.Extent.Y * WWMath::Fabs(Vector3::Dot_Product(context.A[1],context.TestAxis)) + - context.Box0.Extent.Z * WWMath::Fabs(Vector3::Dot_Product(context.A[2],context.TestAxis)); - - *rb = context.Box1.Extent.X * WWMath::Fabs(Vector3::Dot_Product(context.B[0],context.TestAxis)) + - context.Box1.Extent.Y * WWMath::Fabs(Vector3::Dot_Product(context.B[1],context.TestAxis)) + - context.Box1.Extent.Z * WWMath::Fabs(Vector3::Dot_Product(context.B[2],context.TestAxis)); -} - - -/*********************************************************************************************** - * compute_contact_normal -- computes the contact normal (after contact is detected) * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 4/8/99 GTH : Created. * - *=============================================================================================*/ -static inline void compute_contact_normal(ObbCollisionStruct & context,CastResultStruct * result) -{ - switch(context.AxisId) - { - case INTERSECTION: -#pragma message("Fatal assert disabled for demo, obb-obb collision") -// WWASSERT(0); -// break; - - case AXIS_A0: - result->Normal = context.A[0]; - break; - - case AXIS_A1: - result->Normal = context.A[1]; - break; - - case AXIS_A2: - result->Normal = context.A[2]; - break; - - case AXIS_B0: - result->Normal = context.B[0]; - break; - - case AXIS_B1: - result->Normal = context.B[1]; - break; - - case AXIS_B2: - result->Normal = context.B[2]; - break; - - case AXIS_A0B0: - Vector3::Cross_Product(context.A[0],context.B[0],&result->Normal); - result->Normal.Normalize(); - break; - - case AXIS_A0B1: - Vector3::Cross_Product(context.A[0],context.B[1],&result->Normal); - result->Normal.Normalize(); - break; - - case AXIS_A0B2: - Vector3::Cross_Product(context.A[0],context.B[2],&result->Normal); - result->Normal.Normalize(); - break; - - case AXIS_A1B0: - Vector3::Cross_Product(context.A[1],context.B[0],&result->Normal); - result->Normal.Normalize(); - break; - - case AXIS_A1B1: - Vector3::Cross_Product(context.A[1],context.B[1],&result->Normal); - result->Normal.Normalize(); - break; - - case AXIS_A1B2: - Vector3::Cross_Product(context.A[1],context.B[2],&result->Normal); - result->Normal.Normalize(); - break; - - case AXIS_A2B0: - Vector3::Cross_Product(context.A[2],context.B[0],&result->Normal); - result->Normal.Normalize(); - break; - - case AXIS_A2B1: - Vector3::Cross_Product(context.A[2],context.B[1],&result->Normal); - result->Normal.Normalize(); - break; - - case AXIS_A2B2: - Vector3::Cross_Product(context.A[2],context.B[2],&result->Normal); - result->Normal.Normalize(); - break; - } - - result->Normal *= -context.Side; -} - - -/*********************************************************************************************** - * eval_side -- returns -1,0,1 depending on ab and side * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 4/8/99 GTH : Created. * - *=============================================================================================*/ -static inline float eval_side(float ab,float side) -{ - if (ab > 0.0f) { - return side; - } else if (ab < 0.0f) { - return -side; - } else { - return 0.0f; - } -} - - -/*********************************************************************************************** - * compute_contact_point -- computes the contact point (after contact is detected) * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 4/8/99 GTH : Created. * - *=============================================================================================*/ -static inline void compute_contact_point(ObbCollisionStruct & context,CastResultStruct * result) -{ - int i,j; - float x[3]; // box0 parameters - float y[3]; // box1 parameters - float den; - Vector3 dcnew(0,0,0); - -//again: - - if (context.AxisId >= AXIS_A0B0) { - Vector3 cnew0; - Vector3 cnew1; - Vector3::Add(context.Box0.Center,context.MaxFrac * context.Move0,&cnew0); - Vector3::Add(context.Box1.Center,context.MaxFrac * context.Move1,&cnew1); - Vector3::Subtract(cnew1,cnew0,&dcnew); - } - - //PROBLEMS: - //in case of edge-face or face-face or perfectly aligned edge-edge this - //routine is only computing a single point. - switch(context.AxisId) - { - case AXIS_A0: - case AXIS_A1: - case AXIS_A2: - i = context.AxisId - AXIS_A0; - for (j=0; j<3; j++) { - y[j] = -eval_side(context.AB[i][j],context.Side); - } - context.Box1.Compute_Point(y,&(result->ContactPoint)); - result->ContactPoint += result->Fraction * context.Move1; - return; - - case AXIS_B0: - case AXIS_B1: - case AXIS_B2: - j = context.AxisId - AXIS_B0; - for (i=0; i<3; i++) { - x[i] = eval_side(context.AB[i][j],context.Side); - } - context.Box0.Compute_Point(x,&(result->ContactPoint)); - result->ContactPoint += result->Fraction * context.Move0; - return; - - case AXIS_A0B0: - x[1] = -eval_side(context.AB[2][0],context.Side) * context.Box0.Extent[1]; - x[2] = eval_side(context.AB[1][0],context.Side) * context.Box0.Extent[2]; - y[1] = -eval_side(context.AB[0][2],context.Side) * context.Box1.Extent[1]; - y[2] = eval_side(context.AB[0][1],context.Side) * context.Box1.Extent[2]; - - den = (1.0f - context.AB[0][0] * context.AB[0][0]); - if (WWMath::Fabs(den) > 0.0f) { - x[0] = Vector3::Dot_Product(context.A[0],dcnew); - x[0] += context.AB[0][0] * (Vector3::Dot_Product(-context.B[0],dcnew) + context.AB[1][0]*x[1] + context.AB[2][0]*x[2]); - x[0] += context.AB[0][1] * y[1] + context.AB[0][2] * y[2]; - x[0] /= den; - } else { - x[0] = 0.0f; - } - break; - - case AXIS_A0B1: - x[1] = -eval_side(context.AB[2][1],context.Side) * context.Box0.Extent[1]; - x[2] = eval_side(context.AB[1][1],context.Side) * context.Box0.Extent[2]; - y[0] = eval_side(context.AB[0][2],context.Side) * context.Box1.Extent[0]; - y[2] = -eval_side(context.AB[0][0],context.Side) * context.Box1.Extent[2]; - - den = (1.0f - context.AB[0][1] * context.AB[0][1]); - if (WWMath::Fabs(den) > 0.0f) { - x[0] = Vector3::Dot_Product(context.A[0],dcnew); - x[0] += context.AB[0][1] * (Vector3::Dot_Product(-context.B[1],dcnew) + context.AB[1][1]*x[1] + context.AB[2][1]*x[2]); - x[0] += context.AB[0][0] * y[0] + context.AB[0][2] * y[2]; - x[0] /= den; - } else { - x[0] = 0.0f; - } - break; - - case AXIS_A0B2: - x[1] = -eval_side(context.AB[2][2],context.Side) * context.Box0.Extent[1]; - x[2] = eval_side(context.AB[1][2],context.Side) * context.Box0.Extent[2]; - y[0] = -eval_side(context.AB[0][1],context.Side) * context.Box1.Extent[0]; - y[1] = eval_side(context.AB[0][0],context.Side) * context.Box1.Extent[1]; - - den = (1.0f - context.AB[0][2] * context.AB[0][2]); - if (WWMath::Fabs(den) > 0.0f) { - x[0] = Vector3::Dot_Product(context.A[0],dcnew); - x[0] += context.AB[0][2] * (Vector3::Dot_Product(-context.B[2],dcnew) + context.AB[1][2]*x[1] + context.AB[2][2]*x[2]); - x[0] += context.AB[0][0] * y[0] + context.AB[0][1] * y[1]; - x[0] /= den; - } else { - x[0] = 0.0f; - } - break; - - case AXIS_A1B0: - x[0] = eval_side(context.AB[2][0],context.Side) * context.Box0.Extent[0]; - x[2] = -eval_side(context.AB[0][0],context.Side) * context.Box0.Extent[2]; - y[1] = -eval_side(context.AB[1][2],context.Side) * context.Box1.Extent[1]; - y[2] = eval_side(context.AB[1][1],context.Side) * context.Box1.Extent[2]; - - den = (1.0f - context.AB[1][0] * context.AB[1][0]); - if (WWMath::Fabs(den) > 0.0f) { - x[1] = Vector3::Dot_Product(context.A[1],dcnew); - x[1] += context.AB[1][0] * (Vector3::Dot_Product(-context.B[0],dcnew) + context.AB[0][0]*x[0] + context.AB[2][0]*x[2]); - x[1] += context.AB[1][1] * y[1] + context.AB[1][2] * y[2]; - x[1] /= den; - } else { - x[1] = 0.0f; - } - break; - - case AXIS_A1B1: - x[0] = eval_side(context.AB[2][1],context.Side) * context.Box0.Extent[0]; - x[2] = -eval_side(context.AB[0][1],context.Side) * context.Box0.Extent[2]; - y[0] = eval_side(context.AB[1][2],context.Side) * context.Box1.Extent[0]; - y[2] = -eval_side(context.AB[1][0],context.Side) * context.Box1.Extent[2]; - - den = 1.0f / (1.0f - context.AB[1][1] * context.AB[1][1]); - if (WWMath::Fabs(den) > 0.0f) { - x[1] = Vector3::Dot_Product(context.A[1],dcnew); - x[1] += context.AB[1][1] * (Vector3::Dot_Product(-context.B[1],dcnew) + context.AB[0][1]*x[0] + context.AB[2][1]*x[2]); - x[1] += context.AB[1][0] * y[0] + context.AB[1][2] * y[2]; - x[1] /= den; - } else { - x[1] = 0.0f; - } - break; - - case AXIS_A1B2: - x[0] = eval_side(context.AB[2][2],context.Side) * context.Box0.Extent[0]; - x[2] = -eval_side(context.AB[0][2],context.Side) * context.Box0.Extent[2]; - y[0] = -eval_side(context.AB[1][1],context.Side) * context.Box1.Extent[0]; - y[1] = eval_side(context.AB[1][0],context.Side) * context.Box1.Extent[1]; - - den = (1.0f - context.AB[1][2] * context.AB[1][2]); - if (WWMath::Fabs(den) > 0.0f) { - x[1] = Vector3::Dot_Product(context.A[1],dcnew); - x[1] += context.AB[1][2] * (Vector3::Dot_Product(-context.B[2],dcnew) + context.AB[0][2]*x[0] + context.AB[2][2]*x[2]); - x[1] += context.AB[1][0] * y[0] + context.AB[1][1] * y[1]; - x[1] /= den; - } else { - x[1] = 0.0f; - } - break; - - case AXIS_A2B0: - x[0] = -eval_side(context.AB[1][0],context.Side) * context.Box0.Extent[0]; - x[1] = eval_side(context.AB[0][0],context.Side) * context.Box0.Extent[1]; - y[1] = -eval_side(context.AB[2][2],context.Side) * context.Box1.Extent[1]; - y[2] = eval_side(context.AB[2][1],context.Side) * context.Box1.Extent[2]; - - den = (1.0f - context.AB[2][0] * context.AB[2][0]); - if (WWMath::Fabs(den) > 0.0f) { - x[2] = Vector3::Dot_Product(context.A[2],dcnew); - x[2] += context.AB[2][0] * (Vector3::Dot_Product(-context.B[0],dcnew) + context.AB[0][0]*x[0] + context.AB[1][0]*x[1]); - x[2] += context.AB[2][1] * y[1] + context.AB[2][2] * y[2]; - x[2] /= den; - } else { - x[2] = 0.0f; - } - break; - - case AXIS_A2B1: - x[0] = -eval_side(context.AB[1][1],context.Side) * context.Box0.Extent[0]; - x[1] = eval_side(context.AB[0][1],context.Side) * context.Box0.Extent[1]; - y[0] = eval_side(context.AB[2][2],context.Side) * context.Box1.Extent[0]; - y[2] = -eval_side(context.AB[2][0],context.Side) * context.Box1.Extent[2]; - - den = (1.0f - context.AB[2][1] * context.AB[2][1]); - if (WWMath::Fabs(den) > 0.0f) { - x[2] = Vector3::Dot_Product(context.A[2],dcnew); - x[2] += context.AB[2][1] * (Vector3::Dot_Product(-context.B[1],dcnew) + context.AB[0][1]*x[0] + context.AB[1][1]*x[1]); - x[2] += context.AB[2][0] * y[0] + context.AB[2][2] * y[2]; - x[2] /= den; - } else { - x[2] = 0.0f; - } - break; - - case AXIS_A2B2: - x[0] = -eval_side(context.AB[1][2],context.Side) * context.Box0.Extent[0]; - x[1] = eval_side(context.AB[0][2],context.Side) * context.Box0.Extent[1]; - y[0] = -eval_side(context.AB[2][1],context.Side) * context.Box1.Extent[0]; - y[1] = eval_side(context.AB[2][0],context.Side) * context.Box1.Extent[1]; - - den = (1.0f - context.AB[2][2] * context.AB[2][2]); - if (WWMath::Fabs(den) > 0.0f) { - x[2] = Vector3::Dot_Product(context.A[2],dcnew); - x[2] += context.AB[2][2] * (Vector3::Dot_Product(-context.B[2],dcnew) + context.AB[0][2]*x[0] + context.AB[1][2]*x[1]); - x[2] += context.AB[2][0] * y[0] + context.AB[2][1] * y[1]; - x[2] /= den; - } else { - x[2] = 0.0f; - } - break; - } - - // all but the first two cases fall through to here - result->ContactPoint.X = context.Box0.Center.X + - x[0]*context.A[0].X + - x[1]*context.A[1].X + - x[2]*context.A[2].X; - - result->ContactPoint.Y = context.Box0.Center.Y + - x[0]*context.A[0].Y + - x[1]*context.A[1].Y + - x[2]*context.A[2].Y; - - result->ContactPoint.Z = context.Box0.Center.Z + - x[0]*context.A[0].Z + - x[1]*context.A[1].Z + - x[2]*context.A[2].Z; - - Vector3::Add(result->ContactPoint,result->Fraction * context.Move0,&(result->ContactPoint)); - -} - - -/*********************************************************************************************** - * collide_obb_obb -- test two obb's for collision * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 5/25/99 GTH : Created. * - *=============================================================================================*/ -bool collide_obb_obb -( - ObbCollisionStruct & context, - CastResultStruct * result -) -{ - Vector3 axis; - float ra,rb; - - ///////////////////////////////////////////////////////////////////////// - // Axis = A0 - // Projecting the two boxes onto Box0's X axis. If their intervals - // on this line do not intersect, the boxes are not intersecting! - // Each of the tests in this function work in a similar way. - // For this function I compute the AB's that are needed. The first - // three tests compute all of these constants. - ///////////////////////////////////////////////////////////////////////// - context.TestAxisId = AXIS_A0; - context.AB[0][0] = Vector3::Dot_Product(context.A[0],context.B[0]); - context.AB[0][1] = Vector3::Dot_Product(context.A[0],context.B[1]); - context.AB[0][2] = Vector3::Dot_Product(context.A[0],context.B[2]); - if (obb_check_box0_basis(context,0)) goto exit; - - ///////////////////////////////////////////////////////////////////////// - // Axsis A1 - ///////////////////////////////////////////////////////////////////////// - context.TestAxisId = AXIS_A1; - context.AB[1][0] = Vector3::Dot_Product(context.A[1],context.B[0]); - context.AB[1][1] = Vector3::Dot_Product(context.A[1],context.B[1]); - context.AB[1][2] = Vector3::Dot_Product(context.A[1],context.B[2]); - if (obb_check_box0_basis(context,1)) goto exit; - - ///////////////////////////////////////////////////////////////////////// - // Axis = A2 - ///////////////////////////////////////////////////////////////////////// - context.TestAxisId = AXIS_A2; - context.AB[2][0] = Vector3::Dot_Product(context.A[2],context.B[0]); - context.AB[2][1] = Vector3::Dot_Product(context.A[2],context.B[1]); - context.AB[2][2] = Vector3::Dot_Product(context.A[2],context.B[2]); - if (obb_check_box0_basis(context,2)) goto exit; - - ///////////////////////////////////////////////////////////////////////// - // Axis = B0 - ///////////////////////////////////////////////////////////////////////// - context.TestAxisId = AXIS_B0; - if (obb_check_box1_basis(context,0)) goto exit; - - ///////////////////////////////////////////////////////////////////////// - // Axis = B1 - ///////////////////////////////////////////////////////////////////////// - context.TestAxisId = AXIS_B1; - if (obb_check_box1_basis(context,1)) goto exit; - - ///////////////////////////////////////////////////////////////////////// - // Axis = B2 - ///////////////////////////////////////////////////////////////////////// - context.TestAxisId = AXIS_B2; - if (obb_check_box1_basis(context,2)) goto exit; - - ///////////////////////////////////////////////////////////////////////// - // Axis = A0xB0 - // The axes defined by the cross product between the boxes' basis - // vectors are optimized in a similar way to this one: - // - // ra = |ex*A0*(A0xB0)| + |ey*A1*(A0xB0)| + |ez*A2*(A0xB0)| - // = |ey*A1*(A0xB0)| + |ez*A2*(A0xB0)| A0*(A0xB0)=0 - // = |ey*B0*(A1xA0)| + |ez*B0*(A2xA0)| A*(BxC)=B*(CxA)=C*(AxB) - // = |-ey*A2*B0| + |ez*A1*B0| A0xA1=A2 - // = |ey*AB[2][0]| + |ez*AB[1][0]| already computed these dot products! - // - ///////////////////////////////////////////////////////////////////////// - Vector3::Cross_Product(context.A[0],context.B[0],&context.TestAxis); - context.TestAxisId = AXIS_A0B0; - if (context.TestAxis.Length2() > AXISLEN_EPSILON2) { - ra = WWMath::Fabs(context.Box0.Extent[1]*context.AB[2][0])+WWMath::Fabs(context.Box0.Extent[2]*context.AB[1][0]); - rb = WWMath::Fabs(context.Box1.Extent[1]*context.AB[0][2])+WWMath::Fabs(context.Box1.Extent[2]*context.AB[0][1]); - if (obb_check_axis(context,ra,rb)) goto exit; - } - - ///////////////////////////////////////////////////////////////////////// - // Axis = A0xB1 - ///////////////////////////////////////////////////////////////////////// - Vector3::Cross_Product(context.A[0],context.B[1],&context.TestAxis); - context.TestAxisId = AXIS_A0B1; - if (context.TestAxis.Length2() > AXISLEN_EPSILON2) { - ra = WWMath::Fabs(context.Box0.Extent[1]*context.AB[2][1])+WWMath::Fabs(context.Box0.Extent[2]*context.AB[1][1]); - rb = WWMath::Fabs(context.Box1.Extent[0]*context.AB[0][2])+WWMath::Fabs(context.Box1.Extent[2]*context.AB[0][0]); - if (obb_check_axis(context,ra,rb)) goto exit; - } - - ///////////////////////////////////////////////////////////////////////// - // Axis = A0xB2 - ///////////////////////////////////////////////////////////////////////// - Vector3::Cross_Product(context.A[0],context.B[2],&context.TestAxis); - context.TestAxisId = AXIS_A0B2; - if (context.TestAxis.Length2() > AXISLEN_EPSILON2) { - ra = WWMath::Fabs(context.Box0.Extent[1]*context.AB[2][2])+WWMath::Fabs(context.Box0.Extent[2]*context.AB[1][2]); - rb = WWMath::Fabs(context.Box1.Extent[0]*context.AB[0][1])+WWMath::Fabs(context.Box1.Extent[1]*context.AB[0][0]); - if (obb_check_axis(context,ra,rb)) goto exit; - } - - ///////////////////////////////////////////////////////////////////////// - // Axis = A1xB0 - ///////////////////////////////////////////////////////////////////////// - Vector3::Cross_Product(context.A[1],context.B[0],&context.TestAxis); - context.TestAxisId = AXIS_A1B0; - if (context.TestAxis.Length2() > AXISLEN_EPSILON2) { - ra = WWMath::Fabs(context.Box0.Extent[0]*context.AB[2][0])+WWMath::Fabs(context.Box0.Extent[2]*context.AB[0][0]); - rb = WWMath::Fabs(context.Box1.Extent[1]*context.AB[1][2])+WWMath::Fabs(context.Box1.Extent[2]*context.AB[1][1]); - if (obb_check_axis(context,ra,rb)) goto exit; - } - - ///////////////////////////////////////////////////////////////////////// - // Axis = A1xB1 - ///////////////////////////////////////////////////////////////////////// - Vector3::Cross_Product(context.A[1],context.B[1],&context.TestAxis); - context.TestAxisId = AXIS_A1B1; - if (context.TestAxis.Length2() > AXISLEN_EPSILON2) { - ra = WWMath::Fabs(context.Box0.Extent[0]*context.AB[2][1])+WWMath::Fabs(context.Box0.Extent[2]*context.AB[0][1]); - rb = WWMath::Fabs(context.Box1.Extent[0]*context.AB[1][2])+WWMath::Fabs(context.Box1.Extent[2]*context.AB[1][0]); - if (obb_check_axis(context,ra,rb)) goto exit; - } - - ///////////////////////////////////////////////////////////////////////// - // Axis = A1xB2 - ///////////////////////////////////////////////////////////////////////// - Vector3::Cross_Product(context.A[1],context.B[2],&context.TestAxis); - context.TestAxisId = AXIS_A1B2; - if (context.TestAxis.Length2() > AXISLEN_EPSILON2) { - ra = WWMath::Fabs(context.Box0.Extent[0]*context.AB[2][2])+WWMath::Fabs(context.Box0.Extent[2]*context.AB[0][2]); - rb = WWMath::Fabs(context.Box1.Extent[0]*context.AB[1][1])+WWMath::Fabs(context.Box1.Extent[1]*context.AB[1][0]); - if (obb_check_axis(context,ra,rb)) goto exit; - } - - ///////////////////////////////////////////////////////////////////////// - // Axis = A2xB0 - ///////////////////////////////////////////////////////////////////////// - Vector3::Cross_Product(context.A[2],context.B[0],&context.TestAxis); - context.TestAxisId = AXIS_A2B0; - if (context.TestAxis.Length2() > AXISLEN_EPSILON2) { - ra = WWMath::Fabs(context.Box0.Extent[0]*context.AB[1][0])+WWMath::Fabs(context.Box0.Extent[1]*context.AB[0][0]); - rb = WWMath::Fabs(context.Box1.Extent[1]*context.AB[2][2])+WWMath::Fabs(context.Box1.Extent[2]*context.AB[2][1]); - if (obb_check_axis(context,ra,rb)) goto exit; - } - - ///////////////////////////////////////////////////////////////////////// - // Axis = A2xB1 - ///////////////////////////////////////////////////////////////////////// - Vector3::Cross_Product(context.A[2],context.B[1],&context.TestAxis); - context.TestAxisId = AXIS_A2B1; - if (context.TestAxis.Length2() > AXISLEN_EPSILON2) { - ra = WWMath::Fabs(context.Box0.Extent[0]*context.AB[1][1])+WWMath::Fabs(context.Box0.Extent[1]*context.AB[0][1]); - rb = WWMath::Fabs(context.Box1.Extent[0]*context.AB[2][2])+WWMath::Fabs(context.Box1.Extent[2]*context.AB[2][0]); - if (obb_check_axis(context,ra,rb)) goto exit; - } - - ///////////////////////////////////////////////////////////////////////// - // Axis = A2xB2 - ///////////////////////////////////////////////////////////////////////// - Vector3::Cross_Product(context.A[2],context.B[2],&context.TestAxis); - context.TestAxisId = AXIS_A2B2; - if (context.TestAxis.Length2() > AXISLEN_EPSILON2) { - ra = WWMath::Fabs(context.Box0.Extent[0]*context.AB[1][2])+WWMath::Fabs(context.Box0.Extent[1]*context.AB[0][2]); - rb = WWMath::Fabs(context.Box1.Extent[0]*context.AB[2][1])+WWMath::Fabs(context.Box1.Extent[1]*context.AB[2][0]); - if (obb_check_axis(context,ra,rb)) goto exit; - } - - if (!result->StartBad) { - - context.TestAxisId = context.AxisId; - - ///////////////////////////////////////////////////////////////////////// - // Final three checks are for eliminating false collisions - // Axis = A0xMove - ///////////////////////////////////////////////////////////////////////// - Vector3::Cross_Product(context.A[0],context.Move0,&context.TestAxis); - if (context.TestAxis.Length2() > AXISLEN_EPSILON2) { - obb_compute_projections(context,&ra,&rb); - if (obb_check_axis(context,ra,rb)) goto exit; - } - - ///////////////////////////////////////////////////////////////////////// - // Axis = A1xMove - ///////////////////////////////////////////////////////////////////////// - Vector3::Cross_Product(context.A[1],context.Move0,&context.TestAxis); - if (context.TestAxis.Length2() > AXISLEN_EPSILON2) { - obb_compute_projections(context,&ra,&rb); - if (obb_check_axis(context,ra,rb)) goto exit; - } - - ///////////////////////////////////////////////////////////////////////// - // Axis = A2xMove - ///////////////////////////////////////////////////////////////////////// - Vector3::Cross_Product(context.A[2],context.Move0,&context.TestAxis); - if (context.TestAxis.Length2() > AXISLEN_EPSILON2) { - obb_compute_projections(context,&ra,&rb); - if (obb_check_axis(context,ra,rb)) goto exit; - } - } - -exit: - - if (context.StartBad) { - result->StartBad = true; - result->Fraction = 0.0f; - return true; - } - - - /* - ** If our fraction is smaller, override the previous - ** values because our collision occured first. - */ - if (context.MaxFrac < result->Fraction) { - - result->Fraction = context.MaxFrac; - - compute_contact_normal(context,result); - if (result->ComputeContactPoint) { - compute_contact_point(context,result); - } - return true; - } - return false; -} - -/*********************************************************************************************** - * CollisionMath::Collide -- collide two obb's * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 4/8/99 GTH : Created. * - *=============================================================================================*/ -bool CollisionMath::Collide -( - const OBBoxClass & box0, - const Vector3 & move0, - const OBBoxClass & box1, - const Vector3 & move1, - CastResultStruct * result -) -{ - ObbCollisionStruct context(box0,move0,box1,move1); - return collide_obb_obb(context,result); -} - - -/*********************************************************************************************** - * CollisionMath::Collide -- collide an OBB with an AAB * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 5/25/99 GTH : Created. * - *=============================================================================================*/ -bool CollisionMath::Collide -( - const OBBoxClass & box0, - const Vector3 & move0, - const AABoxClass & box1, - const Vector3 & move1, - CastResultStruct * result -) -{ - OBBoxClass obbox1(box1.Center,box1.Extent); - ObbCollisionStruct context(box0,move0,obbox1,move1); - return collide_obb_obb(context,result); -} - - -/*********************************************************************************************** - * CollisionMath::Collide -- collide an AAB with an OBB * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 5/25/99 GTH : Created. * - *=============================================================================================*/ -bool CollisionMath::Collide -( - const AABoxClass & box0, - const Vector3 & move0, - const OBBoxClass & box1, - const Vector3 & move1, - CastResultStruct * result -) -{ - OBBoxClass obbox0(box0.Center,box0.Extent); - ObbCollisionStruct context(obbox0,move0,box1,move1); - return collide_obb_obb(context,result); -} diff --git a/Generals/Code/Libraries/Source/WWVegas/WWMath/colmathobbox.cpp b/Generals/Code/Libraries/Source/WWVegas/WWMath/colmathobbox.cpp deleted file mode 100644 index 0d7d879eda7..00000000000 --- a/Generals/Code/Libraries/Source/WWVegas/WWMath/colmathobbox.cpp +++ /dev/null @@ -1,171 +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 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 : WWMath * - * * - * $Archive:: /Commando/Code/wwmath/colmathobbox.cpp $* - * * - * Org Author:: Greg Hjelstrom * - * * - * Author : Kenny Mitchell * - * * - * $Modtime:: 06/26/02 4:04p $* - * * - * $Revision:: 9 $* - * * - * 06/26/02 KM Matrix name change to avoid MAX conflicts * - *---------------------------------------------------------------------------------------------* - * Functions: * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - - -#include "colmath.h" -#include "aaplane.h" -#include "plane.h" -#include "lineseg.h" -#include "tri.h" -#include "sphere.h" -#include "aabox.h" -#include "obbox.h" -#include "wwdebug.h" - - - -// OBBox functions, where is operand B with respect to the OBBox -CollisionMath::OverlapType -CollisionMath::Overlap_Test(const OBBoxClass & box,const Vector3 & point) -{ - // transform point into box coordinate system - Vector3 localpoint; - Matrix3x3::Transpose_Rotate_Vector(box.Basis,(point - box.Center),&localpoint); - - // if the point is outside any of the extents, it is outside the box - if (WWMath::Fabs(localpoint.X) > box.Extent.X) { - return OUTSIDE; - } - if (WWMath::Fabs(localpoint.Y) > box.Extent.Y) { - return OUTSIDE; - } - if (WWMath::Fabs(localpoint.Z) > box.Extent.Z) { - return OUTSIDE; - } - return INSIDE; -} - -CollisionMath::OverlapType -CollisionMath::Overlap_Test(const OBBoxClass & box,const LineSegClass & line) -{ - CastResultStruct res; - Collide(line,box,&res); - return eval_overlap_collision(res); -} - -CollisionMath::OverlapType -CollisionMath::Overlap_Test(const OBBoxClass & box,const TriClass & tri) -{ - CastResultStruct res; - Collide(box,Vector3(0,0,0),tri,Vector3(0,0,0),&res); - return eval_overlap_collision(res); -} - -CollisionMath::OverlapType -CollisionMath::Overlap_Test(const AABoxClass & aabox,const OBBoxClass & obbox) -{ - if (CollisionMath::Intersection_Test(aabox,obbox)) { - return BOTH; // inside or overlapping - } else { - return OUTSIDE; - } -} - -CollisionMath::OverlapType -CollisionMath::Overlap_Test(const OBBoxClass & obbox,const AABoxClass & aabox) -{ - if (CollisionMath::Intersection_Test(obbox,aabox)) { - return BOTH; // inside or overlapping - } else { - return OUTSIDE; - } -} - - -CollisionMath::OverlapType -CollisionMath::Overlap_Test(const OBBoxClass & box,const OBBoxClass & box2) -{ - CastResultStruct res; - Collide(box,Vector3(0,0,0),box2,Vector3(0,0,0),&res); - return eval_overlap_collision(res); -} - -bool CollisionMath::Collide -( - const OBBoxClass & box, - const Vector3 & move_vector, - const PlaneClass & plane, - CastResultStruct * result -) -{ - float frac; - - float extent = box.Project_To_Axis(plane.N); - float dist = Vector3::Dot_Product(plane.N,box.Center) + plane.D; - float move = Vector3::Dot_Product(plane.N,move_vector); - - if (dist > extent) { - if (dist + move > extent) { - // entire move ok! - frac = 1.0f; - } else { - // partial move allowed - frac = (extent - dist) / move; - } - - } else if (dist < -extent) { - if (dist + move < -extent) { - // entire move ok! - frac = 1.0f; - } else { - // partial move allowed - frac = (-extent - dist) / move; - } - } else { - result->StartBad = true; - result->Normal = plane.N; - return true; - } - - if (frac < result->Fraction) { - result->Fraction = frac; - result->Normal = plane.N; - if (result->ComputeContactPoint) { - - Vector3 move_dir(move_vector); - move_dir.Normalize(); - float move_extent = Vector3::Dot_Product(move_dir,box.Extent); - result->ContactPoint = box.Center + result->Fraction*move_vector + move_extent*move_dir; - - } - return true; - } - return false; -} - diff --git a/Generals/Code/Libraries/Source/WWVegas/WWMath/colmathobbtri.cpp b/Generals/Code/Libraries/Source/WWVegas/WWMath/colmathobbtri.cpp deleted file mode 100644 index 71052820c85..00000000000 --- a/Generals/Code/Libraries/Source/WWVegas/WWMath/colmathobbtri.cpp +++ /dev/null @@ -1,1507 +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 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 : WWMath * - * * - * $Archive:: /Commando/Code/wwmath/colmathobbtri.cpp $* - * * - * Author:: Greg Hjelstrom * - * * - * $Modtime:: 5/04/01 8:37p $* - * * - * $Revision:: 15 $* - * * - *---------------------------------------------------------------------------------------------* - * Functions: * - * obbtri_collision_separation_test -- test the projected extents for separation * - * obbtri_check_collision_axis -- project the obb and tri onto an arbitrary axis * - * obbtri_check_collision_cross_axis -- intersection check for a "cross-product" axis * - * obbtri_check_collision_basis_axis -- intersection check for a basis axis * - * obbtri_check_collision_normal_axis -- intersection check for the triangle normal * - * eval_side -- returns -1,0,+1 depending on the signe of val and side * - * obbtri_compute_contact_normal -- computes the normal of the collision * - * eval_A0_point -- contact point parameters for A0xEx * - * eval_A1_point -- contact point parameters for A1xEx * - * eval_A2_point -- contact point parameters for A2xEx * - * obbtri_compute_contact_point -- compute the contact point * - * CollisionMath::Collide -- collide an obbox into a triangle * - * obbtri_intersection_separation_test -- test the projected extents for intersection * - * obbtri_check_intersection_cross_axis -- intersection check for a "cross-product" axis * - * obbtri_check_intersection_basis_axis -- intersection check for a basis axis * - * obbtri_check_intersection_normal_axis -- intersection check for the triangle normal * - * CollisionMath::Intersection_Test -- Intersection check for an OBBox and a triangle * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - -#include "colmath.h" -#include "obbox.h" -#include "tri.h" -#include "wwdebug.h" - - -/* -** Separating Axes have to be rejected if their length is smaller than some epsilon. -** Otherwise, erroneous results can be reported. -*/ -#define AXISLEN_EPSILON2 WWMATH_EPSILON * WWMATH_EPSILON // squared length of a separating axis must be larger than this - -/* -** Axes used in Box-Tri intersection tests -** The axes of the box are A0,A1,A2. N is the normal of the triangle, -** E0,E1,E2 are direction vectors for the edges of the triangle. -** (the box axes are labeled A0,A1,A2 as a holdover from the obbox-obbox -** collision code which this was derived from where there are two boxes -** A and B) -*/ -enum -{ - INTERSECTION = 0, - AXIS_N, // normal of the triangle - AXIS_A0, // first basis vector of the box - AXIS_A1, // second basis vector of the box - AXIS_A2, // third basis vector of the box - - AXIS_A0E0, // box0 x edge0... - AXIS_A1E0, - AXIS_A2E0, - AXIS_A0E1, - AXIS_A1E1, - AXIS_A2E1, - AXIS_A0E2, - AXIS_A1E2, - AXIS_A2E2 -}; - - -/****************************************************************************************** - - OBBox->Triangle collision - - As with most of the collision detection functions, this code is based on the theorem - that given any two non-intersecting convex polyhedra, a separating plane/axis - can be found that will be defined by one of the face normals of one of the polyhedra - or the cross product of an edge from each polyhedra. The key optimization for - boxes is that many of these axes are the same. The normal to a face is the same - as the axis for four of the edges of the box, etc. - - This test must be done using the tri normal, the three basis vectors - for the box, and three vectors defined by the cross products of the basis - and edge vectors. When testing the basis vectors, there will be two extents for - the tri (the other two vectors projected onto the axis being tested). - The appropriate extent must be used in the test (largest value which is pointing - towards the direction of the box). In addition, I've found that I must test axes - defined by the cross products of the move vector and the box axes. These tests - catch "false collisions" where the box passes very close to the triangle but does - not actually hit it. - - Each axis test will use the following logic: - Project D onto the axis being used, it is the separation distance. If the - projection of the extent of the box + the projection of the extent of the - tri is greater than D*axis then the two intersect - -******************************************************************************************/ - -/** -** BoxTriColStruct -** Scratchpad variables for the OBBox-Triangle collision detection functions. One instance -** of this structure will be used for all of the local variables and its pointer will be -** handed of to various inline functions for the axis tests. -** Note that much of the code needs the un-normalized triangle normal. For this reason, -** I have to compute N rather than copying it from the triangle. (commenting this to -** avoid re-generating a difficult to find bug that I had) -** -** Note that the MaxFrac variable starts negative so that we can accept slightly negative -** fractions (interpenetrations). But we clamp the returned result to 0.0 so that we never -** allow an object to get more embedded, just to possibly break itself free if it is within -** the epsilon. This is important because sometimes objects seem to intersect simply due to -** floating point roundoff error... -*/ -struct BTCollisionStruct -{ - BTCollisionStruct(const OBBoxClass &box,const Vector3 &move,const TriClass &tri,const Vector3 &trimove) : - Box(box), - Tri(tri), - BoxMove(move), - TriMove(trimove) - { - Reset(); - } - - void Reset(void) - { - StartBad = true; // true until an axis clears it - MaxFrac = -1.0f; // maximum move allowed so far (accept slightly negative but clamp to zero at end) - AxisId = INTERSECTION; // axis that allowed the longest move - Point = 0; // index of triangle point that was closest to the box - Side = 0; // side of the interval - - Vector3::Subtract(*Tri.V[0],Box.Center,&D); // vector from center of box to vertex 0 - Vector3::Subtract(BoxMove,TriMove,&Move); // move vector relative to stationary triangle - - Vector3::Subtract(*Tri.V[1],*Tri.V[0],&E[0]); - Vector3::Subtract(*Tri.V[2],*Tri.V[0],&E[1]); - Vector3::Subtract(E[1],E[0],&E[2]); - - A[0].Set(Box.Basis[0][0],Box.Basis[1][0],Box.Basis[2][0]); - A[1].Set(Box.Basis[0][1],Box.Basis[1][1],Box.Basis[2][1]); - A[2].Set(Box.Basis[0][2],Box.Basis[1][2],Box.Basis[2][2]); - - Vector3::Cross_Product(E[0],E[1],&N); - } - - bool StartBad; // Inital configuration is intersecting? - float MaxFrac; // Longest move allowed so far - int AxisId; // Last separating axis - int Point; // Index of the "closest" triangle point (or one of them) - int Side; // which side of the interval - - int TestSide; // Was the axis we're working on flipped - int TestAxisId; // Axis 'id' we're working on - int TestPoint; // Index of the closest vertex - Vector3 TestAxis; // Axis we're working on - - Vector3 D; // Vector from the center of the box to v0 - Vector3 Move; // Move vector relative to stationary triangle - float AE[3][3]; // Dot products of the Basis vectors and edges - float AN[3]; // Dot products of the Basis vectors and the normal - Vector3 AxE[3][3]; // Cross produts of the Basis vectors and edges - - Vector3 A[3]; // basis vectors for the box - Vector3 E[3]; // edge vectors for the triangle - Vector3 N; // normal (NOT normalized!!!) - Vector3 FinalD; // Vector from center of box to v0 at end of move - - const OBBoxClass & Box; - const TriClass & Tri; - const Vector3 & BoxMove; - const Vector3 & TriMove; - -private: - - // not implemented - BTCollisionStruct(const BTCollisionStruct &); - BTCollisionStruct & operator = (const BTCollisionStruct &); -}; - - - - - -/*********************************************************************************************** - * obbtri_collision_separation_test -- test the projected extents for separation * - * * - * Once the extents are projected onto the axis, this function contains * - * the logic that determines the allowed fraction. * - * * - * INPUT: * - * * - * OUTPUT: * - * true = objects are SEPARATED * - * * - * WARNINGS: * - * * - * HISTORY: * - * 4/8/99 GTH : Created. * - *=============================================================================================*/ -static inline bool obbtri_collision_separation_test -( - BTCollisionStruct & context, - float lp,float leb0,float leb1 -) -{ - /* - ** - compute 'EPSILON' normalized to the length of the axis - ** - If (I'm no more than 'EPSILON' embedded in the polygon) - ** - not startbad - ** - If (I'm moving towards) - ** - fraction = How far I can move before embedding (can be negative if started embedded) - ** - If (I can take entire move) - ** - accept entire move - ** - Else If (I can move more than I could have before; *negative always fails!) - ** - update fraction - ** - Else - ** - Accept entire move since I'm not moving towards the polygon - */ - float eps = 0.0f; - if (lp - leb0 <= 0.0f) { - eps = COLLISION_EPSILON * context.TestAxis.Length(); // trying to only compute epsilon if I have to - } - - if (lp - leb0 > -eps) { - context.StartBad = false; - if (leb1 - leb0 > 0.0f) { - float frac = (lp-leb0)/(leb1-leb0); - if (frac >= 1.0f) { - /* moving toward but not hitting triangle */ - context.AxisId = context.TestAxisId; - context.MaxFrac = 1.0f; - return true; - } else { - /* moving toward, hitting triangle */ - if (frac > context.MaxFrac) { - context.MaxFrac = frac; - context.AxisId = context.TestAxisId; - context.Side = context.TestSide; - context.Point = context.TestPoint; - } - } - } else { - /* moving away or not moving */ - context.AxisId = context.TestAxisId; - context.MaxFrac = 1.0f; - return true; - } - } - return false; -} - - -/*********************************************************************************************** - * obbtri_check_collision_axis -- project the obb and tri onto an arbitrary axis * - * * - * projects the box and the triangle onto the given axis and calls * - * obbtri_separation_test. return true if separation was detected * - * * - * INPUT: * - * * - * OUTPUT: * - * true = objects are SEPARATED * - * * - * WARNINGS: * - * * - * HISTORY: * - * 4/8/99 GTH : Created. * - *=============================================================================================*/ -static inline bool obbtri_check_collision_axis(BTCollisionStruct & context) -{ - float dist; // separation along the axis - float axismove; // size of the move along the axis. - float leb0; // initial coordinate of the leading edge of the box - float leb1; // final coordinate of the leading edge of the box - float lp; // leading edge of the polygon. - float tmp; // temporary - - dist = Vector3::Dot_Product(context.D,context.TestAxis); - axismove = Vector3::Dot_Product(context.Move,context.TestAxis); - - // I want the axis centered at the box, pointing towards the triangle - if (dist < 0) { - dist = -dist; - axismove = -axismove; - context.TestAxis = -context.TestAxis; - context.TestSide = -1.0f; - } else { - context.TestSide = 1.0f; - } - - // compute coordinates of the leading edge of the box at t0 and t1 - leb0 = context.Box.Extent.X * WWMath::Fabs(Vector3::Dot_Product(context.TestAxis,context.A[0])) + - context.Box.Extent.Y * WWMath::Fabs(Vector3::Dot_Product(context.TestAxis,context.A[1])) + - context.Box.Extent.Z * WWMath::Fabs(Vector3::Dot_Product(context.TestAxis,context.A[2])); - leb1 = leb0 + axismove; - - // compute coordinate of "leading edge of the triangle" relative to the box center. - lp = 0; - tmp = Vector3::Dot_Product(context.E[0],context.TestAxis); if (tmp < lp) lp = tmp; - tmp = Vector3::Dot_Product(context.E[1],context.TestAxis); if (tmp < lp) lp = tmp; - lp = dist + lp; - - return obbtri_collision_separation_test(context,lp,leb0,leb1); -} - - -/*********************************************************************************************** - * obbtri_check_collision_cross_axis -- projects obb and tri onto a "cross" axis * - * * - * Assumes that the axis given is one generated from a cross product of one of the edge and * - * basis vectors. In this case, the box extent can be optimized and only two triangle verts * - * need to be checked. * - * * - * INPUT: * - * * - * OUTPUT: * - * true = objects are SEPARATED * - * * - * WARNINGS: * - * * - * HISTORY: * - * 4/8/99 GTH : Created. * - *=============================================================================================*/ -static inline bool obbtri_check_collision_cross_axis -( - BTCollisionStruct & context, - float dp, - int dpi, - float leb0 -) -{ - float p0; // distance from box center to vertex 0 - float axismove; // size of the move along the axis. - float leb1; // final coordinate of the leading edge of the box - float lp; // leading edge of the polygon. - - p0 = Vector3::Dot_Product(context.D,context.TestAxis); - axismove = Vector3::Dot_Product(context.Move,context.TestAxis); - - // I want the axis centered at the box, pointing towards the triangle - if (p0 < 0) { - p0 = -p0; - axismove = -axismove; - dp = -dp; - context.TestAxis = -context.TestAxis; - context.TestSide = -1.0f; - } else { - context.TestSide = 1.0f; - } - - // compute coordinates of the leading edge of the box at t1 - leb1 = leb0 + axismove; - - // compute coordinate of "leading edge of the triangle" relative to the box center. - lp = 0; context.TestPoint = 0; - if (dp < 0) { lp = dp; context.TestPoint = dpi; } - lp = p0 + lp; - - return obbtri_collision_separation_test(context,lp,leb0,leb1); -} - - -/*********************************************************************************************** - * obbtri_check_collision_basis_axis -- projects the obb and tri onto a basis axis * - * * - * Projects the box and triangle onto an axis that is assumed to be a basis * - * vector from the box. In this case, we can skip a dot-product and use the * - * corresponding extent of the box (which is passed in as leb0). * - * * - * INPUT: * - * * - * OUTPUT: * - * true = objects are SEPARATED * - * * - * WARNINGS: * - * * - * HISTORY: * - * 4/8/99 GTH : Created. * - *=============================================================================================*/ -static inline bool obbtri_check_collision_basis_axis -( - BTCollisionStruct & context, - float leb0, - float dp1, - float dp2 -) -{ - float dist; // separation along the axis - float axismove; // size of the move along the axis. - float leb1; // final coordinate of the leading edge of the box - float lp; // leading edge of the polygon. - - dist = Vector3::Dot_Product(context.D,context.TestAxis); - axismove = Vector3::Dot_Product(context.Move,context.TestAxis); - - // we want the axis centered at the box, pointing towards the triangle - if (dist < 0) { - dist = -dist; - axismove = -axismove; - dp1 = -dp1; - dp2 = -dp2; - context.TestAxis = -context.TestAxis; - context.TestSide = -1.0f; - } else { - context.TestSide = 1.0f; - } - - // this is the "optimization", leb0 = one of the extents - leb1 = leb0 + axismove; - - // compute coordinate of "leading edge of the polygon" relative to the box center. - lp = 0; context.TestPoint = 0; - if (dp1 < lp) { lp = dp1; context.TestPoint = 1; } - if (dp2 < lp) { lp = dp2; context.TestPoint = 2; } - lp = dist + lp; - - return obbtri_collision_separation_test(context,lp,leb0,leb1); -} - - -/*********************************************************************************************** - * obbtri_check_collision_normal_axis -- project the box and tri onto the tri-normal * - * * - * Projects the box and triangle onto an axis that is assumed to be the normal * - * vector from the triangle. In this case, the triangle extents are zero. * - * * - * INPUT: * - * * - * OUTPUT: * - * true = objects are SEPARATED * - * * - * WARNINGS: * - * * - * HISTORY: * - * 4/8/99 GTH : Created. * - *=============================================================================================*/ -static inline bool obbtri_check_collision_normal_axis(BTCollisionStruct & context) -{ - float dist; // separation along the axis - float axismove; // size of the move along the axis. - float leb0; // initial coordinate of the leading edge of the box - float leb1; // final coordinate of the leading edge of the box - float lp; // leading edge of the polygon. - - dist = Vector3::Dot_Product(context.D,context.TestAxis); - axismove = Vector3::Dot_Product(context.Move,context.TestAxis); - - // we want the axis centered at the box, pointing towards the triangle - if (dist < 0) { - dist = -dist; - axismove = -axismove; - context.TestAxis = -context.TestAxis; - context.TestSide = -1.0f; - } else { - context.TestSide = 1.0f; - } - - leb0 = context.Box.Extent.X * WWMath::Fabs(context.AN[0]) + - context.Box.Extent.Y * WWMath::Fabs(context.AN[1]) + - context.Box.Extent.Z * WWMath::Fabs(context.AN[2]); - leb1 = leb0 + axismove; - context.TestPoint = 0; - lp = dist; // this is the "optimization", don't have to find lp - - return obbtri_collision_separation_test(context,lp,leb0,leb1); -} - -/*********************************************************************************************** - * eval_side -- returns -1,0,+1 depending on the sign of val and side * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 4/8/99 GTH : Created. * - *=============================================================================================*/ -static inline float eval_side(float val,int side) -{ - if (val > 0.0f) { - return side; - } else if (val < 0.0f) { - return -side; - } else { - return 0.0f; - } -} - -/*********************************************************************************************** - * obbtri_compute_contact_normal -- computes the normal of the collision * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 4/8/99 GTH : Created. * - *=============================================================================================*/ -static inline void obbtri_compute_contact_normal -( - const BTCollisionStruct & context, - CastResultStruct * result -) -{ - switch(context.AxisId) - { - case INTERSECTION: -// WWASSERT(0); - break; - case AXIS_N: - result->Normal = -context.Side * *context.Tri.N; - break; - case AXIS_A0: - result->Normal = -context.Side * context.A[0]; - break; - case AXIS_A1: - result->Normal = -context.Side * context.A[1]; - break; - case AXIS_A2: - result->Normal = -context.Side * context.A[2]; - break; - case AXIS_A0E0: - result->Normal = -context.Side * context.AxE[0][0]; - result->Normal.Normalize(); - break; - case AXIS_A1E0: - result->Normal = -context.Side * context.AxE[1][0]; - result->Normal.Normalize(); - break; - case AXIS_A2E0: - result->Normal = -context.Side * context.AxE[2][0]; - result->Normal.Normalize(); - break; - case AXIS_A0E1: - result->Normal = -context.Side * context.AxE[0][1]; - result->Normal.Normalize(); - break; - case AXIS_A1E1: - result->Normal = -context.Side * context.AxE[1][1]; - result->Normal.Normalize(); - break; - case AXIS_A2E1: - result->Normal = -context.Side * context.AxE[2][1]; - result->Normal.Normalize(); - break; - case AXIS_A0E2: - result->Normal = -context.Side * context.AxE[0][2]; - result->Normal.Normalize(); - break; - case AXIS_A1E2: - result->Normal = -context.Side * context.AxE[1][2]; - result->Normal.Normalize(); - break; - case AXIS_A2E2: - result->Normal = -context.Side * context.AxE[2][2]; - result->Normal.Normalize(); - break; - } - WWASSERT(result->Normal.Length2() > 0.0f); -} - - -/*********************************************************************************************** - * eval_A0_point -- contact point parameters for A0xEx * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 4/8/99 GTH : Created. * - *=============================================================================================*/ -static inline void eval_A0_point(const BTCollisionStruct & context,float * x,int edge) -{ - float yval,den; - Vector3 DxE; - - x[1] = -eval_side(context.AE[2][edge],context.Side) * context.Box.Extent[1]; - x[2] = eval_side(context.AE[1][edge],context.Side) * context.Box.Extent[2]; - if (context.Point == 0) { yval = 0.0f; } else { yval = 1.0f; } - - den = Vector3::Dot_Product(context.N,context.AxE[0][edge]); - if (WWMath::Fabs(den) > 0.0f) { - - Vector3::Cross_Product(context.FinalD,context.E[edge],&DxE); - x[0] = Vector3::Dot_Product(context.N,DxE); - if (edge == 0) { - x[0] -= context.N.Length2() * yval; - } else { - x[0] += context.N.Length2() * yval; - } - x[0] -= Vector3::Dot_Product(context.N,context.AxE[1][edge]) * x[1]; - x[0] -= Vector3::Dot_Product(context.N,context.AxE[2][edge]) * x[2]; - x[0] /= den; - - } else { - - x[0] = 0.0f; - - } -} - - -/*********************************************************************************************** - * eval_A1_point -- contact point parameters for A1xEx * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 4/8/99 GTH : Created. * - *=============================================================================================*/ -static inline void eval_A1_point(const BTCollisionStruct & context,float * x,int edge) -{ - float yval,den; - Vector3 DxE; - - x[0] = eval_side(context.AE[2][edge],context.Side) * context.Box.Extent[0]; - x[2] = -eval_side(context.AE[0][edge],context.Side) * context.Box.Extent[2]; - if (context.Point == 0) { yval = 0.0f; } else { yval = 1.0f; } - - den = Vector3::Dot_Product(context.N,context.AxE[1][edge]); - if (WWMath::Fabs(den) > 0.0f) { - - Vector3::Cross_Product(context.FinalD,context.E[edge],&DxE); - x[1] = Vector3::Dot_Product(context.N,DxE); - if (edge == 0) { - x[1] -= context.N.Length2() * yval; - } else { - x[1] += context.N.Length2() * yval; - } - x[1] -= Vector3::Dot_Product(context.N,context.AxE[0][edge]) * x[0]; - x[1] -= Vector3::Dot_Product(context.N,context.AxE[2][edge]) * x[2]; - x[1] /= den; - - } else { - - x[1] = 0.0f; - - } -} - -/*********************************************************************************************** - * eval_A2_point -- contact point parameters for A2xEx * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 4/8/99 GTH : Created. * - *=============================================================================================*/ -static inline void eval_A2_point(const BTCollisionStruct & context,float * x,int edge) -{ - float yval,den; - Vector3 DxE; - - x[0] = -eval_side(context.AE[1][edge],context.Side) * context.Box.Extent[0]; - x[1] = eval_side(context.AE[0][edge],context.Side) * context.Box.Extent[1]; - if (context.Point == 0) { yval = 0.0f; } else { yval = 1.0f; } - - den = Vector3::Dot_Product(context.N,context.AxE[2][edge]); - if (WWMath::Fabs(den) > 0.0f) { - - Vector3::Cross_Product(context.FinalD,context.E[edge],&DxE); - x[2] = Vector3::Dot_Product(context.N,DxE); - if (edge == 0) { - x[2] -= context.N.Length2() * yval; - } else { - x[2] += context.N.Length2() * yval; - } - x[2] -= Vector3::Dot_Product(context.N,context.AxE[0][edge]) * x[0]; - x[2] -= Vector3::Dot_Product(context.N,context.AxE[1][edge]) * x[1]; - x[2] /= den; - - } else { - - x[2] = 0.0f; - - } -} - - -/*********************************************************************************************** - * obbtri_compute_contact_point -- compute the contact point * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 4/8/99 GTH : Created. * - *=============================================================================================*/ -static inline void obbtri_compute_contact_point -( - BTCollisionStruct & context, - CastResultStruct * result -) -{ - int i; - float x[3]; - - if (context.AxisId >= AXIS_A0E0) { - Vector3 newc = context.Box.Center + result->Fraction * context.BoxMove; - Vector3 newv0 = *context.Tri.V[0] + result->Fraction * context.TriMove; - context.FinalD = newv0 - newc; - } - - switch (context.AxisId) - { - - case INTERSECTION: - WWASSERT(0); - return; - - case AXIS_N: // part of the box is touching the face of the triangle - - for (i = 0; i < 3; i++) { - x[i] = eval_side(context.AN[i],context.Side) * context.Box.Extent[i]; - } - break; - - case AXIS_A0: // part of the triangle is touching a face of the box - case AXIS_A1: - case AXIS_A2: - - if (context.Point == 0) { - result->ContactPoint = *context.Tri.V[0]; - } else if (context.Point == 1) { - result->ContactPoint = *context.Tri.V[1]; - } else { - result->ContactPoint = *context.Tri.V[2]; - } - Vector3::Add(result->ContactPoint,result->Fraction * context.TriMove,&(result->ContactPoint)); - return; - - case AXIS_A0E0: // one of the x-aligned edges of the box is contacting edge0 - eval_A0_point(context,x,0); - break; - - case AXIS_A0E1: // one of the x-aligned edges of the box is contacting edge1 - eval_A0_point(context,x,1); - break; - - case AXIS_A0E2: // one of the x-aligned edges of the box is contacting edge2 - eval_A0_point(context,x,2); - break; - - case AXIS_A1E0: // one of the y-aligned edges of the box is contacting edge0 - eval_A1_point(context,x,0); - break; - - case AXIS_A1E1: // one of the y-aligned edges of the box is contacting edge1 - eval_A1_point(context,x,1); - break; - - case AXIS_A1E2: // one of the y-aligned edges of the box is contacting edge2 - eval_A1_point(context,x,2); - break; - - case AXIS_A2E0: // one of the z-aligned edges of the box is contacting edge0 - eval_A2_point(context,x,0); - break; - - case AXIS_A2E1: // one of the z-aligned edges of the box is contacting edge1 - eval_A2_point(context,x,1); - break; - - case AXIS_A2E2: // one of the z-aligned edges of the box is contacting edge3 - eval_A2_point(context,x,2); - break; - - } - - /* - ** In certain circumstances, the x's computed above are outside the size of - ** the box. I have tracked at least one of these cases to a situation where the - ** separating axis is the triangle normal but one of the AxE axes also lines up - ** with the normal. In this case, the Normal was 0,0,25 and the A0xE0 axis - ** was 0,0,5. When the fraction was calculated for both of these, they were - ** the same up to the six decimal places that MSVC will show me in the debugger. - ** However, the fraction computed for the 0,0,5 axis was larger by some very small - ** amount. This causes it to be used as the "separating axis". Looks like floating - ** point roundoff error to me. The problem is that since the axis was perpendicular - ** to the triangle, the "nearest-point" logic chose V0 which resulted in the - ** calculation for x[0] being way off. The equations for finding the contact point - ** in the AxE axis case assume that the axis is not normal to the triangle since - ** that should be handled in the simpler routine for the N separating axis... - ** Since I am at a loss for how to deal with this problem, I'm going to clamp all - ** of the x's to be within the box here... - */ - if (x[0] > context.Box.Extent.X) { - x[0] = context.Box.Extent.X; - } else if (x[0] < -context.Box.Extent.X) { - x[0] = -context.Box.Extent.X; - } - - if (x[1] > context.Box.Extent.Y) { - x[1] = context.Box.Extent.Y; - } else if (x[1] < -context.Box.Extent.Y) { - x[1] = -context.Box.Extent.Y; - } - - if (x[2] > context.Box.Extent.Z) { - x[2] = context.Box.Extent.Z; - } else if (x[2] < -context.Box.Extent.Z) { - x[2] = -context.Box.Extent.Z; - } - - /* - ** Now, compute the point - */ - result->ContactPoint.X = context.Box.Center.X + - x[0]*context.A[0].X + - x[1]*context.A[1].X + - x[2]*context.A[2].X; - - result->ContactPoint.Y = context.Box.Center.Y + - x[0]*context.A[0].Y + - x[1]*context.A[1].Y + - x[2]*context.A[2].Y; - - result->ContactPoint.Z = context.Box.Center.Z + - x[0]*context.A[0].Z + - x[1]*context.A[1].Z + - x[2]*context.A[2].Z; - - Vector3::Add(result->ContactPoint,result->Fraction * context.BoxMove,&(result->ContactPoint)); -} - - - -/*********************************************************************************************** - * CollisionMath::Collide -- collide an obbox into a triangle * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 4/8/99 GTH : Created. * - *=============================================================================================*/ -bool CollisionMath::Collide -( - const OBBoxClass & box, - const Vector3 & move, - const TriClass & tri, - const Vector3 & trimove, - CastResultStruct * result -) -{ - TRACK_COLLISION_OBBOX_TRI; - float dp,leb0; - BTCollisionStruct context(box,move,tri,trimove); - - /* - ** AXIS_N - */ - context.TestAxis = context.N; - context.TestAxisId = AXIS_N; - context.AN[0] = Vector3::Dot_Product(context.A[0],context.N); - context.AN[1] = Vector3::Dot_Product(context.A[1],context.N); - context.AN[2] = Vector3::Dot_Product(context.A[2],context.N); - if (obbtri_check_collision_normal_axis(context)) goto exit; - - /* - ** AXIS_A0 - */ - context.TestAxis = context.A[0]; - context.TestAxisId = AXIS_A0; - context.AE[0][0] = Vector3::Dot_Product(context.A[0],context.E[0]); - context.AE[0][1] = Vector3::Dot_Product(context.A[0],context.E[1]); - if (obbtri_check_collision_basis_axis(context,box.Extent.X,context.AE[0][0],context.AE[0][1])) goto exit; - - /* - ** AXIS_A1 - */ - context.TestAxis = context.A[1]; - context.TestAxisId = AXIS_A1; - context.AE[1][0] = Vector3::Dot_Product(context.A[1],context.E[0]); - context.AE[1][1] = Vector3::Dot_Product(context.A[1],context.E[1]); - if (obbtri_check_collision_basis_axis(context,box.Extent.Y,context.AE[1][0],context.AE[1][1])) goto exit; - - /* - ** AXIS_A2 - */ - context.TestAxis = context.A[2]; - context.TestAxisId = AXIS_A2; - context.AE[2][0] = Vector3::Dot_Product(context.A[2],context.E[0]); - context.AE[2][1] = Vector3::Dot_Product(context.A[2],context.E[1]); - if (obbtri_check_collision_basis_axis(context,box.Extent.Z,context.AE[2][0],context.AE[2][1])) goto exit; - - /* - ** AXIS_A0xE0 - */ - Vector3::Cross_Product(context.A[0],context.E[0],&context.AxE[0][0]); - context.TestAxis = context.AxE[0][0]; - context.TestAxisId = AXIS_A0E0; - if (context.TestAxis.Length2() > AXISLEN_EPSILON2) { - dp = context.AN[0]; - leb0 = box.Extent[1]*WWMath::Fabs(context.AE[2][0]) + box.Extent[2]*WWMath::Fabs(context.AE[1][0]); - if (obbtri_check_collision_cross_axis(context,dp,2,leb0)) goto exit; - } - - /* - ** AXIS_A0xE1 - */ - Vector3::Cross_Product(context.A[0],context.E[1],&context.AxE[0][1]); - context.TestAxis = context.AxE[0][1]; - context.TestAxisId = AXIS_A0E1; - if (context.TestAxis.Length2() > AXISLEN_EPSILON2) { - dp = -context.AN[0]; - leb0 = box.Extent[1]*WWMath::Fabs(context.AE[2][1]) + box.Extent[2]*WWMath::Fabs(context.AE[1][1]); - if (obbtri_check_collision_cross_axis(context,dp,1,leb0)) goto exit; - } - - /* - ** AXIS_A0xE2 - */ - Vector3::Cross_Product(context.A[0],context.E[2],&context.AxE[0][2]); - context.TestAxis = context.AxE[0][2]; - context.TestAxisId = AXIS_A0E2; - context.AE[1][2] = Vector3::Dot_Product(context.A[1],context.E[2]); - context.AE[2][2] = Vector3::Dot_Product(context.A[2],context.E[2]); - if (context.TestAxis.Length2() > AXISLEN_EPSILON2) { - dp = -context.AN[0]; - leb0 = box.Extent[1]*WWMath::Fabs(context.AE[2][2]) + box.Extent[2]*WWMath::Fabs(context.AE[1][2]); - if (obbtri_check_collision_cross_axis(context,dp,1,leb0)) goto exit; - } - - /* - ** AXIS_A1xE0 - */ - Vector3::Cross_Product(context.A[1],context.E[0],&context.AxE[1][0]); - context.TestAxis = context.AxE[1][0]; - context.TestAxisId = AXIS_A1E0; - if (context.TestAxis.Length2() > AXISLEN_EPSILON2) { - dp = context.AN[1]; - leb0 = box.Extent[0]*WWMath::Fabs(context.AE[2][0]) + box.Extent[2]*WWMath::Fabs(context.AE[0][0]); - if (obbtri_check_collision_cross_axis(context,dp,2,leb0)) goto exit; - } - - /* - ** AXIS_A1xE1 - */ - Vector3::Cross_Product(context.A[1],context.E[1],&context.AxE[1][1]); - context.TestAxis = context.AxE[1][1]; - context.TestAxisId = AXIS_A1E1; - if (context.TestAxis.Length2() > AXISLEN_EPSILON2) { - dp = -context.AN[1]; - leb0 = box.Extent[0]*WWMath::Fabs(context.AE[2][1]) + box.Extent[2]*WWMath::Fabs(context.AE[0][1]); - if (obbtri_check_collision_cross_axis(context,dp,1,leb0)) goto exit; - } - - /* - ** AXIS_A1xE2 - */ - Vector3::Cross_Product(context.A[1],context.E[2],&context.AxE[1][2]); - context.TestAxis = context.AxE[1][2]; - context.TestAxisId = AXIS_A1E2; - context.AE[0][2] = Vector3::Dot_Product(context.A[0],context.E[2]); - if (context.TestAxis.Length2() > AXISLEN_EPSILON2) { - dp = -context.AN[1]; - leb0 = box.Extent[0]*WWMath::Fabs(context.AE[2][2]) + box.Extent[2]*WWMath::Fabs(context.AE[0][2]); - if (obbtri_check_collision_cross_axis(context,dp,1,leb0)) goto exit; - } - - /* - ** AXIS_A2xE0 - */ - Vector3::Cross_Product(context.A[2],context.E[0],&context.AxE[2][0]); - context.TestAxis = context.AxE[2][0]; - context.TestAxisId = AXIS_A2E0; - if (context.TestAxis.Length2() > AXISLEN_EPSILON2) { - dp = context.AN[2]; - leb0 = box.Extent[0]*WWMath::Fabs(context.AE[1][0]) + box.Extent[1]*WWMath::Fabs(context.AE[0][0]); - if (obbtri_check_collision_cross_axis(context,dp,2,leb0)) goto exit; - } - - /* - ** AXIS_A2xE1 - */ - Vector3::Cross_Product(context.A[2],context.E[1],&context.AxE[2][1]); - context.TestAxis = context.AxE[2][1]; - context.TestAxisId = AXIS_A2E1; - if (context.TestAxis.Length2() > AXISLEN_EPSILON2) { - dp = -context.AN[2]; - leb0 = box.Extent[0]*WWMath::Fabs(context.AE[1][1]) + box.Extent[1]*WWMath::Fabs(context.AE[0][1]); - if (obbtri_check_collision_cross_axis(context,dp,1,leb0)) goto exit; - } - - /* - ** AXIS_A2xE2 - */ - Vector3::Cross_Product(context.A[2],context.E[2],&context.AxE[2][2]); - context.TestAxis = context.AxE[2][2]; - context.TestAxisId = AXIS_A2E2; - if (context.TestAxis.Length2() > AXISLEN_EPSILON2) { - dp = -context.AN[2]; - leb0 = box.Extent[0]*WWMath::Fabs(context.AE[1][2]) + box.Extent[1]*WWMath::Fabs(context.AE[0][2]); - if (obbtri_check_collision_cross_axis(context,dp,1,leb0)) goto exit; - } - - /* - ** Last ditch effort, check an axis based on the move vector - */ - if (!context.StartBad) { - context.TestPoint = context.Point; - context.TestAxisId = context.AxisId; - - Vector3::Cross_Product(context.Move,context.A[0],&context.TestAxis); - if (context.TestAxis.Length2() > AXISLEN_EPSILON2) { - if (obbtri_check_collision_axis(context)) goto exit; - } - Vector3::Cross_Product(context.Move,context.A[1],&context.TestAxis); - if (context.TestAxis.Length2() > AXISLEN_EPSILON2) { - if (obbtri_check_collision_axis(context)) goto exit; - } - Vector3::Cross_Product(context.Move,context.A[2],&context.TestAxis); - if (context.TestAxis.Length2() > AXISLEN_EPSILON2) { - if (obbtri_check_collision_axis(context)) goto exit; - } - } - -exit: - -#pragma message ("(gth) disabling an assert in obb->tri collision, investigate later\n") -#if 0 - WWASSERT((context.AxisId != INTERSECTION) || (context.StartBad)); -#else - if (context.AxisId == INTERSECTION) { - context.StartBad = true; - } -#endif - - /* - ** If the triangle and box are intersecting before the move, return that - ** result. - */ - if (context.StartBad) { - result->StartBad = true; - result->Fraction = 0.0f; - result->Normal = *tri.N; - TRACK_COLLISION_OBBOX_TRI_HIT; - return true; - } - - /* - ** If the fraction allowed is basically equal to the fraction allowed by - ** another polygon, try to pick the polygon which is least "edge-on" to the - ** move. - */ - if (context.MaxFrac < 0.0f) { - context.MaxFrac = 0.0f; - } - - if ((context.MaxFrac < 1.0f) && (context.MaxFrac <= result->Fraction)) { - - if ( (WWMath::Fabs(context.MaxFrac - result->Fraction) > WWMATH_EPSILON) || - (Vector3::Dot_Product(*(tri.N),move) < Vector3::Dot_Product(result->Normal,move)) ) - { - obbtri_compute_contact_normal(context,result); - } - - result->Fraction = context.MaxFrac; - - if (result->ComputeContactPoint) { - obbtri_compute_contact_point(context,result); - } - TRACK_COLLISION_OBBOX_TRI_HIT; - return true; - } - - return false; -} - - -/*********************************************************************************************** - - OBBox-Triangle Intersection - - The following code implements a simple boolean intersection check. It uses the same - algorithm as the collision function but can avoid some of the calculations. For a very - simple implementation of this algorithm, see Oriented_Box_Intersects_Tri in obbox.h - -***********************************************************************************************/ - -/** -** BTIntersectStruct -** Scratchpad variables for the OBBox-Triangle intersection functions. One instance -** of this structure will be used for all of the local variables and its pointer will be -** handed of to various inline functions for the axis tests. -** Note that much of the code needs the un-normalized triangle normal. For this reason, -** I have to compute N rather than copying it from the triangle. (commenting this to -** avoid re-generating a difficult to find bug that I had) -*/ -struct BTIntersectStruct -{ - BTIntersectStruct(const OBBoxClass &box,const TriClass &tri) : - Box(box), - Tri(tri) - { - Vector3::Subtract(*tri.V[0],box.Center,&D); // vector from center of box to vertex 0 - Vector3::Subtract(*tri.V[1],*tri.V[0],&E[0]); - Vector3::Subtract(*tri.V[2],*tri.V[0],&E[1]); - Vector3::Subtract(E[1],E[0],&E[2]); - - A[0].Set(box.Basis[0][0],box.Basis[1][0],box.Basis[2][0]); - A[1].Set(box.Basis[0][1],box.Basis[1][1],box.Basis[2][1]); - A[2].Set(box.Basis[0][2],box.Basis[1][2],box.Basis[2][2]); - - Vector3::Cross_Product(E[0],E[1],&N); - } - - Vector3 D; // Vector from the center of the box to v0 - float AE[3][3]; // Dot products of the Basis vectors and edges - float AN[3]; // Dot products of the Basis vectors and the normal - Vector3 AxE[3][3]; // Cross produts of the Basis vectors and edges - - Vector3 A[3]; // basis vectors for the box - Vector3 E[3]; // edge vectors for the triangle - Vector3 N; // normal (NOT normalized!!!) - - Vector3 TestAxis; // separating axis currently being tested - - const OBBoxClass & Box; - const TriClass & Tri; - -private: - - // not implemented - BTIntersectStruct(const BTIntersectStruct &); - BTIntersectStruct & operator = (const BTIntersectStruct &); -}; - - -/*********************************************************************************************** - * obbtri_intersection_separation_test -- test the projected extents for intersection * - * * - * Once the extents are projected onto the axis, this function contains * - * the logic that determines whether the box and triangle intersect. * - * * - * INPUT: * - * context - the BTIntersectStruct containing the data for this intersection test * - * lp - the leading edge of the polygon projected onto the axis * - * leb0 - the leading edge of the box projected onto the axis * - * * - * OUTPUT: * - * true = objects are separated * - * * - * WARNINGS: * - * * - * HISTORY: * - * 2/3/2000 gth : Created. * - *=============================================================================================*/ -static inline bool obbtri_intersection_separation_test -( - BTIntersectStruct & context, - float lp, - float leb0 -) -{ - /* - ** Only compute the normalized epsilon if we need to. - ** - compute 'EPSILON' normalized to the length of the axis - ** - If (I'm no more than 'EPSILON' embedded in the polygon) then the box and tri are separated - */ - float eps = 0.0f; - if (lp - leb0 <= 0.0f) { - eps = COLLISION_EPSILON * context.TestAxis.Length(); // trying to only compute epsilon if I have to - } - - return (lp - leb0 > -eps); -} - - -/*********************************************************************************************** - * obbtri_check_intersection_cross_axis -- intersection check for a "cross-product" axis * - * * - * axis being checked is a cross product between a triangle edge and a box basis vector * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * true = the objects are SEPARATED * - * * - * HISTORY: * - * 5/4/99 GTH : Created. * - *=============================================================================================*/ -static inline bool obbtri_check_intersection_cross_axis -( - BTIntersectStruct & context, - float dp, - float leb0 -) -{ - float p0; // distance from box center to vertex 0 - float lp; // leading edge of the polygon. - - p0 = Vector3::Dot_Product(context.D,context.TestAxis); - - // I want the axis centered at the box, pointing towards the triangle - if (p0 < 0) { - context.TestAxis = -context.TestAxis; - p0 = -p0; - dp = -dp; - } - - // compute coordinate of "leading edge of the triangle" relative to the box center. - lp = 0; - if (dp < 0) { lp = dp; } - lp = p0 + lp; - - return obbtri_intersection_separation_test(context,lp,leb0); -} - - -/*********************************************************************************************** - * obbtri_check_intersection_basis_axis -- intersection check for a basis axis * - * * - * axis being checked is one of the basis vectors for the box * - * * - * INPUT: * - * * - * OUTPUT: * - * true = the objects are SEPARATED * - * * - * WARNINGS: * - * * - * HISTORY: * - * 5/4/99 GTH : Created. * - *=============================================================================================*/ -static inline bool obbtri_check_intersection_basis_axis -( - BTIntersectStruct & context, - float leb0, - float dp1, - float dp2 -) -{ - float dist; // separation along the axis - float lp; // leading edge of the polygon. - - dist = Vector3::Dot_Product(context.D,context.TestAxis); - - // we want the axis centered at the box, pointing towards the triangle - if (dist < 0) { - context.TestAxis = -context.TestAxis; - dist = -dist; - dp1 = -dp1; - dp2 = -dp2; - } - - // compute coordinate of "leading edge of the polygon" relative to the box center. - lp = 0; - if (dp1 < lp) { lp = dp1; } - if (dp2 < lp) { lp = dp2; } - lp = dist + lp; - - return obbtri_intersection_separation_test(context,lp,leb0); -} - - -/*********************************************************************************************** - * obbtri_check_intersection_normal_axis -- intersection check for the triangle normal * - * * - * axis being checked is the triangle's normal * - * * - * INPUT: * - * * - * OUTPUT: * - * true = the objects are SEPARATED * - * * - * WARNINGS: * - * * - * HISTORY: * - * 5/4/99 GTH : Created. * - *=============================================================================================*/ -static inline bool obbtri_check_intersection_normal_axis -( - BTIntersectStruct & context -) -{ - float dist; // separation along the axis - float leb0; // initial coordinate of the leading edge of the box - float lp; // leading edge of the polygon. - - dist = Vector3::Dot_Product(context.D,context.TestAxis); - - // we want the axis centered at the box, pointing towards the triangle - if (dist < 0) { - context.TestAxis = -context.TestAxis; - dist = -dist; - } - - leb0 = context.Box.Extent.X * WWMath::Fabs(context.AN[0]) + - context.Box.Extent.Y * WWMath::Fabs(context.AN[1]) + - context.Box.Extent.Z * WWMath::Fabs(context.AN[2]); - lp = dist; // this is the "optimization", don't have to find lp - - return obbtri_intersection_separation_test(context,lp,leb0); -} - - -/*********************************************************************************************** - * CollisionMath::Intersection_Test -- Intersection check for an OBBox and a triangle * - * * - * INPUT: * - * box - obbox to be tested * - * tri - triangle to be tested * - * * - * OUTPUT: * - * true = objects INTERSECT * - * * - * WARNINGS: * - * note that the other inline functions are "quick-reject" functions which return true when * - * the objects are separated. * - * * - * HISTORY: * - * 5/4/99 GTH : Created. * - *=============================================================================================*/ -bool CollisionMath::Intersection_Test(const OBBoxClass & box,const TriClass & tri) -{ - float dp,leb0; - BTIntersectStruct context(box,tri); - - /* - ** AXIS_N - */ - context.TestAxis = context.N; - context.AN[0] = Vector3::Dot_Product(context.A[0],context.N); - context.AN[1] = Vector3::Dot_Product(context.A[1],context.N); - context.AN[2] = Vector3::Dot_Product(context.A[2],context.N); - if (obbtri_check_intersection_normal_axis(context)) return false; - - /* - ** AXIS_A0 - */ - context.TestAxis = context.A[0]; - context.AE[0][0] = Vector3::Dot_Product(context.A[0],context.E[0]); - context.AE[0][1] = Vector3::Dot_Product(context.A[0],context.E[1]); - if (obbtri_check_intersection_basis_axis(context,box.Extent.X,context.AE[0][0],context.AE[0][1])) return false; - - /* - ** AXIS_A1 - */ - context.TestAxis = context.A[1]; - context.AE[1][0] = Vector3::Dot_Product(context.A[1],context.E[0]); - context.AE[1][1] = Vector3::Dot_Product(context.A[1],context.E[1]); - if (obbtri_check_intersection_basis_axis(context,box.Extent.Y,context.AE[1][0],context.AE[1][1])) return false; - - /* - ** AXIS_A2 - */ - context.TestAxis = context.A[2]; - context.AE[2][0] = Vector3::Dot_Product(context.A[2],context.E[0]); - context.AE[2][1] = Vector3::Dot_Product(context.A[2],context.E[1]); - if (obbtri_check_intersection_basis_axis(context,box.Extent.Z,context.AE[2][0],context.AE[2][1])) return false; - - /* - ** AXIS_A0xE0 - */ - Vector3::Cross_Product(context.A[0],context.E[0],&context.AxE[0][0]); - context.TestAxis = context.AxE[0][0]; - if (context.TestAxis.Length2() > AXISLEN_EPSILON2) { - dp = context.AN[0]; - leb0 = box.Extent[1]*WWMath::Fabs(context.AE[2][0]) + box.Extent[2]*WWMath::Fabs(context.AE[1][0]); - if (obbtri_check_intersection_cross_axis(context,dp,leb0)) return false; - } - - /* - ** AXIS_A0xE1 - */ - Vector3::Cross_Product(context.A[0],context.E[1],&context.AxE[0][1]); - context.TestAxis = context.AxE[0][1]; - if (context.TestAxis.Length2() > AXISLEN_EPSILON2) { - dp = -context.AN[0]; - leb0 = box.Extent[1]*WWMath::Fabs(context.AE[2][1]) + box.Extent[2]*WWMath::Fabs(context.AE[1][1]); - if (obbtri_check_intersection_cross_axis(context,dp,leb0)) return false; - } - - /* - ** AXIS_A0xE2 - */ - Vector3::Cross_Product(context.A[0],context.E[2],&context.AxE[0][2]); - context.TestAxis = context.AxE[0][2]; - context.AE[1][2] = Vector3::Dot_Product(context.A[1],context.E[2]); - context.AE[2][2] = Vector3::Dot_Product(context.A[2],context.E[2]); - if (context.TestAxis.Length2() > AXISLEN_EPSILON2) { - dp = -context.AN[0]; - leb0 = box.Extent[1]*WWMath::Fabs(context.AE[2][2]) + box.Extent[2]*WWMath::Fabs(context.AE[1][2]); - if (obbtri_check_intersection_cross_axis(context,dp,leb0)) return false; - } - - /* - ** AXIS_A1xE0 - */ - Vector3::Cross_Product(context.A[1],context.E[0],&context.AxE[1][0]); - context.TestAxis = context.AxE[1][0]; - if (context.TestAxis.Length2() > AXISLEN_EPSILON2) { - dp = context.AN[1]; - leb0 = box.Extent[0]*WWMath::Fabs(context.AE[2][0]) + box.Extent[2]*WWMath::Fabs(context.AE[0][0]); - if (obbtri_check_intersection_cross_axis(context,dp,leb0)) return false; - } - - /* - ** AXIS_A1xE1 - */ - Vector3::Cross_Product(context.A[1],context.E[1],&context.AxE[1][1]); - context.TestAxis = context.AxE[1][1]; - if (context.TestAxis.Length2() > AXISLEN_EPSILON2) { - dp = -context.AN[1]; - leb0 = box.Extent[0]*WWMath::Fabs(context.AE[2][1]) + box.Extent[2]*WWMath::Fabs(context.AE[0][1]); - if (obbtri_check_intersection_cross_axis(context,dp,leb0)) return false; - } - - /* - ** AXIS_A1xE2 - */ - Vector3::Cross_Product(context.A[1],context.E[2],&context.AxE[1][2]); - context.TestAxis = context.AxE[1][2]; - context.AE[0][2] = Vector3::Dot_Product(context.A[0],context.E[2]); - if (context.TestAxis.Length2() > AXISLEN_EPSILON2) { - dp = -context.AN[1]; - leb0 = box.Extent[0]*WWMath::Fabs(context.AE[2][2]) + box.Extent[2]*WWMath::Fabs(context.AE[0][2]); - if (obbtri_check_intersection_cross_axis(context,dp,leb0)) return false; - } - - /* - ** AXIS_A2xE0 - */ - Vector3::Cross_Product(context.A[2],context.E[0],&context.AxE[2][0]); - context.TestAxis = context.AxE[2][0]; - if (context.TestAxis.Length2() > AXISLEN_EPSILON2) { - dp = context.AN[2]; - leb0 = box.Extent[0]*WWMath::Fabs(context.AE[1][0]) + box.Extent[1]*WWMath::Fabs(context.AE[0][0]); - if (obbtri_check_intersection_cross_axis(context,dp,leb0)) return false; - } - - /* - ** AXIS_A2xE1 - */ - Vector3::Cross_Product(context.A[2],context.E[1],&context.AxE[2][1]); - context.TestAxis = context.AxE[2][1]; - if (context.TestAxis.Length2() > AXISLEN_EPSILON2) { - dp = -context.AN[2]; - leb0 = box.Extent[0]*WWMath::Fabs(context.AE[1][1]) + box.Extent[1]*WWMath::Fabs(context.AE[0][1]); - if (obbtri_check_intersection_cross_axis(context,dp,leb0)) return false; - } - - /* - ** AXIS_A2xE2 - */ - Vector3::Cross_Product(context.A[2],context.E[2],&context.AxE[2][2]); - context.TestAxis = context.AxE[2][2]; - if (context.TestAxis.Length2() > AXISLEN_EPSILON2) { - dp = -context.AN[2]; - leb0 = box.Extent[0]*WWMath::Fabs(context.AE[1][2]) + box.Extent[1]*WWMath::Fabs(context.AE[0][2]); - if (obbtri_check_intersection_cross_axis(context,dp,leb0)) return false; - } - - return true; -} - - - diff --git a/Generals/Code/Libraries/Source/WWVegas/WWMath/colmathplane.cpp b/Generals/Code/Libraries/Source/WWVegas/WWMath/colmathplane.cpp deleted file mode 100644 index f0822cccd91..00000000000 --- a/Generals/Code/Libraries/Source/WWVegas/WWMath/colmathplane.cpp +++ /dev/null @@ -1,197 +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 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 : WWMath * - * * - * $Archive:: /Commando/Code/wwmath/colmathplane.cpp $* - * * - * Org Author:: Greg Hjelstrom * - * * - * Author : Kenny Mitchell * - * * - * $Modtime:: 06/26/02 4:04p $* - * * - * $Revision:: 10 $* - * * - * 06/26/02 KM Matrix name change to avoid MAX conflicts * - *---------------------------------------------------------------------------------------------* - * Functions: * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - - -#include "colmath.h" -#include "colmathplane.h" -#include "aaplane.h" -#include "plane.h" -#include "lineseg.h" -#include "tri.h" -#include "sphere.h" -#include "aabox.h" -#include "obbox.h" -#include "wwdebug.h" - - - -CollisionMath::OverlapType -CollisionMath::Overlap_Test(const AAPlaneClass & plane,const Vector3 & point) -{ - float delta = point[plane.Normal] - plane.Dist; - if (delta > COINCIDENCE_EPSILON) { - return POS; - } - if (delta < -COINCIDENCE_EPSILON) { - return NEG; - } - return ON; -} - -CollisionMath::OverlapType -CollisionMath::Overlap_Test(const AAPlaneClass & plane,const LineSegClass & line) -{ - int mask = 0; - mask |= CollisionMath::Overlap_Test(plane,line.Get_P0()); - mask |= CollisionMath::Overlap_Test(plane,line.Get_P1()); - return eval_overlap_mask(mask); -} - -CollisionMath::OverlapType -CollisionMath::Overlap_Test(const AAPlaneClass & plane,const TriClass & tri) -{ - int mask = 0; - mask |= CollisionMath::Overlap_Test(plane,*tri.V[0]); - mask |= CollisionMath::Overlap_Test(plane,*tri.V[1]); - mask |= CollisionMath::Overlap_Test(plane,*tri.V[2]); - return eval_overlap_mask(mask); -} - -CollisionMath::OverlapType -CollisionMath::Overlap_Test(const AAPlaneClass & plane,const SphereClass & sphere) -{ - float delta = sphere.Center[plane.Normal] - plane.Dist; - if (delta > sphere.Radius) { - return POS; - } - if (delta < sphere.Radius) { - return NEG; - } - return BOTH; -} - -CollisionMath::OverlapType -CollisionMath::Overlap_Test(const AAPlaneClass & plane,const AABoxClass & box) -{ - float delta; - int mask = 0; - - // check the 'min' side of the box - delta = (box.Center[plane.Normal] - box.Extent[plane.Normal]) - plane.Dist; - if (delta > WWMATH_EPSILON) { - mask |= POS; - } else if (delta < -WWMATH_EPSILON) { - mask |= NEG; - } else { - mask |= ON; - } - - // check the 'max' side of the box - delta = (box.Center[plane.Normal] + box.Extent[plane.Normal]) - plane.Dist; - if (delta > WWMATH_EPSILON) { - mask |= POS; - } else if (delta < -WWMATH_EPSILON) { - mask |= NEG; - } else { - mask |= ON; - } - - return eval_overlap_mask(mask); -} - - -CollisionMath::OverlapType -CollisionMath::Overlap_Test(const AAPlaneClass & /*plane*/,const OBBoxClass & /*box*/) -{ -// TODO - WWASSERT(0); - return POS; -} - - -// Plane functions. Where is operand B with respect to the plane - -CollisionMath::OverlapType -CollisionMath::Overlap_Test(const PlaneClass & plane,const LineSegClass & line) -{ - int mask = 0; - mask |= CollisionMath::Overlap_Test(plane,line.Get_P0()); - mask |= CollisionMath::Overlap_Test(plane,line.Get_P1()); - return eval_overlap_mask(mask); -} - -CollisionMath::OverlapType -CollisionMath::Overlap_Test(const PlaneClass & plane,const TriClass & tri) -{ - int mask = 0; - mask |= CollisionMath::Overlap_Test(plane,*tri.V[0]); - mask |= CollisionMath::Overlap_Test(plane,*tri.V[1]); - mask |= CollisionMath::Overlap_Test(plane,*tri.V[2]); - return eval_overlap_mask(mask); -} - -CollisionMath::OverlapType -CollisionMath::Overlap_Test(const PlaneClass & plane,const SphereClass & sphere) -{ - float dist = Vector3::Dot_Product(sphere.Center,plane.N) - plane.D; - if (dist > sphere.Radius) { - return POS; - } - if (dist < -sphere.Radius) { - return NEG; - } - return BOTH; -} - -CollisionMath::OverlapType -CollisionMath::Overlap_Test(const PlaneClass & plane,const OBBoxClass & box) -{ - // rotate the plane normal into box coordinates - Vector3 local_normal; - Vector3 posfarpt; - Vector3 negfarpt; - Matrix3x3::Transpose_Rotate_Vector(box.Basis,plane.N,&local_normal); - - get_far_extent(local_normal,box.Extent,&posfarpt); - - // transform the two extreme box coordinates into world space - Matrix3x3::Rotate_Vector(box.Basis,posfarpt,&posfarpt); - negfarpt = -posfarpt; - posfarpt += box.Center; - negfarpt += box.Center; - - // overlap test - if (Overlap_Test(plane,negfarpt) == POS) { - return POS; - } - if (Overlap_Test(plane,posfarpt) == NEG) { - return NEG; - } - return BOTH; -} diff --git a/Generals/Code/Libraries/Source/WWVegas/WWMath/colmathplane.h b/Generals/Code/Libraries/Source/WWVegas/WWMath/colmathplane.h deleted file mode 100644 index 2c59e3c1624..00000000000 --- a/Generals/Code/Libraries/Source/WWVegas/WWMath/colmathplane.h +++ /dev/null @@ -1,154 +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 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 : WWMath * - * * - * $Archive:: /Commando/Code/wwmath/colmathplane.h $* - * * - * Original Author:: Greg Hjelstrom * - * * - * $Author:: Greg_h $* - * * - * $Modtime:: 3/29/00 4:42p $* - * * - * $Revision:: 2 $* - * * - *---------------------------------------------------------------------------------------------* - * Functions: * - * get_far_extent -- gets extents of a box projected onto an axis * - * CollisionMath::Overlap_Test -- Tests overlap between a plane and a point * - * CollisionMath::Overlap_Test -- Tests overlap between a plane and an AABox * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - - -#ifndef COLMATHPLANE_H -#define COLMATHPLANE_H - -#include "always.h" -#include "plane.h" -#include "aabox.h" - -/* -** Inline collision functions dealing with planes -** This module is meant to be included only in .CPP files after you include colmath.h -** It is not automatically included in order to reduce file dependencies... -*/ - -/*********************************************************************************************** - * get_far_extent -- gets extents of a box projected onto an axis * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 3/29/2000 gth : Created. * - *=============================================================================================*/ -inline void get_far_extent(const Vector3 & normal,const Vector3 & extent,Vector3 * posfarpt) -{ - if (WWMath::Fast_Is_Float_Positive(normal.X)) { - posfarpt->X = extent.X; - } else { - posfarpt->X = -extent.X; - } - - if (WWMath::Fast_Is_Float_Positive(normal.Y)) { - posfarpt->Y = extent.Y; - } else { - posfarpt->Y = -extent.Y; - } - - if (WWMath::Fast_Is_Float_Positive(normal.Z)) { - posfarpt->Z = extent.Z; - } else { - posfarpt->Z = -extent.Z; - } -} - - -/*********************************************************************************************** - * CollisionMath::Overlap_Test -- Tests overlap between a plane and a point * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 3/29/2000 gth : Created. * - *=============================================================================================*/ -inline -CollisionMath::OverlapType -CollisionMath::Overlap_Test(const PlaneClass & plane,const Vector3 & point) -{ - float delta = Vector3::Dot_Product(point,plane.N) - plane.D; - if (delta > COINCIDENCE_EPSILON) { - return POS; - } - if (delta < -COINCIDENCE_EPSILON) { - return NEG; - } - return ON; -} - - -/*********************************************************************************************** - * CollisionMath::Overlap_Test -- Tests overlap between a plane and an AABox * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 3/29/2000 gth : Created. * - *=============================================================================================*/ -inline -CollisionMath::OverlapType -CollisionMath::Overlap_Test(const PlaneClass & plane,const AABoxClass & box) -{ - // First, we determine the the near and far points of the box in the - // direction of the plane normal - Vector3 posfarpt; - Vector3 negfarpt; - - get_far_extent(plane.N,box.Extent,&posfarpt); - - negfarpt = -posfarpt; - posfarpt += box.Center; - negfarpt += box.Center; - if (Overlap_Test(plane,negfarpt) == POS) { - return POS; - } - if (Overlap_Test(plane,posfarpt) == NEG) { - return NEG; - } - return BOTH; -} - - -#endif - diff --git a/Generals/Code/Libraries/Source/WWVegas/WWMath/colmathsphere.cpp b/Generals/Code/Libraries/Source/WWVegas/WWMath/colmathsphere.cpp deleted file mode 100644 index 6a5f861a50f..00000000000 --- a/Generals/Code/Libraries/Source/WWVegas/WWMath/colmathsphere.cpp +++ /dev/null @@ -1,249 +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 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 : WWMath * - * * - * $Archive:: /Commando/Code/wwmath/colmathsphere.cpp $* - * * - * Author:: Greg Hjelstrom * - * * - * $Modtime:: 4/25/01 2:05p $* - * * - * $Revision:: 6 $* - * * - *---------------------------------------------------------------------------------------------* - * Functions: * - * CollisionMath::Intersection_Test -- Sphere - AAbox intersection * - * CollisionMath::Intersection_Test -- Sphere - OBBox intersection * - * CollisionMath::Overlap_Test -- Sphere - Point overlap test * - * CollisionMath::Overlap_Test -- sphere line overlap test * - * CollisionMath::Overlap_Test -- sphere triangle overlap test * - * CollisionMath::Overlap_Test -- Sphere - Sphere overlap test * - * CollisionMath::Overlap_Test -- Sphere - AABox overlap test * - * CollisionMath::Overlap_Test -- Sphere - OBBox overlap test * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - - -#include "colmath.h" -#include "aaplane.h" -#include "plane.h" -#include "lineseg.h" -#include "tri.h" -#include "sphere.h" -#include "aabox.h" -#include "obbox.h" -#include "wwdebug.h" - - -// Sphere Intersection fucntions. Does the sphere intersect the passed in object -/*********************************************************************************************** - * CollisionMath::Intersection_Test -- Sphere - AAbox intersection * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 4/25/2001 gth : Created. * - *=============================================================================================*/ -bool CollisionMath::Intersection_Test(const SphereClass & sphere,const AABoxClass & box) -{ - /* - ** Simple but slightly inaccurate test, expand the box by the sphere's radius, then - ** test whether the sphere is contained in that new box. This is actually testing - ** against a cube which encloses the sphere... - */ - Vector3 dc = box.Center - sphere.Center; - if (WWMath::Fabs(dc.X) < box.Extent.X + sphere.Radius) return false; - if (WWMath::Fabs(dc.Y) < box.Extent.Y + sphere.Radius) return false; - if (WWMath::Fabs(dc.Z) < box.Extent.Z + sphere.Radius) return false; - return true; -} - - -/*********************************************************************************************** - * CollisionMath::Intersection_Test -- Sphere - OBBox intersection * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 4/25/2001 gth : Created. * - *=============================================================================================*/ -bool CollisionMath::Intersection_Test(const SphereClass & sphere,const OBBoxClass & box) -{ - /* - ** Compute the sphere's position in the box's coordinate system - */ - Matrix3D tm(box.Basis,box.Center); - Vector3 box_rel_center; - Matrix3D::Inverse_Transform_Vector(tm,sphere.Center,&box_rel_center); - - if (box.Extent.X < WWMath::Fabs(box_rel_center.X)) return false; - if (box.Extent.Y < WWMath::Fabs(box_rel_center.Y)) return false; - if (box.Extent.Z < WWMath::Fabs(box_rel_center.Z)) return false; - - return true; -} - -// Sphere Overlap functions. Where is operand B with respect to the sphere -/*********************************************************************************************** - * CollisionMath::Overlap_Test -- Sphere - Point overlap test * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 4/25/2001 gth : Created. * - *=============================================================================================*/ -CollisionMath::OverlapType -CollisionMath::Overlap_Test(const SphereClass & sphere,const Vector3 & point) -{ - float r2 = (point - sphere.Center).Length2(); - if (r2 < sphere.Radius * sphere.Radius - COINCIDENCE_EPSILON) { - return NEG; - } - if (r2 > sphere.Radius * sphere.Radius + COINCIDENCE_EPSILON) { - return POS; - } - return ON; -} - - -/*********************************************************************************************** - * CollisionMath::Overlap_Test -- sphere line overlap test * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 4/25/2001 gth : Created. * - *=============================================================================================*/ -CollisionMath::OverlapType -CollisionMath::Overlap_Test(const SphereClass & /*sphere*/,const LineSegClass & /*line*/) -{ - WWASSERT(0); //TODO - return POS; -} - - -/*********************************************************************************************** - * CollisionMath::Overlap_Test -- sphere triangle overlap test * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 4/25/2001 gth : Created. * - *=============================================================================================*/ -CollisionMath::OverlapType -CollisionMath::Overlap_Test(const SphereClass & /*sphere*/,const TriClass & /*tri*/) -{ - WWASSERT(0); //TODO - return POS; -} - - -/*********************************************************************************************** - * CollisionMath::Overlap_Test -- Sphere - Sphere overlap test * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 4/25/2001 gth : Created. * - *=============================================================================================*/ -CollisionMath::OverlapType -CollisionMath::Overlap_Test(const SphereClass & sphere,const SphereClass & sphere2) -{ - CollisionMath::OverlapType retval = OUTSIDE; - - float radius = sphere.Radius + sphere2.Radius; - float dist2 = (sphere2.Center - sphere.Center).Length2(); - - if (dist2 == 0 && sphere.Radius == sphere2.Radius) { - retval = OVERLAPPED; - } else if (dist2 <= radius * radius - COINCIDENCE_EPSILON) { - retval = INSIDE; - } - - return retval; -} - - -/*********************************************************************************************** - * CollisionMath::Overlap_Test -- Sphere - AABox overlap test * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 4/25/2001 gth : Created. * - *=============================================================================================*/ -CollisionMath::OverlapType -CollisionMath::Overlap_Test(const SphereClass & sphere,const AABoxClass & aabox) -{ - // TODO: overlap function that detects containment? - return ( Intersection_Test(sphere,aabox) ? BOTH : POS ); -} - - -/*********************************************************************************************** - * CollisionMath::Overlap_Test -- Sphere - OBBox overlap test * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 4/25/2001 gth : Created. * - *=============================================================================================*/ -CollisionMath::OverlapType -CollisionMath::Overlap_Test(const SphereClass & sphere,const OBBoxClass & obbox) -{ - // TODO: overlap function that detects containment? - return ( Intersection_Test(sphere,obbox) ? BOTH : POS ); -} - - diff --git a/Generals/Code/Libraries/Source/WWVegas/WWMath/cullsys.cpp b/Generals/Code/Libraries/Source/WWVegas/WWMath/cullsys.cpp deleted file mode 100644 index aca4729f791..00000000000 --- a/Generals/Code/Libraries/Source/WWVegas/WWMath/cullsys.cpp +++ /dev/null @@ -1,154 +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 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 : WWMath * - * * - * $Archive:: /VSS_Sync/wwmath/cullsys.cpp $* - * * - * Author:: Greg Hjelstrom * - * * - * $Modtime:: 10/16/00 11:42a $* - * * - * $Revision:: 5 $* - * * - *---------------------------------------------------------------------------------------------* - * Functions: * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - -#include "cullsys.h" -#include "wwdebug.h" -#include "wwprofile.h" - - -/************************************************************************* -** -** CullableClass Implementation -** -*************************************************************************/ -CullableClass::CullableClass(void) : - CullLink(NULL), - NextCollected(NULL) -{ - CullBox.Init(Vector3(0,0,0),Vector3(1,1,1)); -} - -CullableClass::~CullableClass(void) -{ - // the cull system that contains us is responsible for any culling link - // so we better be out of it and it should have cleared our pointer before - // we are deleted. - WWASSERT(CullLink == NULL); -} - -void CullableClass::Set_Cull_Box(const AABoxClass & box,bool just_loaded) -{ - CullBox = box; - - WWPROFILE("Cullable::Set_Cull_Box"); - - // Just_loaded flag allows us to update the box without notifying the - // culling system. Use this when you've saved and loaded the linkage - // so you know you're in the right node of the culling system... - if (!just_loaded) { - CullSystemClass * sys = Get_Culling_System(); - if (sys != NULL) { - sys->Update_Culling(this); - } - } -} - -void CullableClass::Set_Culling_System(CullSystemClass * sys) -{ - if (CullLink) { - CullLink->Set_Culling_System(sys); - } -} - -CullSystemClass * CullableClass::Get_Culling_System(void) const -{ - if (CullLink) { - return CullLink->Get_Culling_System(); - } - return NULL; -} - - -/************************************************************************* -** -** CullSystemClass Implementation -** -** The base CullSystemClass mainly contains code for maintaining the -** current collection list and iterating through it. -** -*************************************************************************/ -CullSystemClass::CullSystemClass(void) : - CollectionHead(NULL) -{ -} - -CullSystemClass::~CullSystemClass(void) -{ -} - -// NOTE: THE Get_() functions currently are the same as the Peek_() functions (e.g., they do not -// add a Ref). This is wrong and will be fixed. -CullableClass * CullSystemClass::Get_First_Collected_Object_Internal(void) -{ - return CollectionHead; -} - -CullableClass * CullSystemClass::Get_Next_Collected_Object_Internal(CullableClass * obj) -{ - if (obj != NULL) { - return obj->NextCollected; - } - return NULL; -} - -CullableClass * CullSystemClass::Peek_First_Collected_Object_Internal(void) -{ - return CollectionHead; -} - -CullableClass * CullSystemClass::Peek_Next_Collected_Object_Internal(CullableClass * obj) -{ - if (obj != NULL) { - return obj->NextCollected; - } - return NULL; -} - -void CullSystemClass::Reset_Collection(void) -{ - CollectionHead = NULL; -} - -void CullSystemClass::Add_To_Collection(CullableClass * obj) -{ - WWASSERT(obj != NULL); - obj->NextCollected = CollectionHead; - CollectionHead = obj; -} - - - - diff --git a/Generals/Code/Libraries/Source/WWVegas/WWMath/cullsys.h b/Generals/Code/Libraries/Source/WWVegas/WWMath/cullsys.h deleted file mode 100644 index e23791d9f41..00000000000 --- a/Generals/Code/Libraries/Source/WWVegas/WWMath/cullsys.h +++ /dev/null @@ -1,201 +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 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 : WWMath * - * * - * $Archive:: /Commando/Code/wwmath/cullsys.h $* - * * - * Author:: Greg Hjelstrom * - * * - * $Modtime:: 5/08/01 6:33p $* - * * - * $Revision:: 5 $* - * * - *---------------------------------------------------------------------------------------------* - * Functions: * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - - -#if defined(_MSC_VER) -#pragma once -#endif - -#ifndef CULLSYS_H -#define CULLSYS_H - -#include "wwdebug.h" -#include "stdlib.h" -#include "refcount.h" -#include "aabox.h" - -class CullableClass; -class CullSystemClass; -class FrustumClass; - -/* -** CullLinkClass -** This class will serve as a base class for the various types of linkage information -** that the Cullable instances will need. Each CullableClass will have a pointer to -** a class derived from CullLinkClass where the different culling systems can store -** things. -*/ -class CullLinkClass -{ -public: - WWINLINE CullLinkClass(CullSystemClass * system) { System = system; WWASSERT(System); } - virtual ~CullLinkClass(void) { WWASSERT(System == NULL); } - - WWINLINE void Set_Culling_System(CullSystemClass * sys) { System = sys; } - WWINLINE CullSystemClass * Get_Culling_System(void) { return System; } - -protected: - CullSystemClass * System; -}; - - -/* -** CullableClass -** This is the base class for any object that can be inserted into a culling system -** This class provides an axis aligned bounding box and some linkage variables which -** allow it to be processed by any culling system. -*/ -class CullableClass : public RefCountClass -{ -public: - - CullableClass(void); - virtual ~CullableClass(void); - - /* - ** Access to the culling box for this object. When you set the cull box, you are - ** basically guaranteeing that the object is contained within the given box. The - ** object will automatically be updated in whatever culling system it is currently - ** contained in (if any) - */ - WWINLINE const AABoxClass & Get_Cull_Box(void) const { return CullBox; } - void Set_Cull_Box(const AABoxClass & box,bool just_loaded = false); - - /* - ** These functions are used by various culling systems to manage the linkage - ** pointers. *The average user should NEVER call these* - */ - void Set_Culling_System(CullSystemClass * sys); - CullSystemClass * Get_Culling_System(void) const; - WWINLINE void Set_Cull_Link(CullLinkClass * c) { CullLink = c; } - WWINLINE CullLinkClass * Get_Cull_Link(void) const { return CullLink; } - -private: - - WWINLINE void Set_Next_Collected(CullableClass * c) { NextCollected = c; } - WWINLINE CullableClass * Get_Next_Collected(void) { return NextCollected; } - - /* - ** Culling Data - ** Each object can be linked into various types of culling systems. - ** Each culling system can use its own linkage data structure (derived - ** from CullLinkClass) to keep track of the object. The CullData pointer - ** will point to one of the culling link objects and NULL - ** if its not in any system. - */ - CullLinkClass * CullLink; - - /* - ** Bounding Box - ** Any objects derived from Cullable should update the bounding box - ** whenever the object moves or changes size. In order to do this, - ** call Set_Cull_Box... - */ - AABoxClass CullBox; - - /* - ** NextCollected - ** This pointer is used by the culling system to keep a singly linked - ** list of cullable object that have been "collected". - */ - CullableClass * NextCollected; - - // Not Implemented: - CullableClass(const CullableClass & src); - CullableClass & operator = (const CullableClass & src); - - friend class CullSystemClass; -}; - - - - -/* -** CullSystemClass -** Base class of any culling system. This interface exists so that things can -** be shuffled around without having explicit knowledge of what system they are in. -*/ -class CullSystemClass -{ -public: - - CullSystemClass(void); - virtual ~CullSystemClass(void); - - /* - ** Collect_Objects. Updates the internal collection list with the - ** objects that overlap the given primitive. - ** WARNING: This builds an internal list that is only valid until - ** another list is built, only one list can be valid at any time. - ** WARNING: Always call Reset_Collection if you want to start a - ** fresh collection! - */ - void Reset_Collection(void); - virtual void Collect_Objects(const Vector3 & point) = 0; - virtual void Collect_Objects(const AABoxClass & box) = 0; - virtual void Collect_Objects(const OBBoxClass & box) = 0; - virtual void Collect_Objects(const FrustumClass & frustum) = 0; - - /* - ** This object has moved or changed size, update it - */ - virtual void Update_Culling(CullableClass * obj) = 0; - -protected: - - /* - ** Iterate through the collected objects - */ - CullableClass * Get_First_Collected_Object_Internal(void); - CullableClass * Get_Next_Collected_Object_Internal(CullableClass * obj); - CullableClass * Peek_First_Collected_Object_Internal(void); - CullableClass * Peek_Next_Collected_Object_Internal(CullableClass * obj); - - /* - ** Build the list of collected objects - */ - void Add_To_Collection(CullableClass * obj); - - /* - ** Pointer to the head of the current collection of objects - */ - CullableClass * CollectionHead; - - friend class CullableClass; -}; - - -#endif diff --git a/Generals/Code/Libraries/Source/WWVegas/WWMath/culltype.h b/Generals/Code/Libraries/Source/WWVegas/WWMath/culltype.h deleted file mode 100644 index 696b7443820..00000000000 --- a/Generals/Code/Libraries/Source/WWVegas/WWMath/culltype.h +++ /dev/null @@ -1,62 +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 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 : WWMath * - * * - * $Archive:: /Commando/Code/wwmath/culltype.h $* - * * - * Author:: Greg Hjelstrom * - * * - * $Modtime:: 10/23/98 2:34p $* - * * - * $Revision:: 3 $* - * * - *---------------------------------------------------------------------------------------------* - * Functions: * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - - -#if defined(_MSC_VER) -#pragma once -#endif - -#ifndef CULLTYPE_H -#define CULLTYPE_H - -#include "always.h" - -/* -** CullType is an enumeration of the possible results of a culling -** operation. It is placed here so that all of the different cull functions -** (which are scattered throughout WWMath, WW3D, WWPhys, etc) can -** communicate the result in a consistent way -*/ - -typedef enum CULLTYPE -{ - CULL_OUTSIDE = 0, // the object was completely outside the culling volume - CULL_INTERSECTING, // the object intersects an edge of the culling volume - CULL_INSIDE // the object is completely inside the culling volume -}; - - -#endif \ No newline at end of file diff --git a/Generals/Code/Libraries/Source/WWVegas/WWMath/curve.cpp b/Generals/Code/Libraries/Source/WWVegas/WWMath/curve.cpp deleted file mode 100644 index 4f2961b0671..00000000000 --- a/Generals/Code/Libraries/Source/WWVegas/WWMath/curve.cpp +++ /dev/null @@ -1,591 +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 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 : WWMath * - * * - * $Archive:: /VSS_Sync/wwmath/curve.cpp $* - * * - * Original Author:: Greg Hjelstrom * - * * - * $Author:: Vss_sync $* - * * - * $Modtime:: 6/13/01 2:18p $* - * * - * $Revision:: 9 $* - * * - *---------------------------------------------------------------------------------------------* - * Functions: * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - - -#include "curve.h" -#include "wwdebug.h" -#include "persistfactory.h" -#include "wwmathids.h" -#include "wwhack.h" - -/* -** Force-Link this module because the linker can't detect that we actually need it... -*/ -DECLARE_FORCE_LINK(curve); - -/* -** Persist factories and chunk-id's used to save and load. -*/ -SimplePersistFactoryClass _LinearCurve3DFactory; -SimplePersistFactoryClass _LinearCurve1DFactory; - -enum -{ - // ID's used by Curve3D - CURVE3D_CHUNK_VARIABLES = 0x00020651, - CURVE3D_CHUNK_KEYS, - - CURVE3D_VARIABLE_ISLOOPING = 0x00, - CURVE3D_VARIABLE_KEYCOUNT, - - // ID's used by LinearCurve3D - LINEARCURVE3D_CHUNK_CURVE3D = 0x00020653, - - // ID's used by Curve1D - CURVE1D_CHUNK_VARIABLES = 0x00020655, - CURVE1D_CHUNK_KEYS, - - CURVE1D_VARIABLE_ISLOOPING = 0x00, - CURVE1D_VARIABLE_KEYCOUNT, - - // ID's used by LinearCurve1D - LINEARCURVE1D_CHUNK_CURVE1D = 0x00020657, - -}; - - -/*********************************************************************************************** -** -** Curve3DCLass Implementation -** -***********************************************************************************************/ -Curve3DClass::Curve3DClass(void) : - IsLooping(false) -{ -} - -Curve3DClass::Curve3DClass(const Curve3DClass & that) -{ - *this = that; -} - -Curve3DClass::~Curve3DClass(void) -{ -} - -Curve3DClass & Curve3DClass::operator = (const Curve3DClass & that) -{ - IsLooping = that.IsLooping; - Keys = that.Keys; - return *this; -} - -bool Curve3DClass::Is_Looping(void) -{ - return IsLooping; -} - -void Curve3DClass::Set_Looping(bool onoff) -{ - IsLooping = onoff; -} - -float Curve3DClass::Get_Start_Time(void) -{ - if (Keys.Count() > 0) { - return Keys[0].Time; - } else { - return 0.0f; - } -} - -float Curve3DClass::Get_End_Time(void) -{ - if (Keys.Count() > 0) { - return Keys[Keys.Count() - 1].Time; - } else { - return 0.0f; - } -} - -int Curve3DClass::Key_Count(void) -{ - return Keys.Count(); -} - -void Curve3DClass::Get_Key(int i,Vector3 * set_point,float * set_t) -{ - assert(i >= 0); - assert(i < Keys.Count()); - if (set_point != NULL) { - *set_point = Keys[i].Point; - } - if (set_t != NULL) { - *set_t = Keys[i].Time; - } -} - -void Curve3DClass::Set_Key(int i,const Vector3 & point) -{ - assert(i >= 0); - assert(i < Keys.Count()); - Keys[i].Point = point; -} - - -int Curve3DClass::Add_Key(const Vector3 & point,float t) -{ - int idx = 0; - while (idx < Keys.Count() && Keys[idx].Time < t) { - idx++; - } - - KeyClass newkey; - newkey.Point = point; - newkey.Time = t; - - Keys.Insert(idx,newkey); - return idx; -} - -void Curve3DClass::Remove_Key(int i) -{ - assert(i >= 0); - assert(i < Keys.Count()); - Keys.Delete(i); -} - -void Curve3DClass::Clear_Keys(void) -{ - Keys.Clear(); -} - -void Curve3DClass::Find_Interval(float time,int * i0,int * i1,float * t) -{ - WWASSERT(time >= Keys[0].Time); - WWASSERT(time <= Keys[Keys.Count()-1].Time); - - int i=0; - while (time > Keys[i+1].Time) { - i++; - } - *i0 = i; - *i1 = i+1; - *t = (time - Keys[i].Time) / (Keys[i+1].Time - Keys[i].Time); -} - -bool Curve3DClass::Save(ChunkSaveClass & csave) -{ - int keycount = Keys.Count(); - csave.Begin_Chunk(CURVE3D_CHUNK_VARIABLES); - WRITE_MICRO_CHUNK(csave,CURVE3D_VARIABLE_ISLOOPING,IsLooping); - WRITE_MICRO_CHUNK(csave,CURVE3D_VARIABLE_KEYCOUNT,keycount); - csave.End_Chunk(); - - // Saving the keys, Note that if the format of a key changes we'll - // need a new chunk. (I didn't wrap each variable in its own chunk) - csave.Begin_Chunk(CURVE3D_CHUNK_KEYS); - for (int i=0; i= Keys[Keys.Count() - 1].Time) { - *set_val = Keys[Keys.Count() - 1].Point; - return; - } - - int i0,i1; - float t; - Find_Interval(time,&i0,&i1,&t); - - *set_val = Keys[i0].Point + t * (Keys[i1].Point - Keys[i0].Point); -} - -const PersistFactoryClass & LinearCurve3DClass::Get_Factory(void) const -{ - return _LinearCurve3DFactory; -} - -bool LinearCurve3DClass::Save(ChunkSaveClass & csave) -{ - csave.Begin_Chunk(LINEARCURVE3D_CHUNK_CURVE3D); - Curve3DClass::Save(csave); - csave.End_Chunk(); - return true; -} - -bool LinearCurve3DClass::Load(ChunkLoadClass & cload) -{ - while (cload.Open_Chunk()) { - - switch(cload.Cur_Chunk_ID()) - { - case LINEARCURVE3D_CHUNK_CURVE3D: - Curve3DClass::Load(cload); - break; - - default: - WWDEBUG_SAY(("Unhandled Chunk: 0x%X File: %s Line: %d\r\n",__FILE__,__LINE__)); - break; - } - cload.Close_Chunk(); - } - - return true; -} - - -/*********************************************************************************************** -** -** Curve1DClass -** -***********************************************************************************************/ -Curve1DClass::Curve1DClass(void) : - IsLooping(false) -{ -} - -Curve1DClass::Curve1DClass(const Curve1DClass & that) -{ - *this = that; -} - -Curve1DClass::~Curve1DClass(void) -{ -} - -Curve1DClass & Curve1DClass::operator = (const Curve1DClass & that) -{ - IsLooping = that.IsLooping; - Keys = that.Keys; - return *this; -} - -bool Curve1DClass::Is_Looping(void) -{ - return IsLooping; -} - -void Curve1DClass::Set_Looping(bool onoff) -{ - IsLooping = onoff; -} - -float Curve1DClass::Get_Start_Time(void) -{ - if (Keys.Count() > 0) { - return Keys[0].Time; - } else { - return 0.0f; - } -} - -float Curve1DClass::Get_End_Time(void) -{ - if (Keys.Count() > 0) { - return Keys[Keys.Count() - 1].Time; - } else { - return 0.0f; - } -} - -int Curve1DClass::Key_Count(void) -{ - return Keys.Count(); -} - -void Curve1DClass::Get_Key(int i,float * set_point,float * set_t,unsigned int * extra) -{ - assert(i >= 0); - assert(i < Keys.Count()); - if (set_point != NULL) { - *set_point = Keys[i].Point; - } - if (set_t != NULL) { - *set_t = Keys[i].Time; - } - if (extra != NULL) { - *extra = Keys[i].Extra; - } -} - -void Curve1DClass::Set_Key(int i,float point,unsigned int extra) -{ - assert(i >= 0); - assert(i < Keys.Count()); - Keys[i].Point = point; - Keys[i].Extra = extra; -} - - -int Curve1DClass::Add_Key(float point,float t,unsigned int extra) -{ - int idx = 0; - while (idx < Keys.Count() && Keys[idx].Time < t) { - idx++; - } - - KeyClass newkey; - newkey.Point = point; - newkey.Time = t; - newkey.Extra = extra; - - Keys.Insert(idx,newkey); - return idx; -} - -void Curve1DClass::Remove_Key(int i) -{ - assert(i >= 0); - assert(i < Keys.Count()); - Keys.Delete(i); -} - -void Curve1DClass::Clear_Keys(void) -{ - Keys.Clear(); -} - -void Curve1DClass::Find_Interval(float time,int * i0,int * i1,float * t) -{ - if (IsLooping) { - if (time < Keys[0].Time) { - *i0 = Keys.Count() - 1; - *i1 = 0; - float interval = 1.0f - Keys[*i0].Time + Keys[*i1].Time; - *t = (1.0f - Keys[*i0].Time + time) / interval; - return; - } - else if (time > Keys[Keys.Count() - 1].Time) { - *i0 = Keys.Count() - 1; - *i1 = 0; - float interval = 1.0f - Keys[*i0].Time + Keys[*i1].Time; - *t = (time - Keys[*i0].Time) / interval; - return; - } - } - else { - WWASSERT(time >= Keys[0].Time); - WWASSERT(time <= Keys[Keys.Count()-1].Time); - } - - int i=0; - while (time > Keys[i+1].Time) { - i++; - } - *i0 = i; - *i1 = i+1; - *t = (time - Keys[i].Time) / (Keys[i+1].Time - Keys[i].Time); -} - -bool Curve1DClass::Save(ChunkSaveClass & csave) -{ - int keycount = Keys.Count(); - csave.Begin_Chunk(CURVE1D_CHUNK_VARIABLES); - WRITE_MICRO_CHUNK(csave,CURVE1D_VARIABLE_ISLOOPING,IsLooping); - WRITE_MICRO_CHUNK(csave,CURVE1D_VARIABLE_KEYCOUNT,keycount); - csave.End_Chunk(); - - // Saving the keys, Note that if the format of a key changes we'll - // need a new chunk. (I didn't wrap each variable in its own chunk) - csave.Begin_Chunk(CURVE1D_CHUNK_KEYS); - for (int i=0; i= Keys[Keys.Count() - 1].Time) { - *set_val = Keys[Keys.Count() - 1].Point; - return; - } - } - - int i0,i1; - float t; - Find_Interval(time,&i0,&i1,&t); - - *set_val = Keys[i0].Point + t * (Keys[i1].Point - Keys[i0].Point); -} - -const PersistFactoryClass & LinearCurve1DClass::Get_Factory(void) const -{ - return _LinearCurve1DFactory; -} - -bool LinearCurve1DClass::Save(ChunkSaveClass & csave) -{ - csave.Begin_Chunk(LINEARCURVE1D_CHUNK_CURVE1D); - Curve1DClass::Save(csave); - csave.End_Chunk(); - return true; -} - -bool LinearCurve1DClass::Load(ChunkLoadClass & cload) -{ - while (cload.Open_Chunk()) { - - switch(cload.Cur_Chunk_ID()) - { - case LINEARCURVE1D_CHUNK_CURVE1D: - Curve1DClass::Load(cload); - break; - - default: - WWDEBUG_SAY(("Unhandled Chunk: 0x%X File: %s Line: %d\r\n",__FILE__,__LINE__)); - break; - } - cload.Close_Chunk(); - } - - return true; -} - - diff --git a/Generals/Code/Libraries/Source/WWVegas/WWMath/curve.h b/Generals/Code/Libraries/Source/WWVegas/WWMath/curve.h deleted file mode 100644 index e86d910c31a..00000000000 --- a/Generals/Code/Libraries/Source/WWVegas/WWMath/curve.h +++ /dev/null @@ -1,179 +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 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 : WWMath * - * * - * $Archive:: /VSS_Sync/wwmath/curve.h $* - * * - * Author:: Greg Hjelstrom * - * * - * $Modtime:: 6/13/01 2:18p $* - * * - * $Revision:: 8 $* - * * - *---------------------------------------------------------------------------------------------* - * Functions: * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - - -#if defined(_MSC_VER) -#pragma once -#endif - -#ifndef CURVE_H -#define CURVE_H - -#ifndef ALWAYS_H -#include "always.h" -#endif - -#ifndef VECTOR_H -#include "Vector.H" -#endif - -#ifndef VECTOR3_H -#include "vector3.h" -#endif - -#ifndef PERSIST_H -#include "persist.h" -#endif - -class ChunkLoadClass; -class ChunkSaveClass; - - -class Curve3DClass : public PersistClass -{ -public: - - Curve3DClass(void); - Curve3DClass(const Curve3DClass & that); - virtual ~Curve3DClass(void); - Curve3DClass & operator = (const Curve3DClass & that); - - virtual void Evaluate(float time,Vector3 * set_val) = 0; - virtual bool Is_Looping(void); - virtual void Set_Looping(bool onoff); - virtual int Key_Count(void); - virtual void Get_Key(int i,Vector3 * set_point,float * set_t); - virtual void Set_Key(int i,const Vector3 & point); - virtual int Add_Key(const Vector3 & point,float t); - virtual void Remove_Key(int i); - virtual void Clear_Keys(void); - float Get_Start_Time(void); - float Get_End_Time(void); - - // persistant object support - virtual bool Save (ChunkSaveClass &csave); - virtual bool Load (ChunkLoadClass &cload); - -protected: - - void Find_Interval(float time,int * i0,int * i1,float * t); - - class KeyClass - { - public: - Vector3 Point; - float Time; - bool operator == (const KeyClass & that) { return ((Point == that.Point) && (Time == that.Time)); } - bool operator != (const KeyClass & that) { return !KeyClass::operator==(that); } - }; - - bool IsLooping; - DynamicVectorClass Keys; -}; - - -class LinearCurve3DClass : public Curve3DClass -{ -public: - virtual void Evaluate(float time,Vector3 * set_val); - - // persistant object support - virtual const PersistFactoryClass & Get_Factory(void) const; - virtual bool Save(ChunkSaveClass &csave); - virtual bool Load(ChunkLoadClass &cload); -}; - - -/* -** 1-Dimensional curve classes. -*/ -class Curve1DClass : public PersistClass -{ -public: - - Curve1DClass(void); - Curve1DClass(const Curve1DClass & that); - virtual ~Curve1DClass(void); - Curve1DClass & operator = (const Curve1DClass & that); - - virtual void Evaluate(float time,float * set_val) = 0; - virtual bool Is_Looping(void); - virtual void Set_Looping(bool onoff); - virtual int Key_Count(void); - virtual void Get_Key(int i,float * set_point,float * set_t,unsigned int * extra=NULL); - virtual void Set_Key(int i,float point,unsigned int extra=0); - virtual int Add_Key(float point,float t,unsigned int extra=0); - virtual void Remove_Key(int i); - virtual void Clear_Keys(void); - float Get_Start_Time(void); - float Get_End_Time(void); - - // persistant object support - virtual bool Save (ChunkSaveClass &csave); - virtual bool Load (ChunkLoadClass &cload); - -protected: - - void Find_Interval(float time,int * i0,int * i1,float * t); - - class KeyClass - { - public: - float Point; - float Time; - unsigned int Extra; - bool operator == (const KeyClass & that) { return ((Point == that.Point) && (Time == that.Time) && (Extra == that.Extra)); } - bool operator != (const KeyClass & that) { return !KeyClass::operator==(that); } - }; - - bool IsLooping; - DynamicVectorClass Keys; -}; - - -class LinearCurve1DClass : public Curve1DClass -{ -public: - virtual void Evaluate(float time,float * set_val); - - // persistant object support - virtual const PersistFactoryClass & Get_Factory(void) const; - virtual bool Save(ChunkSaveClass &csave); - virtual bool Load(ChunkLoadClass &cload); -}; - - -#endif //CURVE_H diff --git a/Generals/Code/Libraries/Source/WWVegas/WWMath/euler.cpp b/Generals/Code/Libraries/Source/WWVegas/WWMath/euler.cpp deleted file mode 100644 index 4e15ea4ce5c..00000000000 --- a/Generals/Code/Libraries/Source/WWVegas/WWMath/euler.cpp +++ /dev/null @@ -1,373 +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 . -*/ - -/* $Header: /Commando/Code/wwmath/euler.cpp 5 4/27/01 11:51a Jani_p $ */ -/*********************************************************************************************** - *** Confidential - Westwood Studios *** - *********************************************************************************************** - * * - * Project Name : Commando / G Math Library * - * * - * $Archive:: /Commando/Code/wwmath/euler.cpp $* - * * - * Author:: Greg_h * - * * - * $Modtime:: 4/23/01 6:08p $* - * * - * $Revision:: 5 $* - * * - *---------------------------------------------------------------------------------------------* - * Functions: * - * EulerAnglesClass::EulerAnglesClass -- constructor * - * EulerAnglesClass::Get_Angle -- returns angle 'i' of the euler angles * - * EulerAnglesClass::From_Matrix -- computes the equivalent euler angles for the given matrix* - * EulerAnglesClass::To_Matrix -- Builds a matrix from the given euler angles * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - - -#include "euler.h" -#include - - -/********************************************************************* - - There are 24 possible conventions for Euler angles. They can - be designated by: - - EulerAxis = Axis used initially - EulerParity = parity of axis permutation (even = x,y,z) - EulerRepeat = is last axis a repeat of the initial axis? - EulerFrame = frame from which axes are taken (rotating or static) - - For example, in this system an euler angle convention of: - - Rotate_X(a0); - Rotate_Y(a1); - Rotate_Z(a2); - - would be described as EulerOrderXYZr. - -*********************************************************************/ - -#define EULER_FRAME_STATIC 0x00000000 -#define EULER_FRAME_ROTATING 0x00000001 -#define EULER_FRAME(order) ((unsigned)(order) & 1) - -#define EULER_REPEAT_NO 0x00000000 -#define EULER_REPEAT_YES 0x00000001 -#define EULER_REPEAT(order) (((unsigned)(order) >> 1) & 1) - -#define EULER_PARITY_EVEN 0x00000000 -#define EULER_PARITY_ODD 0x00000001 -#define EULER_PARITY(order) (((unsigned)(order) >> 2) & 1) - -#define EULER_BUILD_ORDER(i,p,r,f) (((((((i) << 1) + (p)) << 1) + (r)) << 1) + (f)) - - -/* static axes */ -int EulerOrderXYZs = EULER_BUILD_ORDER(0, EULER_PARITY_EVEN, EULER_REPEAT_NO, EULER_FRAME_STATIC); -int EulerOrderXYXs = EULER_BUILD_ORDER(0, EULER_PARITY_EVEN, EULER_REPEAT_YES, EULER_FRAME_STATIC); -int EulerOrderXZYs = EULER_BUILD_ORDER(0, EULER_PARITY_ODD, EULER_REPEAT_NO, EULER_FRAME_STATIC); -int EulerOrderXZXs = EULER_BUILD_ORDER(0, EULER_PARITY_ODD, EULER_REPEAT_YES, EULER_FRAME_STATIC); -int EulerOrderYZXs = EULER_BUILD_ORDER(1, EULER_PARITY_EVEN, EULER_REPEAT_NO, EULER_FRAME_STATIC); -int EulerOrderYZYs = EULER_BUILD_ORDER(1, EULER_PARITY_EVEN, EULER_REPEAT_YES, EULER_FRAME_STATIC); -int EulerOrderYXZs = EULER_BUILD_ORDER(1, EULER_PARITY_ODD, EULER_REPEAT_NO, EULER_FRAME_STATIC); -int EulerOrderYXYs = EULER_BUILD_ORDER(1, EULER_PARITY_ODD, EULER_REPEAT_YES, EULER_FRAME_STATIC); -int EulerOrderZXYs = EULER_BUILD_ORDER(2, EULER_PARITY_EVEN, EULER_REPEAT_NO, EULER_FRAME_STATIC); -int EulerOrderZXZs = EULER_BUILD_ORDER(2, EULER_PARITY_EVEN, EULER_REPEAT_YES, EULER_FRAME_STATIC); -int EulerOrderZYXs = EULER_BUILD_ORDER(2, EULER_PARITY_ODD, EULER_REPEAT_NO, EULER_FRAME_STATIC); -int EulerOrderZYZs = EULER_BUILD_ORDER(2, EULER_PARITY_ODD, EULER_REPEAT_YES, EULER_FRAME_STATIC); - -/* rotating axes */ -int EulerOrderZYXr = EULER_BUILD_ORDER(0, EULER_PARITY_EVEN, EULER_REPEAT_NO, EULER_FRAME_ROTATING); -int EulerOrderXYXr = EULER_BUILD_ORDER(0, EULER_PARITY_EVEN, EULER_REPEAT_YES, EULER_FRAME_ROTATING); -int EulerOrderYZXr = EULER_BUILD_ORDER(0, EULER_PARITY_ODD, EULER_REPEAT_NO, EULER_FRAME_ROTATING); -int EulerOrderXZXr = EULER_BUILD_ORDER(0, EULER_PARITY_ODD, EULER_REPEAT_YES, EULER_FRAME_ROTATING); -int EulerOrderXZYr = EULER_BUILD_ORDER(1, EULER_PARITY_EVEN, EULER_REPEAT_NO, EULER_FRAME_ROTATING); -int EulerOrderYZYr = EULER_BUILD_ORDER(1, EULER_PARITY_EVEN, EULER_REPEAT_YES, EULER_FRAME_ROTATING); -int EulerOrderZXYr = EULER_BUILD_ORDER(1, EULER_PARITY_ODD, EULER_REPEAT_NO, EULER_FRAME_ROTATING); -int EulerOrderYXYr = EULER_BUILD_ORDER(1, EULER_PARITY_ODD, EULER_REPEAT_YES, EULER_FRAME_ROTATING); -int EulerOrderYXZr = EULER_BUILD_ORDER(2, EULER_PARITY_EVEN, EULER_REPEAT_NO, EULER_FRAME_ROTATING); -int EulerOrderZXZr = EULER_BUILD_ORDER(2, EULER_PARITY_EVEN, EULER_REPEAT_YES, EULER_FRAME_ROTATING); -int EulerOrderXYZr = EULER_BUILD_ORDER(2, EULER_PARITY_ODD, EULER_REPEAT_NO, EULER_FRAME_ROTATING); -int EulerOrderZYZr = EULER_BUILD_ORDER(2, EULER_PARITY_ODD, EULER_REPEAT_YES, EULER_FRAME_ROTATING); - - -#define EULER_SAFE "\000\001\002\000" -#define EULER_NEXT "\001\002\000\001" - -#define EULER_AXIS_I(order) ((int)(EULER_SAFE[(((unsigned)(ord)>>3) & 3)])) -#define EULER_AXIS_J(order) ((int)(EULER_NEXT[EULER_AXIS_I(order) + (EULER_PARITY(order) == EULER_PARITY_ODD)])) -#define EULER_AXIS_K(order) ((int)(EULER_NEXT[EULER_AXIS_I(order) + (EULER_PARITY(order) != EULER_PARITY_ODD)])) -#define EULER_AXIS_H(order) ((EULER_REPEAT(order) == EULER_REPEAT_NO) ? EULER_AXIS_K(order) : EULER_AXIS_I(order)) - - - -/* local functions */ -static void _euler_unpack_order(int order,int &i,int &j,int &k,int &h,int &n,int &s,int &f); -static int _euler_axis_i(int order); -static int _euler_axis_j(int order); -static int _euler_axis_k(int order); -static int _euler_axis_h(int order); - - -/*********************************************************************************************** - * EulerAnglesClass::EulerAnglesClass -- constructor * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 08/11/1997 GH : Created. * - *=============================================================================================*/ -EulerAnglesClass::EulerAnglesClass(const Matrix3D & M,int order) -{ - this->From_Matrix(M,order); -} - -/*********************************************************************************************** - * EulerAnglesClass::Get_Angle -- returns angle 'i' of the euler angles * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 08/11/1997 GH : Created. * - *=============================================================================================*/ -double EulerAnglesClass::Get_Angle(int i) -{ - return Angle[i]; -} - -/*********************************************************************************************** - * EulerAnglesClass::From_Matrix -- computes the equivalent euler angles for the given matrix * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 08/11/1997 GH : Created. * - *=============================================================================================*/ -void EulerAnglesClass::From_Matrix(const Matrix3D & M, int order) -{ - int i,j,k,h,n,s,f; - - Order = order; - _euler_unpack_order(order,i,j,k,h,n,s,f); - - if (s == EULER_REPEAT_YES) { - double sy = sqrt(M[i][j]*M[i][j] + M[i][k]*M[i][k]); - - if (sy > 16*FLT_EPSILON) { - - Angle[0] = WWMath::Atan2(M[i][j],M[i][k]); - Angle[1] = WWMath::Atan2(sy,M[i][i]); - Angle[2] = WWMath::Atan2(M[j][i],-M[k][i]); - - } else { - - Angle[0] = WWMath::Atan2(-M[j][k],M[j][j]); - Angle[1] = WWMath::Atan2(sy,M[i][i]); - Angle[2] = 0.0; - } - - } else { - - double cy = sqrt(M[i][i]*M[i][i] + M[j][i]*M[j][i]); - - if (cy > 16*FLT_EPSILON) { - - Angle[0] = WWMath::Atan2(M[k][j],M[k][k]); - Angle[1] = WWMath::Atan2(-M[k][i],cy); - Angle[2] = WWMath::Atan2(M[j][i],M[i][i]); - - } else { - - Angle[0] = WWMath::Atan2(-M[j][k],M[j][j]); - Angle[1] = WWMath::Atan2(-M[k][i],cy); - Angle[2] = 0; - } - } - - if (n==EULER_PARITY_ODD) { Angle[0] = -Angle[0]; Angle[1] = -Angle[1]; Angle[2] = -Angle[2]; } - if (f==EULER_FRAME_ROTATING) { double t = Angle[0]; Angle[0] = Angle[2]; Angle[2] = t; } - - // Trying to "clean" up the eulers, special cased for XYZr - if (order == EulerOrderXYZr) { - - const double PI = 3.141592654; - - double x2 = PI + Angle[0]; - double y2 = PI - Angle[1]; - double z2 = PI + Angle[2]; - - if (x2 > PI) { - x2 = x2 - 2*PI; - } - - if (y2 > PI) { - y2 = y2 - 2*PI; - } - - if (z2 > PI) { - z2 = z2 - 2*PI; - } - - double mag0 = Angle[0]*Angle[0] + Angle[1]*Angle[1] + Angle[2]*Angle[2]; - double mag1 = x2*x2 + y2*y2 + z2*z2; - - if (mag1 < mag0) { - Angle[0] = x2; - Angle[1] = y2; - Angle[2] = z2; - } - } -} - - - -/*********************************************************************************************** - * EulerAnglesClass::To_Matrix -- Builds a matrix from the given euler angles * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 08/11/1997 GH : Created. * - *=============================================================================================*/ -void EulerAnglesClass::To_Matrix(Matrix3D & M) -{ - M.Make_Identity(); - - double a0,a1,a2; - double ti,tj,th,ci,cj,ch,si,sj,sh,cc,cs,sc,ss; - int i,j,k,h,n,s,f; - - a0 = Angle[0]; - a1 = Angle[1]; - a2 = Angle[2]; - - _euler_unpack_order(Order,i,j,k,h,n,s,f); - if (f == EULER_FRAME_ROTATING) { - double t = a0; a0 = a2; a2 = t; - } - - if (n == EULER_PARITY_ODD) { - a0 = -a0; a1 = -a1; a2 = -a2; - } - - ti = a0; tj = a1; th = a2; - ci = WWMath::Cos(ti); cj = WWMath::Cos(tj); ch = WWMath::Cos(th); - si = WWMath::Sin(ti); sj = WWMath::Sin(tj); sh = WWMath::Sin(th); - - cc = ci*ch; - cs = ci*sh; - sc = si*ch; - ss = si*sh; - - if (s == EULER_REPEAT_YES) { - - M[i][i] = (float)(cj); M[i][j] = (float)(sj*si); M[i][k] = (float)(sj*ci); - M[j][i] = (float)(sj*sh); M[j][j] = (float)(-cj*ss+cc); M[j][k] = (float)(-cj*cs-sc); - M[k][i] = (float)(-sj*ch); M[k][j] = (float)(cj*sc+cs); M[k][k] = (float)(cj*cc-ss); - - } else { - - M[i][i] = (float)(cj*ch); M[i][j] = (float)(sj*sc-cs); M[i][k] = (float)(sj*cc+ss); - M[j][i] = (float)(cj*sh); M[j][j] = (float)(sj*ss+cc); M[j][k] = (float)(sj*cs-sc); - M[k][i] = (float)(-sj); M[k][j] = (float)(cj*si); M[k][k] = (float)(cj*ci); - - } -} - - -/* -** Local functions -*/ - -static int _euler_safe[] = { 0,1,2,0 }; -static int _euler_next[] = { 1,2,0,1 }; - -int _euler_axis_i(int order) -{ - return _euler_safe[ (order>>3) & 3 ]; -} - -int _euler_axis_j(int order) -{ - int index = _euler_axis_i(order); - if (EULER_PARITY(order) == 1) { - index++; - } - - return _euler_next[ index ]; -} - -int _euler_axis_k(int order) -{ - int index = _euler_axis_i(order); - if (EULER_PARITY(order) != 1) { - index++; - } - - return _euler_next[ index ]; -} - -int _euler_axis_h(int order) -{ - if (EULER_REPEAT(order) == 1) { - return _euler_axis_k(order); - } else { - return _euler_axis_i(order); - } -} - -void _euler_unpack_order(int order,int &i,int &j,int &k,int &h,int &n,int &s,int &f) -{ - - f = order & 1; - order >>= 1; - - s = order & 1; - order >>= 1; - - n = order & 1; - order >>= 1; - - i = _euler_safe[order & 3]; - j = _euler_next[i+n]; - k = _euler_next[i+1-n]; - h = (s ? k : i); -} - - - - - diff --git a/Generals/Code/Libraries/Source/WWVegas/WWMath/euler.h b/Generals/Code/Libraries/Source/WWVegas/WWMath/euler.h deleted file mode 100644 index bf7a90bd36a..00000000000 --- a/Generals/Code/Libraries/Source/WWVegas/WWMath/euler.h +++ /dev/null @@ -1,127 +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 . -*/ - -/* $Header: /Commando/Code/wwmath/euler.h 5 5/05/01 5:48p Jani_p $ */ -/*********************************************************************************************** - *** Confidential - Westwood Studios *** - *********************************************************************************************** - * * - * Project Name : Commando / G Math Library * - * * - * $Archive:: /Commando/Code/wwmath/euler.h $* - * * - * Author:: Greg_h * - * * - * $Modtime:: 5/04/01 8:37p $* - * * - * $Revision:: 5 $* - * * - *---------------------------------------------------------------------------------------------* - * Functions: * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - - -#if defined(_MSC_VER) -#pragma once -#endif - -#ifndef EULER_H -#define EULER_H - -#include "always.h" -#include "matrix3d.h" -#include "quat.h" - - -/********************************************************************* - - Euler Order Types - - When creating an EulerAngles object, use one of the below - constants to describe the axis convention. - - XYZ - order of the axes - s/r - whether the rotations are applied to a static or - rotating frame. - -*********************************************************************/ - - -/* static axes */ -extern int EulerOrderXYZs; -extern int EulerOrderXYXs; -extern int EulerOrderXZYs; -extern int EulerOrderXZXs; -extern int EulerOrderYZXs; -extern int EulerOrderYZYs; -extern int EulerOrderYXZs; -extern int EulerOrderYXYs; -extern int EulerOrderZXYs; -extern int EulerOrderZXZs; -extern int EulerOrderZYXs; -extern int EulerOrderZYZs; - -/* rotating axes */ -extern int EulerOrderXYZr; -extern int EulerOrderXYXr; -extern int EulerOrderXZYr; -extern int EulerOrderXZXr; -extern int EulerOrderYZXr; -extern int EulerOrderYZYr; -extern int EulerOrderYXZr; -extern int EulerOrderYXYr; -extern int EulerOrderZXYr; -extern int EulerOrderZXZr; -extern int EulerOrderZYXr; -extern int EulerOrderZYZr; - - -/********************************************************************* - - EulerAnglesClass - - The purpose for this class is mainly for conversion. You can - choose a convention for the order of your rotations and then - convert matrices into a set of euler angles. You don't really - want to use this at run-time to convert matrices into angles. - - The guts of this implementation is based on the article in Graphics - Gems IV by Ken Shoemake. The original article is on page 222. - -*********************************************************************/ -class EulerAnglesClass -{ - -public: - - EulerAnglesClass(void) : Order(0) { Angle[0] = 0.0; Angle[1] = 0.0; Angle[2] = 0.0; }; - EulerAnglesClass(const Matrix3D & from,int order); - void From_Matrix(const Matrix3D & from,int order); - void To_Matrix(Matrix3D & M); - - double Get_Angle(int i); - -private: - - double Angle[3]; - int Order; - -}; - - -#endif /*EULER_H*/ diff --git a/Generals/Code/Libraries/Source/WWVegas/WWMath/frustum.cpp b/Generals/Code/Libraries/Source/WWVegas/WWMath/frustum.cpp deleted file mode 100644 index 7bb5e124097..00000000000 --- a/Generals/Code/Libraries/Source/WWVegas/WWMath/frustum.cpp +++ /dev/null @@ -1,168 +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 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 : WWMath * - * * - * $Archive:: /Commando/Code/wwmath/frustum.cpp $* - * * - * Author:: Greg Hjelstrom * - * * - * $Modtime:: 4/01/01 12:47p $* - * * - * $Revision:: 5 $* - * * - *---------------------------------------------------------------------------------------------* - * Functions: * - * FrustumClass::Init -- Initialize a frustum object * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - -#include "frustum.h" - - -/*********************************************************************************************** - * FrustumClass::Init -- Initialize a frustum object * - * * - * This function initializes a frustum from the description of a camera * - * * - * INPUT: * - * camera - camera transform, note that the camera looks down the -Z axis * - * vpmin - min corner of the z=-1.0 view plane (not necessarily the near clip plane) * - * vpmax - max corner of the z=-1.0 view plane (not necessarily the near clip plane) * - * znear - near clip plane (should be negative, negated if it is not) * - * zfar - far clip plane (should be negative, negated if it is not) * - * * - * OUTPUT: * - * * - * WARNINGS: * - * The vpmin and vpmax variables are the min and max of a view-plane at z=-1.0 * - * * - * * - * HISTORY: * - * 2/17/2000 gth : Created. * - *=============================================================================================*/ -void FrustumClass::Init -( - const Matrix3D & camera, - const Vector2 & vpmin, - const Vector2 & vpmax, - float znear, - float zfar -) -{ - int i; - - // Store the camera transform - CameraTransform = camera; - - // Forward is negative Z in our viewspace coordinate system. - // Just flip the sign if the user passed in positive values. - if ((znear > 0.0f) && (zfar > 0.0f)) { - znear = -znear; - zfar = -zfar; - } - - // Calculate the corners of the camera frustum. - // Generate the camera-space frustum corners by linearly - // extrapolating the viewplane to the near and far z clipping planes. - - // The camera frustum corners are defined in the following order: - // When looking at the frustum from the position of the camera, the near four corners are - // numbered: upper left 0, upper right 1, lower left 2, lower right 3. The far plane's - // Frustum corners are numbered from 4 to 7 in an analogous fashion. - // (remember: the camera space has x going to the right, y up and z backwards). - - //calculate a proper z-vector assuming our right-handed coordinate system - Vector3 zv; - Vector3::Cross_Product(CameraTransform.Get_X_Vector(),CameraTransform.Get_Y_Vector(),&zv); - - //compare correct z-vector with the one in the camera matrix. If they point in - //opposite directions, we have a reflected camera matrix. - if (Vector3::Dot_Product(CameraTransform.Get_Z_Vector(),zv) < 0) - { //flip the frustum corners horizontally for a reflected matrix - Corners[1].Set(vpmin.X, vpmax.Y, 1.0); - Corners[5] = Corners[1]; - Corners[1] *= znear; - Corners[5] *= zfar; - Corners[0].Set(vpmax.X, vpmax.Y, 1.0); - Corners[4] = Corners[0]; - Corners[0] *= znear; - Corners[4] *= zfar; - Corners[3].Set(vpmin.X, vpmin.Y, 1.0); - Corners[7] = Corners[3]; - Corners[3] *= znear; - Corners[7] *= zfar; - Corners[2].Set(vpmax.X, vpmin.Y, 1.0); - Corners[6] = Corners[2]; - Corners[2] *= znear; - Corners[6] *= zfar; - } - else - { //normal camera - Corners[0].Set(vpmin.X, vpmax.Y, 1.0); - Corners[4] = Corners[0]; - Corners[0] *= znear; - Corners[4] *= zfar; - Corners[1].Set(vpmax.X, vpmax.Y, 1.0); - Corners[5] = Corners[1]; - Corners[1] *= znear; - Corners[5] *= zfar; - Corners[2].Set(vpmin.X, vpmin.Y, 1.0); - Corners[6] = Corners[2]; - Corners[2] *= znear; - Corners[6] *= zfar; - Corners[3].Set(vpmax.X, vpmin.Y, 1.0); - Corners[7] = Corners[3]; - Corners[3] *= znear; - Corners[7] *= zfar; - } - - - // Transform the eight corners of the view frustum from camera space to world space. - for (i = 0; i < 8; i++) { - Matrix3D::Transform_Vector(CameraTransform, Corners[i], &(Corners[i])); - } - - // Create the six frustum bounding planes from the eight corner Corners. - // The bounding planes are oriented so that their normals point outward - PlaneClass frustum_planes[6]; - Planes[0].Set(Corners[0], Corners[3], Corners[1]); // near - Planes[1].Set(Corners[0], Corners[5], Corners[4]); // bottom - Planes[2].Set(Corners[0], Corners[6], Corners[2]); // right - Planes[3].Set(Corners[2], Corners[7], Corners[3]); // top - Planes[4].Set(Corners[1], Corners[7], Corners[5]); // left - Planes[5].Set(Corners[4], Corners[7], Corners[6]); // far - - // find the bounding box of the entire frustum (may be used for sloppy quick rejection) - BoundMin = BoundMax = Corners[0]; - - for (i=1; i<8;i++) { - if (Corners[i].X < BoundMin.X) BoundMin.X = Corners[i].X; - if (Corners[i].X > BoundMax.X) BoundMax.X = Corners[i].X; - - if (Corners[i].Y < BoundMin.Y) BoundMin.Y = Corners[i].Y; - if (Corners[i].Y > BoundMax.Y) BoundMax.Y = Corners[i].Y; - - if (Corners[i].Z < BoundMin.Z) BoundMin.Z = Corners[i].Z; - if (Corners[i].Z > BoundMax.Z) BoundMax.Z = Corners[i].Z; - } -} - diff --git a/Generals/Code/Libraries/Source/WWVegas/WWMath/frustum.h b/Generals/Code/Libraries/Source/WWVegas/WWMath/frustum.h deleted file mode 100644 index a849eb84be1..00000000000 --- a/Generals/Code/Libraries/Source/WWVegas/WWMath/frustum.h +++ /dev/null @@ -1,73 +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 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 : WWMath * - * * - * $Archive:: /Commando/Code/wwmath/frustum.h $* - * * - * Author:: Greg Hjelstrom * - * * - * $Modtime:: 3/29/00 10:20a $* - * * - * $Revision:: 3 $* - * * - *---------------------------------------------------------------------------------------------* - * Functions: * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - - -#if defined(_MSC_VER) -#pragma once -#endif - -#ifndef FRUSTUM_H -#define FRUSTUM_H - -#include "vector3.h" -#include "plane.h" - - -class FrustumClass -{ -public: - void Init( const Matrix3D & camera, - const Vector2 & viewport_min, - const Vector2 & viewport_max, - float znear, - float zfar ); - - const Vector3 & Get_Bound_Min(void) const { return BoundMin; } - const Vector3 & Get_Bound_Max(void) const { return BoundMax; } - -public: - - Matrix3D CameraTransform; - PlaneClass Planes[6]; - Vector3 Corners[8]; - Vector3 BoundMin; - Vector3 BoundMax; -}; - - - -#endif - diff --git a/Generals/Code/Libraries/Source/WWVegas/WWMath/gridcull.cpp b/Generals/Code/Libraries/Source/WWVegas/WWMath/gridcull.cpp deleted file mode 100644 index 1d628382c28..00000000000 --- a/Generals/Code/Libraries/Source/WWVegas/WWMath/gridcull.cpp +++ /dev/null @@ -1,1024 +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 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 : WWMath * - * * - * $Archive:: /Commando/Code/wwmath/gridcull.cpp $* - * * - * Author:: Greg Hjelstrom * - * * - * $Modtime:: 4/27/00 7:00p $* - * * - * $Revision:: 18 $* - * * - *---------------------------------------------------------------------------------------------* - * Functions: * - * GridCullSystemClass::GridCullSystemClass -- Constructor * - * GridCullSystemClass::~GridCullSystemClass -- Destructor * - * GridCullSystemClass::Collect_Objects -- Collect all objects touching the given point * - * GridCullSystemClass::Collect_Objects -- Collect all objects touching the given AABox * - * GridCullSystemClass::Collect_Objects -- Collect all objects touching the given OBBox * - * GridCullSystemClass::Collect_Objects -- Collect all objects touching the given Frustum * - * GridCullSystemClass::Re_Partition -- re-compute grid parameters for the given volume * - * GridCullSystemClass::Collect_And_Unlink_All -- collects all objects and removes them from * - * GridCullSystemClass::Update_Culling -- updates an objects position in the grid * - * GridCullSystemClass::Load -- load function * - * GridCullSystemClass::Save -- Save function * - * GridCullSystemClass::Reset_Statistics -- reset debugging stats * - * GridCullSystemClass::Get_Statistics -- returns reference to the statistics structure * - * GridCullSystemClass::Add_Object_Internal -- links an object into the system * - * GridCullSystemClass::Remove_Object_Internal -- unlinks an object from the system * - * GridCullSystemClass::link_object -- figures out which cell the object is in and links it * - * GridCullSystemClass::unlink_object -- unlinks the object from the cell it is in * - * GridCullSystemClass::link_object_to_list -- grid list link function * - * GridCullSystemClass::unlink_object_from_list -- grid list unlink function * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - - -#include "gridcull.h" -#include "chunkio.h" -#include "iostruct.h" -#include "colmath.h" -#include "colmathinlines.h" - - - -/* -** Declare the pool for GridLinks -*/ -DEFINE_AUTO_POOL(GridLinkClass,256); - - -/* -** Current version of the file format -*/ -const uint32 GRID_CURRENT_VERSION = 0x00010000; - - -/* -** Chunk Id's used by the aabtree code to save itself into a file -*/ -enum -{ - GRID_CHUNK_VERSION = 0x00000001, // version wrapper, contains 32bit version # - GRID_CHUNK_PARAMETERS = 0x00000100, // parameters for the grid cull system -}; - - -/* -** IOGridParametersStruct -** Data structure for the contents of a node in the AAB-Tree -*/ -struct IOGridParametersStruct -{ - IOVector3Struct MinCellSize; - IOVector3Struct Origin; - IOVector3Struct CellDim; - uint32 CellCount[3]; - float32 MaxObjExtent; -}; - - -/************************************************************************* -** -** Utility functions for walking the object list in an AABTree Node -** -*************************************************************************/ -static inline CullableClass * get_next_object(CullableClass * obj) -{ - return ((GridLinkClass *)obj->Get_Cull_Link())->Next; -} - -/************************************************************************* -** -** GridLinkClass Implementation -** -*************************************************************************/ -GridLinkClass::GridLinkClass(GridCullSystemClass * system) : - CullLinkClass(system), - GridAddress(-1), - Prev(NULL), - Next(NULL) -{ -} - -GridLinkClass::~GridLinkClass(void) -{ -} - - - - - -/************************************************************************* -** -** GridCullSystemClass Implementation -** -*************************************************************************/ - - -/*********************************************************************************************** - * GridCullSystemClass::GridCullSystemClass -- Constructor * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 4/27/2000 gth : Created. * - *=============================================================================================*/ -GridCullSystemClass::GridCullSystemClass(void) : - MinCellSize(10,10,10), - MaxObjExtent(15), - Origin(-100,-100,-100), - CellDim(10,10,10), - Cells(NULL), - NoGridList(NULL), - ObjCount(0), - TerminationCellCount(TERMINATION_CELL_COUNT) -{ - CellCount[0] = CellCount[1] = CellCount[2] = 0; - Re_Partition(Vector3(-100,-100,-100),Vector3(100,100,100),15); - Reset_Statistics(); -} - - -/*********************************************************************************************** - * GridCullSystemClass::~GridCullSystemClass -- Destructor * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 4/27/2000 gth : Created. * - *=============================================================================================*/ -GridCullSystemClass::~GridCullSystemClass(void) -{ - if (Cells != NULL) { - delete Cells; - Cells = NULL; - } -} - - -/*********************************************************************************************** - * GridCullSystemClass::Collect_Objects -- Collect all objects touching the given point * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 4/27/2000 gth : Created. * - *=============================================================================================*/ -void GridCullSystemClass::Collect_Objects(const Vector3 & point) -{ - /* - ** Collect the objects in the grid - */ - VolumeStruct vol; - init_volume(point,point,&vol); - if (!vol.Is_Empty()) { - - int delta_x = vol.Max[0] - vol.Min[0]; - int i,j,k; - int address = map_indices_to_address(vol.Min[0],vol.Min[1],vol.Min[2]); - - for (k=vol.Min[2]; k 0.0f); - WWASSERT(world_dim.Y > 0.0f); - WWASSERT(world_dim.Z > 0.0f); - - /* - ** how many cells should we use on each dimension? - */ - CellCount[0] = CellCount[1] = CellCount[2] = 1; - CellDim = world_dim; - bool done = false; - - while (!done) { - - /* - ** find biggest dimension - */ - int bigdim = 0; - if (CellDim[1]/MinCellSize[1] > CellDim[bigdim]/MinCellSize[bigdim]) bigdim = 1; - if (CellDim[2]/MinCellSize[2] > CellDim[bigdim]/MinCellSize[bigdim]) bigdim = 2; - - /* - ** split dimension in two if possible - */ - if (CellDim[bigdim] >= 2.0f * MinCellSize[bigdim]) { - CellDim[bigdim] /= 2.0f; - CellCount[bigdim] *= 2; - } - - /* - ** check termination conditions - */ - if (total_cell_count() >= TerminationCellCount) { - done = true; - } - - if ( (CellDim[0] < 2.0*MinCellSize[0]) && - (CellDim[1] < 2.0*MinCellSize[1]) && - (CellDim[2] < 2.0*MinCellSize[2]) ) { - done = true; - } - } - - OOCellDim.X = 1.0f / CellDim.X; - OOCellDim.Y = 1.0f / CellDim.Y; - OOCellDim.Z = 1.0f / CellDim.Z; - - if (Cells != NULL) { - delete[] Cells; - } - Cells = W3DNEWARRAY CullableClass * [total_cell_count()]; - memset(&(Cells[0]),0,total_cell_count() * sizeof(CullableClass *)); - - /* - ** iterate the collection list and re-insert all objects into the grid - */ - CullableClass * obj; - for ( obj = Get_First_Collected_Object_Internal(); - obj != NULL; - obj = Get_Next_Collected_Object_Internal(obj)) - { - link_object(obj); - } -} - - -/*********************************************************************************************** - * GridCullSystemClass::Collect_And_Unlink_All -- collects all objects and removes them from t * - * * - * This is used when re-partitioning the grid. All objects are pulled out and linked into * - * the collection list. When the grid has been re-initialized, the objects are put back in. * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 4/27/2000 gth : Created. * - *=============================================================================================*/ -void GridCullSystemClass::Collect_And_Unlink_All(void) -{ - Reset_Collection(); - - /* - ** pull all objects out of the grid - */ - for (int k=0; kGet_Culling_System() == this); - - int address; - GridLinkClass * link = (GridLinkClass *)obj->Get_Cull_Link(); - map_point_to_address(obj->Get_Cull_Box().Center,address); - - if (address != link->GridAddress) { - unlink_object(obj); - link_object(obj,address); - } -} - - -/*********************************************************************************************** - * GridCullSystemClass::Load -- load function * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 4/27/2000 gth : Created. * - *=============================================================================================*/ -void GridCullSystemClass::Load(ChunkLoadClass & cload) -{ - /* - ** read the version chunk - */ - uint32 version; - cload.Open_Chunk(); - WWASSERT(cload.Cur_Chunk_ID() == GRID_CHUNK_VERSION); - cload.Read(&version,sizeof(version)); - cload.Close_Chunk(); - - /* - ** read the parameters chunk - */ - IOGridParametersStruct params; - memset(¶ms,0,sizeof(params)); - cload.Open_Chunk(); - WWASSERT(cload.Cur_Chunk_ID() == GRID_CHUNK_PARAMETERS); - cload.Read(¶ms,sizeof(params)); - cload.Close_Chunk(); - - /* - ** unlink all objects - */ - Collect_And_Unlink_All(); - - /* - ** partition the grid according to the loaded parameters - */ - CellCount[0] = params.CellCount[0]; - CellCount[1] = params.CellCount[1]; - CellCount[2] = params.CellCount[2]; - CellDim.X = params.CellDim.X; - CellDim.Y = params.CellDim.Y; - CellDim.Z = params.CellDim.Z; - MaxObjExtent = params.MaxObjExtent; - MinCellSize.X = params.MinCellSize.X; - MinCellSize.Y = params.MinCellSize.Y; - MinCellSize.Z = params.MinCellSize.Z; - Origin.X = params.Origin.X; - Origin.Y = params.Origin.Y; - Origin.Z = params.Origin.Z; - - OOCellDim.X = 1.0f / CellDim.X; - OOCellDim.Y = 1.0f / CellDim.Y; - OOCellDim.Z = 1.0f / CellDim.Z; - - if (Cells != NULL) { - delete [] Cells; - Cells = NULL; - } - - Cells = W3DNEWARRAY CullableClass * [total_cell_count()]; - memset(&(Cells[0]),0,total_cell_count() * sizeof(CullableClass *)); - - /* - ** re-link the objects in - */ - CullableClass * obj; - for ( obj = Get_First_Collected_Object_Internal(); - obj != NULL; - obj = Get_Next_Collected_Object_Internal(obj)) - { - link_object(obj); - } -} - - -/*********************************************************************************************** - * GridCullSystemClass::Save -- Save function * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 4/27/2000 gth : Created. * - *=============================================================================================*/ -void GridCullSystemClass::Save(ChunkSaveClass & csave) -{ - /* - ** write the version chunk - */ - uint32 version = GRID_CURRENT_VERSION; - csave.Begin_Chunk(GRID_CHUNK_VERSION); - csave.Write(&version,sizeof(version)); - csave.End_Chunk(); - - /* - ** write the grid parameters - */ - IOGridParametersStruct params; - memset(¶ms,0,sizeof(params)); - params.CellCount[0] = CellCount[0]; - params.CellCount[1] = CellCount[1]; - params.CellCount[2] = CellCount[2]; - params.CellDim.X = CellDim.X; - params.CellDim.Y = CellDim.Y; - params.CellDim.Z = CellDim.Z; - params.MaxObjExtent = MaxObjExtent; - params.MinCellSize.X = MinCellSize.X; - params.MinCellSize.Y = MinCellSize.Y; - params.MinCellSize.Z = MinCellSize.Z; - params.Origin.X = Origin.X; - params.Origin.Y = Origin.Y; - params.Origin.Z = Origin.Z; - - csave.Begin_Chunk(GRID_CHUNK_PARAMETERS); - csave.Write(¶ms,sizeof(params)); - csave.End_Chunk(); -} - - -/*********************************************************************************************** - * GridCullSystemClass::Reset_Statistics -- reset debugging stats * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 4/27/2000 gth : Created. * - *=============================================================================================*/ -void GridCullSystemClass::Reset_Statistics(void) -{ - // number of (virtual) nodes = 2n-1 - Stats.NodeCount = 2 * (CellCount[0] * CellCount[1] * CellCount[2]) - 1; - Stats.NodesAccepted = 0; - Stats.NodesTriviallyAccepted = 0; - Stats.NodesRejected = 0; -} - - -/*********************************************************************************************** - * GridCullSystemClass::Get_Statistics -- returns reference to the statistics structure * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 4/27/2000 gth : Created. * - *=============================================================================================*/ -const GridCullSystemClass::StatsStruct & GridCullSystemClass::Get_Statistics(void) -{ - return Stats; -} - - -/*********************************************************************************************** - * GridCullSystemClass::Add_Object_Internal -- links an object into the system * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 4/27/2000 gth : Created. * - *=============================================================================================*/ -void GridCullSystemClass::Add_Object_Internal(CullableClass * obj) -{ - WWASSERT(obj); - WWASSERT(obj->Get_Culling_System() == NULL); - - GridLinkClass * link = new GridLinkClass(this); - obj->Set_Cull_Link(link); - link_object(obj); - - ObjCount++; - obj->Add_Ref(); -} - - -/*********************************************************************************************** - * GridCullSystemClass::Remove_Object_Internal -- unlinks an object from the system * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 4/27/2000 gth : Created. * - *=============================================================================================*/ -void GridCullSystemClass::Remove_Object_Internal(CullableClass * obj) -{ - WWASSERT(obj); - WWASSERT(obj->Get_Culling_System() == this); - GridLinkClass * link = (GridLinkClass *)obj->Get_Cull_Link(); - - unlink_object(obj); - link->Set_Culling_System(NULL); - delete link; - obj->Set_Cull_Link(NULL); - - ObjCount--; - obj->Release_Ref(); -} - - -/*********************************************************************************************** - * GridCullSystemClass::link_object -- figures out which cell the object is in and links it * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 4/27/2000 gth : Created. * - *=============================================================================================*/ -void GridCullSystemClass::link_object(CullableClass * obj) -{ - WWASSERT(obj); - WWASSERT(obj->Get_Culling_System() == this); - - int address; - map_point_to_address(obj->Get_Cull_Box().Center,address); - - link_object(obj,address); -} - -void GridCullSystemClass::link_object(CullableClass * obj,int address) -{ - WWASSERT(obj); - WWASSERT(obj->Get_Culling_System() == this); - GridLinkClass * link = (GridLinkClass *)obj->Get_Cull_Link(); - WWASSERT(link != NULL); - - /* - ** if obj cannot be inserted into the grid, add it to the NoGridList - ** otherwise, insert it into the cell - */ - const AABoxClass & box = obj->Get_Cull_Box(); - if ( - (box.Extent.X > MaxObjExtent) || - (box.Extent.Y > MaxObjExtent) || - (box.Extent.Z > MaxObjExtent) || - (address == UNGRIDDED_ADDRESS) - ) - { - link->GridAddress = UNGRIDDED_ADDRESS; - link_object_to_list(&NoGridList,obj); - } else { - link->GridAddress = address; - link_object_to_list(&(Cells[address]),obj); - } -} - -/*********************************************************************************************** - * GridCullSystemClass::unlink_object -- unlinks the object from the cell it is in * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 4/27/2000 gth : Created. * - *=============================================================================================*/ -void GridCullSystemClass::unlink_object(CullableClass * obj) -{ - WWASSERT(obj); - WWASSERT(obj->Get_Culling_System() == this); - GridLinkClass * link = (GridLinkClass *)obj->Get_Cull_Link(); - - if (link->GridAddress == UNGRIDDED_ADDRESS) { - unlink_object_from_list(&NoGridList,obj); - } else { - unlink_object_from_list(&(Cells[link->GridAddress]),obj); - } -} - - -/*********************************************************************************************** - * GridCullSystemClass::link_object_to_list -- grid list link function * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 4/27/2000 gth : Created. * - *=============================================================================================*/ -void GridCullSystemClass::link_object_to_list(CullableClass ** head,CullableClass * obj) -{ - WWASSERT(obj); - WWASSERT(obj->Get_Culling_System() == this); - GridLinkClass * link = (GridLinkClass *)obj->Get_Cull_Link(); - - /* - ** Insert this object as the new head of the list. - */ - link->Next = *head; - link->Prev = NULL; - - if (link->Next != NULL) { - GridLinkClass * next_link = (GridLinkClass *)link->Next->Get_Cull_Link(); - WWASSERT(next_link != NULL); - next_link->Prev = obj; - } - - *head = obj; -} - - -/*********************************************************************************************** - * GridCullSystemClass::unlink_object_from_list -- grid list unlink function * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 4/27/2000 gth : Created. * - *=============================================================================================*/ -void GridCullSystemClass::unlink_object_from_list(CullableClass ** head,CullableClass * obj) -{ - WWASSERT(obj); - WWASSERT(obj->Get_Culling_System() == this); - GridLinkClass * link = (GridLinkClass *)obj->Get_Cull_Link(); - - /* - ** check to see that the object is actually in this list - */ -#ifdef WWDEBUG - CullableClass * tmp = *head; - bool found = false; - while (tmp && !found) { - if (tmp == obj) found = true; - tmp = ((GridLinkClass *)(tmp->Get_Cull_Link()))->Next; - } - WWASSERT(found); -#endif - - /* - ** If we were the head of the list, make the head point to the next object - */ - if (obj == *head) { - *head = link->Next; - } - - /* - ** Link the object previous to us to our next... - */ - if (link->Prev) { - GridLinkClass * prev_link = (GridLinkClass *)link->Prev->Get_Cull_Link(); - prev_link->Next = link->Next; - } - - /* - ** Link the objects after us to our previous... - */ - if (link->Next) { - GridLinkClass * next_link = (GridLinkClass *)link->Next->Get_Cull_Link(); - next_link->Prev = link->Prev; - } - - link->Prev = NULL; - link->Next = NULL; -} - - - -/************************************************************************* -** -** GridCullSystem Internal Leaf-iterating collection functions -** -*************************************************************************/ -void GridCullSystemClass::collect_objects_in_leaf(const Vector3 & point,CullableClass * head) -{ - if (head != NULL) { - GridListIterator it(head); - for (;!it.Is_Done(); it.Next()) { - CullableClass * obj = it.Peek_Obj(); - if (obj->Get_Cull_Box ().Contains (point) == true) { - Add_To_Collection(obj); - } - } - } -} - -void GridCullSystemClass::collect_objects_in_leaf(const AABoxClass & box,CullableClass * head) -{ - if (head != NULL) { - GridListIterator it(head); - for (;!it.Is_Done(); it.Next()) { - CullableClass * obj = it.Peek_Obj(); - if (CollisionMath::Overlap_Test(box,obj->Get_Cull_Box()) != CollisionMath::OUTSIDE) { - Add_To_Collection(obj); - } - } - } -} - -void GridCullSystemClass::collect_objects_in_leaf(const OBBoxClass & obbox,CullableClass * head) -{ - if (head != NULL) { - GridListIterator it(head); - for (;!it.Is_Done(); it.Next()) { - CullableClass * obj = it.Peek_Obj(); - if (CollisionMath::Overlap_Test(obbox,obj->Get_Cull_Box()) != CollisionMath::OUTSIDE) { - Add_To_Collection(obj); - } - } - } -} - -void GridCullSystemClass::collect_objects_in_leaf(const FrustumClass & frustum,CullableClass * head) -{ - if (head != NULL) { - GridListIterator it(head); - for (;!it.Is_Done(); it.Next()) { - CullableClass * obj = it.Peek_Obj(); - if (CollisionMath::Overlap_Test(frustum,obj->Get_Cull_Box()) != CollisionMath::OUTSIDE) { - Add_To_Collection(obj); - } - } - } -} diff --git a/Generals/Code/Libraries/Source/WWVegas/WWMath/gridcull.h b/Generals/Code/Libraries/Source/WWVegas/WWMath/gridcull.h deleted file mode 100644 index 2e7bc89abe9..00000000000 --- a/Generals/Code/Libraries/Source/WWVegas/WWMath/gridcull.h +++ /dev/null @@ -1,706 +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 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 : WWMath * - * * - * $Archive:: /Commando/Code/wwmath/gridcull.h $* - * * - * Author:: Greg Hjelstrom * - * * - * $Modtime:: 5/10/01 10:42a $* - * * - * $Revision:: 14 $* - * * - *---------------------------------------------------------------------------------------------* - * Functions: * - * GridCullSystemClass::clamp_indices_to_grid -- constrains indices to be a valid location * - * GridCullSystemClass::map_point_to_cell -- determines which cell the point is in * - * GridCullSystemClass::map_point_to_address -- determines the address of a point in the gri * - * GridCullSystemClass::map_indices_to_address -- computes the address for given index tripl * - * GridCullSystemClass::total_cell_count -- returns the total number of cells in the grid * - * GridCullSystemClass::compute_box -- computes the bounding box for a grid cell * - * GridCullSystemClass::compute_box -- computes bounding box for a range of grid cells * - * GridCullSystemClass::init_volume -- inits volume to contain the given range * - * GridCullSystemClass::init_volume -- inits volume to contain the given line segment * - * GridCullSystemClass::init_volume -- inits volume to contain the given box * - * GridCullSystemClass::init_volume -- inits volume to contain the given oriented box * - * GridCullSystemClass::init_volume -- inits volume to contain the given frustum * - * GridCullSystemClass::VolumeStruct::VolumeStruct -- constructor * - * GridCullSystemClass::VolumeStruct::VolumeStruct -- constructor * - * GridCullSystemClass::VolumeStruct::Is_Leaf -- check if volume is a leaf * - * GridCullSystemClass::VolumeStruct::Is_Empty -- check if volume is empty (or invalid) * - * GridCullSystemClass::VolumeStruct::Split -- split this volume * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - -#if defined(_MSC_VER) -#pragma once -#endif - -#include "cullsys.h" -#include "mempool.h" -#include "frustum.h" -#include "aabox.h" -#include "lineseg.h" -#include "obbox.h" -#include - -class ChunkLoadClass; -class ChunkSaveClass; - -/* -** GridCullSystemClass -** This is a culling system designed for dynamic objects (objects which are moving or -** changing bounding box size). It features O(1) insertion as opposed to -** the AABTree, QuadTree, or Octree insertion times which are O(logn). It's disadvantages -** compared to the above mentioned systems are that it must uniformly divide space. The -** AABTree conforms to the geometry placed in it and can therefore cull things more -** efficiently. In actual use, this system is like an AAB-tree which is uniformly subdivided, -** its just that we can jump straight to the leaves of the tree for insertion... -** -** The bounding volume for each grid cell is considered to be the volume of the cell, expanded -** by the maximum object size. Inserting an object into the grid is a matter of determining -** which cell its center point is in. Objects which are larger than the maximum size are -** allowed but they are simply put into a linked list which is iterated with each call to -** the culling system (linearly culled rather than logarithmic...) -*/ -class GridCullSystemClass : public CullSystemClass -{ - -public: - - GridCullSystemClass(void); - ~GridCullSystemClass(void); - - virtual void Collect_Objects(const Vector3 & point); - virtual void Collect_Objects(const AABoxClass & box); - virtual void Collect_Objects(const OBBoxClass & box); - virtual void Collect_Objects(const FrustumClass & frustum); - - virtual void Re_Partition(const Vector3 & min,const Vector3 & max,float objdim); - virtual void Update_Culling(CullableClass * obj); - - virtual void Load(ChunkLoadClass & cload); - virtual void Save(ChunkSaveClass & csave); - - virtual int Get_Object_Count (void) const { return ObjCount; } - - /* - ** Statistics - */ - struct StatsStruct - { - int NodeCount; - int NodesAccepted; - int NodesTriviallyAccepted; - int NodesRejected; - }; - - void Reset_Statistics(void); - const StatsStruct & Get_Statistics(void); - - void Get_Min_Cell_Size (Vector3 &size) const { size = MinCellSize; } - void Set_Min_Cell_Size (const Vector3 &size) { MinCellSize = size; } - - int Get_Termination_Count (void) const { return TerminationCellCount; } - void Set_Termination_Count (int count) { TerminationCellCount = count; } - -protected: - - void Collect_And_Unlink_All(void); - void Add_Object_Internal(CullableClass * obj); - void Remove_Object_Internal(CullableClass * obj); - - enum - { - TERMINATION_CELL_COUNT = 16384, // algorithm terminates if we ever have more than this many cells. - UNGRIDDED_ADDRESS = 0xFFFFFFFF // address given to objs that didn't fit in grid - }; - - // Constants which control the division of space: - Vector3 MinCellSize; // min dimensions for a cell (don't go below this...) - float MaxObjExtent; // max extent/radius (objects bigger than this are just put in a list) - int TerminationCellCount; - - // Constants that define the division of space - Vector3 Origin; - Vector3 CellDim; - Vector3 OOCellDim; - int CellCount[3]; - - // 3D array of pointers to objects in each cell - CullableClass ** Cells; - - // list of objs that were outside or too big for the grid. - CullableClass * NoGridList; - - // number of objects in the system - int ObjCount; - - // statistics - StatsStruct Stats; - - // Structure used to define a volume in the grid. The volume spans from the cell indexed - // by Min[0],Min[1],Min[2] to the cell indexed by Max[0]-1,Max[1]-1,Max[2]-1. - struct VolumeStruct - { - VolumeStruct(void); - VolumeStruct(int i0,int j0,int k0,int i1,int j1,int k1); - bool Is_Leaf(void) const; - bool Is_Empty(void) const; - void Split(VolumeStruct & v0,VolumeStruct & v1) const; - - int Min[3]; - int Max[3]; - }; - - void link_object(CullableClass * obj); - void link_object(CullableClass * obj,int address); - void unlink_object(CullableClass * obj); - void link_object_to_list(CullableClass ** head,CullableClass * obj); - void unlink_object_from_list(CullableClass ** head,CullableClass * obj); - - bool map_point_to_cell(const Vector3 & pt,int & set_i,int & set_j,int & set_k); - bool map_point_to_address(const Vector3 & pt,int & set_address); - WWINLINE int map_indices_to_address(int i,int j,int k); - void clamp_indices_to_grid(int * i,int * j,int * k); - - int total_cell_count(void); - void compute_box(int i,int j,int k,AABoxClass * set_box); - void compute_box(const VolumeStruct & area, AABoxClass * set_box); - - void init_volume(const Vector3 & bound_min,const Vector3 & bound_max,VolumeStruct * set_volume); - void init_volume(const Vector3 & point,VolumeStruct * set_volume); - void init_volume(const LineSegClass & line,VolumeStruct * set_volume); - void init_volume(const AABoxClass & box,VolumeStruct * set_volume); - void init_volume(const OBBoxClass & box,VolumeStruct * set_volume); - void init_volume(const FrustumClass & frustum,VolumeStruct * set_volume); - - void collect_objects_in_leaf(const Vector3 & point,CullableClass * head); - void collect_objects_in_leaf(const AABoxClass & aabox,CullableClass * head); - void collect_objects_in_leaf(const OBBoxClass & obbox,CullableClass * head); - void collect_objects_in_leaf(const FrustumClass & frustum,CullableClass * head); -}; - -/* -** Macros for gathering statistics. Placed here in the header file so that -** derived classes can use them as well. -*/ -#ifdef WWDEBUG - -#define GRIDCULL_NODE_ACCEPTED Stats.NodesAccepted ++; -#define GRIDCULL_NODE_TRIVIALLY_ACCEPTED Stats.NodesTriviallyAccepted ++; -#define GRIDCULL_NODE_REJECTED Stats.NodesRejected ++; - -#else - -#define GRIDCULL_NODE_ACCEPTED -#define GRIDCULL_NODE_TRIVIALLY_ACCEPTED -#define GRIDCULL_NODE_REJECTED - -#endif - - -/* -** TypedGridCullSystemClass -** This class simply enforces that a certain type of object is inserted into the grid cull system. -** It exposes the add, remove, and collection iterating functions and is intended to be the class -** actually used by the end user. -*/ -template class TypedGridCullSystemClass : public GridCullSystemClass -{ -public: - - virtual void Add_Object(T * obj) { Add_Object_Internal(obj); } - virtual void Remove_Object(T * obj) { Remove_Object_Internal(obj); } - - T * Get_First_Collected_Object(void) { return (T*)Get_First_Collected_Object_Internal(); } - T * Get_Next_Collected_Object(T * obj) { return (T*)Get_Next_Collected_Object_Internal(obj); } - -}; - - -/* -** GridLinkClass -** This structure is used to link cullable objects into a Grid culling system -** This class is should only be used by classes which derive from GridCullSystemClass -** not normal users. -*/ -class GridLinkClass : public CullLinkClass, public AutoPoolClass -{ -public: - GridLinkClass(GridCullSystemClass * system); - virtual ~GridLinkClass(void); - - int GridAddress; // address in the grid. - CullableClass * Prev; // prev object in this cell - CullableClass * Next; // next object in this cell -}; - - -/* -** GridListIterator -** This is just a simple iterator that contains the code for traversing the -** list of objects either in a cell in the grid or in the NoGridList... -** This class should only be used by classes which derive from GridCullSystemClass -** not normal users. -*/ -class GridListIterator -{ -public: - - GridListIterator(CullableClass * head) { First(head); } - - void First(CullableClass * head) { Head = head; CurObj = head; } - void First(void) { CurObj = Head; } - void Next(void) { if (CurObj) { CurObj = ((GridLinkClass *)CurObj->Get_Cull_Link())->Next; } } - void Prev(void) { if (CurObj) { CurObj = ((GridLinkClass *)CurObj->Get_Cull_Link())->Prev; } } - bool Is_Done(void) { return (CurObj == NULL); } - - CullableClass * Get_Obj(void) { if (CurObj) { CurObj->Add_Ref(); } return CurObj; } - CullableClass * Peek_Obj(void) { return CurObj; } - -private: - - CullableClass * Head; // head of the list we're working in - CullableClass * CurObj; // node we're currently at. - -}; - - - -/*********************************************************************************************** - * GridCullSystemClass::clamp_indices_to_grid -- constrains indices to be a valid location * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 3/30/2000 gth : Created. * - *=============================================================================================*/ -WWINLINE void GridCullSystemClass::clamp_indices_to_grid(int * i,int * j,int * k) -{ - if (*i < 0) *i = 0; - if (*i >= CellCount[0]) *i = CellCount[0] - 1; - if (*j < 0) *j = 0; - if (*j >= CellCount[1]) *j = CellCount[1] - 1; - if (*k < 0) *k = 0; - if (*k >= CellCount[2]) *k = CellCount[2] - 1; -} - - -/*********************************************************************************************** - * GridCullSystemClass::map_point_to_cell -- determines which cell the point is in * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 3/30/2000 gth : Created. * - *=============================================================================================*/ -WWINLINE bool GridCullSystemClass::map_point_to_cell(const Vector3 & pt,int & set_i,int & set_j,int & set_k) -{ - Vector3 dp = pt - Origin; - set_i = floor(dp.X * OOCellDim.X); - set_j = floor(dp.Y * OOCellDim.Y); - set_k = floor(dp.Z * OOCellDim.Z); - - if ( (set_i >= 0) && (set_j >= 0) && (set_k >= 0) && - (set_i < CellCount[0]) && (set_j < CellCount[1]) && (set_k < CellCount[2]) ) - { - return true; - } - return false; -} - - -/*********************************************************************************************** - * GridCullSystemClass::map_point_to_address -- determines the address of a point in the grid * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 3/30/2000 gth : Created. * - *=============================================================================================*/ -WWINLINE bool GridCullSystemClass::map_point_to_address(const Vector3 & pt,int &set_address) -{ - int i,j,k; - bool res = map_point_to_cell(pt,i,j,k); - - if (res) { - set_address = map_indices_to_address(i,j,k); - return true; - } else { - set_address = UNGRIDDED_ADDRESS; - return false; - } -} - - -/*********************************************************************************************** - * GridCullSystemClass::map_indices_to_address -- computes the address for given index triplet * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 3/30/2000 gth : Created. * - *=============================================================================================*/ -WWINLINE int GridCullSystemClass::map_indices_to_address(int i,int j,int k) -{ - return i + j*CellCount[0] + k*CellCount[0]*CellCount[1]; -} - - -/*********************************************************************************************** - * GridCullSystemClass::total_cell_count -- returns the total number of cells in the grid * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 3/30/2000 gth : Created. * - *=============================================================================================*/ -WWINLINE int GridCullSystemClass::total_cell_count(void) -{ - return CellCount[0] * CellCount[1] * CellCount[2]; -} - - -/*********************************************************************************************** - * GridCullSystemClass::compute_box -- computes the bounding box for a grid cell * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 3/30/2000 gth : Created. * - *=============================================================================================*/ -WWINLINE void GridCullSystemClass::compute_box(int i,int j,int k,AABoxClass * set_box) -{ - WWASSERT(set_box != NULL); - WWASSERT((i >= 0) && (j >= 0) && (k >= 0)); - WWASSERT((i < CellCount[0]) && (j < CellCount[1]) && (k < CellCount[2])); - - Vector3 min,max; - - min.X = Origin.X + i * CellDim.X - MaxObjExtent; - min.Y = Origin.Y + j * CellDim.Y - MaxObjExtent; - min.Z = Origin.Z + k * CellDim.Z - MaxObjExtent; - - max.X = min.X + CellDim.X + 2.0f*MaxObjExtent; - max.Y = min.Y + CellDim.Y + 2.0f*MaxObjExtent; - max.Z = min.Z + CellDim.Z + 2.0f*MaxObjExtent; - - set_box->Init((min+max)*0.5f, (min-max)*0.5f); -} - - -/*********************************************************************************************** - * GridCullSystemClass::compute_box -- computes bounding box for a range of grid cells * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 3/30/2000 gth : Created. * - *=============================================================================================*/ -WWINLINE void GridCullSystemClass::compute_box(const GridCullSystemClass::VolumeStruct & vol, AABoxClass * set_box) -{ - WWASSERT(set_box != NULL); - WWASSERT((vol.Min[0] >= 0) && (vol.Min[1] >= 0) && (vol.Min[2] >= 0)); - WWASSERT((vol.Max[0] <= CellCount[0]) && (vol.Max[1] <= CellCount[1]) && (vol.Max[2] <= CellCount[2])); - - Vector3 min,max; - - min.X = Origin.X + vol.Min[0] * CellDim.X - MaxObjExtent; - min.Y = Origin.Y + vol.Min[1] * CellDim.Y - MaxObjExtent; - min.Z = Origin.Z + vol.Min[2] * CellDim.Z - MaxObjExtent; - - max.X = Origin.X + vol.Max[0] * CellDim.X + MaxObjExtent; - max.Y = Origin.Y + vol.Max[1] * CellDim.Y + MaxObjExtent; - max.Z = Origin.Z + vol.Max[2] * CellDim.Z + MaxObjExtent; - - Vector3 center((max.X+min.X)*0.5f,(max.Y+min.Y)*0.5f,(max.Z+min.Z)*0.5f); - Vector3 extent((max.X-min.X)*0.5f,(max.Y-min.Y)*0.5f,(max.Z-min.Z)*0.5f); - set_box->Init(center,extent); -} - - -/*********************************************************************************************** - * GridCullSystemClass::init_volume -- inits volume to contain the given range * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 3/30/2000 gth : Created. * - *=============================================================================================*/ -WWINLINE void GridCullSystemClass::init_volume -( - const Vector3 & bound_min, - const Vector3 & bound_max, - VolumeStruct * set_vol -) -{ - // expand the box by the maximum size of any object - Vector3 grid_min = bound_min; - grid_min.X -= MaxObjExtent; - grid_min.Y -= MaxObjExtent; - grid_min.Z -= MaxObjExtent; - - Vector3 grid_max = bound_max; - grid_max.X += MaxObjExtent; - grid_max.Y += MaxObjExtent; - grid_max.Z += MaxObjExtent; - - // now compute the grid coordinates of the corners of the box - GridCullSystemClass::map_point_to_cell(grid_min,set_vol->Min[0],set_vol->Min[1],set_vol->Min[2]); - GridCullSystemClass::map_point_to_cell(grid_max,set_vol->Max[0],set_vol->Max[1],set_vol->Max[2]); - - // now clamp the volume to the actual grid - clamp_indices_to_grid(&(set_vol->Min[0]),&(set_vol->Min[1]),&(set_vol->Min[2])); - clamp_indices_to_grid(&(set_vol->Max[0]),&(set_vol->Max[1]),&(set_vol->Max[2])); - - // increment the outer edge of the box due to the way we traverse the grid... - set_vol->Max[0] ++; - set_vol->Max[1] ++; - set_vol->Max[2] ++; -} - - -/*********************************************************************************************** - * GridCullSystemClass::init_volume -- inits volume to contain the given line segment * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 3/30/2000 gth : Created. * - *=============================================================================================*/ -WWINLINE void GridCullSystemClass::init_volume(const LineSegClass & line,VolumeStruct * set_volume) -{ - Vector3 min_pt,max_pt; - min_pt.X = WWMath::Min(line.Get_P0().X,line.Get_P1().X); - max_pt.X = WWMath::Max(line.Get_P0().X,line.Get_P1().X); - min_pt.Y = WWMath::Min(line.Get_P0().Y,line.Get_P1().Y); - max_pt.Y = WWMath::Max(line.Get_P0().Y,line.Get_P1().Y); - min_pt.Z = WWMath::Min(line.Get_P0().Z,line.Get_P1().Z); - max_pt.Z = WWMath::Max(line.Get_P0().Z,line.Get_P1().Z); - init_volume(min_pt,max_pt,set_volume); -} - - -/*********************************************************************************************** - * GridCullSystemClass::init_volume -- inits volume to contain the given box * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 3/30/2000 gth : Created. * - *=============================================================================================*/ -WWINLINE void GridCullSystemClass::init_volume(const AABoxClass & box,VolumeStruct * set_volume) -{ - init_volume(box.Center - box.Extent,box.Center + box.Extent,set_volume); -} - - -/*********************************************************************************************** - * GridCullSystemClass::init_volume -- inits volume to contain the given oriented box * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 3/30/2000 gth : Created. * - *=============================================================================================*/ -WWINLINE void GridCullSystemClass::init_volume(const OBBoxClass & box,VolumeStruct * set_volume) -{ - Vector3 aaextent; - box.Compute_Axis_Aligned_Extent(&aaextent); - init_volume(box.Center - aaextent,box.Center + aaextent,set_volume); -} - - -/*********************************************************************************************** - * GridCullSystemClass::init_volume -- inits volume to contain the given frustum * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 3/30/2000 gth : Created. * - *=============================================================================================*/ -WWINLINE void GridCullSystemClass::init_volume(const FrustumClass & frustum,VolumeStruct * set_volume) -{ - init_volume(frustum.Get_Bound_Min(),frustum.Get_Bound_Max(),set_volume); -} - - -/*********************************************************************************************** - * GridCullSystemClass::VolumeStruct::VolumeStruct -- constructor * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - *=============================================================================================*/ -WWINLINE GridCullSystemClass::VolumeStruct::VolumeStruct(void) -{ -} - - -/*********************************************************************************************** - * GridCullSystemClass::VolumeStruct::VolumeStruct -- constructor * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 3/30/2000 gth : Created. * - *=============================================================================================*/ -WWINLINE GridCullSystemClass::VolumeStruct::VolumeStruct(int i0,int j0,int k0,int i1,int j1,int k1) -{ - Min[0] = i0; - Min[1] = j0; - Min[2] = k0; - Max[0] = i1; - Max[1] = j1; - Max[2] = k1; - WWASSERT(Max[0] > Min[0]); - WWASSERT(Max[1] > Min[1]); - WWASSERT(Max[2] > Min[2]); -} - - -/*********************************************************************************************** - * GridCullSystemClass::VolumeStruct::Is_Leaf -- check if volume is a leaf * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 3/30/2000 gth : Created. * - *=============================================================================================*/ -WWINLINE bool GridCullSystemClass::VolumeStruct::Is_Leaf(void) const -{ - return ((Max[0]-Min[0] == 1) && (Max[1]-Min[1] == 1) && (Max[2]-Min[2] == 1)); -} - - -/*********************************************************************************************** - * GridCullSystemClass::VolumeStruct::Is_Empty -- check if volume is empty (or invalid) * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 3/30/2000 gth : Created. * - *=============================================================================================*/ -WWINLINE bool GridCullSystemClass::VolumeStruct::Is_Empty(void) const -{ - return ((Max[0]-Min[0] <= 0) || (Max[1]-Min[1] <= 0) || (Max[2]-Min[2] <= 0)); -} - - -/*********************************************************************************************** - * GridCullSystemClass::VolumeStruct::Split -- split this volume * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 3/30/2000 gth : Created. * - *=============================================================================================*/ -WWINLINE void GridCullSystemClass::VolumeStruct::Split(VolumeStruct & v0,VolumeStruct & v1) const -{ - // find the longest dimension - int split_axis = 0; - int delta[3]; - - delta[0] = Max[0] - Min[0]; - delta[1] = Max[1] - Min[1]; - delta[2] = Max[2] - Min[2]; - - if (delta[1] > delta[split_axis]) split_axis = 1; - if (delta[2] > delta[split_axis]) split_axis = 2; - - WWASSERT(delta[split_axis] > 0); - - // split the volume perpendicularly to that dimension - memcpy(&v0,this,sizeof(VolumeStruct)); - memcpy(&v1,this,sizeof(VolumeStruct)); - - v0.Max[split_axis] = v1.Min[split_axis] = Min[split_axis] + (delta[split_axis] >> 1); -} diff --git a/Generals/Code/Libraries/Source/WWVegas/WWMath/hermitespline.cpp b/Generals/Code/Libraries/Source/WWVegas/WWMath/hermitespline.cpp deleted file mode 100644 index 77cda843ee5..00000000000 --- a/Generals/Code/Libraries/Source/WWVegas/WWMath/hermitespline.cpp +++ /dev/null @@ -1,437 +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 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 : WWMath * - * * - * $Archive:: /VSS_Sync/wwmath/hermitespline.cpp $* - * * - * Author:: Greg Hjelstrom * - * * - * $Modtime:: 6/13/01 2:18p $* - * * - * $Revision:: 11 $* - * * - *---------------------------------------------------------------------------------------------* - * Functions: * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - - -#include "hermitespline.h" -#include "wwmathids.h" -#include "persistfactory.h" -#include "wwhack.h" - - -/* -** Force-Link this module because the linker can't detect that we actually need it... -*/ -DECLARE_FORCE_LINK(hermitespline); - -/* -** Save-Load stuff -*/ -SimplePersistFactoryClass _HermiteSpline3DFactory; -SimplePersistFactoryClass _HermiteSpline1DFactory; - -enum -{ - // ID's used by HermiteSpline3D - HERMITE3D_CHUNK_CURVE3D = 0x00020727, - HERMITE3D_CHUNK_TANGENTS, - - // ID's used by HermiteSpline1D - HERMITE1D_CHUNK_CURVE1D = 0x00020729, - HERMITE1D_CHUNK_TANGENTS, -}; - - -/* -** Hermite Spline -*/ -const HermiteSpline3DClass &HermiteSpline3DClass::operator= (const HermiteSpline3DClass &that) -{ - // - // This is included for completeness only, it basically - // implements the default bitwise copy operator. - // - TangentsDirty = that.TangentsDirty; - Tangents = that.Tangents; - Curve3DClass::operator= (that); - return (*this); -} - -void HermiteSpline3DClass::Set_Looping(bool onoff) -{ - if (onoff != IsLooping) { - Curve3DClass::Set_Looping(onoff); - TangentsDirty = true; - } -} - -void HermiteSpline3DClass::Evaluate(float time,Vector3 * set_val) -{ - // if we're outside the range, return the start or end... - if (time < Keys[0].Time) { - *set_val = Keys[0].Point; - return; - } - - if (time > Keys[Keys.Count() - 1].Time) { - *set_val = Keys[Keys.Count() - 1].Point; - return; - } - - // if the tangents are marked dirty, give derived classes a chance to recompute them - if (TangentsDirty) { - Update_Tangents(); - } - - // ok find the segment - int i0,i1; - float t; - Find_Interval(time,&i0,&i1,&t); - - float t2 = t*t; - float t3 = t2*t; - - // hermite basis functions: - float h0 = 2*t3 - 3*t2 + 1; - float h1 = -2*t3 + 3*t2; - float h2 = t3 - 2*t2 + t; - float h3 = t3 - t2; - - set_val->X = h0*Keys[i0].Point.X + h1*Keys[i1].Point.X + - h2*Tangents[i0].OutTangent.X + h3*Tangents[i1].InTangent.X; - - set_val->Y = h0*Keys[i0].Point.Y + h1*Keys[i1].Point.Y + - h2*Tangents[i0].OutTangent.Y + h3*Tangents[i1].InTangent.Y; - - set_val->Z = h0*Keys[i0].Point.Z + h1*Keys[i1].Point.Z + - h2*Tangents[i0].OutTangent.Z + h3*Tangents[i1].InTangent.Z; -} - -void HermiteSpline3DClass::Evaluate_Derivative(float time,Vector3 * set_val) -{ - // if we're outside the range, return the value for the start or end... - float min_time = Keys[0].Time; - float max_time = Keys[Keys.Count() - 1].Time; - time = MAX(time, min_time); - time = MIN(time, max_time); - - // if the tangents are marked dirty, give derived classes a chance to recompute them - if (TangentsDirty) { - Update_Tangents(); - } - - // ok find the segment - int i0,i1; - float t; - Find_Interval(time,&i0,&i1,&t); - - float t2 = t*t; - - // derivatives of hermite basis functions: - float dh0 = 6*t2 - 6*t; - float dh1 = -6*t2 + 6*t; - float dh2 = 3*t2 - 4*t + 1; - float dh3 = 3*t2 - 2*t; - - set_val->X = dh0*Keys[i0].Point.X + dh1*Keys[i1].Point.X + - dh2*Tangents[i0].OutTangent.X + dh3*Tangents[i1].InTangent.X; - - set_val->Y = dh0*Keys[i0].Point.Y + dh1*Keys[i1].Point.Y + - dh2*Tangents[i0].OutTangent.Y + dh3*Tangents[i1].InTangent.Y; - - set_val->Z = dh0*Keys[i0].Point.Z + dh1*Keys[i1].Point.Z + - dh2*Tangents[i0].OutTangent.Z + dh3*Tangents[i1].InTangent.Z; -} - -void HermiteSpline3DClass::Set_Key(int i,const Vector3 & point) -{ - Curve3DClass::Set_Key(i,point); - TangentsDirty = true; -} - -int HermiteSpline3DClass::Add_Key(const Vector3 & point,float t) -{ - int index = Curve3DClass::Add_Key(point,t); - TangentsDirty = true; - TangentsClass tan; - tan.InTangent.Set(0,0,0); - tan.OutTangent.Set(0,0,0); - Tangents.Insert(index,tan); - return index; -} - -void HermiteSpline3DClass::Remove_Key(int i) -{ - Tangents.Delete(i); - Curve3DClass::Remove_Key(i); - TangentsDirty = true; -} - -void HermiteSpline3DClass::Clear_Keys(void) -{ - Tangents.Clear(); - Curve3DClass::Clear_Keys(); - TangentsDirty = true; -} - -void HermiteSpline3DClass::Set_Tangents(int i,const Vector3 & in_tan,const Vector3 & out_tan) -{ - assert(i>=0); - assert(i=0); - assert(i Keys[Keys.Count() - 1].Time) { - *set_val = Keys[Keys.Count() - 1].Point; - return; - } - } - - // if the tangents are marked dirty, give derived classes a chance to recompute them - if (TangentsDirty) { - Update_Tangents(); - } - - // ok find the segment - int i0,i1; - float t; - Find_Interval(time,&i0,&i1,&t); - - float t2 = t*t; - float t3 = t2*t; - - // hermite basis functions: - float h0 = 2*t3 - 3*t2 + 1; - float h1 = -2*t3 + 3*t2; - float h2 = t3 - 2*t2 + t; - float h3 = t3 - t2; - - *set_val = h0*Keys[i0].Point + h1*Keys[i1].Point + - h2*Tangents[i0].OutTangent + h3*Tangents[i1].InTangent; -} - -void HermiteSpline1DClass::Set_Key(int i,float point,unsigned int extra) -{ - Curve1DClass::Set_Key(i,point,extra); - TangentsDirty = true; -} - -int HermiteSpline1DClass::Add_Key(float point,float t,unsigned int extra) -{ - int index = Curve1DClass::Add_Key(point,t,extra); - TangentsDirty = true; - TangentsClass tan; - tan.InTangent = 0.0f; - tan.OutTangent = 0.0f; - Tangents.Insert(index,tan); - return index; -} - -void HermiteSpline1DClass::Remove_Key(int i) -{ - Tangents.Delete(i); - Curve1DClass::Remove_Key(i); - TangentsDirty = true; -} - -void HermiteSpline1DClass::Clear_Keys(void) -{ - Tangents.Clear(); - Curve1DClass::Clear_Keys(); - TangentsDirty = true; -} - -void HermiteSpline1DClass::Set_Tangents(int i,float in_tan,float out_tan) -{ - assert(i>=0); - assert(i=0); - assert(i. -*/ - -/*********************************************************************************************** - *** 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 : WWMath * - * * - * $Archive:: /VSS_Sync/wwmath/hermitespline.h $* - * * - * Author:: Greg Hjelstrom * - * * - * $Modtime:: 6/13/01 2:18p $* - * * - * $Revision:: 7 $* - * * - *---------------------------------------------------------------------------------------------* - * Functions: * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - - -#if defined(_MSC_VER) -#pragma once -#endif - -#ifndef HERMITE_H -#define HERMITE_H - -#include "curve.h" - -/* -** HermiteSpline3DClass -** 3-Dimensional hermite spline interpolation -** Hermite splines require you to input all of the tangents... -*/ -class HermiteSpline3DClass : public Curve3DClass -{ -public: - HermiteSpline3DClass(void) - : TangentsDirty (true) { } - - HermiteSpline3DClass(const HermiteSpline3DClass &that) - : TangentsDirty (true) { (*this) = that; } - - const HermiteSpline3DClass &operator= (const HermiteSpline3DClass &that); - - virtual void Evaluate(float time,Vector3 * set_val); - virtual void Evaluate_Derivative(float time,Vector3 * set_val); - virtual void Set_Looping(bool onoff); - - virtual void Set_Key(int i,const Vector3 & point); - virtual int Add_Key(const Vector3 & point,float t); - virtual void Remove_Key(int i); - virtual void Clear_Keys(void); - - virtual void Set_Tangents(int i,const Vector3 & in_tan,const Vector3 & out_tan); - virtual void Get_Tangents(int i,Vector3 * set_in,Vector3 * set_out); - - virtual void Update_Tangents(void) { TangentsDirty = false; } - - // save-load support - virtual const PersistFactoryClass & Get_Factory(void) const; - virtual bool Save(ChunkSaveClass &csave); - virtual bool Load(ChunkLoadClass &cload); - -protected: - - class TangentsClass - { - public: - Vector3 InTangent; - Vector3 OutTangent; - bool operator == (const TangentsClass & that) { return ((InTangent == that.InTangent) && (OutTangent == that.OutTangent)); } - bool operator != (const TangentsClass & that) { return !TangentsClass::operator == (that); } - }; - - bool TangentsDirty; - DynamicVectorClass Tangents; -}; - - -/* -** HermiteSpline1DClass -** 1-Dimensional hermite spline interpolation -** Hermite splines require you to input all of the tangents... -*/ -class HermiteSpline1DClass : public Curve1DClass -{ -public: - HermiteSpline1DClass (void) - : TangentsDirty (true) { } - - virtual void Evaluate(float time,float * set_val); - virtual void Set_Looping(bool onoff); - - virtual void Set_Key(int i,float point,unsigned int extra=0); - virtual int Add_Key(float point,float t,unsigned int extra=0); - virtual void Remove_Key(int i); - virtual void Clear_Keys(void); - - virtual void Set_Tangents(int i,float in_tan,float out_tan); - virtual void Get_Tangents(int i,float * set_in,float * set_out); - - // save-load support - virtual const PersistFactoryClass & Get_Factory(void) const; - virtual bool Save(ChunkSaveClass &csave); - virtual bool Load(ChunkLoadClass &cload); - -protected: - - class TangentsClass - { - public: - float InTangent; - float OutTangent; - bool operator == (const TangentsClass & that) { return ((InTangent == that.InTangent) && (OutTangent == that.OutTangent)); } - bool operator != (const TangentsClass & that) { return !TangentsClass::operator == (that); } - }; - - virtual void Update_Tangents(void) { TangentsDirty = false; } - - bool TangentsDirty; - DynamicVectorClass Tangents; -}; - - -#endif diff --git a/Generals/Code/Libraries/Source/WWVegas/WWMath/lineseg.cpp b/Generals/Code/Libraries/Source/WWVegas/WWMath/lineseg.cpp deleted file mode 100644 index 88fec4e9caf..00000000000 --- a/Generals/Code/Libraries/Source/WWVegas/WWMath/lineseg.cpp +++ /dev/null @@ -1,231 +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 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 : WWMath * - * * - * $Archive:: /Commando/Code/wwmath/lineseg.cpp $* - * * - * Author:: Greg_h * - * * - * $Modtime:: 3/16/00 3:16p $* - * * - * $Revision:: 25 $* - * * - *---------------------------------------------------------------------------------------------* - * Functions: * - * LineSegClass::Set -- Initialize this 'lineseg' by transforming another 'lineseg' * - * LineSegClass::Set_Random -- create a random linesegment within the given space * - * LineSegClass::Find_Point_Closest_To -- Finds point on line closest to point supplied. * - * LineSegClass::Find_Intersection -- Finds the closest points on the two lines * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - -#include "lineseg.h" -//#include - -#include "matrix3d.h" - -/*********************************************************************************************** - * LineSegClass::Set -- Initialize this 'lineseg' by transforming another 'lineseg' * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 6/17/98 GTH : Created. * - *=============================================================================================*/ -void LineSegClass::Set(const LineSegClass & that,const Matrix3D & tm) -{ - /* - ** Transform P0 and P1 - */ - Matrix3D::Transform_Vector(tm,that.P0,&P0); - Matrix3D::Transform_Vector(tm,that.P1,&P1); - - /* - ** Just calculate DP - */ - DP = P1 - P0; - - /* - ** Rotate the direction vector - */ - Matrix3D::Rotate_Vector(tm,that.Dir,&Dir); - - /* - ** Length should be un-changed - */ - Length = that.Length; -} - -/*********************************************************************************************** - * LineSegClass::Set_Random -- create a random linesegment within the given space * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 4/21/98 GTH : Created. * - *=============================================================================================*/ -void LineSegClass::Set_Random(const Vector3 & min,const Vector3 & max) -{ - float frac; - - frac = WWMath::Random_Float(); - P0.X = min.X + frac * (max.X - min.X); - frac = WWMath::Random_Float(); - P0.Y = min.Y + frac * (max.Y - min.Y); - frac = WWMath::Random_Float(); - P0.Z = min.Z + frac * (max.Z - min.Z); - - frac = WWMath::Random_Float(); - P1.X = min.X + frac * (max.X - min.X); - frac = WWMath::Random_Float(); - P1.Y = min.Y + frac * (max.Y - min.Y); - frac = WWMath::Random_Float(); - P1.Z = min.Z + frac * (max.Z - min.Z); - - DP = P1 - P0; - Dir = DP; - Dir.Normalize(); - Length = DP.Length(); -} - - - - -/*********************************************************************************************** - * LineSegClass::Find_Point_Closest_To -- Finds point on line closest to point supplied. * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 07/26/1999 SKB : Created. * - *=============================================================================================*/ -Vector3 LineSegClass::Find_Point_Closest_To(const Vector3 &pos) const -{ - // Get a vector from one line endpoint to point in question. - Vector3 v_0_pos = (pos - P0); - float dotprod = Vector3::Dot_Product(Dir, v_0_pos); - - // Check to see if point is past either of the endpoints. - // (Unable to draw a perpendicular line from the point to the line segment.) - if (dotprod <= 0.0) { - return(P0); - } else if (dotprod >= Length) { - return(P1); - } - - // Find point on line seg that is closest to pos passed in. - Vector3 point = P0 + (dotprod * Dir); - return(point); -} - - -/*********************************************************************************************** - * LineSegClass::Find_Intersection -- Finds the closest points on the two lines.. * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 03/03/2000 PDS : Created. * - *=============================================================================================*/ -bool -LineSegClass::Find_Intersection -( - const LineSegClass & other_line, - Vector3 * p1, - float * fraction1, - Vector3 * p2, - float * fraction2 -) const -{ - bool retval = false; - -#ifdef ALLOW_TEMPORARIES - Vector3 cross1 = Vector3::Cross_Product (Dir, other_line.Dir); - Vector3 cross2 = Vector3::Cross_Product (other_line.P0 - P0, other_line.Dir); - float top1 = cross2 * cross1; - float bottom1 = cross1 * cross1; - - Vector3 cross3 = Vector3::Cross_Product (other_line.Dir, Dir); - Vector3 cross4 = Vector3::Cross_Product (P0 - other_line.P0, Dir); - float top2 = cross4 * cross3; - float bottom2 = cross3 * cross3; -#else - Vector3 cross1, cross2, cross3, cross4; - - Vector3::Cross_Product(Dir, other_line.Dir, &cross1); - Vector3::Cross_Product(other_line.P0 - P0, other_line.Dir, &cross2); - float top1 = Vector3::Dot_Product(cross2, cross1); - float bottom1 = Vector3::Dot_Product(cross1, cross1); - - Vector3::Cross_Product(other_line.Dir, Dir, &cross3); - Vector3::Cross_Product(P0 - other_line.P0, Dir, &cross4); - float top2 = Vector3::Dot_Product(cross4, cross3); - float bottom2 = Vector3::Dot_Product(cross3, cross3); -#endif - - // - // If either of the divisors are 0, then the lines are parallel - // - if (bottom1 != 0 && bottom2 != 0) { - float length1 = top1 / bottom1; - float length2 = top2 / bottom2; - - // - // Calculate the closest points on both lines. - // Note: If the points are the same, then the lines intersect. - // - (*p1) = P0 + (Dir * length1); - (*p2) = other_line.P0 + (other_line.Dir * length2); - - // - // Return the fractions if they caller wants them - // - if (fraction1 != NULL) { - (*fraction1) = length1 / Length; - } - - if (fraction2 != NULL) { - (*fraction2) = length2 / Length; - } - - retval = true; - } - - return retval; -} - diff --git a/Generals/Code/Libraries/Source/WWVegas/WWMath/lineseg.h b/Generals/Code/Libraries/Source/WWVegas/WWMath/lineseg.h deleted file mode 100644 index d0b7ee79f14..00000000000 --- a/Generals/Code/Libraries/Source/WWVegas/WWMath/lineseg.h +++ /dev/null @@ -1,93 +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 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 : WWMath * - * * - * $Archive:: /Commando/Code/wwmath/lineseg.h $* - * * - * Author:: Greg_h * - * * - * $Modtime:: 3/16/00 3:16p $* - * * - * $Revision:: 21 $* - * * - *---------------------------------------------------------------------------------------------* - * Functions: * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - - -#if defined(_MSC_VER) -#pragma once -#endif - -#ifndef LINESEG_H -#define LINESEG_H - -#include "always.h" -#include "vector3.h" -#include "castres.h" - -class TriClass; -class AABoxClass; -class OBBoxClass; -class PlaneClass; -class SphereClass; -class Matrix3D; - - -class LineSegClass -{ - -public: - - LineSegClass(void) { } - LineSegClass(const Vector3 & p0,const Vector3 & p1) : P0(p0), P1(p1) { recalculate(); } - LineSegClass(const LineSegClass & that,const Matrix3D & tm) { Set(that,tm); } - - void Set(const Vector3 & p0,const Vector3 & p1) { P0 = p0; P1 = p1; recalculate(); } - void Set(const LineSegClass & that,const Matrix3D & tm); - void Set_Random(const Vector3 & min,const Vector3 & max); - - const Vector3 & Get_P0() const { return P0; } // start point - const Vector3 & Get_P1() const { return P1; } // end point - const Vector3 & Get_DP() const { return DP; } // difference of the two points - const Vector3 & Get_Dir() const { return Dir; } // normalized direction. - float Get_Length() const { return Length; } // length of the segment - - void Compute_Point(float t,Vector3 * set) const { Vector3::Add(P0,t*DP,set); } - - Vector3 Find_Point_Closest_To(const Vector3 &pos) const; - bool Find_Intersection (const LineSegClass &other_line, Vector3 *p1, float *fraction1, Vector3 *p2, float *fraction2) const; - -protected: - - void recalculate(void) { DP = P1 - P0; Dir = DP; Dir.Normalize(); Length = DP.Length(); } - - Vector3 P0; // start point - Vector3 P1; // end point - Vector3 DP; // difference of the two points - Vector3 Dir; // normalized direction. - float Length; // length of the segment -}; - - -#endif diff --git a/Generals/Code/Libraries/Source/WWVegas/WWMath/lookuptable.cpp b/Generals/Code/Libraries/Source/WWVegas/WWMath/lookuptable.cpp deleted file mode 100644 index 4608cfbb754..00000000000 --- a/Generals/Code/Libraries/Source/WWVegas/WWMath/lookuptable.cpp +++ /dev/null @@ -1,250 +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 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 : WWPhys * - * * - * $Archive:: /Commando/Code/wwmath/lookuptable.cpp $* - * * - * Original Author:: Greg Hjelstrom * - * * - * $Author:: Byon_g $* - * * - * $Modtime:: 7/23/01 6:18p $* - * * - * $Revision:: 5 $* - * * - *---------------------------------------------------------------------------------------------* - * Functions: * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - -#include "lookuptable.h" -#include "curve.h" -#include "WWFILE.H" -#include "ffactory.h" -#include "chunkio.h" -#include "persistfactory.h" -#include "vector2.h" - - -/* -** Static members -*/ -RefMultiListClass LookupTableMgrClass::Tables; - -/* -** Save-Load stuff. Lookup tables are basically saved 1D curve classes. They are turned -** into tables at load time. For future expansion, the curve is wrapped in a chunk. -*/ -enum -{ - LOOKUPTABLE_CHUNK_CURVE = 03071200, - LOOKUPTABLE_CHUNK_EXTENTS, -}; - - -/*********************************************************************************************** -** -** LookupTableClass Implementation -** -***********************************************************************************************/ -LookupTableClass::LookupTableClass(int sample_count) : - MinInputValue(0.0f), - MaxInputValue(0.0f), - OutputSamples(sample_count) -{ -} - -LookupTableClass::~LookupTableClass(void) -{ -} - -void LookupTableClass::Init(const char * name,Curve1DClass * curve) -{ - // copy the name - Name = name; - - // Store the min and max input values for the table - curve->Get_Key(0,NULL,&MinInputValue,NULL); - curve->Get_Key(curve->Key_Count()-1,NULL,&MaxInputValue,NULL); - OOMaxMinusMin = 1.0f / (MaxInputValue - MinInputValue); - - // Sample the curve and store the output values - for (int i=0; iEvaluate(x,&y); - OutputSamples[i] = y; - } -} - - - -/*********************************************************************************************** -** -** LookupTableManager Implementation -** -***********************************************************************************************/ -void LookupTableMgrClass::Init(void) -{ - // create a default table that the user can use in an emergency - LookupTableClass * default_table = NEW_REF(LookupTableClass,(2)); - LinearCurve1DClass * default_curve = W3DNEW LinearCurve1DClass; - - default_curve->Add_Key(0.5f,0.0f); - default_curve->Add_Key(0.5f,1.0f); - default_table->Init("DefaultTable",default_curve); - Add_Table(default_table); - - delete default_curve; - default_table->Release_Ref(); -} - -void LookupTableMgrClass::Shutdown(void) -{ - Reset(); -} - -void LookupTableMgrClass::Reset(void) -{ - while (Tables.Peek_Head() != NULL) { - Tables.Release_Head(); - } -} - -bool LookupTableMgrClass::Add_Table(LookupTableClass * table) -{ - return Tables.Add(table); -} - -bool LookupTableMgrClass::Remove_Table(LookupTableClass * table) -{ - return Tables.Remove(table); -} - -LookupTableClass * LookupTableMgrClass::Get_Table(const char * name,bool try_to_load) -{ - // check if we already have this table loaded... - RefMultiListIterator it(&Tables); - for (it.First(); !it.Is_Done(); it.Next()) { - if (stricmp(it.Peek_Obj()->Get_Name(),name) == 0) { - return it.Get_Obj(); // add a reference for the user... - } - } - - // otherwise we can try to load it. - LookupTableClass * new_table = NULL; - if (try_to_load) { - - FileClass * file = _TheFileFactory->Get_File(name); - if (file && file->Open()) { - - ChunkLoadClass cload(file); - - Curve1DClass * curve = NULL; - Load_Table_Desc(cload,&curve); - if (curve != NULL) { - new_table = NEW_REF(LookupTableClass,()); - new_table->Init(name,curve); - Add_Table(new_table); - delete curve; - } - } - _TheFileFactory->Return_File(file); - } - - return new_table; // constructor ref is returned to user. -} - -void LookupTableMgrClass::Save_Table_Desc -( - ChunkSaveClass & csave, - Curve1DClass * curve, - const Vector2 & min_corner, - const Vector2 & max_corner -) -{ - // save the curve - csave.Begin_Chunk(LOOKUPTABLE_CHUNK_CURVE); - csave.Begin_Chunk(curve->Get_Factory().Chunk_ID()); - curve->Get_Factory().Save(csave,curve); - csave.End_Chunk(); - csave.End_Chunk(); - - // save the extents - csave.Begin_Chunk(LOOKUPTABLE_CHUNK_EXTENTS); - csave.Write(&(min_corner.X),sizeof(float)); - csave.Write(&(min_corner.Y),sizeof(float)); - csave.Write(&(max_corner.X),sizeof(float)); - csave.Write(&(max_corner.Y),sizeof(float)); - csave.End_Chunk(); -} - -void LookupTableMgrClass::Load_Table_Desc -( - ChunkLoadClass & cload, - Curve1DClass ** curve_ptr, - Vector2 * set_min_corner, - Vector2 * set_max_corner -) -{ - *curve_ptr = NULL; - PersistFactoryClass * factory; - - float xmin,xmax; - float ymin,ymax; - xmin = xmax = ymin = ymax = 0.0f; - - while (cload.Open_Chunk()) { - switch(cload.Cur_Chunk_ID()) { - case LOOKUPTABLE_CHUNK_CURVE: - cload.Open_Chunk(); - factory = SaveLoadSystemClass::Find_Persist_Factory(cload.Cur_Chunk_ID()); - WWASSERT(factory != NULL); - if (factory != NULL) { - *curve_ptr = (Curve1DClass *)factory->Load(cload); - } - cload.Close_Chunk(); - break; - case LOOKUPTABLE_CHUNK_EXTENTS: - cload.Read(&xmin,sizeof(xmin)); - cload.Read(&ymin,sizeof(ymin)); - cload.Read(&xmax,sizeof(xmax)); - cload.Read(&ymax,sizeof(ymax)); - break; - - default: - WWDEBUG_SAY(("Unhandled Chunk: 0x%X File: %s Line: %d\r\n",__FILE__,__LINE__)); - break; - } - cload.Close_Chunk(); - } - - if (set_min_corner != NULL) { - set_min_corner->Set(xmin,ymin); - } - if (set_max_corner != NULL) { - set_max_corner->Set(xmax,ymax); - } -} - - - diff --git a/Generals/Code/Libraries/Source/WWVegas/WWMath/lookuptable.h b/Generals/Code/Libraries/Source/WWVegas/WWMath/lookuptable.h deleted file mode 100644 index 33b70ee8e19..00000000000 --- a/Generals/Code/Libraries/Source/WWVegas/WWMath/lookuptable.h +++ /dev/null @@ -1,161 +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 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 : WWPhys * - * * - * $Archive:: /Commando/Code/wwmath/lookuptable.h $* - * * - * Original Author:: Greg Hjelstrom * - * * - * $Author:: Greg_h $* - * * - * $Modtime:: 4/18/00 1:20p $* - * * - * $Revision:: 6 $* - * * - *---------------------------------------------------------------------------------------------* - * Functions: * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - - -#ifndef LOOKUPTABLE_H -#define LOOKUPTABLE_H - -#include "always.h" -#include "simplevec.h" -#include "wwstring.h" -#include "refcount.h" -#include "multilist.h" -#include "wwmath.h" - - -class Vector2; -class Curve1DClass; -class ChunkSaveClass; -class ChunkLoadClass; - - -/** -** LookupTableClass -** This class contains the tabulated values for a function. -*/ -class LookupTableClass : public RefCountClass, public MultiListObjectClass -{ -public: - - LookupTableClass(int sample_count = 256); - virtual ~LookupTableClass(void); - - void Init(const char * name,Curve1DClass * curve); - float Get_Value(float input); - float Get_Value_Quick(float input); - const char * Get_Name(void) { return Name; } -protected: - - StringClass Name; // name of this table, if it came from a file, this is also the filename - float MinInputValue; - float MaxInputValue; - float OOMaxMinusMin; - SimpleVecClass OutputSamples; - -}; - -inline float LookupTableClass::Get_Value(float input) -{ - if (input <= MinInputValue) { - return OutputSamples[0]; - } - if (input >= MaxInputValue) { - return OutputSamples[OutputSamples.Length()-1]; - } - - float normalized_input = (float)(OutputSamples.Length()-1) * (input - MinInputValue) * OOMaxMinusMin; - float input0 = WWMath::Floor(normalized_input); - - int index0 = WWMath::Float_To_Long(input0); - int index1 = index0+1; - float lerp = normalized_input - input0; - - return OutputSamples[index0] + lerp * (OutputSamples[index1] - OutputSamples[index0]); -} - -inline float LookupTableClass::Get_Value_Quick(float input) -{ - if (input <= MinInputValue) { - return OutputSamples[0]; - } - if (input >= MaxInputValue) { - return OutputSamples[OutputSamples.Length()-1]; - } - - int index = (OutputSamples.Length()-1) * WWMath::Float_To_Long((input - MinInputValue) * OOMaxMinusMin); - return OutputSamples[index]; -} - - -/** -** LookupTableMgrClass -** This class tracks all of the LookupTableClass's that have been loaded or installed. -** LookupTables can be created using the "SimpleGraph" tool. It basically allows you -** to edit a curve which will be used to generate the table. These curves are stored -** in .TBL files. -** -** NOTE: Use the SimpleGraph program to create lookup tables! Then just ask for them -** by filename and it will load the table for you (unless it is already loaded). -** -** NOTE: I add a table called "DefaultTable" so that you can revert to that if -** your table isn't found. -*/ -class LookupTableMgrClass -{ -public: - LookupTableMgrClass(void); - ~LookupTableMgrClass(void); - - // init and shutdown are automatically called from WWMath::Init, WWMath::Shutdown... - static void Init(void); - static void Shutdown(void); - - static bool Add_Table(LookupTableClass * table); - static bool Remove_Table(LookupTableClass * table); - static LookupTableClass * Get_Table(const char * name,bool try_to_load = true); - - static void Save_Table_Desc( ChunkSaveClass & csave, - Curve1DClass * curve, - const Vector2 & min, - const Vector2 & max ); - - static void Load_Table_Desc( ChunkLoadClass & cload, - Curve1DClass ** curve_ptr, - Vector2 * set_min = NULL, - Vector2 * set_max = NULL ); - - static void Reset(void); - -protected: - - static RefMultiListClass Tables; - -}; - - -#endif // LOOKUPTABLE_H diff --git a/Generals/Code/Libraries/Source/WWVegas/WWMath/matrix3.cpp b/Generals/Code/Libraries/Source/WWVegas/WWMath/matrix3.cpp deleted file mode 100644 index 70cbfbf07c6..00000000000 --- a/Generals/Code/Libraries/Source/WWVegas/WWMath/matrix3.cpp +++ /dev/null @@ -1,393 +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 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 : WWMath * - * * - * $Archive:: /Commando/Code/wwmath/matrix3.cpp $* - * * - * Org Author:: Greg_h * - * * - * Author : Kenny Mitchell * - * * - * $Modtime:: 06/26/02 4:04p $* - * * - * $Revision:: 17 $* - * * - * 06/26/02 KM Matrix name change to avoid MAX conflicts * - *---------------------------------------------------------------------------------------------* - * Functions: * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - - -#include "matrix3.h" -#include "matrix3d.h" -#include "matrix4.h" -#include "quat.h" - - -/* -** Some pre-initialized Matrix3x3's -*/ -const Matrix3x3 Matrix3x3::Identity -( - 1.0, 0.0, 0.0, - 0.0, 1.0, 0.0, - 0.0, 0.0, 1.0 -); - -const Matrix3x3 Matrix3x3::RotateX90 -( - 1.0, 0.0, 0.0, - 0.0, 0.0, -1.0, - 0.0, 1.0, 0.0 -); - -const Matrix3x3 Matrix3x3::RotateX180 -( - 1.0, 0.0, 0.0, - 0.0, -1.0, 0.0, - 0.0, 0.0, -1.0 -); - -const Matrix3x3 Matrix3x3::RotateX270 -( - 1.0, 0.0, 0.0, - 0.0, 0.0, 1.0, - 0.0, -1.0, 0.0 -); - -const Matrix3x3 Matrix3x3::RotateY90 -( - 0.0, 0.0, 1.0, - 0.0, 1.0, 0.0, - -1.0, 0.0, 0.0 -); - -const Matrix3x3 Matrix3x3::RotateY180 -( - -1.0, 0.0, 0.0, - 0.0, 1.0, 0.0, - 0.0, 0.0, -1.0 -); - -const Matrix3x3 Matrix3x3::RotateY270 -( - 0.0, 0.0, -1.0, - 0.0, 1.0, 0.0, - 1.0, 0.0, 0.0 -); - -const Matrix3x3 Matrix3x3::RotateZ90 -( - 0.0, -1.0, 0.0, - 1.0, 0.0, 0.0, - 0.0, 0.0, 1.0 -); - -const Matrix3x3 Matrix3x3::RotateZ180 -( - -1.0, 0.0, 0.0, - 0.0, -1.0, 0.0, - 0.0, 0.0, 1.0 -); - -const Matrix3x3 Matrix3x3::RotateZ270 -( - 0.0, 1.0, 0.0, - -1.0, 0.0, 0.0, - 0.0, 0.0, 1.0 -); - - - -/*********************************************************************************************** - * Matrix3x3::Matrix3x3 -- Convert a Matrix3D (fake 4x4) to a Matrix3x3 * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 06/02/1997 GH : Created. * - *=============================================================================================*/ -Matrix3x3::Matrix3x3(const Matrix3D & m) -{ - Row[0].Set(m[0][0],m[0][1],m[0][2]); - Row[1].Set(m[1][0],m[1][1],m[1][2]); - Row[2].Set(m[2][0],m[2][1],m[2][2]); -} - -Matrix3x3::Matrix3x3(const Matrix4x4 & m) -{ - Row[0].Set(m[0][0],m[0][1],m[0][2]); - Row[1].Set(m[1][0],m[1][1],m[1][2]); - Row[2].Set(m[2][0],m[2][1],m[2][2]); -} - -void Matrix3x3::Set(const Matrix3D & m) -{ - Row[0].Set(m[0][0],m[0][1],m[0][2]); - Row[1].Set(m[1][0],m[1][1],m[1][2]); - Row[2].Set(m[2][0],m[2][1],m[2][2]); -} - -void Matrix3x3::Set(const Matrix4x4 & m) -{ - Row[0].Set(m[0][0],m[0][1],m[0][2]); - Row[1].Set(m[1][0],m[1][1],m[1][2]); - Row[2].Set(m[2][0],m[2][1],m[2][2]); -} - -void Matrix3x3::Set(const Quaternion & q) -{ - Row[0][0] = (float)(1.0 - 2.0 * (q[1] * q[1] + q[2] * q[2])); - Row[0][1] = (float)(2.0 * (q[0] * q[1] - q[2] * q[3])); - Row[0][2] = (float)(2.0 * (q[2] * q[0] + q[1] * q[3])); - - Row[1][0] = (float)(2.0 * (q[0] * q[1] + q[2] * q[3])); - Row[1][1] = (float)(1.0 - 2.0f * (q[2] * q[2] + q[0] * q[0])); - Row[1][2] = (float)(2.0 * (q[1] * q[2] - q[0] * q[3])); - - Row[2][0] = (float)(2.0 * (q[2] * q[0] - q[1] * q[3])); - Row[2][1] = (float)(2.0 * (q[1] * q[2] + q[0] * q[3])); - Row[2][2] =(float)(1.0 - 2.0 * (q[1] * q[1] + q[0] * q[0])); -} - - -Matrix3x3 & Matrix3x3::operator = (const Matrix3D & m) -{ - Row[0].Set(m[0][0],m[0][1],m[0][2]); - Row[1].Set(m[1][0],m[1][1],m[1][2]); - Row[2].Set(m[2][0],m[2][1],m[2][2]); - return *this; -} - -Matrix3x3 & Matrix3x3::operator = (const Matrix4x4 & m) -{ - Row[0].Set(m[0][0],m[0][1],m[0][2]); - Row[1].Set(m[1][0],m[1][1],m[1][2]); - Row[2].Set(m[2][0],m[2][1],m[2][2]); - return *this; -} - -void Matrix3x3::Multiply(const Matrix3D & a, const Matrix3x3 & b,Matrix3x3 * res) -{ - #define ROWCOL(i,j) a[i][0]*b[0][j] + a[i][1]*b[1][j] + a[i][2]*b[2][j] - - (*res)[0][0] = ROWCOL(0,0); - (*res)[0][1] = ROWCOL(0,1); - (*res)[0][2] = ROWCOL(0,2); - - (*res)[1][0] = ROWCOL(1,0); - (*res)[1][1] = ROWCOL(1,1); - (*res)[1][2] = ROWCOL(1,2); - - (*res)[2][0] = ROWCOL(2,0); - (*res)[2][1] = ROWCOL(2,1); - (*res)[2][2] = ROWCOL(2,2); - - #undef ROWCOL -} - -void Matrix3x3::Multiply(const Matrix3x3 & a, const Matrix3D & b,Matrix3x3 * res) -{ - #define ROWCOL(i,j) a[i][0]*b[0][j] + a[i][1]*b[1][j] + a[i][2]*b[2][j] - - (*res)[0][0] = ROWCOL(0,0); - (*res)[0][1] = ROWCOL(0,1); - (*res)[0][2] = ROWCOL(0,2); - - (*res)[1][0] = ROWCOL(1,0); - (*res)[1][1] = ROWCOL(1,1); - (*res)[1][2] = ROWCOL(1,2); - - (*res)[2][0] = ROWCOL(2,0); - (*res)[2][1] = ROWCOL(2,1); - (*res)[2][2] = ROWCOL(2,2); - - #undef ROWCOL -} - -Matrix3x3 operator * (const Matrix3D & a, const Matrix3x3 & b) -{ - #define ROWCOL(i,j) a[i][0]*b[0][j] + a[i][1]*b[1][j] + a[i][2]*b[2][j] - - return Matrix3x3( - Vector3(ROWCOL(0,0), ROWCOL(0,1), ROWCOL(0,2) ), - Vector3(ROWCOL(1,0), ROWCOL(1,1), ROWCOL(1,2) ), - Vector3(ROWCOL(2,0), ROWCOL(2,1), ROWCOL(2,2) ) - ); - - #undef ROWCOL -} - -Matrix3x3 operator * (const Matrix3x3 & a, const Matrix3D & b) -{ - #define ROWCOL(i,j) a[i][0]*b[0][j] + a[i][1]*b[1][j] + a[i][2]*b[2][j] - - return Matrix3x3( - Vector3(ROWCOL(0,0), ROWCOL(0,1), ROWCOL(0,2) ), - Vector3(ROWCOL(1,0), ROWCOL(1,1), ROWCOL(1,2) ), - Vector3(ROWCOL(2,0), ROWCOL(2,1), ROWCOL(2,2) ) - ); - - #undef ROWCOL -} - - -#if 0 - -void Matrix3x3::Compute_Jacobi_Rotation(int i,int j,Matrix3x3 * r,Matrix3x3 * rinv) -{ - -} - -void Matrix3x3::Symmetric_Eigen_Solve(void) -{ - Matrix3x3 eigen_vals = *this; - Matrix3x3 eigen_vecs(1); - - Matrix3x3 jr,jrinv; - - while (!done) { - eigen_vals.Compute_Jacobi_Rotation(i,j,&jr,&jrinv); - eigen_vals = jr * (eigenvals) * jrinv; - eigen_vecs = eigen_vecs * jr; - } - - /* - ** Done! Eigen values are the diagonals of - ** the eigen_vals matrix and the eigen vectors - ** are the columns of the eigen_vecs matrix - */ - -} - -#endif - - -void Matrix3x3::Multiply(const Matrix3x3 & A,const Matrix3x3 & B,Matrix3x3 * set_res) -{ - Matrix3x3 tmp; - Matrix3x3 * Aptr; - float tmp1,tmp2,tmp3; - - // Check for aliased parameters, copy the 'A' matrix into a temporary if the - // result is going into 'A'. (in this case, this function is no better than - // the overloaded C++ operator...) - if (set_res == &A) { - tmp = A; - Aptr = &tmp; - } else { - Aptr = (Matrix3x3 *)&A; - } - - tmp1 = B[0][0]; - tmp2 = B[1][0]; - tmp3 = B[2][0]; - - (*set_res)[0][0] = (float)((*Aptr)[0][0]*tmp1 + (*Aptr)[0][1]*tmp2 + (*Aptr)[0][2]*tmp3); - (*set_res)[1][0] = (float)((*Aptr)[1][0]*tmp1 + (*Aptr)[1][1]*tmp2 + (*Aptr)[1][2]*tmp3); - (*set_res)[2][0] = (float)((*Aptr)[2][0]*tmp1 + (*Aptr)[2][1]*tmp2 + (*Aptr)[2][2]*tmp3); - - tmp1 = B[0][1]; - tmp2 = B[1][1]; - tmp3 = B[2][1]; - - (*set_res)[0][1] = (float)((*Aptr)[0][0]*tmp1 + (*Aptr)[0][1]*tmp2 + (*Aptr)[0][2]*tmp3); - (*set_res)[1][1] = (float)((*Aptr)[1][0]*tmp1 + (*Aptr)[1][1]*tmp2 + (*Aptr)[1][2]*tmp3); - (*set_res)[2][1] = (float)((*Aptr)[2][0]*tmp1 + (*Aptr)[2][1]*tmp2 + (*Aptr)[2][2]*tmp3); - - tmp1 = B[0][2]; - tmp2 = B[1][2]; - tmp3 = B[2][2]; - - (*set_res)[0][2] = (float)((*Aptr)[0][0]*tmp1 + (*Aptr)[0][1]*tmp2 + (*Aptr)[0][2]*tmp3); - (*set_res)[1][2] = (float)((*Aptr)[1][0]*tmp1 + (*Aptr)[1][1]*tmp2 + (*Aptr)[1][2]*tmp3); - (*set_res)[2][2] = (float)((*Aptr)[2][0]*tmp1 + (*Aptr)[2][1]*tmp2 + (*Aptr)[2][2]*tmp3); -} - -int Matrix3x3::Is_Orthogonal(void) const -{ - Vector3 x(Row[0].X,Row[0].Y,Row[0].Z); - Vector3 y(Row[1].X,Row[1].Y,Row[1].Z); - Vector3 z(Row[2].X,Row[2].Y,Row[2].Z); - - if (Vector3::Dot_Product(x,y) > WWMATH_EPSILON) return 0; - if (Vector3::Dot_Product(y,z) > WWMATH_EPSILON) return 0; - if (Vector3::Dot_Product(z,x) > WWMATH_EPSILON) return 0; - - if (WWMath::Fabs(x.Length() - 1.0f) > WWMATH_EPSILON) return 0; - if (WWMath::Fabs(y.Length() - 1.0f) > WWMATH_EPSILON) return 0; - if (WWMath::Fabs(z.Length() - 1.0f) > WWMATH_EPSILON) return 0; - - return 1; -} - -void Matrix3x3::Re_Orthogonalize(void) -{ - Vector3 x(Row[0][0],Row[0][1],Row[0][2]); - Vector3 y(Row[1][0],Row[1][1],Row[1][2]); - Vector3 z; - - Vector3::Cross_Product(x,y,&z); - Vector3::Cross_Product(z,x,&y); - - float len = x.Length(); - if (len < WWMATH_EPSILON) { - Make_Identity(); - return; - } else { - x /= len; - } - - len = y.Length(); - if (len < WWMATH_EPSILON) { - Make_Identity(); - return; - } else { - y /= len; - } - - len = z.Length(); - if (len < WWMATH_EPSILON) { - Make_Identity(); - return; - } else { - z /= len; - } - - Row[0][0] = x.X; - Row[0][1] = x.Y; - Row[0][2] = x.Z; - - Row[1][0] = y.X; - Row[1][1] = y.Y; - Row[1][2] = y.Z; - - Row[2][0] = z.X; - Row[2][1] = z.Y; - Row[2][2] = z.Z; -} - diff --git a/Generals/Code/Libraries/Source/WWVegas/WWMath/matrix3.h b/Generals/Code/Libraries/Source/WWVegas/WWMath/matrix3.h deleted file mode 100644 index a2c447de01e..00000000000 --- a/Generals/Code/Libraries/Source/WWVegas/WWMath/matrix3.h +++ /dev/null @@ -1,1032 +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 . -*/ - -/* $Header: /Commando/Code/wwmath/matrix3.h 36 5/11/01 7:11p Jani_p $ */ -/*********************************************************************************************** - *** Confidential - Westwood Studios *** - *********************************************************************************************** - * * - * Project Name : WW3D * - * * - * File Name : MATRIX3.H * - * * - * Org Programmer : Greg Hjelstrom * - * * - * Author : Kenny Mitchell * - * * - * Start Date : 06/02/97 * - * * - * Last Update : June 6, 2002 [KM] * - * * - * 06/26/02 KM Matrix name change to avoid MAX conflicts * - *---------------------------------------------------------------------------------------------* - * Functions: * - * Matrix3x3::Matrix3x3 -- Constructor, optionally initialize to Identitiy matrix * - * Matrix3x3::Matrix3x3 -- Copy Constructor * - * Matrix3x3::Matrix3x3 -- Convert a Matrix3D (fake 4x4) to a Matrix3x3 * - * Matrix3x3::Matrix3x3 -- Constructor * - * Matrix3x3::Transpose -- Returns transpose of the matrix * - * Matrix3x3::Inverse -- returns the inverse of the matrix * - * Matrix3x3::Determinant -- returns the determinant of the matrix * - * Matrix3x3::operator = -- assignment operator * - * Matrix3x3::operator += -- "plus equals" operator * - * Matrix3x3::operator-= -- "minus equals" operator * - * Matrix3x3::operator *= -- "times equals" operator * - * Matrix3x3::operator /= -- "divide equals" operator * - * Create_X_Rotation_Matrix3 -- creates a matrix3 which is a rotation about X * - * Create_Y_Rotation_Matrix3 -- Creates a Matrix3x3 which is a rotation about Y * - * Create_Z_Rotation_Matrix3 -- Creates a matrix3 which is a rotation about Z * - * Matrix3x3::Rotate_X -- Post-mutiplies an x rotation onto the current matrix * - * Matrix3x3::Rotate_Y -- Post-multiplies the matrix with a rotation about Y * - * Matrix3x3::Rotate_Z -- Post-multiplies the matrix with a rotation about Z * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - - -#if defined(_MSC_VER) -#pragma once -#endif - -#ifndef Matrix3_H -#define Matrix3_H - -#include "always.h" -#include "vector3.h" -#include "wwdebug.h" -#ifdef _UNIX -#include "osdep.h" -#endif - - -class Matrix3D; -class Matrix4x4; -class Quaternion; - -class Matrix3x3 -{ -public: - - /* - ** Constructors - */ - WWINLINE Matrix3x3(void) {}; - WWINLINE Matrix3x3(const Matrix3x3 & m); - - WWINLINE explicit Matrix3x3(bool identity); - WWINLINE explicit Matrix3x3(const Vector3 & v0, const Vector3 & v1, const Vector3 & v2); - explicit Matrix3x3(const Matrix3D & m); - explicit Matrix3x3(const Matrix4x4 & m); - WWINLINE explicit Matrix3x3( - float m11,float m12,float m13, - float m21,float m22,float m23, - float m31,float m32,float m33 - ); - WWINLINE explicit Matrix3x3(const Vector3 & axis,float angle); - WWINLINE explicit Matrix3x3(const Vector3 & axis,float s_angle,float c_angle); - WWINLINE explicit Matrix3x3(const Quaternion & q); - - /* - ** 'Set' functions - */ - void Set(const Matrix3D & m); - void Set(const Matrix4x4 & m); - WWINLINE void Set(const Vector3 & v0, const Vector3 & v1, const Vector3 & v2); - WWINLINE void Set( - float m11,float m12,float m13, - float m21,float m22,float m23, - float m31,float m32,float m33 - ); - WWINLINE void Set(const Vector3 & axis,float angle); - WWINLINE void Set(const Vector3 & axis,float s_angle,float c_angle); - void Set(const Quaternion & q); - - /* - ** Access operators - */ - WWINLINE Vector3 & operator [] (int i) { return Row[i]; } - WWINLINE const Vector3 & operator [] (int i) const { return Row[i]; } - - /* - ** Transpose and Inverse - */ - WWINLINE Matrix3x3 Transpose (void) const; - WWINLINE Matrix3x3 Inverse (void) const; - WWINLINE float Determinant (void) const; - - /* - ** Assignment operators - */ - WWINLINE Matrix3x3 & operator = (const Matrix3x3 & m); - Matrix3x3 & operator = (const Matrix3D & m); - Matrix3x3 & operator = (const Matrix4x4 & m); - - WWINLINE Matrix3x3 & operator += (const Matrix3x3 & m); - WWINLINE Matrix3x3 & operator -= (const Matrix3x3 & m); - WWINLINE Matrix3x3 & operator *= (float d); - WWINLINE Matrix3x3 & operator /= (float d); - - WWINLINE void Make_Identity(void); - - /* - ** Automatically concatenate a rotation onto the current matrix - */ - WWINLINE void Rotate_X(float theta); - WWINLINE void Rotate_X(float s,float c); - - WWINLINE void Rotate_Y(float theta); - WWINLINE void Rotate_Y(float s,float c); - - WWINLINE void Rotate_Z(float theta); - WWINLINE void Rotate_Z(float s,float c); - - /* - ** These functions will give you the approximate amount that the - ** matrix has been rotated about a given axis. These functions - ** cannot be used to re-build a matrx. Use the EulerAnglesClass - ** to convert a matrix into a set of three Euler angles. - */ - float Get_X_Rotation(void) const; - float Get_Y_Rotation(void) const; - float Get_Z_Rotation(void) const; - - /* - ** These functions return a vector representing the direction an - ** axis is pointing. - */ - WWINLINE Vector3 Get_X_Vector(void) const; - WWINLINE Vector3 Get_Y_Vector(void) const; - WWINLINE Vector3 Get_Z_Vector(void) const; - WWINLINE void Get_X_Vector(Vector3 * set_x) const; - WWINLINE void Get_Y_Vector(Vector3 * set_y) const; - WWINLINE void Get_Z_Vector(Vector3 * set_z) const; - - /* - ** Negation - */ - WWINLINE friend Matrix3x3 operator - (const Matrix3x3& a); - - /* - ** Scalar multiplication and division - */ - WWINLINE friend Matrix3x3 operator * (const Matrix3x3& a,float d); - WWINLINE friend Matrix3x3 operator * (float d,const Matrix3x3& a); - WWINLINE friend Matrix3x3 operator / (const Matrix3x3& a,float d); - - /* - ** matrix addition - */ - WWINLINE friend Matrix3x3 operator + (const Matrix3x3& a, const Matrix3x3& b); - static WWINLINE void Add(const Matrix3x3 & a, const Matrix3x3 & b,Matrix3x3 * res); - - /* - ** matrix subtraction - */ - WWINLINE friend Matrix3x3 operator - (const Matrix3x3 & a, const Matrix3x3 & b); - static WWINLINE void Subtract(const Matrix3x3 & a, const Matrix3x3 & b,Matrix3x3 * res); - - /* - ** matrix multiplication - */ - WWINLINE friend Matrix3x3 operator * (const Matrix3x3 & a, const Matrix3x3 & b); - WWINLINE friend Matrix3x3 operator * (const Matrix3D & a, const Matrix3x3 & b); - WWINLINE friend Matrix3x3 operator * (const Matrix3x3 & a, const Matrix3D & b); - - static void Multiply(const Matrix3x3 & a, const Matrix3x3 & b,Matrix3x3 * res); - static void Multiply(const Matrix3D & a, const Matrix3x3 & b,Matrix3x3 * res); - static void Multiply(const Matrix3x3 & a, const Matrix3D & b,Matrix3x3 * res); - - /* - ** Matrix-Vector multiplication - */ - WWINLINE friend Vector3 operator * (const Matrix3x3 & a, const Vector3 & v); - static WWINLINE void Rotate_Vector(const Matrix3x3 & tm,const Vector3 & in,Vector3 * out); - static WWINLINE void Transpose_Rotate_Vector(const Matrix3x3 & tm,const Vector3 & in,Vector3 * out); - - /* - ** Comparison operators - */ - WWINLINE friend int operator == (const Matrix3x3 & a, const Matrix3x3 & b); - WWINLINE friend int operator != (const Matrix3x3 & a, const Matrix3x3 & b); - - /* - ** Swap two matrices in place - */ - WWINLINE friend void Swap(Matrix3x3 & a,Matrix3x3 & b); - - /* - ** Check whether a matrix is orthogonal, make it orthogonal - */ - int Is_Orthogonal(void) const; - void Re_Orthogonalize(void); - - /* - ** Miscellaneous - */ - WWINLINE void Rotate_AABox_Extent(const Vector3 & extent,Vector3 * new_extent); - - /* - ** Some useful pre-initialized Matrix3x3's - */ - static const Matrix3x3 Identity; - static const Matrix3x3 RotateX90; - static const Matrix3x3 RotateX180; - static const Matrix3x3 RotateX270; - static const Matrix3x3 RotateY90; - static const Matrix3x3 RotateY180; - static const Matrix3x3 RotateY270; - static const Matrix3x3 RotateZ90; - static const Matrix3x3 RotateZ180; - static const Matrix3x3 RotateZ270; - -protected: - - Vector3 Row[3]; - -}; - - -/*********************************************************************************************** - * Matrix3x3::Matrix3x3 -- Constructor, optionally initialize to Identitiy matrix * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 06/02/1997 GH : Created. * - *=============================================================================================*/ -WWINLINE Matrix3x3::Matrix3x3(bool identity) -{ - if (identity) { - Row[0].Set(1.0,0.0,0.0); - Row[1].Set(0.0,1.0,0.0); - Row[2].Set(0.0,0.0,1.0); - } -} - -/*********************************************************************************************** - * Matrix3x3::Matrix3x3 -- Copy Constructor * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 06/02/1997 GH : Created. * - *=============================================================================================*/ -WWINLINE Matrix3x3::Matrix3x3(const Matrix3x3 & m) -{ - Row[0] = m.Row[0]; Row[1] = m.Row[1]; Row[2] = m.Row[2]; -} - -/*********************************************************************************************** - * Matrix3x3::Matrix3x3 -- Constructor * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 06/02/1997 GH : Created. * - *=============================================================================================*/ -WWINLINE Matrix3x3::Matrix3x3(const Vector3 & r0, const Vector3 & r1, const Vector3 & r2) -{ - Row[0] = r0; - Row[1] = r1; - Row[2] = r2; -} - -WWINLINE void Matrix3x3::Set(const Vector3 & r0, const Vector3 & r1, const Vector3 & r2) -{ - Row[0] = r0; - Row[1] = r1; - Row[2] = r2; -} - -WWINLINE void Matrix3x3::Make_Identity(void) -{ - Row[0].Set(1.0f,0.0f,0.0f); - Row[1].Set(0.0f,1.0f,0.0f); - Row[2].Set(0.0f,0.0f,1.0f); -} - - -WWINLINE Matrix3x3::Matrix3x3 -( - float m11,float m12,float m13, - float m21,float m22,float m23, - float m31,float m32,float m33 -) -{ - Row[0].Set(m11,m12,m13); - Row[1].Set(m21,m22,m23); - Row[2].Set(m31,m32,m33); -} - -WWINLINE void Matrix3x3::Set -( - float m11,float m12,float m13, - float m21,float m22,float m23, - float m31,float m32,float m33 -) -{ - Row[0].Set(m11,m12,m13); - Row[1].Set(m21,m22,m23); - Row[2].Set(m31,m32,m33); -} - -WWINLINE Matrix3x3::Matrix3x3(const Vector3 & axis,float angle) -{ - Set(axis,angle); -} - -WWINLINE Matrix3x3::Matrix3x3(const Vector3 & axis,float s_angle,float c_angle) -{ - Set(axis,s_angle,c_angle); -} - -WWINLINE void Matrix3x3::Set(const Vector3 & axis,float angle) -{ - Set(axis,sinf(angle),cosf(angle)); -} - -WWINLINE void Matrix3x3::Set(const Vector3 & axis,float s,float c) -{ - WWASSERT(WWMath::Fabs(axis.Length2() - 1.0f) < 0.001f); - - Row[0].Set( - (float)(axis[0]*axis[0] + c*(1.0f - axis[0]*axis[0])), - (float)(axis[0]*axis[1]*(1.0f - c) - axis[2]*s), - (float)(axis[2]*axis[0]*(1.0f - c) + axis[1]*s) - ); - - Row[1].Set( - (float)(axis[0]*axis[1]*(1.0f - c) + axis[2]*s), - (float)(axis[1]*axis[1] + c*(1.0f - axis[1]*axis[1])), - (float)(axis[1]*axis[2]*(1.0f - c) - axis[0]*s) - ); - - Row[2].Set( - (float)(axis[2]*axis[0]*(1.0f - c) - axis[1]*s), - (float)(axis[1]*axis[2]*(1.0f - c) + axis[0]*s), - (float)(axis[2]*axis[2] + c*(1 - axis[2]*axis[2])) - ); -} - -WWINLINE Matrix3x3::Matrix3x3(const Quaternion & q) -{ - this->Set(q); -} - -/*********************************************************************************************** - * Matrix3x3::Transpose -- Returns transpose of the matrix * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 06/02/1997 GH : Created. * - *=============================================================================================*/ -WWINLINE Matrix3x3 Matrix3x3::Transpose() const -{ - return Matrix3x3( - Vector3(Row[0][0], Row[1][0], Row[2][0]), - Vector3(Row[0][1], Row[1][1], Row[2][1]), - Vector3(Row[0][2], Row[1][2], Row[2][2]) - ); -} - -/*********************************************************************************************** - * Matrix3x3::Inverse -- returns the inverse of the matrix * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 06/02/1997 GH : Created. * - *=============================================================================================*/ -WWINLINE Matrix3x3 Matrix3x3::Inverse() const // Gauss-Jordan elimination with partial pivoting -{ - Matrix3x3 a(*this); // As a evolves from original mat into identity - Matrix3x3 b(true); // b evolves from identity into inverse(a) - int i, j, i1; - - // Loop over cols of a from left to right, eliminating above and below diagonal - for (j=0; j<3; j++) { - - // Find largest pivot in column j among rows j..3 - i1 = j; - for (i=j+1; i<3; i++) { - if (WWMath::Fabs(a[i][j]) > WWMath::Fabs(a[i1][j])) { - i1 = i; - } - } - - // Swap rows i1 and j in a and b to put pivot on diagonal - Swap(a.Row[i1], a.Row[j]); - Swap(b.Row[i1], b.Row[j]); - - // Scale row j to have a unit diagonal - if (a[j][j]==0.) { - //Matrix3x3::inverse: singular matrix; can't invert - } - b.Row[j] /= a.Row[j][j]; - a.Row[j] /= a.Row[j][j]; - - // Eliminate off-diagonal elems in col j of a, doing identical ops to b - for (i=0; i<3; i++) { - if (i != j) { - b.Row[i] -= a[i][j] * b.Row[j]; - a.Row[i] -= a[i][j] * a.Row[j]; - } - } - } - return b; -} - - -/*********************************************************************************************** - * Matrix3x3::Determinant -- returns the determinant of the matrix * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 1/7/20 DRM : Created. * - *=============================================================================================*/ -WWINLINE float Matrix3x3::Determinant(void) const -{ - return Row[0][0] * (Row[1][1] * Row[2][2] - Row[1][2] * Row[2][1]) - - Row[0][1] * (Row[1][0] * Row[2][2] - Row[1][2] * Row[2][0]) - - Row[0][2] * (Row[1][0] * Row[2][1] - Row[1][1] * Row[2][0]); -} - -/*********************************************************************************************** - * Matrix3x3::operator = -- assignment operator * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 06/02/1997 GH : Created. * - *=============================================================================================*/ -WWINLINE Matrix3x3 & Matrix3x3::operator = (const Matrix3x3 & m) -{ - Row[0] = m.Row[0]; Row[1] = m.Row[1]; Row[2] = m.Row[2]; - return *this; -} - -/*********************************************************************************************** - * Matrix3x3::operator += -- "plus equals" operator * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 06/02/1997 GH : Created. * - *=============================================================================================*/ -WWINLINE Matrix3x3& Matrix3x3::operator += (const Matrix3x3 & m) -{ - Row[0] += m.Row[0]; Row[1] += m.Row[1]; Row[2] += m.Row[2]; - return *this; -} - -/*********************************************************************************************** - * Matrix3x3::operator-= -- "minus equals" operator * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 06/02/1997 GH : Created. * - *=============================================================================================*/ -WWINLINE Matrix3x3& Matrix3x3::operator -= (const Matrix3x3 & m) -{ - Row[0] -= m.Row[0]; Row[1] -= m.Row[1]; Row[2] -= m.Row[2]; - return *this; -} - -/*********************************************************************************************** - * Matrix3x3::operator *= -- "times equals" operator * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 06/02/1997 GH : Created. * - *=============================================================================================*/ -WWINLINE Matrix3x3& Matrix3x3::operator *= (float d) -{ - Row[0] *= d; Row[1] *= d; Row[2] *= d; - return *this; -} - -/*********************************************************************************************** - * Matrix3x3::operator /= -- "divide equals" operator * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 06/02/1997 GH : Created. * - *=============================================================================================*/ -WWINLINE Matrix3x3& Matrix3x3::operator /= (float d) -{ - Row[0] /= d; Row[1] /= d; Row[2] /= d; - return *this; -} - -/*********************************************************************************************** - * Matrix3x3::Get_X_Rotation -- approximates the rotation about the X axis * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 08/11/1997 GH : Created. * - *=============================================================================================*/ -WWINLINE float Matrix3x3::Get_X_Rotation(void) const -{ - Vector3 v = (*this) * Vector3(0.0,1.0,0.0); - return WWMath::Atan2(v[2], v[1]); -} - -/*********************************************************************************************** - * Matrix3x3::Get_Y_Rotation -- approximates the rotation about the Y axis * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 08/11/1997 GH : Created. * - *=============================================================================================*/ -WWINLINE float Matrix3x3::Get_Y_Rotation(void) const -{ - Vector3 v = (*this) * Vector3(0.0,0.0,1.0); - return WWMath::Atan2(v[0],v[2]); -} - -/*********************************************************************************************** - * Matrix3x3::Get_Z_Rotation -- approximates the rotation about the Z axis * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 08/11/1997 GH : Created. * - *=============================================================================================*/ -WWINLINE float Matrix3x3::Get_Z_Rotation(void) const -{ - Vector3 v = (*this) * Vector3(1.0,0.0,0.0); - return WWMath::Atan2(v[1],v[0]); -} - -WWINLINE Vector3 Matrix3x3::Get_X_Vector(void) const -{ - return Vector3(Row[0][0], Row[1][0], Row[2][0]); -} - -WWINLINE Vector3 Matrix3x3::Get_Y_Vector(void) const -{ - return Vector3(Row[0][1], Row[1][1], Row[2][1]); -} - -WWINLINE Vector3 Matrix3x3::Get_Z_Vector(void) const -{ - return Vector3(Row[0][2], Row[1][2], Row[2][2]); -} - -WWINLINE void Matrix3x3::Get_X_Vector(Vector3 * set) const -{ - set->Set(Row[0][0], Row[1][0], Row[2][0]); -} - -WWINLINE void Matrix3x3::Get_Y_Vector(Vector3 * set) const -{ - set->Set(Row[0][1], Row[1][1], Row[2][1]); -} - -WWINLINE void Matrix3x3::Get_Z_Vector(Vector3 * set) const -{ - set->Set(Row[0][2], Row[1][2], Row[2][2]); -} - -WWINLINE Matrix3x3 operator - (const Matrix3x3 & a) -{ - return Matrix3x3(-a.Row[0], -a.Row[1], -a.Row[2]); -} - -WWINLINE Matrix3x3 operator * (const Matrix3x3 & a, float d) -{ - return Matrix3x3(a.Row[0] * d, a.Row[1] * d, a.Row[2] * d); -} - -WWINLINE Matrix3x3 operator * (float d, const Matrix3x3 & a) -{ - return a*d; -} - -WWINLINE Matrix3x3 operator / (const Matrix3x3 & a, float d) -{ - float ood = 1.0f / d; - return Matrix3x3(a.Row[0] * ood, a.Row[1] * ood, a.Row[2] * ood); -} - -/* -** matrix addition -*/ -WWINLINE Matrix3x3 operator + (const Matrix3x3 & a, const Matrix3x3 & b) -{ - return Matrix3x3( - a.Row[0] + b.Row[0], - a.Row[1] + b.Row[1], - a.Row[2] + b.Row[2] - ); -} - -WWINLINE void Matrix3x3::Add(const Matrix3x3 & a, const Matrix3x3 & b,Matrix3x3 * c) -{ - WWASSERT(c); - Vector3::Add(a.Row[0],b.Row[0],&(c->Row[0])); - Vector3::Add(a.Row[1],b.Row[1],&(c->Row[1])); - Vector3::Add(a.Row[2],b.Row[2],&(c->Row[2])); -} - -/* -** matrix subtraction -*/ -WWINLINE Matrix3x3 operator - (const Matrix3x3 & a, const Matrix3x3 & b) -{ - return Matrix3x3( - a.Row[0] - b.Row[0], - a.Row[1] - b.Row[1], - a.Row[2] - b.Row[2] - ); -} - -WWINLINE void Matrix3x3::Subtract(const Matrix3x3 & a, const Matrix3x3 & b,Matrix3x3 * c) -{ - WWASSERT(c); - Vector3::Subtract(a.Row[0],b.Row[0],&(c->Row[0])); - Vector3::Subtract(a.Row[1],b.Row[1],&(c->Row[1])); - Vector3::Subtract(a.Row[2],b.Row[2],&(c->Row[2])); -} - -/* -** matrix multiplication -*/ -WWINLINE Matrix3x3 operator * (const Matrix3x3 & a, const Matrix3x3 & b) -{ - #define ROWCOL(i,j) a[i][0]*b[0][j] + a[i][1]*b[1][j] + a[i][2]*b[2][j] - - return Matrix3x3( - Vector3(ROWCOL(0,0), ROWCOL(0,1), ROWCOL(0,2) ), - Vector3(ROWCOL(1,0), ROWCOL(1,1), ROWCOL(1,2) ), - Vector3(ROWCOL(2,0), ROWCOL(2,1), ROWCOL(2,2) ) - ); - - #undef ROWCOL -} - - -/* -** Multiply a Matrix3x3 by a Vector3. Yeilds a Vector3 result -*/ -WWINLINE Vector3 operator * (const Matrix3x3 & a, const Vector3 & v) -{ - return Vector3( - a[0][0] * v[0] + a[0][1] * v[1] + a[0][2] * v[2], - a[1][0] * v[0] + a[1][1] * v[1] + a[1][2] * v[2], - a[2][0] * v[0] + a[2][1] * v[1] + a[2][2] * v[2] - ); -} - - -WWINLINE int operator == (const Matrix3x3 & a, const Matrix3x3 & b) -{ - return ((a [0] == b [0]) && (a [1] == b [1]) && (a [2] == b [2])); -} - - -WWINLINE int operator != (const Matrix3x3 & a, const Matrix3x3 & b) -{ - return (!(a == b)); -} - - -/*********************************************************************************************** - * Matrix3x3::Rotate_X -- Post-mutiplies an x rotation onto the current matrix * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 08/26/1997 GH : Created. * - *=============================================================================================*/ -WWINLINE void Matrix3x3::Rotate_X(float theta) -{ - Rotate_X(sinf(theta),cosf(theta)); -} - -WWINLINE void Matrix3x3::Rotate_X(float s,float c) -{ - float tmp1,tmp2; - - tmp1 = Row[0][1]; tmp2 = Row[0][2]; - Row[0][1] = (float)( c*tmp1 + s*tmp2); - Row[0][2] = (float)(-s*tmp1 + c*tmp2); - - tmp1 = Row[1][1]; tmp2 = Row[1][2]; - Row[1][1] = (float)( c*tmp1 + s*tmp2); - Row[1][2] = (float)(-s*tmp1 + c*tmp2); - - tmp1 = Row[2][1]; tmp2 = Row[2][2]; - Row[2][1] = (float)( c*tmp1 + s*tmp2); - Row[2][2] = (float)(-s*tmp1 + c*tmp2); -} - -/*********************************************************************************************** - * Matrix3x3::Rotate_Y -- Post-multiplies the matrix with a rotation about Y * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 08/26/1997 GH : Created. * - *=============================================================================================*/ -WWINLINE void Matrix3x3::Rotate_Y(float theta) -{ - Rotate_Y(sinf(theta),cosf(theta)); -} - -WWINLINE void Matrix3x3::Rotate_Y(float s,float c) -{ - float tmp1,tmp2; - - tmp1 = Row[0][0]; tmp2 = Row[0][2]; - Row[0][0] = (float)(c*tmp1 - s*tmp2); - Row[0][2] = (float)(s*tmp1 + c*tmp2); - - tmp1 = Row[1][0]; tmp2 = Row[1][2]; - Row[1][0] = (float)(c*tmp1 - s*tmp2); - Row[1][2] = (float)(s*tmp1 + c*tmp2); - - tmp1 = Row[2][0]; tmp2 = Row[2][2]; - Row[2][0] = (float)(c*tmp1 - s*tmp2); - Row[2][2] = (float)(s*tmp1 + c*tmp2); -} - - -/*********************************************************************************************** - * Matrix3x3::Rotate_Z -- Post-multiplies the matrix with a rotation about Z * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 08/26/1997 GH : Created. * - *=============================================================================================*/ -WWINLINE void Matrix3x3::Rotate_Z(float theta) -{ - Rotate_Z(sinf(theta),cosf(theta)); -} - -WWINLINE void Matrix3x3::Rotate_Z(float s,float c) -{ - float tmp1,tmp2; - - tmp1 = Row[0][0]; tmp2 = Row[0][1]; - Row[0][0] = (float)( c*tmp1 + s*tmp2); - Row[0][1] = (float)(-s*tmp1 + c*tmp2); - - tmp1 = Row[1][0]; tmp2 = Row[1][1]; - Row[1][0] = (float)( c*tmp1 + s*tmp2); - Row[1][1] = (float)(-s*tmp1 + c*tmp2); - - tmp1 = Row[2][0]; tmp2 = Row[2][1]; - Row[2][0] = (float)( c*tmp1 + s*tmp2); - Row[2][1] = (float)(-s*tmp1 + c*tmp2); -} - - -/*********************************************************************************************** - * Create_X_Rotation_Matrix3 -- creates a matrix3 which is a rotation about X * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 08/26/1997 GH : Created. * - *=============================================================================================*/ -WWINLINE Matrix3x3 Create_X_Rotation_Matrix3(float s,float c) -{ - Matrix3x3 mat; - - mat[0][0] = 1.0f; - mat[0][1] = 0.0f; - mat[0][2] = 0.0f; - - mat[1][0] = 0.0f; - mat[1][1] = c; - mat[1][2] = -s; - - mat[2][0] = 0.0f; - mat[2][1] = s; - mat[2][2] = c; - - return mat; -} - -WWINLINE Matrix3x3 Create_X_Rotation_Matrix3(float rad) -{ - return Create_X_Rotation_Matrix3(sinf(rad),cosf(rad)); -} - -/*********************************************************************************************** - * Create_Y_Rotation_Matrix3 -- Creates a Matrix3x3 which is a rotation about Y * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 08/26/1997 GH : Created. * - *=============================================================================================*/ -WWINLINE Matrix3x3 Create_Y_Rotation_Matrix3(float s,float c) -{ - Matrix3x3 mat; - - mat[0][0] = c; - mat[0][1] = 0.0f; - mat[0][2] = s; - - mat[1][0] = 0.0f; - mat[1][1] = 1.0f; - mat[1][2] = 0.0f; - - mat[2][0] = -s; - mat[2][1] = 0.0f; - mat[2][2] = c; - - return mat; -} - -WWINLINE Matrix3x3 Create_Y_Rotation_Matrix3(float rad) -{ - return Create_Y_Rotation_Matrix3(sinf(rad),cosf(rad)); -} - -/*********************************************************************************************** - * Create_Z_Rotation_Matrix3 -- Creates a matrix3 which is a rotation about Z * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 08/26/1997 GH : Created. * - *=============================================================================================*/ -WWINLINE Matrix3x3 Create_Z_Rotation_Matrix3(float s,float c) -{ - Matrix3x3 mat; - - mat[0][0] = c; - mat[0][1] = -s; - mat[0][2] = 0.0f; - - mat[1][0] = s; - mat[1][1] = c; - mat[1][2] = 0.0f; - - mat[2][0] = 0.0f; - mat[2][1] = 0.0f; - mat[2][2] = 1.0f; - - return mat; -} - -WWINLINE Matrix3x3 Create_Z_Rotation_Matrix3(float rad) -{ - return Create_Z_Rotation_Matrix3(sinf(rad),cosf(rad)); -} - -WWINLINE void Matrix3x3::Rotate_Vector(const Matrix3x3 & A,const Vector3 & in,Vector3 * out) -{ - Vector3 tmp; - Vector3 * v; - - // check for aliased parameters - if (out == &in) { - tmp = in; - v = &tmp; - } else { - v = (Vector3 *)∈ // whats the right way to do this... - } - - out->X = (A[0][0] * v->X + A[0][1] * v->Y + A[0][2] * v->Z); - out->Y = (A[1][0] * v->X + A[1][1] * v->Y + A[1][2] * v->Z); - out->Z = (A[2][0] * v->X + A[2][1] * v->Y + A[2][2] * v->Z); -} - -WWINLINE void Matrix3x3::Transpose_Rotate_Vector(const Matrix3x3 & A,const Vector3 & in,Vector3 * out) -{ - Vector3 tmp; - Vector3 * v; - - // check for aliased parameters - if (out == &in) { - tmp = in; - v = &tmp; - } else { - v = (Vector3 *)∈ - } - out->X = (A[0][0] * v->X + A[1][0] * v->Y + A[2][0] * v->Z); - out->Y = (A[0][1] * v->X + A[1][1] * v->Y + A[2][1] * v->Z); - out->Z = (A[0][2] * v->X + A[1][2] * v->Y + A[2][2] * v->Z); -} - -WWINLINE void Matrix3x3::Rotate_AABox_Extent(const Vector3 & extent,Vector3 * set_extent) -{ - // push each extent out to the projections of the original extents - for (int i=0; i<3; i++) { - - // start the center out at the translation portion of the matrix - // and the extent at zero - (*set_extent)[i] = 0.0f; - - for (int j=0; j<3; j++) { - (*set_extent)[i] += WWMath::Fabs(Row[i][j] * extent[j]); - } - } -} - -#endif /*Matrix3_H*/ diff --git a/Generals/Code/Libraries/Source/WWVegas/WWMath/matrix3d.cpp b/Generals/Code/Libraries/Source/WWVegas/WWMath/matrix3d.cpp deleted file mode 100644 index ec9b42c8dad..00000000000 --- a/Generals/Code/Libraries/Source/WWVegas/WWMath/matrix3d.cpp +++ /dev/null @@ -1,1242 +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 . -*/ - -/* $Header: /Commando/Code/wwmath/matrix3d.cpp 41 5/09/01 2:38p Greg_h $ */ -/*********************************************************************************************** - *** Confidential - Westwood Studios *** - *********************************************************************************************** - * * - * Project Name : Voxel Technology * - * * - * File Name : MATRIX3D.CPP * - * * - * Org Programmer : Greg Hjelstrom * - * * - * Programmer : Kenny Mitchell * - * * - * Start Date : 02/24/97 * - * * - * Last Update : June 6, 2002 [KM] * - * * - * 06/26/02 KM Matrix name change to avoid MAX conflicts * - *---------------------------------------------------------------------------------------------* - * Functions: * - * Matrix3D::Set_Rotation -- Sets the rotation part of the matrix * - * Matrix3D::Set_Rotation -- Sets the rotation part of the matrix * - * Matrix3D::Set -- Init a matrix3D from a matrix3 and a position * - * Matrix3D::Set -- Init a matrix3D from a quaternion and a position * - * Matrix3D::Get_X_Rotation -- approximates the rotation about the X axis * - * Matrix3D::Get_Y_Rotation -- approximates the rotation about the Y axis * - * Matrix3D::Get_Z_Rotation -- approximates the rotation about the Z axis * - * Matrix3D::Multiply -- matrix multiplication without temporaries. * - * Matrix3D::Inverse_Rotate_Vector -- rotates a vector by the inverse of the 3x3 sub-matrix * - * Matrix3D::Transform_Min_Max_AABox -- compute transformed axis-aligned box * - * Matrix3D::Transform_Center_Extent_AABox -- compute transformed axis-aligned box * - * Matrix3D::Get_Inverse -- calculate the inverse of this matrix * - * Matrix3D::Get_Orthogonal_Inverse -- Returns the inverse of the matrix * - * Matrix3D::Re_Orthogonalize -- makes this matrix orthogonal. * - * Matrix3D::Is_Orthogonal -- checks whether this matrix is orthogonal * - * Lerp - linearly interpolate matrices (orientation is slerped) * - * Matrix3D::Solve_Linear_System -- 3x3 Gauss-Jordan elimination * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - -#include "matrix3d.h" - -#include -#include -#include -//#include -#include "vector3.h" -#include "matrix3.h" -#include "matrix4.h" -#include "quat.h" -#include "d3dx8math.h" - -// some static matrices which are sometimes useful -const Matrix3D Matrix3D::Identity -( - 1.0, 0.0, 0.0, 0.0, - 0.0, 1.0, 0.0, 0.0, - 0.0, 0.0, 1.0, 0.0 -); - -const Matrix3D Matrix3D::RotateX90 -( - 1.0, 0.0, 0.0, 0.0, - 0.0, 0.0, -1.0, 0.0, - 0.0, 1.0, 0.0, 0.0 -); - -const Matrix3D Matrix3D::RotateX180 -( - 1.0, 0.0, 0.0, 0.0, - 0.0, -1.0, 0.0, 0.0, - 0.0, 0.0, -1.0, 0.0 -); - -const Matrix3D Matrix3D::RotateX270 -( - 1.0, 0.0, 0.0, 0.0, - 0.0, 0.0, 1.0, 0.0, - 0.0, -1.0, 0.0, 0.0 -); - -const Matrix3D Matrix3D::RotateY90 -( - 0.0, 0.0, 1.0, 0.0, - 0.0, 1.0, 0.0, 0.0, - -1.0, 0.0, 0.0, 0.0 -); - -const Matrix3D Matrix3D::RotateY180 -( - -1.0, 0.0, 0.0, 0.0, - 0.0, 1.0, 0.0, 0.0, - 0.0, 0.0, -1.0, 0.0 -); - -const Matrix3D Matrix3D::RotateY270 -( - 0.0, 0.0, -1.0, 0.0, - 0.0, 1.0, 0.0, 0.0, - 1.0, 0.0, 0.0, 0.0 -); - -const Matrix3D Matrix3D::RotateZ90 -( - 0.0, -1.0, 0.0, 0.0, - 1.0, 0.0, 0.0, 0.0, - 0.0, 0.0, 1.0, 0.0 -); - -const Matrix3D Matrix3D::RotateZ180 -( - -1.0, 0.0, 0.0, 0.0, - 0.0, -1.0, 0.0, 0.0, - 0.0, 0.0, 1.0, 0.0 -); - -const Matrix3D Matrix3D::RotateZ270 -( - 0.0, 1.0, 0.0, 0.0, - -1.0, 0.0, 0.0, 0.0, - 0.0, 0.0, 1.0, 0.0 -); - - -/*********************************************************************************************** - * Matrix3D::Set -- Init a matrix3D from a matrix3 and a position * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - *=============================================================================================*/ -void Matrix3D::Set(const Matrix3x3 & rot,const Vector3 & pos) -{ - Row[0].Set( rot[0][0], rot[0][1], rot[0][2], pos[0]); - Row[1].Set( rot[1][0], rot[1][1], rot[1][2], pos[1]); - Row[2].Set( rot[2][0], rot[2][1], rot[2][2], pos[2]); -} - - -/*********************************************************************************************** - * Matrix3D::Set -- Init a matrix3D from a quaternion and a position * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - *=============================================================================================*/ -void Matrix3D::Set(const Quaternion & rot,const Vector3 & pos) -{ - Set_Rotation(rot); - Set_Translation(pos); -} - - -/*********************************************************************************************** - * Matrix3D::Set_Rotation -- Sets the rotation part of the matrix * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 5/11/98 GTH : Created. * - *=============================================================================================*/ -void Matrix3D::Set_Rotation(const Matrix3x3 & m) -{ - Row[0][0] = m[0][0]; - Row[0][1] = m[0][1]; - Row[0][2] = m[0][2]; - - Row[1][0] = m[1][0]; - Row[1][1] = m[1][1]; - Row[1][2] = m[1][2]; - - Row[2][0] = m[2][0]; - Row[2][1] = m[2][1]; - Row[2][2] = m[2][2]; -} - - -/*********************************************************************************************** - * Matrix3D::Set_Rotation -- Sets the rotation part of the matrix * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 5/11/98 GTH : Created. * - *=============================================================================================*/ -void Matrix3D::Set_Rotation(const Quaternion & q) -{ - Row[0][0] = (float)(1.0 - 2.0 * (q[1] * q[1] + q[2] * q[2])); - Row[0][1] = (float)(2.0 * (q[0] * q[1] - q[2] * q[3])); - Row[0][2] = (float)(2.0 * (q[2] * q[0] + q[1] * q[3])); - - Row[1][0] = (float)(2.0 * (q[0] * q[1] + q[2] * q[3])); - Row[1][1] = (float)(1.0 - 2.0f * (q[2] * q[2] + q[0] * q[0])); - Row[1][2] = (float)(2.0 * (q[1] * q[2] - q[0] * q[3])); - - Row[2][0] = (float)(2.0 * (q[2] * q[0] - q[1] * q[3])); - Row[2][1] = (float)(2.0 * (q[1] * q[2] + q[0] * q[3])); - Row[2][2] =(float)(1.0 - 2.0 * (q[1] * q[1] + q[0] * q[0])); -} - - -/*********************************************************************************************** - * Matrix3D::Get_X_Rotation -- approximates the rotation about the X axis * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 08/11/1997 GH : Created. * - *=============================================================================================*/ -float Matrix3D::Get_X_Rotation(void) const -{ - return WWMath::Atan2(Row[2][1], Row[1][1]); -} - - -/*********************************************************************************************** - * Matrix3D::Get_Y_Rotation -- approximates the rotation about the Y axis * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 08/11/1997 GH : Created. * - *=============================================================================================*/ -float Matrix3D::Get_Y_Rotation(void) const -{ - return WWMath::Atan2(Row[0][2], Row[2][2]); -} - - -/*********************************************************************************************** - * Matrix3D::Get_Z_Rotation -- approximates the rotation about the Z axis * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 08/11/1997 GH : Created. * - *=============================================================================================*/ -float Matrix3D::Get_Z_Rotation(void) const -{ - return WWMath::Atan2(Row[1][0], Row[0][0]); -} - - -/*********************************************************************************************** - * M3DC::Rotate_Vector -- Uses the 3x3 sub-matrix to rotate a vector * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - *=============================================================================================*/ -Vector3 Matrix3D::Rotate_Vector(const Vector3 &vect) const -{ - return Vector3( - (Row[0][0]*vect[0] + Row[0][1]*vect[1] + Row[0][2]*vect[2]), - (Row[1][0]*vect[0] + Row[1][1]*vect[1] + Row[1][2]*vect[2]), - (Row[2][0]*vect[0] + Row[2][1]*vect[1] + Row[2][2]*vect[2]) - ); -} - - -/*********************************************************************************************** - * Matrix3D::Inverse_Rotate_Vector -- rotates a vector by the inverse of the 3x3 sub-matrix * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 4/27/98 GTH : Created. * - *=============================================================================================*/ -Vector3 Matrix3D::Inverse_Rotate_Vector(const Vector3 &vect) const -{ - return Vector3( - (Row[0][0]*vect[0] + Row[1][0]*vect[1] + Row[2][0]*vect[2]), - (Row[0][1]*vect[0] + Row[1][1]*vect[1] + Row[2][1]*vect[2]), - (Row[0][2]*vect[0] + Row[1][2]*vect[1] + Row[2][2]*vect[2]) - ); -} - -/*********************************************************************************************** - * M3DC::Look_At -- Creates a "look at" transformation. * - * * - * Builds a transformation matrix which positions the origin at p, * - * points the negative z-axis towards a target t, and rolls about the z-axis * - * by the angle specified by roll. * - * * - * This can be useful for creating a camera matrix, just invert * - * the matrix after initializing it with this function... * - * * - * INPUT: * - * p - position of the coordinate system * - * t - target of the coordinate system * - * roll - roll angle (in radians) * - * * - * OUTPUT: * - * * - * WARNINGS: * - * This function is written assuming the convention that the "ground" is the X-Y plane and * - * Z is altitude. * - * * - * HISTORY: * - *=============================================================================================*/ -void Matrix3D::Look_At(const Vector3 &p,const Vector3 &t,float roll) -{ - float dx,dy,dz; //vector from p to t - float len1,len2; - float sinp,cosp; //sine and cosine of the pitch ("up-down" tilt about x) - float siny,cosy; //sine and cosine of the yaw ("left-right"tilt about z) - - dx = (t[0] - p[0]); - dy = (t[1] - p[1]); - dz = (t[2] - p[2]); - - len1 = (float)WWMath::Sqrt(dx*dx + dy*dy + dz*dz); - len2 = (float)WWMath::Sqrt(dx*dx + dy*dy); - - if (len1 != 0.0f) { - sinp = dz/len1; - cosp = len2/len1; - } else { - sinp = 0.0f; - cosp = 1.0f; - } - - if (len2 != 0.0f) { - siny = dy/len2; - cosy = dx/len2; - } else { - siny = 0.0f; - cosy = 1.0f; - } - - // init the matrix with position p and -z pointing down +x and +y up - Row[0].X = 0.0f; Row[0].Y = 0.0f; Row[0].Z = -1.0f; - Row[1].X = -1.0f; Row[1].Y = 0.0f; Row[1].Z = 0.0f; - Row[2].X = 0.0f; Row[2].Y = 1.0f; Row[2].Z = 0.0f; - - Row[0].W = p.X; - Row[1].W = p.Y; - Row[2].W = p.Z; - - // Yaw rotation to make the matrix look at the projection of the target - // into the x-y plane - Rotate_Y(siny,cosy); - - // rotate about local x axis to pitch up to the targets position - Rotate_X(sinp,cosp); - - // roll about the local z axis (negate since we look down -z) - Rotate_Z(-roll); -} - -// Create a matrix given a position and a direction (x axis will point in direction) -// Make sure you pass in UNITIZED direction!!! -void Matrix3D::buildTransformMatrix( const Vector3 &pos, const Vector3 &dir ) -{ - float sinp, cosp; // sine and cosine of the pitch ("up-down" tilt about y) - float siny, cosy; // sine and cosine of the yaw ("left-right"tilt about z) - - float len2 = (float)sqrt( (dir.X * dir.X) + (dir.Y * dir.Y) ); - - sinp = dir.Z; - cosp = len2; - - if( len2 != 0.0f ) - { - siny = dir.Y / len2; - cosy = dir.X / len2; - } - else - { - siny = 0.0f; - cosy = 1.0f; - } - - Make_Identity(); - Translate( pos ); - - // Yaw rotation to projection of target in x-y plane - Rotate_Z( siny, cosy ); - - // Pitch rotation - Rotate_Y( -sinp, cosp ); -} - -/*********************************************************************************************** - * M3DC::Obj_Look_At -- Commando Object "look at" transformation. * - * * - * Builds a transformation matrix which positions the origin at p, * - * points the positive X axis towards a target t, and rolls about the X axis * - * by the angle specified by roll. * - * * - * The object convention used by Commando and G is Forward = +X, Left = +Y, Up = +Z. The * - * world is basically the x-y plane with z as altitude and +x is the default "forward". * - * * - * INPUT: * - * p - position of the coordinate system * - * t - target of the coordinate system * - * roll - roll angle (in radians) * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - *=============================================================================================*/ -void Matrix3D::Obj_Look_At(const Vector3 &p,const Vector3 &t,float roll) -{ - float dx,dy,dz; //vector from p to t - float len1,len2; - float sinp,cosp; //sine and cosine of the pitch ("up-down" tilt about y) - float siny,cosy; //sine and cosine of the yaw ("left-right"tilt about z) - - dx = (t[0] - p[0]); - dy = (t[1] - p[1]); - dz = (t[2] - p[2]); - - len1 = (float)sqrt(dx*dx + dy*dy + dz*dz); - len2 = (float)sqrt(dx*dx + dy*dy); - - if (len1 != 0.0f) { - sinp = dz/len1; - cosp = len2/len1; - } else { - sinp = 0.0f; - cosp = 1.0f; - } - - if (len2 != 0.0f) { - siny = dy/len2; - cosy = dx/len2; - } else { - siny = 0.0f; - cosy = 1.0f; - } - - Make_Identity(); - Translate(p); - - // Yaw rotation to projection of target in x-y plane - Rotate_Z(siny,cosy); - - // Pitch rotation - Rotate_Y(-sinp,cosp); - - // Roll rotation - Rotate_X(roll); -} - - -/*********************************************************************************************** - * Matrix3D::Get_Inverse -- calculate the inverse of this matrix * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 8/7/98 GTH : Created. * - *=============================================================================================*/ -void Matrix3D::Get_Inverse(Matrix3D & inv) const -{ - // TODO: Implement the general purpose inverse function here (once we need it :-) - //Get_Orthogonal_Inverse(inv); - - Matrix4x4 mat4(*this); - Matrix4x4 mat4Inv; - - float det; - D3DXMatrixInverse((D3DXMATRIX *)&mat4Inv, &det, (D3DXMATRIX*)&mat4); - - inv.Row[0][0]=mat4Inv[0][0]; - inv.Row[0][1]=mat4Inv[0][1]; - inv.Row[0][2]=mat4Inv[0][2]; - inv.Row[0][3]=mat4Inv[0][3]; - - inv.Row[1][0]=mat4Inv[1][0]; - inv.Row[1][1]=mat4Inv[1][1]; - inv.Row[1][2]=mat4Inv[1][2]; - inv.Row[1][3]=mat4Inv[1][3]; - - inv.Row[2][0]=mat4Inv[2][0]; - inv.Row[2][1]=mat4Inv[2][1]; - inv.Row[2][2]=mat4Inv[2][2]; - inv.Row[2][3]=mat4Inv[2][3]; -} - -/*********************************************************************************************** - * Matrix3D::Get_Orthogonal_Inverse -- Returns the inverse of the matrix * - * * - * NOTE!!! This only works if the matrix is really ORTHOGONAL!!! * - * * - *********************************************************************************************** - * Inverting an orthogonal Matrix3D * - * * - * M is the original transform, * - * R is rotation submatrix, * - * T is translation vector in M. * - * * - * To build MINV * - * * - * R' = transpose of R (inverse of orthogonal 3x3 matrix is transpose) * - * T' = -R'T * - * * - * Build MINV with R'and T' * - * MINV is the inverse of M * - * * - *********************************************************************************************** - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - *=============================================================================================*/ -void Matrix3D::Get_Orthogonal_Inverse(Matrix3D & inv) const -{ - // Transposing the rotation submatrix - inv.Row[0][0] = Row[0][0]; - inv.Row[0][1] = Row[1][0]; - inv.Row[0][2] = Row[2][0]; - - inv.Row[1][0] = Row[0][1]; - inv.Row[1][1] = Row[1][1]; - inv.Row[1][2] = Row[2][1]; - - inv.Row[2][0] = Row[0][2]; - inv.Row[2][1] = Row[1][2]; - inv.Row[2][2] = Row[2][2]; - - // Now, calculate translation portion of matrix: - // T' = -R'T - Vector3 trans = Get_Translation(); - trans = inv.Rotate_Vector(trans); - trans = -trans; - - inv.Row[0][3] = trans[0]; - inv.Row[1][3] = trans[1]; - inv.Row[2][3] = trans[2]; -} - -/*********************************************************************************************** - * Copy_3x3_Matrix(float *matrix) -- Copies a 3x3 (float[9]) matrix into this matrix * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 1/16/98 EHC : Created. * - *=============================================================================================*/ -void Matrix3D::Copy_3x3_Matrix(float matrix[3][3]) -{ - Row[0][0] = matrix[0][0]; - Row[0][1] = matrix[0][1]; - Row[0][2] = matrix[0][2]; - Row[0][3] = 0; - Row[1][0] = matrix[1][0]; - Row[1][1] = matrix[1][1]; - Row[1][2] = matrix[1][2]; - Row[1][3] = 0; - Row[2][0] = matrix[2][0]; - Row[2][1] = matrix[2][1]; - Row[2][2] = matrix[2][2]; - Row[2][3] = 0; -} - - - -/*********************************************************************************************** - * Matrix3D::Multiply -- matrix multiplication without temporaries. * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 4/22/98 GTH : Created. * - *=============================================================================================*/ -//void print_matrix(const Matrix3D & m); - -void Matrix3D::Multiply(const Matrix3D & A,const Matrix3D & B,Matrix3D * set_res) -{ - assert(set_res != NULL); - - Matrix3D tmp; - Matrix3D * Aptr; - - // Check for aliased parameters, copy the 'A' matrix into a temporary if the - // result is going into 'A'. (in this case, this function is no better than - // the overloaded C++ operator...) - if (set_res == &A) { - tmp = A; - Aptr = &tmp; - } else { - Aptr = (Matrix3D *)&A; - } - -#ifdef ALLOW_TEMPORARIES - float tmp1,tmp2,tmp3; - - tmp1 = B[0][0]; - tmp2 = B[1][0]; - tmp3 = B[2][0]; - - (*set_res)[0][0] = (*Aptr)[0][0]*tmp1 + (*Aptr)[0][1]*tmp2 + (*Aptr)[0][2]*tmp3; - (*set_res)[1][0] = (*Aptr)[1][0]*tmp1 + (*Aptr)[1][1]*tmp2 + (*Aptr)[1][2]*tmp3; - (*set_res)[2][0] = (*Aptr)[2][0]*tmp1 + (*Aptr)[2][1]*tmp2 + (*Aptr)[2][2]*tmp3; - - tmp1 = B[0][1]; - tmp2 = B[1][1]; - tmp3 = B[2][1]; - - (*set_res)[0][1] = (*Aptr)[0][0]*tmp1 + (*Aptr)[0][1]*tmp2 + (*Aptr)[0][2]*tmp3; - (*set_res)[1][1] = (*Aptr)[1][0]*tmp1 + (*Aptr)[1][1]*tmp2 + (*Aptr)[1][2]*tmp3; - (*set_res)[2][1] = (*Aptr)[2][0]*tmp1 + (*Aptr)[2][1]*tmp2 + (*Aptr)[2][2]*tmp3; - - tmp1 = B[0][2]; - tmp2 = B[1][2]; - tmp3 = B[2][2]; - - (*set_res)[0][2] = (*Aptr)[0][0]*tmp1 + (*Aptr)[0][1]*tmp2 + (*Aptr)[0][2]*tmp3; - (*set_res)[1][2] = (*Aptr)[1][0]*tmp1 + (*Aptr)[1][1]*tmp2 + (*Aptr)[1][2]*tmp3; - (*set_res)[2][2] = (*Aptr)[2][0]*tmp1 + (*Aptr)[2][1]*tmp2 + (*Aptr)[2][2]*tmp3; - - tmp1 = B[0][3]; - tmp2 = B[1][3]; - tmp3 = B[2][3]; - - (*set_res)[0][3] = (*Aptr)[0][0]*tmp1 + (*Aptr)[0][1]*tmp2 + (*Aptr)[0][2]*tmp3 + (*Aptr)[0][3]; - (*set_res)[1][3] = (*Aptr)[1][0]*tmp1 + (*Aptr)[1][1]*tmp2 + (*Aptr)[1][2]*tmp3 + (*Aptr)[1][3]; - (*set_res)[2][3] = (*Aptr)[2][0]*tmp1 + (*Aptr)[2][1]*tmp2 + (*Aptr)[2][2]*tmp3 + (*Aptr)[2][3]; -#else - set_res->mul(*Aptr, B); -#endif -} - -#if 0 -void Matrix3D::Multiply(const Matrix3D & A,const Matrix3D & B,Matrix3D * set_res) -{ - assert(set_res != NULL); - - float tmp[12]; -// Check for aliased parameters, copy the 'A' matrix into a temporary if the -// result is going into 'A'. (in this case, this function is no better than -// the overloaded C++ operator...) - -/* if (set_res == &A) - { - Matrix3D tmp; - Matrix3D * Aptr; - float tmp1,tmp2,tmp3; - tmp = A; - Aptr = &tmp; - - tmp1 = B[0][0]; - tmp2 = B[1][0]; - tmp3 = B[2][0]; - - (*set_res)[0][0] = (*Aptr)[0][0]*tmp1 + (*Aptr)[0][1]*tmp2 + (*Aptr)[0][2]*tmp3; - (*set_res)[1][0] = (*Aptr)[1][0]*tmp1 + (*Aptr)[1][1]*tmp2 + (*Aptr)[1][2]*tmp3; - (*set_res)[2][0] = (*Aptr)[2][0]*tmp1 + (*Aptr)[2][1]*tmp2 + (*Aptr)[2][2]*tmp3; - - tmp1 = B[0][1]; - tmp2 = B[1][1]; - tmp3 = B[2][1]; - - (*set_res)[0][1] = (*Aptr)[0][0]*tmp1 + (*Aptr)[0][1]*tmp2 + (*Aptr)[0][2]*tmp3; - (*set_res)[1][1] = (*Aptr)[1][0]*tmp1 + (*Aptr)[1][1]*tmp2 + (*Aptr)[1][2]*tmp3; - (*set_res)[2][1] = (*Aptr)[2][0]*tmp1 + (*Aptr)[2][1]*tmp2 + (*Aptr)[2][2]*tmp3; - - tmp1 = B[0][2]; - tmp2 = B[1][2]; - tmp3 = B[2][2]; - - (*set_res)[0][2] = (*Aptr)[0][0]*tmp1 + (*Aptr)[0][1]*tmp2 + (*Aptr)[0][2]*tmp3; - (*set_res)[1][2] = (*Aptr)[1][0]*tmp1 + (*Aptr)[1][1]*tmp2 + (*Aptr)[1][2]*tmp3; - (*set_res)[2][2] = (*Aptr)[2][0]*tmp1 + (*Aptr)[2][1]*tmp2 + (*Aptr)[2][2]*tmp3; - - tmp1 = B[0][3]; - tmp2 = B[1][3]; - tmp3 = B[2][3]; - - (*set_res)[0][3] = (*Aptr)[0][0]*tmp1 + (*Aptr)[0][1]*tmp2 + (*Aptr)[0][2]*tmp3 + (*Aptr)[0][3]; - (*set_res)[1][3] = (*Aptr)[1][0]*tmp1 + (*Aptr)[1][1]*tmp2 + (*Aptr)[1][2]*tmp3 + (*Aptr)[1][3]; - (*set_res)[2][3] = (*Aptr)[2][0]*tmp1 + (*Aptr)[2][1]*tmp2 + (*Aptr)[2][2]*tmp3 + (*Aptr)[2][3]; - - return; - } -*/ - - __asm { - mov ecx,B - fld dword ptr [ecx+32] // B[2][0] - mov edx,A - lea ebx,tmp - mov eax,set_res - cmp eax,edx - jne not_equal - mov eax,ebx -not_equal: - fld dword ptr [ecx+16] // B[1][0] - fld dword ptr [ecx] // B[0][0] - -// tmp1 = B[0][0]; -// tmp2 = B[1][0]; -// tmp3 = B[2][0]; - -// (*set_res)[0][0] = (*Aptr)[0][0]*tmp1 + (*Aptr)[0][1]*tmp2 + (*Aptr)[0][2]*tmp3; - fld dword ptr [edx+8] // A[0][2] - fmul st(0),st(3) // A[0][2] * B[2][0] - fld dword ptr [edx+4] // A[0][1] - fmul st(0),st(3) // A[0][1] * B[1][0] - fld dword ptr [edx] // A[0][0] - fmul st(0),st(3) // A[0][2] * B[0][0] - faddp st(1),st(0) - faddp st(1),st(0) - fstp dword ptr [eax] // res[0][0] - -// (*set_res)[1][0] = A[1][0]*tmp1 + A[1][1]*tmp2 + A[1][2]*tmp3; - fld dword ptr [edx+24] // A[1][2] - fmul st(0),st(3) // A[1][2] * B[2][0] - fld dword ptr [edx+20] // A[1][1] - fmul st(0),st(3) // A[1][1] * B[1][0] - fld dword ptr [edx+16] // A[1][0] - fmul st(0),st(3) // A[1][0] * B[0][0] - faddp st(1),st(0) - faddp st(1),st(0) - fstp dword ptr [eax+16] // res[1][0] - -// (*set_res)[2][0] = A[2][0]*tmp1 + A[2][1]*tmp2 + A[2][2]*tmp3; - - fld dword ptr [edx+40] // A[2][2] - fmul st(0),st(3) // A[2][2] * B[2][0] - fld dword ptr [edx+36] // A[2][1] - fmul st(0),st(3) // A[2][1] * B[1][0] - fld dword ptr [edx+32] // A[2][0] - fmul st(0),st(3) // A[2][0] * B[0][0] - faddp st(1),st(0) - faddp st(1),st(0) - fstp dword ptr [eax+32] // res[2][0] - -// tmp1 = B[0][1]; -// tmp2 = B[1][1]; -// tmp3 = B[2][1]; - fstp st(0) - fstp st(0) - fstp st(0) - fld dword ptr [ecx+36] // B[2][1] - fld dword ptr [ecx+20] // B[1][1] - fld dword ptr [ecx+4] // B[0][1] - -// (*set_res)[0][1] = (*Aptr)[0][0]*tmp1 + (*Aptr)[0][1]*tmp2 + (*Aptr)[0][2]*tmp3; - fld dword ptr [edx+8] // A[0][2] - fmul st(0),st(3) // A[0][2] * B[2][1] - fld dword ptr [edx+4] // A[0][1] - fmul st(0),st(3) // A[0][1] * B[1][1] - fld dword ptr [edx] // A[0][0] - fmul st(0),st(3) // A[0][2] * B[0][1] - faddp st(1),st(0) - faddp st(1),st(0) - fstp dword ptr [eax+4] // res[0][1] - -// (*set_res)[1][1] = A[1][0]*tmp1 + A[1][1]*tmp2 + A[1][2]*tmp3; - fld dword ptr [edx+24] // A[1][2] - fmul st(0),st(3) // A[1][2] * B[2][1] - fld dword ptr [edx+20] // A[1][1] - fmul st(0),st(3) // A[1][1] * B[1][1] - fld dword ptr [edx+16] // A[1][0] - fmul st(0),st(3) // A[1][0] * B[0][1] - faddp st(1),st(0) - faddp st(1),st(0) - fstp dword ptr [eax+20] // res[1][1] - -// (*set_res)[2][1] = A[2][0]*tmp1 + A[2][1]*tmp2 + A[2][2]*tmp3; - - fld dword ptr [edx+40] // A[2][2] - fmul st(0),st(3) // A[2][2] * B[2][1] - fld dword ptr [edx+36] // A[2][1] - fmul st(0),st(3) // A[2][1] * B[1][1] - fld dword ptr [edx+32] // A[2][0] - fmul st(0),st(3) // A[2][0] * B[0][1] - faddp st(1),st(0) - faddp st(1),st(0) - fstp dword ptr [eax+36] // res[2][1] - -// tmp1 = B[0][2]; -// tmp2 = B[1][2]; -// tmp3 = B[2][2]; - fstp st(0) - fstp st(0) - fstp st(0) - fld dword ptr [ecx+40] // B[2][2] - fld dword ptr [ecx+24] // B[1][2] - fld dword ptr [ecx+8] // B[0][2] - -// (*set_res)[0][2] = (*Aptr)[0][0]*tmp1 + (*Aptr)[0][1]*tmp2 + (*Aptr)[0][2]*tmp3; - fld dword ptr [edx+8] // A[0][2] - fmul st(0),st(3) // A[0][2] * B[2][2] - fld dword ptr [edx+4] // A[0][1] - fmul st(0),st(3) // A[0][1] * B[1][2] - fld dword ptr [edx] // A[0][0] - fmul st(0),st(3) // A[0][2] * B[0][2] - faddp st(1),st(0) - faddp st(1),st(0) - fstp dword ptr [eax+8] // res[0][2] - -// (*set_res)[1][2] = A[1][0]*tmp1 + A[1][1]*tmp2 + A[1][2]*tmp3; - fld dword ptr [edx+24] // A[1][2] - fmul st(0),st(3) // A[1][2] * B[2][2] - fld dword ptr [edx+20] // A[1][1] - fmul st(0),st(3) // A[1][1] * B[1][2] - fld dword ptr [edx+16] // A[1][0] - fmul st(0),st(3) // A[1][0] * B[0][2] - faddp st(1),st(0) - faddp st(1),st(0) - fstp dword ptr [eax+24] // res[1][2] - -// (*set_res)[2][2] = A[2][0]*tmp1 + A[2][1]*tmp2 + A[2][2]*tmp3; - - fld dword ptr [edx+40] // A[2][2] - fmul st(0),st(3) // A[2][2] * B[2][2] - fld dword ptr [edx+36] // A[2][1] - fmul st(0),st(3) // A[2][1] * B[1][2] - fld dword ptr [edx+32] // A[2][0] - fmul st(0),st(3) // A[2][0] * B[0][2] - faddp st(1),st(0) - faddp st(1),st(0) - fstp dword ptr [eax+40] // res[2][2] - -// ------------------------------- -// tmp1 = B[0][3]; -// tmp2 = B[1][3]; -// tmp3 = B[2][3]; - fstp st(0) - fstp st(0) - fstp st(0) - fld dword ptr [ecx+44] // B[2][3] - fld dword ptr [ecx+28] // B[1][3] - fld dword ptr [ecx+12] // B[0][3] - -// (*set_res)[0][3] = A[0][0]*tmp1 + A[0][1]*tmp2 + A[0][2]*tmp3 + A[0][3]; - fld dword ptr [edx+8] // A[0][2] - fmul st(0),st(3) // A[0][2] * B[2][3] - fld dword ptr [edx+4] // A[0][1] - fmul st(0),st(3) // A[0][1] * B[1][3] - fld dword ptr [edx] // A[0][0] - fmul st(0),st(3) // A[0][2] * B[0][3] - faddp st(1),st(0) - faddp st(1),st(0) - fadd dword ptr [edx+12] // + A[0][3] - fstp dword ptr [eax+12] // res[0][3] - -// (*set_res)[1][3] = A[1][0]*tmp1 + A[1][1]*tmp2 + A[1][2]*tmp3 + A[1][3]; - fld dword ptr [edx+24] // A[1][2] - fmul st(0),st(3) // A[1][2] * B[2][3] - fld dword ptr [edx+20] // A[1][1] - fmul st(0),st(3) // A[1][1] * B[1][3] - fld dword ptr [edx+16] // A[1][0] - fmul st(0),st(3) // A[1][0] * B[0][3] - faddp st(1),st(0) - faddp st(1),st(0) - fadd dword ptr [edx+28] // + A[1][3] - fstp dword ptr [eax+28] // res[1][3] - -// (*set_res)[2][3] = A[2][0]*tmp1 + A[2][1]*tmp2 + A[2][2]*tmp3 + A[2][3]; - - fld dword ptr [edx+40] // A[2][2] - fmul st(0),st(3) // A[2][2] * B[2][3] - fld dword ptr [edx+36] // A[2][1] - fmul st(0),st(3) // A[2][1] * B[1][3] - fld dword ptr [edx+32] // A[2][0] - fmul st(0),st(3) // A[2][0] * B[0][3] - faddp st(1),st(0) - faddp st(1),st(0) - fadd dword ptr [edx+44] // + A[2][3] - fstp dword ptr [eax+44] // res[2][3] - fstp st(0) - fstp st(0) - fstp st(0) - - cmp eax,ebx - jne not_equal2 - mov ecx,12 // copy 12 dwords - mov esi,eax // set source to tmp - mov edi,set_res // set destination to set_res - rep movsd // copy -not_equal2: - - } -/* - WWDEBUG_SAY(("{%2.2f, %2.2f, %2.2f, %2.2f}, {%2.2f, %2.2f, %2.2f, %2.2f}, {%2.2f, %2.2f, %2.2f, %2.2f}\n" - ,res[0][0],res[0][1],res[0][2],res[0][3] - ,res[1][0],res[1][1],res[1][2],res[1][3] - ,res[2][0],res[2][1],res[2][2],res[2][3])); - WWDEBUG_SAY(("{%2.2f, %2.2f, %2.2f, %2.2f}, {%2.2f, %2.2f, %2.2f, %2.2f}, {%2.2f, %2.2f, %2.2f, %2.2f}\n" - ,res2[0][0],res2[0][1],res2[0][2],res2[0][3] - ,res2[1][0],res2[1][1],res2[1][2],res2[1][3] - ,res2[2][0],res2[2][1],res2[2][2],res2[2][3])); -// res[2][3]=res2[2][3]; -// res=res2; -*/ -/* for (int y=0;y<3;++y) { - for (int x=0;x<4;++x) { - if (fabs(res2[y][x]-res[y][x])>0.001f) { - WWDEBUG_SAY(("x: %d, y: %d, %f != %f\n",x,y,res2[y][x],res[y][x])); - __asm nop - } - } - } -*/ -/* WWASSERT(res2[0][0]==res[0][0]); - WWASSERT(res2[0][1]==res[0][1]); - WWASSERT(res2[0][2]==res[0][2]); - WWASSERT(res2[0][3]==res[0][3]); - WWASSERT(res2[1][0]==res[1][0]); - WWASSERT(res2[1][1]==res[1][1]); - WWASSERT(res2[1][2]==res[1][2]); - WWASSERT(res2[1][3]==res[1][3]); - WWASSERT(res2[2][0]==res[2][0]); - WWASSERT(res2[2][1]==res[2][1]); - WWASSERT(res2[2][2]==res[2][2]); - WWASSERT(res2[2][3]==res[2][3]); -*/ -} -#endif - -/*********************************************************************************************** - * Matrix3D::Transform_Min_Max_AABox -- compute transformed axis-aligned box * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 7/17/98 GTH : Created. * - *=============================================================================================*/ -void Matrix3D::Transform_Min_Max_AABox -( - const Vector3 & min, - const Vector3 & max, - Vector3 * set_min, - Vector3 * set_max -) const -{ - WWASSERT(set_min != &min); - WWASSERT(set_max != &max); - - float tmp0,tmp1; - - // init the min and max to the translation of the transform - set_min->X = set_max->X = Row[0][3]; - set_min->Y = set_max->Y = Row[1][3]; - set_min->Z = set_max->Z = Row[2][3]; - - // now push them both out by the projections of the original intervals - for (int i=0; i<3; i++) { - - for (int j=0; j<3; j++) { - - tmp0 = Row[i][j] * min[j]; - tmp1 = Row[i][j] * max[j]; - - if (tmp0 < tmp1) { - - (*set_min)[i] += tmp0; - (*set_max)[i] += tmp1; - - } else { - - (*set_min)[i] += tmp1; - (*set_max)[i] += tmp0; - - } - } - } -} - - -/*********************************************************************************************** - * Matrix3D::Transform_Center_Extent_AABox -- compute transformed axis-aligned box * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 7/17/98 GTH : Created. * - *=============================================================================================*/ -void Matrix3D::Transform_Center_Extent_AABox -( - const Vector3 & center, - const Vector3 & extent, - Vector3 * set_center, - Vector3 * set_extent -) const -{ - WWASSERT(set_center != ¢er); - WWASSERT(set_extent != &extent); - - // push each extent out to the projections of the original extents - for (int i=0; i<3; i++) { - - // start the center out at the translation portion of the matrix - // and the extent at zero - (*set_center)[i] = Row[i][3]; - (*set_extent)[i] = 0.0f; - - for (int j=0; j<3; j++) { - - (*set_center)[i] += Row[i][j] * center[j]; - (*set_extent)[i] += WWMath::Fabs(Row[i][j] * extent[j]); - - } - } -} - - -/*********************************************************************************************** - * Matrix3D::Is_Orthogonal -- checks whether this matrix is orthogonal * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 9/16/98 GTH : Created. * - *=============================================================================================*/ -int Matrix3D::Is_Orthogonal(void) const -{ - Vector3 x(Row[0].X,Row[0].Y,Row[0].Z); - Vector3 y(Row[1].X,Row[1].Y,Row[1].Z); - Vector3 z(Row[2].X,Row[2].Y,Row[2].Z); - - if (Vector3::Dot_Product(x,y) > WWMATH_EPSILON) return 0; - if (Vector3::Dot_Product(y,z) > WWMATH_EPSILON) return 0; - if (Vector3::Dot_Product(z,x) > WWMATH_EPSILON) return 0; - - if (WWMath::Fabs(x.Length2() - 1.0f) > WWMATH_EPSILON) return 0; - if (WWMath::Fabs(y.Length2() - 1.0f) > WWMATH_EPSILON) return 0; - if (WWMath::Fabs(z.Length2() - 1.0f) > WWMATH_EPSILON) return 0; - - return 1; -} - -/*********************************************************************************************** - * Matrix3D::Re_Orthogonalize -- makes this matrix orthogonal. * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * This function is rather expensive, should only be used if you *know* numerical error is * - * killing you. * - * * - * HISTORY: * - * 9/16/98 GTH : Created. * - *=============================================================================================*/ -void Matrix3D::Re_Orthogonalize(void) -{ - Vector3 x(Row[0][0],Row[0][1],Row[0][2]); - Vector3 y(Row[1][0],Row[1][1],Row[1][2]); - Vector3 z; - - Vector3::Cross_Product(x,y,&z); - Vector3::Cross_Product(z,x,&y); - - float len = x.Length(); - if (len < WWMATH_EPSILON) { - Make_Identity(); - return; - } else { - x *= 1.0f/len; - } - - len = y.Length(); - if (len < WWMATH_EPSILON) { - Make_Identity(); - return; - } else { - y *= 1.0f/len; - } - - len = z.Length(); - if (len < WWMATH_EPSILON) { - Make_Identity(); - return; - } else { - z *= 1.0f/len; - } - - Row[0][0] = x.X; - Row[0][1] = x.Y; - Row[0][2] = x.Z; - - Row[1][0] = y.X; - Row[1][1] = y.Y; - Row[1][2] = y.Z; - - Row[2][0] = z.X; - Row[2][1] = z.Y; - Row[2][2] = z.Z; -} - - -/*********************************************************************************************** - * Lerp - linearly interpolate matrices (orientation is slerped) * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 10/05/1998 NH : Created. * - *=============================================================================================*/ -void Matrix3D::Lerp(const Matrix3D &A, const Matrix3D &B, float factor, Matrix3D& result) -{ - assert(factor >= 0.0f); - assert(factor <= 1.0f); - - // Lerp position -#ifdef ALLOW_TEMPORARIES - Vector3 pos = Vector3::Lerp(A.Get_Translation(), B.Get_Translation(), factor); -#else - Vector3 pos; - Vector3::Lerp(A.Get_Translation(), B.Get_Translation(), factor, &pos); -#endif - Quaternion rot; - Slerp(rot,Build_Quaternion(A), Build_Quaternion(B), factor); - result.Set(rot, pos); -} - - -/*********************************************************************************************** - * Matrix3D::Solve_Linear_System -- 3x3 Gauss-Jordan elimination * - * * - * The result of this function will be that the 3x3 sub-matrix is inverted and the * - * final column will contain the result. False is returned if the system cannot be solved. * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 2/18/2001 gth : Created. * - *=============================================================================================*/ -bool Matrix3D::Solve_Linear_System(Matrix3D & system) -{ - /* - ** Gauss-Jordan Elimination - ** We repeatedly replace rows in the matrix with a linear combination of itself and - ** another row in the system in order to reduce the matrix to the identity matrix. - ** TODO: optimize away all unnecessary math operations! - */ - if (system[0][0] == 0.0f) return false; - system[0] *= 1.0f / system[0][0]; // (0,0) now equals 1.0 (row,col) - system[1] -= system[1][0] * system[0]; // (1,0) now equals 0.0 - system[2] -= system[2][0] * system[0]; // (2,0) now equals 0.0 - - if (system[1][1] == 0.0f) return false; - system[1] *= 1.0f / system[1][1]; // (1,1) now equals 1.0 - system[2] -= system[2][1] * system[1]; // (2,1) now equals 0.0 - - if (system[2][2] == 0.0f) return false; - system[2] *= 1.0f / system[2][2]; // (2,2) now equals 1.0, and we already have one answer - - system[1] -= system[1][2] * system[2]; // (1,2) now equals 0.0, and we have another answer - system[0] -= system[0][2] * system[2]; // (0,2) now equals 0.0 - - system[0] -= system[0][1] * system[1]; // (0,1) now equals 0.0, and we are done! - - return true; -} diff --git a/Generals/Code/Libraries/Source/WWVegas/WWMath/matrix3d.h b/Generals/Code/Libraries/Source/WWVegas/WWMath/matrix3d.h deleted file mode 100644 index 591363d5b7b..00000000000 --- a/Generals/Code/Libraries/Source/WWVegas/WWMath/matrix3d.h +++ /dev/null @@ -1,1818 +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 . -*/ - -/* $Header: /Commando/Code/wwmath/matrix3d.h 55 5/11/01 7:11p Jani_p $ */ -/*********************************************************************************************** - *** Confidential - Westwood Studios *** - *********************************************************************************************** - * * - * Project Name : Voxel Technology * - * * - * File Name : MATRIX3D.H * - * * - * Org Programmer : Greg Hjelstrom * - * * - * Programmer : Kenny Mitchell * - * * - * Start Date : 06/02/97 * - * * - * Last Update : June 6, 2002 [KM] * - * * - * 06/26/02 KM Matrix name change to avoid MAX conflicts * - *---------------------------------------------------------------------------------------------* - * Functions: * - * Matrix3D::Matrix3D -- Constructors for Matrix3D * - * Matrix3D::Set -- init a Matrix3D from an arrray of 12 floats * - * Matrix3D::Set -- Init a Matrix3D from 12 individual floats * - * Matrix3D::Set -- Init a matrix from 3 axis vectors and a position * - * Matrix3D::Set -- init a matrix to be a rotation about the given axis * - * Matrix3D::Set -- init a matrix to be a rotation about the given axis * - * Matrix3D::Set -- Init a matrix to be a pure translation * - * Matrix3D::Make_Identity -- Initializes the matrix to be the identity matrix * - * Matrix3D::Translate -- Post-Multiplies by a Translation Matrix * - * Matrix3D::Translate -- Post-Multiplies the matrix by a translation matrix * - * M3DC::Translate_X -- Post-Multiplies the matrix by a translation matrix with X only * - * M3DC::Translate_Y -- Post-Multiplies the matrix by a translation matrix with Y only * - * M3DC::Translate_Z -- Post-Multiplies the matrix by a translation matrix with Z only * - * Matrix3D::Rotate_X -- Post-Multiplies the matrix by a rotation about the X axis * - * Matrix3D::Rotate_X -- Post-Multiplies the matrix by a rotation about the X axis * - * Matrix3D::Rotate_Y -- Post-multiplies the matrix by a rotation about the Y axis * - * Matrix3D::Rotate_Y -- Post-Multiplies the matrix by a rotation about Y * - * Matrix3D::Rotate_Z -- Post-multiplies the matrix by a rotation about Z * - * Matrix3D::Rotate_Z -- Post-multiplies the matrix by a rotation about Z * - * Matrix3D::Scale -- Scales Matrix !!! WARNING DO NOT USE, INV FUNCTION WILL FAIL * - * Matrix3D::Scale -- Scales Matrix !!! WARNING DO NOT USE, INV FUNCTION WILL FAIL * - * Matrix3D::Scale -- Scales Matrix !!! WARNING DO NOT USE, INV FUNCTION WILL FAIL * - * M3DC::Pre_Rotate_X -- Pre-multiplies the matrix by a rotation about X * - * M3DC::Pre_Rotate_Y -- Pre-multiplies the matrix by a rotation about Y * - * M3DC::Pre_Rotate_Z -- Pre-multiplies the matrix by a rotation about Z * - * M3DC::Pre_Rotate_X -- Pre-multiplies the matrix by a rotation about X * - * M3DC::Pre_Rotate_Y -- Pre-multiplies the matrix by a rotation about Y * - * M3DC::Pre_Rotate_Z -- Pre-multiplies the matrix by a rotation about Z * - * M3DC::In_Place_Pre_Rotate_X -- Pre-multiplies rotation part of matrix by rotation about X * - * M3DC::In_Place_Pre_Rotate_Y -- Pre-multiplies rotation part of matrix by rotation about Y * - * M3DC::In_Place_Pre_Rotate_Z -- Pre-multiplies rotation part of matrix by rotation about Z * - * M3DC::In_Place_Pre_Rotate_X -- Pre-multiplies rotation part of matrix by rotation about X * - * M3DC::In_Place_Pre_Rotate_Y -- Pre-multiplies rotation part of matrix by rotation about Y * - * M3DC::In_Place_Pre_Rotate_Z -- Pre-multiplies rotation part of matrix by rotation about Z * - * operator * -- Matrix multiplication * - * operator * -- Matrix - vector multiplication * - * operator == -- Matrix equality operator * - * operator != -- Matrix inequality operator * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - -#define NO_ALLOW_TEMPORARIES - -#if defined(_MSC_VER) -#pragma once -#endif - -#ifndef MATRIX3D_H -#define MATRIX3D_H - -#ifdef _UNIX -#include "osdep.h" -#endif - -#include "always.h" -#include -#include "vector2.h" -#include "vector3.h" -#include "vector4.h" -#ifdef _UNIX -#include "osdep.h" -#endif - - -class Matrix3x3; -class Matrix4x4; -class Quaternion; - -/******************************************************************************* - - Matrix3D - - Three important notes: - - I use *column-vectors* - - I use a *right-handed* coordinate system - - These matrices are *orthogonal* - - 3D Transformation matrices. This class is really a 4x4 homogeneous - matrix where the last row is assumed to always be 0 0 0 1. However, - since I don't store the last row, you cant do some things that you can - do with a real 4x4 homogeneous matrix. - - I use column-vectors so normally transformations are post-multiplied - and camera transformations should be pre-multiplied. The methods of - this class called Translate, Rotate_X, etc. all perform post-multiplication - with the current matix. These methods (Translate, Rotate_X, etc) also - have been hand-coded to only perform the necessary arithmetic. The - * operator can be used for general purpose matrix multiplication or to - transform a vector by a matrix. - - Some operations in this class assume that the matrix is orthogonal. - -*********************************************************************************/ - -class Matrix3D -{ -public: - - // Constructors - WWINLINE Matrix3D(void) {} - - WWINLINE explicit Matrix3D(bool init) { if (init) Make_Identity(); } - - WWINLINE explicit Matrix3D(float m[12]); - - WWINLINE explicit Matrix3D( - float m11,float m12,float m13,float m14, - float m21,float m22,float m23,float m24, - float m31,float m32,float m33,float m34 - ); - - WWINLINE explicit Matrix3D( - const Vector3 &x, // x-axis unit vector - const Vector3 &y, // y-axis unit vector - const Vector3 &z, // z-axis unit vector - const Vector3 &pos // position - ); - - WWINLINE explicit Matrix3D( - const Vector3 &axis, - float angle - ); - - WWINLINE explicit Matrix3D( - const Vector3 &axis, - float sine, - float cosine - ); - - WWINLINE explicit Matrix3D( - const Matrix3x3 & rotation, - const Vector3 & position - ); - - WWINLINE explicit Matrix3D( - const Quaternion & rotation, - const Vector3 & position - ); - - // Creates identity rotation w. given position. - WWINLINE explicit Matrix3D(const Vector3 & position); - - // Copy constructor - WWINLINE Matrix3D(const Matrix3D & m); - - // Assignment operator - WWINLINE Matrix3D & operator = (const Matrix3D & m); - - // Init functions - WWINLINE void Set(float m[12]); - - WWINLINE void Set( - float m11,float m12,float m13,float m14, - float m21,float m22,float m23,float m24, - float m31,float m32,float m33,float m34 - ); - - WWINLINE void Set( - const Vector3 &x, // x-axis unit vector - const Vector3 &y, // y-axis unit vector - const Vector3 &z, // z-axis unit vector - const Vector3 &pos // position - ); - - WWINLINE void Set(const Vector3 & axis,float angle); - - WWINLINE void Set(const Vector3 & axis,float sine,float cosine); - - void Set(const Matrix3x3 & rotation,const Vector3 & position); - - void Set(const Quaternion & rotation,const Vector3 & position); - - // Creates identity rotation w. given position. - WWINLINE void Set(const Vector3 & position); - - // access functions: - WWINLINE Vector4 & operator [] (int i) { return Row[i]; } - WWINLINE const Vector4 & operator [] (int i) const { return Row[i]; } - - WWINLINE Vector3 Get_Translation(void) const { return Vector3(Row[0][3],Row[1][3],Row[2][3]); } - WWINLINE void Get_Translation(Vector3 * set) const { set->X = Row[0][3]; set->Y = Row[1][3]; set->Z = Row[2][3]; } - WWINLINE void Set_Translation(const Vector3 & t) { Row[0][3] = t[0]; Row[1][3] = t[1];Row[2][3] = t[2]; } - - void Set_Rotation(const Matrix3x3 & m); - void Set_Rotation(const Quaternion & q); - - WWINLINE float Get_X_Translation(void) const { return Row[0][3]; }; - WWINLINE float Get_Y_Translation(void) const { return Row[1][3]; }; - WWINLINE float Get_Z_Translation(void) const { return Row[2][3]; }; - - WWINLINE void Set_X_Translation(float x) { Row[0][3] = x; }; - WWINLINE void Set_Y_Translation(float y) { Row[1][3] = y; }; - WWINLINE void Set_Z_Translation(float z) { Row[2][3] = z; }; - - WWINLINE void Adjust_Translation(const Vector3 & t) { Row[0][3] += t[0]; Row[1][3] += t[1]; Row[2][3] += t[2]; }; - WWINLINE void Adjust_X_Translation(float x) { Row[0][3] += x; }; - WWINLINE void Adjust_Y_Translation(float y) { Row[1][3] += y; }; - WWINLINE void Adjust_Z_Translation(float z) { Row[2][3] += z; }; - - // These functions will give you the approximate amount that the - // matrix has been rotated about a given axis. These functions - // cannot be used to re-build a matrx. Use the EulerAnglesClass - // to convert a matrix into a set of three Euler angles. - float Get_X_Rotation(void) const; - float Get_Y_Rotation(void) const; - float Get_Z_Rotation(void) const; - - // Each of the transformation methods performs an - // "optimized" post-multiplication with the current matrix. - // All angles are assumed to be radians. - WWINLINE void Make_Identity(void); - void Translate(float x,float y,float z); - void Translate(const Vector3 &t); - void Translate_X(float x); - void Translate_Y(float y); - void Translate_Z(float z); - void Rotate_X(float theta); - void Rotate_Y(float theta); - void Rotate_Z(float theta); - void Rotate_X(float s,float c); - void Rotate_Y(float s,float c); - void Rotate_Z(float s,float c); - - // !! - // !! Use Scale methods with Extreme Caution - // !! The Matrix Inverse function, only works - // !! with Orthogonal Matrices, for optimization purposes - // !! - WWINLINE void Scale(float scale); // uniform scale all 3 axis - WWINLINE void Scale(float x, float y, float z); // separate input for each axis - WWINLINE void Scale(Vector3 &scale); // scale each axis - - - // Each of these performs an "optimized" pre-multiplication with the - // current matrix. All angles are assumed to be radians. The "In_Place" - // versions do not affect the translation part of the matrix, - WWINLINE void Pre_Rotate_X(float theta); - WWINLINE void Pre_Rotate_Y(float theta); - WWINLINE void Pre_Rotate_Z(float theta); - WWINLINE void Pre_Rotate_X(float s,float c); - WWINLINE void Pre_Rotate_Y(float s,float c); - WWINLINE void Pre_Rotate_Z(float s,float c); - WWINLINE void In_Place_Pre_Rotate_X(float theta); - WWINLINE void In_Place_Pre_Rotate_Y(float theta); - WWINLINE void In_Place_Pre_Rotate_Z(float theta); - WWINLINE void In_Place_Pre_Rotate_X(float s,float c); - WWINLINE void In_Place_Pre_Rotate_Y(float s,float c); - WWINLINE void In_Place_Pre_Rotate_Z(float s,float c); - - // Points the negative Z axis at the target t. Assumes that - // the "world" uses x-y as the ground and z as altitude. - // Used for pointing cameras at targets. - void Look_At(const Vector3 &p,const Vector3 &t,float roll); - - // Previous look_at function follows the camera coordinate convention. - // This one follows the object convention used in Commando and G. I - // special cased this convention since it is used so much by us rather - // than supporting every one of the 24(?) possible conventions... - void Obj_Look_At(const Vector3 &p,const Vector3 &t,float roll); - - // Create a matrix given a position and a direction (x axis will point in direction) - void buildTransformMatrix( const Vector3 &pos, const Vector3 &dir ); - - // use the 3x3 sub-matrix only (ignore translation) - Vector3 Rotate_Vector(const Vector3 &vect) const; - Vector3 Inverse_Rotate_Vector(const Vector3 &vect) const; - - // these get the a vector representing the direction an axis is pointing - WWINLINE Vector3 Get_X_Vector() const { return Vector3(Row[0][0], Row[1][0], Row[2][0]); } - WWINLINE Vector3 Get_Y_Vector() const { return Vector3(Row[0][1], Row[1][1], Row[2][1]); } - WWINLINE Vector3 Get_Z_Vector() const { return Vector3(Row[0][2], Row[1][2], Row[2][2]); } - WWINLINE void Get_X_Vector(Vector3 * set_x) const { set_x->Set(Row[0][0], Row[1][0], Row[2][0]); } - WWINLINE void Get_Y_Vector(Vector3 * set_y) const { set_y->Set(Row[0][1], Row[1][1], Row[2][1]); } - WWINLINE void Get_Z_Vector(Vector3 * set_z) const { set_z->Set(Row[0][2], Row[1][2], Row[2][2]); } - - // Get the inverse of the matrix. - // TODO: currently the "intended-to-be" general inverse function just calls - // the special case Orthogonal inverse functions. Also, when we implement - // general case, check where we were using Get_Inverse since usually it should - // be changed to Get_Orthogonal_Inverse... - void Get_Inverse(Matrix3D & set_inverse) const; - void Get_Orthogonal_Inverse(Matrix3D & set_inverse) const; - - // used for importing SurRender matrices - void Copy_3x3_Matrix(float matrix[3][3]); - - // Optimized Axis-Aligned Box transforms. One for each of the common forms of - // axis aligned box: min,max vectors and center,extent vectors. - void Transform_Min_Max_AABox(const Vector3 & min,const Vector3 & max,Vector3 * set_min,Vector3 * set_max) const; - void Transform_Center_Extent_AABox(const Vector3 & center,const Vector3 & extent,Vector3 * set_center,Vector3 * set_extent) const; - - // matrix multiplication without temporaries - static void Multiply(const Matrix3D &A,const Matrix3D &B,Matrix3D * set_result); - static WWINLINE void Transform_Vector(const Matrix3D & tm,const Vector3 & in,Vector3 * out); - static WWINLINE void Rotate_Vector(const Matrix3D & tm,const Vector3 & in,Vector3 * out); - - // transform a vector by the inverse of this matrix (note: assumes the matrix - // is orthogonal; if you've manually scaled or sheared the matrix this function - // will not give correct results) - static WWINLINE void Inverse_Transform_Vector(const Matrix3D & tm,const Vector3 & in,Vector3 * out); - static WWINLINE void Inverse_Rotate_Vector(const Matrix3D & tm,const Vector3 & in,Vector3 * out); - - // Solve a linear system of 3 equations and 3 unknowns. The result of this function is - // that the 3x3 portion of the matrix is inverted and the final column is your answer... - static bool Solve_Linear_System(Matrix3D & system); - - // Check whether a matrix is orthogonal or FORCE it to be :-) - int Is_Orthogonal(void) const; - void Re_Orthogonalize(void); - - static void Lerp(const Matrix3D &A, const Matrix3D &B, float factor, Matrix3D& result); - -#ifdef ALLOW_TEMPORARIES - // nothing -#else - - // does "this = that * this" - void preMul(const Matrix3D& that); - - // does "this = this * that" - void postMul(const Matrix3D& that); - - // does "this = a * b" - void mul(const Matrix3D& a, const Matrix3D& b); - - void mulVector3(const Vector3& in, Vector3& out) const; - void mulVector3(Vector3& inout) const { mulVector3(inout, inout); } - -#endif - - void mulVector3Array(const Vector3* in, Vector3* out, int count) const; - void mulVector3Array(Vector3* inout, int count) const; - - // some static matrices which are sometimes useful - static const Matrix3D Identity; - static const Matrix3D RotateX90; - static const Matrix3D RotateX180; - static const Matrix3D RotateX270; - static const Matrix3D RotateY90; - static const Matrix3D RotateY180; - static const Matrix3D RotateY270; - static const Matrix3D RotateZ90; - static const Matrix3D RotateZ180; - static const Matrix3D RotateZ270; - -protected: - - Vector4 Row[3]; - -#ifdef ALLOW_TEMPORARIES - WWINLINE friend Vector3 operator * (const Matrix3D &A,const Vector3 &a); -#endif -}; - - - -/* --------------------------------------------------------------- - Vector Transformation, Matrix concatenation ---------------------------------------------------------------- */ -#ifdef ALLOW_TEMPORARIES -Vector3 operator * (const Matrix3D &A,const Vector3 &v); -Matrix3D operator * (const Matrix3D &A,const Matrix3D &B); -#endif - -/* --------------------------------------------------------------- - Equality and inequality operators ---------------------------------------------------------------- */ -bool operator == (const Matrix3D &A, const Matrix3D &B); -bool operator != (const Matrix3D &A, const Matrix3D &B); - - -/*********************************************************************************************** - * M3DC::Matrix3D -- Constructors for Matrix3D * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 02/24/1997 GH : Created. * - *=============================================================================================*/ -WWINLINE Matrix3D::Matrix3D(float m[12]) -{ - Row[0].Set(m[0],m[1],m[2],m[3]); - Row[1].Set(m[4],m[5],m[6],m[7]); - Row[2].Set(m[8],m[9],m[10],m[11]); -} - -WWINLINE Matrix3D::Matrix3D -( - float m11,float m12,float m13,float m14, - float m21,float m22,float m23,float m24, - float m31,float m32,float m33,float m34 -) -{ - Row[0].Set(m11,m12,m13,m14); - Row[1].Set(m21,m22,m23,m24); - Row[2].Set(m31,m32,m33,m34); -} - -WWINLINE Matrix3D::Matrix3D -( - const Vector3 &x, // x-axis unit vector - const Vector3 &y, // y-axis unit vector - const Vector3 &z, // z-axis unit vector - const Vector3 &pos // position -) -{ - Set(x,y,z,pos); -} - -WWINLINE Matrix3D::Matrix3D(const Vector3 & axis,float angle) -{ - Set(axis,angle); -} - -WWINLINE Matrix3D::Matrix3D(const Vector3 & axis,float sine,float cosine) -{ - Set(axis,sine,cosine); -} - -WWINLINE Matrix3D::Matrix3D(const Matrix3x3 & rot,const Vector3 & pos) -{ - Set(rot,pos); -} - -WWINLINE Matrix3D::Matrix3D(const Quaternion & rot,const Vector3 & pos) -{ - Set(rot,pos); -} - -WWINLINE Matrix3D::Matrix3D(const Vector3 & position) -{ - Set(position); -} - -// Copy Constructor -WWINLINE Matrix3D::Matrix3D(const Matrix3D & m) -{ - Row[0] = m.Row[0]; - Row[1] = m.Row[1]; - Row[2] = m.Row[2]; -} - -// Assignment operator -WWINLINE Matrix3D & Matrix3D::operator = (const Matrix3D & m) -{ - Row[0] = m.Row[0]; - Row[1] = m.Row[1]; - Row[2] = m.Row[2]; - return *this; -} - - -/*********************************************************************************************** - * Matrix3D::Set -- init a Matrix3D from an arrray of 12 floats * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 2/24/98 GTH : Created. * - *=============================================================================================*/ -WWINLINE void Matrix3D::Set(float m[12]) -{ - Row[0].Set(m[0],m[1],m[2],m[3]); - Row[1].Set(m[4],m[5],m[6],m[7]); - Row[2].Set(m[8],m[9],m[10],m[11]); -} - - -/*********************************************************************************************** - * Matrix3D::Set -- Init a Matrix3D from 12 individual floats * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 2/24/98 GTH : Created. * - *=============================================================================================*/ -WWINLINE void Matrix3D::Set( float m11,float m12,float m13,float m14, - float m21,float m22,float m23,float m24, - float m31,float m32,float m33,float m34) -{ - Row[0].Set(m11,m12,m13,m14); - Row[1].Set(m21,m22,m23,m24); - Row[2].Set(m31,m32,m33,m34); -} - - -/*********************************************************************************************** - * Matrix3D::Set -- Init a matrix from 3 axis vectors and a position * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 2/24/98 GTH : Created. * - *=============================================================================================*/ -WWINLINE void Matrix3D::Set( const Vector3 &x, // x-axis unit vector - const Vector3 &y, // y-axis unit vector - const Vector3 &z, // z-axis unit vector - const Vector3 &pos) // position -{ - Row[0].Set(x[0],y[0],z[0],pos[0]); - Row[1].Set(x[1],y[1],z[1],pos[1]); - Row[2].Set(x[2],y[2],z[2],pos[2]); -} - - -/*********************************************************************************************** - * Matrix3D::Set -- init a matrix to be a rotation about the given axis * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 2/24/98 GTH : Created. * - *=============================================================================================*/ -WWINLINE void Matrix3D::Set(const Vector3 & axis,float angle) -{ - float c = cosf(angle); - float s = sinf(angle); - - Set(axis,s,c); -} - -/*********************************************************************************************** - * Matrix3D::Set -- init a matrix to be a rotation about the given axis * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 2/24/98 GTH : Created. * - *=============================================================================================*/ -WWINLINE void Matrix3D::Set(const Vector3 & axis,float s,float c) -{ - assert(WWMath::Fabs(axis.Length2() - 1.0f) < 0.001f); - - Row[0].Set( - (float)(axis[0]*axis[0] + c*(1.0f - axis[0]*axis[0])), - (float)(axis[0]*axis[1]*(1.0f - c) - axis[2]*s), - (float)(axis[2]*axis[0]*(1.0f - c) + axis[1]*s), - 0.0f - ); - - Row[1].Set( - (float)(axis[0]*axis[1]*(1.0f - c) + axis[2]*s), - (float)(axis[1]*axis[1] + c*(1.0f - axis[1]*axis[1])), - (float)(axis[1]*axis[2]*(1.0f - c) - axis[0]*s), - 0.0f - ); - - Row[2].Set( - (float)(axis[2]*axis[0]*(1.0f - c) - axis[1]*s), - (float)(axis[1]*axis[2]*(1.0f - c) + axis[0]*s), - (float)(axis[2]*axis[2] + c*(1 - axis[2]*axis[2])), - 0.0f - ); -} - - -/*********************************************************************************************** - * Matrix3D::Set -- Init a matrix to be a pure translation * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 2/24/98 GTH : Created. * - *=============================================================================================*/ -WWINLINE void Matrix3D::Set(const Vector3 & position) -{ - Row[0].Set(1.0f,0.0f,0.0f,position[0]); - Row[1].Set(0.0f,1.0f,0.0f,position[1]); - Row[2].Set(0.0f,0.0f,1.0f,position[2]); -} - - -/*********************************************************************************************** - * M3DC::Make_Identity -- Initializes the matrix to be the identity matrix * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 02/24/1997 GH : Created. * - *=============================================================================================*/ -WWINLINE void Matrix3D::Make_Identity(void) -{ - Row[0].Set(1.0f,0.0f,0.0f,0.0f); - Row[1].Set(0.0f,1.0f,0.0f,0.0f); - Row[2].Set(0.0f,0.0f,1.0f,0.0f); -} - - -/*********************************************************************************************** - * M3DC::Translate -- Post-Multiplies by a Translation Matrix * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 02/24/1997 GH : Created. * - *=============================================================================================*/ -WWINLINE void Matrix3D::Translate(float x,float y,float z) -{ - Row[0][3] += (float)(Row[0][0]*x + Row[0][1]*y + Row[0][2]*z); - Row[1][3] += (float)(Row[1][0]*x + Row[1][1]*y + Row[1][2]*z); - Row[2][3] += (float)(Row[2][0]*x + Row[2][1]*y + Row[2][2]*z); -} - - -/*********************************************************************************************** - * M3DC::Translate -- Post-Multiplies the matrix by a translation matrix * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 02/24/1997 GH : Created. * - *=============================================================================================*/ -WWINLINE void Matrix3D::Translate(const Vector3 &t) -{ - Row[0][3] += Row[0][0]*t[0] + Row[0][1]*t[1] + Row[0][2]*t[2]; - Row[1][3] += Row[1][0]*t[0] + Row[1][1]*t[1] + Row[1][2]*t[2]; - Row[2][3] += Row[2][0]*t[0] + Row[2][1]*t[1] + Row[2][2]*t[2]; -} - - -/*********************************************************************************************** - * M3DC::Translate_X -- Post-Multiplies the matrix by a translation matrix with X only * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 07/06/1998 NH : Created. * - *=============================================================================================*/ -WWINLINE void Matrix3D::Translate_X(float x) -{ - Row[0][3] += (float)(Row[0][0]*x); - Row[1][3] += (float)(Row[1][0]*x); - Row[2][3] += (float)(Row[2][0]*x); -} - - -/*********************************************************************************************** - * M3DC::Translate_Y -- Post-Multiplies the matrix by a translation matrix with Y only * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 07/06/1998 NH : Created. * - *=============================================================================================*/ -WWINLINE void Matrix3D::Translate_Y(float y) -{ - Row[0][3] += (float)(Row[0][1]*y); - Row[1][3] += (float)(Row[1][1]*y); - Row[2][3] += (float)(Row[2][1]*y); -} - - -/*********************************************************************************************** - * M3DC::Translate_Z -- Post-Multiplies the matrix by a translation matrix with Z only * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 07/06/1998 NH : Created. * - *=============================================================================================*/ -WWINLINE void Matrix3D::Translate_Z(float z) -{ - Row[0][3] += (float)(Row[0][2]*z); - Row[1][3] += (float)(Row[1][2]*z); - Row[2][3] += (float)(Row[2][2]*z); -} - - -/*********************************************************************************************** - * M3DC::Rotate_X -- Post-Multiplies the matrix by a rotation about the X axis * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 02/24/1997 GH : Created. * - *=============================================================================================*/ -WWINLINE void Matrix3D::Rotate_X(float theta) -{ - float tmp1,tmp2; - float s,c; - - s = sinf(theta); - c = cosf(theta); - - tmp1 = Row[0][1]; tmp2 = Row[0][2]; - Row[0][1] = (float)( c*tmp1 + s*tmp2); - Row[0][2] = (float)(-s*tmp1 + c*tmp2); - - tmp1 = Row[1][1]; tmp2 = Row[1][2]; - Row[1][1] = (float)( c*tmp1 + s*tmp2); - Row[1][2] = (float)(-s*tmp1 + c*tmp2); - - tmp1 = Row[2][1]; tmp2 = Row[2][2]; - Row[2][1] = (float)( c*tmp1 + s*tmp2); - Row[2][2] = (float)(-s*tmp1 + c*tmp2); - -} - - -/*********************************************************************************************** - * M3DC::Rotate_X -- Post-Multiplies the matrix by a rotation about the X axis * - * * - * INPUT: * - * s - sine of the angle * - * c - cosine of the angle * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 02/24/1997 GH : Created. * - *=============================================================================================*/ -WWINLINE void Matrix3D::Rotate_X(float s,float c) -{ - float tmp1,tmp2; - - tmp1 = Row[0][1]; tmp2 = Row[0][2]; - Row[0][1] = (float)( c*tmp1 + s*tmp2); - Row[0][2] = (float)(-s*tmp1 + c*tmp2); - - tmp1 = Row[1][1]; tmp2 = Row[1][2]; - Row[1][1] = (float)( c*tmp1 + s*tmp2); - Row[1][2] = (float)(-s*tmp1 + c*tmp2); - - tmp1 = Row[2][1]; tmp2 = Row[2][2]; - Row[2][1] = (float)( c*tmp1 + s*tmp2); - Row[2][2] = (float)(-s*tmp1 + c*tmp2); -} - - -/*********************************************************************************************** - * M3DC::Rotate_Y -- Post-multiplies the matrix by a rotation about the Y axis * - * * - * INPUT: * - * theta - angle (in radians) to rotate * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 02/24/1997 GH : Created. * - *=============================================================================================*/ -WWINLINE void Matrix3D::Rotate_Y(float theta) -{ - float tmp1,tmp2; - float s,c; - - s = sinf(theta); - c = cosf(theta); - - tmp1 = Row[0][0]; tmp2 = Row[0][2]; - Row[0][0] = (float)(c*tmp1 - s*tmp2); - Row[0][2] = (float)(s*tmp1 + c*tmp2); - - tmp1 = Row[1][0]; tmp2 = Row[1][2]; - Row[1][0] = (float)(c*tmp1 - s*tmp2); - Row[1][2] = (float)(s*tmp1 + c*tmp2); - - tmp1 = Row[2][0]; tmp2 = Row[2][2]; - Row[2][0] = (float)(c*tmp1 - s*tmp2); - Row[2][2] = (float)(s*tmp1 + c*tmp2); -} - - -/*********************************************************************************************** - * M3DC::Rotate_Y -- Post-Multiplies the matrix by a rotation about Y * - * * - * INPUT: * - * s - sine of the angle * - * c - cosine of the angle * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 02/24/1997 GH : Created. * - *=============================================================================================*/ -WWINLINE void Matrix3D::Rotate_Y(float s,float c) -{ - float tmp1,tmp2; - - tmp1 = Row[0][0]; tmp2 = Row[0][2]; - Row[0][0] = (float)(c*tmp1 - s*tmp2); - Row[0][2] = (float)(s*tmp1 + c*tmp2); - - tmp1 = Row[1][0]; tmp2 = Row[1][2]; - Row[1][0] = (float)(c*tmp1 - s*tmp2); - Row[1][2] = (float)(s*tmp1 + c*tmp2); - - tmp1 = Row[2][0]; tmp2 = Row[2][2]; - Row[2][0] = (float)(c*tmp1 - s*tmp2); - Row[2][2] = (float)(s*tmp1 + c*tmp2); -} - - -/*********************************************************************************************** - * M3DC::Rotate_Z -- Post-multiplies the matrix by a rotation about Z * - * * - * INPUT: * - * theta - angle (in radians) to rotate * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 02/24/1997 GH : Created. * - *=============================================================================================*/ -WWINLINE void Matrix3D::Rotate_Z(float theta) -{ - float tmp1,tmp2; - float c,s; - - c = cosf(theta); - s = sinf(theta); - - tmp1 = Row[0][0]; tmp2 = Row[0][1]; - Row[0][0] = (float)( c*tmp1 + s*tmp2); - Row[0][1] = (float)(-s*tmp1 + c*tmp2); - - tmp1 = Row[1][0]; tmp2 = Row[1][1]; - Row[1][0] = (float)( c*tmp1 + s*tmp2); - Row[1][1] = (float)(-s*tmp1 + c*tmp2); - - tmp1 = Row[2][0]; tmp2 = Row[2][1]; - Row[2][0] = (float)( c*tmp1 + s*tmp2); - Row[2][1] = (float)(-s*tmp1 + c*tmp2); -} - - -/*********************************************************************************************** - * M3DC::Rotate_Z -- Post-multiplies the matrix by a rotation about Z * - * * - * INPUT: * - * s - sine of the angle to rotate * - * c - cosine of the angle to rotate * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 02/24/1997 GH : Created. * - *=============================================================================================*/ -WWINLINE void Matrix3D::Rotate_Z(float s,float c) -{ - float tmp1,tmp2; - - tmp1 = Row[0][0]; tmp2 = Row[0][1]; - Row[0][0] = (float)( c*tmp1 + s*tmp2); - Row[0][1] = (float)(-s*tmp1 + c*tmp2); - - tmp1 = Row[1][0]; tmp2 = Row[1][1]; - Row[1][0] = (float)( c*tmp1 + s*tmp2); - Row[1][1] = (float)(-s*tmp1 + c*tmp2); - - tmp1 = Row[2][0]; tmp2 = Row[2][1]; - Row[2][0] = (float)( c*tmp1 + s*tmp2); - Row[2][1] = (float)(-s*tmp1 + c*tmp2); -} - -/*********************************************************************************************** - * Matrix3D::Scale -- Scales each Axis * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 03/07/2000 jga : Created. * - *=============================================================================================*/ -// !! -// !! Use Scale methods with Extreme Caution -// !! The Matrix Inverse function, only works -// !! with Orthogonal Matrices, for optimization purposes -// !! -WWINLINE void Matrix3D::Scale(float scale) -{ // uniform scale all 3 axis - // X - Row[0][0] *= scale; - Row[1][0] *= scale; - Row[2][0] *= scale; - // Y - Row[0][1] *= scale; - Row[1][1] *= scale; - Row[2][1] *= scale; - // Z - Row[0][2] *= scale; - Row[1][2] *= scale; - Row[2][2] *= scale; -} -/*********************************************************************************************** - * Matrix3D::Scale -- Scales each Axis * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 03/07/2000 jga : Created. * - *=============================================================================================*/ -// !! -// !! Use Scale methods with Extreme Caution -// !! The Matrix Inverse function, only works -// !! with Orthogonal Matrices, for optimization purposes -// !! -WWINLINE void Matrix3D::Scale(float x, float y, float z) -{ // separate input for each axis - // X - Row[0][0] *= x; - Row[1][0] *= x; - Row[2][0] *= x; - // Y - Row[0][1] *= y; - Row[1][1] *= y; - Row[2][1] *= y; - // Z - Row[0][2] *= z; - Row[1][2] *= z; - Row[2][2] *= z; -} -/*********************************************************************************************** - * Matrix3D::Scale -- Scales each Axis * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 03/07/2000 jga : Created. * - *=============================================================================================*/ -// !! -// !! Use Scale methods with Extreme Caution -// !! The Matrix Inverse function, only works -// !! with Orthogonal Matrices, for optimization purposes -// !! -WWINLINE void Matrix3D::Scale(Vector3 &scale) -{ // scale each axis - Scale(scale.X, scale.Y, scale.Z); -} - -/*********************************************************************************************** - * M3DC::Pre_Rotate_X -- Pre-multiplies the matrix by a rotation about X * - * * - * INPUT: * - * theta - angle (in radians) to rotate * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 07/1/1999 NH : Created. * - *=============================================================================================*/ -WWINLINE void Matrix3D::Pre_Rotate_X(float theta) -{ - float tmp1,tmp2; - float c,s; - - c = cosf(theta); - s = sinf(theta); - - tmp1 = Row[1][0]; tmp2 = Row[2][0]; - Row[1][0] = (float)(c*tmp1 - s*tmp2); - Row[2][0] = (float)(s*tmp1 + c*tmp2); - - tmp1 = Row[1][1]; tmp2 = Row[2][1]; - Row[1][1] = (float)(c*tmp1 - s*tmp2); - Row[2][1] = (float)(s*tmp1 + c*tmp2); - - tmp1 = Row[1][2]; tmp2 = Row[2][2]; - Row[1][2] = (float)(c*tmp1 - s*tmp2); - Row[2][2] = (float)(s*tmp1 + c*tmp2); - - tmp1 = Row[1][3]; tmp2 = Row[2][3]; - Row[1][3] = (float)(c*tmp1 - s*tmp2); - Row[2][3] = (float)(s*tmp1 + c*tmp2); -} - -/*********************************************************************************************** - * M3DC::Pre_Rotate_Y -- Pre-multiplies the matrix by a rotation about Y * - * * - * INPUT: * - * theta - angle (in radians) to rotate * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 07/1/1999 NH : Created. * - *=============================================================================================*/ -WWINLINE void Matrix3D::Pre_Rotate_Y(float theta) -{ - float tmp1,tmp2; - float c,s; - - c = cosf(theta); - s = sinf(theta); - - tmp1 = Row[0][0]; tmp2 = Row[2][0]; - Row[0][0] = (float)( c*tmp1 + s*tmp2); - Row[2][0] = (float)(-s*tmp1 + c*tmp2); - - tmp1 = Row[0][1]; tmp2 = Row[2][1]; - Row[0][1] = (float)( c*tmp1 + s*tmp2); - Row[2][1] = (float)(-s*tmp1 + c*tmp2); - - tmp1 = Row[0][2]; tmp2 = Row[2][2]; - Row[0][2] = (float)( c*tmp1 + s*tmp2); - Row[2][2] = (float)(-s*tmp1 + c*tmp2); - - tmp1 = Row[0][3]; tmp2 = Row[2][3]; - Row[0][3] = (float)( c*tmp1 + s*tmp2); - Row[2][3] = (float)(-s*tmp1 + c*tmp2); -} - -/*********************************************************************************************** - * M3DC::Pre_Rotate_Z -- Pre-multiplies the matrix by a rotation about Z * - * * - * INPUT: * - * theta - angle (in radians) to rotate * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 07/1/1999 NH : Created. * - *=============================================================================================*/ -WWINLINE void Matrix3D::Pre_Rotate_Z(float theta) -{ - float tmp1,tmp2; - float c,s; - - c = cosf(theta); - s = sinf(theta); - - tmp1 = Row[0][0]; tmp2 = Row[1][0]; - Row[0][0] = (float)(c*tmp1 - s*tmp2); - Row[1][0] = (float)(s*tmp1 + c*tmp2); - - tmp1 = Row[0][1]; tmp2 = Row[1][1]; - Row[0][1] = (float)(c*tmp1 - s*tmp2); - Row[1][1] = (float)(s*tmp1 + c*tmp2); - - tmp1 = Row[0][2]; tmp2 = Row[1][2]; - Row[0][2] = (float)(c*tmp1 - s*tmp2); - Row[1][2] = (float)(s*tmp1 + c*tmp2); - - tmp1 = Row[0][3]; tmp2 = Row[1][3]; - Row[0][3] = (float)(c*tmp1 - s*tmp2); - Row[1][3] = (float)(s*tmp1 + c*tmp2); -} - -/*********************************************************************************************** - * M3DC::Pre_Rotate_X -- Pre-multiplies the matrix by a rotation about X * - * * - * INPUT: * - * s - sine of the angle to rotate * - * c - cosine of the angle to rotate * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 07/1/1999 NH : Created. * - *=============================================================================================*/ -WWINLINE void Matrix3D::Pre_Rotate_X(float s,float c) -{ - float tmp1,tmp2; - - tmp1 = Row[1][0]; tmp2 = Row[2][0]; - Row[1][0] = (float)(c*tmp1 - s*tmp2); - Row[2][0] = (float)(s*tmp1 + c*tmp2); - - tmp1 = Row[1][1]; tmp2 = Row[2][1]; - Row[1][1] = (float)(c*tmp1 - s*tmp2); - Row[2][1] = (float)(s*tmp1 + c*tmp2); - - tmp1 = Row[1][2]; tmp2 = Row[2][2]; - Row[1][2] = (float)(c*tmp1 - s*tmp2); - Row[2][2] = (float)(s*tmp1 + c*tmp2); - - tmp1 = Row[1][3]; tmp2 = Row[2][3]; - Row[1][3] = (float)(c*tmp1 - s*tmp2); - Row[2][3] = (float)(s*tmp1 + c*tmp2); -} - -/*********************************************************************************************** - * M3DC::Pre_Rotate_Y -- Pre-multiplies the matrix by a rotation about Y * - * * - * INPUT: * - * s - sine of the angle to rotate * - * c - cosine of the angle to rotate * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 07/1/1999 NH : Created. * - *=============================================================================================*/ -WWINLINE void Matrix3D::Pre_Rotate_Y(float s,float c) -{ - float tmp1,tmp2; - - tmp1 = Row[0][0]; tmp2 = Row[2][0]; - Row[0][0] = (float)( c*tmp1 + s*tmp2); - Row[2][0] = (float)(-s*tmp1 + c*tmp2); - - tmp1 = Row[0][1]; tmp2 = Row[2][1]; - Row[0][1] = (float)( c*tmp1 + s*tmp2); - Row[2][1] = (float)(-s*tmp1 + c*tmp2); - - tmp1 = Row[0][2]; tmp2 = Row[2][2]; - Row[0][2] = (float)( c*tmp1 + s*tmp2); - Row[2][2] = (float)(-s*tmp1 + c*tmp2); - - tmp1 = Row[0][3]; tmp2 = Row[2][3]; - Row[0][3] = (float)( c*tmp1 + s*tmp2); - Row[2][3] = (float)(-s*tmp1 + c*tmp2); -} - -/*********************************************************************************************** - * M3DC::Pre_Rotate_Z -- Pre-multiplies the matrix by a rotation about Z * - * * - * INPUT: * - * s - sine of the angle to rotate * - * c - cosine of the angle to rotate * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 07/1/1999 NH : Created. * - *=============================================================================================*/ -WWINLINE void Matrix3D::Pre_Rotate_Z(float s,float c) -{ - float tmp1,tmp2; - - tmp1 = Row[0][0]; tmp2 = Row[1][0]; - Row[0][0] = (float)(c*tmp1 - s*tmp2); - Row[1][0] = (float)(s*tmp1 + c*tmp2); - - tmp1 = Row[0][1]; tmp2 = Row[1][1]; - Row[0][1] = (float)(c*tmp1 - s*tmp2); - Row[1][1] = (float)(s*tmp1 + c*tmp2); - - tmp1 = Row[0][2]; tmp2 = Row[1][2]; - Row[0][2] = (float)(c*tmp1 - s*tmp2); - Row[1][2] = (float)(s*tmp1 + c*tmp2); - - tmp1 = Row[0][3]; tmp2 = Row[1][3]; - Row[0][3] = (float)(c*tmp1 - s*tmp2); - Row[1][3] = (float)(s*tmp1 + c*tmp2); -} - -/*********************************************************************************************** - * M3DC::In_Place_Pre_Rotate_X -- Pre-multiplies rotation part of matrix by a rotation about X * - * * - * INPUT: * - * theta - angle (in radians) to rotate * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 07/1/1999 NH : Created. * - *=============================================================================================*/ -WWINLINE void Matrix3D::In_Place_Pre_Rotate_X(float theta) -{ - float tmp1,tmp2; - float c,s; - - c = cosf(theta); - s = sinf(theta); - - tmp1 = Row[1][0]; tmp2 = Row[2][0]; - Row[1][0] = (float)(c*tmp1 - s*tmp2); - Row[2][0] = (float)(s*tmp1 + c*tmp2); - - tmp1 = Row[1][1]; tmp2 = Row[2][1]; - Row[1][1] = (float)(c*tmp1 - s*tmp2); - Row[2][1] = (float)(s*tmp1 + c*tmp2); - - tmp1 = Row[1][2]; tmp2 = Row[2][2]; - Row[1][2] = (float)(c*tmp1 - s*tmp2); - Row[2][2] = (float)(s*tmp1 + c*tmp2); -} - -/*********************************************************************************************** - * M3DC::In_Place_Pre_Rotate_Y -- Pre-multiplies rotation part of matrix by a rotation about Y * - * * - * INPUT: * - * theta - angle (in radians) to rotate * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 07/1/1999 NH : Created. * - *=============================================================================================*/ -WWINLINE void Matrix3D::In_Place_Pre_Rotate_Y(float theta) -{ - float tmp1,tmp2; - float c,s; - - c = cosf(theta); - s = sinf(theta); - - tmp1 = Row[0][0]; tmp2 = Row[2][0]; - Row[0][0] = (float)( c*tmp1 + s*tmp2); - Row[2][0] = (float)(-s*tmp1 + c*tmp2); - - tmp1 = Row[0][1]; tmp2 = Row[2][1]; - Row[0][1] = (float)( c*tmp1 + s*tmp2); - Row[2][1] = (float)(-s*tmp1 + c*tmp2); - - tmp1 = Row[0][2]; tmp2 = Row[2][2]; - Row[0][2] = (float)( c*tmp1 + s*tmp2); - Row[2][2] = (float)(-s*tmp1 + c*tmp2); -} - -/*********************************************************************************************** - * M3DC::In_Place_Pre_Rotate_Z -- Pre-multiplies rotation part of matrix by a rotation about Z * - * * - * INPUT: * - * theta - angle (in radians) to rotate * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 07/1/1999 NH : Created. * - *=============================================================================================*/ -WWINLINE void Matrix3D::In_Place_Pre_Rotate_Z(float theta) -{ - float tmp1,tmp2; - float c,s; - - c = cosf(theta); - s = sinf(theta); - - tmp1 = Row[0][0]; tmp2 = Row[1][0]; - Row[0][0] = (float)(c*tmp1 - s*tmp2); - Row[1][0] = (float)(s*tmp1 + c*tmp2); - - tmp1 = Row[0][1]; tmp2 = Row[1][1]; - Row[0][1] = (float)(c*tmp1 - s*tmp2); - Row[1][1] = (float)(s*tmp1 + c*tmp2); - - tmp1 = Row[0][2]; tmp2 = Row[1][2]; - Row[0][2] = (float)(c*tmp1 - s*tmp2); - Row[1][2] = (float)(s*tmp1 + c*tmp2); -} - -/*********************************************************************************************** - * M3DC::In_Place_Pre_Rotate_X -- Pre-multiplies rotation part of matrix by a rotation about X * - * * - * INPUT: * - * s - sine of the angle to rotate * - * c - cosine of the angle to rotate * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 07/1/1999 NH : Created. * - *=============================================================================================*/ -WWINLINE void Matrix3D::In_Place_Pre_Rotate_X(float s,float c) -{ - float tmp1,tmp2; - - tmp1 = Row[1][0]; tmp2 = Row[2][0]; - Row[1][0] = (float)(c*tmp1 - s*tmp2); - Row[2][0] = (float)(s*tmp1 + c*tmp2); - - tmp1 = Row[1][1]; tmp2 = Row[2][1]; - Row[1][1] = (float)(c*tmp1 - s*tmp2); - Row[2][1] = (float)(s*tmp1 + c*tmp2); - - tmp1 = Row[1][2]; tmp2 = Row[2][2]; - Row[1][2] = (float)(c*tmp1 - s*tmp2); - Row[2][2] = (float)(s*tmp1 + c*tmp2); -} - -/*********************************************************************************************** - * M3DC::In_Place_Pre_Rotate_Y -- Pre-multiplies rotation part of matrix by a rotation about Y * - * * - * INPUT: * - * s - sine of the angle to rotate * - * c - cosine of the angle to rotate * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 07/1/1999 NH : Created. * - *=============================================================================================*/ -WWINLINE void Matrix3D::In_Place_Pre_Rotate_Y(float s,float c) -{ - float tmp1,tmp2; - - tmp1 = Row[0][0]; tmp2 = Row[2][0]; - Row[0][0] = (float)( c*tmp1 + s*tmp2); - Row[2][0] = (float)(-s*tmp1 + c*tmp2); - - tmp1 = Row[0][1]; tmp2 = Row[2][1]; - Row[0][1] = (float)( c*tmp1 + s*tmp2); - Row[2][1] = (float)(-s*tmp1 + c*tmp2); - - tmp1 = Row[0][2]; tmp2 = Row[2][2]; - Row[0][2] = (float)( c*tmp1 + s*tmp2); - Row[2][2] = (float)(-s*tmp1 + c*tmp2); -} - -/*********************************************************************************************** - * M3DC::In_Place_Pre_Rotate_Z -- Pre-multiplies rotation part of matrix by a rotation about Z * - * * - * INPUT: * - * s - sine of the angle to rotate * - * c - cosine of the angle to rotate * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 07/1/1999 NH : Created. * - *=============================================================================================*/ -WWINLINE void Matrix3D::In_Place_Pre_Rotate_Z(float s,float c) -{ - float tmp1,tmp2; - - tmp1 = Row[0][0]; tmp2 = Row[1][0]; - Row[0][0] = (float)(c*tmp1 - s*tmp2); - Row[1][0] = (float)(s*tmp1 + c*tmp2); - - tmp1 = Row[0][1]; tmp2 = Row[1][1]; - Row[0][1] = (float)(c*tmp1 - s*tmp2); - Row[1][1] = (float)(s*tmp1 + c*tmp2); - - tmp1 = Row[0][2]; tmp2 = Row[1][2]; - Row[0][2] = (float)(c*tmp1 - s*tmp2); - Row[1][2] = (float)(s*tmp1 + c*tmp2); -} - -#ifdef ALLOW_TEMPORARIES -/*********************************************************************************************** - * operator * -- Matrix multiplication * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 02/24/1997 GH : Created. * - *=============================================================================================*/ -WWINLINE Matrix3D operator * (const Matrix3D &A,const Matrix3D &B) -{ - Matrix3D C; - float tmp1,tmp2,tmp3; - - tmp1 = B[0][0]; - tmp2 = B[1][0]; - tmp3 = B[2][0]; - - C[0][0] = (float)(A[0][0]*tmp1 + A[0][1]*tmp2 + A[0][2]*tmp3); - C[1][0] = (float)(A[1][0]*tmp1 + A[1][1]*tmp2 + A[1][2]*tmp3); - C[2][0] = (float)(A[2][0]*tmp1 + A[2][1]*tmp2 + A[2][2]*tmp3); - - tmp1 = B[0][1]; - tmp2 = B[1][1]; - tmp3 = B[2][1]; - - C[0][1] = (float)(A[0][0]*tmp1 + A[0][1]*tmp2 + A[0][2]*tmp3); - C[1][1] = (float)(A[1][0]*tmp1 + A[1][1]*tmp2 + A[1][2]*tmp3); - C[2][1] = (float)(A[2][0]*tmp1 + A[2][1]*tmp2 + A[2][2]*tmp3); - - tmp1 = B[0][2]; - tmp2 = B[1][2]; - tmp3 = B[2][2]; - - C[0][2] = (float)(A[0][0]*tmp1 + A[0][1]*tmp2 + A[0][2]*tmp3); - C[1][2] = (float)(A[1][0]*tmp1 + A[1][1]*tmp2 + A[1][2]*tmp3); - C[2][2] = (float)(A[2][0]*tmp1 + A[2][1]*tmp2 + A[2][2]*tmp3); - - tmp1 = B[0][3]; - tmp2 = B[1][3]; - tmp3 = B[2][3]; - - C[0][3] = (float)(A[0][0]*tmp1 + A[0][1]*tmp2 + A[0][2]*tmp3 + A[0][3]); - C[1][3] = (float)(A[1][0]*tmp1 + A[1][1]*tmp2 + A[1][2]*tmp3 + A[1][3]); - C[2][3] = (float)(A[2][0]*tmp1 + A[2][1]*tmp2 + A[2][2]*tmp3 + A[2][3]); - - return C; -} - -#else - -WWINLINE float submul(const Vector4& row, float tmp1, float tmp2, float tmp3) -{ - return row.X * tmp1 + row.Y * tmp2 + row.Z * tmp3; -} - -// does "this = that * this" -WWINLINE void Matrix3D::preMul(const Matrix3D& that) -{ - assert(this != &that); - - // yes, this is ok. see the comments for 'mul' - this->mul(that, *this); -} - -// does "this = this * that" -WWINLINE void Matrix3D::postMul(const Matrix3D& that) -{ - assert(this != &that); - -#define AVOID_TEMP_IN_POSTMUL -#ifdef AVOID_TEMP_IN_POSTMUL - float tmpX, tmpY, tmpZ, tmpW; - - tmpX = submul(this->Row[0], that.Row[0].X, that.Row[1].X, that.Row[2].X); - tmpY = submul(this->Row[0], that.Row[0].Y, that.Row[1].Y, that.Row[2].Y); - tmpZ = submul(this->Row[0], that.Row[0].Z, that.Row[1].Z, that.Row[2].Z); - tmpW = submul(this->Row[0], that.Row[0].W, that.Row[1].W, that.Row[2].W); - - this->Row[0].X = tmpX; - this->Row[0].Y = tmpY; - this->Row[0].Z = tmpZ; - this->Row[0].W += tmpW; - - tmpX = submul(this->Row[1], that.Row[0].X, that.Row[1].X, that.Row[2].X); - tmpY = submul(this->Row[1], that.Row[0].Y, that.Row[1].Y, that.Row[2].Y); - tmpZ = submul(this->Row[1], that.Row[0].Z, that.Row[1].Z, that.Row[2].Z); - tmpW = submul(this->Row[1], that.Row[0].W, that.Row[1].W, that.Row[2].W); - - this->Row[1].X = tmpX; - this->Row[1].Y = tmpY; - this->Row[1].Z = tmpZ; - this->Row[1].W += tmpW; - - tmpX = submul(this->Row[2], that.Row[0].X, that.Row[1].X, that.Row[2].X); - tmpY = submul(this->Row[2], that.Row[0].Y, that.Row[1].Y, that.Row[2].Y); - tmpZ = submul(this->Row[2], that.Row[0].Z, that.Row[1].Z, that.Row[2].Z); - tmpW = submul(this->Row[2], that.Row[0].W, that.Row[1].W, that.Row[2].W); - - this->Row[2].X = tmpX; - this->Row[2].Y = tmpY; - this->Row[2].Z = tmpZ; - this->Row[2].W += tmpW; -#else - Matrix3D tmp = *this; - this->mul(tmp, that); -#endif -} - -// does "this = A * B" -WWINLINE void Matrix3D::mul(const Matrix3D& A, const Matrix3D& B) -{ - assert(this != &A); - //assert(this != &B); - // nope, this is actually ok. (srj) - //assert(this != &B); - - float tmp1,tmp2,tmp3; - - tmp1 = B.Row[0].X; - tmp2 = B.Row[1].X; - tmp3 = B.Row[2].X; - - this->Row[0].X = submul(A.Row[0], tmp1, tmp2, tmp3); - this->Row[1].X = submul(A.Row[1], tmp1, tmp2, tmp3); - this->Row[2].X = submul(A.Row[2], tmp1, tmp2, tmp3); - - tmp1 = B.Row[0].Y; - tmp2 = B.Row[1].Y; - tmp3 = B.Row[2].Y; - - this->Row[0].Y = submul(A.Row[0], tmp1, tmp2, tmp3); - this->Row[1].Y = submul(A.Row[1], tmp1, tmp2, tmp3); - this->Row[2].Y = submul(A.Row[2], tmp1, tmp2, tmp3); - - tmp1 = B.Row[0].Z; - tmp2 = B.Row[1].Z; - tmp3 = B.Row[2].Z; - - this->Row[0].Z = submul(A.Row[0], tmp1, tmp2, tmp3); - this->Row[1].Z = submul(A.Row[1], tmp1, tmp2, tmp3); - this->Row[2].Z = submul(A.Row[2], tmp1, tmp2, tmp3); - - tmp1 = B.Row[0].W; - tmp2 = B.Row[1].W; - tmp3 = B.Row[2].W; - - this->Row[0].W = submul(A.Row[0], tmp1, tmp2, tmp3) + A.Row[0].W; - this->Row[1].W = submul(A.Row[1], tmp1, tmp2, tmp3) + A.Row[1].W; - this->Row[2].W = submul(A.Row[2], tmp1, tmp2, tmp3) + A.Row[2].W; -} - -#endif - -#ifdef ALLOW_TEMPORARIES -/*********************************************************************************************** - * operator * -- Matrix - vector multiplication * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 02/24/1997 GH : Created. * - *=============================================================================================*/ -WWINLINE Vector3 operator * (const Matrix3D &A,const Vector3 &a) -{ -#if 0 - return Vector3 - ( - (A[0][0]*a[0] + A[0][1]*a[1] + A[0][2]*a[2] + A[0][3]), - (A[1][0]*a[0] + A[1][1]*a[1] + A[1][2]*a[2] + A[1][3]), - (A[2][0]*a[0] + A[2][1]*a[1] + A[2][2]*a[2] + A[2][3]) - ); -#else - return Vector3 - ( - (A.Row[0].X*a.X + A.Row[0].Y*a.Y + A.Row[0].Z*a.Z + A.Row[0].W), - (A.Row[1].X*a.X + A.Row[1].Y*a.Y + A.Row[1].Z*a.Z + A.Row[1].W), - (A.Row[2].X*a.X + A.Row[2].Y*a.Y + A.Row[2].Z*a.Z + A.Row[2].W) - ); -#endif -} - -#else - -WWINLINE void Matrix3D::mulVector3(const Vector3& in, Vector3& out) const -{ - // note, it's ok for in==out here. - float x = (Row[0].X * in.X + Row[0].Y * in.Y + Row[0].Z * in.Z + Row[0].W); - float y = (Row[1].X * in.X + Row[1].Y * in.Y + Row[1].Z * in.Z + Row[1].W); - float z = (Row[2].X * in.X + Row[2].Y * in.Y + Row[2].Z * in.Z + Row[2].W); - out.Set(x, y, z); -} - -#endif - -WWINLINE void Matrix3D::mulVector3Array(const Vector3* in, Vector3* out, int count) const -{ - assert(in != out); -#ifdef ALLOW_TEMPORARIES - for (int i=0; iX = (Row[0].X * in->X + Row[0].Y * in->Y + Row[0].Z * in->Z + Row[0].W); - out->Y = (Row[1].X * in->X + Row[1].Y * in->Y + Row[1].Z * in->Z + Row[1].W); - out->Z = (Row[2].X * in->X + Row[2].Y * in->Y + Row[2].Z * in->Z + Row[2].W); - ++in; - ++out; - } -#endif -} - -WWINLINE void Matrix3D::mulVector3Array(Vector3* inout, int count) const -{ -#ifdef ALLOW_TEMPORARIES - for (int i=0; iX + Row[0].Y * inout->Y + Row[0].Z * inout->Z + Row[0].W); - float y = (Row[1].X * inout->X + Row[1].Y * inout->Y + Row[1].Z * inout->Z + Row[1].W); - float z = (Row[2].X * inout->X + Row[2].Y * inout->Y + Row[2].Z * inout->Z + Row[2].W); - inout->Set(x, y, z); - ++inout; - } -#endif -} - -/*********************************************************************************************** - * operator == -- Matrix equality operator * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 04/29/1998 NH : Created. * - *=============================================================================================*/ -WWINLINE bool operator == (const Matrix3D &A, const Matrix3D &B) -{ - for (int i = 0; i < 3; i++) { - for (int j = 0; j < 4; j++) { - if (A[i][j] != B[i][j]) return false; - } - } - return true; -} - - -/*********************************************************************************************** - * operator != -- Matrix inequality operator * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 04/29/1998 NH : Created. * - *=============================================================================================*/ -WWINLINE bool operator != (const Matrix3D &A, const Matrix3D &B) -{ - return !(A == B); -} - - -WWINLINE void Matrix3D::Transform_Vector(const Matrix3D & A,const Vector3 & in,Vector3 * out) -{ - Vector3 tmp; - Vector3 * v; - - // check for aliased parameters - if (out == &in) { - tmp = in; - v = &tmp; - } else { - v = (Vector3 *)∈ // whats the right way to do this... - } - - out->X = (A[0][0] * v->X + A[0][1] * v->Y + A[0][2] * v->Z + A[0][3]); - out->Y = (A[1][0] * v->X + A[1][1] * v->Y + A[1][2] * v->Z + A[1][3]); - out->Z = (A[2][0] * v->X + A[2][1] * v->Y + A[2][2] * v->Z + A[2][3]); -} - -WWINLINE void Matrix3D::Rotate_Vector(const Matrix3D & A,const Vector3 & in,Vector3 * out) -{ - Vector3 tmp; - Vector3 * v; - - // check for aliased parameters - if (out == &in) { - tmp = in; - v = &tmp; - } else { - v = (Vector3 *)∈ - } - - out->X = (A[0][0] * v->X + A[0][1] * v->Y + A[0][2] * v->Z); - out->Y = (A[1][0] * v->X + A[1][1] * v->Y + A[1][2] * v->Z); - out->Z = (A[2][0] * v->X + A[2][1] * v->Y + A[2][2] * v->Z); -} - -WWINLINE void Matrix3D::Inverse_Transform_Vector(const Matrix3D & A,const Vector3 & in,Vector3 * out) -{ - Vector3 tmp; - Vector3 * v; - - // check for aliased parameters - if (out == &in) { - tmp = in; - v = &tmp; - } else { - v = (Vector3 *)∈ // whats the right way to do this... - } - - Vector3 diff(v->X - A[0][3], v->Y - A[1][3], v->Z - A[2][3]); - Matrix3D::Inverse_Rotate_Vector(A, diff, out); -} - -WWINLINE void Matrix3D::Inverse_Rotate_Vector(const Matrix3D & A,const Vector3 & in,Vector3 * out) -{ - Vector3 tmp; - Vector3 * v; - - // check for aliased parameters - if (out == &in) { - tmp = in; - v = &tmp; - } else { - v = (Vector3 *)∈ - } - out->X = (A[0][0] * v->X + A[1][0] * v->Y + A[2][0] * v->Z); - out->Y = (A[0][1] * v->X + A[1][1] * v->Y + A[2][1] * v->Z); - out->Z = (A[0][2] * v->X + A[1][2] * v->Y + A[2][2] * v->Z); -} - -class DynamicMatrix3D : public W3DMPO -{ - W3DMPO_GLUE(DynamicMatrix3D) -public: - Matrix3D Mat; -}; -#endif /* MATRIX3D_H */ diff --git a/Generals/Code/Libraries/Source/WWVegas/WWMath/matrix4.cpp b/Generals/Code/Libraries/Source/WWVegas/WWMath/matrix4.cpp deleted file mode 100644 index 72fdf245fe3..00000000000 --- a/Generals/Code/Libraries/Source/WWVegas/WWMath/matrix4.cpp +++ /dev/null @@ -1,197 +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 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 : WWMath * - * * - * $Archive:: /Commando/Code/wwmath/matrix4.cpp $* - * * - * Org Author:: Greg_h * - * * - * Author : Kenny_m * - * * - * $Modtime:: 06/26/02 4:04p $* - * * - * $Revision:: 6 $* - * * - * 06/26/02 KM Matrix name change to avoid MAX conflicts * - *---------------------------------------------------------------------------------------------* - * Functions: * - * Matrix4x4::Multiply -- Multiply two Matrix4x4's together * - * Matrix4x4::Multiply -- Multiply a Matrix3D * Matrix4x4 * - * Matrix4x4::Multiply -- Multiply a Matrix4x4 * Matrix3D * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - -#include "matrix4.h" -#include - -/*********************************************************************************************** - * Matrix4x4::Multiply -- Multiply two Matrix4x4's together * - * * - * INPUT: * - * a - first operand * - * b - second operand * - * res - pointer to matrix to store the result in (must not point to a or b) * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 11/13/99 gth : Created. * - *=============================================================================================*/ -void Matrix4x4::Multiply(const Matrix4x4 &a,const Matrix4x4 &b,Matrix4x4 * res) -{ - assert(res != &a); - assert(res != &b); - - #define ROWCOL(i,j) a[i][0]*b[0][j] + a[i][1]*b[1][j] + a[i][2]*b[2][j] + a[i][3]*b[3][j] - - (*res)[0][0] = ROWCOL(0,0); - (*res)[0][1] = ROWCOL(0,1); - (*res)[0][2] = ROWCOL(0,2); - (*res)[0][3] = ROWCOL(0,3); - - (*res)[1][0] = ROWCOL(1,0); - (*res)[1][1] = ROWCOL(1,1); - (*res)[1][2] = ROWCOL(1,2); - (*res)[1][3] = ROWCOL(1,3); - - (*res)[2][0] = ROWCOL(2,0); - (*res)[2][1] = ROWCOL(2,1); - (*res)[2][2] = ROWCOL(2,2); - (*res)[2][3] = ROWCOL(2,3); - - (*res)[3][0] = ROWCOL(3,0); - (*res)[3][1] = ROWCOL(3,1); - (*res)[3][2] = ROWCOL(3,2); - (*res)[3][3] = ROWCOL(3,3); - - #undef ROWCOL -} - - -/*********************************************************************************************** - * Matrix4x4::Multiply -- Multiply a Matrix3D * Matrix4x4 * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 11/13/99 gth : Created. * - *=============================================================================================*/ -void Matrix4x4::Multiply(const Matrix3D &a,const Matrix4x4 &b,Matrix4x4 * res) -{ - assert(res != &b); - - #define ROWCOL(i,j) a[i][0]*b[0][j] + a[i][1]*b[1][j] + a[i][2]*b[2][j] + a[i][3]*b[3][j] - - (*res)[0][0] = ROWCOL(0,0); - (*res)[0][1] = ROWCOL(0,1); - (*res)[0][2] = ROWCOL(0,2); - (*res)[0][3] = ROWCOL(0,3); - - (*res)[1][0] = ROWCOL(1,0); - (*res)[1][1] = ROWCOL(1,1); - (*res)[1][2] = ROWCOL(1,2); - (*res)[1][3] = ROWCOL(1,3); - - (*res)[2][0] = ROWCOL(2,0); - (*res)[2][1] = ROWCOL(2,1); - (*res)[2][2] = ROWCOL(2,2); - (*res)[2][3] = ROWCOL(2,3); - - (*res)[3][0] = b[3][0]; // last row of a is 0,0,0,1 - (*res)[3][1] = b[3][1]; // this leaves the last row of b unchanged - (*res)[3][2] = b[3][2]; - (*res)[3][3] = b[3][3]; - - #undef ROWCOL -} - - -/*********************************************************************************************** - * Matrix4x4::Multiply -- Multiply a Matrix4x4 * Matrix3D * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - *=============================================================================================*/ -void Matrix4x4::Multiply(const Matrix4x4 & a,const Matrix3D & b,Matrix4x4 * res) -{ - assert(res != &a); - - // ROWCOL multiplies a row of 'a' by one of the first three columns of 'b' (4th entry in b is zero) - // ROWCOL4 multiplies a row of 'a' by the fourth column of 'b' (4th entry in b is one) - - #define ROWCOL(i,j) a[i][0]*b[0][j] + a[i][1]*b[1][j] + a[i][2]*b[2][j] - #define ROWCOL4(i,j) a[i][0]*b[0][j] + a[i][1]*b[1][j] + a[i][2]*b[2][j] + a[i][3] - - (*res)[0][0] = ROWCOL(0,0); - (*res)[0][1] = ROWCOL(0,1); - (*res)[0][2] = ROWCOL(0,2); - (*res)[0][3] = ROWCOL4(0,3); - - (*res)[1][0] = ROWCOL(1,0); - (*res)[1][1] = ROWCOL(1,1); - (*res)[1][2] = ROWCOL(1,2); - (*res)[1][3] = ROWCOL4(1,3); - - (*res)[2][0] = ROWCOL(2,0); - (*res)[2][1] = ROWCOL(2,1); - (*res)[2][2] = ROWCOL(2,2); - (*res)[2][3] = ROWCOL4(2,3); - - (*res)[3][0] = ROWCOL(3,0); - (*res)[3][1] = ROWCOL(3,1); - (*res)[3][2] = ROWCOL(3,2); - (*res)[3][3] = ROWCOL4(3,3); - - #undef ROWCOL - #undef ROWCOL4 -} - -int operator == (const Matrix4x4 & a, const Matrix4x4 & b) -{ - unsigned* m1=(unsigned*)&a; - unsigned* m2=(unsigned*)&b; - unsigned res=0; - for (int i=0;i<4;++i) { - res|=*m1++^*m2++; - res|=*m1++^*m2++; - res|=*m1++^*m2++; - res|=*m1++^*m2++; - } - return !res; -} - -int operator != (const Matrix4x4 & a, const Matrix4x4 & b) -{ - return (!(a == b)); -} - diff --git a/Generals/Code/Libraries/Source/WWVegas/WWMath/matrix4.h b/Generals/Code/Libraries/Source/WWVegas/WWMath/matrix4.h deleted file mode 100644 index b062816479d..00000000000 --- a/Generals/Code/Libraries/Source/WWVegas/WWMath/matrix4.h +++ /dev/null @@ -1,848 +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 . -*/ - -/* $Header: /Commando/Code/wwmath/matrix4.h 20 10/04/01 10:33a Greg_h $ */ -/*********************************************************************************************** - *** Confidential - Westwood Studios *** - *********************************************************************************************** - * * - * Project Name : WW3D * - * * - * File Name : MATRIX4.H * - * * - * Org Programmer : Greg Hjelstrom * - * * - * Author : Kenny Mitchell * - * * - * Start Date : 06/02/97 * - * * - * Last Update : June 6, 2002 [KM] * - * * - * 06/26/02 KM Matrix name change to avoid MAX conflicts * - *---------------------------------------------------------------------------------------------* - * Functions: * - * Matrix4x4::Matrix4x4 -- Constructor, optionally initialize to Identitiy matrix * - * Matrix4x4::Matrix4x4 -- Copy Constructor * - * Matrix4x4::Matrix4x4 -- Convert a Matrix3D (fake 4x4) to a Matrix4x4 * - * Matrix4x4::Matrix4x4 -- Constructor * - * Matrix4x4::Make_Identity -- Initializes the matrix to Identity * - * Matrix4x4::Init -- Initializes from the contents of the give Matrix3D * - * Matrix4x4::Init -- Initializes the rows from the given Vector4s * - * Matrix4x4::Init -- Initializes the rows from the given 16 floats * - * Matrix4x4::Init_Ortho -- Initialize to an orthographic projection matrix * - * Matrix4x4::Init_Perspective -- Initialize to a perspective projection matrix * - * Matrix4x4::Init_Perspective -- Initialize to a perspective projection matrix * - * Matrix4x4::Transpose -- Returns transpose of the matrix * - * Matrix4x4::Inverse -- returns the inverse of the matrix * - * Matrix4x4::operator = -- assignment operator * - * Matrix4x4::operator += -- "plus equals" operator * - * Matrix4x4::operator -= -- "minus equals" operator * - * Matrix4x4::operator *= -- "times equals" operator * - * Matrix4x4::operator /= -- "divide equals" operator * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - - -#if defined(_MSC_VER) -#pragma once -#endif - - -#ifndef MATRIX4_H -#define MATRIX4_H - -#include "always.h" -#include "vector4.h" -#include "matrix3d.h" -#include "matrix3.h" - - -class Matrix4x4 -{ -public: - - /* - ** Constructors - */ - Matrix4x4(void) {}; - Matrix4x4(const Matrix4x4 & m); - - WWINLINE explicit Matrix4x4(bool identity); - WWINLINE explicit Matrix4x4(const Matrix3D & m); - WWINLINE explicit Matrix4x4(const Matrix3x3 & m); - WWINLINE explicit Matrix4x4(const Vector4 & v0, const Vector4 & v1, const Vector4 & v2, const Vector4 & v3); - WWINLINE explicit Matrix4x4( float m11,float m12,float m13,float m14, - float m21,float m22,float m23,float m24, - float m31,float m32,float m33,float m34, - float m41,float m42,float m43,float m44 ); - - WWINLINE void Make_Identity(void); - WWINLINE void Init(const Matrix3D & m); - WWINLINE void Init(const Matrix3x3 & m); - WWINLINE void Init(const Vector4 & v0, const Vector4 & v1, const Vector4 & v2, const Vector4 & v3); - WWINLINE void Init( float m11,float m12,float m13,float m14, - float m21,float m22,float m23,float m24, - float m31,float m32,float m33,float m34, - float m41,float m42,float m43,float m44 ); - - /* - ** Projection matrices. The znear and zfar parameters are positive values indicating the - ** distance from the camera to the z clipping planes. See implementations for more info. - */ - WWINLINE void Init_Ortho(float left,float right,float bottom,float top,float znear,float zfar); - WWINLINE void Init_Perspective(float hfov,float vfov,float znear,float zfar); - WWINLINE void Init_Perspective(float left,float right,float bottom,float top,float znear,float zfar); - - /* - ** Access operators - */ - WWINLINE Vector4 & operator [] (int i) { return Row[i]; } - WWINLINE const Vector4 & operator [] (int i) const { return Row[i]; } - - /* - ** Transpose and Inverse - */ - WWINLINE Matrix4x4 Transpose(void) const; - WWINLINE Matrix4x4 Inverse(void) const; - - /* - ** Assignment operators - */ - WWINLINE Matrix4x4 & operator = (const Matrix4x4 & m); - WWINLINE Matrix4x4 & operator += (const Matrix4x4 & m); - WWINLINE Matrix4x4 & operator -= (const Matrix4x4 & m); - WWINLINE Matrix4x4 & operator *= (float d); - WWINLINE Matrix4x4 & operator /= (float d); - - /* - ** Negation - */ - WWINLINE friend Matrix4x4 operator - (const Matrix4x4& a); - - /* - ** Scalar multiplication and division - */ - WWINLINE friend Matrix4x4 operator * (const Matrix4x4& a,float d); - WWINLINE friend Matrix4x4 operator * (float d,const Matrix4x4& a); - WWINLINE friend Matrix4x4 operator / (const Matrix4x4& a,float d); - - /* - ** matrix addition - */ - WWINLINE friend Matrix4x4 operator + (const Matrix4x4& a, const Matrix4x4& b); - WWINLINE friend Matrix4x4 Add(const Matrix4x4& a); - - /* - ** matrix subtraction - */ - WWINLINE friend Matrix4x4 operator - (const Matrix4x4 & a, const Matrix4x4 & b); - WWINLINE friend Matrix4x4 Subtract(const Matrix4x4 & a, const Matrix4x4 & b); - - /* - ** matrix multiplication - */ - WWINLINE friend Matrix4x4 operator * (const Matrix4x4 & a, const Matrix4x4 & b); - WWINLINE friend Matrix4x4 Multiply(const Matrix4x4 & a, const Matrix4x4 & b); - WWINLINE friend Matrix4x4 operator * (const Matrix4x4 & a, const Matrix3D & b); - WWINLINE friend Matrix4x4 operator * (const Matrix3D & a, const Matrix4x4 & b); - - /* - ** Comparison operators - */ - friend int operator == (const Matrix4x4 & a, const Matrix4x4 & b); - friend int operator != (const Matrix4x4 & a, const Matrix4x4 & b); - - /* - ** Swap two matrices in place - */ - WWINLINE friend void Swap(Matrix4x4 & a,Matrix4x4 & b); - - /* - ** Linear Transforms - */ - WWINLINE friend Vector4 operator * (const Matrix4x4 & a, const Vector4 & v); - WWINLINE friend Vector4 operator * (const Matrix4x4 & a, const Vector3 & v); - - /* - ** Matrix multiplication without temporaries... - */ - static void Multiply(const Matrix4x4 &A,const Matrix4x4 &B,Matrix4x4 * set_result); - static void Multiply(const Matrix3D &A,const Matrix4x4 &B,Matrix4x4 * set_result); - static void Multiply(const Matrix4x4 &A,const Matrix3D &B,Matrix4x4 * set_result); - - static WWINLINE void Transform_Vector(const Matrix4x4 & tm,const Vector3 & in,Vector3 * out); - static WWINLINE void Transform_Vector(const Matrix4x4 & tm,const Vector3 & in,Vector4 * out); - static WWINLINE void Transform_Vector(const Matrix4x4 & tm,const Vector4 & in,Vector4 * out); - -protected: - - Vector4 Row[4]; - -}; - - -/*********************************************************************************************** - * Matrix4x4::Matrix4x4 -- Constructor, optionally initialize to Identitiy matrix * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 06/02/1997 GH : Created. * - *=============================================================================================*/ -WWINLINE Matrix4x4::Matrix4x4(bool identity) -{ - if (identity) { - Make_Identity(); - } -} - -/*********************************************************************************************** - * Matrix4x4::Matrix4x4 -- Copy Constructor * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 06/02/1997 GH : Created. * - *=============================================================================================*/ -WWINLINE Matrix4x4::Matrix4x4(const Matrix4x4 & m) -{ - Row[0] = m.Row[0]; Row[1] = m.Row[1]; Row[2] = m.Row[2]; Row[3] = m.Row[3]; -} - -/*********************************************************************************************** - * Matrix4x4::Matrix4x4 -- Convert a Matrix3D (fake 4x4) to a Matrix4x4 * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 06/02/1997 GH : Created. * - *=============================================================================================*/ -WWINLINE Matrix4x4::Matrix4x4(const Matrix3D & m) -{ - Init(m); -} - -/*********************************************************************************************** - * Matrix4x4::Matrix4x4 -- Constructor * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 06/02/1997 GH : Created. * - *=============================================================================================*/ -WWINLINE Matrix4x4::Matrix4x4(const Vector4 & r0, const Vector4 & r1, const Vector4 & r2, const Vector4 & r3) -{ - Init(r0,r1,r2,r3); -} - -/*********************************************************************************************** - * Matrix4x4::Matrix4x4 -- Constructor * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 11/06/2001 NH : Created. * - *=============================================================================================*/ -WWINLINE Matrix4x4::Matrix4x4(float m11,float m12,float m13,float m14, float m21,float m22,float m23,float m24, - float m31,float m32,float m33,float m34, float m41,float m42,float m43,float m44 ) -{ - Init(m11, m12, m13, m14, m21, m22, m23, m24, m31, m32, m33, m34, m41, m42, m43, m44); -} - -/*********************************************************************************************** - * Matrix4x4::Make_Identity -- Initializes the matrix to Identity * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 11/5/99 gth : Created. * - *=============================================================================================*/ -WWINLINE void Matrix4x4::Make_Identity(void) -{ - Row[0].Set(1.0,0.0,0.0,0.0); - Row[1].Set(0.0,1.0,0.0,0.0); - Row[2].Set(0.0,0.0,1.0,0.0); - Row[3].Set(0.0,0.0,0.0,1.0); -} - - -/*********************************************************************************************** - * Matrix4x4::Init -- Initializes from the contents of the give Matrix3D * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 11/5/99 gth : Created. * - *=============================================================================================*/ -WWINLINE void Matrix4x4::Init(const Matrix3D & m) -{ - Row[0] = m[0]; Row[1] = m[1]; Row[2] = m[2]; Row[3] = Vector4(0.0,0.0,0.0,1.0); -} - - -/*********************************************************************************************** - * Matrix4x4::Init -- Initializes the rows from the given Vector4s * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 11/5/99 gth : Created. * - *=============================================================================================*/ -WWINLINE void Matrix4x4::Init(const Vector4 & r0, const Vector4 & r1, const Vector4 & r2, const Vector4 & r3) -{ - Row[0] = r0; Row[1] = r1; Row[2] = r2; Row[3] = r3; -} - - -/*********************************************************************************************** - * Matrix4x4::Init -- Initializes the rows from the given 16 floats * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 11/6/01 NH : Created. * - *=============================================================================================*/ -WWINLINE void Matrix4x4::Init(float m11,float m12,float m13,float m14, float m21,float m22,float m23,float m24, - float m31,float m32,float m33,float m34, float m41,float m42,float m43,float m44) -{ - Row[0].Set(m11,m12,m13,m14); - Row[1].Set(m21,m22,m23,m24); - Row[2].Set(m31,m32,m33,m34); - Row[3].Set(m41,m42,m43,m44); -} - - -/*********************************************************************************************** - * Matrix4x4::Init_Ortho -- Initialize to an orthographic projection matrix * - * * - * You can find the formulas for this in the appendix of the OpenGL programming guide. Also * - * this happens to be the same convention used by Surrender. * - * * - * The result of this projection will be that points inside the volume will have all coords * - * between -1 and +1. A point at znear will project to z=-1. A point at zfar will project * - * to z=+1... * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * Note that the znear and zfar parameters are positive distances to the clipping planes * - * even though in the camera coordinate system, the clipping planes are at negative z * - * coordinates. This holds for all of the projection initializations and is consistent * - * with OpenGL's convention. * - * * - * HISTORY: * - * 11/5/99 gth : Created. * - *=============================================================================================*/ -WWINLINE void Matrix4x4::Init_Ortho -( - float left, - float right, - float bottom, - float top, - float znear, - float zfar -) -{ - assert(znear >= 0.0f); - assert(zfar > znear); - - Make_Identity(); - Row[0][0] = 2.0f / (right - left); - Row[0][3] = -(right + left) / (right - left); - Row[1][1] = 2.0f / (top - bottom); - Row[1][3] = -(top + bottom) / (top - bottom); - Row[2][2] = -2.0f / (zfar - znear); - Row[2][3] = -(zfar + znear) / (zfar - znear); -} - - -/*********************************************************************************************** - * Matrix4x4::Init_Perspective -- Initialize to a perspective projection matrix * - * * - * You can find the formulas for this matrix in the appendix of the OpenGL programming guide. * - * Also, this happens to be the same convention used by Surrender. * - * * - * The result of this projection will be that points inside the volume will have all coords * - * between -1 and +1. A point at znear will project to z=-1. A point at zfar will project * - * to z=+1... * - * * - * INPUT: * - * hfov - horizontal field of view (in radians) * - * vfov - vertical field of view (in radians) * - * znear - distance to near z clipping plane (positive) * - * zfar - distance to the far z clipping plane (positive) * - * * - * OUTPUT: * - * * - * WARNINGS: * - * Note that the znear and zfar parameters are positive distances to the clipping planes * - * even though in the camera coordinate system, the clipping planes are at negative z * - * coordinates. This holds for all of the projection initializations and is consistent * - * with OpenGL's convention. * - * * - * HISTORY: * - * 11/5/99 gth : Created. * - *=============================================================================================*/ -WWINLINE void Matrix4x4::Init_Perspective(float hfov,float vfov,float znear,float zfar) -{ - assert(znear > 0.0f); - assert(zfar > znear); - - Make_Identity(); - Row[0][0] = static_cast(1.0 / tan(hfov*0.5)); - Row[1][1] = static_cast(1.0 / tan(vfov*0.5)); - Row[2][2] = -(zfar + znear) / (zfar - znear); - Row[2][3] = static_cast(-(2.0*zfar*znear) / (zfar - znear)); - Row[3][2] = -1.0f; - Row[3][3] = 0.0f; -} - - -/*********************************************************************************************** - * Matrix4x4::Init_Perspective -- Initialize to a perspective projection matrix * - * * - * You can find the formulas for this matrix in the appendix of the OpenGL programming guide. * - * Also, this happens to be the same convention used by Surrender. * - * * - * The result of this projection will be that points inside the volume will have all coords * - * between -1 and +1. A point at znear will project to z=-1. A point at zfar will project * - * to z=+1... * - * * - * INPUT: * - * * - * left - min x coordinate of near clip plane * - * right - max x coordinate of near clip plane * - * bottom - min y coordinate of near clip plane * - * top - max y coordinate of near clip plane * - * znear - distance to near Z clipping plane * - * zfar - distance to far Z clipping plane * - * * - * OUTPUT: * - * * - * WARNINGS: * - * Note that the znear and zfar parameters are positive distances to the clipping planes * - * even though in the camera coordinate system, the clipping planes are at negative z * - * coordinates. This holds for all of the projection initializations and is consistent * - * with OpenGL's convention. * - * * - * HISTORY: * - * 11/5/99 gth : Created. * - *=============================================================================================*/ -WWINLINE void Matrix4x4::Init_Perspective -( - float left, - float right, - float bottom, - float top, - float znear, - float zfar -) -{ - assert(znear > 0.0f); - assert(zfar > 0.0f); - - Make_Identity(); - Row[0][0] = static_cast(2.0*znear / (right - left)); - Row[0][2] = (right + left) / (right - left); - Row[1][1] = static_cast(2.0*znear / (top - bottom)); - Row[1][2] = (top + bottom) / (top - bottom); - Row[2][2] = -(zfar + znear) / (zfar - znear); - Row[2][3] = static_cast(-(2.0*zfar*znear) / (zfar - znear)); - Row[3][2] = -1.0f; - Row[3][3] = 0.0f; -} - -/*********************************************************************************************** - * Matrix4x4::Transpose -- Returns transpose of the matrix * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 06/02/1997 GH : Created. * - *=============================================================================================*/ -WWINLINE Matrix4x4 Matrix4x4::Transpose() const -{ - return Matrix4x4( - Vector4(Row[0][0], Row[1][0], Row[2][0], Row[3][0]), - Vector4(Row[0][1], Row[1][1], Row[2][1], Row[3][1]), - Vector4(Row[0][2], Row[1][2], Row[2][2], Row[3][2]), - Vector4(Row[0][3], Row[1][3], Row[2][3], Row[3][3]) - ); -} - -/*********************************************************************************************** - * Matrix4x4::Inverse -- returns the inverse of the matrix * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 06/02/1997 GH : Created. * - *=============================================================================================*/ -WWINLINE Matrix4x4 Matrix4x4::Inverse() const // Gauss-Jordan elimination with partial pivoting -{ - WWASSERT_PRINT(0,"Matrix4x4::Inverse does not work, re-implement!"); - - Matrix4x4 a(*this); // As a evolves from original mat into identity - Matrix4x4 b(true); // b evolves from identity into inverse(a) - int i, j, i1; - - // Loop over cols of a from left to right, eliminating above and below diagonal - for (j=0; j<4; j++) { - - // Find largest pivot in column j among rows j..3 - i1 = j; - for (i=j+1; i<4; i++) { - if (WWMath::Fabs(a[i][j]) > WWMath::Fabs(a[i1][j])) { - i1 = i; - } - } - - // Swap rows i1 and j in a and b to put pivot on diagonal - Swap(a.Row[i1], a.Row[j]); - Swap(b.Row[i1], b.Row[j]); - - // Scale row j to have a unit diagonal - if (a[j][j]==0.) { - //ALGEBRA_ERROR("Matrix4x4::inverse: singular matrix; can't invert\n"); - } - b.Row[j] /= a.Row[j][j]; - a.Row[j] /= a.Row[j][j]; - - // Eliminate off-diagonal elems in col j of a, doing identical ops to b - for (i=0; i<4; i++) { - if (i != j) { - b.Row[i] -= a[i][j] * b.Row[j]; - a.Row[i] -= a[i][j] * a.Row[j]; - } - } - } - return b; -} - -/*********************************************************************************************** - * Matrix4x4::operator = -- assignment operator * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 06/02/1997 GH : Created. * - *=============================================================================================*/ -WWINLINE Matrix4x4 & Matrix4x4::operator = (const Matrix4x4 & m) -{ - Row[0] = m.Row[0]; Row[1] = m.Row[1]; Row[2] = m.Row[2]; Row[3] = m.Row[3]; - return *this; -} - -/*********************************************************************************************** - * Matrix4x4::operator += -- "plus equals" operator * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 06/02/1997 GH : Created. * - *=============================================================================================*/ -WWINLINE Matrix4x4& Matrix4x4::operator += (const Matrix4x4 & m) -{ - Row[0] += m.Row[0]; Row[1] += m.Row[1]; Row[2] += m.Row[2]; Row[3] += m.Row[3]; - return *this; -} - -/*********************************************************************************************** - * Matrix4x4::operator-= -- "minus equals" operator * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 06/02/1997 GH : Created. * - *=============================================================================================*/ -WWINLINE Matrix4x4& Matrix4x4::operator -= (const Matrix4x4 & m) -{ - Row[0] -= m.Row[0]; Row[1] -= m.Row[1]; Row[2] -= m.Row[2]; Row[3] -= m.Row[3]; - return *this; -} - -/*********************************************************************************************** - * Matrix4x4::operator *= -- "times equals" operator * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 06/02/1997 GH : Created. * - *=============================================================================================*/ -WWINLINE Matrix4x4& Matrix4x4::operator *= (float d) -{ - Row[0] *= d; Row[1] *= d; Row[2] *= d; Row[3] *= d; - return *this; -} - -/*********************************************************************************************** - * Matrix4x4::operator /= -- "divide equals" operator * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 06/02/1997 GH : Created. * - *=============================================================================================*/ -WWINLINE Matrix4x4& Matrix4x4::operator /= (float d) -{ - float ood = d; - Row[0] *= ood; Row[1] *= ood; Row[2] *= ood; Row[3] *= ood; - return *this; -} - -WWINLINE Matrix4x4 operator - (const Matrix4x4 & a) -{ - return Matrix4x4(-a.Row[0], -a.Row[1], -a.Row[2], -a.Row[3]); -} - -WWINLINE Matrix4x4 operator * (const Matrix4x4 & a, float d) -{ - return Matrix4x4(a.Row[0] * d, a.Row[1] * d, a.Row[2] * d, a.Row[3] * d); -} - -WWINLINE Matrix4x4 operator * (float d, const Matrix4x4 & a) -{ - return a*d; -} - -WWINLINE Matrix4x4 operator / (const Matrix4x4 & a, float d) -{ - float ood = 1.0f / d; - return Matrix4x4(a.Row[0] * ood, a.Row[1] * ood, a.Row[2] * ood, a.Row[3] * ood); -} - -/* -** matrix addition -*/ -WWINLINE Matrix4x4 operator + (const Matrix4x4 & a, const Matrix4x4 & b) -{ - return Matrix4x4( - a.Row[0] + b.Row[0], - a.Row[1] + b.Row[1], - a.Row[2] + b.Row[2], - a.Row[3] + b.Row[3] - ); -} - -WWINLINE Matrix4x4 Add(const Matrix4x4 & a, const Matrix4x4 & b) -{ return a+b; } - -/* -** matrix subtraction -*/ -WWINLINE Matrix4x4 operator - (const Matrix4x4 & a, const Matrix4x4 & b) -{ - return Matrix4x4( - a.Row[0] - b.Row[0], - a.Row[1] - b.Row[1], - a.Row[2] - b.Row[2], - a.Row[3] - b.Row[3] - ); -} - -WWINLINE Matrix4x4 Subtract(const Matrix4x4 & a, const Matrix4x4 & b) -{ return a-b; } - -/* -** matrix multiplication -*/ -WWINLINE Matrix4x4 operator * (const Matrix4x4 & a, const Matrix4x4 & b) -{ - #define ROWCOL(i, j) a[i][0]*b[0][j] + a[i][1]*b[1][j] + a[i][2]*b[2][j] + a[i][3]*b[3][j] - - return Matrix4x4( - Vector4(ROWCOL(0,0), ROWCOL(0,1), ROWCOL(0,2), ROWCOL(0,3)), - Vector4(ROWCOL(1,0), ROWCOL(1,1), ROWCOL(1,2), ROWCOL(1,3)), - Vector4(ROWCOL(2,0), ROWCOL(2,1), ROWCOL(2,2), ROWCOL(2,3)), - Vector4(ROWCOL(3,0), ROWCOL(3,1), ROWCOL(3,2), ROWCOL(3,3)) - ); - - #undef ROWCOL -} - -WWINLINE Matrix4x4 Multiply(const Matrix4x4 & a, const Matrix4x4 & b) -{ return a*b; } - -WWINLINE Matrix4x4 operator * (const Matrix4x4 & a, const Matrix3D & b) -{ - // This function hand coded to handle the last row of b as 0,0,0,1 - #define ROWCOL(i,j) a[i][0]*b[0][j] + a[i][1]*b[1][j] + a[i][2]*b[2][j] - #define ROWCOL_LAST(i,j) a[i][0]*b[0][j] + a[i][1]*b[1][j] + a[i][2]*b[2][j] + a[i][3] - return Matrix4x4( - Vector4(ROWCOL(0,0), ROWCOL(0,1), ROWCOL(0,2), ROWCOL_LAST(0,3)), - Vector4(ROWCOL(1,0), ROWCOL(1,1), ROWCOL(1,2), ROWCOL_LAST(1,3)), - Vector4(ROWCOL(2,0), ROWCOL(2,1), ROWCOL(2,2), ROWCOL_LAST(2,3)), - Vector4(ROWCOL(3,0), ROWCOL(3,1), ROWCOL(3,2), ROWCOL_LAST(3,3)) - ); - #undef ROWCOL - #undef ROWCOL_LAST -} - -WWINLINE Matrix4x4 operator * (const Matrix3D & a, const Matrix4x4 & b) -{ - // This function hand coded to handle the last row of a as 0,0,0,1 - #define ROWCOL(i,j) a[i][0]*b[0][j] + a[i][1]*b[1][j] + a[i][2]*b[2][j] + a[i][3]*b[3][j] - return Matrix4x4( - Vector4(ROWCOL(0,0), ROWCOL(0,1), ROWCOL(0,2), ROWCOL(0,3)), - Vector4(ROWCOL(1,0), ROWCOL(1,1), ROWCOL(1,2), ROWCOL(1,3)), - Vector4(ROWCOL(2,0), ROWCOL(2,1), ROWCOL(2,2), ROWCOL(2,3)), - Vector4(b[3][0], b[3][1], b[3][2], b[3][3]) - ); - #undef ROWCOL -} - -/* -** Multiply a Matrix4x4 by a Vector3 (assumes w=1.0!!!). Yeilds a Vector4 result -*/ -WWINLINE Vector4 operator * (const Matrix4x4 & a, const Vector3 & v) { - return Vector4( - a[0][0] * v[0] + a[0][1] * v[1] + a[0][2] * v[2] + a[0][3] * 1.0f, - a[1][0] * v[0] + a[1][1] * v[1] + a[1][2] * v[2] + a[1][3] * 1.0f, - a[2][0] * v[0] + a[2][1] * v[1] + a[2][2] * v[2] + a[2][3] * 1.0f, - a[3][0] * v[0] + a[3][1] * v[1] + a[3][2] * v[2] + a[3][3] * 1.0f - ); -} - -/* -** Multiply a Matrix4x4 by a Vector4 -*/ -WWINLINE Vector4 operator * (const Matrix4x4 & a, const Vector4 & v) { - return Vector4( - a[0][0] * v[0] + a[0][1] * v[1] + a[0][2] * v[2] + a[0][3] * v[3], - a[1][0] * v[0] + a[1][1] * v[1] + a[1][2] * v[2] + a[1][3] * v[3], - a[2][0] * v[0] + a[2][1] * v[1] + a[2][2] * v[2] + a[2][3] * v[3], - a[3][0] * v[0] + a[3][1] * v[1] + a[3][2] * v[2] + a[3][3] * v[3] - ); -} - -/* -** Multiply a Matrix4x4 by a Vector4 -*/ -WWINLINE void Matrix4x4::Transform_Vector(const Matrix4x4 & A,const Vector3 & in,Vector3 * out) -{ - Vector3 tmp; - Vector3 * v; - - // check for aliased parameters - if (out == &in) { - tmp = in; - v = &tmp; - } else { - v = (Vector3 *)∈ // whats the right way to do this... - } - - out->X = (A[0][0] * v->X + A[0][1] * v->Y + A[0][2] * v->Z + A[0][3]); - out->Y = (A[1][0] * v->X + A[1][1] * v->Y + A[1][2] * v->Z + A[1][3]); - out->Z = (A[2][0] * v->X + A[2][1] * v->Y + A[2][2] * v->Z + A[2][3]); -} - - -WWINLINE void Matrix4x4::Transform_Vector(const Matrix4x4 & A,const Vector3 & in,Vector4 * out) -{ - out->X = (A[0][0] * in.X + A[0][1] * in.Y + A[0][2] * in.Z + A[0][3]); - out->Y = (A[1][0] * in.X + A[1][1] * in.Y + A[1][2] * in.Z + A[1][3]); - out->Z = (A[2][0] * in.X + A[2][1] * in.Y + A[2][2] * in.Z + A[2][3]); - out->W = 1.0f; -} - -WWINLINE void Matrix4x4::Transform_Vector(const Matrix4x4 & A,const Vector4 & in,Vector4 * out) -{ - Vector4 tmp; - Vector4 * v; - - // check for aliased parameters - if (out == &in) { - tmp = in; - v = &tmp; - } else { - v = (Vector4 *)∈ // whats the right way to do this... - } - - out->X = (A[0][0] * v->X + A[0][1] * v->Y + A[0][2] * v->Z + A[0][3] * v->W); - out->Y = (A[1][0] * v->X + A[1][1] * v->Y + A[1][2] * v->Z + A[1][3] * v->W); - out->Z = (A[2][0] * v->X + A[2][1] * v->Y + A[2][2] * v->Z + A[2][3] * v->W); - out->W = (A[3][0] * v->X + A[3][1] * v->Y + A[3][2] * v->Z + A[3][3] * v->W); -} - - -#endif /*MATRIX4_H*/ \ No newline at end of file diff --git a/Generals/Code/Libraries/Source/WWVegas/WWMath/obbox.cpp b/Generals/Code/Libraries/Source/WWVegas/WWMath/obbox.cpp deleted file mode 100644 index e65a49e6fb0..00000000000 --- a/Generals/Code/Libraries/Source/WWVegas/WWMath/obbox.cpp +++ /dev/null @@ -1,791 +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 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 : WWMath * - * * - * $Archive:: /Commando/Code/wwmath/obbox.cpp $* - * * - * Org Author:: Greg_h * - * * - * Author : Kenny Mitchell * - * * - * $Modtime:: 06/26/02 4:04p $* - * * - * $Revision:: 24 $* - * * - * 06/26/02 KM Matrix name change to avoid MAX conflicts * - *---------------------------------------------------------------------------------------------* - * Functions: * - * OBBoxClass::OBBoxClass -- Constructor that computes the box for a set of point * - * OBBoxClass::Init_From_Box_Points -- Create an OBBox from 8 corners of a box * - * OBBoxClass::Init_Random -- initalize a random oriented box * - * Oriented_Boxes_Intersect_On_Axis -- test if two boxes intersect on given axis * - * Oriented_Boxes_Intersect -- test if two oriented boxes intersect * - * Oriented_Boxes_Collide_On_Axis -- test if two boxes collide on the given axis * - * Oriented_Boxes_Collide -- test if two oriented boxes collide * - * Oriented_Box_Intersects_Tri_On_Axis -- tests if the box and tri intersect on the axis * - * Oriented_Box_Intersects_Tri -- tests if the given box and tri intersect * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - - -#include "obbox.h" -#include "matrix3.h" -#include "vector3.h" -#include "aabox.h" -#include "tri.h" -#include "plane.h" -#include "quat.h" -#include -//#include - - -/*********************************************************************************************** - * OBBoxClass::OBBoxClass -- Constructor that computes the box for a set of points * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 2/4/98 GTH : Created. * - *=============================================================================================*/ -OBBoxClass::OBBoxClass(const Vector3 * /*points*/, int /*n*/) -{ - // TODO: IMPLEMENT THIS!!! - assert(0); - -#if 0 - int i; - - // compute mean and covariances of points - float xsum = 0.0f, ysum = 0.0f, zsum = 0.0f;; - float xxsum = 0.0f, xysum = 0.0f, xzsum = 0.0f; - float yysum = 0.0f, yzsum = 0.0f, zzsum = 0.0f; - - for (i = 0; i < n; i++) - { - xsum += points[i].X; - ysum += points[i].Y; - zsum += points[i].Z; - - xxsum += points[i].X * points[i].X; - xysum += points[i].X * points[i].Y; - xzsum += points[i].X * points[i].Z; - - yysum += points[i].Y * points[i].Y; - yzsum += points[i].Y * points[i].Z; - zzsum += points[i].Z * points[i].Z; - } - - float xmean = xsum/n; - float ymean = ysum/n; - float zmean = zsum/n; - float xxcov = xxsum/n - xmean*xmean; - float xycov = xysum/n - xmean*ymean; - float xzcov = xzsum/n - xmean*zmean; - float yycov = yysum/n - ymean*ymean; - float yzcov = yzsum/n - ymean*zmean; - float zzcov = zzsum/n - zmean*zmean; - - // compute eigenvectors for covariance matrix, - // these will be the axes. - mgcEigen eig(3); - eig.Matrix(0,0) = xxcov; - eig.Matrix(0,1) = xycov; - eig.Matrix(0,2) = xzcov; - eig.Matrix(1,0) = xycov; - eig.Matrix(1,1) = yycov; - eig.Matrix(1,2) = yzcov; - eig.Matrix(2,0) = xzcov; - eig.Matrix(2,1) = yzcov; - eig.Matrix(2,2) = zzcov; - - eig.EigenStuff3(); - Point3 U = - { - eig.Eigenvector(0,0), - eig.Eigenvector(1,0), - eig.Eigenvector(2,0) - }; - Point3 V = - { - eig.Eigenvector(0,1), - eig.Eigenvector(1,1), - eig.Eigenvector(2,1) - }; - Point3 W = - { - eig.Eigenvector(0,2), - eig.Eigenvector(1,2), - eig.Eigenvector(2,2) - }; - - // box center is the mean of the distribution - box.center.x = xmean; - box.center.y = ymean; - box.center.z = zmean; - - - // Box axes are the eigenvectors of the covariance matrix with - // adjusted lengths to enclose the points. If U, V, and W are the - // eigenvectors, C is the center of the box, and X is a point in - // the input list, then X = C + a*U + b*V + c*W. The box extent is - // determined by max|a|, max|b|, and max|c|. The box axes are then - // defined to be (max|a|)*U and (max|b|)*V. Note that since U and V - // are unit length and orthogonal, a = Dot(U,X-C), b = Dot(V,X-C), - // and c = Dot(W,X-C). - float amax = 0.0f, bmax = 0.0f, cmax = 0.0f; - for (i = 0; i < n; i++) - { - float dx = pt[i].x - box.center.x; - float dy = pt[i].y - box.center.y; - float dz = pt[i].z - box.center.z; - float absdot = float(WWMath::Fabs(U.x*dx+U.y*dy+U.z*dz)); - if ( absdot > amax ) - amax = absdot; - absdot = float(WWMath::Fabs(V.x*dx+V.y*dy+V.z*dz)); - if ( absdot > bmax ) - bmax = absdot; - absdot = float(WWMath::Fabs(W.x*dx+W.y*dy+W.z*dz)); - if ( absdot > cmax ) - cmax = absdot; - } - - box.axis[0].x = amax*U.x; - box.axis[0].y = amax*U.y; - box.axis[0].z = amax*U.z; - box.axis[1].x = bmax*V.x; - box.axis[1].y = bmax*V.y; - box.axis[1].z = bmax*V.z; - box.axis[2].x = cmax*W.x; - box.axis[2].y = cmax*W.y; - box.axis[2].z = cmax*W.z; - -#endif -} - -/*********************************************************************************************** - * OBBoxClass::Init_From_Box_Points -- Create an OBBox from 8 corners of a box * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 2/24/98 GTH : Created. * - *=============================================================================================*/ -void OBBoxClass::Init_From_Box_Points(Vector3 * points,int num) -{ - int i,j; - - /* - ** This function assumes that you pass in 8 points which are the - ** corners of a rectangular solid. Bad things will happen if - ** this assumption is not true!!!! - */ - assert(num == 8); - - /* - ** Just pick the first point as the preliminary center. Compute - ** vectors from this point to each of the other points - */ - Vector3 dp[8]; - for (i=1;i Extent.X) Extent.X = xprj; - - float yprj = float(WWMath::Fabs(axis1.X * dx + axis1.Y * dy + axis1.Z * dz)); - if (yprj > Extent.Y) Extent.Y = yprj; - - float zprj = float(WWMath::Fabs(axis2.X * dx + axis2.Y * dy + axis2.Z * dz)); - if (zprj > Extent.Z) Extent.Z = zprj; - } -} - - -/*********************************************************************************************** - * OBBoxClass::Init_Random -- initalize a random oriented box * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 4/21/98 GTH : Created. * - *=============================================================================================*/ -void OBBoxClass::Init_Random(float min_extent,float max_extent) -{ - Center.Set(0,0,0); - - Extent.X = min_extent + WWMath::Random_Float() * (max_extent - min_extent); - Extent.Y = min_extent + WWMath::Random_Float() * (max_extent - min_extent); - Extent.Z = min_extent + WWMath::Random_Float() * (max_extent - min_extent); - - Quaternion orient; - orient.X = WWMath::Random_Float(); - orient.Y = WWMath::Random_Float(); - orient.Z = WWMath::Random_Float(); - orient.W = WWMath::Random_Float(); - orient.Normalize(); - - Basis = Build_Matrix3(orient); -} - - - - -/*********************************************************************************************** - * Oriented_Boxes_Intersect_On_Axis -- test if two boxes intersect on given axis * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 4/7/99 GTH : Created. * - *=============================================================================================*/ -bool Oriented_Boxes_Intersect_On_Axis -( - const OBBoxClass & box0, - const OBBoxClass & box1, - const Vector3 & axis -) -{ - float ra,rb,rsum; - - if (axis.Length2() < WWMATH_EPSILON) return true; - - ra = box0.Project_To_Axis(axis); - rb = box1.Project_To_Axis(axis); - rsum = WWMath::Fabs(ra) + WWMath::Fabs(rb); - - // project the center distance onto the line: - Vector3 C = box1.Center - box0.Center; - float cdist = Vector3::Dot_Product(axis,C); - - if ((cdist > rsum) || (cdist < -rsum)) { - return false; - } - return true; -} - - -/*********************************************************************************************** - * Oriented_Boxes_Intersect -- test if two oriented boxes intersect * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 4/7/99 GTH : Created. * - *=============================================================================================*/ -bool Oriented_Boxes_Intersect -( - const OBBoxClass & box0, - const OBBoxClass & box1 -) -{ - Vector3 axis; - Vector3 A[3],B[3]; - - // vectors for the axis directions of the two boxes in world space - A[0].Set(box0.Basis[0][0],box0.Basis[1][0],box0.Basis[2][0]); - A[1].Set(box0.Basis[0][1],box0.Basis[1][1],box0.Basis[2][1]); - A[2].Set(box0.Basis[0][2],box0.Basis[1][2],box0.Basis[2][2]); - - B[0].Set(box1.Basis[0][0],box1.Basis[1][0],box1.Basis[2][0]); - B[1].Set(box1.Basis[0][1],box1.Basis[1][1],box1.Basis[2][1]); - B[2].Set(box1.Basis[0][2],box1.Basis[1][2],box1.Basis[2][2]); - - ///////////////////////////////////////////////////////////////////////// - // Projecting the two boxes onto Box0's X axis. If their intervals - // on this line do not intersect, the boxes are not intersecting. - // Each of the tests in this function work in a similar way. - ///////////////////////////////////////////////////////////////////////// - if (!Oriented_Boxes_Intersect_On_Axis(box0,box1,A[0])) return false; - if (!Oriented_Boxes_Intersect_On_Axis(box0,box1,A[1])) return false; - if (!Oriented_Boxes_Intersect_On_Axis(box0,box1,A[2])) return false; - if (!Oriented_Boxes_Intersect_On_Axis(box0,box1,B[0])) return false; - if (!Oriented_Boxes_Intersect_On_Axis(box0,box1,B[1])) return false; - if (!Oriented_Boxes_Intersect_On_Axis(box0,box1,B[2])) return false; - - ///////////////////////////////////////////////////////////////////////// - // None of the aligned axes turned out to be separating axes. Now - // we check all combinations of cross products of the two boxes axes. - ///////////////////////////////////////////////////////////////////////// - Vector3::Cross_Product(A[0],B[0],&axis); - if (!Oriented_Boxes_Intersect_On_Axis(box0,box1,axis)) return false; - - Vector3::Cross_Product(A[0],B[1],&axis); - if (!Oriented_Boxes_Intersect_On_Axis(box0,box1,axis)) return false; - - Vector3::Cross_Product(A[0],B[2],&axis); - if (!Oriented_Boxes_Intersect_On_Axis(box0,box1,axis)) return false; - - Vector3::Cross_Product(A[1],B[0],&axis); - if (!Oriented_Boxes_Intersect_On_Axis(box0,box1,axis)) return false; - - Vector3::Cross_Product(A[1],B[1],&axis); - if (!Oriented_Boxes_Intersect_On_Axis(box0,box1,axis)) return false; - - Vector3::Cross_Product(A[1],B[2],&axis); - if (!Oriented_Boxes_Intersect_On_Axis(box0,box1,axis)) return false; - - Vector3::Cross_Product(A[2],B[0],&axis); - if (!Oriented_Boxes_Intersect_On_Axis(box0,box1,axis)) return false; - - Vector3::Cross_Product(A[2],B[1],&axis); - if (!Oriented_Boxes_Intersect_On_Axis(box0,box1,axis)) return false; - - Vector3::Cross_Product(A[2],B[2],&axis); - if (!Oriented_Boxes_Intersect_On_Axis(box0,box1,axis)) return false; - - // None of the above tests separated the two boxes, so they are intersecting - return true; -} - - - - - -/*********************************************************************************************** - * Oriented_Boxes_Collide_On_Axis -- test if two boxes collide on the given axis * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 4/7/99 GTH : Created. * - *=============================================================================================*/ -bool Oriented_Boxes_Collide_On_Axis -( - const OBBoxClass & box0, - const Vector3 & v0, - const OBBoxClass & box1, - const Vector3 & v1, - const Vector3 & axis, - float dt -) -{ - float ra,rb,rsum; - - if (axis.Length2() < WWMATH_EPSILON) return true; - - ra = box0.Project_To_Axis(axis); - rb = box1.Project_To_Axis(axis); - rsum = WWMath::Fabs(ra) + WWMath::Fabs(rb); - - // project the center distance onto the line: - Vector3 C = box1.Center - box0.Center; - Vector3 V = v1 - v0; - - float cdist = Vector3::Dot_Product(axis,C); - float vdist = cdist + dt * Vector3::Dot_Product(axis,V); - - if ((cdist > rsum && vdist > rsum) || (cdist < -rsum && vdist < -rsum)) { - return false; - } - return true; -} - - -/*********************************************************************************************** - * Oriented_Boxes_Collide -- test if two oriented boxes collide * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 4/7/99 GTH : Created. * - *=============================================================================================*/ -bool Oriented_Boxes_Collide -( - const OBBoxClass & box0, - const Vector3 & v0, - const OBBoxClass & box1, - const Vector3 & v1, - float dt -) -{ - bool intersect = true; - - // variables for holding the separating axis and the projected distances - Vector3 SepAxis; - - // vectors for the axis directions of the two boxes in world space - Vector3 A0(box0.Basis[0][0],box0.Basis[1][0],box0.Basis[2][0]); - Vector3 A1(box0.Basis[0][1],box0.Basis[1][1],box0.Basis[2][1]); - Vector3 A2(box0.Basis[0][2],box0.Basis[1][2],box0.Basis[2][2]); - - Vector3 B0(box1.Basis[0][0],box1.Basis[1][0],box1.Basis[2][0]); - Vector3 B1(box1.Basis[0][1],box1.Basis[1][1],box1.Basis[2][1]); - Vector3 B2(box1.Basis[0][2],box1.Basis[1][2],box1.Basis[2][2]); - - - ///////////////////////////////////////////////////////////////////////// - // L = A0 - // - // Projecting the two boxes onto Box0's X axis. If their intervals - // on this line do not intersect, the boxes are not intersecting! - // Each of the tests in this function work in a similar way. - ///////////////////////////////////////////////////////////////////////// - SepAxis = A0; - - if (!Oriented_Boxes_Collide_On_Axis(box0,v0,box1,v1,SepAxis,dt)) { - intersect = false; - goto exit; - } - - ///////////////////////////////////////////////////////////////////////// - // L = A1 - // Separating Axis is Box0's Y axis - ///////////////////////////////////////////////////////////////////////// - SepAxis = A1; - - if (!Oriented_Boxes_Collide_On_Axis(box0,v0,box1,v1,SepAxis,dt)) { - intersect = false; - goto exit; - } - - ///////////////////////////////////////////////////////////////////////// - // L = A2 - // Separating Axis is Box0's Z axis - ///////////////////////////////////////////////////////////////////////// - SepAxis = A2; - - if (!Oriented_Boxes_Collide_On_Axis(box0,v0,box1,v1,SepAxis,dt)) { - intersect = false; - goto exit; - } - - ///////////////////////////////////////////////////////////////////////// - // L = B0 - // Separating Axis is Box1's X axis - ///////////////////////////////////////////////////////////////////////// - SepAxis = B0; - - if (!Oriented_Boxes_Collide_On_Axis(box0,v0,box1,v1,SepAxis,dt)) { - intersect = false; - goto exit; - } - - ///////////////////////////////////////////////////////////////////////// - // L = B1 - // Separating Axis is Box1's Y axis - ///////////////////////////////////////////////////////////////////////// - SepAxis = B1; - - if (!Oriented_Boxes_Collide_On_Axis(box0,v0,box1,v1,SepAxis,dt)) { - intersect = false; - goto exit; - } - - ///////////////////////////////////////////////////////////////////////// - // L = B2 - // Separating Axis is Box1's Z axis - ///////////////////////////////////////////////////////////////////////// - SepAxis = B2; - - if (!Oriented_Boxes_Collide_On_Axis(box0,v0,box1,v1,SepAxis,dt)) { - intersect = false; - goto exit; - } - - ///////////////////////////////////////////////////////////////////////// - // None of the aligned axes turned out to be separating axes. Now - // we check all combinations of cross products of the two boxes axes. - ///////////////////////////////////////////////////////////////////////// - - ///////////////////////////////////////////////////////////////////////// - // L = A0xB0 - ///////////////////////////////////////////////////////////////////////// - Vector3::Cross_Product(A0,B0,&SepAxis); - - if (!Oriented_Boxes_Collide_On_Axis(box0,v0,box1,v1,SepAxis,dt)) { - intersect = false; - goto exit; - } - - ///////////////////////////////////////////////////////////////////////// - // L = A0xB1 - ///////////////////////////////////////////////////////////////////////// - Vector3::Cross_Product(A0,B1,&SepAxis); - - if (!Oriented_Boxes_Collide_On_Axis(box0,v0,box1,v1,SepAxis,dt)) { - intersect = false; - goto exit; - } - - ///////////////////////////////////////////////////////////////////////// - // L = A0xB2 - ///////////////////////////////////////////////////////////////////////// - Vector3::Cross_Product(A0,B2,&SepAxis); - - if (!Oriented_Boxes_Collide_On_Axis(box0,v0,box1,v1,SepAxis,dt)) { - intersect = false; - goto exit; - } - - ///////////////////////////////////////////////////////////////////////// - // L = A1xB0 - ///////////////////////////////////////////////////////////////////////// - Vector3::Cross_Product(A1,B0,&SepAxis); - - if (!Oriented_Boxes_Collide_On_Axis(box0,v0,box1,v1,SepAxis,dt)) { - intersect = false; - goto exit; - } - - ///////////////////////////////////////////////////////////////////////// - // L = A1xB1 - ///////////////////////////////////////////////////////////////////////// - Vector3::Cross_Product(A1,B1,&SepAxis); - - if (!Oriented_Boxes_Collide_On_Axis(box0,v0,box1,v1,SepAxis,dt)) { - intersect = false; - goto exit; - } - - ///////////////////////////////////////////////////////////////////////// - // L = A1xB2 - ///////////////////////////////////////////////////////////////////////// - Vector3::Cross_Product(A1,B2,&SepAxis); - - if (!Oriented_Boxes_Collide_On_Axis(box0,v0,box1,v1,SepAxis,dt)) { - intersect = false; - goto exit; - } - - ///////////////////////////////////////////////////////////////////////// - // L = A2xB0 - ///////////////////////////////////////////////////////////////////////// - Vector3::Cross_Product(A2,B0,&SepAxis); - - if (!Oriented_Boxes_Collide_On_Axis(box0,v0,box1,v1,SepAxis,dt)) { - intersect = false; - goto exit; - } - - ///////////////////////////////////////////////////////////////////////// - // L = A2xB1 - ///////////////////////////////////////////////////////////////////////// - Vector3::Cross_Product(A2,B1,&SepAxis); - - if (!Oriented_Boxes_Collide_On_Axis(box0,v0,box1,v1,SepAxis,dt)) { - intersect = false; - goto exit; - } - - ///////////////////////////////////////////////////////////////////////// - // L = A2xB2 - ///////////////////////////////////////////////////////////////////////// - Vector3::Cross_Product(A2,B2,&SepAxis); - - if (!Oriented_Boxes_Collide_On_Axis(box0,v0,box1,v1,SepAxis,dt)) { - intersect = false; - goto exit; - } - -exit: - - return intersect; -} - - - -/*********************************************************************************************** - * Oriented_Box_Intersects_Tri_On_Axis -- tests if the box and tri intersect on the axis * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 4/7/99 GTH : Created. * - *=============================================================================================*/ -bool Oriented_Box_Intersects_Tri_On_Axis(const OBBoxClass & box,const TriClass & tri,Vector3 & axis) -{ - float leb; // leading edge of box (farthest point from center) - float lep; // leading edge of poly (closest point to center) - float dist; // distance from box center to v0 - float tmp; - - if (axis.Length2() < WWMATH_EPSILON) return true; - - Vector3 D = *(tri.V[0]) - box.Center; - Vector3 r1 = *(tri.V[1]) - *(tri.V[0]); - Vector3 r2 = *(tri.V[2]) - *(tri.V[0]); - - // I want the axis to point from box.center to tri.v0 - dist = Vector3::Dot_Product(D,axis); - if (dist < 0) { - dist = -dist; - axis = -axis; - } - - // compute leading edge of the box - leb = box.Project_To_Axis(axis); - - // compute the leading edge of the triangle - lep = 0; - tmp = Vector3::Dot_Product(r1,axis); if (tmp < lep) lep = tmp; - tmp = Vector3::Dot_Product(r2,axis); if (tmp < lep) lep = tmp; - lep += dist; - - if (lep >= leb) { - return false; - } else { - return true; - } -} - - -/*********************************************************************************************** - * Oriented_Box_Intersects_Tri -- tests if the given box and tri intersect * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 4/7/99 GTH : Created. * - *=============================================================================================*/ -bool Oriented_Box_Intersects_Tri(const OBBoxClass & box,const TriClass & tri) -{ - Vector3 axis; - - // vectors for the axis directions of the two boxes in world space - Vector3 A[3]; - Vector3 E[3]; - Vector3 normal = *tri.N; - A[0].Set(box.Basis[0][0],box.Basis[1][0],box.Basis[2][0]); - A[1].Set(box.Basis[0][1],box.Basis[1][1],box.Basis[2][1]); - A[2].Set(box.Basis[0][2],box.Basis[1][2],box.Basis[2][2]); - E[0] = *(tri.V[1]) - *(tri.V[0]); - E[1] = *(tri.V[2]) - *(tri.V[1]); - E[2] = *(tri.V[0]) - *(tri.V[2]); - - if (!Oriented_Box_Intersects_Tri_On_Axis(box,tri,normal)) return false; - if (!Oriented_Box_Intersects_Tri_On_Axis(box,tri,A[0])) return false; - if (!Oriented_Box_Intersects_Tri_On_Axis(box,tri,A[1])) return false; - if (!Oriented_Box_Intersects_Tri_On_Axis(box,tri,A[2])) return false; - - Vector3::Cross_Product(A[0],E[0],&axis); - if (!Oriented_Box_Intersects_Tri_On_Axis(box,tri,axis)) return false; - - Vector3::Cross_Product(A[0],E[1],&axis); - if (!Oriented_Box_Intersects_Tri_On_Axis(box,tri,axis)) return false; - - Vector3::Cross_Product(A[0],E[2],&axis); - if (!Oriented_Box_Intersects_Tri_On_Axis(box,tri,axis)) return false; - - Vector3::Cross_Product(A[1],E[0],&axis); - if (!Oriented_Box_Intersects_Tri_On_Axis(box,tri,axis)) return false; - - Vector3::Cross_Product(A[1],E[1],&axis); - if (!Oriented_Box_Intersects_Tri_On_Axis(box,tri,axis)) return false; - - Vector3::Cross_Product(A[1],E[2],&axis); - if (!Oriented_Box_Intersects_Tri_On_Axis(box,tri,axis)) return false; - - Vector3::Cross_Product(A[2],E[0],&axis); - if (!Oriented_Box_Intersects_Tri_On_Axis(box,tri,axis)) return false; - - Vector3::Cross_Product(A[2],E[1],&axis); - if (!Oriented_Box_Intersects_Tri_On_Axis(box,tri,axis)) return false; - - Vector3::Cross_Product(A[2],E[2],&axis); - if (!Oriented_Box_Intersects_Tri_On_Axis(box,tri,axis)) return false; - - return true; -} diff --git a/Generals/Code/Libraries/Source/WWVegas/WWMath/obbox.h b/Generals/Code/Libraries/Source/WWVegas/WWMath/obbox.h deleted file mode 100644 index 87060325983..00000000000 --- a/Generals/Code/Libraries/Source/WWVegas/WWMath/obbox.h +++ /dev/null @@ -1,271 +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 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 : wwmath * - * * - * $Archive:: /Commando/Code/wwmath/obbox.h $* - * * - * Org Author:: Greg_h * - * * - * Author : Kenny Mitchell * - * * - * $Modtime:: 06/26/02 4:04p $* - * * - * $Revision:: 24 $* - * * - * 06/26/02 KM Matrix name change to avoid MAX conflicts * - *---------------------------------------------------------------------------------------------* - * Functions: * - * OBBoxClass::Transform -- transform an oriented box * - * OBBoxClass::Project_To_Axis -- compute projection onto the given axis * - * OBBoxClass::Compute_Point -- computes position of a parametricly defined point * - * OBBoxClass::Compute_Axis_Aligned_Extent -- computes extent of an AABox enclosing this box * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - -#if defined(_MSC_VER) -#pragma once -#endif - -#ifndef OBBOX_H -#define OBBOX_H - -#include "always.h" -#include "vector3.h" -#include "matrix3.h" -#include "matrix3d.h" -#include "wwmath.h" -#include "castres.h" - -class TriClass; -class AABoxClass; -class PlaneClass; - - -/* -** OBBoxClass -** -** Oriented-Bounding-Box Class. -** This is a collision box in world space. -** Center - position of the center of the box -** Extents - size of the box -** Basis - rotation matrix defining the orientation of the box -** -** To find the world space coordinates of the "+x,+y,+z" corner of -** the bounding box you could use this equation: -** Vector3 corner = Center + Basis * Extent; -*/ -class OBBoxClass -{ -public: - - OBBoxClass(void) { } - - OBBoxClass(const OBBoxClass & that) : - Basis(that.Basis), - Center(that.Center), - Extent(that.Extent) - { } - - OBBoxClass(const Vector3 & center,const Vector3 & extent) : - Basis(1), - Center(center), - Extent(extent) - { } - - OBBoxClass(const Vector3 & center,const Vector3 & extent,const Matrix3x3 & basis) : - Basis(basis), - Center(center), - Extent(extent) - { } - - OBBoxClass(const Vector3 * points, int num_points); - - bool operator== (const OBBoxClass &src); - bool operator!= (const OBBoxClass &src); - - void Init_From_Box_Points(Vector3 * points,int num_points); - void Init_Random(float min_extent = 0.5f,float max_extent = 1.0f); - float Project_To_Axis(const Vector3 & axis) const; - float Volume(void) const { return 2.0*Extent.X * 2.0*Extent.Y * 2.0*Extent.Z; } - void Compute_Point(float params[3],Vector3 * set_point) const; - void Compute_Axis_Aligned_Extent(Vector3 * set_extent) const; - - Matrix3x3 Basis; - Vector3 Center; - Vector3 Extent; - - static void Transform(const Matrix3D & tm,const OBBoxClass & in,OBBoxClass * out); -}; - -// Test functions: slow, easy to understand version of box intersection code :) -bool Oriented_Boxes_Intersect(const OBBoxClass & box0,const OBBoxClass & box1); -bool Oriented_Boxes_Collide(const OBBoxClass & box0,const Vector3 & v0,const OBBoxClass & box1,const Vector3 & v1,float dt); -bool Oriented_Box_Intersects_Tri(const OBBoxClass & box,const TriClass & tri); - - -/*********************************************************************************************** - * OBBoxClass::Project_To_Axis -- compute projection onto the given axis * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 2/24/98 GTH : Created. * - *=============================================================================================*/ -inline float OBBoxClass::Project_To_Axis(const Vector3 & axis) const -{ - float x = Extent[0] * Vector3::Dot_Product(axis,Vector3(Basis[0][0],Basis[1][0],Basis[2][0])); - float y = Extent[1] * Vector3::Dot_Product(axis,Vector3(Basis[0][1],Basis[1][1],Basis[2][1])); - float z = Extent[2] * Vector3::Dot_Product(axis,Vector3(Basis[0][2],Basis[1][2],Basis[2][2])); - - // projection is the sum of the absolute values of the projections of the three extents - return (WWMath::Fabs(x) + WWMath::Fabs(y) + WWMath::Fabs(z)); -} - - -/*********************************************************************************************** - * OBBoxClass::Transform -- transform an oriented box * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 2/24/98 GTH : Created. * - *=============================================================================================*/ -inline void OBBoxClass::Transform -( - const Matrix3D & tm, - const OBBoxClass & in, - OBBoxClass * out -) -{ - WWASSERT(out); - WWASSERT(out!=&in); - - out->Extent = in.Extent; - Matrix3D::Transform_Vector(tm,in.Center,&(out->Center)); - Matrix3x3::Multiply(tm,in.Basis,&(out->Basis)); -} - - -/*********************************************************************************************** - * OBBoxClass::Compute_Point -- computes position of a parametricly defined point * - * * - * set_point = Center + params[0]*A0 + params[1]*A1 + params[2]*A2 * - * * - * INPUT: * - * params - parametric description of a point in the box. -1 < params[i] < 1 * - * set_point - pointer to a Vector3 to set. * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 4/2/99 GTH : Created. * - *=============================================================================================*/ -inline void OBBoxClass::Compute_Point(float params[3],Vector3 * set_point) const -{ - Vector3 point = Extent; - point.X *= params[0]; - point.Y *= params[1]; - point.Z *= params[2]; - - Matrix3x3::Rotate_Vector(Basis,point,set_point); - Vector3::Add(Center,*set_point,set_point); -} - - -/*********************************************************************************************** - * OBBoxClass::Compute_Axis_Aligned_Extent -- computes extent of an AABox enclosing this box * - * * - * INPUT: * - * set_extent - pointer to a Vector3 to put the result into * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 11/15/99 gth : Created. * - *=============================================================================================*/ -inline void OBBoxClass::Compute_Axis_Aligned_Extent(Vector3 * set_extent) const -{ - WWASSERT(set_extent != NULL); - - // x extent is the box projected onto the x axis - set_extent->X = WWMath::Fabs(Extent[0] * Basis[0][0]) + - WWMath::Fabs(Extent[1] * Basis[0][1]) + - WWMath::Fabs(Extent[2] * Basis[0][2]); - - set_extent->Y = WWMath::Fabs(Extent[0] * Basis[1][0]) + - WWMath::Fabs(Extent[1] * Basis[1][1]) + - WWMath::Fabs(Extent[2] * Basis[1][2]); - - set_extent->Z = WWMath::Fabs(Extent[0] * Basis[2][0]) + - WWMath::Fabs(Extent[1] * Basis[2][1]) + - WWMath::Fabs(Extent[2] * Basis[2][2]); -} - - -/*********************************************************************************************** - * OBBoxClass::operator== -- Comparison operator * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 6/21/00 PDS : Created. * - *=============================================================================================*/ -inline bool OBBoxClass::operator== (const OBBoxClass &src) -{ - return (Center == src.Center) && (Extent == src.Extent) && (Basis == src.Basis); -} - - -/*********************************************************************************************** - * OBBoxClass::operator!= -- Comparison operator * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 6/21/00 PDS : Created. * - *=============================================================================================*/ -inline bool OBBoxClass::operator!= (const OBBoxClass &src) -{ - return (Center != src.Center) || (Extent != src.Extent) && (Basis == src.Basis); -} - -#endif diff --git a/Generals/Code/Libraries/Source/WWVegas/WWMath/ode.cpp b/Generals/Code/Libraries/Source/WWVegas/WWMath/ode.cpp deleted file mode 100644 index 0926eba4e07..00000000000 --- a/Generals/Code/Libraries/Source/WWVegas/WWMath/ode.cpp +++ /dev/null @@ -1,367 +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 . -*/ - -/* $Header: /Commando/Code/wwmath/ODE.CPP 8 7/02/99 10:32a Greg_h $ */ -/*********************************************************************************************** - *** Confidential - Westwood Studios *** - *********************************************************************************************** - * * - * Project Name : Commando * - * * - * $Archive:: /Commando/Code/wwmath/ODE.CPP $* - * * - * Author:: Greg_h * - * * - * $Modtime:: 6/25/99 6:23p $* - * * - * $Revision:: 8 $* - * * - *---------------------------------------------------------------------------------------------* - * Functions: * - * Euler_Integrate -- uses Eulers method to integrate a system of ODE's * - * Midpoint_Integrate -- midpoint method (Runge-Kutta 2) for integration * - * Runge_Kutta_Integrate -- Runge Kutta 4 method * - * Runge_Kutta5_Integrate -- 5th order Runge-Kutta * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - -#include "ode.h" -#include - -static StateVectorClass Y0; -static StateVectorClass Y1; -static StateVectorClass _WorkVector0; -static StateVectorClass _WorkVector1; -static StateVectorClass _WorkVector2; -static StateVectorClass _WorkVector3; -static StateVectorClass _WorkVector4; -static StateVectorClass _WorkVector5; -static StateVectorClass _WorkVector6; -static StateVectorClass _WorkVector7; - -/*********************************************************************************************** - * Euler_Solve -- uses Eulers method to integrate a system of ODE's * - * * - * INPUT: * - * odesys - pointer to the ODE system to integrate * - * dt - size of the timestep * - * * - * OUTPUT: * - * state vector in odesys will be updated for the next timestep * - * * - * WARNINGS: * - * * - * HISTORY: * - * 08/11/1997 GH : Created. * - * 6/25/99 GTH : Updated to the new integrator system * - *=============================================================================================*/ -void IntegrationSystem::Euler_Integrate(ODESystemClass * sys, float dt) -{ - WWASSERT(sys != NULL); - - /* - ** Get the current state - */ - Y0.Reset(); - sys->Get_State(Y0); - Y1.Resize(Y0.Count()); - - /* - ** make aliases to the work-vectors we need - */ - StateVectorClass & dydt = _WorkVector0; - dydt.Resize(Y0.Count()); - - /* - ** Euler method, just evaluate the derivative, multiply - ** by the time-step and add to the current state vector. - */ - sys->Compute_Derivatives(0,NULL,&dydt); - - Y1.Resize(Y0.Count()); - for (int i = 0; i < Y0.Count(); i++) { - Y1[i] = Y0[i] + dydt[i] * dt; - } - - sys->Set_State(Y1); -} - -/*********************************************************************************************** - * Midpoint_Integrate -- midpoint method (Runge-Kutta 2) * - * * - * INPUT: * - * sys - pointer to the ODE system to integrate * - * dt - size of the timestep * - * * - * OUTPUT: * - * state vector in odesys will be updated for the next timestep * - * * - * WARNINGS: * - * * - * HISTORY: * - * 08/11/1997 GH : Created. * - * 6/25/99 GTH : Updated to the new integrator system * - *=============================================================================================*/ -void IntegrationSystem::Midpoint_Integrate(ODESystemClass * sys,float dt) -{ - int i; - - /* - ** Get the current state - */ - Y0.Reset(); - sys->Get_State(Y0); - Y1.Resize(Y0.Count()); - - /* - ** make aliases to the work-vectors we need - */ - StateVectorClass & dydt = _WorkVector0; - StateVectorClass & ymid = _WorkVector1; - dydt.Resize(Y0.Count()); - ymid.Resize(Y0.Count()); - - /* - ** MidPoint method, first evaluate the derivitives of the - ** state vector just like the Euler method. - */ - sys->Compute_Derivatives(0.0f,NULL,&dydt); - - /* - ** Compute the midpoint between the Euler solution and - ** the input values. - */ - for (i=0; iCompute_Derivatives(dt/2.0f,&ymid,&dydt); - - /* - ** Use these derivatives to compute the solution. - */ - for (i=0; iSet_State(Y1); -} - - -/*********************************************************************************************** - * Runge_Kutta_Integrate -- Runge Kutta 4 method * - * * - * INPUT: * - * odesys - pointer to the ODE system to integrate * - * dt - size of the timestep * - * * - * OUTPUT: * - * state vector in odesys will be updated for the next timestep * - * * - * WARNINGS: * - * * - * HISTORY: * - * 08/11/1997 GH : Created. * - *=============================================================================================*/ -void IntegrationSystem::Runge_Kutta_Integrate(ODESystemClass * sys,float dt) -{ - int i; - float dt2 = dt / 2.0f; - float dt6 = dt / 6.0f; - - /* - ** Get the current state - */ - Y0.Reset(); - sys->Get_State(Y0); - Y1.Resize(Y0.Count()); - - /* - ** make aliases to the work-vectors we need - */ - StateVectorClass & dydt = _WorkVector0; - StateVectorClass & dym = _WorkVector1; - StateVectorClass & dyt = _WorkVector2; - StateVectorClass & yt = _WorkVector3; - dydt.Resize(Y0.Count()); - dym.Resize(Y0.Count()); - dyt.Resize(Y0.Count()); - yt.Resize(Y0.Count()); - - /* - ** First Step - */ - sys->Compute_Derivatives(0.0f,NULL,&dydt); - for (i=0; iCompute_Derivatives(dt2, &yt, &dyt); - for (i=0; iCompute_Derivatives(dt2, &yt, &dym); - for (i=0; iCompute_Derivatives(dt, &yt, &dyt); - for (i=0; iSet_State(Y1); -} - -/*********************************************************************************************** - * Runge_Kutta5_Integrate -- 5th order Runge-Kutta * - * * - * INPUT: * - * odesys - pointer to the ODE system to integrate * - * dt - size of the timestep * - * * - * OUTPUT: * - * state vector in odesys will be updated for the next timestep * - * * - * WARNINGS: * - * * - * HISTORY: * - * 08/11/1997 GH : Created. * - * 6/25/99 GTH : Converted to the new Integrator system * - *=============================================================================================*/ -void IntegrationSystem::Runge_Kutta5_Integrate(ODESystemClass * odesys,float dt) -{ - int i; - int veclen; - static const float a2 = 0.2f; - static const float a3 = 0.3f; - static const float a4 = 0.6f; - static const float a5 = 1.0f; - static const float a6 = 0.875f; - static const float b21 = 0.2f; - static const float b31 = 3.0f/40.0f; - static const float b32 = 9.0f/40.0f; - static const float b41 = 0.3f; - static const float b42 = -0.9f; - static const float b43 = 1.2f; - static const float b51 = -11.0f /54.0f; - static const float b52 = 2.5f; - static const float b53 = -70.0f/27.0f; - static const float b54 = 35.0f/27.0f; - static const float b61 = 1631.0f/55296.0f; - static const float b62 = 175.0f/512.0f; - static const float b63 = 575.0f/13824.0f; - static const float b64 = 44275.0f/110592.0f; - static const float b65 = 253.0f/4096.0f; - static const float c1 = 37.0f/378.0f; - static const float c3 = 250.0f/621.0f; - static const float c4 = 125.0f/594.0f; - static const float c6 = 512.0f/1771.0f; - static const float dc5 = -277.0f/14336.0f; - static const float dc1 = c1 - 2825.0f/27648.0f; - static const float dc3 = c3 - 18575.0f/48384.0f; - static const float dc4 = c4 - 13525.0f/55296.0f; - static const float dc6 = c6 - 0.25f; - - /* - ** Get the current state - */ - Y0.Reset(); - odesys->Get_State(Y0); - veclen = Y0.Count(); - Y1.Resize(veclen); - - /* - ** make aliases to the work-vectors we need - */ - StateVectorClass & dydt = _WorkVector0; - StateVectorClass & ak2 = _WorkVector1; - StateVectorClass & ak3 = _WorkVector2; - StateVectorClass & ak4 = _WorkVector3; - StateVectorClass & ak5 = _WorkVector4; - StateVectorClass & ak6 = _WorkVector5; - StateVectorClass & ytmp = _WorkVector6; - StateVectorClass & yerr = _WorkVector7; - - dydt.Resize(veclen); - ak2.Resize(veclen); - ak3.Resize(veclen); - ak4.Resize(veclen); - ak5.Resize(veclen); - ak6.Resize(veclen); - ytmp.Resize(veclen); - yerr.Resize(veclen); - - // First step - odesys->Compute_Derivatives(0.0f,NULL,&dydt); - for (i=0;iCompute_Derivatives(a2*dt, &ytmp, &ak2); - for (i=0; iCompute_Derivatives(a3*dt, &ytmp, &ak3); - for (i=0; iCompute_Derivatives(a4*dt, &ytmp, &ak4); - for (i=0; iCompute_Derivatives(a5*dt, &ytmp, &ak5); - for (i=0; iCompute_Derivatives(a6*dt, &ytmp, &ak6); - for (i=0; iSet_State(Y1); -} - diff --git a/Generals/Code/Libraries/Source/WWVegas/WWMath/ode.h b/Generals/Code/Libraries/Source/WWVegas/WWMath/ode.h deleted file mode 100644 index ffaf6300287..00000000000 --- a/Generals/Code/Libraries/Source/WWVegas/WWMath/ode.h +++ /dev/null @@ -1,134 +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 . -*/ - -/* $Header: /G/wwmath/ode.h 9 9/21/99 5:54p Neal_k $ */ -/*********************************************************************************************** - *** Confidential - Westwood Studios *** - *********************************************************************************************** - * * - * Project Name : Commando * - * * - * $Archive:: /G/wwmath/ode.h $* - * * - * Author:: Greg_h * - * * - * $Modtime:: 9/21/99 5:54p $* - * * - * $Revision:: 9 $* - * * - *---------------------------------------------------------------------------------------------* - * Functions: * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - - -#if defined(_MSC_VER) -#pragma once -#endif - -#ifndef ODE_H -#define ODE_H - -#include "always.h" -#include "Vector.H" -#include "wwdebug.h" - - -/* -** StateVectorClass -** The state vector for a system of ordinary differential equations will be -** stored in this form. It is a dynamically resizeable array so that we don't -** have to hard-code a maximum size. If needed, in the final product, we could -** do a slight optimization which makes this a normal fixed size array that -** we've determined is "big enough". -*/ -class StateVectorClass : public DynamicVectorClass -{ -public: - void Reset(void) { ActiveCount = 0; } - void Resize(int size) { if (size > VectorMax) { DynamicVectorClass::Resize(size); } } -}; - - -/* -** ODESystemClass -** If a system of Ordinary Differential Equations (ODE's) are put behind an interface -** of this type, they can be integrated using the Integrators defined in this module. -*/ -class ODESystemClass -{ - -public: - - /* - ** Get_Current_State - ** This function should fill the given state vector with the - ** current state of this object. Each state variable should be - ** inserted into the vector using its 'Add' interface. - */ - virtual void Get_State(StateVectorClass & set_state) = 0; - - /* - ** Set_Current_State - ** This function should read its state from this state vector starting from the - ** given index. The return value should be the index that the next object should - ** read from (i.e. increment the index past your state) - */ - virtual int Set_State(const StateVectorClass & new_state,int start_index = 0) = 0; - - /* - ** Compute_Derivatives - ** The various ODE solvers will use this interface to ask the ODESystemClass to - ** compute the derivatives of their state. In some cases, the integrator will - ** pass in a new state vector (test_state) to be used when computing the derivatives. - ** NULL will be passed if they want the derivatives for the initial state. - ** This function works similarly to the Set_State function in that it passes you - ** the index to start reading from and you pass it back the index to continue from. - */ - virtual int Compute_Derivatives(float t,StateVectorClass * test_state,StateVectorClass * dydt,int start_index = 0) = 0; - -}; - - -/* -** IntegrationSystem -** -** The Euler_Solve is the simplest but most inaccurate. It requires only -** a single computation of the derivatives per timestep. -** -** The Midpoint_Solve function will evaluate the derivatives at two points -** -** The Runge_Kutta_Solve requires four evaluations of the derivatives. -** This is the fourth order Runge-Kutta method... -** -** Runge_Kutta5_Solve is an implementation of fifth order Runge- -** Kutta. It requires six evaluations of the derivatives. -*/ - -class IntegrationSystem -{ -public: - - static void Euler_Integrate(ODESystemClass * sys,float dt); - static void Midpoint_Integrate(ODESystemClass * sys,float dt); - static void Runge_Kutta_Integrate(ODESystemClass * sys,float dt); - static void Runge_Kutta5_Integrate(ODESystemClass * odesys,float dt); - -}; - -#endif - diff --git a/Generals/Code/Libraries/Source/WWVegas/WWMath/plane.h b/Generals/Code/Libraries/Source/WWVegas/WWMath/plane.h deleted file mode 100644 index f607a685414..00000000000 --- a/Generals/Code/Libraries/Source/WWVegas/WWMath/plane.h +++ /dev/null @@ -1,250 +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 . -*/ - -/* $Header: /Commando/Code/wwmath/plane.h 16 5/05/01 5:48p Jani_p $ */ -/*********************************************************************************************** - *** Confidential - Westwood Studios *** - *********************************************************************************************** - * * - * Project Name : Voxel Technology * - * * - * File Name : PLANE.H * - * * - * Programmer : Greg Hjelstrom * - * * - * Start Date : 03/17/97 * - * * - * Last Update : March 17, 1997 [GH] * - * * - *---------------------------------------------------------------------------------------------* - * Functions: * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - -#if defined(_MSC_VER) -#pragma once -#endif - -#ifndef PLANE_H -#define PLANE_H - -#include "always.h" -#include "vector3.h" -#include "sphere.h" - -/* -** PlaneClass -** -** 3D-planes. This class uses the Normal+Distance description of a plane. -** The relationship for all points (p) on the plane is given by: -** -** N.X * p.X + N.Y * p.Y + N.Z * p.Z = D -** -** BEWARE, if you are used to the Ax + By + Cz + D = 0 description, the -** sign of the D value is inverted. -*/ - -class PlaneClass -{ -public: - - enum { FRONT = 0, BACK, ON }; - - Vector3 N; // Normal of the plane - float D; // Distance along the normal from the origin - - PlaneClass(void) : N(0.0f,0.0f,1.0f), D(0.0f) { } - - /* - ** Plane initialization: - ** a,b,c,d - explicitly set the four coefficients (note the sign of d!) - ** normal,dist - explicitly set the normal and distance - ** normal,point - compute plane with normal, containing point - ** p1,p2,p3 - compute plane containing three points - */ - PlaneClass(float nx,float ny,float nz,float dist); - PlaneClass(const Vector3 & normal,float dist); - PlaneClass(const Vector3 & normal,const Vector3 & point); - PlaneClass(const Vector3 & point1,const Vector3 & point2,const Vector3 & point3); - - inline void Set(float a,float b,float c,float d); - inline void Set(const Vector3 & normal,float dist); - inline void Set(const Vector3 & normal,const Vector3 & point); - inline void Set(const Vector3 & point1,const Vector3 & point2,const Vector3 & point3); - - bool Compute_Intersection(const Vector3 & p0,const Vector3 & p1,float * set_t) const; - bool In_Front(const Vector3 & point) const; - bool In_Front(const SphereClass & sphere) const; - bool In_Front_Or_Intersecting(const SphereClass & sphere) const; - - static void Intersect_Planes(const PlaneClass & a, const PlaneClass & b, Vector3 *line_dir, Vector3 *line_point); -}; - -inline PlaneClass::PlaneClass(float nx,float ny,float nz,float dist) -{ - Set(nx,ny,nz,dist); -} - -inline PlaneClass::PlaneClass(const Vector3 & normal,float dist) -{ - Set(normal,dist); -} - -inline PlaneClass::PlaneClass(const Vector3 & normal,const Vector3 & point) -{ - Set(normal,point); -} - -inline PlaneClass::PlaneClass(const Vector3 & point1, const Vector3 & point2, const Vector3 & point3) -{ - Set(point1,point2,point3); -} - -inline void PlaneClass::Set(float a,float b,float c,float d) -{ - N.X = a; - N.Y = b; - N.Z = c; - D = d; -} - -inline void PlaneClass::Set(const Vector3 & normal,float dist) -{ - N = normal; - D = dist; -} - -inline void PlaneClass::Set(const Vector3 & normal,const Vector3 & point) -{ - N = normal; - D = Vector3::Dot_Product(normal , point); -} - - -inline void PlaneClass::Set(const Vector3 & point1, const Vector3 & point2, const Vector3 & point3) -{ -#ifdef ALLOW_TEMPORARIES - N = Vector3::Cross_Product((point2 - point1), (point3 - point1)); -#else - Vector3::Cross_Product((point2 - point1), (point3 - point1), &N); -#endif - if (N != Vector3(0.0f, 0.0f, 0.0f)) { - // Points are not colinear. Normalize N and calculate D. - N.Normalize(); - D = Vector3::Dot_Product(N, point1); - } else { - // They are colinear - return default plane (constructors can't fail). - N = Vector3(0.0f, 0.0f, 1.0f); - D = 0.0f; - } -} - -inline bool PlaneClass::Compute_Intersection(const Vector3 & p0,const Vector3 & p1,float * set_t) const -{ - float num,den; - den = Vector3::Dot_Product(N,p1-p0); - - /* - ** If the denominator is zero, the ray is parallel to the plane - */ - if (den == 0.0f) { - return false; - } - - num = -(Vector3::Dot_Product(N,p0) - D); - - *set_t = num/den; - - /* - ** If t is not between 0 and 1, the line containing the segment intersects - ** the plane but the segment does not - */ - if ((*set_t < 0.0f) || (*set_t > 1.0f)) { - return false; - } - - return true; -} - -inline bool PlaneClass::In_Front(const Vector3 & point) const -{ - float dist = Vector3::Dot_Product(point,N); - return (dist > D); -} - -// This function returns true if the sphere is in front of the plane. -inline bool PlaneClass::In_Front(const SphereClass & sphere) const -{ - float dist = Vector3::Dot_Product(sphere.Center,N); - return ((dist - D) >= sphere.Radius); -} - -// This function will return 1 if any part of the sphere is in front of the plane. -// (i.e. if the sphere is entirely in front of the plane or if it intersects the plane). -inline bool PlaneClass::In_Front_Or_Intersecting(const SphereClass & sphere) const -{ - float dist = Vector3::Dot_Product(sphere.Center , N); - return ((D - dist) < sphere.Radius); -} - -inline void PlaneClass::Intersect_Planes(const PlaneClass & a, const PlaneClass & b, Vector3 *line_dir, Vector3 *line_point) -{ - // Method used is from "plane-to-plane intersection", Graphics Gems III, pp. 233-235. - - // Find line of intersection. First find direction vector of line: - Vector3::Cross_Product(a.N, b.N, line_dir); - - // Now find point on line. How we do it depends on what the largest coordinate of the - // direction vector is. - Vector3 abs_dir = *line_dir; - abs_dir.Update_Max(-abs_dir); - if (abs_dir.X > abs_dir.Y) { - if (abs_dir.X > abs_dir.Z) { - // X largest - float ool = 1.0f / line_dir->X; - line_point->Y = (b.N.Z * a.D - a.N.Z * b.D) * ool; - line_point->Z = (a.N.Y * b.D - b.N.Y * a.D) * ool; - line_point->X = 0.0f; - } else { - // Z largest - float ool = 1.0f / line_dir->Z; - line_point->X = (b.N.Y * a.D - a.N.Y * b.D) * ool; - line_point->Y = (a.N.X * b.D - b.N.X * a.D) * ool; - line_point->Z = 0.0f; - } - } else { - if (abs_dir.Y > abs_dir.Z) { - // Y largest - float ool = 1.0f / line_dir->Y; - line_point->Z = (b.N.X * a.D - a.N.X * b.D) * ool; - line_point->X = (a.N.Z * b.D - b.N.Z * a.D) * ool; - line_point->Y = 0.0f; - } else { - // Z largest - float ool = 1.0f / line_dir->Z; - line_point->X = (b.N.Y * a.D - a.N.Y * b.D) * ool; - line_point->Y = (a.N.X * b.D - b.N.X * a.D) * ool; - line_point->Z = 0.0f; - } - } - - // Normalize direction vector (we do it here because we needed the non-normalized version to - // find the point). - line_dir->Normalize(); -} - -#endif /*PLANE_H*/ diff --git a/Generals/Code/Libraries/Source/WWVegas/WWMath/pot.cpp b/Generals/Code/Libraries/Source/WWVegas/WWMath/pot.cpp deleted file mode 100644 index ea20b93374e..00000000000 --- a/Generals/Code/Libraries/Source/WWVegas/WWMath/pot.cpp +++ /dev/null @@ -1,118 +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 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 : G * - * * - * $Archive:: /G/ww3d/POT.CPP $* - * * - * $Author:: Naty_h $* - * * - * $Modtime:: 12/23/98 7:58a $* - * * - * $Revision:: 3 $* - * * - *-------------------------------------------------------------------------* - * Functions: * - * Find_POT -- finds closest inclusive power of 2 to a value * - * Find_POT_Log2 -- finds log2 of closest inclusive power of 2 to a value* - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - -#include "pot.h" - -/************************************************************************** - * Find_POT -- finds closest inclusive power of 2 to a value * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 10/20/1997 PWG : Created. * - *========================================================================*/ -int Find_POT(int val) -{ - // clear out the recorded position and the recorded count - int recpos = 0; - int reccnt = 0; - - // walk through the value shifting off bits and record the - // position of the highest bit, and whether we have found - // more than one bit. - for (int lp = 0; val; lp++) { - if (val & 1) { - recpos = lp; - reccnt++; - } - val >>= 1; - } - // if we have not found more than one bit then the number - // was the power of two so return it. - if (reccnt < 2) { - return( 1 << recpos); - } - // if we found more than one bit, then the number needs to - // be rounded up to the next highest power of 2. - return( 1 << (recpos + 1)); -} - - -/************************************************************************** - * Find_POT_Log2 -- finds log2 of closest inclusive power of 2 to a value * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 12/23/1998 NH : Created. * - *========================================================================*/ -unsigned int Find_POT_Log2(unsigned int val) -{ - // clear out the recorded position and the recorded count - int recpos = 0; - int reccnt = 0; - - // walk through the value shifting off bits and record the - // position of the highest bit, and whether we have found - // more than one bit. - for (int lp = 0; val; lp++) { - if (val & 1) { - recpos = lp; - reccnt++; - } - val >>= 1; - } - // if we have not found more than one bit then the number - // was the power of two so return it. - if (reccnt < 2) { - return recpos; - } - // if we found more than one bit, then the number needs to - // be rounded up to the next highest power of 2. - return recpos + 1; -} - - diff --git a/Generals/Code/Libraries/Source/WWVegas/WWMath/pot.h b/Generals/Code/Libraries/Source/WWVegas/WWMath/pot.h deleted file mode 100644 index 8b8cff5e902..00000000000 --- a/Generals/Code/Libraries/Source/WWVegas/WWMath/pot.h +++ /dev/null @@ -1,45 +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 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 : G * - * * - * $Archive:: /G/ww3d/POT.H $* - * * - * $Author:: Naty_h $* - * * - * $Modtime:: 12/23/98 7:51a $* - * * - * $Revision:: 4 $* - * * - *-------------------------------------------------------------------------* - * Functions: * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - -#if defined(_MSC_VER) -#pragma once -#endif - -#ifndef __POT_H__ -#define __POT_H__ -int Find_POT(int val); -unsigned int Find_POT_Log2(unsigned int val); -#endif \ No newline at end of file diff --git a/Generals/Code/Libraries/Source/WWVegas/WWMath/quat.cpp b/Generals/Code/Libraries/Source/WWVegas/WWMath/quat.cpp deleted file mode 100644 index 691b24ed2a6..00000000000 --- a/Generals/Code/Libraries/Source/WWVegas/WWMath/quat.cpp +++ /dev/null @@ -1,895 +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 . -*/ - -/* $Header: /Commando/Code/wwmath/quat.cpp 38 8/28/01 10:26a Greg_h $ */ -/*********************************************************************************************** - *** Confidential - Westwood Studios *** - *********************************************************************************************** - * * - * Project Name : Voxel Technology * - * * - * File Name : QUAT.CPP * - * * - * Programmer : Greg Hjelstrom * - * * - * Start Date : 02/24/97 * - * * - * Last Update : February 28, 1997 [GH] * - * * - *---------------------------------------------------------------------------------------------* - * Functions: * - * Quaternion::Quaternion -- constructor * - * Quaternion::Set -- Set the quaternion * - * Quaternion::operator= -- Assignment operator * - * Quaternion::Make_Closest -- Use nearest representation to the given quaternion. * - * Trackball -- Computes a "trackball" quaternion given 2D mouse coordinates * - * Axis_To_Quat -- Creates a quaternion given an axis and angle of rotation * - * Slerp -- Spherical Linear interpolation! * - * Build_Quaternion -- Creates a quaternion from a Matrix * - * Build_Matrix -- Creates a Matrix from a Quaternion * - * Normalize -- normalizes a quaternion * - * Quaternion::Quaternion -- constructor * - * Slerp_Setup -- Get ready to call "Cached_Slerp" * - * Cached_Slerp -- Quaternion slerping, optimized with cached values * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - - -#include "quat.h" -#include "matrix3d.h" -#include "matrix4.h" -#include "wwmath.h" - -#include -#include -#include -#include - -#define SLERP_EPSILON 0.001 - -static int _nxt[3] = { 1 , 2 , 0 }; - - -// ------------------------------------------------------------ -// local functions -// ------------------------------------------------------------ -static float project_to_sphere(float,float,float); - - -/*********************************************************************************************** - * Quaternion::Quaternion -- constructor * - * * - * constructs a quaternion from the given axis and angle of rotation (in RADIANS of course) * - * * - * INPUT: * - * axis - axis of the rotation * - * angle - rotation angle * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 12/10/97 GTH : Created. * - *=============================================================================================*/ -Quaternion::Quaternion(const Vector3 & axis,float angle) -{ - float s = WWMath::Sin(angle/2); - float c = WWMath::Cos(angle/2); - X = s * axis.X; - Y = s * axis.Y; - Z = s * axis.Z; - W = c; -} - - -/*********************************************************************************************** - * Quaternion::Normalize -- Normalize to a unit quaternion * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 02/24/1997 GH : Created. * - *=============================================================================================*/ -void Quaternion::Normalize() -{ - float len2=X * X + Y * Y + Z * Z + W * W; - if (0.0f == len2) { - return; - } else { - float inv_mag = WWMath::Inv_Sqrt(len2); - - X *= inv_mag; - Y *= inv_mag; - Z *= inv_mag; - W *= inv_mag; - } -} - -/*********************************************************************************************** - * Q::Make_Closest -- Use nearest representation to the given quaternion. * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 02/28/1997 GH : Created. * - *=============================================================================================*/ -Quaternion & Quaternion::Make_Closest(const Quaternion & qto) -{ - float cos_t = qto.X * X + qto.Y * Y + qto.Z * Z + qto.W * W; - - // if we are on opposite hemisphere from qto, negate ourselves - if (cos_t < 0.0) { - X = -X; - Y = -Y; - Z = -Z; - W = -W; - } - - return *this; -} - -/*********************************************************************************************** - * Trackball -- Computes a "trackball" quaternion given 2D mouse coordinates * - * * - * INPUT: * - * x0,y0 - x1,y1 - "normalized" mouse coordinates for the mouse movement * - * sphsize - size of the trackball sphere * - * * - * OUTPUT: * - * a quaternion representing the rotation of a trackball * - * * - * WARNINGS: * - * * - * HISTORY: * - * 02/28/1997 GH : Created. * - *=============================================================================================*/ -Quaternion Trackball(float x0, float y0, float x1, float y1, float sphsize) -{ - Vector3 a; - Vector3 p1; - Vector3 p2; - Vector3 d; - - float phi,t; - - if ((x0 == x1) && (y0 == y1)) { - return Quaternion(0.0f, 0.0f, 0.0f, 1.0f); // Zero rotation - } - - - // Compute z coordinates for projection of p1 and p2 to - // deformed sphere - p1[0] = x0; - p1[1] = y0; - p1[2] = project_to_sphere(sphsize, x0, y0); - - p2[0] = x1; - p2[1] = y1; - p2[2] = project_to_sphere(sphsize, x1, y1); - - - // Find their cross product - Vector3::Cross_Product(p2,p1,&a); - - // Compute how much to rotate - d = p1 - p2; - t = d.Length() / (2.0f * sphsize); - - // Avoid problems with out of control values - if (t > 1.0f) t = 1.0f; - if (t < -1.0f) t = -1.0f; - phi = 2.0f * WWMath::Asin(t); - - return Axis_To_Quat(a, phi); -} - - -/*********************************************************************************************** - * Axis_To_Quat -- Creates a quaternion given an axis and angle of rotation * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 02/28/1997 GH : Created. * - *=============================================================================================*/ -Quaternion Axis_To_Quat(const Vector3 &a, float phi) -{ - Quaternion q; - Vector3 tmp = a; - - tmp.Normalize(); - q[0] = tmp[0]; - q[1] = tmp[1]; - q[2] = tmp[2]; - - q.Scale(WWMath::Sin(phi / 2.0f)); - q[3] = WWMath::Cos(phi / 2.0f); - - return q; -} - -/*********************************************************************************************** - * Slerp -- Spherical Linear interpolation! * - * * - * INPUT: * - * p - start quaternion * - * q - end quaternion * - * alpha - interpolating parameter * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 02/28/1997 GH : Created. * - *=============================================================================================*/ - -#if 0 -#pragma warning (disable : 4725) - -#define ARC_TABLE_SIZE_MASK 1023 -#define SIN_TABLE_SIZE_MASK 1023 - -void __cdecl Fast_Slerp(Quaternion& res, const Quaternion & p,const Quaternion & q,float alpha) -{ - float float_epsilon2=WWMATH_EPSILON * WWMATH_EPSILON; - float HalfOfArcTableSize=float(ARC_TABLE_SIZE/2); - float HalfOfSinTableSize=float(SIN_TABLE_SIZE/2); - const unsigned ARC_TABLE_SIZE_PER_2=ARC_TABLE_SIZE/2; - - float beta; // complementary interploation parameter - float theta; // angle between p and q - - __asm { - mov esi, p - mov edi, q - fld1 // we'll need 1.0 and 0.0 later - -// ---------------------------------------------------------------------------- -// cos theta = dot product of p and q -// cos_t = p.X * q.X + p.Y * q.Y + p.Z * q.Z + p.W * q.W; -// if q is on opposite hemisphere from A, use -B instead -// if (cos_t < 0.0) { -// cos_t = -cos_t; -// qflip = true; -// } -// else { -// qflip = false; -// } -// ---------------------------------------------------------------------------- - - fld dword ptr [esi] // p.X - fmul dword ptr [edi] // p.X*q.X - fld dword ptr [esi+08h] // p.Y - fmul dword ptr [edi+08h] // p.Y*q.Y - fld dword ptr [esi+04h] // p.Z - fmul dword ptr [edi+04h] // p.Z*q.Z - fld dword ptr [edi+0ch] // p.W - fmul dword ptr [esi+0ch] // p.W*q.W - faddp st(2), st(0) // y+=w - faddp st(2), st(0) // x+=z - faddp st(1),st(0) // x+z + y+w - fst beta - fabs - mov ebx,beta - and ebx,0x80000000 - -// ---------------------------------------------------------------------------- -// if q is very close to p, just linearly interpolate -// between the two. -// if (1.0 - cos_t < WWMATH_EPSILON * WWMATH_EPSILON) { -// beta = 1.0 - alpha; -// } -// ---------------------------------------------------------------------------- - - fld st(0) // duplicate st(0), which contains cos_t - fsubr st(0),st(2) // st(2) contains 1.0 - fcomp float_epsilon2 - fnstsw ax - test ah, 01h - je normal_slerp - - fld alpha - fsubr st(0),st(1) // st(1) contains 1.0 - fstp beta - jmp done_slerp - -normal_slerp: -// ---------------------------------------------------------------------------- -// normal slerp! -// else { -// theta = WWMath::Acos(cos_t); -// sin_t = WWMath::Sin(theta); -// oo_sin_t = 1.0 / sin_t; -// beta = WWMath::Sin(theta - alpha*theta) * oo_sin_t; -// alpha = WWMath::Sin(alpha*theta) * oo_sin_t; -// } -// if (qflip) { -// alpha = -alpha; -// } -// ---------------------------------------------------------------------------- - - fld HalfOfSinTableSize - fld HalfOfArcTableSize - fmul st(0),st(2) // cos_t * (ARC_TABLE_SIZE/2) - fistp theta // convert to integer - mov eax,theta - add eax,ARC_TABLE_SIZE_PER_2 - jns no_neg - xor eax,eax - jmp contin -no_neg: - cmp eax,ARC_TABLE_SIZE - jl contin // Note: Use Setcc/Movcc here!!! - mov eax,ARC_TABLE_SIZE_MASK -contin: - fld dword ptr[_FastAcosTable+eax*4] - fst theta - - fmul st(0),st(1) // theta * (sin_table_size/2) - fadd st(0),st(1) // theta * (sin_table_size/2) + (sin_table_size/2) - fistp beta // conver to integer - mov ecx,SIN_TABLE_SIZE_MASK - mov eax,beta - and eax,ecx // & SIN_TABLE_SIZE_MASK - fld dword ptr[_FastInvSinTable+eax*4] // 1.0f/sin(theta) - - fld theta - fmul alpha // theta*alpha - fld st(0) // duplicate stack head as we need theta*alpha later - fsubr theta // theta-theta*alpha - - fmul st(0),st(3) // (theta-theta*alpha)*HalfOfSinTableSize - fadd st(0),st(3) // (theta-theta*alpha)*HalfOfSinTableSize+HalfOfSinTableSize - fistp beta // convert to integer - mov eax,beta - and eax,ecx // & SIN_TABLE_SIZE_MASK - fld dword ptr[_FastSinTable+eax*4] // sin(theta-theta*alpha) - - fmul st(0),st(2) // sin(theta-theta*alpha) * oo_sin_t - fstp beta - - fmul st(0),st(2) // (theta*alpha)*HalfOfSinTableSize - fadd st(0),st(2) // (theta*alpha)*HalfOfSinTableSize+HalfOfSinTableSize - fistp theta // convert to integer - mov eax,theta - and eax,ecx // & SIN_TABLE_SIZE_MASK - fld dword ptr[_FastSinTable+eax*4] // sin(theta*alpha) - - fmul st(0),st(1) // oo_sin_t - fstp alpha - fstp st(0) // pop oo_sin_t - fstp st(0) // pop HalfOfSinTableSize -done_slerp: - test ebx, ebx - je no_negative - fld alpha - fchs - fstp alpha - -no_negative: -// ---------------------------------------------------------------------------- -// res.X = beta*p.X + alpha*q.X; -// res.Y = beta*p.Y + alpha*q.Y; -// res.Z = beta*p.Z + alpha*q.Z; -// res.W = beta*p.W + alpha*q.W; -// ---------------------------------------------------------------------------- - - fstp st(0) // pop cos_t - fstp st(0) // pop 1.0 - - fld alpha - fld dword ptr [edi+4] // q.Y - fmul st(0),st(1) // alpha*q.Y - fld dword ptr [edi+8] // q.Z - fmul st(0),st(2) // alpha*q.Z - fld dword ptr [edi+12] // q.W - fmul st(0),st(3) // alpha*q.W - fld dword ptr [edi] // q.X - fmulp st(4),st // alpha*q.X - - fld beta - fld dword ptr [esi+4] // p.Y - fmul st(0),st(1) // beta*p.Y - fld dword ptr [esi+8] // p.Z - fmul st(0),st(2) // beta*p.Z - fld dword ptr [esi] // p.X - fmul st(0),st(3) // beta*p.X - fxch st(3) // move beta to top of stack - fmul dword ptr [esi+12] // beta*p.W - - faddp st(4),st // w - faddp st(4),st // z - faddp st(4),st // y - faddp st(4),st // x - - mov ecx, res - fstp [ecx+12] // w - fstp [ecx+8] // z - fstp [ecx+4] // y - fstp [ecx] // x - } -} -#else -void __cdecl Fast_Slerp(Quaternion& res, const Quaternion & p,const Quaternion & q,float alpha) -{ - float beta; // complementary interploation parameter - float theta; // angle between p and q - float cos_t; // sine, cosine of theta - float oo_sin_t; - int qflip; // use flip of q? - - // cos theta = dot product of p and q - cos_t = p.X * q.X + p.Y * q.Y + p.Z * q.Z + p.W * q.W; - - // if q is on opposite hemisphere from A, use -B instead - if (cos_t < 0.0f) { - cos_t = -cos_t; - qflip = true; - } else { - qflip = false; - } - - if (1.0f - cos_t < WWMATH_EPSILON * WWMATH_EPSILON) { - - // if q is very close to p, just linearly interpolate - // between the two. - beta = 1.0f - alpha; - - } else { - - theta = WWMath::Fast_Acos(cos_t); - float sin_t = WWMath::Fast_Sin(theta); - oo_sin_t = 1.0f / sin_t; - beta = WWMath::Fast_Sin(theta - alpha*theta) * oo_sin_t; - alpha = WWMath::Fast_Sin(alpha*theta) * oo_sin_t; - } - - if (qflip) { - alpha = -alpha; - } - - res.X = beta*p.X + alpha*q.X; - res.Y = beta*p.Y + alpha*q.Y; - res.Z = beta*p.Z + alpha*q.Z; - res.W = beta*p.W + alpha*q.W; -} - -#endif // MSC_VER - -void Slerp(Quaternion& res, const Quaternion & p,const Quaternion & q,float alpha) -{ - float beta; // complementary interploation parameter - float theta; // angle between p and q - //float sin_t - float cos_t; // sine, cosine of theta - float oo_sin_t; - int qflip; // use flip of q? - - // cos theta = dot product of p and q - cos_t = p.X * q.X + p.Y * q.Y + p.Z * q.Z + p.W * q.W; - - // if q is on opposite hemisphere from A, use -B instead - if (cos_t < 0.0f) { - cos_t = -cos_t; - qflip = true; - } else { - qflip = false; - } - - if (1.0f - cos_t < WWMATH_EPSILON * WWMATH_EPSILON) { - - // if q is very close to p, just linearly interpolate - // between the two. - beta = 1.0f - alpha; - - } else { - - // normal slerp! - theta = WWMath::Acos(cos_t); - float sin_t = WWMath::Sin(theta); - oo_sin_t = 1.0f / sin_t; - beta = WWMath::Sin(theta - alpha*theta) * oo_sin_t; - alpha = WWMath::Sin(alpha*theta) * oo_sin_t; - } - - if (qflip) { - alpha = -alpha; - } - - res.X = beta*p.X + alpha*q.X; - res.Y = beta*p.Y + alpha*q.Y; - res.Z = beta*p.Z + alpha*q.Z; - res.W = beta*p.W + alpha*q.W; -} - -/*********************************************************************************************** - * Slerp_Setup -- Get ready to call "Cached_Slerp" * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 2/27/98 GTH : Created. * - *=============================================================================================*/ -void Slerp_Setup(const Quaternion & p,const Quaternion & q,SlerpInfoStruct * slerpinfo) -{ - float cos_t; - - assert(slerpinfo != NULL); - - // cos theta = dot product of p and q - cos_t = p.X * q.X + p.Y * q.Y + p.Z * q.Z + p.W * q.W; - - // if q is on opposite hemisphere from A, use -B instead - if (cos_t < 0.0f) { - cos_t = -cos_t; - slerpinfo->Flip = true; - } else { - slerpinfo->Flip = false; - } - - if (1.0f - cos_t < SLERP_EPSILON) { - - slerpinfo->Linear = true; - slerpinfo->Theta = 0.0f; - slerpinfo->SinT = 0.0f; - - } else { - - slerpinfo->Linear = false; - slerpinfo->Theta = WWMath::Acos(cos_t); - slerpinfo->SinT = WWMath::Sin(slerpinfo->Theta); - - } -} - -/*********************************************************************************************** - * Cached_Slerp -- Quaternion slerping, optimized with cached values * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 2/27/98 GTH : Created. * - *=============================================================================================*/ -Quaternion Cached_Slerp(const Quaternion & p,const Quaternion & q,float alpha,SlerpInfoStruct * slerpinfo) -{ - float beta; // complementary interploation parameter - float oo_sin_t; - - if (slerpinfo->Linear) { - - // if q is very close to p, just linearly interpolate - // between the two. - beta = 1.0f - alpha; - - } else { - - // normal slerp! - oo_sin_t = 1.0f / slerpinfo->Theta; - beta = WWMath::Sin(slerpinfo->Theta - alpha*slerpinfo->Theta) * oo_sin_t; - alpha = WWMath::Sin(alpha*slerpinfo->Theta) * oo_sin_t; - } - - if (slerpinfo->Flip) { - alpha = -alpha; - } - - Quaternion res; - res.X = beta*p.X + alpha*q.X; - res.Y = beta*p.Y + alpha*q.Y; - res.Z = beta*p.Z + alpha*q.Z; - res.W = beta*p.W + alpha*q.W; - - return res; -} - -void Cached_Slerp(const Quaternion & p,const Quaternion & q,float alpha,SlerpInfoStruct * slerpinfo,Quaternion * set_q) -{ - float beta; // complementary interploation parameter - float oo_sin_t; - - if (slerpinfo->Linear) { - - // if q is very close to p, just linearly interpolate - // between the two. - beta = 1.0f - alpha; - - } else { - - // normal slerp! - oo_sin_t = 1.0f / slerpinfo->Theta; - beta = WWMath::Sin(slerpinfo->Theta - alpha*slerpinfo->Theta) * oo_sin_t; - alpha = WWMath::Sin(alpha*slerpinfo->Theta) * oo_sin_t; - } - - if (slerpinfo->Flip) { - alpha = -alpha; - } - - set_q->X = beta*p.X + alpha*q.X; - set_q->Y = beta*p.Y + alpha*q.Y; - set_q->Z = beta*p.Z + alpha*q.Z; - set_q->W = beta*p.W + alpha*q.W; -} - -/*********************************************************************************************** - * Build_Quaternion -- Creates a quaternion from a Matrix * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * Matrix MUST NOT have scaling! * - * * - * HISTORY: * - * 02/28/1997 GH : Created. * - *=============================================================================================*/ -Quaternion Build_Quaternion(const Matrix3D & mat) -{ - float tr,s; - int i,j,k; - Quaternion q; - - // sum the diagonal of the rotation matrix - tr = mat[0][0] + mat[1][1] + mat[2][2]; - - if (tr > 0.0f) { - - s = sqrt(tr + 1.0); - q[3] = s * 0.5; - s = 0.5 / s; - - q[0] = (mat[2][1] - mat[1][2]) * s; - q[1] = (mat[0][2] - mat[2][0]) * s; - q[2] = (mat[1][0] - mat[0][1]) * s; - - } else { - - i=0; - if (mat[1][1] > mat[0][0]) i = 1; - if (mat[2][2] > mat[i][i]) i = 2; - j = _nxt[i]; - k = _nxt[j]; - - s = sqrt((mat[i][i] - (mat[j][j] + mat[k][k])) + 1.0); - - q[i] = s * 0.5; - if (s != 0.0) { - s = 0.5 / s; - } - - q[3] = ( mat[k][j] - mat[j][k] ) * s; - q[j] = ( mat[j][i] + mat[i][j] ) * s; - q[k] = ( mat[k][i] + mat[i][k] ) * s; - - } - - return q; -} - -Quaternion Build_Quaternion(const Matrix3x3 & mat) -{ - float tr,s; - int i,j,k; - Quaternion q; - - // sum the diagonal of the rotation matrix - tr = mat[0][0] + mat[1][1] + mat[2][2]; - - if (tr > 0.0) { - - s = sqrt(tr + 1.0); - q[3] = s * 0.5; - s = 0.5 / s; - - q[0] = (mat[2][1] - mat[1][2]) * s; - q[1] = (mat[0][2] - mat[2][0]) * s; - q[2] = (mat[1][0] - mat[0][1]) * s; - - } else { - - i = 0; - if (mat[1][1] > mat[0][0]) i = 1; - if (mat[2][2] > mat[i][i]) i = 2; - - j = _nxt[i]; - k = _nxt[j]; - - s = sqrt( (mat[i][i] - (mat[j][j]+mat[k][k])) + 1.0); - - q[i] = s * 0.5; - - if (s != 0.0) { - s = 0.5/s; - } - - q[3] = ( mat[k][j] - mat[j][k] ) * s; - q[j] = ( mat[j][i] + mat[i][j] ) * s; - q[k] = ( mat[k][i] + mat[i][k] ) * s; - } - - return q; -} - -Quaternion Build_Quaternion(const Matrix4x4 & mat) -{ - float tr,s; - int i,j,k; - Quaternion q; - - // sum the diagonal of the rotation matrix - tr = mat[0][0] + mat[1][1] + mat[2][2]; - - if (tr > 0.0) { - - s = sqrt(tr + 1.0); - q[3] = s * 0.5; - s = 0.5 / s; - - q[0] = (mat[2][1] - mat[1][2]) * s; - q[1] = (mat[0][2] - mat[2][0]) * s; - q[2] = (mat[1][0] - mat[0][1]) * s; - - } else { - - i = 0; - if (mat[1][1] > mat[0][0]) i = 1; - if (mat[2][2] > mat[i][i]) i = 2; - - j = _nxt[i]; - k = _nxt[j]; - - s = sqrt( (mat[i][i] - (mat[j][j]+mat[k][k])) + 1.0); - - q[i] = s * 0.5; - if (s != 0.0) { - s = 0.5/s; - } - q[3] = ( mat[k][j] - mat[j][k] ) * s; - q[j] = ( mat[j][i] + mat[i][j] ) * s; - q[k] = ( mat[k][i] + mat[i][k] ) * s; - } - - return q; -} - - -/*********************************************************************************************** - * Build_Matrix -- Creates a Matrix from a Quaternion * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 02/28/1997 GH : Created. * - *=============================================================================================*/ -Matrix3x3 Build_Matrix3(const Quaternion & q) -{ - Matrix3x3 m; - - m[0][0] = (float)(1.0 - 2.0 * (q[1] * q[1] + q[2] * q[2])); - m[0][1] = (float)(2.0 * (q[0] * q[1] - q[2] * q[3])); - m[0][2] = (float)(2.0 * (q[2] * q[0] + q[1] * q[3])); - - m[1][0] = (float)(2.0 * (q[0] * q[1] + q[2] * q[3])); - m[1][1] = (float)(1.0 - 2.0f * (q[2] * q[2] + q[0] * q[0])); - m[1][2] = (float)(2.0 * (q[1] * q[2] - q[0] * q[3])); - - m[2][0] = (float)(2.0 * (q[2] * q[0] - q[1] * q[3])); - m[2][1] = (float)(2.0 * (q[1] * q[2] + q[0] * q[3])); - m[2][2] =(float)(1.0 - 2.0 * (q[1] * q[1] + q[0] * q[0])); - - return m; -} - -Matrix4x4 Build_Matrix4(const Quaternion & q) -{ - Matrix4x4 m; - - // initialize the rotation sub-matrix - m[0][0] = (float)(1.0 - 2.0 * (q[1] * q[1] + q[2] * q[2])); - m[0][1] = (float)(2.0 * (q[0] * q[1] - q[2] * q[3])); - m[0][2] = (float)(2.0 * (q[2] * q[0] + q[1] * q[3])); - - m[1][0] = (float)(2.0 * (q[0] * q[1] + q[2] * q[3])); - m[1][1] = (float)(1.0 - 2.0f * (q[2] * q[2] + q[0] * q[0])); - m[1][2] = (float)(2.0 * (q[1] * q[2] - q[0] * q[3])); - - m[2][0] = (float)(2.0 * (q[2] * q[0] - q[1] * q[3])); - m[2][1] = (float)(2.0 * (q[1] * q[2] + q[0] * q[3])); - m[2][2] = (float)(1.0 - 2.0 * (q[1] * q[1] + q[0] * q[0])); - - // no translation - m[0][3] = m[1][3] = m[2][3] = 0.0f; - - // last row - m[3][0] = m[3][1] = m[3][2] = 0.0f; - m[3][3] = 1.0f; - return m; -} - -void Quaternion::Rotate_X(float theta) -{ - // TODO: optimize this - *this = (*this) * Quaternion(Vector3(1,0,0),theta); -} - -void Quaternion::Rotate_Y(float theta) -{ - // TODO: optimize this - *this = (*this) * Quaternion(Vector3(0,1,0),theta); -} - -void Quaternion::Rotate_Z(float theta) -{ - // TODO: optimize this - *this = (*this) * Quaternion(Vector3(0,0,1),theta); -} - -float project_to_sphere(float r, float x, float y) -{ - const float SQRT2 = 1.41421356f; - float t, z; - float d = WWMath::Sqrt(x * x + y * y); - - if (d < r * (SQRT2/(2.0f))) // inside sphere - z = WWMath::Sqrt(r * r - d * d); - else { // on hyperbola - t = r / SQRT2; - z = t * t / d; - } - - return z; -} - - -void Quaternion::Randomize(void) -{ - X = ((float) (rand() & 0xFFFF)) / 65536.0f; - Y = ((float) (rand() & 0xFFFF)) / 65536.0f; - Z = ((float) (rand() & 0xFFFF)) / 65536.0f; - W = ((float) (rand() & 0xFFFF)) / 65536.0f; - - Normalize(); -} - - diff --git a/Generals/Code/Libraries/Source/WWVegas/WWMath/quat.h b/Generals/Code/Libraries/Source/WWVegas/WWMath/quat.h deleted file mode 100644 index 620cd6f8534..00000000000 --- a/Generals/Code/Libraries/Source/WWVegas/WWMath/quat.h +++ /dev/null @@ -1,317 +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 . -*/ - -/* $Header: /Commando/Code/wwmath/quat.h 29 5/11/01 7:11p Jani_p $ */ -/*************************************************************************** - *** Confidential - Westwood Studios *** - *************************************************************************** - * * - * Project Name : Voxel Technology * - * * - * File Name : QUAT.H * - * * - * Programmer : Greg Hjelstrom * - * * - * Start Date : 02/24/97 * - * * - * Last Update : February 24, 1997 [GH] * - * * - *-------------------------------------------------------------------------* - * Functions: * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - -#if defined(_MSC_VER) -#pragma once -#endif - -#ifndef QUAT_H -#define QUAT_H - -#include "always.h" -#include "wwmath.h" -#include "matrix3.h" -#include "vector3.h" -#include "matrix3d.h" - - -class Quaternion -{ -private: - -public: - - // X,Y,Z are the imaginary parts of the quaterion - // W is the real part - float X; - float Y; - float Z; - float W; - -public: - - WWINLINE Quaternion(void) {}; - WWINLINE explicit Quaternion(bool init) { if (init) { X = 0.0f; Y = 0.0f; Z = 0.0f; W = 1.0f; } } - WWINLINE explicit Quaternion(float a, float b, float c, float d) { X=a; Y=b; Z=c; W=d; } - WWINLINE explicit Quaternion(const Vector3 & axis,float angle); - WWINLINE Quaternion & operator=(const Quaternion & source); - - WWINLINE void Set(float a = 0.0, float b = 0.0, float c = 0.0, float d = 1.0) { X = a; Y = b; Z = c; W = d; } - WWINLINE void Make_Identity(void) { Set(); }; - WWINLINE void Scale(float s) { X = (float)(s*X); Y = (float)(s*Y); Z = (float)(s*Z); W = (float)(s*W); } - - // Array access - WWINLINE float & operator [](int i) { return (&X)[i]; } - WWINLINE const float & operator [](int i) const { return (&X)[i]; } - - // Unary operators. - // Remember that q and -q represent the same 3D rotation. - WWINLINE Quaternion operator-() const { return(Quaternion(-X,-Y,-Z,-W)); } - WWINLINE Quaternion operator+() const { return *this; } - - // Every 3D rotation can be expressed by two different quaternions, This - // function makes the current quaternion convert itself to the representation - // which is closer on the 4D unit-hypersphere to the given quaternion. - Quaternion & Make_Closest(const Quaternion & qto); - - // Square of the magnitude of the quaternion - WWINLINE float Length2(void) const { return (X*X + Y*Y + Z*Z + W*W); } - - // Magnitude of the quaternion - WWINLINE float Length(void) const { return WWMath::Sqrt(Length2()); } - - // Make the quaternion unit length - void Normalize(void); - - // post-concatenate rotations about the coordinate axes - void Rotate_X(float theta); - void Rotate_Y(float theta); - void Rotate_Z(float theta); - - // initialize this quaternion randomly (creates a random *unit* quaternion) - void Randomize(void); - - // transform (rotate) a vector with this quaternion - WWINLINE Vector3 Rotate_Vector(const Vector3 & v) const; - WWINLINE void Rotate_Vector(const Vector3 & v,Vector3 * set_result) const; - - // verify that none of the members of this quaternion are invalid floats - bool Is_Valid(void) const; -}; - -// Inverse of the quaternion (1/q) -WWINLINE Quaternion Inverse(const Quaternion & a) -{ - return Quaternion(-a[0],-a[1],-a[2],a[3]); -} - -// Conjugate of the quaternion -WWINLINE Quaternion Conjugate(const Quaternion & a) -{ - return Quaternion(-a[0],-a[1],-a[2],a[3]); -} - -// Add two quaternions -WWINLINE Quaternion operator + (const Quaternion & a,const Quaternion & b) -{ - return Quaternion(a[0] + b[0], a[1] + b[1], a[2] + b[2], a[3] + b[3]); -} - -// Subract two quaternions -WWINLINE Quaternion operator - (const Quaternion & a,const Quaternion & b) -{ - return Quaternion(a[0] - b[0], a[1] - b[1], a[2] - b[2], a[3] - b[3]); -} - -// Multiply a quaternion by a scalar: -WWINLINE Quaternion operator * (float scl, const Quaternion & a) -{ - return Quaternion(scl*a[0], scl*a[1], scl*a[2], scl*a[3]); -} - -// Multiply a quaternion by a scalar -WWINLINE Quaternion operator * (const Quaternion & a, float scl) -{ - return scl*a; -} - -// Multiply two quaternions -WWINLINE Quaternion operator * (const Quaternion & a,const Quaternion & b) -{ - return Quaternion - ( - a.W*b.X + b.W*a.X + (a.Y*b.Z - b.Y*a.Z), - a.W*b.Y + b.W*a.Y - (a.X*b.Z - b.X*a.Z), - a.W*b.Z + b.W*a.Z + (a.X*b.Y - b.X*a.Y), - a.W * b.W - (a.X * b.X + a.Y * b.Y + a.Z * b.Z) - ); -} - -// Divide two quaternions -WWINLINE Quaternion operator / (const Quaternion & a,const Quaternion & b) -{ - return a * Inverse(b); -} - -// Normalized version of the quaternion -WWINLINE Quaternion Normalize(const Quaternion & a) -{ - float mag = a.Length(); - if (0.0f == mag) { - return a; - } else { - float oomag = 1.0f / mag; - return Quaternion(a[0] * oomag, a[1] * oomag, a[2] * oomag, a[3] * oomag); - } -} - -// This function computes a quaternion based on an axis -// (defined by the given Vector a) and an angle about -// which to rotate. The angle is expressed in radians. -Quaternion Axis_To_Quat(const Vector3 &a, float angle); - -// Pass the x and y coordinates of the last and current position -// of the mouse, scaled so they are from -1.0 to 1.0 -// The quaternion is the computed as the rotation of a trackball -// between the two points projected onto a sphere. This can -// be used to implement an intuitive viewing control system. -Quaternion Trackball(float x0, float y0, float x1, float y1, float sphsize); - -// Spherical Linear interpolation of quaternions -//Quaternion Slerp(const Quaternion & a,const Quaternion & b,float t); -void __cdecl Slerp(Quaternion& result, const Quaternion & a,const Quaternion & b,float t); -// Fast slerp is innaccurate but multiple times faster -void __cdecl Fast_Slerp(Quaternion& result, const Quaternion & a,const Quaternion & b,float t); - -// Convert a rotation matrix into a quaternion -Quaternion Build_Quaternion(const Matrix3x3 & matrix); -Quaternion Build_Quaternion(const Matrix3D & matrix); -Quaternion Build_Quaternion(const Matrix4x4 & matrix); - -// Convert a quaternion into a rotation matrix -Matrix3x3 Build_Matrix3(const Quaternion & quat); -Matrix3D &Build_Matrix3D(const Quaternion & q, Matrix3D &out); -WWINLINE Matrix3D &Build_Matrix3D(const Quaternion & q, Matrix3D &out) -{ - out[0][0] = (float)(1.0 - 2.0 * (q[1] * q[1] + q[2] * q[2])); - out[0][1] = (float)(2.0 * (q[0] * q[1] - q[2] * q[3])); - out[0][2] = (float)(2.0 * (q[2] * q[0] + q[1] * q[3])); - - out[1][0] = (float)(2.0 * (q[0] * q[1] + q[2] * q[3])); - out[1][1] = (float)(1.0 - 2.0f * (q[2] * q[2] + q[0] * q[0])); - out[1][2] = (float)(2.0 * (q[1] * q[2] - q[0] * q[3])); - - out[2][0] = (float)(2.0 * (q[2] * q[0] - q[1] * q[3])); - out[2][1] = (float)(2.0 * (q[1] * q[2] + q[0] * q[3])); - out[2][2] =(float)(1.0 - 2.0 * (q[1] * q[1] + q[0] * q[0])); - - // no translation - out[0][3] = out[1][3] = out[2][3] = 0.0f; - - return out; -} - -Matrix4x4 Build_Matrix4(const Quaternion & quat); - - -// Some values can be cached if you are performing multiple slerps -// between the same two quaternions... -struct SlerpInfoStruct -{ - float SinT; - float Theta; - bool Flip; - bool Linear; -}; - -// Cached slerp implementation -void Slerp_Setup(const Quaternion & p,const Quaternion & q,SlerpInfoStruct * slerpinfo); -void Cached_Slerp(const Quaternion & p,const Quaternion & q,float alpha,SlerpInfoStruct * slerpinfo,Quaternion * set_q); -Quaternion Cached_Slerp(const Quaternion & p,const Quaternion & q,float alpha,SlerpInfoStruct * slerpinfo); - -WWINLINE Vector3 Quaternion::Rotate_Vector(const Vector3 & v) const -{ - float x = W*v.X + (Y*v.Z - v.Y*Z); - float y = W*v.Y - (X*v.Z - v.X*Z); - float z = W*v.Z + (X*v.Y - v.X*Y); - float w = -(X*v.X + Y*v.Y + Z*v.Z); - - return Vector3 - ( - w*(-X) + W*x + (y*(-Z) - (-Y)*z), - w*(-Y) + W*y - (x*(-Z) - (-X)*z), - w*(-Z) + W*z + (x*(-Y) - (-X)*y) - ); -} - -WWINLINE void Quaternion::Rotate_Vector(const Vector3 & v,Vector3 * result) const -{ - assert(result != NULL); - - float x = W*v.X + (Y*v.Z - v.Y*Z); - float y = W*v.Y - (X*v.Z - v.X*Z); - float z = W*v.Z + (X*v.Y - v.X*Y); - float w = -(X*v.X + Y*v.Y + Z*v.Z); - - result->X = w*(-X) + W*x + (y*(-Z) - (-Y)*z); - result->Y = w*(-Y) + W*y - (x*(-Z) - (-X)*z); - result->Z = w*(-Z) + W*z + (x*(-Y) - (-X)*y); -} - -WWINLINE bool Quaternion::Is_Valid(void) const -{ - return ( WWMath::Is_Valid_Float(X) && - WWMath::Is_Valid_Float(Y) && - WWMath::Is_Valid_Float(Z) && - WWMath::Is_Valid_Float(W) ); -} - -WWINLINE bool Equal_Within_Epsilon(const Quaternion &a, const Quaternion &b, float epsilon) -{ - return( (WWMath::Fabs(a.X - b.X) < epsilon) && - (WWMath::Fabs(a.Y - b.Y) < epsilon) && - (WWMath::Fabs(a.Z - b.Z) < epsilon) && - (WWMath::Fabs(a.W - b.W) < epsilon) ); -} - -/*********************************************************************************************** - * Quaternion::operator= -- Assignment operator * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 02/24/1997 GH : Created. * - *=============================================================================================*/ -WWINLINE Quaternion & Quaternion::operator = (const Quaternion & source) -{ - X = source[0]; - Y = source[1]; - Z = source[2]; - W = source[3]; - - return *this; -} - - -#endif /* QUAT_H */ - - - diff --git a/Generals/Code/Libraries/Source/WWVegas/WWMath/rect.h b/Generals/Code/Libraries/Source/WWVegas/WWMath/rect.h deleted file mode 100644 index 116a253c25e..00000000000 --- a/Generals/Code/Libraries/Source/WWVegas/WWMath/rect.h +++ /dev/null @@ -1,108 +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 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 : WWMath * - * * - * $Archive:: /Commando/Code/wwmath/rect.h $* - * * - * Author:: Byon Garrabrant * - * * - * $Modtime:: 4/16/01 10:01a $* - * * - * $Revision:: 9 $* - * * - *---------------------------------------------------------------------------------------------* - * Functions: * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - - -#if defined(_MSC_VER) -#pragma once -#endif - -#ifndef RECT_H -#define RECT_H - -#include "vector2.h" - -class RectClass -{ -public: - float Left; - float Top; - float Right; - float Bottom; - - // Constructors - RectClass( void ) {}; - RectClass( const RectClass & r ) { Left = r.Left; Top = r.Top; Right = r.Right; Bottom = r.Bottom; } - RectClass( float left, float top, float right, float bottom ) { Left = left; Top = top; Right = right; Bottom = bottom; } - RectClass( const Vector2 & top_left, const Vector2 & bottom_right ) { Left = top_left.X; Top = top_left.Y; Right = bottom_right.X; Bottom = bottom_right.Y; } - - // Assignment - RectClass & operator = (const RectClass & r) { Left = r.Left; Top = r.Top; Right = r.Right; Bottom = r.Bottom; return *this; } - void Set(float left, float top, float right, float bottom) { Left = left; Top = top; Right = right; Bottom = bottom; } - void Set( const Vector2 & top_left, const Vector2 & bottom_right ) { Left = top_left.X; Top = top_left.Y; Right = bottom_right.X; Bottom = bottom_right.Y; } - void Set(const RectClass & r) { Left = r.Left; Top = r.Top; Right = r.Right; Bottom = r.Bottom; } - - // Access - float Width(void) const { return Right - Left; } - float Height(void) const { return Bottom - Top; } - Vector2 Center( void ) const { return Vector2( (Left + Right)/2, (Top + Bottom)/2 ); } - Vector2 Extent( void ) const { return Vector2( (Right - Left)/2, (Bottom - Top)/2 ); } - Vector2 Upper_Left( void ) const { return Vector2( Left, Top ); } - Vector2 Lower_Right( void ) const { return Vector2( Right, Bottom ); } - Vector2 Upper_Right( void ) const { return Vector2( Right, Top ); } - Vector2 Lower_Left( void ) const { return Vector2( Left, Bottom ); } - - // Scaling - RectClass & operator *= (float k) { return Scale( k ); } - RectClass & operator /= (float k) { return Scale( 1/k ); } - RectClass & Scale_Relative_Center( float k ) { Vector2 center = Center(); *this-=center; Left*=k; Top*=k; Right*=k; Bottom*=k; *this+=center; return *this; } - RectClass & Scale( float k ) { Left*=k; Top*=k; Right*=k; Bottom*=k; return *this; } - RectClass & Scale( const Vector2 &k ) { Left*=k.X; Top*=k.Y; Right*=k.X; Bottom*=k.Y; return *this; } - RectClass & Inverse_Scale( const Vector2 &k ) { Left/=k.X; Top/=k.Y; Right/=k.X; Bottom/=k.Y; return *this; } - - // Offset - RectClass & operator += ( const Vector2 & o ) { Left+=o.X; Top+=o.Y; Right+=o.X; Bottom+=o.Y; return *this; } - RectClass & operator -= ( const Vector2 & o ) { Left-=o.X; Top-=o.Y; Right-=o.X; Bottom-=o.Y; return *this; } - - // Inflate - void Inflate( const Vector2 & o ) { Left-=o.X; Top-=o.Y; Right+=o.X; Bottom+=o.Y; } - - // Union - RectClass & operator += ( const RectClass & r ) { Left=MIN(Left,r.Left); Top=MIN(Top,r.Top); Right=MAX(Right,r.Right); Bottom=MAX(Bottom,r.Bottom); return *this; } - - // Equality - bool operator == ( const RectClass &rval ) const { return (rval.Left == Left) && (rval.Right == Right) && (rval.Top == Top) && (rval.Bottom == Bottom); } - bool operator != ( const RectClass &rval ) const { return (rval.Left != Left) || (rval.Right != Right) || (rval.Top != Top) || (rval.Bottom != Bottom); } - - // Containment - bool Contains ( const Vector2 &pos ) const { return (pos.X >= Left) && (pos.X <= Right) && (pos.Y >= Top) && (pos.Y <= Bottom); } - - // Misc - void Snap_To_Units( const Vector2 & u ) { Left = (int)(Left / u.X + 0.5f) * u.X; Right = (int)(Right / u.X + 0.5f) * u.X; Top = (int)(Top / u.Y + 0.5f) * u.Y; Bottom = (int)(Bottom / u.Y + 0.5f) * u.Y; } - -}; - -#endif - diff --git a/Generals/Code/Libraries/Source/WWVegas/WWMath/sphere.h b/Generals/Code/Libraries/Source/WWVegas/WWMath/sphere.h deleted file mode 100644 index bb19d36fed0..00000000000 --- a/Generals/Code/Libraries/Source/WWVegas/WWMath/sphere.h +++ /dev/null @@ -1,552 +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 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 : wwmath * - * * - * $Archive:: /Commando/Code/WWMath/sphere.h $* - * * - * Author:: Greg_h * - * * - * $Modtime:: 3/29/01 10:37a $* - * * - * $Revision:: 18 $* - * * - *---------------------------------------------------------------------------------------------* - * Functions: * - * SphereClass::SphereClass -- constructor * - * SphereClass::Init -- assign a new center and radius to this sphere * - * SphereClass::Re_Center -- move the center, update radius to enclose old sphere * - * SphereClass::Add_Sphere -- expands 'this' sphere to enclose the given sphere * - * SphereClass::Transform -- transforms this sphere * - * SphereClass::Volume -- returns the volume of this sphere * - * SphereClass::operator+= -- 'Add' a sphere to this one * - * SphereClass::operator *= -- transform this sphere by the given radius * - * Spheres_Intersect -- test whether two spheres intersect * - * Add_Spheres -- Add two spheres together, creating sphere which encloses both * - * operator + -- Add two spheres together, creating a sphere which encloses both * - * Transform Sphere -- transform a sphere * - * Transform_Sphere -- transform a sphere * - * operator * -- Transform a sphere * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - - -#if defined(_MSC_VER) -#pragma once -#endif - -#ifndef SPHERE_H -#define SPHERE_H - -#include "always.h" -#include "vector3.h" -#include "matrix3d.h" - - -///////////////////////////////////////////////////////////////////// -// SphereClass -// -// Center - center of the sphere. -// Radius - radius of the sphere -// -///////////////////////////////////////////////////////////////////// -class SphereClass -{ -public: - inline SphereClass(void) { }; - inline SphereClass(const Vector3 & center,float radius) { Init(center,radius); } - inline SphereClass(const Matrix3D& mtx,const Vector3 & center,float radius) { Init(mtx,center,radius); } - inline SphereClass(const Vector3 & center,const SphereClass & s0); - inline SphereClass(const Vector3 *Position, const int VertCount); - - inline void Init(const Vector3 & pos,float radius); - inline void Init(const Matrix3D& mtx,const Vector3 & pos,float radius); - inline void Re_Center(const Vector3 & center); - inline void Add_Sphere(const SphereClass & s); - inline void Transform(const Matrix3D & tm); - inline float Volume(void) const; - - inline SphereClass & operator += (const SphereClass & s); - inline SphereClass & operator *= (const Matrix3D & m); - - Vector3 Center; - float Radius; -}; - - -/*********************************************************************************************** - * SphereClass::SphereClass -- constructor * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 8/12/98 GTH : Created. * - *=============================================================================================*/ -inline SphereClass::SphereClass(const Vector3 & center,const SphereClass & s0) -{ - float dist = (s0.Center - center).Length(); - Center = center; - Radius = s0.Radius + dist; -} - -inline SphereClass::SphereClass(const Vector3 *Position,const int VertCount) -{ - int i; - double dx,dy,dz; - - // bounding sphere - // Using the algorithm described in Graphics Gems I page 301. - // This algorithm supposedly generates a bounding sphere within - // 5% of the optimal one but is much faster and simpler to implement. - Vector3 xmin(Position[0].X,Position[0].Y,Position[0].Z); - Vector3 xmax(Position[0].X,Position[0].Y,Position[0].Z); - Vector3 ymin(Position[0].X,Position[0].Y,Position[0].Z); - Vector3 ymax(Position[0].X,Position[0].Y,Position[0].Z); - Vector3 zmin(Position[0].X,Position[0].Y,Position[0].Z); - Vector3 zmax(Position[0].X,Position[0].Y,Position[0].Z); - - - // FIRST PASS: - // finding the 6 minima and maxima points - for (i=1; i xmax.X) { - xmax.X = Position[i].X; xmax.Y = Position[i].Y; xmax.Z = Position[i].Z; - } - if (Position[i].Y < ymin.Y) { - ymin.X = Position[i].X; ymin.Y = Position[i].Y; ymin.Z = Position[i].Z; - } - if (Position[i].Y > ymax.Y) { - ymax.X = Position[i].X; ymax.Y = Position[i].Y; ymax.Z = Position[i].Z; - } - if (Position[i].Z < zmin.Z) { - zmin.X = Position[i].X; zmin.Y = Position[i].Y; zmin.Z = Position[i].Z; - } - if (Position[i].Z > zmax.Z) { - zmax.X = Position[i].X; zmax.Y = Position[i].Y; zmax.Z = Position[i].Z; - } - } - - // xspan = distance between the 2 points xmin and xmax squared. - // same goes for yspan and zspan. - dx = xmax.X - xmin.X; - dy = xmax.Y - xmin.Y; - dz = xmax.Z - xmin.Z; - double xspan = dx*dx + dy*dy + dz*dz; - - dx = ymax.X - ymin.X; - dy = ymax.Y - ymin.Y; - dz = ymax.Z - ymin.Z; - double yspan = dx*dx + dy*dy + dz*dz; - - dx = zmax.X - zmin.X; - dy = zmax.Y - zmin.Y; - dz = zmax.Z - zmin.Z; - double zspan = dx*dx + dy*dy + dz*dz; - - - // Set points dia1 and dia2 to the maximally separated pair - // This will be the diameter of the initial sphere - Vector3 dia1 = xmin; - Vector3 dia2 = xmax; - double maxspan = xspan; - - if (yspan > maxspan) { - maxspan = yspan; - dia1 = ymin; - dia2 = ymax; - } - if (zspan > maxspan) { - maxspan = zspan; - dia1 = zmin; - dia2 = zmax; - } - - - // Compute initial center and radius and radius squared - Vector3 center; - center.X = (dia1.X + dia2.X) / 2.0f; - center.Y = (dia1.Y + dia2.Y) / 2.0f; - center.Z = (dia1.Z + dia2.Z) / 2.0f; - - dx = dia2.X - center.X; - dy = dia2.Y - center.Y; - dz = dia2.Z - center.Z; - - double radsqr = dx*dx + dy*dy + dz*dz; - double radius = sqrt(radsqr); - - - // SECOND PASS: - // Increment current sphere if any points fall outside of it. - for (i=0; i radsqr) { - - // this point was outside the old sphere, compute a new - // center point and radius which contains this point - double testrad = sqrt(testrad2); - - // adjust center and radius - radius = (radius + testrad) / 2.0; - radsqr = radius * radius; - - double oldtonew = testrad - radius; - center.X = (radius * center.X + oldtonew * Position[i].X) / testrad; - center.Y = (radius * center.Y + oldtonew * Position[i].Y) / testrad; - center.Z = (radius * center.Z + oldtonew * Position[i].Z) / testrad; - } - } - - Center = center; - Radius = radius; -} - - -/*********************************************************************************************** - * SphereClass::Init -- assign a new center and radius to this sphere * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 8/12/98 GTH : Created. * - *=============================================================================================*/ -inline void SphereClass::Init(const Vector3 & pos,float radius) -{ - Center = pos; - Radius = radius; -} - -/*********************************************************************************************** - * SphereClass::Init -- assign a new center and radius to this sphere * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 8/12/98 GTH : Created. * - *=============================================================================================*/ -inline void SphereClass::Init(const Matrix3D& mtx, const Vector3 & pos,float radius) -{ -#ifdef ALLOW_TEMPORARIES - Center = mtx * pos; -#else - mtx.mulVector3(pos, Center); -#endif - Radius = radius; -} - - -/*********************************************************************************************** - * SphereClass::Re_Center -- move the center, update radius to enclose old sphere * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 8/12/98 GTH : Created. * - *=============================================================================================*/ -inline void SphereClass::Re_Center(const Vector3 & center) -{ - float dist = (Center - center).Length(); - Center = center; - Radius += dist; -} - - -/*********************************************************************************************** - * SphereClass::Add_Sphere -- expands 'this' sphere to enclose the given sphere * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 8/12/98 GTH : Created. * - *=============================================================================================*/ -inline void SphereClass::Add_Sphere(const SphereClass & s) -{ - if (s.Radius == 0.0f) return; - - float dist = (s.Center - Center).Length(); - if (dist == 0.0f) { - Radius = (Radius > s.Radius) ? Radius : s.Radius; - return; - } - - float rnew = (dist + Radius + s.Radius) / 2.0f; - - // If rnew is smaller than either of the two sphere radii (it can't be - // smaller than both of them), this means that the smaller sphere is - // completely inside the larger, and the result of adding the two is - // simply the larger sphere. If rnew isn't less than either of them, it is - // the new radius - calculate the new center. - if (rnew < Radius) { - // The existing sphere is the result - do nothing. - } else { - if (rnew < s.Radius) { - // The new sphere is the result: - Init(s.Center, s.Radius); - } else { - // Neither sphere is completely inside the other, so rnew is the new - // radius - calculate the new center - float lerp = (rnew - Radius) / dist; - Vector3 center = (s.Center - Center) * lerp + Center; - Init(center, rnew); - } - } -} - -/*********************************************************************************************** - * SphereClass::Transform -- transforms this sphere * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 3/12/99 GTH : Created. * - *=============================================================================================*/ -inline void SphereClass::Transform(const Matrix3D & tm) -{ - // warning, assumes Orthogonal matrix -#ifdef ALLOW_TEMPORARIES - Center = tm * Center; -#else - tm.mulVector3(Center, Center); -#endif -} - - -/*********************************************************************************************** - * SphereClass::Volume -- returns the volume of this sphere * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 3/22/99 GTH : Created. * - *=============================================================================================*/ -inline float SphereClass::Volume(void) const -{ - return (4.0 / 3.0) * WWMATH_PI * (Radius * Radius * Radius); -} - -/*********************************************************************************************** - * SphereClass::operator+= -- 'Add' a sphere to this one * - * * - * Expands 'this' sphere to also enclose the given sphere * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 8/12/98 GTH : Created. * - *=============================================================================================*/ -inline SphereClass & SphereClass::operator += (const SphereClass & s) -{ - Add_Sphere(s); - return *this; -} - - -/*********************************************************************************************** - * SphereClass::operator *= -- transform this sphere by the given radius * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 8/12/98 GTH : Created. * - *=============================================================================================*/ -inline SphereClass & SphereClass::operator *= (const Matrix3D & m) -{ - Init(m, Center, Radius); - return *this; -} - - -/*********************************************************************************************** - * Spheres_Intersect -- test whether two spheres intersect * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 8/12/98 GTH : Created. * - *=============================================================================================*/ -inline bool Spheres_Intersect(const SphereClass & s0,const SphereClass & s1) -{ - Vector3 delta = s0.Center - s1.Center; - float dist2 = Vector3::Dot_Product(delta, delta); - - if (dist2 < (s0.Radius + s1.Radius) * (s0.Radius + s1.Radius)) { - return true; - } else { - return false; - } -} - - -/*********************************************************************************************** - * Add_Spheres -- Add two spheres together, creating sphere which encloses both * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 8/12/98 GTH : Created. * - *=============================================================================================*/ -inline SphereClass Add_Spheres(const SphereClass & s0, const SphereClass & s1) -{ - if (s0.Radius == 0.0f) { - return s1; - } else { - SphereClass result(s0); - result.Add_Sphere(s1); - return result; - } -} - - -/*********************************************************************************************** - * operator + -- Add two spheres together, creating a sphere which encloses both * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 8/12/98 GTH : Created. * - *=============================================================================================*/ -inline SphereClass operator + (const SphereClass & s0,const SphereClass & s1) -{ - return Add_Spheres(s0,s1); -} - - -/*********************************************************************************************** - * Transform Sphere -- transform a sphere * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 8/12/98 GTH : Created. * - *=============================================================================================*/ -inline SphereClass Transform_Sphere(const Matrix3D & m, const SphereClass & s) -{ - // Warning, assumes Orthogonal matrix - return SphereClass(m,s.Center,s.Radius); -} - - -/*********************************************************************************************** - * Transform_Sphere -- transform a sphere * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 8/12/98 GTH : Created. * - *=============================================================================================*/ -inline void Transform_Sphere(const Matrix3D & m, const SphereClass & s,SphereClass & res) -{ - // warning, assumes Orthogonal matrix -#ifdef ALLOW_TEMPORARIES - res.Center = m*s.Center; -#else - m.mulVector3(s.Center, res.Center); -#endif - res.Radius = s.Radius; -} - - -/*********************************************************************************************** - * operator * -- Transform a sphere * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 8/12/98 GTH : Created. * - *=============================================================================================*/ -inline SphereClass operator * (const Matrix3D & m, const SphereClass & s) -{ - return Transform_Sphere(m,s); -} - - - -#endif - diff --git a/Generals/Code/Libraries/Source/WWVegas/WWMath/tcbspline.cpp b/Generals/Code/Libraries/Source/WWVegas/WWMath/tcbspline.cpp deleted file mode 100644 index 85ad2bd083d..00000000000 --- a/Generals/Code/Libraries/Source/WWVegas/WWMath/tcbspline.cpp +++ /dev/null @@ -1,248 +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 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 : WWMath * - * * - * $Archive:: /VSS_Sync/wwmath/tcbspline.cpp $* - * * - * Author:: Greg Hjelstrom * - * * - * $Modtime:: 6/13/01 2:18p $* - * * - * $Revision:: 6 $* - * * - *---------------------------------------------------------------------------------------------* - * Functions: * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - - -#include "tcbspline.h" -#include "wwdebug.h" -#include "persistfactory.h" -#include "wwmathids.h" -#include "wwhack.h" - - -/* -** Force-Link this module because the linker can't detect that we actually need it... -*/ -DECLARE_FORCE_LINK(tcbspline); - -/* -** Save-Load stuff -*/ -SimplePersistFactoryClass _TCBSpline3DFactory; - -enum -{ - // ID's used by TCBSpline3D - TCB3D_CHUNK_HERMITE3D = 0x02071009, - TCB3D_CHUNK_PARAMS, -}; - - -/* -** TCBSpline3DClass Implemenation -*/ - -int TCBSpline3DClass::Add_Key(const Vector3 & point,float t) -{ - int index; - index = HermiteSpline3DClass::Add_Key(point,t); - - TCBClass params; - params.Tension = 0.0f; - params.Continuity = 0.0f; - params.Bias = 0.0f; - Params.Insert(index,params); - return index; -} - -void TCBSpline3DClass::Remove_Key(int i) -{ - HermiteSpline3DClass::Remove_Key(i); - Params.Delete(i); -} - -void TCBSpline3DClass::Clear_Keys(void) -{ - HermiteSpline3DClass::Clear_Keys(); - Params.Clear(); -} - -void TCBSpline3DClass::Set_TCB_Params(int i,float tension,float continuity,float bias) -{ - WWASSERT(i >= 0); - WWASSERT(i < Params.Count()); - Params[i].Tension = tension; - Params[i].Continuity = continuity; - Params[i].Bias = bias; - TangentsDirty = true; -} - -void TCBSpline3DClass::Get_TCB_Params(int i,float *tension,float *continuity,float *bias) -{ - if (tension) *tension = Params[i].Tension; - if (continuity) *continuity = Params[i].Continuity; - if (bias) *bias = Params[i].Bias; -} - -void TCBSpline3DClass::Update_Tangents(void) -{ - if (Keys.Count() < 2) { - for (int i=0; i. -*/ - -/*********************************************************************************************** - *** 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 : WWMath * - * * - * $Archive:: /VSS_Sync/wwmath/tcbspline.h $* - * * - * Author:: Greg Hjelstrom * - * * - * $Modtime:: 6/13/01 2:18p $* - * * - * $Revision:: 4 $* - * * - *---------------------------------------------------------------------------------------------* - * Functions: * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - - -#if defined(_MSC_VER) -#pragma once -#endif - -#ifndef TCBSPLINE_H -#define TCBSPLINE_H - -#include "hermitespline.h" - -/* -** TCBSpline3DClass -** Tension-Continuity-Bias splines. Otherwise known as Kochanek-Bartels cubic splines -*/ -class TCBSpline3DClass : public HermiteSpline3DClass -{ -public: - - virtual int Add_Key(const Vector3 & point,float t); - virtual void Remove_Key(int i); - virtual void Clear_Keys(void); - - virtual void Set_TCB_Params(int i,float tension,float continuity,float bias); - virtual void Get_TCB_Params(int i,float *tension,float *continuity,float *bias); - - void Update_Tangents(void); - - // save-load support - virtual const PersistFactoryClass & Get_Factory(void) const; - virtual bool Save(ChunkSaveClass &csave); - virtual bool Load(ChunkLoadClass &cload); - -protected: - - class TCBClass - { - public: - float Tension; - float Continuity; - float Bias; - bool operator == (const TCBClass & that) { return ((Tension == that.Tension) && (Continuity == that.Continuity) && (Bias == that.Bias)); } - bool operator != (const TCBClass & that) { return !TCBClass::operator == (that); } - }; - - DynamicVectorClass Params; -}; - - -#endif - diff --git a/Generals/Code/Libraries/Source/WWVegas/WWMath/tri.cpp b/Generals/Code/Libraries/Source/WWVegas/WWMath/tri.cpp deleted file mode 100644 index f450b9187df..00000000000 --- a/Generals/Code/Libraries/Source/WWVegas/WWMath/tri.cpp +++ /dev/null @@ -1,363 +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 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 : WWMath * - * * - * $Archive:: /Commando/Code/WWMath/tri.cpp $* - * * - * Author:: Greg Hjelstrom * - * * - * $Modtime:: 5/03/01 3:41p $* - * * - * $Revision:: 8 $* - * * - *---------------------------------------------------------------------------------------------* - * Functions: * - * TriClass::Find_Dominant_Plane -- returns indices of the axes of the dominant plane * - * TriClass::Contains_Point -- performs 2D point-in-triangle test. * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - -#include "tri.h" -#include "vector2.h" - - -struct FDPRec -{ - int axis1; - int axis2; - int axis3; -}; - -static inline void find_dominant_plane_fast(const TriClass & tri, FDPRec& info) -{ - static const FDPRec dominance[3] = - { - { 1, 2, 0 }, // Dominant is the X axis - { 0, 2, 1 }, // Dominant is the Y axis - { 0, 1, 2 } // Dominant is the Z axis - }; - - /* - ** Find the largest component of the normal - */ - float x = WWMath::Fabs(tri.N->X); - float y = WWMath::Fabs(tri.N->Y); - float z = WWMath::Fabs(tri.N->Z); - - float val = x; - int ni = 0; - - if (y > val) - { - ni = 1; - val = y; - } - - if (z > val) - { - ni = 2; - } - - info = dominance[ni]; -} - -static inline void find_dominant_plane(const TriClass & tri, int * axis1,int * axis2,int * axis3) -{ - /* - ** Find the largest component of the normal - */ - int ni = 0; - float x = WWMath::Fabs(tri.N->X); - float y = WWMath::Fabs(tri.N->Y); - float z = WWMath::Fabs(tri.N->Z); - float val = x; - - if (y > val) { - ni = 1; - val = y; - } - - if (z > val) { - ni = 2; - } - - /* - ** return the indices of the two axes perpendicular - */ - switch (ni) - { - case 0: - // Dominant is the X axis - *axis1 = 1; - *axis2 = 2; - *axis3 = 0; - break; - case 1: - // Dominant is the Y axis - *axis1 = 0; - *axis2 = 2; - *axis3 = 1; - break; - case 2: - // Dominant is the Z axis - *axis1 = 0; - *axis2 = 1; - *axis3 = 2; - break; - } -} - - - -/*********************************************************************************************** - * TriClass::Find_Dominant_Plane -- returns indices of the axes of the dominant plane * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 3/24/99 GTH : Created. * - *=============================================================================================*/ -void TriClass::Find_Dominant_Plane(int * axis1,int * axis2) const -{ - /* - ** Find the largest component of the normal - */ - int ni = 0; - float x = WWMath::Fabs(N->X); - float y = WWMath::Fabs(N->Y); - float z = WWMath::Fabs(N->Z); - float val = x; - - if (y > val) { - ni = 1; - val = y; - } - - if (z > val) { - ni = 2; - } - - /* - ** return the indices of the two axes perpendicular - */ - switch (ni) - { - case 0: - // Dominant is the X axis - *axis1 = 1; - *axis2 = 2; - break; - case 1: - // Dominant is the Y axis - *axis1 = 0; - *axis2 = 2; - break; - case 2: - // Dominant is the Z axis - *axis1 = 0; - *axis2 = 1; - break; - } -} - - -/*********************************************************************************************** - * TriClass::Contains_Point -- performs 2D point-in-triangle test. * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * Assumes that the point is in the plane of the triangle... use this after you've intersected * - * a ray with the plane of the triangle. * - * * - * HISTORY: * - * 3/24/99 GTH : Created. * - *=============================================================================================*/ -bool TriClass::Contains_Point(const Vector3 & ipoint) const -{ -#if 0 - /* - ** Perform the test in 2d on the plane which the normal - ** is most perpendicular to. (copied from E.Cosky's intersection code) - */ - int axis1 = 0; - int axis2 = 0; - Find_Dominant_Plane(&axis1,&axis2); - -#if 1 - unsigned char flags; // dummy variable passed into function and not used here - return Point_In_Triangle_2D(*V[0], *V[1], *V[2], ipoint, axis1, axis2, flags); -#else - float u0 = ipoint[axis1] - (*V[0])[axis1]; - float v0 = ipoint[axis2] - (*V[0])[axis2]; - - /* - ** determine the 2d vectors on the dominant plane from the first vertex to the other two - */ - float u1 = (*V[1])[axis1] - (*V[0])[axis1]; - float v1 = (*V[1])[axis2] - (*V[0])[axis2]; - float u2 = (*V[2])[axis1] - (*V[0])[axis1]; - float v2 = (*V[2])[axis2] - (*V[0])[axis2]; - - float alpha, beta; - bool intersect = false; - - // calculate alpha and beta as normalized (0..1) percentages across the 2d projected triangle - // and do bounds checking (sum <= 1) to determine whether or not the triangle intersection occurs. - if (u1 == 0) { - beta = u0 / u2; - if ((beta >= 0) && (beta <= 1)) { - alpha = (v0 - beta * v2) / v1; - intersect = ((alpha >= 0) && ((alpha + beta) <= 1 + WWMATH_EPSILON)); - } - } else { - beta = (v0 * u1 - u0 * v1) / (v2 * u1 - u2 * v1); - if ((beta >= 0) && (beta <= 1)) { - alpha = (u0 - beta * u2) / u1; - intersect = ((alpha >= 0) && ((alpha + beta) <= 1 + WWMATH_EPSILON)); - } - } - - return intersect; -#endif -#endif -/* -** New cross-product based point-containment -*/ -#if 0 - int vi; - int axis3 = 0; - - for (vi=0; vi<3; vi++) { - if ((axis1 != vi) && (axis2 != vi)) axis3 = vi; - } - - Vector3 test_point = ipoint; - test_point[axis3] = 0.0f; - - Vector3 points[3]; - for (vi=0; vi<3; vi++) { - points[vi] = *(V[vi]); - points[vi][axis3] = 0.0f; - } - - bool side[3]; - Vector3 edge; - Vector3 cross; - Vector3 dp; - - for (vi=0; vi<3; vi++) { - edge = points[(vi+1)%3] - points[vi]; - dp = test_point - points[vi]; - - Vector3::Cross_Product(dp,edge,&cross); - side[vi] = (cross[axis3] > 0.0f); - } - - bool my_intersect = ((side[0] == side[1]) && (side[1] == side[2])); - return my_intersect; -#endif - - -/* -** "Optimized" version -*/ -#if 1 -#if 0 - - // srj opto version - /// @todo srj -- profile me to see if this is actually faster - - FDPRec info; - find_dominant_plane_fast(*this, info); - - /* - ** Compute the 2D cross product of edge0 with a vector to the point - */ - - float edge_x, edge_y, dp_x, dp_y, cross; - bool side0, side1, side2; - - edge_x = (*V[1])[info.axis1] - (*V[0])[info.axis1]; - edge_y = (*V[1])[info.axis2] - (*V[0])[info.axis2]; - dp_x = ipoint[info.axis1] - (*V[0])[info.axis1]; - dp_y = ipoint[info.axis2] - (*V[0])[info.axis2]; - cross = edge_x * dp_y - edge_y * dp_x; - side0 = (cross >= 0.0f); - - edge_x = (*V[2])[info.axis1] - (*V[1])[info.axis1]; - edge_y = (*V[2])[info.axis2] - (*V[1])[info.axis2]; - dp_x = ipoint[info.axis1] - (*V[1])[info.axis1]; - dp_y = ipoint[info.axis2] - (*V[1])[info.axis2]; - cross = edge_x * dp_y - edge_y * dp_x; - side1 = (cross >= 0.0f); - - edge_x = (*V[0])[info.axis1] - (*V[2])[info.axis1]; - edge_y = (*V[0])[info.axis2] - (*V[2])[info.axis2]; - dp_x = ipoint[info.axis1] - (*V[2])[info.axis1]; - dp_y = ipoint[info.axis2] - (*V[2])[info.axis2]; - cross = edge_x * dp_y - edge_y * dp_x; - side2 = (cross >= 0.0f); - - bool my_intersect = ((side0 == side1) && (side1 == side2)); - return my_intersect; - -#else - int vi; - int axis1 = 0; - int axis2 = 0; - int axis3 = 0; - - find_dominant_plane(*this,&axis1,&axis2,&axis3); - - bool side[3]; - - /* - ** Compute the 2D cross product of edge0 with a vector to the point - */ - Vector2 edge; - Vector2 dp; - - for (vi=0; vi<3; vi++) { - - int va=vi; - int vb=(vi+1)%3; - - edge.Set((*V[vb])[axis1] - (*V[va])[axis1] , (*V[vb])[axis2] - (*V[va])[axis2]); - dp.Set(ipoint[axis1] - (*V[va])[axis1] , ipoint[axis2] - (*V[va])[axis2]); - float cross = edge.X * dp.Y - edge.Y * dp.X; - side[vi] = (cross >= 0.0f); - } - - bool my_intersect = ((side[0] == side[1]) && (side[1] == side[2])); - return my_intersect; -#endif -#endif - - -} diff --git a/Generals/Code/Libraries/Source/WWVegas/WWMath/tri.h b/Generals/Code/Libraries/Source/WWVegas/WWMath/tri.h deleted file mode 100644 index 329f68b463a..00000000000 --- a/Generals/Code/Libraries/Source/WWVegas/WWMath/tri.h +++ /dev/null @@ -1,306 +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 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 : WWMath * - * * - * $Archive:: /Commando/Code/wwmath/tri.h $* - * * - * Author:: Greg_h * - * * - * $Modtime:: 5/04/01 8:35p $* - * * - * $Revision:: 14 $* - * * - *---------------------------------------------------------------------------------------------* - * Functions: * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - - -#if defined(_MSC_VER) -#pragma once -#endif - -#ifndef TRI_H -#define TRI_H - -#include "always.h" -#include "vector4.h" -#include "vector3.h" -#include "vector2.h" -#include - - -/** -** TriClass -** When the math library needs to deal with triangles, this will be the form used. -** The initial reason for this class is for Commando's collision detection code. Initially -** I wrote custom code inside the render object for the terrain to perform collision -** detection. Moving the low-level geometrical collision code into the math library makes it -** more re-useable and independent from changes in the rendering code. -*/ -class TriClass -{ -public: - - const Vector3 * N; - const Vector3 * V[3]; - - void Compute_Normal() - { - assert(N); - assert(V[0]); - assert(V[1]); - assert(V[2]); - - Vector3::Cross_Product(*(V[1])-*(V[0]),*(V[2])-*(V[0]),(Vector3 *)N); - ((Vector3 *)N)->Normalize(); - } - - - bool Contains_Point(const Vector3 & ipoint) const; - void Find_Dominant_Plane(int * axis1,int * axis2) const; -}; - - -/* -** Utility functions: -** Functions which have to do with triangles but not neccessarily with TriClass - usually used -** by TriClass but also available for use elsewhere. -*/ - -// Enums for raycast flags (currently used only for semi-infinite axis-aligned rays) -enum -{ - TRI_RAYCAST_FLAG_NONE = 0x00, - TRI_RAYCAST_FLAG_HIT_EDGE = 0x01, - TRI_RAYCAST_FLAG_START_IN_TRI = 0x02 -}; - -// This function does a pure 2D point-in-triangle test. We pass in 3D points both for the -// triangle and test points, but we also pass in the two axes to use (the third axis is ignored, -// so we are actually testing the projection of the four points onto one of the axis planes). The -// triangle points are not assumed to be in any particular winding order (that is checked for -// internally). It is used internally by TriClass::Contains_Point(), and may be used elsewhere. -// If the ray intersects the camera at an edge we also count it as an intersection. We set a bit -// in 'flags' to true in this case (some users of this function need this extra information and -// it is very cheap to compute). We do not modify 'flags' if no edges are hit, so it must be -// initialized outside this function if its value is to be used. -inline bool Point_In_Triangle_2D(const Vector3 &tri_point0, const Vector3 &tri_point1, - const Vector3 &tri_point2, const Vector3 &test_point, int axis_1, int axis_2, - unsigned char &flags) -{ - // The function is based on checking signs of determinants, or in a more visually intuitive - // sense, checking on which side of a line a point lies. For example, if the points run in - // counter-clockwise order, the interior of the triangle is the intersection of the three - // half-planes to the left of the directed infinite lines along P0 to P1, P1 to P2, P2 to P0. - // Therefore the test point is in the triangle iff it is to the left of all three lines (if - // the points are in clockwise order, we check if it is to the right of the lines). - Vector2 p0p1(tri_point1[axis_1] - tri_point0[axis_1], tri_point1[axis_2] - tri_point0[axis_2]); - Vector2 p1p2(tri_point2[axis_1] - tri_point1[axis_1], tri_point2[axis_2] - tri_point1[axis_2]); - Vector2 p2p0(tri_point0[axis_1] - tri_point2[axis_1], tri_point0[axis_2] - tri_point2[axis_2]); - - // Check which side P2 is relative to P0P1. The sign of this test must equal the sign of all - // three tests between the lines and the test point for the test point to be inside the - // triangle. (this test will also tell us if the three points are colinear - if the triangle - // is degenerate). - Vector2 p0p2(tri_point2[axis_1] - tri_point0[axis_1], tri_point2[axis_2] - tri_point0[axis_2]); - float p0p1p2 = Vector2::Perp_Dot_Product(p0p1, p0p2); - if (p0p1p2 != 0.0f) { - - // The triangle is not degenerate - test three sides - float side_factor = p0p1p2 > 0.0f ? 1.0f : -1.0f; - float factors[3]; - - // Now perform tests - Vector2 p0pT(test_point[axis_1] - tri_point0[axis_1], test_point[axis_2] - tri_point0[axis_2]); - factors[0] = Vector2::Perp_Dot_Product(p0p1, p0pT); - if (factors[0] * side_factor < 0.0f) { - return false; - } - Vector2 p1pT(test_point[axis_1] - tri_point1[axis_1], test_point[axis_2] - tri_point1[axis_2]); - factors[1] = Vector2::Perp_Dot_Product(p1p2, p1pT); - if (factors[1] * side_factor < 0.0f) { - return false; - } - Vector2 p2pT(test_point[axis_1] - tri_point2[axis_1], test_point[axis_2] - tri_point2[axis_2]); - factors[2] = Vector2::Perp_Dot_Product(p2p0, p2pT); - if (factors[2] * side_factor < 0.0f) { - return false; - } - if ((factors[0] == 0.0f) || (factors[1] == 0.0f) || (factors[2] == 0.0f)) flags |= TRI_RAYCAST_FLAG_HIT_EDGE; - return true; - - } else { - - // The triangle is degenerate. This should be a rare case, so it does not matter much if it - // is a little slower than the non-colinear case. - - // Find the two outer points along the triangle's line ('start' and 'end' points) - float p0p1dist2 = p0p1.Length2(); - float p1p2dist2 = p1p2.Length2(); - float p2p0dist2 = p1p2.Length2(); - float max_dist2; - Vector2 pSpE, pSpT; // 'end' point, test point - both in 'start' points' frame - if (p0p1dist2 > p1p2dist2) { - if (p0p1dist2 > p2p0dist2) { - // points 0 and 1 are the 'outer' points. 0 is 'start' and 1 is 'end'. - pSpE = p0p1; - pSpT.Set(test_point[axis_1] - tri_point0[axis_1], test_point[axis_2] - tri_point0[axis_2]); - max_dist2 = p0p1dist2; - } else { - // points 0 and 2 are the 'outer' points. 2 is 'start' and 0 is 'end'. - pSpE = p2p0; - pSpT.Set(test_point[axis_1] - tri_point2[axis_1], test_point[axis_2] - tri_point2[axis_2]); - max_dist2 = p2p0dist2; - } - } else { - if (p1p2dist2 > p2p0dist2) { - // points 1 and 2 are the 'outer' points. 1 is 'start' and 2 is 'end'. - pSpE = p1p2; - pSpT.Set(test_point[axis_1] - tri_point1[axis_1], test_point[axis_2] - tri_point1[axis_2]); - max_dist2 = p1p2dist2; - } else { - // points 0 and 2 are the 'outer' points. 2 is 'start' and 0 is 'end'. - pSpE = p2p0; - pSpT.Set(test_point[axis_1] - tri_point2[axis_1], test_point[axis_2] - tri_point2[axis_2]); - max_dist2 = p2p0dist2; - } - } - - if (max_dist2 != 0.0f) { - // Triangle is line segment, check if test point is colinear with it - if (Vector2::Perp_Dot_Product(pSpE, pSpT)) { - // Not colinear - return false; - } else { - // Colinear - is test point's distance from start and end <= segment length? - Vector2 pEpT = pSpT - pSpE; - if (pSpT.Length2() <= max_dist2 && pEpT.Length2() <= max_dist2) { - flags |= TRI_RAYCAST_FLAG_HIT_EDGE; - return true; - } else { - return false; - } - } - } else { - // All triangle points coincide, check if test point coincides with them - if (pSpT.Length2() == 0.0f) { - flags |= TRI_RAYCAST_FLAG_HIT_EDGE; - return true; - } else { - return false; - } - } - } -} - - -// This function tests a semi-infinite axis-aligned ray vs. a triangle. -// The inputs are blah blah blah -inline bool Cast_Semi_Infinite_Axis_Aligned_Ray_To_Triangle(const Vector3 &tri_point0, - const Vector3 &tri_point1, const Vector3 &tri_point2, const Vector4 &tri_plane, - const Vector3 &ray_start, int axis_r, int axis_1, int axis_2, int direction, - unsigned char & flags) -{ - bool retval = false; - - // First check infinite ray vs. triangle (2D check) - unsigned char flags_2d = TRI_RAYCAST_FLAG_NONE; - if (Point_In_Triangle_2D(tri_point0, tri_point1, tri_point2, ray_start, axis_1, axis_2, flags_2d)) { - - // NOTE: SR plane equations, unlike WWMath's PlaneClass, use the Ax+By+Cz+D = 0 - // representation. It can also be viewed as C0x+C1y+C2z+C3 = dist where dist is the - // signed distance from the plane (and therefore the plane is defined as those points - // where dist = 0). Now that we know that the projection along the ray is inside the - // triangle, determining whether the ray hits the triangle is a matter of determining - // whether the start point is on the triangle plane's "anti-rayward side" (the side - // which the ray points away from). - // To determine this, we will use C[axis_r] (the plane coefficient of the ray axis). - // This coefficient is positive if the positive direction of the ray axis points into - // the planes' positive halfspace and negative if it points into the planes' negative - // halfspace (it is zero if the ray axis is parallel to the triangle plane). If we - // multiply this by 'sign' which is defined to be -1.0 if 'direction' equals 0 and - // 1.0 if 'direction' equals 1, we will get a number which is positive or negative - // depending on which halfspace the ray itself (as opposed to the rays axis) points - // towards. If we further multiply this by dist(start point) - the result of plugging - // the start point into the plane equation - we will get a number which is positive - // if the start point is on the 'rayward side' (ray does not intersect the triangle) - // and is negative if the start point is on the 'anti-rayward side' (ray does - // intersect triangle). In either of these two cases we are done. - // (see below for what happens when the result is zero - more checks need to be made). - static const float sign[2] = {-1.0f, 1.0f }; - float result = tri_plane[axis_r] * sign[direction] * (tri_plane.X * ray_start.X + - tri_plane.Y * ray_start.Y + tri_plane.Z * ray_start.Z + tri_plane.W); - if (result < 0.0f) { - // Intersection! - flags |= (flags_2d & TRI_RAYCAST_FLAG_HIT_EDGE); - retval = true; - } else { - if (result == 0.0f) { - // If the result is 0, this means either the ray is parallel to the triangle - // plane or the start point is embedded in the triangle plane. Note that since - // the start point passed the 2D check, then if the ray is parallel the start - // point must also be embedded in the triangle plane. This leaves us with two - // cases: - // A) The ray is not parallel to the plane - in this case the start point is - // embedded in the triangle. We report an intersection, bitwise OR the edge - // result from the 2D check into the 'edge hit' flag and set the 'start in tri' - // flag. - // B) The ray is parallel to the plane. In this case the result of the 2D test - // tells us that the infinite line intersects the triangle (actually is - // embedded in the triangle along part of its length), but we do not know - // whether the semi-infinite ray also does so. We simplify things by not - // counting such an 'intersection'. There are four reasons behind this: - // 1. It differs from a 'normal' intersection (which has one intersecting - // point) - there are infinitely many intersecting points. - // 2. Moving the plane by an infinitesimally small amount to either side will - // cause the ray to no longer touch the plane. - // 3. This will not affect results for the known uses of this function. - // 4. By doing so we avoid having to code up a bunch of complex tests. - // Therefore in case B) we just report no intersection. We still need to find - // out whether the point is embedded in the triangle (for setting the flag) so - // we do another simple 2D test on the dominant plane. - if (tri_plane[axis_r]) { - // Case A) - flags |= (flags_2d & TRI_RAYCAST_FLAG_HIT_EDGE); - flags |= TRI_RAYCAST_FLAG_START_IN_TRI; - retval = true; - } else { - // Case B) - test if point in tri (we know it is in plane, so we can use - // TriClass function) - TriClass tri; - tri.V[0] = &tri_point0; - tri.V[1] = &tri_point1; - tri.V[2] = &tri_point2; - tri.N = (Vector3*)&tri_plane; - if (tri.Contains_Point(ray_start)) { - flags |= TRI_RAYCAST_FLAG_START_IN_TRI; - } - } - } // if (result == 0.0f) - } // else (result < 0.0f) - } // if Point_In_Triangle_2D() - - return retval; -} - -#endif diff --git a/Generals/Code/Libraries/Source/WWVegas/WWMath/v3_rnd.cpp b/Generals/Code/Libraries/Source/WWVegas/WWMath/v3_rnd.cpp deleted file mode 100644 index 550ebcabac6..00000000000 --- a/Generals/Code/Libraries/Source/WWVegas/WWMath/v3_rnd.cpp +++ /dev/null @@ -1,173 +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 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 : G * - * * - * $Archive:: /Commando/Code/wwmath/v3_rnd.cpp $* - * * - * $Author:: Greg_h $* - * * - * $Modtime:: 7/09/99 9:49a $* - * * - * $Revision:: 4 $* - * * - *---------------------------------------------------------------------------------------------* - * Functions: * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - -#include "v3_rnd.h" -#include "vector2.h" - -const float Vector3Randomizer::OOIntMax = 1.0f / (float)INT_MAX; -const float Vector3Randomizer::OOUIntMax = 1.0f / (float)UINT_MAX; -Random3Class Vector3Randomizer::Randomizer; - -Vector3SolidBoxRandomizer::Vector3SolidBoxRandomizer(const Vector3 & extents) -{ - Extents.X = MAX(extents.X, 0.0f); - Extents.Y = MAX(extents.Y, 0.0f); - Extents.Z = MAX(extents.Z, 0.0f); -} - -void Vector3SolidBoxRandomizer::Get_Vector(Vector3 &vector) -{ - vector.X = Get_Random_Float_Minus1_To_1() * Extents.X; - vector.Y = Get_Random_Float_Minus1_To_1() * Extents.Y; - vector.Z = Get_Random_Float_Minus1_To_1() * Extents.Z; -} - -float Vector3SolidBoxRandomizer::Get_Maximum_Extent(void) -{ - float max = MAX(Extents.X, Extents.Y); - max = MAX(max, Extents.Z); - return max; -} - -void Vector3SolidBoxRandomizer::Scale(float scale) -{ - scale = MAX(scale, 0.0f); - Extents.X *= scale; - Extents.Y *= scale; - Extents.Z *= scale; -} - - -Vector3SolidSphereRandomizer::Vector3SolidSphereRandomizer(float radius) -{ - Radius = MAX(radius, 0.0f); -} - -void Vector3SolidSphereRandomizer::Get_Vector(Vector3 &vector) -{ - // Generate vectors in a cube and discard the ones not in a sphere - float rad_squared = Radius * Radius; - for (;;) { - vector.X = Get_Random_Float_Minus1_To_1() * Radius; - vector.Y = Get_Random_Float_Minus1_To_1() * Radius; - vector.Z = Get_Random_Float_Minus1_To_1() * Radius; - if (vector.Length2() <= rad_squared) break; - } -} - -float Vector3SolidSphereRandomizer::Get_Maximum_Extent(void) -{ - return Radius; -} - -void Vector3SolidSphereRandomizer::Scale(float scale) -{ - scale = MAX(scale, 0.0f); - Radius *= scale; -} - - -Vector3HollowSphereRandomizer::Vector3HollowSphereRandomizer(float radius) -{ - Radius = MAX(radius, 0.0f); -} - -void Vector3HollowSphereRandomizer::Get_Vector(Vector3 &vector) -{ - // Generate vectors in a 2x2x2 origin-centered cube, discard the ones not in a unit-radius - // sphere and scale the result to Radius. - float v_l2; - for (;;) { - vector.X = Get_Random_Float_Minus1_To_1(); - vector.Y = Get_Random_Float_Minus1_To_1(); - vector.Z = Get_Random_Float_Minus1_To_1(); - v_l2 = vector.Length2(); - if (v_l2 <= 1.0f && v_l2 > 0.0f) break; - } - - float scale = Radius * WWMath::Inv_Sqrt(v_l2); - - vector.X *= scale; - vector.Y *= scale; - vector.Z *= scale; -} - -float Vector3HollowSphereRandomizer::Get_Maximum_Extent(void) -{ - return Radius; -} - -void Vector3HollowSphereRandomizer::Scale(float scale) -{ - scale = MAX(scale, 0.0f); - Radius *= scale; -} - - -Vector3SolidCylinderRandomizer::Vector3SolidCylinderRandomizer(float extent, float radius) -{ - Extent = MAX(extent, 0.0f); - Radius = MAX(radius, 0.0f); -} - -void Vector3SolidCylinderRandomizer::Get_Vector(Vector3 &vector) -{ - vector.X = Get_Random_Float_Minus1_To_1() * Extent; - - // Generate 2D vectors in a square and discard the ones not in a circle - Vector2 vec2; - float rad_squared = Radius * Radius; - for (;;) { - vec2.X = Get_Random_Float_Minus1_To_1() * Radius; - vec2.Y = Get_Random_Float_Minus1_To_1() * Radius; - if (vec2.Length2() <= rad_squared) break; - } - - vector.Y = vec2.X; - vector.Z = vec2.Y; -} - -float Vector3SolidCylinderRandomizer::Get_Maximum_Extent(void) -{ - return MAX(Extent, Radius); -} - -void Vector3SolidCylinderRandomizer::Scale(float scale) -{ - scale = MAX(scale, 0.0f); - Extent *= scale; - Radius *= scale; -} diff --git a/Generals/Code/Libraries/Source/WWVegas/WWMath/v3_rnd.h b/Generals/Code/Libraries/Source/WWVegas/WWMath/v3_rnd.h deleted file mode 100644 index aba4fdc157d..00000000000 --- a/Generals/Code/Libraries/Source/WWVegas/WWMath/v3_rnd.h +++ /dev/null @@ -1,235 +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 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 : G * - * * - * $Archive:: /Commando/Code/wwmath/v3_rnd.h $* - * * - * $Author:: Greg_h $* - * * - * $Modtime:: 7/09/99 9:49a $* - * * - * $Revision:: 4 $* - * * - *---------------------------------------------------------------------------------------------* - * Functions: * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ -#if defined(_MSC_VER) -#pragma once -#endif - -#ifndef V3_RND_H -#define V3_RND_H - -#include "always.h" -#include "vector3.h" -#include "RANDOM.H" -#include - -/* -** Vector3Randomizer is an abstract class for generating random Vector3s. -** Examples: generating vectors in a sphere, cylinder, etc. -** This file contains several concrete derived classes; others may be defined -** in future. -** A possible future extension to this class would be to add a method to -** efficiently get an array of random points. -*/ - -class Vector3Randomizer { - - public: - - enum - { - CLASSID_UNKNOWN = 0xFFFFFFFF, - CLASSID_SOLIDBOX = 0, - CLASSID_SOLIDSPHERE, - CLASSID_HOLLOWSPHERE, - CLASSID_SOLIDCYLINDER, - CLASSID_MAXKNOWN, - CLASSID_LAST = 0x0000FFFF - }; - - virtual ~Vector3Randomizer(void) { } - - // RTTI identifiction - virtual unsigned int Class_ID (void) const = 0; - - // Return a random vector - virtual void Get_Vector(Vector3 &vector) = 0; - - // Get the maximum component possible for generated vectors - virtual float Get_Maximum_Extent(void) = 0; - - // Scale all vectors produced in future - virtual void Scale(float scale) = 0; - - // Clone the randomizer - virtual Vector3Randomizer * Clone(void) const = 0; - - protected: - - // Derived classes should have protected copy CTors so users use the Clone() function - - // Utility functions - float Get_Random_Float_Minus1_To_1() { return Randomizer * OOIntMax; } - float Get_Random_Float_0_To_1() { return ((unsigned int)Randomizer) * OOUIntMax; } - - static const float OOIntMax; - static const float OOUIntMax; - static Random3Class Randomizer; - - private: - - // Derived classes should have a private dummy assignment operator to block usage -}; - - -/* -** Vector3SolidBoxRandomizer is a randomizer for generating points uniformly distributed inside a -** box which is centered on the origin. -*/ -class Vector3SolidBoxRandomizer : public Vector3Randomizer { - - public: - - Vector3SolidBoxRandomizer(const Vector3 & extents); - - virtual unsigned int Class_ID (void) const { return CLASSID_SOLIDBOX; } - virtual const Vector3 & Get_Extents (void) const { return Extents; } - virtual void Get_Vector(Vector3 &vector); - virtual float Get_Maximum_Extent(void); - virtual void Scale(float scale); - virtual Vector3Randomizer * Clone(void) const { return W3DNEW Vector3SolidBoxRandomizer(*this); } - - protected: - - // Derived classes should have protected copy CTors so users use the Clone() function - Vector3SolidBoxRandomizer(const Vector3SolidBoxRandomizer &src) : Extents(src.Extents) { } - - private: - - // Derived classes should have a private dummy assignment operator to block usage - Vector3SolidBoxRandomizer & operator = (const Vector3SolidBoxRandomizer &that) { that; return *this; } - - Vector3 Extents; -}; - - -/* -** Vector3SolidSphereRandomizer is a randomizer for generating points uniformly distributed inside -** a sphere which is centered on the origin. -*/ -class Vector3SolidSphereRandomizer : public Vector3Randomizer { - - public: - - Vector3SolidSphereRandomizer(float radius); - - virtual unsigned int Class_ID (void) const { return CLASSID_SOLIDSPHERE; } - virtual float Get_Radius (void) const { return Radius; } - virtual void Get_Vector(Vector3 &vector); - virtual float Get_Maximum_Extent(void); - virtual void Scale(float scale); - virtual Vector3Randomizer * Clone(void) const { return W3DNEW Vector3SolidSphereRandomizer(*this); } - - protected: - - // Derived classes should have protected copy CTors so users use the Clone() function - Vector3SolidSphereRandomizer(const Vector3SolidSphereRandomizer &src) : Radius(src.Radius) { } - - private: - - // Derived classes should have a private dummy assignment operator to block usage - Vector3SolidSphereRandomizer & operator = (const Vector3SolidSphereRandomizer &that) { that; return *this; } - - float Radius; -}; - - -/* -** Vector3HollowSphereRandomizer is a randomizer for generating points uniformly distributed on the -** surface of a sphere which is centered on the origin. -*/ -class Vector3HollowSphereRandomizer : public Vector3Randomizer { - - public: - - Vector3HollowSphereRandomizer(float radius); - - virtual unsigned int Class_ID (void) const { return CLASSID_HOLLOWSPHERE; } - virtual float Get_Radius (void) const { return Radius; } - virtual void Get_Vector(Vector3 &vector); - virtual float Get_Maximum_Extent(void); - virtual void Scale(float scale); - virtual Vector3Randomizer * Clone(void) const { return W3DNEW Vector3HollowSphereRandomizer(*this); } - - protected: - - // Derived classes should have protected copy CTors so users use the Clone() function - Vector3HollowSphereRandomizer(const Vector3HollowSphereRandomizer &src) : Radius(src.Radius) { } - - private: - - // Derived classes should have a private dummy assignment operator to block usage - Vector3HollowSphereRandomizer & operator = (const Vector3HollowSphereRandomizer &that) { that; return *this; } - - float Radius; -}; - - -/* -** Vector3SolidCylinderRandomizer is a randomizer for generating points uniformly distributed -** inside a cylinder which is centered on the origin (set extent to 0 for a disk). -*/ -class Vector3SolidCylinderRandomizer : public Vector3Randomizer { - - public: - - Vector3SolidCylinderRandomizer(float extent, float radius); - - virtual unsigned int Class_ID (void) const { return CLASSID_SOLIDCYLINDER; } - virtual float Get_Radius (void) const { return Radius; } - virtual float Get_Height (void) const { return Extent; } - virtual void Get_Vector(Vector3 &vector); - virtual float Get_Maximum_Extent(void); - virtual void Scale(float scale); - virtual Vector3Randomizer * Clone(void) const { return W3DNEW Vector3SolidCylinderRandomizer(*this); } - - protected: - - // Derived classes should have protected copy CTors so users use the Clone() function - Vector3SolidCylinderRandomizer(const Vector3SolidCylinderRandomizer &src) : Extent(src.Extent), Radius(src.Radius) { } - - private: - - // Derived classes should have a private dummy assignment operator to block usage - Vector3SolidCylinderRandomizer & operator = (const Vector3SolidCylinderRandomizer &that) { that; return *this; } - - float Extent; - float Radius; -}; - - -#endif - - diff --git a/Generals/Code/Libraries/Source/WWVegas/WWMath/vector2.h b/Generals/Code/Libraries/Source/WWVegas/WWMath/vector2.h deleted file mode 100644 index d324cee3a21..00000000000 --- a/Generals/Code/Libraries/Source/WWVegas/WWMath/vector2.h +++ /dev/null @@ -1,671 +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 . -*/ - -/* $Header: /Commando/Code/wwmath/vector2.h 24 7/06/01 9:43a Byon_g $ */ -/*********************************************************************************************** - *** Confidential - Westwood Studios *** - *********************************************************************************************** - * * - * Project Name : Westwood 3D * - * * - * File Name : VECTOR2.H * - * * - * Programmer : Greg Hjelstrom * - * * - * Start Date : 02/24/97 * - * * - * Last Update : February 24, 1997 [GH] * - * * - *---------------------------------------------------------------------------------------------* - * Functions: * - * Scalar Division Operator -- Divide a vector by a scalar * - * Scalar Multiply Operator -- Multiply a vector by a scalar * - * Vector Addition Operator -- Add two vectors * - * Vector Subtraction Operator -- Subract two vectors * - * Vector Inner Product Operator -- Compute the inner or dot product * - * Vector Equality Operator -- Detemine if two vectors are identical * - * Equal_Within_Epsilon -- Determine if two vectors are identical within * - * Vector Inequality Operator -- Detemine if two vectors are identical * - * Swap -- swap two Vector2's * - * Vector2::Is_Valid -- Verifies that all components are valid floats * - * Vector2::Update_Min -- sets each component of the vector to the min of this and a. * - * Vector2::Update_Max -- sets each component of the vector to the max of this and a. * - * Vector2::Scale -- multiply components of a vector by independant scaling factors. * - * Vector2::Lerp -- linearly interpolates two Vector2's * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - -#if defined(_MSC_VER) -#pragma once -#endif - -#ifndef VECTOR2_H -#define VECTOR2_H - -#include "always.h" -#include "wwmath.h" -#include - - -/* -** 2-Dimensional Vectors -*/ - -class Vector2 -{ - -public: - - union { - float X; - float U; - }; - - union { - float Y; - float V; - }; - - // Constructors - WWINLINE Vector2(void) {}; - WWINLINE Vector2(const Vector2 & v) { X = v.X; Y = v.Y; } - WWINLINE Vector2(float x, float y) { X = x; Y = y; } - WWINLINE Vector2(const float vector[2]) { X = vector[0]; Y = vector[1]; } - - - // Assignment - WWINLINE Vector2 & operator = (const Vector2 & v) { X = v[0]; Y = v[1]; return *this; } - WWINLINE void Set(float x, float y) { X = x; Y = y; } - WWINLINE void Set(const Vector2 & v) { X = v.X; Y = v.Y; } - - // Array access - WWINLINE float & operator [](int i) { return (&X)[i]; } - WWINLINE const float & operator [](int i) const { return (&X)[i]; } - - // normalize, compute length - WWINLINE void Normalize(void); - WWINLINE float Length(void) const; - WWINLINE float Length2(void) const; - - // unary operators - WWINLINE Vector2 operator-() const { return Vector2(-X,-Y); } - WWINLINE Vector2 operator+() const { return *this; } - - WWINLINE Vector2 & operator += (const Vector2 & v) { X += v.X; Y += v.Y; return *this; } - WWINLINE Vector2 & operator -= (const Vector2 & v) { X -= v.X; Y -= v.Y; return *this; } - WWINLINE Vector2 & operator *= (float k) { X = (float)(X*k); Y=(float)(Y*k); return *this; } - WWINLINE Vector2 & operator /= (float k) { k=1.0f/k; X*=k; Y*=k; return *this; } - - // scalar multiplication, division - WWINLINE friend Vector2 operator * (const Vector2 &a,float k); - WWINLINE friend Vector2 operator * (float k,const Vector2 &a); - WWINLINE friend Vector2 operator / (const Vector2 &a,float k); - - // vector addition,subtraction - WWINLINE friend Vector2 operator + (const Vector2 &a,const Vector2 &b); - WWINLINE friend Vector2 operator - (const Vector2 &a,const Vector2 &b); - - // dot product / inner product - WWINLINE friend float operator * (const Vector2 &a,const Vector2 &b); - static WWINLINE float Dot_Product(const Vector2 &a,const Vector2 &b); - - // dot product between a and perpendicular vector to b - static float Perp_Dot_Product(const Vector2 &a,const Vector2 &b); - - // Equality operators - friend bool operator == (const Vector2 &a,const Vector2 &b); - friend bool operator != (const Vector2 &a,const Vector2 &b); - WWINLINE friend bool Equal_Within_Epsilon(const Vector2 &a,const Vector2 &b,float epsilon); - - // Rotation - WWINLINE void Rotate(float theta); - WWINLINE void Rotate(float s, float c); - WWINLINE bool Rotate_Towards_Vector(Vector2 &target, float max_theta, bool & positive_turn); - WWINLINE bool Rotate_Towards_Vector(Vector2 &target, float max_s, float max_c, bool & positive_turn); - - // verify that none of the members of this vector are invalid floats - WWINLINE bool Is_Valid(void) const; - - // make this vector the min or max of itself and the passed vector - WWINLINE void Update_Min (const Vector2 & a); - WWINLINE void Update_Max (const Vector2 & a); - WWINLINE void Scale (float a, float b); - WWINLINE void Scale (const Vector2 & a); - - static WWINLINE float Distance(const Vector2 &p1, const Vector2 &p2); - static WWINLINE float Quick_Distance(const Vector2 &p1, const Vector2 &p2); - - // interpolate between two Vector2's - static void Lerp(const Vector2 & a,const Vector2 & b,float t,Vector2 * set_result); -}; - - -/************************************************************************** - * Scalar Multiply Operator -- Multiply a vector by a scalar * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 02/24/1997 GH : Created. * - *========================================================================*/ -WWINLINE Vector2 operator * (const Vector2 &a,float k) -{ - float a0k(a[0] * k); - float a1k(a[1] * k); - return Vector2(a0k,a1k); -} - -WWINLINE Vector2 operator * (float k, const Vector2 &a) -{ - float a0k(a[0] * k); - float a1k(a[1] * k); - return Vector2(a0k,a1k); -} - -/************************************************************************** - * Scalar Division Operator -- Divide a vector by a scalar * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - *========================================================================*/ -WWINLINE Vector2 operator / (const Vector2 &a,float k) -{ - float ook=1.0f/k; - float a0ook(a[0] * ook); - float a1ook(a[1] * ook); - return Vector2(a0ook,a1ook); -} - -/************************************************************************** - * Vector Addition Operator -- Add two vectors * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 02/24/1997 GH : Created. * - *========================================================================*/ -WWINLINE Vector2 operator + (const Vector2 &a,const Vector2 &b) -{ - return Vector2( - a.X + b.X, - a.Y + b.Y - ); -} - -/************************************************************************** - * Vector Subtraction Operator -- Subract two vectors * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 02/24/1997 GH : Created. * - *========================================================================*/ -WWINLINE Vector2 operator - (const Vector2 &a,const Vector2 &b) -{ - return Vector2( - a.X - b.X, - a.Y - b.Y - ); -} - -/************************************************************************** - * Vector Inner Product -- Compute the inner or dot product of two vector * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - *========================================================================*/ -WWINLINE float operator * (const Vector2 &a,const Vector2 &b) -{ - return a.X*b.X + a.Y*b.Y; -} - -WWINLINE float Vector2::Dot_Product(const Vector2 &a,const Vector2 &b) -{ - return a*b; -} - -WWINLINE float Vector2::Perp_Dot_Product(const Vector2 &a,const Vector2 &b) -{ - return a.X * -b.Y + a.Y * b.X; -} - -/************************************************************************** - * Vector Equality Operator -- Detemine if two vectors are identical * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - *========================================================================*/ -WWINLINE bool operator == (const Vector2 &a,const Vector2 &b) -{ - bool a0b0(a[0] == b[0]); - bool a1b1(a[1] == b[1]); - return ( a0b0 & a1b1); -} - -/************************************************************************** - * Vector Inequality Operator -- Detemine if two vectors are identical * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - *========================================================================*/ -WWINLINE bool operator != (const Vector2 &a,const Vector2 &b) -{ - bool a0b0(a[0] != b[0]); - bool a1b1(a[1] != b[1]); - return ( a0b0 | a1b1); -} - -/************************************************************************** - * Equal_Within_Epsilon -- Determine if two vectors are identical within e* - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - *========================================================================*/ -WWINLINE bool Equal_Within_Epsilon(const Vector2 &a,const Vector2 &b,float epsilon) -{ - return( (WWMath::Fabs(a.X - b.X) < epsilon) && (WWMath::Fabs(a.Y - b.Y) < epsilon) ); -} - -/************************************************************************** - * Vector2::Normalize -- Normalizes the vector. * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - *========================================================================*/ -WWINLINE void Vector2::Normalize() -{ - float len2 = Length2(); - if (len2 != 0.0f) { - float oolen = WWMath::Inv_Sqrt(len2); - X *= oolen; - Y *= oolen; - } -} - -WWINLINE Vector2 Normalize(const Vector2 & vec) -{ - float len2 = vec.Length2(); - if (len2 != 0.0f) { - float oolen = WWMath::Inv_Sqrt(len2); - return vec / oolen; - } - return Vector2(0.0f,0.0f); -} - -/************************************************************************** - * Vector2::Length -- Returns the length of the vector * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - *========================================================================*/ -WWINLINE float Vector2::Length() const -{ - return (float)WWMath::Sqrt(Length2()); -} - -/************************************************************************** - * Vector2::Length -- Returns the square of the length of the vector * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - *========================================================================*/ -WWINLINE float Vector2::Length2() const -{ - return (X*X + Y*Y); -} - -/************************************************************************** - * Vector2::Rotate -- Rotate vector * - * * - * INPUT: * - * float theta - angle to rotate * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - *========================================================================*/ -WWINLINE void Vector2::Rotate(float theta) -{ - Rotate(WWMath::Sin(theta), WWMath::Cos(theta)); -} - -/************************************************************************** - * Vector2::Rotate -- Rotate vector * - * * - * INPUT: * - * s - sine of the angle * - * c - cosine of the angle * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - *========================================================================*/ -WWINLINE void Vector2::Rotate(float s, float c) -{ - float new_x = X * c + Y * -s; - float new_y = X * s + Y * c; - X = new_x; - Y = new_y; -} - -/************************************************************************** - * Vector2::Rotate -- Rotate towards given vector (stop on reaching it) * - * * - * INPUT: * - * float theta - angle to rotate * - * * - * OUTPUT: * - * bool - true if we have reached the desired vector * - * * - * WARNINGS: * - * This function assumes both vectors are normalized! * - * * - * HISTORY: * - *========================================================================*/ -WWINLINE bool Vector2::Rotate_Towards_Vector(Vector2 &target, float max_theta, bool & positive_turn) -{ - return Rotate_Towards_Vector(target, WWMath::Sin(max_theta), WWMath::Cos(max_theta), positive_turn); -} - -/************************************************************************** - * Vector2::Rotate -- Rotate towards given vector (stop on reaching it) * - * * - * INPUT: * - * s - sine of the angle * - * c - cosine of the angle * - * * - * OUTPUT: * - * bool - true if we have reached the desired vector * - * * - * WARNINGS: * - * This function assumes both vectors are normalized! * - * * - * HISTORY: * - *========================================================================*/ -WWINLINE bool Vector2::Rotate_Towards_Vector(Vector2 &target, float max_s, float max_c, bool & positive_turn) -{ - bool return_value = false; - - positive_turn = Vector2::Perp_Dot_Product(target, *this) > 0.0f; - - if (Vector2::Dot_Product(*this, target) >= max_c) { - Set(target); - return_value = true; - } else { - // Determine turn direction and rotate accordingly. - if (positive_turn) { - Rotate(max_s, max_c); - } else { - Rotate(-max_s, max_c); - } - } - - return return_value; -} - -/*********************************************************************************************** - * Swap -- swap two Vector2's * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 08/11/1997 GH : Created. * - *=============================================================================================*/ -WWINLINE void Swap(Vector2 & a,Vector2 & b) -{ - Vector2 tmp(a); - a = b; - b = tmp; -} - - -/*********************************************************************************************** - * Vector2::Is_Valid -- Verifies that all components are valid floats * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 10/18/99 gth : Created. * - *=============================================================================================*/ -WWINLINE bool Vector2::Is_Valid(void) const -{ - return (WWMath::Is_Valid_Float(X) && WWMath::Is_Valid_Float(Y)); -} - - -/*********************************************************************************************** - * Vector2::Update_Min -- Set each component of the vector to the min of this and a. * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 06/12/00 IML : Created. * - *=============================================================================================*/ -WWINLINE void Vector2::Update_Min (const Vector2 & a) -{ - if (a.X < X) X = a.X; - if (a.Y < Y) Y = a.Y; -} - - -/*********************************************************************************************** - * Vector2::Update_Max -- Set each component of the vector to the max of this and a. * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 06/12/00 IML : Created. * - *=============================================================================================*/ -WWINLINE void Vector2::Update_Max (const Vector2 & a) -{ - if (a.X > X) X = a.X; - if (a.Y > Y) Y = a.Y; -} - - -/*********************************************************************************************** - * Vector2::Scale -- multiply components of a vector by independant scaling factors. * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 06/19/2000 IML : Created. * - *=============================================================================================*/ -WWINLINE void Vector2::Scale (float a, float b) -{ - X *= a; - Y *= b; -} - - -/*********************************************************************************************** - * Vector2::Scale -- multiply components of a vector by independant scaling factors. * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 06/19/2000 IML : Created. * - *=============================================================================================*/ -WWINLINE void Vector2::Scale (const Vector2 & a) -{ - X *= a.X; - Y *= a.Y; -} - - -/*********************************************************************************************** - * Quick_Distance -- Fast but inaccurate 2D distance calculation. * - * * - * * - * * - * * - * HISTORY: * - * 11/29/1999MLL: Created. * - *=============================================================================================*/ -WWINLINE float Quick_Distance(float x1, float y1, float x2, float y2) -{ - // From Graphic Gems I. - float x_diff = x1 - x2; - float y_diff = y1 - y2; - - WWMath::Fabs(x_diff); - WWMath::Fabs(y_diff); - - if (x_diff > y_diff) - { - return ((y_diff / 2) + x_diff); - } - else - { - return ((x_diff / 2) + y_diff); - } -} - -WWINLINE float Vector2::Quick_Distance(const Vector2 &a, const Vector2 &b) -{ - return ::Quick_Distance(a.X, a.Y, b.X, b.Y); -} - - -/*********************************************************************************************** - * Distance -- Accurate distance 2D calculation. * - * * - * * - * * - * * - * HISTORY: * - * 11/29/1999MLL: Created. * - *=============================================================================================*/ -WWINLINE float Vector2::Distance(const Vector2 &a, const Vector2 &b) -{ - Vector2 temp; - temp = a - b; - - return (temp.Length()); -} - -WWINLINE float Distance(float x1, float y1, float x2, float y2) -{ - float x_diff = x1 - x2; - float y_diff = y1 - y2; - - return (WWMath::Sqrt((x_diff * x_diff) + (y_diff * y_diff))); -} - - -/*********************************************************************************************** - * Vector2::Lerp -- linearly interpolates two Vector2's * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 4/14/2000 gth : Created. * - *=============================================================================================*/ -WWINLINE void Vector2::Lerp(const Vector2 & a,const Vector2 & b,float t,Vector2 * set_result) -{ - assert(set_result != NULL); - set_result->X = (a.X + (b.X - a.X)*t); - set_result->Y = (a.Y + (b.Y - a.Y)*t); -} - - -#endif /* VECTOR2_H */ - diff --git a/Generals/Code/Libraries/Source/WWVegas/WWMath/vector2i.h b/Generals/Code/Libraries/Source/WWVegas/WWMath/vector2i.h deleted file mode 100644 index 2bf67476a78..00000000000 --- a/Generals/Code/Libraries/Source/WWVegas/WWMath/vector2i.h +++ /dev/null @@ -1,113 +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 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 : WWMath * - * * - * $Archive:: /Commando/Code/wwmath/vector2i.h $* - * * - * Author:: Eric Cosky * - * * - * $Modtime:: 5/10/01 11:37p $* - * * - * $Revision:: 4 $* - * * - *---------------------------------------------------------------------------------------------* - * Functions: * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - - -#if defined(_MSC_VER) -#pragma once -#endif - -#ifndef VECTOR2I_H -#define VECTOR2I_H - -#include "always.h" - -class Vector2i -{ -public: - - int I; - int J; - - WWINLINE Vector2i(void); - WWINLINE Vector2i(int i,int j); - - WWINLINE void Set(int i, int j); - - WWINLINE void Swap(Vector2i & other); - - WWINLINE bool operator== (const Vector2i & v) const; - WWINLINE bool operator!= (const Vector2i& v) const; - WWINLINE const int& operator[] (int n) const; - WWINLINE int& operator[] (int n); -}; - - -WWINLINE Vector2i::Vector2i(void) -{ -} - -WWINLINE Vector2i::Vector2i(int i,int j) -{ - I = i; J = j; -} - -WWINLINE bool Vector2i::operator == (const Vector2i & v) const -{ - return (I == v.I && J == v.J ); -} - -WWINLINE bool Vector2i::operator != (const Vector2i& v) const -{ - return !(I == v.I && J == v.J); -} - -WWINLINE const int& Vector2i::operator[] (int n) const -{ - return ((int*)this)[n]; -} - -WWINLINE int& Vector2i::operator[] (int n) -{ - return ((int*)this)[n]; -} - -WWINLINE void Vector2i::Set(int i, int j) { I = i; J = j; } - -WWINLINE void Vector2i::Swap(Vector2i & other) -{ - // this could use MMX.. - - I ^= other.I; - other.I ^= I; - I ^= other.I; - - J ^= other.J; - other.J ^= J; - J ^= other.J; -} - - -#endif \ No newline at end of file diff --git a/Generals/Code/Libraries/Source/WWVegas/WWMath/vector3.h b/Generals/Code/Libraries/Source/WWVegas/WWMath/vector3.h deleted file mode 100644 index 8287842b1de..00000000000 --- a/Generals/Code/Libraries/Source/WWVegas/WWMath/vector3.h +++ /dev/null @@ -1,939 +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 . -*/ - -/* $Header: /Commando/Code/wwmath/vector3.h 40 5/11/01 7:11p Jani_p $ */ -/*********************************************************************************************** - *** Confidential - Westwood Studios *** - *********************************************************************************************** - * * - * Project Name : Westwood 3D * - * * - * File Name : VECTOR3.H * - * * - * Programmer : Greg Hjelstrom * - * * - * Start Date : 02/24/97 * - * * - * Last Update : February 24, 1997 [GH] * - * * - *---------------------------------------------------------------------------------------------* - * Functions: * - * Scalar Division Operator -- Divide a vector by a scalar * - * Scalar Multiply Operator -- Multiply a vector by a scalar * - * Vector Addition Operator -- Add two vectors * - * Vector Subtraction Operator -- Subract two vectors * - * Vector Inner Product Operator -- Compute the inner or dot product * - * Vector Equality Operator -- Determine if two vectors are identical * - * Vector Inequality Operator -- Determine if two vectors are identical * - * Equal_Within_Epsilon -- Determine if two vectors are identical within * - * Cross_Product -- compute the cross product of two vectors * - * Vector3::Normalize -- Normalizes the vector. * - * Vector3::Length -- Returns the length of the vector * - * Vector3::Length2 -- Returns the square of the length of the vector * - * Vector3::Quick_Length -- returns a quick approximation of the length * - * Swap -- swap two Vector3's * - * Lerp -- linearly interpolate two Vector3's by an interpolation factor. * - * Lerp -- linearly interpolate two Vector3's without return-by-value * - * Vector3::Add -- Add two vector3's without return-by-value * - * Vector3::Subtract -- Subtract two vector3's without return-by-value * - * Vector3::Update_Min -- sets each component of the vector to the min of this and a * - * Vector3::Update_Max -- Sets each component of the vector to the max of this and a * - * Vector3::Scale -- scale this vector by 3 independent scale factors * - * Vector3::Rotate_X -- rotates this vector around the X axis * - * Vector3::Rotate_X -- Rotates this vector around the x axis * - * Vector3::Rotate_Y -- Rotates this vector around the y axis * - * Vector3::Rotate_Y -- Rotates this vector around the Y axis * - * Vector3::Rotate_Z -- Rotates this vector around the Z axis * - * Vector3::Rotate_Z -- Rotates this vector around the Z axis * - * Vector3::Is_Valid -- Verifies that each component of this vector is a valid float * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - -#if defined(_MSC_VER) -#pragma once -#endif - -#ifndef VECTOR3_H -#define VECTOR3_H - -#include "always.h" -#include "wwmath.h" -#include -#ifdef _UNIX -#include "osdep.h" -#endif - - -/* -** Vector3 - 3-Dimensional Vectors -*/ -class Vector3 -{ - -public: - - - float X; - float Y; - float Z; - - - // Constructors - WWINLINE Vector3(void) {}; - WWINLINE Vector3(const Vector3 & v) { X = v.X; Y = v.Y; Z = v.Z; } - WWINLINE Vector3(float x, float y, float z) { X = x; Y = y; Z = z; } - WWINLINE Vector3(const float vector[3]) { X = vector[0]; Y = vector[1]; Z = vector[2]; } - - // Assignment - WWINLINE Vector3 & operator = (const Vector3 & v) { X = v.X; Y = v.Y; Z = v.Z; return *this; } - WWINLINE void Set(float x, float y, float z) { X = x; Y = y; Z = z; } - WWINLINE void Set(const Vector3 & that) { X = that.X; Y = that.Y; Z = that.Z; } - - // Array access - WWINLINE float & operator [](int i) { return (&X)[i]; } - WWINLINE const float & operator [](int i) const { return (&X)[i]; } - - // normalize, compute length - void Normalize(void); - WWINLINE float Length(void) const; - WWINLINE float Length2(void) const; - float Quick_Length(void) const; - void Scale(const Vector3 & scale); - - // rotation, (warning, modifies this vector!) - WWINLINE void Rotate_X(float angle); - WWINLINE void Rotate_X(float s_angle,float c_angle); - WWINLINE void Rotate_Y(float angle); - WWINLINE void Rotate_Y(float s_angle,float c_angle); - WWINLINE void Rotate_Z(float angle); - WWINLINE void Rotate_Z(float s_angle,float c_angle); - - // unary operators - WWINLINE Vector3 operator-() const { return(Vector3(-X,-Y,-Z)); } - WWINLINE Vector3 operator+() const { return *this; } - - WWINLINE Vector3 & operator += (const Vector3 & v) { X += v.X; Y += v.Y; Z += v.Z; return *this; } - WWINLINE Vector3 & operator -= (const Vector3 & v) { X -= v.X; Y -= v.Y; Z -= v.Z; return *this; } - WWINLINE Vector3 & operator *= (float k) { X = X*k; Y=Y*k; Z=Z*k; return *this; } - WWINLINE Vector3 & operator /= (float k) { float ook=1.0f/k; X=X*ook; Y=Y*ook; Z=Z*ook; return *this; } - - // scalar multiplication, division - WWINLINE friend Vector3 operator * (const Vector3 &a,float k); - WWINLINE friend Vector3 operator * (float k,const Vector3 &a); - WWINLINE friend Vector3 operator / (const Vector3 &a,float k); - - // vector addition,subtraction - WWINLINE friend Vector3 operator + (const Vector3 &a,const Vector3 &b); - WWINLINE friend Vector3 operator - (const Vector3 &a,const Vector3 &b); - - // Equality operators - friend bool operator == (const Vector3 &a,const Vector3 &b); - friend bool operator != (const Vector3 &a,const Vector3 &b); - WWINLINE friend bool Equal_Within_Epsilon(const Vector3 &a,const Vector3 &b,float epsilon); - - // dot product / inner product - WWINLINE friend float operator * (const Vector3 &a,const Vector3 &b); - static WWINLINE float Dot_Product(const Vector3 &a,const Vector3 &b); - - // cross product / outer product -#ifdef ALLOW_TEMPORARIES - static WWINLINE Vector3 Cross_Product(const Vector3 &a,const Vector3 &b); -#endif - static WWINLINE void Cross_Product(const Vector3 &a,const Vector3 &b,Vector3 * result); - static WWINLINE void Normalized_Cross_Product(const Vector3 &a, const Vector3 &b, Vector3 * result); - static WWINLINE float Cross_Product_X(const Vector3 &a,const Vector3 &b); - static WWINLINE float Cross_Product_Y(const Vector3 &a,const Vector3 &b); - static WWINLINE float Cross_Product_Z(const Vector3 &a,const Vector3 &b); - - // add and subtract without return by value - static WWINLINE void Add(const Vector3 & a,const Vector3 & b,Vector3 * c); - static WWINLINE void Subtract(const Vector3 & a,const Vector3 & b,Vector3 * c); - - // Line intersection functions. - static WWINLINE float Find_X_At_Y(float y, const Vector3 &p1, const Vector3 &p2); - static WWINLINE float Find_X_At_Z(float z, const Vector3 &p1, const Vector3 &p2); - static WWINLINE float Find_Y_At_X(float x, const Vector3 &p1, const Vector3 &p2); - static WWINLINE float Find_Y_At_Z(float z, const Vector3 &p1, const Vector3 &p2); - static WWINLINE float Find_Z_At_X(float x, const Vector3 &p1, const Vector3 &p2); - static WWINLINE float Find_Z_At_Y(float z, const Vector3 &p1, const Vector3 &p2); - - // make this vector the min or max of itself and the passed vector - WWINLINE void Update_Min(const Vector3 & a); - WWINLINE void Update_Max(const Vector3 & a); - WWINLINE void Cap_Absolute_To(const Vector3 & a); - - // verify that none of the members of this vector are invalid floats - WWINLINE bool Is_Valid(void) const; - - static WWINLINE float Quick_Distance(const Vector3 &p1, const Vector3 &p2); - static WWINLINE float Distance(const Vector3 &p1, const Vector3 &p2); - - // Linearly interpolate two Vector3's - static void Lerp(const Vector3 & a, const Vector3 & b, float alpha,Vector3 * set_result); - -#ifdef ALLOW_TEMPORARIES - static Vector3 Lerp(const Vector3 & a, const Vector3 & b, float alpha); -#endif - - // Color Conversion - WWINLINE unsigned long Convert_To_ABGR( void ) const; - WWINLINE unsigned long Convert_To_ARGB( void ) const; - WWINLINE unsigned long Convert_To_ARGB( float alpha ) const; -}; - - -/************************************************************************** - * Scalar Multiply Operator -- Multiply a vector by a scalar * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 02/24/1997 GH : Created. * - *========================================================================*/ -WWINLINE Vector3 operator * (const Vector3 &a,float k) -{ - return Vector3((a.X * k),(a.Y * k),(a.Z * k)); -} - -WWINLINE Vector3 operator * (float k, const Vector3 &a) -{ - return Vector3((a.X * k),(a.Y * k),(a.Z * k)); -} - -/************************************************************************** - * Scalar Division Operator -- Divide a vector by a scalar * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - *========================================================================*/ -WWINLINE Vector3 operator / (const Vector3 &a,float k) -{ - float ook = 1.0f/k; - return Vector3((a.X * ook),(a.Y * ook),(a.Z * ook)); -} - -/************************************************************************** - * Vector Addition Operator -- Add two vectors * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 02/24/1997 GH : Created. * - *========================================================================*/ -WWINLINE Vector3 operator + (const Vector3 &a,const Vector3 &b) -{ - return Vector3( - a.X+b.X, - a.Y+b.Y, - a.Z+b.Z - ); -} - -/************************************************************************** - * Vector Subtraction Operator -- Subract two vectors * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 02/24/1997 GH : Created. * - *========================================================================*/ -WWINLINE Vector3 operator - (const Vector3 &a,const Vector3 &b) -{ - return Vector3( - a.X-b.X, - a.Y-b.Y, - a.Z-b.Z - ); -} - -/************************************************************************** - * Vector Inner Product -- Compute the inner or dot product of two vector * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - *========================================================================*/ -WWINLINE float operator * (const Vector3 &a,const Vector3 &b) -{ - return a.X*b.X + - a.Y*b.Y + - a.Z*b.Z; -} - -WWINLINE float Vector3::Dot_Product(const Vector3 &a,const Vector3 &b) -{ - return a.X*b.X + - a.Y*b.Y + - a.Z*b.Z; -} - - -/************************************************************************** - * Vector Equality Operator -- Determine if two vectors are identical * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - *========================================================================*/ -WWINLINE bool operator == (const Vector3 &a,const Vector3 &b) -{ - return ( (a.X == b.X) && (a.Y == b.Y) && (a.Z == b.Z)); -} - -/************************************************************************** - * Vector Inequality Operator -- Determine if two vectors are identical * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - *========================================================================*/ -WWINLINE bool operator != (const Vector3 &a,const Vector3 &b) -{ - return ( (a.X != b.X) || (a.Y != b.Y) || (a.Z != b.Z)); -} - -/************************************************************************** - * Equal_Within_Epsilon -- Determine if two vectors are identical within e* - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - *========================================================================*/ -WWINLINE bool Equal_Within_Epsilon(const Vector3 &a,const Vector3 &b,float epsilon) -{ - return( (WWMath::Fabs(a.X - b.X) < epsilon) && - (WWMath::Fabs(a.Y - b.Y) < epsilon) && - (WWMath::Fabs(a.Z - b.Z) < epsilon) ); -} - - -/************************************************************************** - * Cross_Product -- compute the cross product of two vectors * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - *========================================================================*/ -#ifdef ALLOW_TEMPORARIES -WWINLINE Vector3 Vector3::Cross_Product(const Vector3 &a,const Vector3 &b) -{ - return Vector3( - (a.Y * b.Z - a.Z * b.Y), - (a.Z * b.X - a.X * b.Z), - (a.X * b.Y - a.Y * b.X) - ); -} -#endif - -WWINLINE void Vector3::Cross_Product(const Vector3 &a,const Vector3 &b,Vector3 * set_result) -{ - assert(set_result != &a); - set_result->X = (a.Y * b.Z - a.Z * b.Y); - set_result->Y = (a.Z * b.X - a.X * b.Z); - set_result->Z = (a.X * b.Y - a.Y * b.X); -} - -WWINLINE void Vector3::Normalized_Cross_Product(const Vector3 &a,const Vector3 &b,Vector3 * set_result) -{ - assert(set_result != &a); - set_result->X = (a.Y * b.Z - a.Z * b.Y); - set_result->Y = (a.Z * b.X - a.X * b.Z); - set_result->Z = (a.X * b.Y - a.Y * b.X); - set_result->Normalize(); -} - -WWINLINE float Vector3::Cross_Product_X(const Vector3 &a,const Vector3 &b) -{ - return a.Y * b.Z - a.Z * b.Y; -} - -WWINLINE float Vector3::Cross_Product_Y(const Vector3 &a,const Vector3 &b) -{ - return a.Z * b.X - a.X * b.Z; -} - -WWINLINE float Vector3::Cross_Product_Z(const Vector3 &a,const Vector3 &b) -{ - return a.X * b.Y - a.Y * b.X; -} - -/************************************************************************** - * Vector3::Normalize -- Normalizes the vector. * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - *========================================================================*/ -WWINLINE void Vector3::Normalize() -{ - float len2 = Length2(); - if (len2 != 0.0f) - { - float oolen = WWMath::Inv_Sqrt(len2); - X *= oolen; - Y *= oolen; - Z *= oolen; - } -} - -#ifdef ALLOW_TEMPORARIES -WWINLINE Vector3 Normalize(const Vector3 & vec) -{ - float len2 = vec.Length2(); - if (len2 != 0.0f) - { - float oolen = WWMath::Inv_Sqrt(len2); - return vec * oolen; - } - return vec; -} -#endif - -/************************************************************************** - * Vector3::Length -- Returns the length of the vector * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - *========================================================================*/ -WWINLINE float Vector3::Length() const -{ - return WWMath::Sqrt(Length2()); -} - -/************************************************************************** - * Vector3::Length2 -- Returns the square of the length of the vector * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - *========================================================================*/ -WWINLINE float Vector3::Length2() const -{ - return X*X + Y*Y + Z*Z; -} - - -/*********************************************************************************************** - * Vector3::Quick_Length -- returns a quick approximation of the length * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 7/15/98 GTH : Created. * - *=============================================================================================*/ -WWINLINE float Vector3::Quick_Length(void) const -{ - // this method of approximating the length comes from Graphics Gems 1 and - // supposedly gives an error of +/- 8% - float max = WWMath::Fabs(X); - float mid = WWMath::Fabs(Y); - float min = WWMath::Fabs(Z); - float tmp; - - if (max < mid) { tmp = max; max = mid; mid = tmp; } - if (max < min) { tmp = max; max = min; min = tmp; } - if (mid < min) { tmp = mid; mid = min; min = mid; } - - return max + (11.0f / 32.0f)*mid + (1.0f / 4.0f)*min; -} - - -/*********************************************************************************************** - * Swap -- swap two Vector3's * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 08/11/1997 GH : Created. * - *=============================================================================================*/ -WWINLINE void Swap(Vector3 & a,Vector3 & b) -{ - Vector3 tmp(a); - a = b; - b = tmp; -} - -/*********************************************************************************************** - * Lerp -- linearly interpolate two Vector3's without return-by-value * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 10/18/99 gth : Created. * - *=============================================================================================*/ -WWINLINE void Vector3::Lerp(const Vector3 & a, const Vector3 & b, float alpha,Vector3 * set_result) -{ - assert(set_result != NULL); - set_result->X = (a.X + (b.X - a.X)*alpha); - set_result->Y = (a.Y + (b.Y - a.Y)*alpha); - set_result->Z = (a.Z + (b.Z - a.Z)*alpha); -} - - -#ifdef ALLOW_TEMPORARIES -WWINLINE Vector3 Vector3::Lerp(const Vector3 & a, const Vector3 & b, float alpha) -{ - Vector3 set_result; - Vector3::Lerp(a, b, alpha, &set_result); - return set_result; -} -#endif - -/*********************************************************************************************** - * Vector3::Add -- Add two vector3's without return-by-value * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 10/18/99 gth : Created. * - *=============================================================================================*/ -WWINLINE void Vector3::Add(const Vector3 &a,const Vector3 &b,Vector3 * set_result) -{ - assert(set_result != NULL); - set_result->X = a.X + b.X; - set_result->Y = a.Y + b.Y; - set_result->Z = a.Z + b.Z; -} - - -/*********************************************************************************************** - * Vector3::Subtract -- Subtract two vector3's without return-by-value * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 10/18/99 gth : Created. * - *=============================================================================================*/ -WWINLINE void Vector3::Subtract(const Vector3 &a,const Vector3 &b,Vector3 * set_result) -{ - assert(set_result != NULL); - set_result->X = a.X - b.X; - set_result->Y = a.Y - b.Y; - set_result->Z = a.Z - b.Z; -} - - -/*********************************************************************************************** - * Vector3::Update_Min -- sets each component of the vector to the min of this and a * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 10/18/99 gth : Created. * - *=============================================================================================*/ -WWINLINE void Vector3::Update_Min(const Vector3 & a) -{ - if (a.X < X) X = a.X; - if (a.Y < Y) Y = a.Y; - if (a.Z < Z) Z = a.Z; -} - - -/*********************************************************************************************** - * Vector3::Update_Max -- Sets each component of the vector to the max of this and a * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 10/18/99 gth : Created. * - *=============================================================================================*/ -WWINLINE void Vector3::Update_Max(const Vector3 & a) -{ - if (a.X > X) X = a.X; - if (a.Y > Y) Y = a.Y; - if (a.Z > Z) Z = a.Z; -} - -/*********************************************************************************************** - * Vector3::Cap_To_Absolute_Of -- Sets each component of the vector to no larger than the -ve or +ve of* - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 11/29/99 wst : Created. * - *=============================================================================================*/ -WWINLINE void Vector3::Cap_Absolute_To(const Vector3 & a) -{ - if (X > 0) - { - if (a.X < X) X = a.X; - } - else - { - if (-a.X > X) X = -a.X; - } - - if (Y > 0) - { - if (a.Y < Y) Y = a.Y; - } - else - { - if (-a.Y > Y) Y = -a.Y; - } - - if (Z > 0) - { - if (a.Z < Z) Z = a.Z; - } - else - { - if (-a.Z > Z) Z = -a.Z; - } - -} - -/*********************************************************************************************** - * Vector3::Scale -- scale this vector by 3 independent scale factors * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 10/18/99 gth : Created. * - *=============================================================================================*/ -WWINLINE void Vector3::Scale(const Vector3 & scale) -{ - X *= scale.X; - Y *= scale.Y; - Z *= scale.Z; -} - - -/*********************************************************************************************** - * Vector3::Rotate_X -- rotates this vector around the X axis * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 10/18/99 gth : Created. * - *=============================================================================================*/ -WWINLINE void Vector3::Rotate_X(float angle) -{ - Rotate_X(sinf(angle),cosf(angle)); -} - - -/*********************************************************************************************** - * Vector3::Rotate_X -- Rotates this vector around the x axis * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 10/18/99 gth : Created. * - *=============================================================================================*/ -WWINLINE void Vector3::Rotate_X(float s_angle,float c_angle) -{ - float tmp_y = Y; - float tmp_z = Z; - - Y = c_angle * tmp_y - s_angle * tmp_z; - Z = s_angle * tmp_y + c_angle * tmp_z; -} - - -/*********************************************************************************************** - * Vector3::Rotate_Y -- Rotates this vector around the y axis * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 10/18/99 gth : Created. * - *=============================================================================================*/ -WWINLINE void Vector3::Rotate_Y(float angle) -{ - Rotate_Y(sinf(angle),cosf(angle)); -} - - -/*********************************************************************************************** - * Vector3::Rotate_Y -- Rotates this vector around the Y axis * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 10/18/99 gth : Created. * - *=============================================================================================*/ -WWINLINE void Vector3::Rotate_Y(float s_angle,float c_angle) -{ - float tmp_x = X; - float tmp_z = Z; - - X = c_angle * tmp_x + s_angle * tmp_z; - Z = -s_angle * tmp_x + c_angle * tmp_z; -} - - -/*********************************************************************************************** - * Vector3::Rotate_Z -- Rotates this vector around the Z axis * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 10/18/99 gth : Created. * - *=============================================================================================*/ -WWINLINE void Vector3::Rotate_Z(float angle) -{ - Rotate_Z(sinf(angle),cosf(angle)); -} - - -/*********************************************************************************************** - * Vector3::Rotate_Z -- Rotates this vector around the Z axis * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 10/18/99 gth : Created. * - *=============================================================================================*/ -WWINLINE void Vector3::Rotate_Z(float s_angle,float c_angle) -{ - float tmp_x = X; - float tmp_y = Y; - - X = c_angle * tmp_x - s_angle * tmp_y; - Y = s_angle * tmp_x + c_angle * tmp_y; -} - - -/*********************************************************************************************** - * Vector3::Is_Valid -- Verifies that each component of this vector is a valid float * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 10/18/99 gth : Created. * - *=============================================================================================*/ -WWINLINE bool Vector3::Is_Valid(void) const -{ - return (WWMath::Is_Valid_Float(X) && WWMath::Is_Valid_Float(Y) && WWMath::Is_Valid_Float(Z)); -} - -WWINLINE float Vector3::Find_X_At_Y(float y, const Vector3 &p1, const Vector3 &p2) -{ - return(p1.X + ((y - p1.Y) * ((p2.X - p1.X) / (p2.Y - p1.Y)))); -} -WWINLINE float Vector3::Find_X_At_Z(float z, const Vector3 &p1, const Vector3 &p2) -{ - return(p1.X + ((z - p1.Z) * ((p2.X - p1.X) / (p2.Z - p1.Z)))); -} -WWINLINE float Vector3::Find_Y_At_X(float x, const Vector3 &p1, const Vector3 &p2) -{ - return(p1.Y + ((x - p1.X) * ((p2.Y - p1.Y) / (p2.X - p1.X)))); -} -WWINLINE float Vector3::Find_Y_At_Z(float z, const Vector3 &p1, const Vector3 &p2) -{ - return(p1.Y + ((z - p1.Z) * ((p2.Y - p1.Y) / (p2.Z - p1.Z)))); -} -WWINLINE float Vector3::Find_Z_At_X(float x, const Vector3 &p1, const Vector3 &p2) -{ - return(p1.Z + ((x - p1.X) * ((p2.Z - p1.Z) / (p2.X - p1.X)))); -} -WWINLINE float Vector3::Find_Z_At_Y(float y, const Vector3 &p1, const Vector3 &p2) -{ - return(p1.Z + ((y - p1.Y) * ((p2.Z - p1.Z) / (p2.Y - p1.Y)))); -} - -/*********************************************************************************************** - * Vector3::Distance -- Accurate distance calculation. * - * * - * * - * * - * * - * HISTORY: * - * 11/29/1999MLL: Created. * - *=============================================================================================*/ -WWINLINE float Vector3::Distance(const Vector3 &p1, const Vector3 &p2) -{ - Vector3 temp; - temp = p1 - p2; - return (temp.Length()); -} - -/*********************************************************************************************** - * Vector3::Quick_Distance -- Fast but inaccurate distance calculation. * - * * - * * - * * - * * - * HISTORY: * - * 11/29/1999MLL: Created. * - *=============================================================================================*/ -WWINLINE float Vector3::Quick_Distance(const Vector3 &p1, const Vector3 &p2) -{ - Vector3 temp; - temp = p1 - p2; - return (temp.Quick_Length()); -} - -/*********************************************************************************************** - * Vector3::Convert_To_ABGR -- Converts to SR packed color . * - * * - * * - * * - * * - * HISTORY: * - * 11/29/1999MLL: Created. * - *=============================================================================================*/ -WWINLINE unsigned long Vector3::Convert_To_ABGR( void ) const -{ - return (unsigned(255)<<24) | - (unsigned(Z*255.0f)<<16) | - (unsigned(Y*255.0f)<<8) | - (unsigned(X*255.0f)); -} - -/*********************************************************************************************** - * Vector3::Convert_To_ARGB -- Converts to packed color . * - * * - * * - * * - * * - * HISTORY: * - * 11/29/1999MLL: Created. * - *=============================================================================================*/ -WWINLINE unsigned long Vector3::Convert_To_ARGB( void ) const -{ - return (unsigned(255)<<24) | - (unsigned(X*255.0f)<<16) | - (unsigned(Y*255.0f)<<8) | - (unsigned(Z*255.0f)); -} - -WWINLINE unsigned long Vector3::Convert_To_ARGB( float alpha ) const -{ - return (unsigned(alpha * 255)<<24) | - (unsigned(X*255.0f)<<16) | - (unsigned(Y*255.0f)<<8) | - (unsigned(Z*255.0f)); -} - -#endif /* Vector3_H */ - diff --git a/Generals/Code/Libraries/Source/WWVegas/WWMath/vector4.h b/Generals/Code/Libraries/Source/WWVegas/WWMath/vector4.h deleted file mode 100644 index 146347f8d6f..00000000000 --- a/Generals/Code/Libraries/Source/WWVegas/WWMath/vector4.h +++ /dev/null @@ -1,412 +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 . -*/ - -/* $Header: /Commando/Code/wwmath/vector4.h 16 5/11/01 7:11p Jani_p $ */ -/*************************************************************************** - *** Confidential - Westwood Studios *** - *************************************************************************** - * * - * Project Name : Westwood 3D * - * * - * File Name : VECTOR4.H * - * * - * Programmer : Greg Hjelstrom * - * * - * Start Date : 02/24/97 * - * * - * Last Update : June 2, 1997 [GH] * - * * - *-------------------------------------------------------------------------* - * Functions: * - * Scalar Division Operator -- Divide a vector by a scalar * - * Scalar Multiply Operator -- Multiply a vector by a scalar * - * Vector Addition Operator -- Add two vectors * - * Vector Subtraction Operator -- Subract two vectors * - * Vector Inner Product Operator -- Compute the inner or dot product * - * Vector Equality Operator -- Detemine if two vectors are identical * - * Vector Inequality Operator -- Detemine if two vectors are identical * - * Swap -- swap two Vector4's * - * Vector4::Is_Valid -- Vector4::Is_Valid * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - -#if defined(_MSC_VER) -#pragma once -#endif - -#ifndef VECTOR4_H -#define VECTOR4_H - -#include "always.h" -#include "wwmath.h" -#include - -/* -** Vector4 - 4 dimensional vectors -*/ -class Vector4 -{ - -public: - - float X; - float Y; - float Z; - float W; - - - // Constructors - WWINLINE Vector4(void) {}; - WWINLINE Vector4(const Vector4 & v) { X = v.X; Y = v.Y; Z = v.Z; W = v.W; } - WWINLINE Vector4(float x, float y, float z, float w) { X = x; Y = y; Z = z; W = w; } - WWINLINE Vector4(const float vector[4]) { X = vector[0]; Y = vector[1]; Z = vector[2]; W = vector[3]; } - - // Assignment - WWINLINE Vector4 & operator = (const Vector4 & v) { X = v.X; Y = v.Y; Z = v.Z; W = v.W; return *this; } - WWINLINE void Set(float x, float y, float z, float w) { X = x; Y = y; Z = z; W = w; } - - // Array access - WWINLINE float & operator [](int i) { return (&X)[i]; } - WWINLINE const float & operator [](int i) const { return (&X)[i]; } - - // normalize, compute length - void Normalize(void); - WWINLINE float Length(void) const; - WWINLINE float Length2(void) const; - - // unary operators - WWINLINE Vector4 operator-() const { return(Vector4(-X,-Y,-Z,-W)); } - WWINLINE Vector4 operator+() const { return *this; } - - WWINLINE Vector4 & operator += (const Vector4 & v) { X += v.X; Y += v.Y; Z += v.Z; W += v.W; return *this; } - WWINLINE Vector4 & operator -= (const Vector4 & v) { X -= v.X; Y -= v.Y; Z -= v.Z; W += v.W; return *this; } - WWINLINE Vector4 & operator *= (float k) { X = X*k; Y=Y*k; Z=Z*k; W=W*k; return *this; } - WWINLINE Vector4 & operator /= (float k) { k=1.0f/k; X = X*k; Y=Y*k; Z=Z*k; W=W*k; return *this; } - - // scalar multiplication, division - WWINLINE friend Vector4 operator * (const Vector4 &a,float k); - WWINLINE friend Vector4 operator * (float k,const Vector4 &a); - WWINLINE friend Vector4 operator / (const Vector4 &a,float k); - - // vector addition,subtraction - WWINLINE friend Vector4 operator + (const Vector4 &a,const Vector4 &b); - WWINLINE friend Vector4 operator - (const Vector4 &a,const Vector4 &b); - - // dot product / inner product - WWINLINE friend float operator * (const Vector4 &a,const Vector4 &b); - static WWINLINE float Dot_Product(const Vector4 &a,const Vector4 &b); - - // Equality operators - friend bool operator == (const Vector4 &a,const Vector4 &b); - friend bool operator != (const Vector4 &a,const Vector4 &b); - - // Linearly interpolate between two Vector4's - static Vector4 Lerp(const Vector4 & a, const Vector4 & b, float alpha); - static void Lerp(const Vector4 & a, const Vector4 & b, float alpha,Vector4 * set_result); - - // verify that none of the members of this vector are invalid floats - WWINLINE bool Is_Valid(void) const; -}; - -/************************************************************************** - * Scalar Multiply Operator -- Multiply a vector by a scalar * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 02/24/1997 GH : Created. * - *========================================================================*/ -WWINLINE Vector4 operator * (const Vector4 &a,float k) -{ - return Vector4((a.X * k),(a.Y * k),(a.Z * k),(a.W * k)); -} - -WWINLINE Vector4 operator * (float k, const Vector4 &a) -{ - return a*k; -} - -/************************************************************************** - * Scalar Division Operator -- Divide a vector by a scalar * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - *========================================================================*/ -WWINLINE Vector4 operator / (const Vector4 &a,float k) -{ - float ook=1.0f/k; - return Vector4((a[0] * ook),(a[1] * ook),(a[2] * ook),(a[3] * ook)); -} - -/************************************************************************** - * Vector Addition Operator -- Add two vectors * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 02/24/1997 GH : Created. * - *========================================================================*/ -WWINLINE Vector4 operator + (const Vector4 &a,const Vector4 &b) -{ - return Vector4( - a[0]+b[0], - a[1]+b[1], - a[2]+b[2], - a[3]+b[3] - ); -} - -/************************************************************************** - * Vector Subtraction Operator -- Subract two vectors * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 02/24/1997 GH : Created. * - *========================================================================*/ -WWINLINE Vector4 operator - (const Vector4 &a,const Vector4 &b) -{ - return Vector4( - a[0]-b[0], - a[1]-b[1], - a[2]-b[2], - a[3]-b[3] - ); -} - -/************************************************************************** - * Vector Inner Product -- Compute the inner or dot product of two vector * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - *========================================================================*/ -WWINLINE float operator * (const Vector4 &a,const Vector4 &b) -{ - return a[0]*b[0] + - a[1]*b[1] + - a[2]*b[2] + - a[3]*b[3]; -} - -WWINLINE float Vector4::Dot_Product(const Vector4 &a,const Vector4 &b) -{ - return a*b; -} - - -/************************************************************************** - * Vector Equality Operator -- Detemine if two vectors are identical * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - *========================================================================*/ -WWINLINE bool operator == (const Vector4 &a,const Vector4 &b) -{ - return ( (a[0] == b[0]) && (a[1] == b[1]) && (a[2] == b[2]) && (a[3] == b[3])); -} - -/************************************************************************** - * Vector Inequality Operator -- Detemine if two vectors are identical * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - *========================================================================*/ -WWINLINE bool operator != (const Vector4 &a,const Vector4 &b) -{ - return ( (a[0] != b[0]) || (a[1] != b[1]) || (a[2] != b[2]) || (a[3] != b[3])); -} - -/************************************************************************** - * Vector4::Normalize -- Normalizes the vector. * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - *========================================================================*/ -WWINLINE void Vector4::Normalize() -{ - float len2 = Length2(); - if (len2 != 0.0f) { - float oolen = WWMath::Inv_Sqrt(len2); - X *= oolen; - Y *= oolen; - Z *= oolen; - W *= oolen; - } -} - -WWINLINE Vector4 Normalize(const Vector4 & vec) -{ - float len2 = vec.Length2(); - if (len2 != 0.0f) { - float oolen = WWMath::Inv_Sqrt(len2); - return vec * oolen; - } - return Vector4(0.0f,0.0f,0.0f,0.0f); -} - -/************************************************************************** - * Vector4::Length -- Returns the length of the vector * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - *========================================================================*/ -WWINLINE float Vector4::Length() const -{ - return WWMath::Sqrt(Length2()); -} - -/************************************************************************** - * Vector4::Length -- Returns the square of the length of the vector * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - *========================================================================*/ -WWINLINE float Vector4::Length2() const -{ - return X*X + Y*Y + Z*Z + W*W; -} - - -/*********************************************************************************************** - * Swap -- swap two Vector4's * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 06/02/1997 GH : Created. * - *=============================================================================================*/ -WWINLINE void Swap(Vector4 & a,Vector4 & b) -{ - Vector4 tmp(a); - a = b; - b = tmp; -} - -/*********************************************************************************************** - * Lerp -- linearly interpolate two Vector4's by an interpolation factor. * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: No checking is done to ensure that alpha is between 0 and 1. * - * * - * HISTORY: * - * 01/14/1999 NH : Created. * - *=============================================================================================*/ -WWINLINE Vector4 Lerp(const Vector4 & a, const Vector4 & b, float alpha) -{ - return Vector4( - (a.X + (b.X - a.X)*alpha), - (a.Y + (b.Y - a.Y)*alpha), - (a.Z + (b.Z - a.Z)*alpha), - (a.W + (b.W - a.W)*alpha) - ); -} - -WWINLINE Vector4 Vector4::Lerp(const Vector4 & a, const Vector4 & b, float alpha) -{ - return Vector4( - (a.X + (b.X - a.X)*alpha), - (a.Y + (b.Y - a.Y)*alpha), - (a.Z + (b.Z - a.Z)*alpha), - (a.W + (b.W - a.W)*alpha) - ); -} - -WWINLINE void Vector4::Lerp(const Vector4 & a, const Vector4 & b, float alpha,Vector4 * set_result) -{ - set_result->X = (a.X + (b.X - a.X)*alpha); - set_result->Y = (a.Y + (b.Y - a.Y)*alpha); - set_result->Z = (a.Z + (b.Z - a.Z)*alpha); - set_result->X = (a.W + (b.W - a.W)*alpha); -} - -/*********************************************************************************************** - * Vector4::Is_Valid -- Vector4::Is_Valid * - * * - * verifies that all members of this vector are valid floats * - * * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 10/18/99 gth : Created. * - *=============================================================================================*/ -WWINLINE bool Vector4::Is_Valid(void) const -{ - return (WWMath::Is_Valid_Float(X) && WWMath::Is_Valid_Float(Y) && WWMath::Is_Valid_Float(Z) && WWMath::Is_Valid_Float(W)); -} - - -#endif /* VECTOR4_H */ - diff --git a/Generals/Code/Libraries/Source/WWVegas/WWMath/vehiclecurve.cpp b/Generals/Code/Libraries/Source/WWVegas/WWMath/vehiclecurve.cpp deleted file mode 100644 index 40afd6f50f2..00000000000 --- a/Generals/Code/Libraries/Source/WWVegas/WWMath/vehiclecurve.cpp +++ /dev/null @@ -1,686 +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 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 : LevelEdit * - * * - * $Archive:: /Commando/Code/wwmath/vehiclecurve.cpp $* - * * - * Author:: Patrick Smith * - * * - * $Modtime:: 6/12/01 10:02a $* - * * - * $Revision:: 8 $* - * * - *---------------------------------------------------------------------------------------------* - * Functions: * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - -#include "vehiclecurve.h" -#include "vector3.h" -#include "matrix3d.h" -#include "persistfactory.h" -#include "wwmathids.h" -#include "wwmemlog.h" - - -////////////////////////////////////////////////////////////////////// -// Save-Load stuff -////////////////////////////////////////////////////////////////////// -SimplePersistFactoryClass _VehicleCurveFactory; - -//////////////////////////////////////////////////////////////// -// Save/Load constants -//////////////////////////////////////////////////////////////// -enum -{ - CHUNKID_PARENT = 0x11071217, - CHUNKID_ARC_INFO, - CHUNKID_VARIABLES -}; - -enum -{ - VARID_IS_DIRTY = 1, - VARID_RADIUS, -}; - - -////////////////////////////////////////////////////////////////////// -// Local prototypes -////////////////////////////////////////////////////////////////////// -bool Find_Tangent (const Vector3 ¢er, float radius, const Vector3 &point, bool clockwise, float *result); -float Get_Angle_Delta (float angle1, float angle2, bool clockwise); -void Find_Turn_Arc (const Matrix3D &transform, float radius, const Vector3 &prev_pt, const Vector3 &curr_pt, const Vector3 &next_pt, Vector3 *arc_center, bool *is_right_turn); -void Find_Tangents (float radius, const Vector3 &prev_pt, const Vector3 &curr_pt, const Vector3 &next_pt, const Vector3 &arc_center, bool is_right_turn, float *point_angle, float *angle_in_delta, float *angle_out_delta); - - -////////////////////////////////////////////////////////////////////// -// -// Find_Tangent -// -////////////////////////////////////////////////////////////////////// -bool -Find_Tangent -( - const Vector3 & center, - float radius, - const Vector3 & point, - bool clockwise, - float * result -) -{ - bool retval = false; - - // - // Calculate the distance from the point to the center of the circle - // - float delta_x = point.X - center.X; - float delta_y = point.Y - center.Y; - float dist = ::sqrt (delta_x * delta_x + delta_y * delta_y); - if (dist >= radius) { - - // - // Determine the offset angle (from the line between the point and center) - // where the 2 tangent points lie. - // - float angle_offset = WWMath::Acos (radius / dist); - float base_angle = WWMath::Atan2 (delta_x, -delta_y); - base_angle = WWMath::Wrap (base_angle, 0, DEG_TO_RADF (360)); - - // - // Determine which tangent angle we would come across first, depending - // on our orientation - // - float angle = 0; - if (clockwise) { - angle = base_angle - angle_offset; - } else { - angle = base_angle + angle_offset; - } - angle = WWMath::Wrap (angle, 0, DEG_TO_RADF (360)); - (*result) = angle; - - retval = true; - } - - return retval; -} - - -////////////////////////////////////////////////////////////////////// -// -// Get_Angle_Delta -// -// Angle deltas need to be wrapped around 360 degrees differently -// depending on the orientation (clockwise/counterclockwise). This -// function takes orientation into consideration when determining -// the delta. -// -////////////////////////////////////////////////////////////////////// -float -Get_Angle_Delta -( - float angle1, - float angle2, - bool clockwise -) -{ - float result = angle1 - angle2; - - if (clockwise) { - if (angle1 < angle2) { - result = angle1 - (angle2 - DEG_TO_RADF (360)); - } - } else { - if (angle1 > angle2) { - result = (angle1 - DEG_TO_RADF (360)) - angle2; - } - } - - return result; -} - - -////////////////////////////////////////////////////////////////////// -// -// Find_Turn_Arc -// -////////////////////////////////////////////////////////////////////// -void -Find_Turn_Arc -( - const Matrix3D & transform, - float radius, - const Vector3 & prev_pt, - const Vector3 & curr_pt, - const Vector3 & next_pt, - Vector3 * arc_center, - bool * is_right_turn -) -{ - // - // The center of the turn arc can lie anywhere on the circle centered - // at the current point and 'radius' meters in radius. - // - // We will assume the optimal center of the turn arc will lie at - // the point halfway between the angles formed by the (prev-curr) and - // (next-curr) vectors. - // - float angle1 = ::WWMath::Atan2 ((prev_pt.Y - curr_pt.Y), prev_pt.X - curr_pt.X); - angle1 = WWMath::Wrap (angle1, 0, DEG_TO_RADF (360)); - - float angle2 = ::WWMath::Atan2 ((next_pt.Y - curr_pt.Y), next_pt.X - curr_pt.X); - angle2 = WWMath::Wrap (angle2, 0, DEG_TO_RADF (360)); - - float avg_angle = (angle1 + angle2) * 0.5F; - - // - // Find the shortest delta between the two angles (either clockwise or - // counterclockwise). - // - float delta1 = WWMath::Fabs (::Get_Angle_Delta (angle1, angle2, true)); - float delta2 = WWMath::Fabs (::Get_Angle_Delta (angle1, angle2, false)); - if (delta1 < delta2) { - avg_angle = angle1 - (delta1 * 0.5F); - } else { - avg_angle = angle1 + (delta2 * 0.5F); - } - - // - // Find the point on the circle at this angle - // - arc_center->X = curr_pt.X + (radius * ::WWMath::Cos (avg_angle)); - arc_center->Y = curr_pt.Y + (radius * ::WWMath::Sin (avg_angle)); - arc_center->Z = curr_pt.Z; - - // - // Will we be making a right turn or a left turn? - // - Vector3 rel_center; - Matrix3D::Inverse_Transform_Vector (transform, *arc_center, &rel_center); - (*is_right_turn) = (rel_center.Y > 0); - return ; -} - - -////////////////////////////////////////////////////////////////////// -// -// Find_Tangents -// -////////////////////////////////////////////////////////////////////// -void -Find_Tangents -( - float radius, - const Vector3 & prev_pt, - const Vector3 & curr_pt, - const Vector3 & next_pt, - const Vector3 & arc_center, - bool is_right_turn, - float * point_angle, - float * angle_in_delta, - float * angle_out_delta -) -{ - - // - // Find the 'in' and 'out' tangent angles - // - float angle_in = 0; - float angle_out = 0; - bool valid_in = ::Find_Tangent (arc_center, radius, prev_pt, is_right_turn, &angle_in); - bool valid_out = ::Find_Tangent (arc_center, radius, next_pt, !is_right_turn, &angle_out); - - // - // Find the angle where the current position lies on the turn arc - // - (*point_angle) = ::WWMath::Atan2 (curr_pt.X - arc_center.X, -(curr_pt.Y - arc_center.Y)); - (*point_angle) = WWMath::Wrap ((*point_angle), 0, DEG_TO_RADF (360)); - - // - // If the tangent-in is valid, find its delta from the 'point angle. - // - if (valid_in) { - (*angle_in_delta) = ::Get_Angle_Delta (angle_in, (*point_angle), is_right_turn); - } else { - (*angle_in_delta) = 0; - } - - // - // If the tangent-out is valid, find its delta from the 'point angle. - // - if (valid_out) { - (*angle_out_delta) = ::Get_Angle_Delta (angle_out, (*point_angle), !is_right_turn); - } else { - (*angle_out_delta) = 0; - } - - return ; -} - - -////////////////////////////////////////////////////////////////////// -// -// Update_Arc_List -// -////////////////////////////////////////////////////////////////////// -void -VehicleCurveClass::Update_Arc_List (void) -{ - WWMEMLOG(MEM_PATHFIND); - m_ArcList.Delete_All (); - - // - // Bail out if there is nothing to do - // - int count = Key_Count (); - if (count == 0) { - return ; - } - - // - // Add a record for the starting point of the arc... - // - ArcInfoStruct arc_start; - arc_start.point_in = Keys[0].Point; - arc_start.point_out = Keys[0].Point; - arc_start.center = Keys[0].Point; - arc_start.point_angle = 0; - arc_start.radius = 0; - arc_start.angle_in_delta = 0; - arc_start.angle_out_delta = 0; - m_ArcList.Add (arc_start); - - // - // Loop over each 'interior' point and generate arc information - // for each. - // - for (int index = 1; index < count - 1; index ++) { - - // - // Get information about the previous, next, and current points. - // - Vector3 prev_pt; - Vector3 next_pt; - Vector3 curr_pt; - float time = 0; - Get_Key (index-1, &prev_pt, &time); - Get_Key (index, &curr_pt, &time); - Get_Key (index+1, &next_pt, &time); - - // - // Determine the last known point on the path - // - Vector3 last_path_pt = m_ArcList[index-1].point_out; - - // - // Create a transformation matrix to simulate the vehicle's position and - // orientation at the last point... - // - Vector3 x_vector (curr_pt - last_path_pt); - Vector3 z_vector (0, 0, 1); - x_vector.Normalize (); -#ifdef ALLOW_TEMPORARIES - Vector3 y_vector = Vector3::Cross_Product (x_vector, z_vector); -#else - Vector3 y_vector; - Vector3::Cross_Product (x_vector, z_vector, &y_vector); -#endif - Matrix3D tm (x_vector, y_vector, z_vector, last_path_pt); - - // - // Find where the turn arc should be centered and whether we should - // make a right-turn or a left turn... - // - bool is_right_turn = false; - Vector3 arc_center (0, 0, 0); - ::Find_Turn_Arc ( tm, - m_Radius, - last_path_pt, - curr_pt, - next_pt, - &arc_center, - &is_right_turn); - - // - // Determine where the vehicle should enter and exit the turn - // - float angle_in_delta = 0; - float angle_out_delta = 0; - float point_angle = 0; - ::Find_Tangents ( m_Radius, - last_path_pt, - curr_pt, - next_pt, - arc_center, - is_right_turn, - &point_angle, - &angle_in_delta, - &angle_out_delta); - - // - // Determine at what points these angles intersect the arc - // - Vector3 point_in (0, 0, 0); - point_in.X = arc_center.X + (m_Radius * ::WWMath::Sin (point_angle + angle_in_delta)); - point_in.Y = arc_center.Y + (m_Radius * -::WWMath::Cos (point_angle + angle_in_delta)); - - Vector3 point_out (0, 0, 0); - point_out.X = arc_center.X + (m_Radius * ::WWMath::Sin (point_angle + angle_out_delta)); - point_out.Y = arc_center.Y + (m_Radius * -::WWMath::Cos (point_angle + angle_out_delta)); - - // - // Sanity check to ensure the vehicle doesn't try to go the long way around the - // turn arc... - // - if ( angle_in_delta > DEG_TO_RADF (200) || angle_out_delta > DEG_TO_RADF (200) || - angle_in_delta < -DEG_TO_RADF (200) || angle_out_delta < -DEG_TO_RADF (200) ) - { - // - // Record information about this arc - // - ArcInfoStruct arc_info; - arc_info.center = curr_pt; - arc_info.point_angle = 0; - arc_info.point_in = curr_pt; - arc_info.point_out = curr_pt; - arc_info.radius = 0; - arc_info.angle_in_delta = 0; - arc_info.angle_out_delta = 0; - m_ArcList.Add (arc_info); - - } else { - - // - // Record information about this arc - // - ArcInfoStruct arc_info; - arc_info.center = arc_center; - arc_info.point_angle = point_angle; - arc_info.point_in = point_in; - arc_info.point_out = point_out; - arc_info.radius = m_Radius; - arc_info.angle_in_delta = angle_in_delta; - arc_info.angle_out_delta = angle_out_delta; - m_ArcList.Add (arc_info); - } - } - - // - // Add a record for the starting point of the arc... - // - if (count > 1) { - ArcInfoStruct arc_end; - arc_end.point_in = Keys[count-1].Point; - arc_end.point_out = Keys[count-1].Point; - arc_end.center = Keys[count-1].Point; - arc_end.point_angle = 0; - arc_end.radius = 0; - arc_end.angle_in_delta = 0; - arc_end.angle_out_delta = 0; - m_ArcList.Add (arc_end); - } - - m_IsDirty = false; - return ; -} - - -////////////////////////////////////////////////////////////////////// -// -// Evaluate -// -////////////////////////////////////////////////////////////////////// -void -VehicleCurveClass::Evaluate (float time, Vector3 *set_val) -{ - int count = Keys.Count (); - m_Sharpness = 0; - - if (time < Keys[0].Time) { - *set_val = Keys[0].Point; - m_LastTime = Keys[0].Time; - return; - } - - if (time >= Keys[count - 1].Time) { - *set_val = Keys[count - 1].Point; - m_LastTime = Keys[count - 1].Time; - return; - } - - // - // Update the arc information if any of the keys have changed... - // - if (m_IsDirty) { - Update_Arc_List (); - } - - // - // Determine which segment we are on - // - int index0 = 0; - int index1 = 0; - float seg_time = 0; - Find_Interval (time, &index0, &index1, &seg_time); - - ArcInfoStruct &arc_info0 = m_ArcList[index0]; - ArcInfoStruct &arc_info1 = m_ArcList[index1]; - - // - // Determine the lengths of each segment of this curve. - // The segments are: - // - Exit curve from prev point - // - Straight line from exit of last curve to enter of this curve - // - Enter curve for the current point - // - float arc_length0 = arc_info0.radius * WWMath::Fabs (arc_info0.angle_out_delta); - float arc_length1 = arc_info1.radius * WWMath::Fabs (arc_info1.angle_in_delta); - float other_length = ((arc_info1.point_in - arc_info0.point_out).Length ()) / 2; - float total_length = arc_length0 + arc_length1 + other_length; - - // - // Determine at what times we should switch between parts of the segment - // - float time1 = arc_length0 / total_length; - float time2 = (arc_length0 + other_length) / total_length; - - // - // Determine which part of the segment we are on - // - if (seg_time < time1) { - - // - // We are on the initial curve of the segment, so calculate where - // on the curve we are... - // - //float percent = seg_time / time1; - //float angle = arc_info0.point_angle + (arc_info0.angle_out_delta) * percent; - float angle = arc_info0.point_angle + arc_info0.angle_out_delta; - - set_val->X = arc_info0.center.X + (arc_info0.radius * ::WWMath::Sin (angle)); - set_val->Y = arc_info0.center.Y + (arc_info0.radius * -::WWMath::Cos (angle)); - - m_Sharpness = WWMath::Clamp (WWMath::Fabs (arc_info0.angle_out_delta) / DEG_TO_RADF (15), 0, 1.0F); - m_SharpnessPos.X = set_val->X; - m_SharpnessPos.Y = set_val->Y; - m_SharpnessPos.Z = Keys[index0].Point.Z + (Keys[index1].Point.Z - Keys[index0].Point.Z) * seg_time; - - m_LastTime = Keys[index0].Time + (Keys[index1].Time - Keys[index0].Time) * time1; - - } else if (seg_time < time2) { - - // - // We are on the line between the two curves, so calculate where on - // the line we are - // - float percent = (seg_time - time1) / (time2 - time1); - - if (percent == 0) { - set_val->X = arc_info0.point_out.X; - set_val->Y = arc_info0.point_out.Y; - } else { - set_val->X = arc_info1.point_in.X; - set_val->Y = arc_info1.point_in.Y; - } - - //set_val->X = arc_info0.point_out.X + (arc_info1.point_in.X - arc_info0.point_out.X) * percent; - //set_val->Y = arc_info0.point_out.Y + (arc_info1.point_in.Y - arc_info0.point_out.Y) * percent; - - m_Sharpness = WWMath::Clamp (WWMath::Fabs (arc_info1.angle_out_delta) / DEG_TO_RADF (15), 0, 1.0F); - m_SharpnessPos = arc_info1.point_in; - - m_LastTime = Keys[index0].Time + (Keys[index1].Time - Keys[index0].Time) * time2; - - } else { - - // - // We are on the ending curve of the segment, so calculate where - // on the curve we are... - // - /*float percent = 1.0F - ((seg_time - time2) / (1.0F - time2)); - float angle = arc_info1.point_angle + (arc_info1.angle_in_delta * percent); - - set_val->X = arc_info1.center.X + (arc_info1.radius * ::WWMath::Sin (angle)); - set_val->Y = arc_info1.center.Y + (arc_info1.radius * -::WWMath::Cos (angle)); */ - - float angle = arc_info1.point_angle + (arc_info1.angle_out_delta); - - set_val->X = arc_info1.center.X + (arc_info1.radius * ::WWMath::Sin (angle)); - set_val->Y = arc_info1.center.Y + (arc_info1.radius * -::WWMath::Cos (angle)); - - m_Sharpness = WWMath::Clamp (WWMath::Fabs (arc_info1.angle_out_delta) / DEG_TO_RADF (15), 0, 1.0F); - m_SharpnessPos.X = set_val->X; - m_SharpnessPos.Y = set_val->Y; - m_SharpnessPos.Z = Keys[index0].Point.Z + (Keys[index1].Point.Z - Keys[index0].Point.Z) * seg_time; - - m_LastTime = Keys[index1].Time; - } - - // - // Our Z value is just a linear interpolation - // - set_val->Z = Keys[index0].Point.Z + (Keys[index1].Point.Z - Keys[index0].Point.Z) * seg_time; - return ; -} - -const PersistFactoryClass & VehicleCurveClass::Get_Factory(void) const -{ - return _VehicleCurveFactory; -} - - -//////////////////////////////////////////////////////////////////////////////////////////// -// -// Save -// -//////////////////////////////////////////////////////////////////////////////////////////// -bool -VehicleCurveClass::Save (ChunkSaveClass &csave) -{ - csave.Begin_Chunk (CHUNKID_PARENT); - Curve3DClass::Save (csave); - csave.End_Chunk (); - - csave.Begin_Chunk (CHUNKID_VARIABLES); - - // - // Save each variable to its own microchunk - // - WRITE_MICRO_CHUNK (csave, VARID_IS_DIRTY, m_IsDirty); - WRITE_MICRO_CHUNK (csave, VARID_RADIUS, m_Radius); - - csave.End_Chunk (); - - // - // Save each arc info struct to its own chunk - // - for (int index = 0; index < m_ArcList.Count (); index ++) { - ArcInfoStruct &arc_info = m_ArcList[index]; - - csave.Begin_Chunk (CHUNKID_ARC_INFO); - csave.Write (&arc_info, sizeof (arc_info)); - csave.End_Chunk (); - } - - return true; -} - - -//////////////////////////////////////////////////////////////////////////////////////////// -// -// Load -// -//////////////////////////////////////////////////////////////////////////////////////////// -bool -VehicleCurveClass::Load (ChunkLoadClass &cload) -{ - while (cload.Open_Chunk ()) { - switch (cload.Cur_Chunk_ID ()) { - - case CHUNKID_PARENT: - Curve3DClass::Load (cload); - break; - - case CHUNKID_ARC_INFO: - { - ArcInfoStruct arc_info; - cload.Read (&arc_info, sizeof (arc_info)); - m_ArcList.Add (arc_info); - } - break; - - case CHUNKID_VARIABLES: - Load_Variables (cload); - break; - } - - cload.Close_Chunk (); - } - - return true; -} - - -/////////////////////////////////////////////////////////////////////// -// -// Load_Variables -// -/////////////////////////////////////////////////////////////////////// -void -VehicleCurveClass::Load_Variables (ChunkLoadClass &cload) -{ - // - // Loop through all the microchunks that define the variables - // - while (cload.Open_Micro_Chunk ()) { - switch (cload.Cur_Micro_Chunk_ID ()) { - - READ_MICRO_CHUNK (cload, VARID_IS_DIRTY, m_IsDirty); - READ_MICRO_CHUNK (cload, VARID_RADIUS, m_Radius); - } - - cload.Close_Micro_Chunk (); - } - - return ; -} diff --git a/Generals/Code/Libraries/Source/WWVegas/WWMath/vehiclecurve.h b/Generals/Code/Libraries/Source/WWVegas/WWMath/vehiclecurve.h deleted file mode 100644 index b17adc390e4..00000000000 --- a/Generals/Code/Libraries/Source/WWVegas/WWMath/vehiclecurve.h +++ /dev/null @@ -1,210 +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 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 : LevelEdit * - * * - * $Archive:: /VSS_Sync/wwmath/vehiclecurve.h $* - * * - * Author:: Patrick Smith * - * * - * $Modtime:: 6/13/01 2:18p $* - * * - * $Revision:: 6 $* - * * - *---------------------------------------------------------------------------------------------* - * Functions: * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - - -#if defined(_MSC_VER) -#pragma once -#endif - -#ifndef __VEHICLE_CURVE_H -#define __VEHICLE_CURVE_H - -#include "curve.h" -#include "Vector.H" - - -//////////////////////////////////////////////////////////////////////////////////////////// -// -// VehicleCurveClass -// -// A vehicle curve represents the path a vehicle would take through a series of points. -// Each point on the curve passes through a turn-arc of the vehicle. The size of this -// arc is determined by the turn radius which is used to initialize the curve. -// -//////////////////////////////////////////////////////////////////////////////////////////// -class VehicleCurveClass : public Curve3DClass -{ -public: - - /////////////////////////////////////////////////////////////////////////// - // Public constructors/destructors - /////////////////////////////////////////////////////////////////////////// - VehicleCurveClass (void) - : m_IsDirty (true), - m_Radius (0), - m_LastTime (0), - m_Sharpness (0), - m_SharpnessPos (0, 0, 0), - Curve3DClass () { } - - VehicleCurveClass (float radius) - : m_IsDirty (true), - m_Radius (radius), - m_LastTime (0), - m_Sharpness (0), - m_SharpnessPos (0, 0, 0), - Curve3DClass () { } - - virtual ~VehicleCurveClass () {} - - - /////////////////////////////////////////////////////////////////////////// - // Public methods - /////////////////////////////////////////////////////////////////////////// - - // - // Initialization - // - void Initialize_Arc (float radius); - - // - // From Curve3DClass - // - void Evaluate (float time, Vector3 *set_val); - void Set_Key (int i,const Vector3 & point); - int Add_Key (const Vector3 & point,float t); - void Remove_Key (int i); - void Clear_Keys (void); - - // - // Vehicle curve specific - // - float Get_Current_Sharpness (Vector3 *position) const { *position = m_SharpnessPos; return m_Sharpness; } - float Get_Last_Eval_Time (void) const { return m_LastTime; } - - // - // Save-load support - // - virtual const PersistFactoryClass & Get_Factory(void) const; - virtual bool Save(ChunkSaveClass &csave); - virtual bool Load(ChunkLoadClass &cload); - -protected: - - /////////////////////////////////////////////////////////////////////////// - // Protected methods - /////////////////////////////////////////////////////////////////////////// - void Update_Arc_List (void); - void Load_Variables (ChunkLoadClass &cload); - - - /////////////////////////////////////////////////////////////////////////// - // Protected data types - /////////////////////////////////////////////////////////////////////////// - typedef struct _ArcInfoStruct - { - Vector3 center; - Vector3 point_in; - Vector3 point_out; - float point_angle; - float radius; - float angle_in_delta; - float angle_out_delta; - - _ArcInfoStruct (void) - : center (0, 0, 0), - point_in (0, 0, 0), - point_out (0, 0, 0), - point_angle (0), - radius (0), - angle_in_delta (0), - angle_out_delta (0) { } - - bool operator== (const _ArcInfoStruct &src) { return false; } - bool operator!= (const _ArcInfoStruct &src) { return true; } - - } ArcInfoStruct; - - typedef DynamicVectorClass ARC_LIST; - - /////////////////////////////////////////////////////////////////////////// - // Protected member data - /////////////////////////////////////////////////////////////////////////// - bool m_IsDirty; - float m_Radius; - ARC_LIST m_ArcList; - - float m_LastTime; - float m_Sharpness; - Vector3 m_SharpnessPos; -}; - -/////////////////////////////////////////////////////////////////////////// -// Set_Key -/////////////////////////////////////////////////////////////////////////// -inline void -VehicleCurveClass::Set_Key (int i,const Vector3 & point) -{ - m_IsDirty = true; - Curve3DClass::Set_Key (i, point); - return ; -} - -/////////////////////////////////////////////////////////////////////////// -// Add_Key -/////////////////////////////////////////////////////////////////////////// -inline int -VehicleCurveClass::Add_Key (const Vector3 & point,float t) -{ - m_IsDirty = true; - return Curve3DClass::Add_Key (point, t); -} - -/////////////////////////////////////////////////////////////////////////// -// Remove_Key -/////////////////////////////////////////////////////////////////////////// -inline void -VehicleCurveClass::Remove_Key (int i) -{ - m_IsDirty = true; - Curve3DClass::Remove_Key (i); - return ; -} - -/////////////////////////////////////////////////////////////////////////// -// Clear_Keys -/////////////////////////////////////////////////////////////////////////// -inline void -VehicleCurveClass::Clear_Keys (void) -{ - m_IsDirty = true; - Curve3DClass::Clear_Keys (); - return ; -} - - -#endif //__VEHICLE_CURVE_H - diff --git a/Generals/Code/Libraries/Source/WWVegas/WWMath/vp.cpp b/Generals/Code/Libraries/Source/WWVegas/WWMath/vp.cpp deleted file mode 100644 index 2bfc1e141c5..00000000000 --- a/Generals/Code/Libraries/Source/WWVegas/WWMath/vp.cpp +++ /dev/null @@ -1,539 +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 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 : wwmath * - * * - * $Archive:: /Commando/Code/WWMath/vp.cpp $* - * * - * Org Author:: Hector Yee * - * * - * Author : Kenny Mitchell * - * * - * $Modtime:: 06/26/02 4:04p $* - * * - * $Revision:: 12 $* - * * - * 06/26/02 KM Matrix name change to avoid MAX conflicts * - *---------------------------------------------------------------------------------------------*/ - -#include "vp.h" -#include "vector2.h" -#include "vector3.h" -#include "vector4.h" -#include "matrix3d.h" -#include "matrix4.h" -#include "wwdebug.h" -#include "cpudetect.h" -#include - -#define SHUFFLE(x, y, z, w) (((x)&3)<< 6|((y)&3)<<4|((z)&3)<< 2|((w)&3)) -#define BROADCAST(XMM, INDEX) __asm shufps XMM,XMM,(((INDEX)&3)<< 6|((INDEX)&3)<<4|((INDEX)&3)<< 2|((INDEX)&3)) - -#define TRANSPOSE(BX, BY, BZ, BW, TV) \ - __asm movaps TV,BZ \ - __asm unpcklps BZ,BW \ - __asm unpckhps TV,BW \ - __asm movaps BW,BX \ - __asm unpcklps BX,BY \ - __asm unpckhps BW,BY \ - __asm movaps BY,BX \ - __asm shufps BX,BZ,SHUFFLE(1, 0, 1, 0) \ - __asm shufps BY,BZ,SHUFFLE(3, 2, 3, 2) \ - __asm movaps BZ,BW \ - __asm shufps BZ,TV,SHUFFLE(1, 0, 1, 0) \ - __asm shufps BW,TV,SHUFFLE(3, 2, 3, 2) - - -void VectorProcessorClass::Prefetch(void* address) -{ -#if defined (__ICL) // Detect Intel compiler - if (CPUDetectClass::_Has_SSE_Instruction_Set()) { - __asm { -// mov edx,address -// mov eax,[edx] -// prefetchT1 address - } - } -#endif -} - -static Vector4 lastrow(0.0f,0.0f,0.0f,1.0f); -void VectorProcessorClass::Transform (Vector3* dst,const Vector3 *src, const Matrix3D& mtx, const int count) -{ - if (count<=0) return; - -#if defined (__ICL) // Detect Intel compiler - if (CPUDetectClass::_Has_SSE_Instruction_Set()) { - - __asm { - mov edx,dst - mov eax,src - mov ebx,mtx - mov edi,count - - movups xmm4,[ebx+0] - movups xmm5,[ebx+16] - movups xmm6,[ebx+32] - movups xmm7,lastrow //[ebx+48] - - TRANSPOSE(xmm4, xmm5, xmm6, xmm7, xmm0); - - shufps xmm4,xmm4,SHUFFLE(2,1,0,0) - shufps xmm5,xmm5,SHUFFLE(2,1,0,0) - shufps xmm6,xmm6,SHUFFLE(2,1,0,0) - shufps xmm7,xmm7,SHUFFLE(2,1,0,0) - - mov esi,edx - _lp: - test edi,edi - jz _ulos - test esi,0xf - jz _aligned - movss xmm0,[eax] - movss xmm1,[eax+4] - movss xmm2,[eax+8] - BROADCAST(xmm0,0) - BROADCAST(xmm1,0) - BROADCAST(xmm2,0) - mulps xmm0,xmm4 - mulps xmm1,xmm5 - mulps xmm2,xmm6 - addps xmm0,xmm1 - addps xmm0,xmm2 - addps xmm0,xmm7 - movss [edx],xmm0 - movhps [edx+4],xmm0 - add eax,12 - add edx,12 - add esi,12 - dec edi - jmp _lp - _aligned: - - mov esi,1 - - mov ecx,edi - and edi,3 - and ecx,~3 - jz _lp - - lea ecx,[ecx+ecx*2] - shl ecx,2 - add eax,ecx - add edx,ecx - neg ecx - - cmp dword ptr [ebx+12],0 - jne _xlatelp - cmp dword ptr [ebx+28],0 - jne _xlatelp - cmp dword ptr [ebx+44],0 - jne _xlatelp - jmp _noxlatelp - - align 16 - - _noxlatelp: - prefetchnta [eax+ecx+48] - prefetchnta [eax+ecx+48+32] - - movss xmm0,[eax+ecx] - BROADCAST(xmm0,0) - movss xmm1,[eax+ecx+4] - BROADCAST(xmm1,0) - movss xmm2,[eax+ecx+8] - BROADCAST(xmm2,0) - mulps xmm0,xmm4 - mulps xmm1,xmm5 - mulps xmm2,xmm6 - addps xmm0,xmm1 - addps xmm0,xmm2 - - movss xmm1,[eax+ecx+12] - BROADCAST(xmm1,0) - movss xmm2,[eax+ecx+16] - BROADCAST(xmm2,0) - movss xmm3,[eax+ecx+20] - BROADCAST(xmm3,0) - mulps xmm1,xmm4 - mulps xmm2,xmm5 - mulps xmm3,xmm6 - addps xmm1,xmm2 - addps xmm3,xmm1 - - movss xmm0,xmm3 - shufps xmm0,xmm0,SHUFFLE(0,3,2,1) - - movaps [edx+ecx],xmm0 - - prefetcht0 [edx+ecx+48] - prefetcht0 [edx+ecx+48+32] - - movss xmm0,[eax+ecx+24] - BROADCAST(xmm0,0) - movss xmm1,[eax+ecx+24+4] - BROADCAST(xmm1,0) - movss xmm2,[eax+ecx+24+8] - BROADCAST(xmm2,0) - mulps xmm0,xmm4 - mulps xmm1,xmm5 - mulps xmm2,xmm6 - addps xmm0,xmm1 - addps xmm0,xmm2 - - shufps xmm3,xmm0,SHUFFLE(2,1,3,2) - movaps [edx+ecx+16],xmm3 - - movss xmm1,[eax+ecx+24+12] - BROADCAST(xmm1,0) - movss xmm2,[eax+ecx+24+16] - BROADCAST(xmm2,0) - movss xmm3,[eax+ecx+24+20] - BROADCAST(xmm3,0) - mulps xmm1,xmm4 - mulps xmm2,xmm5 - mulps xmm3,xmm6 - addps xmm1,xmm2 - addps xmm1,xmm3 - - shufps xmm0,xmm0,SHUFFLE(2,1,0,3) - movss xmm1,xmm0 - movaps [edx+ecx+32],xmm1 - - add ecx,48 - js _noxlatelp - - jmp _lp - - align 16 - - _xlatelp: - prefetchnta [eax+ecx+48] - prefetchnta [eax+ecx+48+32] - - movss xmm0,[eax+ecx] - BROADCAST(xmm0,0) - movss xmm1,[eax+ecx+4] - BROADCAST(xmm1,0) - movss xmm2,[eax+ecx+8] - BROADCAST(xmm2,0) - mulps xmm0,xmm4 - mulps xmm1,xmm5 - mulps xmm2,xmm6 - addps xmm0,xmm1 - addps xmm0,xmm2 - addps xmm0,xmm7 - - movss xmm1,[eax+ecx+12] - BROADCAST(xmm1,0) - movss xmm2,[eax+ecx+16] - BROADCAST(xmm2,0) - movss xmm3,[eax+ecx+20] - BROADCAST(xmm3,0) - mulps xmm1,xmm4 - mulps xmm2,xmm5 - mulps xmm3,xmm6 - addps xmm1,xmm2 - addps xmm3,xmm1 - addps xmm3,xmm7 - - movss xmm0,xmm3 - shufps xmm0,xmm0,SHUFFLE(0,3,2,1) - movaps [edx+ecx],xmm0 - - prefetcht0 [edx+ecx+48] - prefetcht0 [edx+ecx+48+32] - - movss xmm0,[eax+ecx+24] - BROADCAST(xmm0,0) - movss xmm1,[eax+ecx+24+4] - BROADCAST(xmm1,0) - movss xmm2,[eax+ecx+24+8] - BROADCAST(xmm2,0) - mulps xmm0,xmm4 - mulps xmm1,xmm5 - mulps xmm2,xmm6 - addps xmm0,xmm1 - addps xmm0,xmm2 - addps xmm0,xmm7 - - shufps xmm3,xmm0,SHUFFLE(2,1,3,2) - movaps [edx+ecx+16],xmm3 - - movss xmm1,[eax+ecx+24+12] - BROADCAST(xmm1,0) - movss xmm2,[eax+ecx+24+16] - BROADCAST(xmm2,0) - movss xmm3,[eax+ecx+24+20] - BROADCAST(xmm3,0) - mulps xmm1,xmm4 - mulps xmm2,xmm5 - mulps xmm3,xmm6 - addps xmm1,xmm2 - addps xmm1,xmm3 - addps xmm1,xmm7 - - shufps xmm0,xmm0,SHUFFLE(2,1,0,3) - movss xmm1,xmm0 - - movaps [edx+ecx+32],xmm1 - - add ecx,48 - js _xlatelp - - jmp _lp - _ulos: - } - - } - else -#endif - { - mtx.mulVector3Array(src, dst, count); - } -} - -void VectorProcessorClass::Transform(Vector4* dst,const Vector3 *src, const Matrix4x4& matrix, const int count) -{ - if (count<=0) return; - - int i; - - for (i=0; imax)?max:src[i].X; - - dst[i].Y=(src[i].Ymax)?max:src[i].Y; - - dst[i].Z=(src[i].Zmax)?max:src[i].Z; - - dst[i].W=(src[i].Wmax)?max:src[i].W; - } -} - -void VectorProcessorClass::Clear(Vector3*dst, const int count) -{ - if (count<=0) return; - memset(dst,0,sizeof(Vector3)*count); -} - - -void VectorProcessorClass::Normalize(Vector3 *dst, const int count) -{ - if (count<=0) return; - int i; - - for (i=0; imin?src[i]:min); -} - -void VectorProcessorClass::Power(float *dst, float *src, const float pow, const int count) -{ - for (int i=0; i. -*/ - -/*********************************************************************************************** - *** 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 : wwmath * - * * - * $Archive:: /Commando/Code/WWMath/vp.h $* - * * - * Org Author:: Hector Yee * - * * - * Author : Kenny Mitchell * - * * - * $Modtime:: 06/26/02 4:04p $* - * * - * $Revision:: 13 $* - * * - * 06/26/02 KM Matrix name change to avoid MAX conflicts * - *---------------------------------------------------------------------------------------------* - * Functions: * - * Transform - transforms a vector array given Matrix3D * - * Copy - Copies data from source to destination * - * CopyIndexed-copies dst[]=src[index[]] * - * Clear - clears array to zero * - * Normalize - normalize the array * - * MinMax - Finds the min and max of the array * - * * - *----------------------------------------------------------------------------------------------* - */ - -#if defined(_MSC_VER) -#pragma once -#endif - -#ifndef VECTORPROCESSOR_H -#define VECTORPROCESSOR_H - -class Vector2; -class Vector3; -class Vector4; -class Matrix3D; -class Matrix4x4; - -class VectorProcessorClass -{ -public: - static void Transform(Vector3* dst,const Vector3 *src, const Matrix3D& matrix, const int count); - static void Transform(Vector4* dst,const Vector3 *src, const Matrix4x4& matrix, const int count); - static void Copy(unsigned *dst,const unsigned *src, const int count); - static void Copy(Vector2 *dst,const Vector2 *src, const int count); - static void Copy(Vector3 *dst,const Vector3 *src, const int count); - static void Copy(Vector4 *dst,const Vector4 *src, const int count); - static void Copy(Vector4 *dst,const Vector3 *src, const float * srca, const int count); - static void Copy(Vector4 *dst,const Vector3 *src, const float srca, const int count); - static void Copy(Vector4 *dst,const Vector3 &src, const float * srca, const int count); - static void CopyIndexed(unsigned *dst,const unsigned *src, const unsigned int *index, const int count); - static void CopyIndexed(Vector2 *dst,const Vector2 *src, const unsigned int *index, const int count); - static void CopyIndexed(Vector3 *dst,const Vector3 *src, const unsigned int *index, const int count); - static void CopyIndexed(Vector4 *dst,const Vector4 *src, const unsigned int *index, const int count); - static void CopyIndexed(unsigned char* dst, const unsigned char* src, const unsigned int *index, int count); - static void CopyIndexed(float* dst, float* src, const unsigned int *index, int count); - static void Clamp(Vector4 *dst,const Vector4 *src, const float min, const float max, const int count); - static void Clear (Vector3 *dst, const int count); - static void Normalize(Vector3 *dst, const int count); - static void MinMax(Vector3 *src, Vector3 &min, Vector3 &max, const int count); - - static void MulAdd(float * dest,float multiplier,float add,int count); - - static void Prefetch(void* address); - - static void DotProduct(float *dst, const Vector3 &a, const Vector3 *b,const int count); - static void ClampMin(float *dst, float *src, const float min, const int count); - static void Power(float *dst, float *src, const float pow, const int count); -}; - -#endif // VECTORPROCESSOR_H diff --git a/Generals/Code/Libraries/Source/WWVegas/WWMath/wwmath.cpp b/Generals/Code/Libraries/Source/WWVegas/WWMath/wwmath.cpp deleted file mode 100644 index e7e5c4fba06..00000000000 --- a/Generals/Code/Libraries/Source/WWVegas/WWMath/wwmath.cpp +++ /dev/null @@ -1,96 +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 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 : WWMath * - * * - * $Archive:: /Commando/Code/wwmath/wwmath.cpp $* - * * - * Author:: Eric_c * - * * - * $Modtime:: 5/10/01 10:52p $* - * * - * $Revision:: 11 $* - * * - *---------------------------------------------------------------------------------------------* - * Functions: * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - - -#include "wwmath.h" -#include "wwhack.h" -#include "lookuptable.h" -#include -#include "wwdebug.h" -#include "wwprofile.h" - -// TODO: convert to use loouptablemanager... -float _FastAcosTable[ARC_TABLE_SIZE]; -float _FastAsinTable[ARC_TABLE_SIZE]; -float _FastSinTable[SIN_TABLE_SIZE]; -float _FastInvSinTable[SIN_TABLE_SIZE]; - -void WWMath::Init(void) -{ - LookupTableMgrClass::Init(); - - int a=0; - for (;a0) { - _FastInvSinTable[a]=1.0f/_FastSinTable[a]; - } else { - _FastInvSinTable[a]=WWMATH_FLOAT_MAX; - } - } -} - -void WWMath::Shutdown(void) -{ - LookupTableMgrClass::Shutdown(); -} - -float WWMath::Random_Float(void) -{ - return ((float)(rand() & 0xFFF)) / (float)(0xFFF); -} - - -/* -** Force link some modules from this library. -*/ -void Do_Force_Links(void) -{ - FORCE_LINK(curve); - FORCE_LINK(hermitespline); - FORCE_LINK(catmullromspline); - FORCE_LINK(cardinalspline); - FORCE_LINK(tcbspline); -} - diff --git a/Generals/Code/Libraries/Source/WWVegas/WWMath/wwmath.h b/Generals/Code/Libraries/Source/WWVegas/WWMath/wwmath.h deleted file mode 100644 index 0a151a65dc3..00000000000 --- a/Generals/Code/Libraries/Source/WWVegas/WWMath/wwmath.h +++ /dev/null @@ -1,658 +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 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 : WWMath * - * * - * $Archive:: /Commando/Code/wwmath/wwmath.h $* - * * - * Author:: Greg Hjelstrom * - * * - * $Modtime:: 8/26/01 2:22p $* - * * - * $Revision:: 64 $* - * * - *---------------------------------------------------------------------------------------------* - * Functions: * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - - -#if defined(_MSC_VER) -#pragma once -#endif - -#ifndef WWMATH_H -#define WWMATH_H - -#include "always.h" -#include -#include -#include -#include - -/* -** Some global constants. -*/ -#define WWMATH_EPSILON 0.0001f -#define WWMATH_EPSILON2 WWMATH_EPSILON * WWMATH_EPSILON -#define WWMATH_PI 3.141592654f -#define WWMATH_FLOAT_MAX (FLT_MAX) -#define WWMATH_FLOAT_MIN (FLT_MIN) -#define WWMATH_SQRT2 1.414213562f -#define WWMATH_SQRT3 1.732050808f -#define WWMATH_OOSQRT2 0.707106781f -#define WWMATH_OOSQRT3 0.577350269f - -// (DRM 05/07/01) Temporarily eliminated _fastcall -// on non-Microsoft compatible compilers. Jani -// should be replacing this soon. -#ifndef _MSC_VER -#define __fastcall -#endif // _MSC_VER - -/* -** Macros to convert between degrees and radians -*/ -#ifndef RAD_TO_DEG -#define RAD_TO_DEG(x) (((double)x)*180.0/WWMATH_PI) -#endif - -#ifndef DEG_TO_RAD -#define DEG_TO_RAD(x) (((double)x)*WWMATH_PI/180.0) -#endif - -#ifndef RAD_TO_DEGF -#define RAD_TO_DEGF(x) (((float)x)*180.0f/WWMATH_PI) -#endif - -#ifndef DEG_TO_RADF -#define DEG_TO_RADF(x) (((float)x)*WWMATH_PI/180.0f) -#endif - - -const int ARC_TABLE_SIZE=1024; -const int SIN_TABLE_SIZE=1024; -extern float _FastAcosTable[ARC_TABLE_SIZE]; -extern float _FastAsinTable[ARC_TABLE_SIZE]; -extern float _FastSinTable[SIN_TABLE_SIZE]; -extern float _FastInvSinTable[SIN_TABLE_SIZE]; - -/* -** Some simple math functions which work on the built-in types. -** Include the various other header files in the WWMATH library -** in order to get matrices, quaternions, etc. -*/ -class WWMath -{ -public: - -// Initialization and Shutdown. Other math sub-systems which require initialization and -// shutdown processing will be handled in these functions -static void Init(void); -static void Shutdown(void); - -// These are meant to be a collection of small math utility functions to be optimized at some point. -static WWINLINE float Fabs(float val) -{ - int value=*(int*)&val; - value&=0x7fffffff; - return *(float*)&value; -} - -static WWINLINE int Float_To_Int_Chop(const float& f); -static WWINLINE int Float_To_Int_Floor(const float& f); - -#if defined(_MSC_VER) && defined(_M_IX86) -static WWINLINE float Cos(float val); -static WWINLINE float Sin(float val); -static WWINLINE float Sqrt(float val); -static float __fastcall Inv_Sqrt(float a); // Some 30% faster inverse square root than regular C++ compiled, from Intel's math library -static WWINLINE long Float_To_Long(float f); -#else -static float Cos(float val); -static float Sin(float val); -static float Sqrt(float val); -static float Inv_Sqrt(float a); -static long Float_To_Long(float f); -#endif - - -static WWINLINE float Fast_Sin(float val); -static WWINLINE float Fast_Inv_Sin(float val); -static WWINLINE float Fast_Cos(float val); -static WWINLINE float Fast_Inv_Cos(float val); - -static WWINLINE float Fast_Acos(float val); -static WWINLINE float Acos(float val); -static WWINLINE float Fast_Asin(float val); -static WWINLINE float Asin(float val); - - -static float Atan(float x) { return static_cast(atan(x)); } -static float Atan2(float y,float x) { return static_cast(atan2(y,x)); } -static float Sign(float val); -static float Ceil(float val) { return ceilf(val); } -static float Floor(float val) { return floorf(val); } -static bool Fast_Is_Float_Positive(const float & val); -static bool Is_Power_Of_2(const unsigned int val); - -static float Random_Float(void); -static float Random_Float(float min,float max); -static float Clamp(float val, float min = 0.0f, float max = 1.0f); -static double Clamp(double val, double min = 0.0f, double max = 1.0f); -static int Clamp_Int(int val, int min_val, int max_val); -static float Wrap(float val, float min = 0.0f, float max = 1.0f); -static double Wrap(double val, double min = 0.0f, double max = 1.0f); -static float Min(float a, float b); -static float Max(float a, float b); - -static int Float_As_Int(const float f) { return *((int*)&f); } - -static float Lerp(float a, float b, float lerp ); -static double Lerp(double a, double b, float lerp ); - -static long Float_To_Long(double f); - -static unsigned char Unit_Float_To_Byte(float f) { return (unsigned char)(f*255.0f); } -static float Byte_To_Unit_Float(unsigned char byte) { return ((float)byte) / 255.0f; } - -static bool Is_Valid_Float(float x); -static bool Is_Valid_Double(double x); - -}; - -WWINLINE float WWMath::Sign(float val) -{ - if (val > 0.0f) { - return +1.0f; - } - if (val < 0.0f) { - return -1.0f; - } - return 0.0f; -} - -WWINLINE bool WWMath::Fast_Is_Float_Positive(const float & val) -{ - return !((*(int *)(&val)) & 0x80000000); -} - -WWINLINE bool WWMath::Is_Power_Of_2(const unsigned int val) -{ - return !((val)&val-1); -} - -WWINLINE float WWMath::Random_Float(float min,float max) -{ - return Random_Float() * (max-min) + min; -} - -WWINLINE float WWMath::Clamp(float val, float min /*= 0.0f*/, float max /*= 1.0f*/) -{ - if(val < min) return min; - if(val > max) return max; - return val; -} - -WWINLINE double WWMath::Clamp(double val, double min /*= 0.0f*/, double max /*= 1.0f*/) -{ - if(val < min) return min; - if(val > max) return max; - return val; -} - -WWINLINE int WWMath::Clamp_Int(int val, int min_val, int max_val) -{ - if(val < min_val) return min_val; - if(val > max_val) return max_val; - return val; -} - -WWINLINE float WWMath::Wrap(float val, float min /*= 0.0f*/, float max /*= 1.0f*/) -{ - // Implemented as an if rather than a while, to long loops - if ( val >= max ) val -= (max-min); - if ( val < min ) val += (max-min); - - if ( val < min ) { - val = min; - } - if ( val > max ) { - val = max; - } - return val; -} - -WWINLINE double WWMath::Wrap(double val, double min /*= 0.0f*/, double max /*= 1.0f*/) -{ - // Implemented as an if rather than a while, to long loops - if ( val >= max ) val -= (max-min); - if ( val < min ) val += (max-min); - if ( val < min ) { - val = min; - } - if ( val > max ) { - val = max; - } - return val; -} - -WWINLINE float WWMath::Min(float a, float b) -{ - if (ab) return a; - return b; -} - -WWINLINE float WWMath::Lerp(float a, float b, float lerp ) -{ - return (a + (b - a)*lerp); -} - -WWINLINE double WWMath::Lerp(double a, double b, float lerp ) -{ - return (a + (b - a)*lerp); -} - - -WWINLINE bool WWMath::Is_Valid_Float(float x) -{ - unsigned long * plong = (unsigned long *)(&x); - unsigned long exponent = ((*plong) & 0x7F800000) >> (32-9); - - // if exponent is 0xFF, this is a NAN - if (exponent == 0xFF) { - return false; - } - return true; -} - -WWINLINE bool WWMath::Is_Valid_Double(double x) -{ - unsigned long * plong = (unsigned long *)(&x) + 1; - unsigned long exponent = ((*plong) & 0x7FF00000) >> (32-12); - - // if exponent is 0x7FF, this is a NAN - if (exponent == 0x7FF) { - return false; - } - return true; -} - -// ---------------------------------------------------------------------------- -// Float to long -// ---------------------------------------------------------------------------- - -#if defined(_MSC_VER) && defined(_M_IX86) -WWINLINE long WWMath::Float_To_Long(float f) -{ - long i; - - __asm { - fld [f] - fistp [i] - } - - return i; -} -#else -WWINLINE long WWMath::Float_To_Long(float f) -{ - return (long) f; -} -#endif - -WWINLINE long WWMath::Float_To_Long(double f) -{ -#if defined(_MSC_VER) && defined(_M_IX86) - long retval; - __asm fld qword ptr [f] - __asm fistp dword ptr [retval] - return retval; -#else - return (long) f; -#endif -} - -// ---------------------------------------------------------------------------- -// Cos -// ---------------------------------------------------------------------------- - -#if defined(_MSC_VER) && defined(_M_IX86) -WWINLINE float WWMath::Cos(float val) -{ - float retval; - __asm { - fld [val] - fcos - fstp [retval] - } - return retval; -} -#else -WWINLINE float WWMath::Cos(float val) -{ - return cosf(val); -} -#endif - -// ---------------------------------------------------------------------------- -// Sin -// ---------------------------------------------------------------------------- - -#if defined(_MSC_VER) && defined(_M_IX86) -WWINLINE float WWMath::Sin(float val) -{ - float retval; - __asm { - fld [val] - fsin - fstp [retval] - } - return retval; -} -#else -WWINLINE float WWMath::Sin(float val) -{ - return sinf(val); -} -#endif - -// ---------------------------------------------------------------------------- -// Fast, table based sin -// ---------------------------------------------------------------------------- - -WWINLINE float WWMath::Fast_Sin(float val) -{ - val*=float(SIN_TABLE_SIZE) / (2.0f * WWMATH_PI); - - int idx0=Float_To_Int_Floor(val); - int idx1=idx0+1; - float frac=val-(float)idx0; - - idx0 = ((unsigned)idx0) & (SIN_TABLE_SIZE-1); - idx1 = ((unsigned)idx1) & (SIN_TABLE_SIZE-1); - - return (1.0f - frac) * _FastSinTable[idx0] + frac * _FastSinTable[idx1]; -} - -// ---------------------------------------------------------------------------- -// Fast, table based 1.0f/sin -// ---------------------------------------------------------------------------- - -WWINLINE float WWMath::Fast_Inv_Sin(float val) -{ -#if 0 // TODO: more testing, not reliable! - float index = val * float(SIN_TABLE_SIZE) / (2.0f * WWMATH_PI); - - int idx0=Float_To_Int_Floor(index); - int idx1=idx0+1; - float frac=val-(float)idx0; - - idx0 = ((unsigned)idx0) & (SIN_TABLE_SIZE-1); - idx1 = ((unsigned)idx1) & (SIN_TABLE_SIZE-1); - - // The table becomes inaccurate near 0 and 2pi so fall back to doing a divide. - const int BUFFER = 16; - if ((idx0 <= BUFFER) || (idx0 >= SIN_TABLE_SIZE-BUFFER-1)) { - return 1.0f / WWMath::Fast_Sin(val); - } else { - return (1.0f - frac) * _FastInvSinTable[idx0] + frac * _FastInvSinTable[idx1]; - } -#else - return 1.0f / WWMath::Fast_Sin(val); -#endif -} - - -// ---------------------------------------------------------------------------- -// Fast, table based cos -// ---------------------------------------------------------------------------- - -WWINLINE float WWMath::Fast_Cos(float val) -{ - val+=(WWMATH_PI * 0.5f); - val*=float(SIN_TABLE_SIZE) / (2.0f * WWMATH_PI); - - int idx0=Float_To_Int_Floor(val); - int idx1=idx0+1; - float frac=val-(float)idx0; - - idx0 = ((unsigned)idx0) & (SIN_TABLE_SIZE-1); - idx1 = ((unsigned)idx1) & (SIN_TABLE_SIZE-1); - - return (1.0f - frac) * _FastSinTable[idx0] + frac * _FastSinTable[idx1]; -} - -// ---------------------------------------------------------------------------- -// Fast, table based 1.0f/cos -// ---------------------------------------------------------------------------- - -WWINLINE float WWMath::Fast_Inv_Cos(float val) -{ -#if 0 // TODO: more testing, not reliable! - float index = val + (WWMATH_PI * 0.5f); - index *= float(SIN_TABLE_SIZE) / (2.0f * WWMATH_PI); - - int idx0=Float_To_Int_Chop(index); - int idx1=idx0+1; - float frac=val-(float)idx0; - - idx0 = ((unsigned)idx0) & (SIN_TABLE_SIZE-1); - idx1 = ((unsigned)idx1) & (SIN_TABLE_SIZE-1); - - // The table becomes inaccurate near 0 and 2pi so fall back to doing a divide. - if ((idx0 <= 2) || (idx0 >= SIN_TABLE_SIZE-3)) { - return 1.0f / WWMath::Fast_Cos(val); - } else { - return (1.0f - frac) * _FastInvSinTable[idx0] + frac * _FastInvSinTable[idx1]; - } -#else - return 1.0f / WWMath::Fast_Cos(val); -#endif -} - -// ---------------------------------------------------------------------------- -// Fast, table based arc cos -// ---------------------------------------------------------------------------- - -WWINLINE float WWMath::Fast_Acos(float val) -{ - // Near -1 and +1, the table becomes too inaccurate - if (WWMath::Fabs(val) > 0.975f) { - return WWMath::Acos(val); - } - - val*=float(ARC_TABLE_SIZE/2); - - int idx0=Float_To_Int_Floor(val); - int idx1=idx0+1; - float frac=val-(float)idx0; - - idx0+=ARC_TABLE_SIZE/2; - idx1+=ARC_TABLE_SIZE/2; - - // we dont even get close to the edge of the table... - assert((idx0 >= 0) && (idx0 < ARC_TABLE_SIZE)); - assert((idx1 >= 0) && (idx1 < ARC_TABLE_SIZE)); - - // compute and return the interpolated value - return (1.0f - frac) * _FastAcosTable[idx0] + frac * _FastAcosTable[idx1]; -} - -// ---------------------------------------------------------------------------- -// Arc cos -// ---------------------------------------------------------------------------- - -WWINLINE float WWMath::Acos(float val) -{ - return (float)acos(val); -} - -// ---------------------------------------------------------------------------- -// Fast, table based arc sin -// ---------------------------------------------------------------------------- - -WWINLINE float WWMath::Fast_Asin(float val) -{ - // Near -1 and +1, the table becomes too inaccurate - if (WWMath::Fabs(val) > 0.975f) { - return WWMath::Asin(val); - } - - val*=float(ARC_TABLE_SIZE/2); - - int idx0=Float_To_Int_Floor(val); - int idx1=idx0+1; - float frac=val-(float)idx0; - - idx0+=ARC_TABLE_SIZE/2; - idx1+=ARC_TABLE_SIZE/2; - - // we dont even get close to the edge of the table... - assert((idx0 >= 0) && (idx0 < ARC_TABLE_SIZE)); - assert((idx1 >= 0) && (idx1 < ARC_TABLE_SIZE)); - - // compute and return the interpolated value - return (1.0f - frac) * _FastAsinTable[idx0] + frac * _FastAsinTable[idx1]; -} - -// ---------------------------------------------------------------------------- -// Arc sin -// ---------------------------------------------------------------------------- - -WWINLINE float WWMath::Asin(float val) -{ - return (float)asin(val); -} - -// ---------------------------------------------------------------------------- -// Sqrt -// ---------------------------------------------------------------------------- - -#if defined(_MSC_VER) && defined(_M_IX86) -WWINLINE float WWMath::Sqrt(float val) -{ - float retval; - __asm { - fld [val] - fsqrt - fstp [retval] - } - return retval; -} -#else -WWINLINE float WWMath::Sqrt(float val) -{ - return (float)sqrt(val); -} -#endif - -WWINLINE int WWMath::Float_To_Int_Chop(const float& f) -{ - int a = *reinterpret_cast(&f); // take bit pattern of float into a register - int sign = (a>>31); // sign = 0xFFFFFFFF if original value is negative, 0 if positive - int mantissa = (a&((1<<23)-1))|(1<<23); // extract mantissa and add the hidden bit - int exponent = ((a&0x7fffffff)>>23)-127; // extract the exponent - int r = ((unsigned int)(mantissa)<<8)>>(31-exponent); // ((1<>24 -- (we know that mantissa > (1<<24)) - return ((r ^ (sign)) - sign ) &~ (exponent>>31); // add original sign. If exponent was negative, make return value 0. -} - -WWINLINE int WWMath::Float_To_Int_Floor (const float& f) -{ - int a = *reinterpret_cast(&f); // take bit pattern of float into a register - int sign = (a>>31); // sign = 0xFFFFFFFF if original value is negative, 0 if positive - a&=0x7fffffff; // we don't need the sign any more - - int exponent = (a>>23)-127; // extract the exponent - int expsign = ~(exponent>>31); // 0xFFFFFFFF if exponent is positive, 0 otherwise - int imask = ( (1<<(31-(exponent))))-1; // mask for true integer values - int mantissa = (a&((1<<23)-1)); // extract mantissa (without the hidden bit) - int r = ((unsigned int)(mantissa|(1<<23))<<8)>>(31-exponent); // ((1<>24 -- (we know that mantissa > (1<<24)) - - r = ((r & expsign) ^ (sign)) + ((!((mantissa<<8)&imask)&(expsign^((a-1)>>31)))&sign); // if (fabs(value)<1.0) value = 0; copy sign; if (value < 0 && value==(int)(value)) value++; - return r; -} - -// ---------------------------------------------------------------------------- -// Inverse square root -// ---------------------------------------------------------------------------- - -#if defined(_MSC_VER) && defined(_M_IX86) -WWINLINE __declspec(naked) float __fastcall WWMath::Inv_Sqrt(float a) -{ - __asm { - mov eax, 0be6eb508h - mov DWORD PTR [esp-12],03fc00000h ; 1.5 on the stack - sub eax, DWORD PTR [esp+4]; a - sub DWORD PTR [esp+4], 800000h ; a/2 a=Y0 - shr eax, 1 ; firs approx in eax=R0 - mov DWORD PTR [esp-8], eax - - fld DWORD PTR [esp-8] ;r - fmul st, st ;r*r - fld DWORD PTR [esp-8] ;r - fxch st(1) - fmul DWORD PTR [esp+4];a ;r*r*y0 - fld DWORD PTR [esp-12];load 1.5 - fld st(0) - fsub st,st(2) ;r1 = 1.5 - y1 - ;x1 = st(3) - ;y1 = st(2) - ;1.5 = st(1) - ;r1 = st(0) - - fld st(1) - fxch st(1) - fmul st(3),st ; y2=y1*r1*... - fmul st(3),st ; y2=y1*r1*r1 - fmulp st(4),st ; x2=x1*r1 - fsub st,st(2) ; r2=1.5-y2 - ;x2=st(3) - ;y2=st(2) - ;1.5=st(1) - ;r2 = st(0) - - fmul st(2),st ;y3=y2*r2*... - fmul st(3),st ;x3=x2*r2 - fmulp st(2),st ;y3=y2*r2*r2 - fxch st(1) - fsubp st(1),st ;r3= 1.5 - y3 - ;x3 = st(1) - ;r3 = st(0) - fmulp st(1), st - ret 4 - } -} -#else -WWINLINE float WWMath::Inv_Sqrt(float val) -{ - return 1.0f / (float)sqrt(val); -} -#endif - - -#endif diff --git a/Generals/Code/Libraries/Source/WWVegas/WWMath/wwmathids.h b/Generals/Code/Libraries/Source/WWVegas/WWMath/wwmathids.h deleted file mode 100644 index 8217d09fa50..00000000000 --- a/Generals/Code/Libraries/Source/WWVegas/WWMath/wwmathids.h +++ /dev/null @@ -1,66 +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 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 : WWMath * - * * - * $Archive:: /Commando/Code/wwmath/wwmathids.h $* - * * - * Original Author:: Greg Hjelstrom * - * * - * $Author:: Jani_p $* - * * - * $Modtime:: 5/04/01 8:42p $* - * * - * $Revision:: 3 $* - * * - *---------------------------------------------------------------------------------------------* - * Functions: * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - -#ifndef WWMATHIDS_H -#define WWMATHIDS_H - -#include "saveloadids.h" - -/* -** Persist Factory ID's for WWMATH -*/ -enum -{ - WWMATH_CHUNKID_LINEARCURVE1D = CHUNKID_WWMATH_BEGIN, - WWMATH_CHUNKID_HERMITESPLINE1D, - WWMATH_CHUNKID_CATMULLROMSPLINE1D, - WWMATH_CHUNKID_CARDINALSPLINE1D, - WWMATH_CHUNKID_TCBSPLINE1D, - - WWMATH_CHUNKID_LINEARCURVE3D = CHUNKID_WWMATH_BEGIN + 0x100, - WWMATH_CHUNKID_HERMITESPLINE3D, - WWMATH_CHUNKID_CATMULLROMSPLINE3D, - WWMATH_CHUNKID_CARDINALSPLINE3D, - WWMATH_CHUNKID_TCBSPLINE3D, - WWMATH_CHUNKID_VEHICLECURVE -}; - - - -#endif //WWMATHIDS_H - diff --git a/Generals/Code/Libraries/Source/WWVegas/WWSaveLoad/definition.cpp b/Generals/Code/Libraries/Source/WWVegas/WWSaveLoad/definition.cpp deleted file mode 100644 index 09ab287fbd0..00000000000 --- a/Generals/Code/Libraries/Source/WWVegas/WWSaveLoad/definition.cpp +++ /dev/null @@ -1,163 +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 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 : WWSaveLoad * - * * - * $Archive:: /Commando/Code/wwsaveload/definition.cpp $* - * * - * Author:: Patrick Smith * - * * - * $Modtime:: 8/24/01 4:35p $* - * * - * $Revision:: 10 $* - * * - *---------------------------------------------------------------------------------------------* - * Functions: * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - -#include "definition.h" -#include "chunkio.h" - -////////////////////////////////////////////////////////////////////////////////// -// Constants -////////////////////////////////////////////////////////////////////////////////// -enum -{ - CHUNKID_VARIABLES = 0x00000100, -}; - -enum -{ - VARID_INSTANCEID = 0x01, - XXX_VARID_PARENTID, - VARID_NAME, -}; - - -///////////////////////////////////////////////////////// -// -// Save -// -///////////////////////////////////////////////////////// -bool -DefinitionClass::Save (ChunkSaveClass &csave) -{ - bool retval = true; - - csave.Begin_Chunk (CHUNKID_VARIABLES); - retval &= Save_Variables (csave); - csave.End_Chunk (); - - return retval; -} - - -///////////////////////////////////////////////////////// -// -// Load -// -///////////////////////////////////////////////////////// -bool -DefinitionClass::Load (ChunkLoadClass &cload) -{ - bool retval = true; - - while (cload.Open_Chunk ()) { - switch (cload.Cur_Chunk_ID ()) { - - case CHUNKID_VARIABLES: - Load_Variables (cload); - break; - } - - cload.Close_Chunk (); - } - - return retval; -} - - -////////////////////////////////////////////////////////////////////////////////// -// -// Save_Variables -// -////////////////////////////////////////////////////////////////////////////////// -bool -DefinitionClass::Save_Variables (ChunkSaveClass &csave) -{ - bool retval = true; - - WRITE_MICRO_CHUNK (csave, VARID_INSTANCEID, m_ID); - WRITE_MICRO_CHUNK_WWSTRING (csave, VARID_NAME, m_Name); - return retval; -} - - -////////////////////////////////////////////////////////////////////////////////// -// -// Load_Variables -// -////////////////////////////////////////////////////////////////////////////////// -bool -DefinitionClass::Load_Variables (ChunkLoadClass &cload) -{ - bool retval = true; - - // - // Loop through all the microchunks that define the variables - // - while (cload.Open_Micro_Chunk ()) { - switch (cload.Cur_Micro_Chunk_ID ()) { - - READ_MICRO_CHUNK (cload, VARID_INSTANCEID, m_ID) - READ_MICRO_CHUNK_WWSTRING (cload, VARID_NAME, m_Name) - } - - cload.Close_Micro_Chunk (); - } - - return retval; -} - - -////////////////////////////////////////////////////////////////////////////////// -// -// Set_ID -// -////////////////////////////////////////////////////////////////////////////////// -void -DefinitionClass::Set_ID (uint32 id) -{ - m_ID = id; - - // - // If we are registered with the definition manager, then we need to - // re-link ourselves back into the list - // - if (m_DefinitionMgrLink != -1) { - DefinitionMgrClass::Unregister_Definition (this); - DefinitionMgrClass::Register_Definition (this); - } - - return ; -} - diff --git a/Generals/Code/Libraries/Source/WWVegas/WWSaveLoad/definition.h b/Generals/Code/Libraries/Source/WWVegas/WWSaveLoad/definition.h deleted file mode 100644 index e73b8ae986c..00000000000 --- a/Generals/Code/Libraries/Source/WWVegas/WWSaveLoad/definition.h +++ /dev/null @@ -1,194 +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 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 : WWSaveLoad * - * * - * $Archive:: /Commando/Code/wwsaveload/definition.h $* - * * - * Author:: Patrick Smith * - * * - * $Modtime:: 8/24/01 4:57p $* - * * - * $Revision:: 20 $* - * * - *---------------------------------------------------------------------------------------------* - * Functions: * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - -#if defined(_MSC_VER) -#pragma once -#endif - -#ifndef __DEFINITION_H -#define __DEFINITION_H - -#include "always.h" -// SKB Remove because of G conflicts with CLASSID_?? -#include "definitionclassids.h" -#include "definitionmgr.h" -#include "editable.h" -#include "wwstring.h" - -// Forward declarations -class ChunkSaveClass; -class ChunkLoadClass; - - -////////////////////////////////////////////////////////////////////////////////// -// -// DefinitionClass -// -////////////////////////////////////////////////////////////////////////////////// -class DefinitionClass : public PersistClass, public EditableClass -{ -public: - - ///////////////////////////////////////////////////////////////////// - // Editable interface requirements - ///////////////////////////////////////////////////////////////////// - DECLARE_EDITABLE(DefinitionClass, EditableClass); - - ///////////////////////////////////////////////////////////////////// - // Public constructors/destructors - ///////////////////////////////////////////////////////////////////// - DefinitionClass (void); - virtual ~DefinitionClass (void); - - ///////////////////////////////////////////////////////////////////// - // Public methods - ///////////////////////////////////////////////////////////////////// - - // Type identification - virtual uint32 Get_Class_ID (void) const = 0; - virtual uint32 Get_ID (void) const; - virtual void Set_ID (uint32 id); - virtual PersistClass * Create (void) const = 0; - - // Display name methods - virtual const char * Get_Name (void) const; - virtual void Set_Name (const char *new_name); - - // Validation methods - virtual bool Is_Valid_Config (StringClass &message); - - // From PersistClass - virtual bool Save (ChunkSaveClass &csave); - virtual bool Load (ChunkLoadClass &cload); - - // User data support - uint32 Get_User_Data (void) const { return m_GenericUserData; } - void Set_User_Data (uint32 data) { m_GenericUserData = data; } - - // Save support - bool Is_Save_Enabled (void) const { return m_SaveEnabled; } - void Enable_Save (bool onoff) { m_SaveEnabled = onoff; } - -protected: - - ///////////////////////////////////////////////////////////////////// - // Protected member data - ///////////////////////////////////////////////////////////////////// - int m_DefinitionMgrLink; - -private: - - ///////////////////////////////////////////////////////////////////// - // Private methods - ///////////////////////////////////////////////////////////////////// - bool Save_Variables (ChunkSaveClass &csave); - bool Load_Variables (ChunkLoadClass &cload); - - ///////////////////////////////////////////////////////////////////// - // Private member data - ///////////////////////////////////////////////////////////////////// - StringClass m_Name; - uint32 m_ID; - uint32 m_GenericUserData; - bool m_SaveEnabled; - - ///////////////////////////////////////////////////////////////////// - // Friends - ///////////////////////////////////////////////////////////////////// - friend class DefinitionMgrClass; -}; - - -///////////////////////////////////////////////////////////////////// -// DefinitionClass -///////////////////////////////////////////////////////////////////// -inline -DefinitionClass::DefinitionClass (void) - : m_ID (0), - m_SaveEnabled (true), - m_DefinitionMgrLink (-1) -{ - return ; -} - -///////////////////////////////////////////////////////////////////// -// DefinitionClass -///////////////////////////////////////////////////////////////////// -inline -DefinitionClass::~DefinitionClass (void) -{ - return ; -} - -////////////////////////////////////////////////////////////////////////////////// -// Get_Name -////////////////////////////////////////////////////////////////////////////////// -inline const char * -DefinitionClass::Get_Name (void) const -{ - return m_Name; -} - -////////////////////////////////////////////////////////////////////////////////// -// Set_Name -////////////////////////////////////////////////////////////////////////////////// -inline void -DefinitionClass::Set_Name (const char *new_name) -{ - m_Name = new_name; - return ; -} - -////////////////////////////////////////////////////////////////////////////////// -// Get_ID -////////////////////////////////////////////////////////////////////////////////// -inline uint32 -DefinitionClass::Get_ID (void) const -{ - return m_ID; -} - -////////////////////////////////////////////////////////////////////////////////// -// Is_Valid_Config -////////////////////////////////////////////////////////////////////////////////// -inline bool -DefinitionClass::Is_Valid_Config (StringClass &message) -{ - return true; -} - - -#endif //__DEFINITION_H diff --git a/Generals/Code/Libraries/Source/WWVegas/WWSaveLoad/definitionclassids.h b/Generals/Code/Libraries/Source/WWVegas/WWSaveLoad/definitionclassids.h deleted file mode 100644 index 973f787ea95..00000000000 --- a/Generals/Code/Libraries/Source/WWVegas/WWSaveLoad/definitionclassids.h +++ /dev/null @@ -1,108 +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 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 : WWSaveLoad * - * * - * $Archive:: /Commando/Code/wwsaveload/definitionclassids.h $* - * * - * Author:: Patrick Smith * - * * - * $Modtime:: 8/03/00 5:44p $* - * * - * $Revision:: 15 $* - * * - *---------------------------------------------------------------------------------------------* - * Functions: * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - - -#if defined(_MSC_VER) -#pragma once -#endif - -#ifndef __DEFINITION_CLASS_ID_H -#define __DEFINITION_CLASS_ID_H - -#include "always.h" -#include "bittype.h" - -////////////////////////////////////////////////////////////////////////////////// -// -// Constants -// -////////////////////////////////////////////////////////////////////////////////// -const int DEF_CLASSID_START = 0x00001000; -const int DEF_CLASSID_RANGE = 0x00001000; -#define NEXT_SUPER_CLASSID(n) DEF_CLASSID_START + (n * DEF_CLASSID_RANGE) - - -////////////////////////////////////////////////////////////////////////////////// -// -// DefinitionClassID -// -// Note: The following enum should contain ALL of the class ids for -// definitions in the entire system (to guarantee they are unique). Each -// super-class is allocated a range of class ids. Use the -// SuperClassID_From_ClassID function to determine which super class -// a particular class id belongs to. -// -////////////////////////////////////////////////////////////////////////////////// -enum -{ - CLASSID_TERRAIN = NEXT_SUPER_CLASSID(0), - CLASSID_TILE = NEXT_SUPER_CLASSID(1), - CLASSID_GAME_OBJECTS = NEXT_SUPER_CLASSID(2), - CLASSID_LIGHT = NEXT_SUPER_CLASSID(3), - CLASSID_SOUND = NEXT_SUPER_CLASSID(4), - CLASSID_WAYPATH = NEXT_SUPER_CLASSID(5), - CLASSID_ZONE = NEXT_SUPER_CLASSID(6), - CLASSID_TRANSITION = NEXT_SUPER_CLASSID(7), - CLASSID_PHYSICS = NEXT_SUPER_CLASSID(8), - CLASSID_EDITOR_OBJECTS = NEXT_SUPER_CLASSID(9), - CLASSID_MUNITIONS = NEXT_SUPER_CLASSID(10), - CLASSID_DUMMY_OBJECTS = NEXT_SUPER_CLASSID(11), - CLASSID_BUILDINGS = NEXT_SUPER_CLASSID(12), - CLASSID_TWIDDLERS = NEXT_SUPER_CLASSID(13), - CLASSID_GLOBAL_SETTINGS = NEXT_SUPER_CLASSID(14), -}; - - -////////////////////////////////////////////////////////////////////////////////// -// -// SuperClassID_From_ClassID -// -////////////////////////////////////////////////////////////////////////////////// -inline uint32 -SuperClassID_From_ClassID (uint32 class_id) -{ - // - // Which id-range does it fall under? - // - int delta = class_id - DEF_CLASSID_START; - int num_ranges = delta / DEF_CLASSID_RANGE; - - return DEF_CLASSID_START + (num_ranges * DEF_CLASSID_RANGE); -} - - -#endif //__DEFINITION_CLASS_ID_H - diff --git a/Generals/Code/Libraries/Source/WWVegas/WWSaveLoad/definitionfactory.cpp b/Generals/Code/Libraries/Source/WWVegas/WWSaveLoad/definitionfactory.cpp deleted file mode 100644 index 53b477acff8..00000000000 --- a/Generals/Code/Libraries/Source/WWVegas/WWSaveLoad/definitionfactory.cpp +++ /dev/null @@ -1,64 +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 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 : WWSaveLoad * - * * - * $Archive:: /Commando/Code/wwsaveload/definitionfactory.cpp $* - * * - * Author:: Patrick Smith * - * * - * $Modtime:: 9/09/99 7:12p $* - * * - * $Revision:: 6 $* - * * - *---------------------------------------------------------------------------------------------* - * Functions: * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - -#include "definitionfactory.h" -#include "definitionfactorymgr.h" - - -///////////////////////////////////////////////////////// -// -// DefinitionFactoryClass -// -///////////////////////////////////////////////////////// -DefinitionFactoryClass::DefinitionFactoryClass (void) - : m_NextFactory (0), - m_PrevFactory (0) -{ - DefinitionFactoryMgrClass::Register_Factory (this); - return ; -} - - -///////////////////////////////////////////////////////// -// -// ~DefinitionFactoryClass -// -///////////////////////////////////////////////////////// -DefinitionFactoryClass::~DefinitionFactoryClass (void) -{ - DefinitionFactoryMgrClass::Unregister_Factory (this); - return ; -} diff --git a/Generals/Code/Libraries/Source/WWVegas/WWSaveLoad/definitionfactory.h b/Generals/Code/Libraries/Source/WWVegas/WWSaveLoad/definitionfactory.h deleted file mode 100644 index 9102a4ace08..00000000000 --- a/Generals/Code/Libraries/Source/WWVegas/WWSaveLoad/definitionfactory.h +++ /dev/null @@ -1,93 +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 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 : WWSaveLoad * - * * - * $Archive:: /Commando/Code/wwsaveload/definitionfactory.h $* - * * - * Author:: Patrick Smith * - * * - * $Modtime:: 2/22/01 6:18p $* - * * - * $Revision:: 9 $* - * * - *---------------------------------------------------------------------------------------------* - * Functions: * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - -#if defined(_MSC_VER) -#pragma once -#endif - -#ifndef __DEFINITION_FACTORY_H -#define __DEFINITION_FACTORY_H - -#include "always.h" -#include "bittype.h" -#include "definitionclassids.h" - -// Forward declarations -class DefinitionClass; - -////////////////////////////////////////////////////////////////////////////////// -// -// DefinitionFactoryClass -// -// Definition factories act as virtual constructors for object definitions. They -// are responsible for creating new definitions for a particular class of objects. -// -////////////////////////////////////////////////////////////////////////////////// -class DefinitionFactoryClass -{ -public: - - ////////////////////////////////////////////////////////////// - // Public constructors/destructors - ////////////////////////////////////////////////////////////// - DefinitionFactoryClass (void); - virtual ~DefinitionFactoryClass (void); - - ////////////////////////////////////////////////////////////// - // Public methods - ////////////////////////////////////////////////////////////// - virtual DefinitionClass * Create (void) const = 0; - virtual const char * Get_Name (void) const = 0; - virtual uint32 Get_Class_ID (void) const = 0; - virtual bool Is_Displayed (void) const = 0; - -protected: - - ////////////////////////////////////////////////////////////// - // Protected member data - ////////////////////////////////////////////////////////////// - DefinitionFactoryClass * m_NextFactory; - DefinitionFactoryClass * m_PrevFactory; - - - ////////////////////////////////////////////////////////////// - // Friends - ////////////////////////////////////////////////////////////// - friend class DefinitionFactoryMgrClass; -}; - - -#endif //__DEFINITION_FACTORY_H diff --git a/Generals/Code/Libraries/Source/WWVegas/WWSaveLoad/definitionfactorymgr.cpp b/Generals/Code/Libraries/Source/WWVegas/WWSaveLoad/definitionfactorymgr.cpp deleted file mode 100644 index 4fd9baa6556..00000000000 --- a/Generals/Code/Libraries/Source/WWVegas/WWSaveLoad/definitionfactorymgr.cpp +++ /dev/null @@ -1,295 +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 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 : WWSaveLoad * - * * - * $Archive:: /VSS_Sync/wwsaveload/definitionfactorymgr.cpp $* - * * - * Author:: Patrick Smith * - * * - * $Modtime:: 10/16/00 11:42a $* - * * - * $Revision:: 12 $* - * * - *---------------------------------------------------------------------------------------------* - * Functions: * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - -#include "definitionfactorymgr.h" -#include "definitionfactory.h" -#include "wwdebug.h" -#include -#ifdef _UNIX -#include "osdep.h" -#endif - -//////////////////////////////////////////////////////////////////////////// -// Static member initialization -//////////////////////////////////////////////////////////////////////////// -DefinitionFactoryClass *DefinitionFactoryMgrClass::_FactoryListHead = 0; - - -//////////////////////////////////////////////////////////////////////////// -// -// Find_Factory -// -//////////////////////////////////////////////////////////////////////////// -DefinitionFactoryClass * -DefinitionFactoryMgrClass::Find_Factory (uint32 class_id) -{ - DefinitionFactoryClass *factory = 0; - - // - // Loop through all the factories and see if we can - // find the one who owns the corresponding class-id. - // - for ( DefinitionFactoryClass *curr_factory = _FactoryListHead; - (factory == 0) && (curr_factory != 0); - curr_factory = curr_factory->m_NextFactory) { - - // - // Is this the factory we were looking for? - // - if (curr_factory->Get_Class_ID () == class_id) { - factory = curr_factory; - } - } - - return factory; -} - - -//////////////////////////////////////////////////////////////////////////// -// -// Find_Factory -// -//////////////////////////////////////////////////////////////////////////// -DefinitionFactoryClass * -DefinitionFactoryMgrClass::Find_Factory (const char *name) -{ - DefinitionFactoryClass *factory = 0; - - // - // Loop through all the factories and see if we can - // find the one who owns the corresponding class-id. - // - for ( DefinitionFactoryClass *curr_factory = _FactoryListHead; - (factory == 0) && (curr_factory != 0); - curr_factory = curr_factory->m_NextFactory) { - - // - // Is this the factory we were looking for? - // - if (::stricmp (curr_factory->Get_Name (), name) == 0) { - factory = curr_factory; - } - } - - return factory; -} - - -//////////////////////////////////////////////////////////////////////////// -// -// Get_First -// -//////////////////////////////////////////////////////////////////////////// -DefinitionFactoryClass * -DefinitionFactoryMgrClass::Get_First (uint32 superclass_id) -{ - DefinitionFactoryClass *factory = 0; - - // - // Loop through all the factories and see if we can - // find the next one that belongs to the given superclass - // - for ( DefinitionFactoryClass *curr_factory = _FactoryListHead; - (factory == 0) && (curr_factory != 0); - curr_factory = curr_factory->m_NextFactory) { - - // - // Is this the factory we were looking for? - // - if (::SuperClassID_From_ClassID (curr_factory->Get_Class_ID ()) == superclass_id) { - factory = curr_factory; - } - } - - return factory; -} - - -//////////////////////////////////////////////////////////////////////////// -// -// Get_Next -// -//////////////////////////////////////////////////////////////////////////// -DefinitionFactoryClass * -DefinitionFactoryMgrClass::Get_Next -( - DefinitionFactoryClass *curr_factory, - uint32 superclass_id -) -{ - DefinitionFactoryClass *factory = 0; - - // - // Loop through all the factories and see if we can - // find the next one that belongs to the given superclass - // - while ((factory == NULL) && ((curr_factory = curr_factory->m_NextFactory) != NULL)) { - - // - // Is this the factory we were looking for? - // - if (::SuperClassID_From_ClassID (curr_factory->Get_Class_ID ()) == superclass_id) { - factory = curr_factory; - } - } - - return factory; -} - - -//////////////////////////////////////////////////////////////////////////// -// -// Get_First -// -//////////////////////////////////////////////////////////////////////////// -DefinitionFactoryClass * -DefinitionFactoryMgrClass::Get_First (void) -{ - return _FactoryListHead; -} - - -//////////////////////////////////////////////////////////////////////////// -// -// Get_Next -// -//////////////////////////////////////////////////////////////////////////// -DefinitionFactoryClass * -DefinitionFactoryMgrClass::Get_Next (DefinitionFactoryClass *curr_factory) -{ - DefinitionFactoryClass *factory = 0; - - // - // Simply return the next factory in the chain - // - if (curr_factory != NULL) { - factory = curr_factory->m_NextFactory; - } - - return factory; -} - - -//////////////////////////////////////////////////////////////////////////// -// -// Register_Factory -// -//////////////////////////////////////////////////////////////////////////// -void -DefinitionFactoryMgrClass::Register_Factory (DefinitionFactoryClass *factory) -{ - WWASSERT (factory->m_NextFactory == 0); - WWASSERT (factory->m_PrevFactory == 0); - Link_Factory (factory); - return ; -} - - -//////////////////////////////////////////////////////////////////////////// -// -// Unregister_Factory -// -//////////////////////////////////////////////////////////////////////////// -void -DefinitionFactoryMgrClass::Unregister_Factory (DefinitionFactoryClass *factory) -{ - WWASSERT (factory != 0); - Unlink_Factory (factory); - return ; -} - - -//////////////////////////////////////////////////////////////////////////// -// -// Link_Factory -// -//////////////////////////////////////////////////////////////////////////// -void -DefinitionFactoryMgrClass::Link_Factory (DefinitionFactoryClass *factory) -{ - WWASSERT (factory->m_NextFactory == 0); - WWASSERT (factory->m_PrevFactory == 0); - - // Adding this factory in front of the current head of the list - factory->m_NextFactory = _FactoryListHead; - - // If the list wasn't empty, link the next factory back to this factory - if (factory->m_NextFactory != 0) { - factory->m_NextFactory->m_PrevFactory = factory; - } - - // Point the head of the list at this factory now - _FactoryListHead = factory; - return ; -} - - -//////////////////////////////////////////////////////////////////////////// -// -// Unlink_Factory -// -//////////////////////////////////////////////////////////////////////////// -void -DefinitionFactoryMgrClass::Unlink_Factory (DefinitionFactoryClass *factory) -{ - WWASSERT(factory != 0); - - // Handle the factory's prev pointer: - if (factory->m_PrevFactory == 0) { - - // this factory is the head - WWASSERT (_FactoryListHead == factory); - _FactoryListHead = factory->m_NextFactory; - - } else { - - // link it's prev with it's next - factory->m_PrevFactory->m_NextFactory = factory->m_NextFactory; - - } - - // Handle the factory's next pointer if its not at the end of the list: - if (factory->m_NextFactory != 0) { - - factory->m_NextFactory->m_PrevFactory = factory->m_PrevFactory; - - } - - // factory is now un-linked - factory->m_NextFactory = 0; - factory->m_PrevFactory = 0; - return ; -} diff --git a/Generals/Code/Libraries/Source/WWVegas/WWSaveLoad/definitionfactorymgr.h b/Generals/Code/Libraries/Source/WWVegas/WWSaveLoad/definitionfactorymgr.h deleted file mode 100644 index a9b2bf939e8..00000000000 --- a/Generals/Code/Libraries/Source/WWVegas/WWSaveLoad/definitionfactorymgr.h +++ /dev/null @@ -1,90 +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 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 : WWSaveLoad * - * * - * $Archive:: /Commando/Code/wwsaveload/definitionfactorymgr.h $* - * * - * Author:: Patrick Smith * - * * - * $Modtime:: 7/07/00 11:55a $* - * * - * $Revision:: 11 $* - * * - *---------------------------------------------------------------------------------------------* - * Functions: * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - -#if defined(_MSC_VER) -#pragma once -#endif - -#ifndef __DEFINITION_FACTORY_MGR_H -#define __DEFINITION_FACTORY_MGR_H - -#include "always.h" -#include "bittype.h" -#include "definitionclassids.h" - -class DefinitionFactoryClass; - -////////////////////////////////////////////////////////////////////////////////// -// -// DefinitionFactoryMgrClass -// -////////////////////////////////////////////////////////////////////////////////// -class DefinitionFactoryMgrClass -{ -public: - - ///////////////////////////////////////////////////////////////////// - // Public methods - ///////////////////////////////////////////////////////////////////// - static DefinitionFactoryClass * Find_Factory (uint32 class_id); - static DefinitionFactoryClass * Find_Factory (const char *name); - static void Register_Factory (DefinitionFactoryClass *factory); - static void Unregister_Factory (DefinitionFactoryClass *factory); - - // Class enumeration - static DefinitionFactoryClass * Get_First (uint32 superclass_id); - static DefinitionFactoryClass * Get_Next (DefinitionFactoryClass *current, uint32 superclass_id); - - // Factory enumeration - static DefinitionFactoryClass * Get_First (void); - static DefinitionFactoryClass * Get_Next (DefinitionFactoryClass *current); - -private: - - ///////////////////////////////////////////////////////////////////// - // Private methods - ///////////////////////////////////////////////////////////////////// - static void Link_Factory (DefinitionFactoryClass *factory); - static void Unlink_Factory (DefinitionFactoryClass *factory); - - ///////////////////////////////////////////////////////////////////// - // Static member data - ///////////////////////////////////////////////////////////////////// - static DefinitionFactoryClass * _FactoryListHead; -}; - - -#endif //__DEFINITION_FACTORY_MGR_H diff --git a/Generals/Code/Libraries/Source/WWVegas/WWSaveLoad/definitionmgr.cpp b/Generals/Code/Libraries/Source/WWVegas/WWSaveLoad/definitionmgr.cpp deleted file mode 100644 index 171f9bcdef9..00000000000 --- a/Generals/Code/Libraries/Source/WWVegas/WWSaveLoad/definitionmgr.cpp +++ /dev/null @@ -1,953 +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 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 : WWSaveLoad * - * * - * $Archive:: /Commando/Code/wwsaveload/definitionmgr.cpp $* - * * - * Author:: Patrick Smith * - * * - * $Modtime:: 12/10/01 2:37p $* - * * - * $Revision:: 35 $* - * * - *---------------------------------------------------------------------------------------------* - * Functions: * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - -#include "definitionmgr.h" -#include "definition.h" -#include "definitionfactory.h" -#include "definitionfactorymgr.h" -#include "definitionclassids.h" -#include "chunkio.h" -#include "persistfactory.h" -#include "wwdebug.h" -#include "wwmemlog.h" -#include "twiddler.h" -#include -#include "wwprofile.h" - - -////////////////////////////////////////////////////////////////////////////////// -// Global instance -////////////////////////////////////////////////////////////////////////////////// -DefinitionMgrClass _TheDefinitionMgr; - -////////////////////////////////////////////////////////////////////////////////// -// Constants -////////////////////////////////////////////////////////////////////////////////// -static const int DEFINTION_LIST_GROW_SIZE = 1000; -static const uint32 IDRANGE_PER_CLASS = 10000; - -enum -{ - CHUNKID_VARIABLES = 0x00000100, - CHUNKID_OBJECTS, - CHUNKID_OBJECT -}; - -enum -{ - VARID_NEXTDEFID = 0x01 -}; - -////////////////////////////////////////////////////////////////////////////////// -// Static member initialization -////////////////////////////////////////////////////////////////////////////////// -DefinitionClass ** DefinitionMgrClass::_SortedDefinitionArray = NULL; -int DefinitionMgrClass::_DefinitionCount = 0; -int DefinitionMgrClass::_MaxDefinitionCount = 0; -HashTemplateClass*>* DefinitionMgrClass::DefinitionHash; - -////////////////////////////////////////////////////////////////////////////////// -// -// DefinitionMgrClass -// -////////////////////////////////////////////////////////////////////////////////// -DefinitionMgrClass::DefinitionMgrClass (void) -{ - return ; -} - - -////////////////////////////////////////////////////////////////////////////////// -// -// ~DefinitionMgrClass -// -////////////////////////////////////////////////////////////////////////////////// -DefinitionMgrClass::~DefinitionMgrClass (void) -{ - Free_Definitions (); - return ; -} - -////////////////////////////////////////////////////////////////////////////////// -// -// Find_Definition -// -////////////////////////////////////////////////////////////////////////////////// -DefinitionClass * -DefinitionMgrClass::Find_Definition (uint32 id, bool twiddle) -{ - DefinitionClass *definition = NULL; - - int lower_index = 0; - int upper_index = _DefinitionCount - 1; - int index = upper_index / 2; - bool keep_going = (_DefinitionCount > 0); - - // - // Binary search the list until we've found the definition - // - while (keep_going) { - - DefinitionClass *curr_def = _SortedDefinitionArray[index]; - WWASSERT (curr_def != NULL); - - // - // Is this the definition we are looking for? - // - if (curr_def->Get_ID () == id) { - definition = _SortedDefinitionArray[index]; - keep_going = false; - } else if (upper_index <= lower_index + 1) { - - // - // When the window get's too small, our divide by two won't catch - // both entries, so just go ahead and do them both now. - // - keep_going = false; - if (_SortedDefinitionArray[lower_index]->Get_ID () == id) { - definition = _SortedDefinitionArray[lower_index]; - } else if (_SortedDefinitionArray[upper_index]->Get_ID () == id) { - definition = _SortedDefinitionArray[upper_index]; - } - - } else { - - // - // Cut our 'window' in half - // - if (id > curr_def->Get_ID ()) { - lower_index = index; - index += (upper_index - index) / 2; - } else { - upper_index = index; - index -= (index - lower_index) / 2; - } - } - } - - // - // Should we twiddle this definition? (Twiddling refers to our randomizing - // framework for definitions) - // - if ( twiddle && - definition != NULL && - definition->Get_Class_ID () == CLASSID_TWIDDLERS) - { - definition = ((TwiddlerClass *)definition)->Twiddle (); - } - - return definition; -} - - -////////////////////////////////////////////////////////////////////////////////// -// -// Find_Named_Definition -// -////////////////////////////////////////////////////////////////////////////////// -DefinitionClass * -DefinitionMgrClass::Find_Named_Definition (const char *name, bool twiddle) -{ - DefinitionClass *definition = NULL; - - // - // Loop through all the definitions and see if we can - // find the one with the requested name - // - for (int index = 0; index < _DefinitionCount; index ++) { - DefinitionClass *curr_def = _SortedDefinitionArray[index]; - - // - // Is this the definition we were looking for? - // - if (curr_def != NULL && ::stricmp (curr_def->Get_Name (), name) == 0) { - definition = curr_def; - break; - } - } - - // - // Should we twiddle this definition? (Twiddling refers to our randomizing - // framework for definitions) - // - if ( twiddle && - definition != NULL && - definition->Get_Class_ID () == CLASSID_TWIDDLERS) - { - definition = ((TwiddlerClass *)definition)->Twiddle (); - } - - return definition; -} - - -////////////////////////////////////////////////////////////////////////////////// -// -// Find_Typed_Definition -// -////////////////////////////////////////////////////////////////////////////////// - -DefinitionClass * -DefinitionMgrClass::Find_Typed_Definition (const char *name, uint32 class_id, bool twiddle) -{ - // - // Sanity check - // - if (DefinitionHash == NULL) { - WWDEBUG_SAY (("DefinitionMgrClass::Find_Typed_Definition () failed due to a NULL DefinitionHash.\n")); - return NULL; - } - - DefinitionClass *definition = NULL; - - // Check the hash table first. The hash table is built as we need the definitions, so if definition is not - // in the table, it will be added there. - - // - // TSS null deref on this sucker 08/03/01 - // - WWASSERT(DefinitionHash != NULL); - - StringClass lower_case_name(name,true); - _strlwr(lower_case_name.Peek_Buffer()); - DynamicVectorClass* defs = DefinitionHash->Get(lower_case_name); - - if (defs) { - for (int i=0;iLength();++i) { - DefinitionClass* curr_def=(*defs)[i]; - WWASSERT(curr_def); - uint32 curr_class_id = curr_def->Get_Class_ID (); - if ( (curr_class_id == class_id) || - (::SuperClassID_From_ClassID (curr_class_id) == class_id) || - (twiddle && (curr_def->Get_Class_ID () == CLASSID_TWIDDLERS))) - { - definition = curr_def; - break; - } - } - } - - // - // Loop through all the definitions and see if we can - // find the one with the requested name - // - if (!definition) { - for (int index = 0; index < _DefinitionCount; index ++) { - DefinitionClass *curr_def = _SortedDefinitionArray[index]; - if (curr_def != NULL) { - - // - // Is this the correct class of definition? - // - uint32 curr_class_id = curr_def->Get_Class_ID (); - if ( (curr_class_id == class_id) || - (::SuperClassID_From_ClassID (curr_class_id) == class_id) || - (twiddle && (curr_def->Get_Class_ID () == CLASSID_TWIDDLERS))) - { - // - // Is this the definition we were looking for? - // - if (::stricmp (curr_def->Get_Name (), name) == 0) { - definition = curr_def; - // Add the definition to the hash table, so that it can be quickly accessed the next time it is needed. - if (!defs) { - defs=W3DNEW DynamicVectorClass; - DefinitionHash->Insert(lower_case_name,defs); - } - defs->Add(definition); - break; - } - } - } - } - } - - // - // Should we twiddle this definition? (Twiddling refers to our randomizing - // framework for definitions) - // - if ( twiddle && - definition != NULL && - definition->Get_Class_ID () == CLASSID_TWIDDLERS) - { - definition = ((TwiddlerClass *)definition)->Twiddle (); - } - - return definition; -} - - -////////////////////////////////////////////////////////////////////////////////// -// -// List_Available_Definitions -// -////////////////////////////////////////////////////////////////////////////////// -void -DefinitionMgrClass::List_Available_Definitions (void) -{ - // - // Loop through all the definitions and print the definition name - // - WWDEBUG_SAY(("Available definitions:\n")); - for (int index = 0; index < _DefinitionCount; index ++) { - DefinitionClass *curr_def = _SortedDefinitionArray[index]; - if (curr_def != NULL) { - WWDEBUG_SAY((" >%s<\n", curr_def->Get_Name ())); - } - } - - return ; -} - - -////////////////////////////////////////////////////////////////////////////////// -// -// List_Available_Definitions -// -////////////////////////////////////////////////////////////////////////////////// -void -DefinitionMgrClass::List_Available_Definitions (int superclass_id) -{ - // - // Loop through all the definitions and print the definition name - // - WWDEBUG_SAY(("Available superclass definitions for 0x%8X:\n", superclass_id)); - DefinitionClass *definition = NULL; - for ( definition = Get_First (superclass_id, DefinitionMgrClass::ID_SUPERCLASS); - definition != NULL; - definition = Get_Next (definition, superclass_id, DefinitionMgrClass::ID_SUPERCLASS)) - { - WWDEBUG_SAY((" >%s<\n", definition->Get_Name ())); - } - - return ; -} - - -////////////////////////////////////////////////////////////////////////////////// -// -// Get_First -// -////////////////////////////////////////////////////////////////////////////////// -DefinitionClass * -DefinitionMgrClass::Get_First (uint32 id, ID_TYPE type) -{ - DefinitionClass *definition = NULL; - - // - // Loop through all the definitions and find the first - // one that belongs to the requested class - // - for ( int index = 0; - (definition == NULL) && (index < _DefinitionCount); - index ++) - { - DefinitionClass *curr_def = _SortedDefinitionArray[index]; - if (curr_def != NULL) { - - // - // Is this the definition we were looking for? - // - if ( (type == ID_SUPERCLASS) && - (::SuperClassID_From_ClassID (curr_def->Get_Class_ID ()) == id)) { - definition = curr_def; - } else if ( (type == ID_CLASS) && - (curr_def->Get_Class_ID () == id)) { - definition = curr_def; - } - } - } - - return definition; -} - - -////////////////////////////////////////////////////////////////////////////////// -// -// Get_Next -// -////////////////////////////////////////////////////////////////////////////////// -DefinitionClass * -DefinitionMgrClass::Get_Next -( - DefinitionClass * curr_def, - uint32 id, - ID_TYPE type -) -{ - DefinitionClass *definition = NULL; - - // - // Loop through all the definitions and find the first - // one that belongs to the requested class - // - for ( int index = curr_def->m_DefinitionMgrLink + 1; - (definition == NULL) && (index < _DefinitionCount); - index ++) - { - DefinitionClass *curr_def = _SortedDefinitionArray[index]; - if (curr_def != NULL) { - - // - // Is this the definition we were looking for? - // - if ( (type == ID_SUPERCLASS) && - (::SuperClassID_From_ClassID (curr_def->Get_Class_ID ()) == id)) { - definition = curr_def; - } else if ( (type == ID_CLASS) && - (curr_def->Get_Class_ID () == id)) { - definition = curr_def; - } - } - } - - return definition; -} - - -//////////////////////////////////////////////////////////////////////////// -// -// Get_Next -// -//////////////////////////////////////////////////////////////////////////// -DefinitionClass * -DefinitionMgrClass::Get_Next (DefinitionClass *curr_def) -{ - WWASSERT (curr_def != NULL); - DefinitionClass *definition = NULL; - - int index = curr_def->m_DefinitionMgrLink + 1; - if (index < _DefinitionCount) { - definition = _SortedDefinitionArray[index]; - } - - return definition; -} - - -//////////////////////////////////////////////////////////////////////////// -// -// Free_Definitions -// -//////////////////////////////////////////////////////////////////////////// -void -DefinitionMgrClass::Free_Definitions (void) -{ - // Clear the hash table - if (DefinitionHash) { - HashTemplateIterator*> ite(*DefinitionHash); - for (ite.First();!ite.Is_Done();ite.Next()) { - DynamicVectorClass* defs=ite.Peek_Value(); -// delete ite.Peek_Value(); - delete defs; - } - DefinitionHash->Remove_All(); - delete DefinitionHash; - DefinitionHash=NULL; - } - - // - // Free each of the definition objects - // - for (int index = 0; index < _DefinitionCount; index ++) { - DefinitionClass *definition = _SortedDefinitionArray[index]; - if (definition != NULL) { - delete definition; - } - } - - // - // Free the definition array - // - if (_SortedDefinitionArray != NULL) { - delete [] _SortedDefinitionArray; - } - - _SortedDefinitionArray = NULL; - _MaxDefinitionCount = 0; - _DefinitionCount = 0; - return ; -} - - -//////////////////////////////////////////////////////////////////////////// -// -// Prepare_Definition_Array -// -//////////////////////////////////////////////////////////////////////////// -void -DefinitionMgrClass::Prepare_Definition_Array (void) -{ - if (_DefinitionCount + 1 > _MaxDefinitionCount) { - - // - // Allocate a new, bigger array - // - int new_size = _MaxDefinitionCount + DEFINTION_LIST_GROW_SIZE; - DefinitionClass **new_array = W3DNEWARRAY DefinitionClass *[new_size]; - - // - // Copy the entries from the old array to the new array - // - ::memcpy (new_array, _SortedDefinitionArray, _DefinitionCount * sizeof (DefinitionClass *)); - - // - // Free the old array and start using the new array - // - if (_SortedDefinitionArray != NULL) { - delete [] _SortedDefinitionArray; - } - _SortedDefinitionArray = new_array; - _MaxDefinitionCount = new_size; - } - if (!DefinitionHash) DefinitionHash=W3DNEW HashTemplateClass*>; - - return ; -} - - -//////////////////////////////////////////////////////////////////////////// -// -// Register_Definition -// -//////////////////////////////////////////////////////////////////////////// -void -DefinitionMgrClass::Register_Definition (DefinitionClass *definition) -{ - WWASSERT (definition != NULL); - if (definition != NULL && definition->m_DefinitionMgrLink == -1 && definition->Get_ID () != 0) { - // - // Make sure the definition array is large enough - // - Prepare_Definition_Array (); - - // - // Calculate where in the list we should insert this definition - // - uint32 id = definition->Get_ID (); - int lower_index = 0; - int upper_index = _DefinitionCount - 1; - int index = upper_index / 2; - int insert_index = _DefinitionCount; - bool keep_going = (_DefinitionCount > 0); - bool is_valid = true; - - while (keep_going) { - - DefinitionClass *curr_def = _SortedDefinitionArray[index]; - WWASSERT (curr_def != NULL); - - // - // Check to make sure we aren't trying to register a definition - // that has the same ID as a definition that is already in the list. - // - if (curr_def->Get_ID () == id) { - insert_index = index; - keep_going = false; - is_valid = false; - } else { - - // - // Cut our 'window' in half - // - if (id > curr_def->Get_ID ()) { - lower_index = index; - index += (upper_index - index) / 2; - } else { - upper_index = index; - index -= (index - lower_index) / 2; - } - - // - // If we've narrowed down the window to 2 entries, then quick check - // the different possibilities. - // - if (upper_index <= lower_index + 1) { - if (_SortedDefinitionArray[upper_index]->Get_ID () <= id) { - insert_index = upper_index + 1; - } else if (_SortedDefinitionArray[lower_index]->Get_ID () <= id) { - insert_index = upper_index; - } else { - insert_index = lower_index; - } - keep_going = false; - } - } - } - - //WWASSERT (is_valid); - if (is_valid) { - - // - // Re-index all the definitions that got bumped one cell due to this insertion. - // - for (index = _DefinitionCount - 1; index >= insert_index; index --) { - _SortedDefinitionArray[index + 1] = _SortedDefinitionArray[index]; - _SortedDefinitionArray[index + 1]->m_DefinitionMgrLink = index + 1; - } - - // - // Insert this definition into the list - // - definition->m_DefinitionMgrLink = insert_index; - _SortedDefinitionArray[insert_index] = definition; - _DefinitionCount ++; - } - } - - return ; -} - - -//////////////////////////////////////////////////////////////////////////// -// -// Unregister_Definition -// -//////////////////////////////////////////////////////////////////////////// -void -DefinitionMgrClass::Unregister_Definition (DefinitionClass *definition) -{ - WWASSERT (definition != 0); - //WWASSERT (definition->m_DefinitionMgrLink >= 0 && definition->m_DefinitionMgrLink < _DefinitionCount); - - if (definition != NULL && definition->m_DefinitionMgrLink != -1) { - - // - // Re-index the definitions that come after this definition in the list - // - for (int index = definition->m_DefinitionMgrLink; index < _DefinitionCount - 1; index ++) { - _SortedDefinitionArray[index] = _SortedDefinitionArray[index + 1]; - _SortedDefinitionArray[index]->m_DefinitionMgrLink = index; - } - - _SortedDefinitionArray[_DefinitionCount - 1] = NULL; - definition->m_DefinitionMgrLink = -1; - _DefinitionCount --; - } - - return ; -} - - -////////////////////////////////////////////////////////////////////////////////// -// -// Save -// -////////////////////////////////////////////////////////////////////////////////// -bool -DefinitionMgrClass::Save -( - ChunkSaveClass & csave -) -{ - WWMEMLOG(MEM_GAMEDATA); - - bool retval = true; - - // - // Create a chunk to contain the class variables we need to serialize. - // - csave.Begin_Chunk (CHUNKID_VARIABLES); - Save_Variables (csave); - csave.End_Chunk (); - - // - // Have the base class write the objects to their own chunk. - // - csave.Begin_Chunk (CHUNKID_OBJECTS); - retval &= Save_Objects (csave); - csave.End_Chunk (); - - return retval; -} - - -////////////////////////////////////////////////////////////////////////////////// -// -// Load -// -////////////////////////////////////////////////////////////////////////////////// -bool -DefinitionMgrClass::Load (ChunkLoadClass &cload) -{ - WWMEMLOG(MEM_GAMEDATA); - bool retval = true; - - while (cload.Open_Chunk ()) { - switch (cload.Cur_Chunk_ID ()) { - - // - // If this is the chunk that contains the class variables, then - // loop through and read each microchunk - // - case CHUNKID_VARIABLES: - retval &= Load_Variables (cload); - break; - - // - // Load all the definition objects from this chunk - // - case CHUNKID_OBJECTS: - retval &= Load_Objects (cload); - break; - } - - cload.Close_Chunk (); - } - - return retval; -} - - -////////////////////////////////////////////////////////////////////////////////// -// -// Save_Objects -// -////////////////////////////////////////////////////////////////////////////////// -bool -DefinitionMgrClass::Save_Objects -( - ChunkSaveClass & csave -) -{ - bool retval = true; - - // - // Loop through all the definition objects - // - for (int index = 0; index < _DefinitionCount; index ++) { - DefinitionClass *definition = _SortedDefinitionArray[index]; - if (definition != NULL && definition->Is_Save_Enabled ()) { - - // - // Save this definition object - // - csave.Begin_Chunk (definition->Get_Factory ().Chunk_ID ()); - definition->Get_Factory ().Save (csave, definition); - csave.End_Chunk (); - } - } - - return retval; -} - - -////////////////////////////////////////////////////////////////////////////////// -// -// Save_Variables -// -////////////////////////////////////////////////////////////////////////////////// -bool -DefinitionMgrClass::Save_Variables (ChunkSaveClass &csave) -{ - bool retval = true; - return retval; -} - -float _alloc_time; -float _load_time; -float _reg_time; - - -////////////////////////////////////////////////////////////////////////////////// -// -// Load_Objects -// -////////////////////////////////////////////////////////////////////////////////// -bool -DefinitionMgrClass::Load_Objects (ChunkLoadClass &cload) -{ - bool retval = true; - - while (cload.Open_Chunk ()) { - - // - // Load this definition from the chunk (if possible) - // - PersistFactoryClass *factory = SaveLoadSystemClass::Find_Persist_Factory (cload.Cur_Chunk_ID ()); - if (factory != NULL) { - - DefinitionClass *definition = (DefinitionClass *)factory->Load (cload); - if (definition != NULL) { - - // - // Add this definition to our array - // - Prepare_Definition_Array (); - _SortedDefinitionArray[_DefinitionCount ++] = definition; - } - } - - cload.Close_Chunk (); - } - - // - // Sort the definitions - // - if (_DefinitionCount > 0) { - ::qsort (_SortedDefinitionArray, _DefinitionCount, sizeof (DefinitionClass *), fnCompareDefinitionsCallback); - } - - // - // Assign a mgr link to each definition - // - for (int index = 0; index < _DefinitionCount; index ++) { - _SortedDefinitionArray[index]->m_DefinitionMgrLink = index; - } - - return retval; -} - - -////////////////////////////////////////////////////////////////////////////////// -// -// Load_Variables -// -////////////////////////////////////////////////////////////////////////////////// -bool -DefinitionMgrClass::Load_Variables (ChunkLoadClass &cload) -{ - bool retval = true; - - // - // Loop through all the microchunks that define the variables - // - while (cload.Open_Micro_Chunk ()) { - switch (cload.Cur_Micro_Chunk_ID ()) { - - case VARID_NEXTDEFID: - break; - } - - cload.Close_Micro_Chunk (); - } - - return retval; -} - - -///////////////////////////////////////////////////////////////////// -// -// Get_New_ID -// -///////////////////////////////////////////////////////////////////// -uint32 -DefinitionMgrClass::Get_New_ID (uint32 class_id) -{ - uint32 idrange_start = (class_id - DEF_CLASSID_START) * IDRANGE_PER_CLASS; - uint32 idrange_end = (idrange_start + IDRANGE_PER_CLASS); - - uint32 new_id = idrange_start + 1; - - // - // Try to find the first empty slot in this ID range - // - for (int index = 0; index < _DefinitionCount; index ++) { - DefinitionClass *definition = _SortedDefinitionArray[index]; - if (definition != NULL) { - - // - // Get this definition's ID - // - uint32 curr_id = definition->Get_ID (); - - // - // Is this id in the range we are looking for? - // - if (curr_id >= idrange_start && curr_id < idrange_end) { - - bool is_ok = false; - if (index < _DefinitionCount - 1) { - - // - // Check to see if the next definition in our array leaves a hole in the - // ID range. - // - DefinitionClass *next_definition = _SortedDefinitionArray[index + 1]; - if (next_definition != NULL && next_definition->Get_ID () > (curr_id + 1)) { - is_ok = true; - } - - } else { - is_ok = true; - } - - // - // Return the new ID - // - if (is_ok) { - new_id = curr_id + 1; - break; - } - } - } - } - - return new_id; -} - - -//////////////////////////////////////////////////////////////// -// -// fnCompareDefinitionsCallback -// -//////////////////////////////////////////////////////////////// -int __cdecl -DefinitionMgrClass::fnCompareDefinitionsCallback -( - const void *elem1, - const void *elem2 -) -{ - WWASSERT (elem1 != NULL); - WWASSERT (elem2 != NULL); - DefinitionClass *definition1 = *((DefinitionClass **)elem1); - DefinitionClass *definition2 = *((DefinitionClass **)elem2); - - // - // Sort the definitions based on ID - // - int result = 0; - if (definition1->Get_ID () > definition2->Get_ID ()) { - result = 1; - } else if (definition1->Get_ID () < definition2->Get_ID ()) { - result = -1; - } else { - result = 0; - } - - return result; -} diff --git a/Generals/Code/Libraries/Source/WWVegas/WWSaveLoad/definitionmgr.h b/Generals/Code/Libraries/Source/WWVegas/WWSaveLoad/definitionmgr.h deleted file mode 100644 index 52d1180df86..00000000000 --- a/Generals/Code/Libraries/Source/WWVegas/WWSaveLoad/definitionmgr.h +++ /dev/null @@ -1,187 +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 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 : WWSaveLoad * - * * - * $Archive:: /Commando/Code/wwsaveload/definitionmgr.h $* - * * - * Author:: Patrick Smith * - * * - * $Modtime:: 8/24/01 5:13p $* - * * - * $Revision:: 24 $* - * * - *---------------------------------------------------------------------------------------------* - * Functions: * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - - -#if defined(_MSC_VER) -#pragma once -#endif - - -#ifndef __DEFINITION_MGR_H -#define __DEFINITION_MGR_H - -#include "always.h" -#include "saveload.h" -#include "saveloadsubsystem.h" -#include "saveloadids.h" -#include "wwdebug.h" -#include "wwstring.h" -#include "hashtemplate.h" -#include "Vector.H" - - -// Forward declarations -class DefinitionClass; - -////////////////////////////////////////////////////////////////////////////////// -// Global declarations -////////////////////////////////////////////////////////////////////////////////// -extern class DefinitionMgrClass _TheDefinitionMgr; - -////////////////////////////////////////////////////////////////////////////////// -// -// DefinitionMgrClass -// -////////////////////////////////////////////////////////////////////////////////// -class DefinitionMgrClass : public SaveLoadSubSystemClass -{ -public: - - ///////////////////////////////////////////////////////////////////// - // Public constructors/destructors - ///////////////////////////////////////////////////////////////////// - DefinitionMgrClass (void); - ~DefinitionMgrClass (void); - - ///////////////////////////////////////////////////////////////////// - // Public methods - ///////////////////////////////////////////////////////////////////// - - // From SaveLoadSubSystemClass - virtual uint32 Chunk_ID (void) const; - - // Type identification - static DefinitionClass * Find_Definition (uint32 id, bool twiddle = true); - static DefinitionClass * Find_Named_Definition (const char *name, bool twiddle = true); - static DefinitionClass * Find_Typed_Definition (const char *name, uint32 class_id, bool twiddle = true); - static void List_Available_Definitions (void); - static void List_Available_Definitions (int superclass_id); - static uint32 Get_New_ID (uint32 class_id); - - // Definition registration - static void Register_Definition (DefinitionClass *definition); - static void Unregister_Definition (DefinitionClass *definition); - - // - // Definition enumeration - // - typedef enum - { - ID_CLASS = 1, - ID_SUPERCLASS, - } ID_TYPE; - - static DefinitionClass * Get_First (void); - static DefinitionClass * Get_First (uint32 id, ID_TYPE type = ID_CLASS); - static DefinitionClass * Get_Next (DefinitionClass *curr_def); - static DefinitionClass * Get_Next (DefinitionClass *curr_def, uint32 id, ID_TYPE type = ID_CLASS); - - static void Free_Definitions (void); - -protected: - - ///////////////////////////////////////////////////////////////////// - // Protected methods - ///////////////////////////////////////////////////////////////////// - - // From SaveLoadSubSystemClass - virtual bool Contains_Data (void) const; - virtual bool Save (ChunkSaveClass &csave); - virtual bool Load (ChunkLoadClass &cload); - virtual const char* Name (void) const { return "DefinitionMgrClass"; } - - // Persistence methods - bool Save_Objects (ChunkSaveClass &csave); - bool Load_Objects (ChunkLoadClass &cload); - bool Save_Variables (ChunkSaveClass &csave); - bool Load_Variables (ChunkLoadClass &cload); - -private: - static HashTemplateClass*>* DefinitionHash; - - ///////////////////////////////////////////////////////////////////// - // Private methods - ///////////////////////////////////////////////////////////////////// - static void Prepare_Definition_Array (void); - static int __cdecl fnCompareDefinitionsCallback (const void *elem1, const void *elem2); - - ///////////////////////////////////////////////////////////////////// - // Static member data - ///////////////////////////////////////////////////////////////////// - static DefinitionClass ** _SortedDefinitionArray; - static int _MaxDefinitionCount; - static int _DefinitionCount; - - ///////////////////////////////////////////////////////////////////// - // Friend classes - ///////////////////////////////////////////////////////////////////// - friend class DefinitionClass; -}; - -///////////////////////////////////////////////////////////////////// -// Chunk_ID -///////////////////////////////////////////////////////////////////// -inline uint32 -DefinitionMgrClass::Chunk_ID (void) const -{ - return CHUNKID_SAVELOAD_DEFMGR; -} - -///////////////////////////////////////////////////////////////////// -// Contains_Data -///////////////////////////////////////////////////////////////////// -inline bool -DefinitionMgrClass::Contains_Data (void) const -{ - return true; // TODO: check if we have any definitions... -} - -///////////////////////////////////////////////////////////////////// -// Get_First_Definition -///////////////////////////////////////////////////////////////////// -inline DefinitionClass * -DefinitionMgrClass::Get_First (void) -{ - DefinitionClass *definition = NULL; - if (_DefinitionCount > 0) { - definition = _SortedDefinitionArray[0]; - } - - return definition; -} - - -#endif //__DEFINITION_MGR_H diff --git a/Generals/Code/Libraries/Source/WWVegas/WWSaveLoad/editable.h b/Generals/Code/Libraries/Source/WWVegas/WWSaveLoad/editable.h deleted file mode 100644 index b2aade33fe8..00000000000 --- a/Generals/Code/Libraries/Source/WWVegas/WWSaveLoad/editable.h +++ /dev/null @@ -1,339 +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 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 : WWSaveLoad * - * * - * $Archive:: /Commando/Code/wwsaveload/editable.h $* - * * - * * - * Org Author:: Patrick Smith * - * * - * Author:: Kenny Mitchell * - * * - * $Modtime:: 5/29/02 11:00a $* - * * - * $Revision:: 29 $* - * * - *---------------------------------------------------------------------------------------------* - * Functions: * - * 5/27/02 KM Added named filename parameter declaration - * 5/29/02 KM Added specific texture filename parameter support - *---------------------------------------------------------------------------------------------* - * Functions: * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - - -#if defined(_MSC_VER) -#pragma once -#endif - - -#ifndef __EDITABLE_H -#define __EDITABLE_H - - -#include "always.h" -#include "persist.h" -#include "parameter.h" -#include "simpleparameter.h" -#include "parameterlist.h" -#include "wwdebug.h" - -////////////////////////////////////////////////////////////////////////////////// -// -// EditableClass -// -////////////////////////////////////////////////////////////////////////////////// -class EditableClass -{ -public: - - ///////////////////////////////////////////////////////////////////// - // Public methods - // - // Note: These methods can be implemented in derived classes - // by the DECLARE_EDITABLE macro. - // - ///////////////////////////////////////////////////////////////////// - virtual int Get_Parameter_Count (void) const; - virtual ParameterClass * Lock_Parameter (int i); - virtual void Unlock_Parameter (int i); -}; - -///////////////////////////////////////////////////////////////////// -// Get_Parameter_Count -///////////////////////////////////////////////////////////////////// -inline int -EditableClass::Get_Parameter_Count (void) const -{ - return 0; -} - -///////////////////////////////////////////////////////////////////// -// Get_Parameter -///////////////////////////////////////////////////////////////////// -inline ParameterClass * -EditableClass::Lock_Parameter (int i) -{ - WWASSERT (0); - return NULL; -} - -///////////////////////////////////////////////////////////////////// -// Set_Parameter -///////////////////////////////////////////////////////////////////// -inline void -EditableClass::Unlock_Parameter (int i) -{ - return ; -} - -//#define PARAM_EDITING_ON -#ifdef PARAM_EDITING_ON - - ////////////////////////////////////////////////////////////////////////////////// - // - // DECLARE_EDITABLE - // - ////////////////////////////////////////////////////////////////////////////////// - #define DECLARE_EDITABLE(_class, _parent) \ - ParameterListClass plist_##_class; \ - virtual int _class::Get_Parameter_Count(void) const \ - { \ - return plist_##_class.Count () + _parent::Get_Parameter_Count (); \ - } \ - virtual ParameterClass *_class::Lock_Parameter(int i) \ - { \ - if (i < _parent::Get_Parameter_Count()) { \ - return _parent::Lock_Parameter (i); \ - } \ - return plist_##_class[i - _parent::Get_Parameter_Count()]; \ - } \ - - ////////////////////////////////////////////////////////////////////////////////// - // - // EDITABLE_PARAM - // - // The following macros are used inside the constructor for an editable - // object to map member data to abstract parameter objects. - // - // Some examples: - // - // To register the player's name (a string): - // EDITABLE_PARAM(GameClass, ParameterClass::TYPE_STRING, Name) - // - // To register the player's name using a more descriptive display string: - // NAMED_EDITABLE_PARAM(GameClass, ParameterClass::TYPE_STRING, Name, "Player Name") - // - // To register a unit's maximum health - // INT_EDITABLE_PARAM(GameClass, MaxHeatlh, 0, 500) - // - // To register a complex variable (such as an enumerated type: - // #ifdef PARAM_EDITING_ON - // EnumParameterClass *param = new EnumParameterClass(GangID); - // param->Set_Name ("Gang"); - // param->Add_Value ("GDI", ID_GDI); - // param->Add_Value ("NOD", ID_NOD); - // param->Add_Value ("Neutral", ID_NEUTRAL); - // GENERIC_EDITABLE_PARAM(param) - // #endif - // - ////////////////////////////////////////////////////////////////////////////////// - - - #define EDITABLE_PARAM(_class, type, data) plist_##_class.Add (&(data), #data, type); - #define NAMED_EDITABLE_PARAM(_class, type, data, name) plist_##_class.Add (&(data), name, type); - - #define INT_EDITABLE_PARAM(_class, data, min, max) { \ - IntParameterClass *param = W3DNEW IntParameterClass( &data, #data); \ - param->Set_Range (min, max); \ - plist_##_class.Add (param); } \ - - #define INT_UNITS_PARAM(_class, data, min, max, unitsname) { \ - IntParameterClass *param = W3DNEW IntParameterClass( &data, #data); \ - param->Set_Range (min, max); \ - param->Set_Units_Name(unitsname); \ - plist_##_class.Add (param); } \ - - #define NAMED_INT_UNITS_PARAM(_class,data,min,max,unitsname,name) { \ - IntParameterClass *param = W3DNEW IntParameterClass( &data, #data); \ - param->Set_Range (min, max); \ - param->Set_Units_Name(unitsname); \ - param->Set_Name(name); \ - plist_##_class.Add (param); } \ - - #define FLOAT_EDITABLE_PARAM(_class, data, min, max) { \ - FloatParameterClass *param = W3DNEW FloatParameterClass( &data, #data); \ - param->Set_Range (min, max); \ - plist_##_class.Add (param); } \ - - #define FLOAT_UNITS_PARAM(_class, data, min, max, unitsname) { \ - FloatParameterClass *param = W3DNEW FloatParameterClass( &data, #data); \ - param->Set_Range (min, max); \ - param->Set_Units_Name(unitsname); \ - plist_##_class.Add (param); } - - #define NAMED_FLOAT_UNITS_PARAM(_class, data, min, max, unitsname,name) { \ - FloatParameterClass *param = W3DNEW FloatParameterClass( &data, #data); \ - param->Set_Range (min, max); \ - param->Set_Units_Name(unitsname); \ - param->Set_Name(name); \ - plist_##_class.Add (param); } - - #define ANGLE_EDITABLE_PARAM(_class, data, min, max) { \ - AngleParameterClass *param = W3DNEW AngleParameterClass( &data, #data); \ - param->Set_Range (min, max); \ - param->Set_Units_Name ("degrees"); \ - plist_##_class.Add (param); } \ - - #define NAMED_ANGLE_EDITABLE_PARAM(_class, data, min, max, name) { \ - AngleParameterClass *param = W3DNEW AngleParameterClass( &data, #data); \ - param->Set_Range (min, max); \ - param->Set_Units_Name ("degrees"); \ - param->Set_Name(name); \ - plist_##_class.Add (param); } \ - - #define GENERIC_EDITABLE_PARAM(_class, param) \ - plist_##_class.Add (param); \ - - #define MODEL_DEF_PARAM(_class, data, name) { \ - ModelDefParameterClass *param = W3DNEW ModelDefParameterClass (&data); \ - param->Set_Name (#data); \ - param->Set_Base_Class (name); \ - GENERIC_EDITABLE_PARAM(_class, param); } - - #define PHYS_DEF_PARAM(_class, data, name) { \ - PhysDefParameterClass *param = W3DNEW PhysDefParameterClass (&data); \ - param->Set_Name (#data); \ - param->Set_Base_Class (name); \ - GENERIC_EDITABLE_PARAM(_class, param); } - - #define SCRIPT_PARAM(_class, name, params) { \ - ScriptParameterClass *param = W3DNEW ScriptParameterClass (&name, ¶ms); \ - param->Set_Name (#name); \ - GENERIC_EDITABLE_PARAM(_class, param); } - - #define SCRIPTLIST_PARAM(_class, name, name_list, param_list) { \ - ScriptListParameterClass *param = W3DNEW ScriptListParameterClass (&name_list, ¶m_list); \ - param->Set_Name (name); \ - GENERIC_EDITABLE_PARAM(_class, param); } - - #define ENUM_PARAM(_class, data, params) { \ - EnumParameterClass *param = W3DNEW EnumParameterClass (&data); \ - param->Set_Name (#data); \ - param->Add_Values params; \ - plist_##_class.Add (param); } \ - - #define FILENAME_PARAM(_class, data, desc, extension) { \ - FilenameParameterClass *param = W3DNEW FilenameParameterClass (&data); \ - param->Set_Name (#data); \ - param->Set_Description (desc); \ - param->Set_Extension (extension); \ - plist_##_class.Add (param); } \ - - #define NAMED_FILENAME_PARAM(_class, data, name, desc, extension) { \ - FilenameParameterClass *param = new FilenameParameterClass (&data); \ - param->Set_Name (name); \ - param->Set_Description (desc); \ - param->Set_Extension (extension); \ - plist_##_class.Add (param); } \ - - #define TEXTURE_FILENAME_PARAM(_class, data, desc, extension) { \ - TextureFilenameParameterClass *param = new TextureFilenameParameterClass (&data); \ - param->Set_Name (#data); \ - param->Set_Description (desc); \ - param->Set_Extension (extension); \ - plist_##_class.Add (param); } \ - - #define NAMED_TEXTURE_FILENAME_PARAM(_class, data, name, desc, extension) { \ - TextureFilenameParameterClass *param = new TextureFilenameParameterClass (&data); \ - param->Set_Name (name); \ - param->Set_Description (desc); \ - param->Set_Extension (extension); \ - plist_##_class.Add (param); } \ - - #define DEFIDLIST_PARAM(_class, data, root_class_id) { \ - DefIDListParameterClass *param = W3DNEW DefIDListParameterClass (&data); \ - param->Set_Name (#data); \ - param->Set_Class_ID (root_class_id); \ - plist_##_class.Add (param); } \ - - #define CLASSID_DEFIDLIST_PARAM(_class, data, root_class_id, class_id, name) { \ - DefIDListParameterClass *param = W3DNEW DefIDListParameterClass (&data); \ - param->Set_Name (name); \ - param->Set_Class_ID (root_class_id); \ - param->Set_Selected_Class_ID (&class_id); \ - plist_##_class.Add (param); } - - #define ZONE_PARAM(_class, data, name) { \ - ZoneParameterClass *param = W3DNEW ZoneParameterClass (&data); \ - param->Set_Name (name); \ - GENERIC_EDITABLE_PARAM(_class, param); } - - #define PARAM_SEPARATOR(_class, name) { \ - SeparatorParameterClass *param = W3DNEW SeparatorParameterClass; \ - param->Set_Name (name); \ - GENERIC_EDITABLE_PARAM(_class, param); } - - #define GENERIC_DEFID_PARAM(_class, data, root_class_id) { \ - GenericDefParameterClass *param = W3DNEW GenericDefParameterClass (&data); \ - param->Set_Class_ID (root_class_id); \ - param->Set_Name (#data); \ - plist_##_class.Add (param); } - - -#else - - #define DECLARE_EDITABLE(_class, _parent) - #define EDITABLE_PARAM(_class, type, data) - #define NAMED_EDITABLE_PARAM(_class, type, data, name) - #define INT_EDITABLE_PARAM(_class, data, min, max) - #define INT_UNITS_PARAM(_class, data, min, max, unitsname) - #define NAMED_INT_UNITS_PARAM(_class,data,min,max,unitsname,name) - #define FLOAT_EDITABLE_PARAM(_class, data, min, max) - #define FLOAT_UNITS_PARAM(_class, data, min, max, unitsname) - #define NAMED_FLOAT_UNITS_PARAM(_class, data, min, max, unitsname,name) - #define ANGLE_EDITABLE_PARAM(_class, data, min, max) - #define NAMED_ANGLE_EDITABLE_PARAM(_class, data, min, max, name) - #define GENERIC_EDITABLE_PARAM(_class, param) - #define MODEL_DEF_PARAM(_class, data, name) - #define PHYS_DEF_PARAM(_class, data, name) - #define SCRIPT_PARAM(_class, name, params) - #define SCRIPTLIST_PARAM(_class, name, name_list, param_list) - #define ENUM_PARAM(_class, data, params) - #define FILENAME_PARAM(_class, data, desc, extension) - #define NAMED_FILENAME_PARAM(_class, data, name, desc, extension) - #define TEXTURE_FILENAME_PARAM(_class, data, desc, extension) - #define NAMED_TEXTURE_FILENAME_PARAM(_class, data, name, desc, extension) - #define DEFIDLIST_PARAM(_class, data, root_class_id) - #define CLASSID_DEFIDLIST_PARAM(_class, data, root_class_id, class_id, name) - #define ZONE_PARAM(_class, data, name) - #define PARAM_SEPARATOR(_class, name) - #define GENERIC_DEFID_PARAM(_class, data, root_class_id) - -#endif //PARAM_EDITING_ON - - -#endif //__EDITABLE_H - - - diff --git a/Generals/Code/Libraries/Source/WWVegas/WWSaveLoad/parameter.cpp b/Generals/Code/Libraries/Source/WWVegas/WWSaveLoad/parameter.cpp deleted file mode 100644 index 5473d0e6d3b..00000000000 --- a/Generals/Code/Libraries/Source/WWVegas/WWSaveLoad/parameter.cpp +++ /dev/null @@ -1,2243 +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 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 : WWSaveLoad * - * * - * $Archive:: /Commando/Code/wwsaveload/parameter.cpp $* - * * - * Org Author:: Patrick Smith * - * * - * Author:: Kenny Mitchell * - * * - * $Modtime:: 5/29/02 11:00a $* - * * - * $Revision:: 33 $* - * * - *---------------------------------------------------------------------------------------------* - * Functions: * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - - -#include "parameter.h" -#include "parametertypes.h" -#include "simpleparameter.h" -#include "wwstring.h" -#include "definitionclassids.h" - - -///////////////////////////////////////////////////////////////////// -// -// Construct -// -// This is a virtual constructor that is capable of creating a new -// instance of any type of parameter used in the Editable system. -// -///////////////////////////////////////////////////////////////////// -ParameterClass * -ParameterClass::Construct (Type type, void *data, const char *name) -{ - ParameterClass *new_param = NULL; - switch (type) { - - case TYPE_INT: - new_param = W3DNEW IntParameterClass (data, name); - break; - - case TYPE_FLOAT: - new_param = W3DNEW FloatParameterClass (data, name); - break; - - case TYPE_VECTOR2: - new_param = W3DNEW Vector2ParameterClass (data, name); - break; - - case TYPE_VECTOR3: - new_param = W3DNEW Vector3ParameterClass (data, name); - break; - - case TYPE_RECT: - new_param = W3DNEW RectParameterClass (data, name); - break; - - case TYPE_COLOR: - new_param = W3DNEW ColorParameterClass (data, name); - break; - - case TYPE_MATRIX3D: - new_param = W3DNEW Matrix3DParameterClass (data, name); - break; - - case TYPE_BOOL: - new_param = W3DNEW BoolParameterClass (data, name); - break; - - case TYPE_STRINGSDB_ID: - new_param = W3DNEW StringsDBEntryParameterClass (data, name); - break; - - case TYPE_ANGLE: - new_param = W3DNEW AngleParameterClass (data, name); - break; - - case TYPE_STRING: - new_param = W3DNEW StringParameterClass ((StringClass *)data); - new_param->Set_Name (name); - break; - - case TYPE_FILENAME: - new_param = W3DNEW FilenameParameterClass ((StringClass *)data); - new_param->Set_Name (name); - break; - - case TYPE_TEXTURE_FILENAME: - new_param = new TextureFilenameParameterClass ((StringClass *)data); - new_param->Set_Name (name); - break; - - case TYPE_SOUND_FILENAME: - new_param = W3DNEW SoundFilenameParameterClass ((StringClass *)data); - new_param->Set_Name (name); - break; - - case TYPE_ENUM: - new_param = W3DNEW EnumParameterClass ((int *)data); - new_param->Set_Name (name); - break; - - case TYPE_GENERICDEFINITIONID: - new_param = W3DNEW GenericDefParameterClass ((int *)data); - new_param->Set_Name (name); - break; - - case TYPE_GAMEOBJDEFINITIONID: - new_param = W3DNEW GameObjDefParameterClass ((int *)data); - new_param->Set_Name (name); - break; - - case TYPE_WEAPONOBJDEFINITIONID: - new_param = W3DNEW WeaponObjDefParameterClass ((int *)data); - new_param->Set_Name (name); - break; - - case TYPE_AMMOOBJDEFINITIONID: - new_param = W3DNEW AmmoObjDefParameterClass ((int *)data); - new_param->Set_Name (name); - break; - - case TYPE_EXPLOSIONDEFINITIONID: - new_param = W3DNEW ExplosionObjDefParameterClass ((int *)data); - new_param->Set_Name (name); - break; - - case TYPE_SOUNDDEFINITIONID: - new_param = W3DNEW SoundDefParameterClass ((int *)data); - new_param->Set_Name (name); - break; - - case TYPE_MODELDEFINITIONID: - new_param = W3DNEW ModelDefParameterClass ((int *)data); - new_param->Set_Name (name); - break; - - case TYPE_PHYSDEFINITIONID: - new_param = W3DNEW PhysDefParameterClass ((int *)data); - new_param->Set_Name (name); - break; - - case TYPE_DEFINITIONIDLIST: - new_param = W3DNEW DefIDListParameterClass ((DynamicVectorClass *)data); - new_param->Set_Name (name); - ((DefIDListParameterClass *)new_param)->Set_Class_ID (CLASSID_GAME_OBJECTS); - break; - - case TYPE_ZONE: - new_param = W3DNEW ZoneParameterClass ((OBBoxClass *)data); - new_param->Set_Name (name); - break; - - case TYPE_FILENAMELIST: - new_param = W3DNEW FilenameListParameterClass ((DynamicVectorClass *)data); - new_param->Set_Name (name); - break; - - case TYPE_SEPARATOR: - new_param = W3DNEW SeparatorParameterClass; - new_param->Set_Name (name); - break; - } - - return new_param; -} - -//*******************************************************************************************// -// -// Start of StringParameterClass -// -//*******************************************************************************************// - -///////////////////////////////////////////////////////////////////// -// -// StringParameterClass -// -///////////////////////////////////////////////////////////////////// -StringParameterClass::StringParameterClass (StringClass *string) - : m_String (string) -{ - return ; -} - -///////////////////////////////////////////////////////////////////// -// -// StringParameterClass -// -///////////////////////////////////////////////////////////////////// -StringParameterClass::StringParameterClass (const StringParameterClass &src) - : m_String (NULL) -{ - (*this) = src; - return ; -} - - -///////////////////////////////////////////////////////////////////// -// -// operator= -// -///////////////////////////////////////////////////////////////////// -const StringParameterClass & -StringParameterClass::operator= (const StringParameterClass &src) -{ - m_String = src.m_String; - ParameterClass::operator= (src); - return *this; -} - - -///////////////////////////////////////////////////////////////////// -// -// operator== -// -///////////////////////////////////////////////////////////////////// -bool -StringParameterClass::operator== (const StringParameterClass &src) -{ - bool retval = false; - - if (m_String != NULL && src.m_String != NULL && - (m_String->Compare (*(src.m_String)) == 0)) { - retval = true; - } - - return retval; -} - - -///////////////////////////////////////////////////////////////////// -// -// operator== -// -///////////////////////////////////////////////////////////////////// -bool -StringParameterClass::operator== (const ParameterClass &src) -{ - bool retval = false; - - if (src.Get_Type () == Get_Type ()) { - retval = StringParameterClass::operator== ((const StringParameterClass &)src); - } - - return retval; -} - - -///////////////////////////////////////////////////////////////////// -// -// Copy_Value -// -///////////////////////////////////////////////////////////////////// -void -StringParameterClass::Copy_Value (const ParameterClass &src) -{ - if (src.Is_Type (ParameterClass::TYPE_STRING)) { - (*m_String) = ((StringParameterClass &)src).Get_String (); - } - - ParameterClass::Copy_Value (src); - return ; -} - - -///////////////////////////////////////////////////////////////////// -// -// Get_String -// -///////////////////////////////////////////////////////////////////// -const char * -StringParameterClass::Get_String (void) const -{ - const char * string = NULL; - if (m_String != NULL) { - string = (*m_String); - } - return string; -} - - -///////////////////////////////////////////////////////////////////// -// -// Set_String -// -///////////////////////////////////////////////////////////////////// -void -StringParameterClass::Set_String (const char * string) -{ - if (m_String != NULL) { - Set_Modified (); - (*m_String) = string; - } - - return ; -} - - -//*******************************************************************************************// -// -// Start of FilenameParameterClass -// -//*******************************************************************************************// - - -///////////////////////////////////////////////////////////////////// -// -// FilenameParameterClass -// -///////////////////////////////////////////////////////////////////// -FilenameParameterClass::FilenameParameterClass (StringClass *string) - : StringParameterClass (string) -{ - return ; -} - - -///////////////////////////////////////////////////////////////////// -// -// FilenameParameterClass -// -///////////////////////////////////////////////////////////////////// -FilenameParameterClass::FilenameParameterClass (const FilenameParameterClass &src) - : StringParameterClass (src) -{ - (*this) = src; - return ; -} - - -///////////////////////////////////////////////////////////////////// -// -// operator= -// -///////////////////////////////////////////////////////////////////// -const FilenameParameterClass & -FilenameParameterClass::operator= (const FilenameParameterClass &src) -{ - StringParameterClass::operator= (src); - return *this; -} - - -///////////////////////////////////////////////////////////////////// -// -// operator== -// -///////////////////////////////////////////////////////////////////// -bool -FilenameParameterClass::operator== (const FilenameParameterClass &src) -{ - return StringParameterClass::operator== (src); -} - - -///////////////////////////////////////////////////////////////////// -// -// operator== -// -///////////////////////////////////////////////////////////////////// -bool -FilenameParameterClass::operator== (const ParameterClass &src) -{ - return StringParameterClass::operator== (src); -} - - -///////////////////////////////////////////////////////////////////// -// -// Copy_Value -// -///////////////////////////////////////////////////////////////////// -void -FilenameParameterClass::Copy_Value (const ParameterClass &src) -{ - if (src.Is_Type (ParameterClass::TYPE_FILENAME)) { - Set_String (((FilenameParameterClass &)src).Get_String ()); - } - - StringParameterClass::Copy_Value (src); - return ; -} - -//*******************************************************************************************// -// -// Start of TextureFilenameParameterClass -// -//*******************************************************************************************// - - -///////////////////////////////////////////////////////////////////// -// -// TextureFilenameParameterClass -// -///////////////////////////////////////////////////////////////////// -TextureFilenameParameterClass::TextureFilenameParameterClass (StringClass *string) -: FilenameParameterClass (string), - Show_Alpha(false), - Show_Texture(false) -{ -} - - -///////////////////////////////////////////////////////////////////// -// -// TextureFilenameParameterClass -// -///////////////////////////////////////////////////////////////////// -TextureFilenameParameterClass::TextureFilenameParameterClass (const TextureFilenameParameterClass &src) -: FilenameParameterClass (src), - Show_Alpha(false), - Show_Texture(false) -{ -} - -///////////////////////////////////////////////////////////////////// -// -// Copy_Value -// -///////////////////////////////////////////////////////////////////// -void TextureFilenameParameterClass::Copy_Value (const ParameterClass &src) -{ - if (src.Is_Type (ParameterClass::TYPE_TEXTURE_FILENAME)) - { - Set_String (((FilenameParameterClass &)src).Get_String ()); - } - - StringParameterClass::Copy_Value (src); - return ; -} - - -//*******************************************************************************************// -// -// Start of SoundFilenameParameterClass -// -//*******************************************************************************************// - - -///////////////////////////////////////////////////////////////////// -// -// SoundFilenameParameterClass -// -///////////////////////////////////////////////////////////////////// -SoundFilenameParameterClass::SoundFilenameParameterClass (StringClass *string) - : FilenameParameterClass (string) -{ - return ; -} - - -///////////////////////////////////////////////////////////////////// -// -// SoundFilenameParameterClass -// -///////////////////////////////////////////////////////////////////// -SoundFilenameParameterClass::SoundFilenameParameterClass (const SoundFilenameParameterClass &src) - : FilenameParameterClass (src) -{ - (*this) = src; - return ; -} - - -///////////////////////////////////////////////////////////////////// -// -// operator= -// -///////////////////////////////////////////////////////////////////// -const SoundFilenameParameterClass & -SoundFilenameParameterClass::operator= (const SoundFilenameParameterClass &src) -{ - FilenameParameterClass::operator= (src); - return *this; -} - - -///////////////////////////////////////////////////////////////////// -// -// operator== -// -///////////////////////////////////////////////////////////////////// -bool -SoundFilenameParameterClass::operator== (const SoundFilenameParameterClass &src) -{ - return FilenameParameterClass::operator== (src); -} - - - -//*******************************************************************************************// -// -// Start of EnumParameterClass -// -//*******************************************************************************************// - - -///////////////////////////////////////////////////////////////////// -// -// EnumParameterClass -// -///////////////////////////////////////////////////////////////////// -EnumParameterClass::EnumParameterClass (int *value) - : m_Value (value) -{ - return ; -} - - -///////////////////////////////////////////////////////////////////// -// -// EnumParameterClass -// -///////////////////////////////////////////////////////////////////// -EnumParameterClass::EnumParameterClass (const EnumParameterClass &src) - : m_Value (NULL) -{ - (*this) = src; - return ; -} - - -///////////////////////////////////////////////////////////////////// -// -// operator= -// -///////////////////////////////////////////////////////////////////// -const EnumParameterClass & -EnumParameterClass::operator= (const EnumParameterClass &src) -{ - m_List.Delete_All (); - - m_Value = src.m_Value; - m_List = src.m_List; - ParameterClass::operator= (src); - return *this; -} - - -///////////////////////////////////////////////////////////////////// -// -// operator== -// -///////////////////////////////////////////////////////////////////// -bool -EnumParameterClass::operator== (const EnumParameterClass &src) -{ - bool retval = false; - - if (m_Value != NULL && src.m_Value != NULL && - (*m_Value) == (*src.m_Value)) - { - retval = true; - } - - return retval; -} - - -///////////////////////////////////////////////////////////////////// -// -// operator== -// -///////////////////////////////////////////////////////////////////// -bool -EnumParameterClass::operator== (const ParameterClass &src) -{ - bool retval = false; - - if (src.Get_Type () == Get_Type ()) { - retval = EnumParameterClass::operator== ((const EnumParameterClass &)src); - } - - return retval; -} - - -///////////////////////////////////////////////////////////////////// -// -// Copy_Value -// -///////////////////////////////////////////////////////////////////// -void -EnumParameterClass::Copy_Value (const ParameterClass &src) -{ - if (src.Is_Type (ParameterClass::TYPE_ENUM)) { - (*m_Value) = ((EnumParameterClass &)src).Get_Selected_Value (); - } - - ParameterClass::Copy_Value (src); - return ; -} - - -///////////////////////////////////////////////////////////////////// -// -// Add_Value -// -///////////////////////////////////////////////////////////////////// -void -EnumParameterClass::Add_Value (const char *display_name, int value) -{ - m_List.Add (ENUM_VALUE(display_name, value)); - return ; -} - - -///////////////////////////////////////////////////////////////////// -// -// Add_Value -// -///////////////////////////////////////////////////////////////////// -void __cdecl -EnumParameterClass::Add_Values (const char *first_name, int first_value, ...) -{ - m_List.Add (ENUM_VALUE(first_name, first_value)); - - va_list arg_list; - va_start (arg_list, first_value); - - // - // Add all the params on the stack (until we found - // the terminator) - // - bool more_params = true; - while (more_params) { - - // - // Get the string param - // - const char *name = va_arg (arg_list, const char *); - if (name == NULL) { - more_params = false; - } else { - - // - // Add the string/id pair to the enum list - // - int value = va_arg (arg_list, int); - m_List.Add (ENUM_VALUE(name, value)); - } - } - - va_end (arg_list); - return ; -} - - - -//*******************************************************************************************// -// -// Start of PhysDefParameterClass -// -//*******************************************************************************************// - - -///////////////////////////////////////////////////////////////////// -// -// PhysDefParameterClass -// -///////////////////////////////////////////////////////////////////// -PhysDefParameterClass::PhysDefParameterClass (int *id) - : m_Value (id) -{ - return ; -} - -///////////////////////////////////////////////////////////////////// -// -// PhysDefParameterClass -// -///////////////////////////////////////////////////////////////////// -PhysDefParameterClass::PhysDefParameterClass (const PhysDefParameterClass &src) - : m_Value (NULL) -{ - (*this) = src; - return ; -} - - -///////////////////////////////////////////////////////////////////// -// -// operator= -// -///////////////////////////////////////////////////////////////////// -const PhysDefParameterClass & -PhysDefParameterClass::operator= (const PhysDefParameterClass &src) -{ - m_Value = src.m_Value; - ParameterClass::operator= (src); - return *this; -} - - -///////////////////////////////////////////////////////////////////// -// -// operator== -// -///////////////////////////////////////////////////////////////////// -bool -PhysDefParameterClass::operator== (const PhysDefParameterClass &src) -{ - bool retval = false; - - if (m_Value != NULL && src.m_Value != NULL && - (*m_Value) == (*src.m_Value)) - { - retval = true; - } - - return retval; -} - - -///////////////////////////////////////////////////////////////////// -// -// operator== -// -///////////////////////////////////////////////////////////////////// -bool -PhysDefParameterClass::operator== (const ParameterClass &src) -{ - bool retval = false; - - if (src.Get_Type () == Get_Type ()) { - retval = PhysDefParameterClass::operator== ((const PhysDefParameterClass &)src); - } - - return retval; -} - - -///////////////////////////////////////////////////////////////////// -// -// Copy_Value -// -///////////////////////////////////////////////////////////////////// -void -PhysDefParameterClass::Copy_Value (const ParameterClass &/*src*/) -{ - // - // We don't allow the value to be copied - // - return ; -} - - -//*******************************************************************************************// -// -// Start of ModelDefParameterClass -// -//*******************************************************************************************// - - -///////////////////////////////////////////////////////////////////// -// -// ModelDefParameterClass -// -///////////////////////////////////////////////////////////////////// -ModelDefParameterClass::ModelDefParameterClass (int *id) - : m_Value (id) -{ - return ; -} - -///////////////////////////////////////////////////////////////////// -// -// ModelDefParameterClass -// -///////////////////////////////////////////////////////////////////// -ModelDefParameterClass::ModelDefParameterClass (const ModelDefParameterClass &src) - : m_Value (NULL) -{ - (*this) = src; - return ; -} - - -///////////////////////////////////////////////////////////////////// -// -// operator= -// -///////////////////////////////////////////////////////////////////// -const ModelDefParameterClass & -ModelDefParameterClass::operator= (const ModelDefParameterClass &src) -{ - m_Value = src.m_Value; - ParameterClass::operator= (src); - return *this; -} - - -///////////////////////////////////////////////////////////////////// -// -// operator== -// -///////////////////////////////////////////////////////////////////// -bool -ModelDefParameterClass::operator== (const ModelDefParameterClass &src) -{ - bool retval = false; - - if (m_Value != NULL && src.m_Value != NULL && - (*m_Value) == (*src.m_Value)) - { - retval = true; - } - - return retval; -} - - -///////////////////////////////////////////////////////////////////// -// -// operator== -// -///////////////////////////////////////////////////////////////////// -bool -ModelDefParameterClass::operator== (const ParameterClass &src) -{ - bool retval = false; - - if (src.Get_Type () == Get_Type ()) { - retval = ModelDefParameterClass::operator== ((const ModelDefParameterClass &)src); - } - - return retval; -} - - -///////////////////////////////////////////////////////////////////// -// -// Copy_Value -// -///////////////////////////////////////////////////////////////////// -void -ModelDefParameterClass::Copy_Value (const ParameterClass &/*src*/) -{ - // - // We don't allow the value to be copied - // - return ; -} - - -//*******************************************************************************************// -// -// Start of DefParameterClass -// -//*******************************************************************************************// - -///////////////////////////////////////////////////////////////////// -// -// DefParameterClass -// -///////////////////////////////////////////////////////////////////// -DefParameterClass::DefParameterClass (int *id) - : m_Value (id) -{ - return ; -} - - -///////////////////////////////////////////////////////////////////// -// -// DefParameterClass -// -///////////////////////////////////////////////////////////////////// -DefParameterClass::DefParameterClass (const DefParameterClass &src) - : m_Value (NULL) -{ - (*this) = src; - return ; -} - - -///////////////////////////////////////////////////////////////////// -// -// operator= -// -///////////////////////////////////////////////////////////////////// -const DefParameterClass & -DefParameterClass::operator= (const DefParameterClass &src) -{ - m_Value = src.m_Value; - ParameterClass::operator= (src); - return *this; -} - - -///////////////////////////////////////////////////////////////////// -// -// operator== -// -///////////////////////////////////////////////////////////////////// -bool -DefParameterClass::operator== (const DefParameterClass &src) -{ - bool retval = false; - - if (m_Value != NULL && src.m_Value != NULL && - (*m_Value) == (*src.m_Value)) - { - retval = true; - } - - return retval; -} - - -///////////////////////////////////////////////////////////////////// -// -// operator== -// -///////////////////////////////////////////////////////////////////// -bool -DefParameterClass::operator== (const ParameterClass &src) -{ - bool retval = false; - - if (src.Get_Type () == Get_Type ()) { - retval = DefParameterClass::operator== ((const DefParameterClass &)src); - } - - return retval; -} - - -///////////////////////////////////////////////////////////////////// -// -// Copy_Value -// -///////////////////////////////////////////////////////////////////// -void -DefParameterClass::Copy_Value (const ParameterClass &src) -{ - if (src.Get_Type () == Get_Type ()) { - (*m_Value) = ((DefParameterClass &)src).Get_Value (); - } - - ParameterClass::Copy_Value (src); - return ; -} - - - -//*******************************************************************************************// -// -// Start of GenericDefParameterClass -// -//*******************************************************************************************// - - -///////////////////////////////////////////////////////////////////// -// -// GenericDefParameterClass -// -///////////////////////////////////////////////////////////////////// -GenericDefParameterClass::GenericDefParameterClass (int *id) - : m_ClassID (0), - DefParameterClass (id) -{ - return ; -} - - -///////////////////////////////////////////////////////////////////// -// -// GenericDefParameterClass -// -///////////////////////////////////////////////////////////////////// -GenericDefParameterClass::GenericDefParameterClass (const GenericDefParameterClass &src) - : m_ClassID (0), - DefParameterClass (src) -{ - (*this) = src; - return ; -} - - -///////////////////////////////////////////////////////////////////// -// -// operator= -// -///////////////////////////////////////////////////////////////////// -const GenericDefParameterClass & -GenericDefParameterClass::operator= (const GenericDefParameterClass &src) -{ - DefParameterClass::operator= (src); - return *this; -} - - -///////////////////////////////////////////////////////////////////// -// -// operator== -// -///////////////////////////////////////////////////////////////////// -bool -GenericDefParameterClass::operator== (const GenericDefParameterClass &src) -{ - bool retval = false; - - if (m_Value != NULL && src.m_Value != NULL && - (*m_Value) == (*src.m_Value)) - { - retval = true; - } - - return retval; -} - - -///////////////////////////////////////////////////////////////////// -// -// operator== -// -///////////////////////////////////////////////////////////////////// -bool -GenericDefParameterClass::operator== (const ParameterClass &src) -{ - bool retval = false; - - if (src.Get_Type () == Get_Type ()) { - retval = GenericDefParameterClass::operator== ((const GenericDefParameterClass &)src); - } - - return retval; -} - - -///////////////////////////////////////////////////////////////////// -// -// Copy_Value -// -///////////////////////////////////////////////////////////////////// -void -GenericDefParameterClass::Copy_Value (const ParameterClass &src) -{ - if (src.Is_Type (ParameterClass::TYPE_GENERICDEFINITIONID)) { - (*m_Value) = ((GenericDefParameterClass &)src).Get_Value (); - } - - ParameterClass::Copy_Value (src); - return ; -} - - -//*******************************************************************************************// -// -// Start of GameObjDefParameterClass -// -//*******************************************************************************************// - - -///////////////////////////////////////////////////////////////////// -// -// GameObjDefParameterClass -// -///////////////////////////////////////////////////////////////////// -GameObjDefParameterClass::GameObjDefParameterClass (int *id) - : DefParameterClass (id) -{ - return ; -} - - -///////////////////////////////////////////////////////////////////// -// -// GameObjDefParameterClass -// -///////////////////////////////////////////////////////////////////// -GameObjDefParameterClass::GameObjDefParameterClass (const GameObjDefParameterClass &src) - : DefParameterClass (src) -{ - (*this) = src; - return ; -} - - -///////////////////////////////////////////////////////////////////// -// -// operator= -// -///////////////////////////////////////////////////////////////////// -const GameObjDefParameterClass & -GameObjDefParameterClass::operator= (const GameObjDefParameterClass &src) -{ - DefParameterClass::operator= (src); - return *this; -} - - -///////////////////////////////////////////////////////////////////// -// -// operator== -// -///////////////////////////////////////////////////////////////////// -bool -GameObjDefParameterClass::operator== (const GameObjDefParameterClass &src) -{ - bool retval = false; - - if (m_Value != NULL && src.m_Value != NULL && - (*m_Value) == (*src.m_Value)) - { - retval = true; - } - - return retval; -} - - -///////////////////////////////////////////////////////////////////// -// -// operator== -// -///////////////////////////////////////////////////////////////////// -bool -GameObjDefParameterClass::operator== (const ParameterClass &src) -{ - bool retval = false; - - if (src.Get_Type () == Get_Type ()) { - retval = GameObjDefParameterClass::operator== ((const GameObjDefParameterClass &)src); - } - - return retval; -} - - -///////////////////////////////////////////////////////////////////// -// -// Copy_Value -// -///////////////////////////////////////////////////////////////////// -void -GameObjDefParameterClass::Copy_Value (const ParameterClass &src) -{ - if (src.Is_Type (ParameterClass::TYPE_GAMEOBJDEFINITIONID)) { - (*m_Value) = ((GameObjDefParameterClass &)src).Get_Value (); - } - - ParameterClass::Copy_Value (src); - return ; -} - - -//*******************************************************************************************// -// -// Start of WeaponObjDefParameterClass -// -//*******************************************************************************************// - - -///////////////////////////////////////////////////////////////////// -// -// WeaponObjDefParameterClass -// -///////////////////////////////////////////////////////////////////// -WeaponObjDefParameterClass::WeaponObjDefParameterClass (int *id) - : GameObjDefParameterClass (id) -{ - return ; -} - - -///////////////////////////////////////////////////////////////////// -// -// WeaponObjDefParameterClass -// -///////////////////////////////////////////////////////////////////// -WeaponObjDefParameterClass::WeaponObjDefParameterClass (const WeaponObjDefParameterClass &src) - : GameObjDefParameterClass (NULL) -{ - (*this) = src; - return ; -} - - -///////////////////////////////////////////////////////////////////// -// -// operator= -// -///////////////////////////////////////////////////////////////////// -const WeaponObjDefParameterClass & -WeaponObjDefParameterClass::operator= (const WeaponObjDefParameterClass &src) -{ - m_Value = src.m_Value; - ParameterClass::operator= (src); - return *this; -} - - -///////////////////////////////////////////////////////////////////// -// -// operator== -// -///////////////////////////////////////////////////////////////////// -bool -WeaponObjDefParameterClass::operator== (const WeaponObjDefParameterClass &src) -{ - bool retval = false; - - if (m_Value != NULL && src.m_Value != NULL && - (*m_Value) == (*src.m_Value)) - { - retval = true; - } - - return retval; -} - - -///////////////////////////////////////////////////////////////////// -// -// operator== -// -///////////////////////////////////////////////////////////////////// -bool -WeaponObjDefParameterClass::operator== (const ParameterClass &src) -{ - bool retval = false; - - if (src.Get_Type () == Get_Type ()) { - retval = WeaponObjDefParameterClass::operator== ((const WeaponObjDefParameterClass &)src); - } - - return retval; -} - - -///////////////////////////////////////////////////////////////////// -// -// Copy_Value -// -///////////////////////////////////////////////////////////////////// -void -WeaponObjDefParameterClass::Copy_Value (const ParameterClass &src) -{ - if (src.Is_Type (ParameterClass::TYPE_WEAPONOBJDEFINITIONID)) { - (*m_Value) = ((WeaponObjDefParameterClass &)src).Get_Value (); - } - - GameObjDefParameterClass::Copy_Value (src); - return ; -} - - -//*******************************************************************************************// -// -// Start of AmmoObjDefParameterClass -// -//*******************************************************************************************// - - -///////////////////////////////////////////////////////////////////// -// -// AmmoObjDefParameterClass -// -///////////////////////////////////////////////////////////////////// -AmmoObjDefParameterClass::AmmoObjDefParameterClass (int *id) - : GameObjDefParameterClass (id) -{ - return ; -} - - -///////////////////////////////////////////////////////////////////// -// -// AmmoObjDefParameterClass -// -///////////////////////////////////////////////////////////////////// -AmmoObjDefParameterClass::AmmoObjDefParameterClass (const AmmoObjDefParameterClass &src) - : GameObjDefParameterClass (NULL) -{ - (*this) = src; - return ; -} - - -///////////////////////////////////////////////////////////////////// -// -// operator= -// -///////////////////////////////////////////////////////////////////// -const AmmoObjDefParameterClass & -AmmoObjDefParameterClass::operator= (const AmmoObjDefParameterClass &src) -{ - m_Value = src.m_Value; - ParameterClass::operator= (src); - return *this; -} - - -///////////////////////////////////////////////////////////////////// -// -// operator== -// -///////////////////////////////////////////////////////////////////// -bool -AmmoObjDefParameterClass::operator== (const AmmoObjDefParameterClass &src) -{ - bool retval = false; - - if (m_Value != NULL && src.m_Value != NULL && - (*m_Value) == (*src.m_Value)) - { - retval = true; - } - - return retval; -} - - -///////////////////////////////////////////////////////////////////// -// -// operator== -// -///////////////////////////////////////////////////////////////////// -bool -AmmoObjDefParameterClass::operator== (const ParameterClass &src) -{ - bool retval = false; - - if (src.Get_Type () == Get_Type ()) { - retval = AmmoObjDefParameterClass::operator== ((const AmmoObjDefParameterClass &)src); - } - - return retval; -} - - -///////////////////////////////////////////////////////////////////// -// -// Copy_Value -// -///////////////////////////////////////////////////////////////////// -void -AmmoObjDefParameterClass::Copy_Value (const ParameterClass &src) -{ - if (src.Is_Type (ParameterClass::TYPE_AMMOOBJDEFINITIONID)) { - (*m_Value) = ((AmmoObjDefParameterClass &)src).Get_Value (); - } - - GameObjDefParameterClass::Copy_Value (src); - return ; -} - - -//*******************************************************************************************// -// -// Start of ExplosionObjDefParameterClass -// -//*******************************************************************************************// - - -///////////////////////////////////////////////////////////////////// -// -// ExplosionObjDefParameterClass -// -///////////////////////////////////////////////////////////////////// -ExplosionObjDefParameterClass::ExplosionObjDefParameterClass (int *id) - : GameObjDefParameterClass (id) -{ - return ; -} - - -///////////////////////////////////////////////////////////////////// -// -// ExplosionObjDefParameterClass -// -///////////////////////////////////////////////////////////////////// -ExplosionObjDefParameterClass::ExplosionObjDefParameterClass (const ExplosionObjDefParameterClass &src) - : GameObjDefParameterClass (NULL) -{ - (*this) = src; - return ; -} - - -///////////////////////////////////////////////////////////////////// -// -// operator= -// -///////////////////////////////////////////////////////////////////// -const ExplosionObjDefParameterClass & -ExplosionObjDefParameterClass::operator= (const ExplosionObjDefParameterClass &src) -{ - m_Value = src.m_Value; - ParameterClass::operator= (src); - return *this; -} - - -///////////////////////////////////////////////////////////////////// -// -// operator== -// -///////////////////////////////////////////////////////////////////// -bool -ExplosionObjDefParameterClass::operator== (const ExplosionObjDefParameterClass &src) -{ - bool retval = false; - - if (m_Value != NULL && src.m_Value != NULL && - (*m_Value) == (*src.m_Value)) - { - retval = true; - } - - return retval; -} - - -///////////////////////////////////////////////////////////////////// -// -// operator== -// -///////////////////////////////////////////////////////////////////// -bool -ExplosionObjDefParameterClass::operator== (const ParameterClass &src) -{ - bool retval = false; - - if (src.Get_Type () == Get_Type ()) { - retval = ExplosionObjDefParameterClass::operator== ((const ExplosionObjDefParameterClass &)src); - } - - return retval; -} - - -///////////////////////////////////////////////////////////////////// -// -// Copy_Value -// -///////////////////////////////////////////////////////////////////// -void -ExplosionObjDefParameterClass::Copy_Value (const ParameterClass &src) -{ - if (src.Is_Type (ParameterClass::TYPE_AMMOOBJDEFINITIONID)) { - (*m_Value) = ((ExplosionObjDefParameterClass &)src).Get_Value (); - } - - GameObjDefParameterClass::Copy_Value (src); - return ; -} - - -//*******************************************************************************************// -// -// Start of SoundDefParameterClass -// -//*******************************************************************************************// - - -///////////////////////////////////////////////////////////////////// -// -// SoundDefParameterClass -// -///////////////////////////////////////////////////////////////////// -SoundDefParameterClass::SoundDefParameterClass (int *id) - : DefParameterClass (id) -{ - return ; -} - -///////////////////////////////////////////////////////////////////// -// -// SoundDefParameterClass -// -///////////////////////////////////////////////////////////////////// -SoundDefParameterClass::SoundDefParameterClass (const SoundDefParameterClass &src) - : DefParameterClass (src) -{ - (*this) = src; - return ; -} - - -///////////////////////////////////////////////////////////////////// -// -// operator= -// -///////////////////////////////////////////////////////////////////// -const SoundDefParameterClass & -SoundDefParameterClass::operator= (const SoundDefParameterClass &src) -{ - DefParameterClass::operator= (src); - return *this; -} - - -///////////////////////////////////////////////////////////////////// -// -// operator== -// -///////////////////////////////////////////////////////////////////// -bool -SoundDefParameterClass::operator== (const SoundDefParameterClass &src) -{ - bool retval = false; - - if (m_Value != NULL && src.m_Value != NULL && - (*m_Value) == (*src.m_Value)) - { - retval = true; - } - - return retval; -} - - -///////////////////////////////////////////////////////////////////// -// -// operator== -// -///////////////////////////////////////////////////////////////////// -bool -SoundDefParameterClass::operator== (const ParameterClass &src) -{ - bool retval = false; - - if (src.Get_Type () == Get_Type ()) { - retval = SoundDefParameterClass::operator== ((const SoundDefParameterClass &)src); - } - - return retval; -} - - -//*******************************************************************************************// -// -// Start of ScriptParameterClass -// -//*******************************************************************************************// - - -///////////////////////////////////////////////////////////////////// -// -// ScriptParameterClass -// -///////////////////////////////////////////////////////////////////// -ScriptParameterClass::ScriptParameterClass (StringClass *name, StringClass *params) - : m_ScriptName (name), - m_ScriptParams (params) -{ - return ; -} - -///////////////////////////////////////////////////////////////////// -// -// ScriptParameterClass -// -///////////////////////////////////////////////////////////////////// -ScriptParameterClass::ScriptParameterClass (const ScriptParameterClass &src) - : m_ScriptName (NULL), - m_ScriptParams (NULL) -{ - (*this) = src; - return ; -} - - -///////////////////////////////////////////////////////////////////// -// -// operator= -// -///////////////////////////////////////////////////////////////////// -const ScriptParameterClass & -ScriptParameterClass::operator= (const ScriptParameterClass &src) -{ - m_ScriptName = src.m_ScriptName; - m_ScriptParams = src.m_ScriptParams; - ParameterClass::operator= (src); - return *this; -} - - -///////////////////////////////////////////////////////////////////// -// -// operator== -// -///////////////////////////////////////////////////////////////////// -bool -ScriptParameterClass::operator== (const ScriptParameterClass &src) -{ - bool retval = false; - - // - // Data valid? - // - if ( (m_ScriptName != NULL) && (src.m_ScriptName != NULL) && - (m_ScriptParams != NULL) && (src.m_ScriptParams != NULL)) - { - - // - // Simple string compares should workd - // - if ( (m_ScriptName->Compare (*(src.m_ScriptName)) == 0) && - (m_ScriptParams->Compare (*(src.m_ScriptParams)) == 0)) - { - retval = true; - } - } - - return retval; -} - - -///////////////////////////////////////////////////////////////////// -// -// operator== -// -///////////////////////////////////////////////////////////////////// -bool -ScriptParameterClass::operator== (const ParameterClass &src) -{ - bool retval = false; - - if (src.Get_Type () == Get_Type ()) { - retval = ScriptParameterClass::operator== ((const ScriptParameterClass &)src); - } - - return retval; -} - - -///////////////////////////////////////////////////////////////////// -// -// Copy_Value -// -///////////////////////////////////////////////////////////////////// -void -ScriptParameterClass::Copy_Value (const ParameterClass &src) -{ - if (src.Is_Type (ParameterClass::TYPE_SCRIPT)) { - (*m_ScriptName) = ((ScriptParameterClass &)src).Get_Script_Name (); - (*m_ScriptParams) = ((ScriptParameterClass &)src).Get_Params (); - } - - ParameterClass::Copy_Value (src); - return ; -} - - -//*******************************************************************************************// -// -// Start of DefIDListParameterClass -// -//*******************************************************************************************// - - -///////////////////////////////////////////////////////////////////// -// -// DefIDListParameterClass -// -///////////////////////////////////////////////////////////////////// -DefIDListParameterClass::DefIDListParameterClass (DynamicVectorClass *list) - : m_IDList (list), - m_ClassID (0), - m_SelectedClassID (NULL) -{ - return ; -} - - -///////////////////////////////////////////////////////////////////// -// -// DefIDListParameterClass -// -///////////////////////////////////////////////////////////////////// -DefIDListParameterClass::DefIDListParameterClass (const DefIDListParameterClass &src) - : m_IDList (NULL), - m_ClassID (0), - m_SelectedClassID (NULL) -{ - (*this) = src; - return ; -} - - -///////////////////////////////////////////////////////////////////// -// -// operator= -// -///////////////////////////////////////////////////////////////////// -const DefIDListParameterClass & -DefIDListParameterClass::operator= (const DefIDListParameterClass &src) -{ - m_IDList = src.m_IDList; - m_ClassID = src.m_ClassID; - m_SelectedClassID = src.m_SelectedClassID; - - ParameterClass::operator= (src); - return *this; -} - - -///////////////////////////////////////////////////////////////////// -// -// operator== -// -///////////////////////////////////////////////////////////////////// -bool -DefIDListParameterClass::operator== (const DefIDListParameterClass &src) -{ - bool retval = false; - - // - // Data valid? - // - if ((m_IDList != NULL) && (src.m_IDList != NULL)) - { - // - // Class IDs the same? - // - if (m_ClassID == src.m_ClassID) { - - int count1 = m_IDList->Count (); - int count2 = src.m_IDList->Count (); - - // - // Are the lists the same? - // - retval = (count1 == count2); - for (int index = 0; (index < count1) && retval; index ++) { - int value1 = (*m_IDList)[index]; - int value2 = (*src.m_IDList)[index]; - retval &= (value1 == value2); - } - } - } - - return retval; -} - - -///////////////////////////////////////////////////////////////////// -// -// operator== -// -///////////////////////////////////////////////////////////////////// -bool -DefIDListParameterClass::operator== (const ParameterClass &src) -{ - bool retval = false; - - if (src.Get_Type () == Get_Type ()) { - retval = DefIDListParameterClass::operator== ((const DefIDListParameterClass &)src); - } - - return retval; -} - - -///////////////////////////////////////////////////////////////////// -// -// Copy_Value -// -///////////////////////////////////////////////////////////////////// -void -DefIDListParameterClass::Copy_Value (const ParameterClass &src) -{ - if (src.Is_Type (ParameterClass::TYPE_DEFINITIONIDLIST)) { - DefIDListParameterClass real_src = (DefIDListParameterClass &)src; - - m_ClassID = real_src.m_ClassID; - (*m_IDList) = (*real_src.m_IDList); - - if (m_SelectedClassID != NULL && real_src.m_SelectedClassID != NULL) { - (*m_SelectedClassID) = (*real_src.m_SelectedClassID); - } - } - - ParameterClass::Copy_Value (src); - return ; -} - - -//*******************************************************************************************// -// -// Start of ZoneParameterClass -// -//*******************************************************************************************// - - -///////////////////////////////////////////////////////////////////// -// -// ZoneParameterClass -// -///////////////////////////////////////////////////////////////////// -ZoneParameterClass::ZoneParameterClass (OBBoxClass *box) - : m_OBBox (box) -{ - return ; -} - - -///////////////////////////////////////////////////////////////////// -// -// ZoneParameterClass -// -///////////////////////////////////////////////////////////////////// -ZoneParameterClass::ZoneParameterClass (const ZoneParameterClass &src) - : m_OBBox (NULL) -{ - (*this) = src; - return ; -} - - -///////////////////////////////////////////////////////////////////// -// -// operator= -// -///////////////////////////////////////////////////////////////////// -const ZoneParameterClass & -ZoneParameterClass::operator= (const ZoneParameterClass &src) -{ - m_OBBox = src.m_OBBox; - - ParameterClass::operator= (src); - return *this; -} - - -///////////////////////////////////////////////////////////////////// -// -// operator== -// -///////////////////////////////////////////////////////////////////// -bool -ZoneParameterClass::operator== (const ZoneParameterClass &src) -{ - bool retval = false; - - // - // Are the OBBoxes the same? - // - if ((m_OBBox != NULL) && (src.m_OBBox != NULL)) { - retval = (*m_OBBox) == (*src.m_OBBox); - } - - return retval; -} - - -///////////////////////////////////////////////////////////////////// -// -// operator== -// -///////////////////////////////////////////////////////////////////// -bool -ZoneParameterClass::operator== (const ParameterClass &src) -{ - bool retval = false; - - if (src.Get_Type () == Get_Type ()) { - retval = ZoneParameterClass::operator== ((const ZoneParameterClass &)src); - } - - return retval; -} - - -///////////////////////////////////////////////////////////////////// -// -// Copy_Value -// -///////////////////////////////////////////////////////////////////// -void -ZoneParameterClass::Copy_Value (const ParameterClass &src) -{ - if (src.Is_Type (ParameterClass::TYPE_ZONE)) { - ZoneParameterClass real_src = (ZoneParameterClass &)src; - - (*m_OBBox) = (*real_src.m_OBBox); - } - - ParameterClass::Copy_Value (src); - return ; -} - - -//*******************************************************************************************// -// -// Start of FilenameListParameterClass -// -//*******************************************************************************************// - - -///////////////////////////////////////////////////////////////////// -// -// FilenameListParameterClass -// -///////////////////////////////////////////////////////////////////// -FilenameListParameterClass::FilenameListParameterClass (DynamicVectorClass *list) - : m_FilenameList (list) -{ - return ; -} - - -///////////////////////////////////////////////////////////////////// -// -// FilenameListParameterClass -// -///////////////////////////////////////////////////////////////////// -FilenameListParameterClass::FilenameListParameterClass (const FilenameListParameterClass &src) - : m_FilenameList (NULL) -{ - (*this) = src; - return ; -} - - -///////////////////////////////////////////////////////////////////// -// -// operator= -// -///////////////////////////////////////////////////////////////////// -const FilenameListParameterClass & -FilenameListParameterClass::operator= (const FilenameListParameterClass &src) -{ - m_FilenameList = src.m_FilenameList; - - ParameterClass::operator= (src); - return *this; -} - - -///////////////////////////////////////////////////////////////////// -// -// operator== -// -///////////////////////////////////////////////////////////////////// -bool -FilenameListParameterClass::operator== (const FilenameListParameterClass &src) -{ - bool retval = false; - - // - // Data valid? - // - if ((m_FilenameList != NULL) && (src.m_FilenameList != NULL)) - { - int count1 = m_FilenameList->Count (); - int count2 = src.m_FilenameList->Count (); - - // - // Are the lists the same? - // - retval = (count1 == count2); - for (int index = 0; (index < count1) && retval; index ++) { - StringClass &filename1 = (*m_FilenameList)[index]; - StringClass &filename2 = (*src.m_FilenameList)[index]; - retval &= (::stricmp (filename1, filename2) == 0); - } - } - - return retval; -} - - -///////////////////////////////////////////////////////////////////// -// -// operator== -// -///////////////////////////////////////////////////////////////////// -bool -FilenameListParameterClass::operator== (const ParameterClass &src) -{ - bool retval = false; - - if (src.Get_Type () == Get_Type ()) { - retval = FilenameListParameterClass::operator== ((const FilenameListParameterClass &)src); - } - - return retval; -} - - -///////////////////////////////////////////////////////////////////// -// -// Copy_Value -// -///////////////////////////////////////////////////////////////////// -void -FilenameListParameterClass::Copy_Value (const ParameterClass &src) -{ - if (src.Is_Type (ParameterClass::TYPE_FILENAMELIST)) { - FilenameListParameterClass real_src = (FilenameListParameterClass &)src; - (*m_FilenameList) = (*real_src.m_FilenameList); - } - - ParameterClass::Copy_Value (src); - return ; -} - - -//*******************************************************************************************// -// -// Start of ScriptListParameterClass -// -//*******************************************************************************************// - - -///////////////////////////////////////////////////////////////////// -// -// ScriptListParameterClass -// -///////////////////////////////////////////////////////////////////// -ScriptListParameterClass::ScriptListParameterClass -( - DynamicVectorClass *name_list, - DynamicVectorClass *param_list -) - : m_NameList (name_list), - m_ParamList (param_list) -{ - return ; -} - - -///////////////////////////////////////////////////////////////////// -// -// ScriptListParameterClass -// -///////////////////////////////////////////////////////////////////// -ScriptListParameterClass::ScriptListParameterClass (const ScriptListParameterClass &src) - : m_NameList (NULL), - m_ParamList (NULL) -{ - (*this) = src; - return ; -} - - -///////////////////////////////////////////////////////////////////// -// -// operator= -// -///////////////////////////////////////////////////////////////////// -const ScriptListParameterClass & -ScriptListParameterClass::operator= (const ScriptListParameterClass &src) -{ - m_NameList = src.m_NameList; - m_ParamList = src.m_ParamList; - - ParameterClass::operator= (src); - return *this; -} - - -///////////////////////////////////////////////////////////////////// -// -// operator== -// -///////////////////////////////////////////////////////////////////// -bool -ScriptListParameterClass::operator== (const ScriptListParameterClass &src) -{ - bool retval = false; - - // - // Data valid? - // - if ( (m_NameList != NULL) && (src.m_NameList != NULL) && - (m_ParamList != NULL) && (src.m_ParamList != NULL)) - { - retval = Are_Lists_Identical (*m_NameList, *(src.m_NameList)); - retval &= Are_Lists_Identical (*m_ParamList, *(src.m_ParamList)); - } - - return retval; -} - - -///////////////////////////////////////////////////////////////////// -// -// Are_Lists_Identical -// -///////////////////////////////////////////////////////////////////// -bool -ScriptListParameterClass::Are_Lists_Identical -( - DynamicVectorClass &list1, - DynamicVectorClass &list2 -) -{ - int count1 = list1.Count (); - int count2 = list2.Count (); - - // - // Do a string compare on every entry - // - bool retval = (count1 == count2); - for (int index = 0; (index < count1) && retval; index ++) { - StringClass &string1 = list1[index]; - StringClass &string2 = list2[index]; - retval &= (::stricmp (string1, string2) == 0); - } - - return retval; -} - - -///////////////////////////////////////////////////////////////////// -// -// operator== -// -///////////////////////////////////////////////////////////////////// -bool -ScriptListParameterClass::operator== (const ParameterClass &src) -{ - bool retval = false; - - if (src.Get_Type () == Get_Type ()) { - retval = ScriptListParameterClass::operator== ((const ScriptListParameterClass &)src); - } - - return retval; -} - - -///////////////////////////////////////////////////////////////////// -// -// Copy_Value -// -///////////////////////////////////////////////////////////////////// -void -ScriptListParameterClass::Copy_Value (const ParameterClass &src) -{ - if (src.Is_Type (ParameterClass::TYPE_SCRIPTLIST)) { - ScriptListParameterClass &real_src = (ScriptListParameterClass &)src; - (*m_NameList) = (*real_src.m_NameList); - (*m_ParamList) = (*real_src.m_ParamList); - } - - ParameterClass::Copy_Value (src); - return ; -} - - -//*******************************************************************************************// -// -// Start of SeparatorParameterClass -// -//*******************************************************************************************// - - -///////////////////////////////////////////////////////////////////// -// -// SeparatorParameterClass -// -///////////////////////////////////////////////////////////////////// -SeparatorParameterClass::SeparatorParameterClass (const SeparatorParameterClass &src) -{ - (*this) = src; - return ; -} - - -///////////////////////////////////////////////////////////////////// -// -// operator= -// -///////////////////////////////////////////////////////////////////// -const SeparatorParameterClass & -SeparatorParameterClass::operator= (const SeparatorParameterClass &src) -{ - ParameterClass::operator= (src); - return *this; -} - - -///////////////////////////////////////////////////////////////////// -// -// operator== -// -///////////////////////////////////////////////////////////////////// -bool -SeparatorParameterClass::operator== (const SeparatorParameterClass &src) -{ - return true; -} - - -///////////////////////////////////////////////////////////////////// -// -// operator== -// -///////////////////////////////////////////////////////////////////// -bool -SeparatorParameterClass::operator== (const ParameterClass &src) -{ - bool retval = false; - - if (src.Get_Type () == Get_Type ()) { - retval = SeparatorParameterClass::operator== ((const SeparatorParameterClass &)src); - } - - return retval; -} - - -///////////////////////////////////////////////////////////////////// -// -// Copy_Value -// -///////////////////////////////////////////////////////////////////// -void -SeparatorParameterClass::Copy_Value (const ParameterClass &src) -{ - ParameterClass::Copy_Value (src); - return ; -} diff --git a/Generals/Code/Libraries/Source/WWVegas/WWSaveLoad/parameter.h b/Generals/Code/Libraries/Source/WWVegas/WWSaveLoad/parameter.h deleted file mode 100644 index da9780e6a47..00000000000 --- a/Generals/Code/Libraries/Source/WWVegas/WWSaveLoad/parameter.h +++ /dev/null @@ -1,1161 +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 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 : WWSaveLoad * - * * - * $Archive:: /Commando/Code/wwsaveload/parameter.h $* - * * - * Org Author:: Patrick Smith * - * * - * Author:: Kenny Mitchell * - * * - * $Modtime:: 5/29/02 11:00a $* - * * - * $Revision:: 38 $* - * * - *---------------------------------------------------------------------------------------------* - * Functions: * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - - -#if defined(_MSC_VER) -#pragma once -#endif - -#ifndef __PARAMETER_H -#define __PARAMETER_H - -#include "always.h" -#include -#include -#include "parametertypes.h" -#include "Vector.H" -#include "wwstring.h" -#include "bittype.h" -#include "obbox.h" - - -////////////////////////////////////////////////////////////////////////////////// -// Forward declarations -////////////////////////////////////////////////////////////////////////////////// -class DefParameterClass; - - -////////////////////////////////////////////////////////////////////////////////// -// -// ParameterClass -// -////////////////////////////////////////////////////////////////////////////////// -class ParameterClass -{ -public: - - typedef enum - { - TYPE_INT = 0, - TYPE_FLOAT, - TYPE_STRING, - TYPE_VECTOR3, - TYPE_MATRIX3D, - TYPE_BOOL, - TYPE_TRANSITION, - TYPE_MODELDEFINITIONID, - TYPE_FILENAME, - TYPE_ENUM, - TYPE_GAMEOBJDEFINITIONID, - TYPE_SCRIPT, - TYPE_SOUND_FILENAME, - TYPE_ANGLE, - TYPE_WEAPONOBJDEFINITIONID, - TYPE_AMMOOBJDEFINITIONID, - TYPE_SOUNDDEFINITIONID, - TYPE_COLOR, - TYPE_PHYSDEFINITIONID, - TYPE_EXPLOSIONDEFINITIONID, - TYPE_DEFINITIONIDLIST, - TYPE_ZONE, - TYPE_FILENAMELIST, - TYPE_SEPARATOR, - TYPE_GENERICDEFINITIONID, - TYPE_SCRIPTLIST, - TYPE_VECTOR2, - TYPE_RECT, - TYPE_TEXTURE_FILENAME, - TYPE_STRINGSDB_ID - - } Type; - - ////////////////////////////////////////////////////////////////////////////// - // Public constructors/destructors - ////////////////////////////////////////////////////////////////////////////// - ParameterClass (void); - ParameterClass (const ParameterClass &src); - virtual ~ParameterClass (void); - - ////////////////////////////////////////////////////////////////////////////// - // Public operators - ////////////////////////////////////////////////////////////////////////////// - const ParameterClass & operator= (const ParameterClass &src); - virtual bool operator== (const ParameterClass &src) = 0; - - ////////////////////////////////////////////////////////////////////////////// - // Public methods - ////////////////////////////////////////////////////////////////////////////// - - // RTTI - virtual DefParameterClass * As_DefParameterClass (void) { return NULL; } - - // Type identification (see paramtypes.h in wwsaveload) - virtual Type Get_Type (void) const = 0; - virtual bool Is_Type (Type type) const { return false; } - - // Modification - virtual bool Is_Modifed (void) const { return IsModified; } - virtual void Set_Modified (bool onoff = true) { IsModified = onoff; } - - // Display name methods - virtual const char * Get_Name (void) const; - virtual void Set_Name (const char *new_name); - - // Units display methods - virtual const char * Get_Units_Name (void) const; - virtual void Set_Units_Name (const char *units_name); - - // Copy methods - virtual void Copy_Value (const ParameterClass &src) { }; - - ////////////////////////////////////////////////////////////////////////////// - // Static methods - ////////////////////////////////////////////////////////////////////////////// - - // Virtual constructor used to create a new instance of any parameter type - static ParameterClass * Construct (ParameterClass::Type type, void *data, const char *param_name); - -private: - - ////////////////////////////////////////////////////////////////////////////// - // Private member data - ////////////////////////////////////////////////////////////////////////////// - bool IsModified; - const char * m_Name; - StringClass m_UnitsName; -}; - - -////////////////////////////////////////////////////////////////////////////////// -// ParameterClass -////////////////////////////////////////////////////////////////////////////////// -inline -ParameterClass::ParameterClass (void) - : m_Name (NULL), - IsModified (false) -{ - return ; -} - -////////////////////////////////////////////////////////////////////////////////// -// ParameterClass -////////////////////////////////////////////////////////////////////////////////// -inline -ParameterClass::ParameterClass (const ParameterClass &src) - : m_Name (NULL), - IsModified (false) -{ - (*this) = src; - return ; -} - -////////////////////////////////////////////////////////////////////////////////// -// ~ParameterClass -////////////////////////////////////////////////////////////////////////////////// -inline -ParameterClass::~ParameterClass (void) -{ - Set_Name (NULL); - return ; -} - -////////////////////////////////////////////////////////////////////////////////// -// operator= -////////////////////////////////////////////////////////////////////////////////// -inline const ParameterClass & -ParameterClass::operator= (const ParameterClass &src) -{ - IsModified = src.IsModified; - Set_Name (src.m_Name); - return *this; -} - -////////////////////////////////////////////////////////////////////////////////// -// Get_Name -////////////////////////////////////////////////////////////////////////////////// -inline const char * -ParameterClass::Get_Name (void) const -{ - return m_Name; -} - -////////////////////////////////////////////////////////////////////////////////// -// Set_Name -////////////////////////////////////////////////////////////////////////////////// -inline void -ParameterClass::Set_Name (const char *new_name) -{ - if (m_Name != NULL) { - ::free ((void *)m_Name); - m_Name = NULL; - } - - if (new_name != NULL) { - m_Name = ::strdup (new_name); - } - - return ; -} - - -////////////////////////////////////////////////////////////////////////////////// -// Get_Units_Name -////////////////////////////////////////////////////////////////////////////////// -inline const char * -ParameterClass::Get_Units_Name (void) const -{ - return m_UnitsName; -} - -////////////////////////////////////////////////////////////////////////////////// -// Set_Units_Name -////////////////////////////////////////////////////////////////////////////////// -inline void -ParameterClass::Set_Units_Name (const char *new_name) -{ - m_UnitsName = new_name; - return ; -} - -////////////////////////////////////////////////////////////////////////////////// -// -// StringParameterClass -// -////////////////////////////////////////////////////////////////////////////////// -class StringParameterClass : public ParameterClass -{ -public: - - ////////////////////////////////////////////////////////////////////////////// - // Public constructors/destructors - ////////////////////////////////////////////////////////////////////////////// - StringParameterClass (StringClass *string); - StringParameterClass (const StringParameterClass &src); - virtual ~StringParameterClass (void) {} - - ////////////////////////////////////////////////////////////////////////////// - // Public operators - ////////////////////////////////////////////////////////////////////////////// - const StringParameterClass & operator= (const StringParameterClass &src); - bool operator== (const StringParameterClass &src); - bool operator== (const ParameterClass &src); - - ////////////////////////////////////////////////////////////////////////////// - // Public methods - ////////////////////////////////////////////////////////////////////////////// - - // Type identification - virtual Type Get_Type (void) const { return TYPE_STRING; } - virtual bool Is_Type (Type type) const { return (type == TYPE_STRING) || ParameterClass::Is_Type (type); } - - // Data manipulation - virtual const char * Get_String (void) const; - virtual void Set_String (const char *string); - - // Copy methods - virtual void Copy_Value (const ParameterClass &src); - -protected: - - ////////////////////////////////////////////////////////////////////////////// - // Private member data - ////////////////////////////////////////////////////////////////////////////// - StringClass * m_String; -}; - - -////////////////////////////////////////////////////////////////////////////////// -// -// FilenameParameterClass -// -////////////////////////////////////////////////////////////////////////////////// -class FilenameParameterClass : public StringParameterClass -{ -public: - - ////////////////////////////////////////////////////////////////////////////// - // Public constructors/destructors - ////////////////////////////////////////////////////////////////////////////// - FilenameParameterClass (StringClass *string); - FilenameParameterClass (const FilenameParameterClass &src); - virtual ~FilenameParameterClass (void) {} - - ////////////////////////////////////////////////////////////////////////////// - // Public operators - ////////////////////////////////////////////////////////////////////////////// - const FilenameParameterClass & operator= (const FilenameParameterClass &src); - bool operator== (const FilenameParameterClass &src); - bool operator== (const ParameterClass &src); - - ////////////////////////////////////////////////////////////////////////////// - // Public methods - ////////////////////////////////////////////////////////////////////////////// - - // Type identification - virtual Type Get_Type (void) const { return TYPE_FILENAME; } - virtual bool Is_Type (Type type) const { return (type == TYPE_FILENAME) || StringParameterClass::Is_Type (type); } - - // Copy methods - virtual void Copy_Value (const ParameterClass &src); - - virtual void Set_Extension (const char *extension) { m_Extension = extension; } - virtual const char * Get_Extension (void) const { return m_Extension; } - - virtual void Set_Description (const char *desc) { m_Description = desc; } - virtual const char * Get_Description (void) const { return m_Description; } - -protected: - - ////////////////////////////////////////////////////////////////////////////// - // Protected member data - ////////////////////////////////////////////////////////////////////////////// - StringClass m_Extension; - StringClass m_Description; -}; - -////////////////////////////////////////////////////////////////////////////////// -// -// TextureFilenameParameterClass -// -////////////////////////////////////////////////////////////////////////////////// -class TextureFilenameParameterClass : public FilenameParameterClass -{ -public: - - ////////////////////////////////////////////////////////////////////////////// - // Public constructors/destructors - ////////////////////////////////////////////////////////////////////////////// - TextureFilenameParameterClass(StringClass *string); - TextureFilenameParameterClass(const TextureFilenameParameterClass& src); - virtual ~TextureFilenameParameterClass() {} - - - ////////////////////////////////////////////////////////////////////////////// - // Public methods - ////////////////////////////////////////////////////////////////////////////// - - // Type identification - virtual Type Get_Type (void) const { return TYPE_TEXTURE_FILENAME; } - virtual bool Is_Type (Type type) const { return (type == TYPE_TEXTURE_FILENAME) || StringParameterClass::Is_Type (type); } - - void Set_Show_Alpha(bool show) { Show_Alpha=show; } - bool Get_Show_Alpha() const { return Show_Alpha; } - - void Set_Show_Texture(bool show) { Show_Texture=show; } - bool Get_Show_Texture() const { return Show_Texture; } - - // Copy methods - virtual void Copy_Value (const ParameterClass &src); - -protected: - - bool Show_Alpha; - bool Show_Texture; -}; - - - -////////////////////////////////////////////////////////////////////////////////// -// -// SoundFilenameParameterClass -// -////////////////////////////////////////////////////////////////////////////////// -class SoundFilenameParameterClass : public FilenameParameterClass -{ -public: - - ////////////////////////////////////////////////////////////////////////////// - // Public constructors/destructors - ////////////////////////////////////////////////////////////////////////////// - SoundFilenameParameterClass (StringClass *string); - SoundFilenameParameterClass (const SoundFilenameParameterClass &src); - virtual ~SoundFilenameParameterClass (void) {} - - ////////////////////////////////////////////////////////////////////////////// - // Public operators - ////////////////////////////////////////////////////////////////////////////// - const SoundFilenameParameterClass & operator= (const SoundFilenameParameterClass &src); - bool operator== (const SoundFilenameParameterClass &src); - - ////////////////////////////////////////////////////////////////////////////// - // Public methods - ////////////////////////////////////////////////////////////////////////////// - - // Type identification - virtual Type Get_Type (void) const { return TYPE_SOUND_FILENAME; } - virtual bool Is_Type (Type type) const { return (type == TYPE_SOUND_FILENAME) || FilenameParameterClass::Is_Type (type); } -}; - -////////////////////////////////////////////////////////////////////////////////// -// -// EnumParameterClass -// -////////////////////////////////////////////////////////////////////////////////// -class EnumParameterClass : public ParameterClass -{ -public: - - ////////////////////////////////////////////////////////////////////////////// - // Public constructors/destructors - ////////////////////////////////////////////////////////////////////////////// - EnumParameterClass (int *value); - EnumParameterClass (const EnumParameterClass &src); - virtual ~EnumParameterClass (void) {} - - ////////////////////////////////////////////////////////////////////////////// - // Public operators - ////////////////////////////////////////////////////////////////////////////// - const EnumParameterClass & operator= (const EnumParameterClass &src); - bool operator== (const EnumParameterClass &src); - bool operator== (const ParameterClass &src); - - ////////////////////////////////////////////////////////////////////////////// - // Public methods - ////////////////////////////////////////////////////////////////////////////// - - // Type identification - virtual Type Get_Type (void) const { return TYPE_ENUM; } - virtual bool Is_Type (Type type) const { return (type == TYPE_ENUM) || ParameterClass::Is_Type (type); } - - // Data manipulation - virtual void __cdecl Add_Values (const char *first_name, int first_value, ...); - virtual void Add_Value (const char *display_name, int value); - virtual int Get_Count (void) const { return m_List.Count (); } - virtual const char * Get_Entry_Name (int index) const { return m_List[index].name; } - virtual int Get_Entry_Value (int index) const { return m_List[index].value; } - - virtual void Set_Selected_Value (int value) { (*m_Value) = value; Set_Modified (); } - virtual int Get_Selected_Value (void) const { return (*m_Value); } - - // Copy methods - virtual void Copy_Value (const ParameterClass &src); - -protected: - - ////////////////////////////////////////////////////////////////////////////// - // Private data types - ////////////////////////////////////////////////////////////////////////////// - typedef struct _ENUM_VALUE - { - StringClass name; - int value; - - _ENUM_VALUE (const char *_name=NULL, int _value=0) : name (_name), value (_value) {} - bool operator== (const _ENUM_VALUE &) { return false; } - bool operator!= (const _ENUM_VALUE &) { return true; } - } ENUM_VALUE; - - ////////////////////////////////////////////////////////////////////////////// - // Private member data - ////////////////////////////////////////////////////////////////////////////// - DynamicVectorClass m_List; - int * m_Value; -}; - - -////////////////////////////////////////////////////////////////////////////////// -// -// PhysDefParameterClass -// -////////////////////////////////////////////////////////////////////////////////// -class PhysDefParameterClass : public ParameterClass -{ -public: - - ////////////////////////////////////////////////////////////////////////////// - // Public constructors/destructors - ////////////////////////////////////////////////////////////////////////////// - PhysDefParameterClass (int *id); - PhysDefParameterClass (const PhysDefParameterClass &src); - virtual ~PhysDefParameterClass (void) {} - - ////////////////////////////////////////////////////////////////////////////// - // Public operators - ////////////////////////////////////////////////////////////////////////////// - const PhysDefParameterClass & operator= (const PhysDefParameterClass &src); - bool operator== (const PhysDefParameterClass &src); - bool operator== (const ParameterClass &src); - - ////////////////////////////////////////////////////////////////////////////// - // Public methods - ////////////////////////////////////////////////////////////////////////////// - - // Type identification - virtual Type Get_Type (void) const { return TYPE_PHYSDEFINITIONID; } - virtual bool Is_Type (Type type) const { return (type == TYPE_PHYSDEFINITIONID) || ParameterClass::Is_Type (type); } - - // Data manipulation - virtual void Set_Value (int id) { (*m_Value) = id; Set_Modified (); } - virtual int Get_Value (void) const { return (*m_Value); } - virtual void Set_Base_Class (const char *name) { m_BaseClass = name; } - virtual const char * Get_Base_Class (void) const { return m_BaseClass; } - - // Copy methods - virtual void Copy_Value (const ParameterClass &src); - -protected: - - ////////////////////////////////////////////////////////////////////////////// - // Private member data - ////////////////////////////////////////////////////////////////////////////// - int * m_Value; - StringClass m_BaseClass; -}; - - -////////////////////////////////////////////////////////////////////////////////// -// -// ModelDefParameterClass -// -////////////////////////////////////////////////////////////////////////////////// -class ModelDefParameterClass : public ParameterClass -{ -public: - - ////////////////////////////////////////////////////////////////////////////// - // Public constructors/destructors - ////////////////////////////////////////////////////////////////////////////// - ModelDefParameterClass (int *id); - ModelDefParameterClass (const ModelDefParameterClass &src); - virtual ~ModelDefParameterClass (void) {} - - ////////////////////////////////////////////////////////////////////////////// - // Public operators - ////////////////////////////////////////////////////////////////////////////// - const ModelDefParameterClass & operator= (const ModelDefParameterClass &src); - bool operator== (const ModelDefParameterClass &src); - bool operator== (const ParameterClass &src); - - ////////////////////////////////////////////////////////////////////////////// - // Public methods - ////////////////////////////////////////////////////////////////////////////// - - // Type identification - virtual Type Get_Type (void) const { return TYPE_MODELDEFINITIONID; } - virtual bool Is_Type (Type type) const { return (type == TYPE_MODELDEFINITIONID) || ParameterClass::Is_Type (type); } - - // Data manipulation - virtual void Set_Value (int id) { (*m_Value) = id; Set_Modified (); } - virtual int Get_Value (void) const { return (*m_Value); } - virtual void Set_Base_Class (const char *name) { m_BaseClass = name; } - virtual const char * Get_Base_Class (void) const { return m_BaseClass; } - - // Copy methods - virtual void Copy_Value (const ParameterClass &src); - -protected: - - ////////////////////////////////////////////////////////////////////////////// - // Private member data - ////////////////////////////////////////////////////////////////////////////// - int * m_Value; - StringClass m_BaseClass; -}; - - -////////////////////////////////////////////////////////////////////////////////// -// -// DefParameterClass -// -////////////////////////////////////////////////////////////////////////////////// -class DefParameterClass : public ParameterClass -{ -public: - - ////////////////////////////////////////////////////////////////////////////// - // Public constructors/destructors - ////////////////////////////////////////////////////////////////////////////// - DefParameterClass (int *id); - DefParameterClass (const DefParameterClass &src); - virtual ~DefParameterClass (void) {} - - ////////////////////////////////////////////////////////////////////////////// - // Public operators - ////////////////////////////////////////////////////////////////////////////// - const DefParameterClass & operator= (const DefParameterClass &src); - bool operator== (const DefParameterClass &src); - bool operator== (const ParameterClass &src); - - ////////////////////////////////////////////////////////////////////////////// - // Public methods - ////////////////////////////////////////////////////////////////////////////// - - // RTTI - virtual DefParameterClass * As_DefParameterClass (void) { return this; } - - // Data manipulation - virtual void Set_Value (int id) { (*m_Value) = id; Set_Modified (); } - virtual int Get_Value (void) const { return (*m_Value); } - - // Copy methods - virtual void Copy_Value (const ParameterClass &src); - -protected: - - ////////////////////////////////////////////////////////////////////////////// - // Private member data - ////////////////////////////////////////////////////////////////////////////// - int * m_Value; -}; - - -////////////////////////////////////////////////////////////////////////////////// -// -// GenericDefParameterClass -// -////////////////////////////////////////////////////////////////////////////////// -class GenericDefParameterClass : public DefParameterClass -{ -public: - - ////////////////////////////////////////////////////////////////////////////// - // Public constructors/destructors - ////////////////////////////////////////////////////////////////////////////// - GenericDefParameterClass (int *id); - GenericDefParameterClass (const GenericDefParameterClass &src); - virtual ~GenericDefParameterClass (void) {} - - ////////////////////////////////////////////////////////////////////////////// - // Public operators - ////////////////////////////////////////////////////////////////////////////// - const GenericDefParameterClass & operator= (const GenericDefParameterClass &src); - bool operator== (const GenericDefParameterClass &src); - bool operator== (const ParameterClass &src); - - ////////////////////////////////////////////////////////////////////////////// - // Public methods - ////////////////////////////////////////////////////////////////////////////// - - // Type identification - virtual Type Get_Type (void) const { return TYPE_GENERICDEFINITIONID; } - virtual bool Is_Type (Type type) const { return (type == TYPE_GENERICDEFINITIONID) || ParameterClass::Is_Type (type); } - - // Class ID control - virtual void Set_Class_ID (int class_id) { m_ClassID = class_id; Set_Modified (); } - virtual int Get_Class_ID (void) const { return m_ClassID; } - - // Copy methods - virtual void Copy_Value (const ParameterClass &src); - -protected: - - ////////////////////////////////////////////////////////////////////////////// - // Private member data - ////////////////////////////////////////////////////////////////////////////// - int m_ClassID; -}; - - -////////////////////////////////////////////////////////////////////////////////// -// -// GameObjDefParameterClass -// -////////////////////////////////////////////////////////////////////////////////// -class GameObjDefParameterClass : public DefParameterClass -{ -public: - - ////////////////////////////////////////////////////////////////////////////// - // Public constructors/destructors - ////////////////////////////////////////////////////////////////////////////// - GameObjDefParameterClass (int *id); - GameObjDefParameterClass (const GameObjDefParameterClass &src); - virtual ~GameObjDefParameterClass (void) {} - - ////////////////////////////////////////////////////////////////////////////// - // Public operators - ////////////////////////////////////////////////////////////////////////////// - const GameObjDefParameterClass & operator= (const GameObjDefParameterClass &src); - bool operator== (const GameObjDefParameterClass &src); - bool operator== (const ParameterClass &src); - - ////////////////////////////////////////////////////////////////////////////// - // Public methods - ////////////////////////////////////////////////////////////////////////////// - - // Type identification - virtual Type Get_Type (void) const { return TYPE_GAMEOBJDEFINITIONID; } - virtual bool Is_Type (Type type) const { return (type == TYPE_GAMEOBJDEFINITIONID) || ParameterClass::Is_Type (type); } - - // Data manipulation - virtual void Set_Base_Class (const char *name) { m_BaseClass = name; Set_Modified (); } - virtual const char * Get_Base_Class (void) const { return m_BaseClass; } - - // Copy methods - virtual void Copy_Value (const ParameterClass &src); - -protected: - - ////////////////////////////////////////////////////////////////////////////// - // Private member data - ////////////////////////////////////////////////////////////////////////////// - StringClass m_BaseClass; -}; - - -////////////////////////////////////////////////////////////////////////////////// -// -// AmmoObjDefParameterClass -// -////////////////////////////////////////////////////////////////////////////////// -class AmmoObjDefParameterClass : public GameObjDefParameterClass -{ -public: - - ////////////////////////////////////////////////////////////////////////////// - // Public constructors/destructors - ////////////////////////////////////////////////////////////////////////////// - AmmoObjDefParameterClass (int *id); - AmmoObjDefParameterClass (const AmmoObjDefParameterClass &src); - virtual ~AmmoObjDefParameterClass (void) {} - - ////////////////////////////////////////////////////////////////////////////// - // Public operators - ////////////////////////////////////////////////////////////////////////////// - const AmmoObjDefParameterClass & operator= (const AmmoObjDefParameterClass &src); - bool operator== (const AmmoObjDefParameterClass &src); - bool operator== (const ParameterClass &src); - - ////////////////////////////////////////////////////////////////////////////// - // Public methods - ////////////////////////////////////////////////////////////////////////////// - - // Type identification - virtual Type Get_Type (void) const { return TYPE_AMMOOBJDEFINITIONID; } - virtual bool Is_Type (Type type) const { return (type == TYPE_AMMOOBJDEFINITIONID) || GameObjDefParameterClass::Is_Type (type); } - - // Copy methods - virtual void Copy_Value (const ParameterClass &src); -}; - - -////////////////////////////////////////////////////////////////////////////////// -// -// WeaponObjDefParameterClass -// -////////////////////////////////////////////////////////////////////////////////// -class WeaponObjDefParameterClass : public GameObjDefParameterClass -{ -public: - - ////////////////////////////////////////////////////////////////////////////// - // Public constructors/destructors - ////////////////////////////////////////////////////////////////////////////// - WeaponObjDefParameterClass (int *id); - WeaponObjDefParameterClass (const WeaponObjDefParameterClass &src); - virtual ~WeaponObjDefParameterClass (void) {} - - ////////////////////////////////////////////////////////////////////////////// - // Public operators - ////////////////////////////////////////////////////////////////////////////// - const WeaponObjDefParameterClass & operator= (const WeaponObjDefParameterClass &src); - bool operator== (const WeaponObjDefParameterClass &src); - bool operator== (const ParameterClass &src); - - ////////////////////////////////////////////////////////////////////////////// - // Public methods - ////////////////////////////////////////////////////////////////////////////// - - // Type identification - virtual Type Get_Type (void) const { return TYPE_WEAPONOBJDEFINITIONID; } - virtual bool Is_Type (Type type) const { return (type == TYPE_WEAPONOBJDEFINITIONID) || GameObjDefParameterClass::Is_Type (type); } - - // Copy methods - virtual void Copy_Value (const ParameterClass &src); -}; - - -////////////////////////////////////////////////////////////////////////////////// -// -// ExplosionObjDefParameterClass -// -////////////////////////////////////////////////////////////////////////////////// -class ExplosionObjDefParameterClass : public GameObjDefParameterClass -{ -public: - - ////////////////////////////////////////////////////////////////////////////// - // Public constructors/destructors - ////////////////////////////////////////////////////////////////////////////// - ExplosionObjDefParameterClass (int *id); - ExplosionObjDefParameterClass (const ExplosionObjDefParameterClass &src); - virtual ~ExplosionObjDefParameterClass (void) {} - - ////////////////////////////////////////////////////////////////////////////// - // Public operators - ////////////////////////////////////////////////////////////////////////////// - const ExplosionObjDefParameterClass & operator= (const ExplosionObjDefParameterClass &src); - bool operator== (const ExplosionObjDefParameterClass &src); - bool operator== (const ParameterClass &src); - - ////////////////////////////////////////////////////////////////////////////// - // Public methods - ////////////////////////////////////////////////////////////////////////////// - - // Type identification - virtual Type Get_Type (void) const { return TYPE_EXPLOSIONDEFINITIONID; } - virtual bool Is_Type (Type type) const { return (type == TYPE_EXPLOSIONDEFINITIONID) || GameObjDefParameterClass::Is_Type (type); } - - // Copy methods - virtual void Copy_Value (const ParameterClass &src); -}; - - - -////////////////////////////////////////////////////////////////////////////////// -// -// SoundDefParameterClass -// -////////////////////////////////////////////////////////////////////////////////// -class SoundDefParameterClass : public DefParameterClass -{ -public: - - ////////////////////////////////////////////////////////////////////////////// - // Public constructors/destructors - ////////////////////////////////////////////////////////////////////////////// - SoundDefParameterClass (int *id); - SoundDefParameterClass (const SoundDefParameterClass &src); - virtual ~SoundDefParameterClass (void) {} - - ////////////////////////////////////////////////////////////////////////////// - // Public operators - ////////////////////////////////////////////////////////////////////////////// - const SoundDefParameterClass & operator= (const SoundDefParameterClass &src); - bool operator== (const SoundDefParameterClass &src); - bool operator== (const ParameterClass &src); - - ////////////////////////////////////////////////////////////////////////////// - // Public methods - ////////////////////////////////////////////////////////////////////////////// - - // Type identification - virtual Type Get_Type (void) const { return TYPE_SOUNDDEFINITIONID; } - virtual bool Is_Type (Type type) const { return (type == TYPE_SOUNDDEFINITIONID) || ParameterClass::Is_Type (type); } -}; - - -////////////////////////////////////////////////////////////////////////////////// -// -// ScriptParameterClass -// -////////////////////////////////////////////////////////////////////////////////// -class ScriptParameterClass : public ParameterClass -{ -public: - - ////////////////////////////////////////////////////////////////////////////// - // Public constructors/destructors - ////////////////////////////////////////////////////////////////////////////// - ScriptParameterClass (StringClass *name, StringClass *params); - ScriptParameterClass (const ScriptParameterClass &src); - virtual ~ScriptParameterClass (void) {} - - ////////////////////////////////////////////////////////////////////////////// - // Public operators - ////////////////////////////////////////////////////////////////////////////// - const ScriptParameterClass & operator= (const ScriptParameterClass &src); - bool operator== (const ScriptParameterClass &src); - bool operator== (const ParameterClass &src); - - ////////////////////////////////////////////////////////////////////////////// - // Public methods - ////////////////////////////////////////////////////////////////////////////// - - // Type identification - virtual Type Get_Type (void) const { return TYPE_SCRIPT; } - virtual bool Is_Type (Type type) const { return (type == TYPE_SCRIPT) || ParameterClass::Is_Type (type); } - - // Data manipulation - virtual void Set_Script_Name (const char *name) { (*m_ScriptName) = name; Set_Modified (); } - virtual const char * Get_Script_Name (void) const { return (*m_ScriptName); } - virtual void Set_Params (const char *params) { (*m_ScriptParams) = params; Set_Modified (); } - virtual const char * Get_Params (void) const { return (*m_ScriptParams); } - - // Copy methods - virtual void Copy_Value (const ParameterClass &src); - -protected: - - ////////////////////////////////////////////////////////////////////////////// - // Private member data - ////////////////////////////////////////////////////////////////////////////// - StringClass * m_ScriptName; - StringClass * m_ScriptParams; -}; - - -////////////////////////////////////////////////////////////////////////////////// -// -// DefIDListParameterClass -// -////////////////////////////////////////////////////////////////////////////////// -class DefIDListParameterClass : public ParameterClass -{ -public: - - ////////////////////////////////////////////////////////////////////////////// - // Public constructors/destructors - ////////////////////////////////////////////////////////////////////////////// - DefIDListParameterClass (DynamicVectorClass *list); - DefIDListParameterClass (const DefIDListParameterClass &src); - virtual ~DefIDListParameterClass (void) {} - - ////////////////////////////////////////////////////////////////////////////// - // Public operators - ////////////////////////////////////////////////////////////////////////////// - const DefIDListParameterClass & operator= (const DefIDListParameterClass &src); - bool operator== (const DefIDListParameterClass &src); - bool operator== (const ParameterClass &src); - - ////////////////////////////////////////////////////////////////////////////// - // Public methods - ////////////////////////////////////////////////////////////////////////////// - - // Type identification - virtual Type Get_Type (void) const { return TYPE_DEFINITIONIDLIST; } - virtual bool Is_Type (Type type) const { return (type == TYPE_DEFINITIONIDLIST) || ParameterClass::Is_Type (type); } - - // Data manipulation - virtual void Set_Selected_Class_ID (uint32 *id) { m_SelectedClassID = id; } - virtual uint32 * Get_Selected_Class_ID (void) const { return m_SelectedClassID; } - virtual void Set_Class_ID (uint32 id) { m_ClassID = id; } - virtual uint32 Get_Class_ID (void) const { return m_ClassID; } - - virtual DynamicVectorClass &Get_List (void) const { return (*m_IDList); } - - // Copy methods - virtual void Copy_Value (const ParameterClass &src); - -protected: - - ////////////////////////////////////////////////////////////////////////////// - // Private member data - ////////////////////////////////////////////////////////////////////////////// - DynamicVectorClass * m_IDList; - uint32 m_ClassID; - uint32 * m_SelectedClassID; -}; - - -////////////////////////////////////////////////////////////////////////////////// -// -// ZoneParameterClass -// -////////////////////////////////////////////////////////////////////////////////// -class ZoneParameterClass : public ParameterClass -{ -public: - - ////////////////////////////////////////////////////////////////////////////// - // Public constructors/destructors - ////////////////////////////////////////////////////////////////////////////// - ZoneParameterClass (OBBoxClass *box); - ZoneParameterClass (const ZoneParameterClass &src); - virtual ~ZoneParameterClass (void) {} - - ////////////////////////////////////////////////////////////////////////////// - // Public operators - ////////////////////////////////////////////////////////////////////////////// - const ZoneParameterClass & operator= (const ZoneParameterClass &src); - bool operator== (const ZoneParameterClass &src); - bool operator== (const ParameterClass &src); - - ////////////////////////////////////////////////////////////////////////////// - // Public methods - ////////////////////////////////////////////////////////////////////////////// - - // Type identification - virtual Type Get_Type (void) const { return TYPE_ZONE; } - virtual bool Is_Type (Type type) const { return (type == TYPE_ZONE) || ParameterClass::Is_Type (type); } - - // Data manipulation - virtual void Set_Zone (const OBBoxClass &box) { (*m_OBBox) = box; Set_Modified (); } - virtual const OBBoxClass & Get_Zone (void) const { return (*m_OBBox); } - - - // Copy methods - virtual void Copy_Value (const ParameterClass &src); - -protected: - - ////////////////////////////////////////////////////////////////////////////// - // Private member data - ////////////////////////////////////////////////////////////////////////////// - OBBoxClass *m_OBBox; -}; - - -////////////////////////////////////////////////////////////////////////////////// -// -// FilenameListParameterClass -// -////////////////////////////////////////////////////////////////////////////////// -class FilenameListParameterClass : public ParameterClass -{ -public: - - ////////////////////////////////////////////////////////////////////////////// - // Public constructors/destructors - ////////////////////////////////////////////////////////////////////////////// - FilenameListParameterClass (DynamicVectorClass *list); - FilenameListParameterClass (const FilenameListParameterClass &src); - virtual ~FilenameListParameterClass (void) {} - - ////////////////////////////////////////////////////////////////////////////// - // Public operators - ////////////////////////////////////////////////////////////////////////////// - const FilenameListParameterClass & operator= (const FilenameListParameterClass &src); - bool operator== (const FilenameListParameterClass &src); - bool operator== (const ParameterClass &src); - - ////////////////////////////////////////////////////////////////////////////// - // Public methods - ////////////////////////////////////////////////////////////////////////////// - - // Type identification - virtual Type Get_Type (void) const { return TYPE_FILENAMELIST; } - virtual bool Is_Type (Type type) const { return (type == TYPE_FILENAMELIST) || ParameterClass::Is_Type (type); } - - // Data manipulation - virtual DynamicVectorClass &Get_List (void) const { return (*m_FilenameList); } - - // Copy methods - virtual void Copy_Value (const ParameterClass &src); - -protected: - - ////////////////////////////////////////////////////////////////////////////// - // Private member data - ////////////////////////////////////////////////////////////////////////////// - DynamicVectorClass * m_FilenameList; -}; - - - -////////////////////////////////////////////////////////////////////////////////// -// -// ScriptListParameterClass -// -////////////////////////////////////////////////////////////////////////////////// -class ScriptListParameterClass : public ParameterClass -{ -public: - - ////////////////////////////////////////////////////////////////////////////// - // Public constructors/destructors - ////////////////////////////////////////////////////////////////////////////// - ScriptListParameterClass (DynamicVectorClass *name_list, DynamicVectorClass *param_list); - ScriptListParameterClass (const ScriptListParameterClass &src); - virtual ~ScriptListParameterClass (void) {} - - ////////////////////////////////////////////////////////////////////////////// - // Public operators - ////////////////////////////////////////////////////////////////////////////// - const ScriptListParameterClass & operator= (const ScriptListParameterClass &src); - bool operator== (const ScriptListParameterClass &src); - bool operator== (const ParameterClass &src); - - ////////////////////////////////////////////////////////////////////////////// - // Public methods - ////////////////////////////////////////////////////////////////////////////// - - // Type identification - virtual Type Get_Type (void) const { return TYPE_SCRIPTLIST; } - virtual bool Is_Type (Type type) const { return (type == TYPE_SCRIPTLIST) || ParameterClass::Is_Type (type); } - - // Data manipulation - virtual DynamicVectorClass &Get_Name_List (void) const { return (*m_NameList); } - virtual DynamicVectorClass &Get_Param_List (void) const { return (*m_ParamList); } - - // Copy methods - virtual void Copy_Value (const ParameterClass &src); - -protected: - - ////////////////////////////////////////////////////////////////////////////// - // Protected members - ////////////////////////////////////////////////////////////////////////////// - bool Are_Lists_Identical (DynamicVectorClass &list1, DynamicVectorClass &list2); - - ////////////////////////////////////////////////////////////////////////////// - // Private member data - ////////////////////////////////////////////////////////////////////////////// - DynamicVectorClass * m_NameList; - DynamicVectorClass * m_ParamList; -}; - - -////////////////////////////////////////////////////////////////////////////////// -// -// SeparatorParameterClass -// -////////////////////////////////////////////////////////////////////////////////// -class SeparatorParameterClass : public ParameterClass -{ -public: - - ////////////////////////////////////////////////////////////////////////////// - // Public constructors/destructors - ////////////////////////////////////////////////////////////////////////////// - SeparatorParameterClass (void) {} - SeparatorParameterClass (const SeparatorParameterClass &src); - virtual ~SeparatorParameterClass (void) {} - - ////////////////////////////////////////////////////////////////////////////// - // Public operators - ////////////////////////////////////////////////////////////////////////////// - const SeparatorParameterClass & operator= (const SeparatorParameterClass &src); - bool operator== (const SeparatorParameterClass &src); - bool operator== (const ParameterClass &src); - - ////////////////////////////////////////////////////////////////////////////// - // Public methods - ////////////////////////////////////////////////////////////////////////////// - - // Type identification - virtual Type Get_Type (void) const { return TYPE_SEPARATOR; } - virtual bool Is_Type (Type type) const { return (type == TYPE_SEPARATOR) || ParameterClass::Is_Type (type); } - - // Copy methods - virtual void Copy_Value (const ParameterClass &src); -}; - - -#endif //__PARAMETER_H - diff --git a/Generals/Code/Libraries/Source/WWVegas/WWSaveLoad/parameterlist.h b/Generals/Code/Libraries/Source/WWVegas/WWSaveLoad/parameterlist.h deleted file mode 100644 index 6bf0250994f..00000000000 --- a/Generals/Code/Libraries/Source/WWVegas/WWSaveLoad/parameterlist.h +++ /dev/null @@ -1,163 +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 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 : WWSaveLoad * - * * - * $Archive:: /Commando/Code/wwsaveload/parameterlist.h $* - * * - * Author:: Patrick Smith * - * * - * $Modtime:: 10/06/99 2:52p $* - * * - * $Revision:: 9 $* - * * - *---------------------------------------------------------------------------------------------* - * Functions: * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - - -#if defined(_MSC_VER) -#pragma once -#endif - - - - -#ifndef __PARAMETER_LIST_H -#define __PARAMETER_LIST_H - -#include "always.h" -#include "Vector.H" -#include "parameter.h" -#include "wwdebug.h" - -////////////////////////////////////////////////////////////////////////////////// -// -// ParameterListClass -// -////////////////////////////////////////////////////////////////////////////////// -class ParameterListClass : public DynamicVectorClass -{ - using DynamicVectorClass::Vector; - -public: - - ///////////////////////////////////////////////////////////////////// - // Public constructurs/destructors - ///////////////////////////////////////////////////////////////////// - ~ParameterListClass (void); - - ///////////////////////////////////////////////////////////////////// - // Public methods - ///////////////////////////////////////////////////////////////////// - void Add (void *data, const char *param_name, ParameterClass::Type type); - void Add (ParameterClass *parameter); - -protected: - - ///////////////////////////////////////////////////////////////////// - // Protected methods - ///////////////////////////////////////////////////////////////////// - void Free_Parameters (void); - -private: - - ///////////////////////////////////////////////////////////////////// - // Private member data - ///////////////////////////////////////////////////////////////////// - //DynamicVectorClass m_Parameters; -}; - - -///////////////////////////////////////////////////////////////////// -// ~ParameterListClass -///////////////////////////////////////////////////////////////////// -inline -ParameterListClass::~ParameterListClass (void) -{ - Free_Parameters (); - return ; -} - -///////////////////////////////////////////////////////////////////// -// Add -///////////////////////////////////////////////////////////////////// -inline void -ParameterListClass::Add (void *data, const char *param_name, ParameterClass::Type type) -{ - // - // Create a new parameter object - // - ParameterClass *new_param = ParameterClass::Construct (type, data, param_name); - - // - // Add the new paramter object to our list - // - WWASSERT (new_param != NULL); - if (new_param != NULL) { - DynamicVectorClass::Add (new_param); - } - - return ; -} - -///////////////////////////////////////////////////////////////////// -// Add -///////////////////////////////////////////////////////////////////// -inline void -ParameterListClass::Add (ParameterClass *new_param) -{ - // - // Add the new paramter object to our list - // - if (new_param != NULL) { - DynamicVectorClass::Add (new_param); - } - - return ; -} - -///////////////////////////////////////////////////////////////////// -// Free_Parameters -///////////////////////////////////////////////////////////////////// -inline void -ParameterListClass::Free_Parameters (void) -{ - for (int index = 0; index < Count (); index ++) { - ParameterClass *param = Vector[index]; - - // - // Free the parameter object - // - if (param != NULL) { - delete param; - } - } - - Delete_All(); -// m_Parameters.Delete_All (); - return ; -} - - -#endif //__PARAMETER_LIST_H - diff --git a/Generals/Code/Libraries/Source/WWVegas/WWSaveLoad/parametertypes.h b/Generals/Code/Libraries/Source/WWVegas/WWSaveLoad/parametertypes.h deleted file mode 100644 index 2a6921bdef3..00000000000 --- a/Generals/Code/Libraries/Source/WWVegas/WWSaveLoad/parametertypes.h +++ /dev/null @@ -1,69 +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 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 : WWSaveLoad * - * * - * $Archive:: /Commando/Code/wwsaveload/parametertypes.h $* - * * - * Author:: Patrick Smith * - * * - * $Modtime:: 9/10/99 3:38p $* - * * - * $Revision:: 6 $* - * * - *---------------------------------------------------------------------------------------------* - * Functions: * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - - -#if defined(_MSC_VER) -#pragma once -#endif - - - -#ifndef __PARAMETER_TYPES_H -#define __PARAMETER_TYPES_H - -#include "always.h" - -////////////////////////////////////////////////////////////////////////////////// -// -// ParameterType -// -////////////////////////////////////////////////////////////////////////////////// -/*typedef enum -{ - TYPE_INT = 0, - TYPE_FLOAT, - TYPE_STRING, - TYPE_VECTOR3, - TYPE_MATRIX3D, - TYPE_TRANSITION, - TYPE_PRESETID, - TYPE_MODELFILENAME - -} ParameterType;*/ - - -#endif //__PARAMETER_TYPES_H - diff --git a/Generals/Code/Libraries/Source/WWVegas/WWSaveLoad/persist.h b/Generals/Code/Libraries/Source/WWVegas/WWSaveLoad/persist.h deleted file mode 100644 index f9cefd727c7..00000000000 --- a/Generals/Code/Libraries/Source/WWVegas/WWSaveLoad/persist.h +++ /dev/null @@ -1,77 +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 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 : WWSaveLoad * - * * - * $Archive:: /Commando/Code/wwsaveload/persist.h $* - * * - * Author:: Greg Hjelstrom * - * * - * $Modtime:: 5/04/01 8:42p $* - * * - * $Revision:: 13 $* - * * - *---------------------------------------------------------------------------------------------* - * Functions: * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - - -#if defined(_MSC_VER) -#pragma once -#endif - -#ifndef PERSIST_H -#define PERSIST_H - -#include "always.h" -#include "refcount.h" -#include "postloadable.h" - -class PersistFactoryClass; -class ChunkSaveClass; -class ChunkLoadClass; - - -////////////////////////////////////////////////////////////////////////////////// -// -// PersistClass -// -// PersistClass defines the interface for an object to the save load system. -// Each concrete derived type of PersistClass must have an associated -// PersistFactoryClass that basically maps a chunk_id to a constructor, -// a save function, a load function, and a on_post_load function (taken from -// PostLoadableClass ) -// -////////////////////////////////////////////////////////////////////////////////// -class PersistClass : public PostLoadableClass -{ -public: - - virtual const PersistFactoryClass & Get_Factory (void) const = 0; - virtual bool Save (ChunkSaveClass &csave) { return true; } - virtual bool Load (ChunkLoadClass &cload) { return true; } - -}; - - - -#endif diff --git a/Generals/Code/Libraries/Source/WWVegas/WWSaveLoad/persistfactory.cpp b/Generals/Code/Libraries/Source/WWVegas/WWSaveLoad/persistfactory.cpp deleted file mode 100644 index 36c67252445..00000000000 --- a/Generals/Code/Libraries/Source/WWVegas/WWSaveLoad/persistfactory.cpp +++ /dev/null @@ -1,50 +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 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 : WWSaveLoad * - * * - * $Archive:: /Commando/Code/wwsaveload/persistfactory.cpp $* - * * - * Author:: Greg Hjelstrom * - * * - * $Modtime:: 9/09/99 9:50a $* - * * - * $Revision:: 2 $* - * * - *---------------------------------------------------------------------------------------------* - * Functions: * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - - -#include "persistfactory.h" -#include "saveload.h" - -PersistFactoryClass::PersistFactoryClass(void) : - NextFactory(NULL) -{ - SaveLoadSystemClass::Register_Persist_Factory(this); -} - -PersistFactoryClass::~PersistFactoryClass(void) -{ - SaveLoadSystemClass::Unregister_Persist_Factory(this); -} diff --git a/Generals/Code/Libraries/Source/WWVegas/WWSaveLoad/persistfactory.h b/Generals/Code/Libraries/Source/WWVegas/WWSaveLoad/persistfactory.h deleted file mode 100644 index d882257905c..00000000000 --- a/Generals/Code/Libraries/Source/WWVegas/WWSaveLoad/persistfactory.h +++ /dev/null @@ -1,143 +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 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 : WWSaveLoad * - * * - * $Archive:: /Commando/Code/wwsaveload/persistfactory.h $* - * * - * Author:: Greg Hjelstrom * - * * - * $Modtime:: 5/04/01 8:42p $* - * * - * $Revision:: 11 $* - * * - *---------------------------------------------------------------------------------------------* - * Functions: * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - - -#if defined(_MSC_VER) -#pragma once -#endif - - - - -#ifndef PERSISTFACTORY_H -#define PERSISTFACTORY_H - -#include "always.h" -#include "bittype.h" -#include "chunkio.h" -#include "wwdebug.h" -#include "saveload.h" -#include "persist.h" - -/* -** PersistFactoryClass -** Create a PersistFactoryClass for each concrete derived PersistClass. These -** factories automatically register with the SaveLoadSystem in their constructors -** and should be accessible through the virtual Get_Factory method of any -** derived PersistClass. -*/ - -class PersistFactoryClass -{ -public: - - PersistFactoryClass(void); - virtual ~PersistFactoryClass(void); - - virtual uint32 Chunk_ID(void) const = 0; - virtual PersistClass * Load(ChunkLoadClass & cload) const = 0; - virtual void Save(ChunkSaveClass & csave,PersistClass * obj) const = 0; - -private: - - PersistFactoryClass * NextFactory; - friend class SaveLoadSystemClass; -}; - - - - -/* -** SimplePersistFactoryClass -** This template automates the creation of a PersistFactory for any type of Persist -** object. Simply instantiate a single static instance of this template with the -** type and chunkid in the .cpp file of your class. -*/ -template class SimplePersistFactoryClass : public PersistFactoryClass -{ -public: - - virtual uint32 Chunk_ID(void) const { return CHUNKID; } - virtual PersistClass * Load(ChunkLoadClass & cload) const; - virtual void Save(ChunkSaveClass & csave,PersistClass * obj) const; - - /* - ** Internal chunk id's - */ - enum - { - SIMPLEFACTORY_CHUNKID_OBJPOINTER = 0x00100100, - SIMPLEFACTORY_CHUNKID_OBJDATA - }; -}; - - -template PersistClass * -SimplePersistFactoryClass::Load(ChunkLoadClass & cload) const -{ - T * new_obj = W3DNEW T; - T * old_obj = NULL; - - cload.Open_Chunk(); - WWASSERT(cload.Cur_Chunk_ID() == SIMPLEFACTORY_CHUNKID_OBJPOINTER); - cload.Read(&old_obj,sizeof(T *)); - cload.Close_Chunk(); - - cload.Open_Chunk(); - WWASSERT(cload.Cur_Chunk_ID() == SIMPLEFACTORY_CHUNKID_OBJDATA); - new_obj->Load(cload); - cload.Close_Chunk(); - - SaveLoadSystemClass::Register_Pointer(old_obj,new_obj); - return new_obj; -} - - -template void -SimplePersistFactoryClass::Save(ChunkSaveClass & csave,PersistClass * obj) const -{ - uint32 objptr = (uint32)obj; - csave.Begin_Chunk(SIMPLEFACTORY_CHUNKID_OBJPOINTER); - csave.Write(&objptr,sizeof(uint32)); - csave.End_Chunk(); - - csave.Begin_Chunk(SIMPLEFACTORY_CHUNKID_OBJDATA); - obj->Save(csave); - csave.End_Chunk(); -} - - -#endif diff --git a/Generals/Code/Libraries/Source/WWVegas/WWSaveLoad/pointerremap.cpp b/Generals/Code/Libraries/Source/WWVegas/WWSaveLoad/pointerremap.cpp deleted file mode 100644 index 952667b8cf7..00000000000 --- a/Generals/Code/Libraries/Source/WWVegas/WWSaveLoad/pointerremap.cpp +++ /dev/null @@ -1,210 +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 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 : WWSaveLoad * - * * - * $Archive:: /Commando/Code/wwsaveload/pointerremap.cpp $* - * * - * Author:: Greg Hjelstrom * - * * - * $Modtime:: 5/09/01 11:36a $* - * * - * $Revision:: 9 $* - * * - *---------------------------------------------------------------------------------------------* - * Functions: * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - - -#include "pointerremap.h" -#include "refcount.h" -#include "wwdebug.h" - - -const int POINTER_TABLES_GROWTH_STEP = 4096; - - -PointerRemapClass::PointerRemapClass(void) -{ - PointerPairTable.Set_Growth_Step(POINTER_TABLES_GROWTH_STEP); - PointerRequestTable.Set_Growth_Step(POINTER_TABLES_GROWTH_STEP); - RefCountRequestTable.Set_Growth_Step(POINTER_TABLES_GROWTH_STEP); -} - -PointerRemapClass::~PointerRemapClass(void) -{ -} - -void PointerRemapClass::Reset(void) -{ - PointerPairTable.Delete_All(); - PointerRequestTable.Delete_All(); - RefCountRequestTable.Delete_All(); -} - -void PointerRemapClass::Process(void) -{ - if ( PointerPairTable.Count() > 0 ) { - qsort(&PointerPairTable[0], PointerPairTable.Count(), sizeof(PointerPairTable[0]), ptr_pair_compare_function); - } - - if ( PointerRequestTable.Count() > 0 ) { - WWASSERT( PointerPairTable.Count() > 0 ); - qsort(&PointerRequestTable[0],PointerRequestTable.Count(), sizeof(PointerRequestTable[0]), ptr_request_compare_function); - Process_Request_Table(PointerRequestTable,false); - } - - // remap the ref-counted pointers - if ( RefCountRequestTable.Count() > 0 ) { - WWASSERT( PointerPairTable.Count() > 0 ); - qsort(&RefCountRequestTable[0],RefCountRequestTable.Count(), sizeof(RefCountRequestTable[0]), ptr_request_compare_function); - Process_Request_Table(RefCountRequestTable,true); - } -} - -void PointerRemapClass::Process_Request_Table(DynamicVectorClass & request_table,bool refcount) -{ - // Remap the pointers - int pointer_index = 0; - int pair_index = 0; - - for (pointer_index = 0; pointer_index < request_table.Count(); pointer_index++) { - - void * pointer_to_remap = *(request_table[pointer_index].PointerToRemap); - int pre_search_index = pair_index; - - // Find the pair which contains the pointer we are looking for as its "old" pointer - while ( (pair_index < PointerPairTable.Count()) && - (PointerPairTable[pair_index].OldPointer < pointer_to_remap) ) - { - pair_index++; - } - - if ((pair_index < PointerPairTable.Count()) && (PointerPairTable[pair_index].OldPointer == pointer_to_remap)) { - - // we found the match, plug in the new pointer and add a ref if needed. - *request_table[pointer_index].PointerToRemap = PointerPairTable[pair_index].NewPointer; - - if (refcount) { - RefCountClass * refptr = (RefCountClass *)(*request_table[pointer_index].PointerToRemap); - refptr->Add_Ref(); - } - - } else { - - // Failed to re-map the pointer. - // warn the user, set pointer to NULL, reset index to the pre_search_index. - // If this happens, things could be going very wrong. (find out why its happening!) - pair_index = pre_search_index; - *request_table[pointer_index].PointerToRemap = NULL; -#ifdef WWDEBUG - const char * file = request_table[pointer_index].File; - int line = request_table[pointer_index].Line; - WWDEBUG_SAY(("Warning! Failed to re-map pointer! old_ptr = 0x%X file = %s line = %d\r\n",(unsigned int)pointer_to_remap,file,line)); - WWASSERT( 0 ); -#endif - } - } -} - -void PointerRemapClass::Register_Pointer (void *old_pointer, void *new_pointer) -{ - PointerPairTable.Add(PtrPairStruct(old_pointer,new_pointer)); -} - -#ifdef WWDEBUG -void PointerRemapClass::Request_Pointer_Remap(void **pointer_to_convert,const char * file,int line) -{ - PtrRemapStruct remap; - remap.PointerToRemap = pointer_to_convert; - remap.File = file; - remap.Line = line; - PointerRequestTable.Add(remap); -} - -void PointerRemapClass::Request_Ref_Counted_Pointer_Remap (RefCountClass **pointer_to_convert,const char * file, int line) -{ - PtrRemapStruct remap; - remap.PointerToRemap = (void**)pointer_to_convert; - remap.File = file; - remap.Line = line; - RefCountRequestTable.Add(remap); -} - -#else - -void PointerRemapClass::Request_Pointer_Remap (void **pointer_to_convert) -{ - PtrRemapStruct remap; - remap.PointerToRemap = pointer_to_convert; - PointerRequestTable.Add(remap); -} - -void PointerRemapClass::Request_Ref_Counted_Pointer_Remap (RefCountClass **pointer_to_convert) -{ - PtrRemapStruct remap; - remap.PointerToRemap = (void**)pointer_to_convert; - RefCountRequestTable.Add(remap); -} - -#endif - -/* -** sort compare function for pointer pair structures -** sorts by the old pointer value -*/ -int __cdecl PointerRemapClass::ptr_pair_compare_function(void const * ptr1, void const * ptr2) -{ - void * old1 = ((PointerRemapClass::PtrPairStruct const *)ptr1)->OldPointer; - void * old2 = ((PointerRemapClass::PtrPairStruct const *)ptr2)->OldPointer; - - if (old1 == old2) { - return(0); - } - if (old1 < old2) { - return(-1); - } - return(1); -} - -/* -** sort compare function for pointer remap structures -** sorts by the old pointer value -*/ -int __cdecl PointerRemapClass::ptr_request_compare_function(void const * ptr1, void const * ptr2) -{ - PtrRemapStruct * remap1 = (PtrRemapStruct *)ptr1; - PtrRemapStruct * remap2 = (PtrRemapStruct *)ptr2; - - void * old1 = *(remap1->PointerToRemap); - void * old2 = *(remap2->PointerToRemap); - - if (old1 == old2) { - return(0); - } - if (old1 < old2) { - return(-1); - } - return(1); -} - - diff --git a/Generals/Code/Libraries/Source/WWVegas/WWSaveLoad/pointerremap.h b/Generals/Code/Libraries/Source/WWVegas/WWSaveLoad/pointerremap.h deleted file mode 100644 index 94f431898a2..00000000000 --- a/Generals/Code/Libraries/Source/WWVegas/WWSaveLoad/pointerremap.h +++ /dev/null @@ -1,115 +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 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 : WWSaveLoad * - * * - * $Archive:: /Commando/Code/wwsaveload/pointerremap.h $* - * * - * Author:: Greg Hjelstrom * - * * - * $Modtime:: 4/30/01 1:54p $* - * * - * $Revision:: 6 $* - * * - *---------------------------------------------------------------------------------------------* - * Functions: * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - - -#if defined(_MSC_VER) -#pragma once -#endif - - -#ifndef POINTERREMAP_H -#define POINTERREMAP_H - -#ifdef _UNIX -#include "osdep/osdep.h" -#endif - -#include "always.h" -#include "Vector.H" - -class RefCountClass; - - -class PointerRemapClass -{ - public: - - PointerRemapClass(void); - ~PointerRemapClass(void); - - void Reset(void); - void Process(void); - - void Register_Pointer (void *old_pointer, void *new_pointer); - -#ifdef WWDEBUG - void Request_Pointer_Remap (void **pointer_to_convert,const char * file,int line); - void Request_Ref_Counted_Pointer_Remap (RefCountClass **pointer_to_convert,const char * file, int line); -#else - void Request_Pointer_Remap (void **pointer_to_convert); - void Request_Ref_Counted_Pointer_Remap (RefCountClass **pointer_to_convert); -#endif - - private: - - struct PtrPairStruct - { - PtrPairStruct(void) {} - PtrPairStruct(void * oldptr,void * newptr) : OldPointer(oldptr),NewPointer(newptr) {} - bool operator == (const PtrPairStruct & that) { return ((OldPointer == that.OldPointer) && (NewPointer == that.NewPointer)); } - bool operator != (const PtrPairStruct & that) { return !(*this == that); } - - void * OldPointer; - void * NewPointer; - }; - - struct PtrRemapStruct - { - PtrRemapStruct(void) {} - bool operator == (const PtrRemapStruct & that) { return (PointerToRemap == that.PointerToRemap); } - bool operator != (const PtrRemapStruct & that) { return !(*this == that); } - - void ** PointerToRemap; -#ifdef WWDEBUG - const char * File; - int Line; -#endif - }; - - void Process_Request_Table(DynamicVectorClass & request_table,bool refcount); - static int __cdecl ptr_pair_compare_function(void const * ptr1, void const * ptr2); - static int __cdecl ptr_request_compare_function(void const * ptr1, void const * ptr2); - - /* - ** Array of pointers associated with ID values to assist in swizzling. - */ - DynamicVectorClass PointerPairTable; - DynamicVectorClass PointerRequestTable; - DynamicVectorClass RefCountRequestTable; -}; - - -#endif diff --git a/Generals/Code/Libraries/Source/WWVegas/WWSaveLoad/postloadable.h b/Generals/Code/Libraries/Source/WWVegas/WWSaveLoad/postloadable.h deleted file mode 100644 index 90c3ccbf71b..00000000000 --- a/Generals/Code/Libraries/Source/WWVegas/WWSaveLoad/postloadable.h +++ /dev/null @@ -1,71 +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 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 : WWSaveLoad * - * * - * $Archive:: /Commando/Code/wwsaveload/postloadable.h $* - * * - * Original Author:: Greg Hjelstrom * - * * - * $Author:: Greg_h $* - * * - * $Modtime:: 5/09/01 11:46a $* - * * - * $Revision:: 3 $* - * * - *---------------------------------------------------------------------------------------------* - * Functions: * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - -#ifndef POSTLOADABLE_H -#define POSTLOADABLE_H - - -////////////////////////////////////////////////////////////////////////////////// -// -// PostLoadableClass -// -// PostLoadableClass allows a lower level for non-Persist objects to On_Post_Load -// without requiring Get_Factory or other requirements of PersistClass. Objects -// derived from this class can be added to the post-load list in the SaveLoadSystem -// -////////////////////////////////////////////////////////////////////////////////// -class PostLoadableClass -{ -public: - PostLoadableClass(void) : IsPostLoadRegistered(false) { } - virtual ~PostLoadableClass(void) { } - - virtual void On_Post_Load (void) { } - - bool Is_Post_Load_Registered(void) { return IsPostLoadRegistered; } - void Set_Post_Load_Registered(bool onoff) { IsPostLoadRegistered = onoff; } - -private: - - bool IsPostLoadRegistered; -}; - - - -#endif - diff --git a/Generals/Code/Libraries/Source/WWVegas/WWSaveLoad/saveload.cpp b/Generals/Code/Libraries/Source/WWVegas/WWSaveLoad/saveload.cpp deleted file mode 100644 index 8923fc6ee28..00000000000 --- a/Generals/Code/Libraries/Source/WWVegas/WWSaveLoad/saveload.cpp +++ /dev/null @@ -1,300 +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 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 : WWSaveLoad * - * * - * $Archive:: /Commando/Code/wwsaveload/saveload.cpp $* - * * - * Author:: Greg Hjelstrom * - * * - * $Modtime:: 12/09/01 6:42p $* - * * - * $Revision:: 19 $* - * * - *---------------------------------------------------------------------------------------------* - * Functions: * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - - -#include "saveload.h" -#include "saveloadsubsystem.h" -#include "persist.h" -#include "persistfactory.h" -#include "chunkio.h" -#include "wwdebug.h" -#include "saveloadstatus.h" -#include "wwhack.h" -#include "wwprofile.h" - -#pragma warning(disable:4201) // warning C4201: nonstandard extension used : nameless struct/union -#include -#include "systimer.h" - - -SaveLoadSubSystemClass * SaveLoadSystemClass::SubSystemListHead = NULL; -PersistFactoryClass * SaveLoadSystemClass::FactoryListHead = NULL; -SList SaveLoadSystemClass::PostLoadList; -PointerRemapClass SaveLoadSystemClass::PointerRemapper; - - - -bool SaveLoadSystemClass::Save (ChunkSaveClass &csave,SaveLoadSubSystemClass & subsystem) -{ - bool ok = true; - - if (subsystem.Contains_Data()) { - csave.Begin_Chunk (subsystem.Chunk_ID ()); - ok &= subsystem.Save (csave); - csave.End_Chunk (); - } - - return ok; -} - -bool SaveLoadSystemClass::Load (ChunkLoadClass &cload,bool auto_post_load) -{ - PointerRemapper.Reset(); - bool ok = true; - - // Load each chunk we encounter and link the manager into the PostLoad list - while (cload.Open_Chunk ()) { - SaveLoadStatus::Inc_Status_Count(); // Count the sub systems loaded - SaveLoadSubSystemClass *sys = Find_Sub_System(cload.Cur_Chunk_ID ()); - if (sys != NULL) { -//WWRELEASE_SAY((" Name: %s\n",sys->Name())); - INIT_SUB_STATUS(sys->Name()); - ok &= sys->Load(cload); - } - cload.Close_Chunk(); - } - - // Process all of the pointer remap requests - PointerRemapper.Process(); - PointerRemapper.Reset(); - - // Call PostLoad on each PersistClass that wanted post-load - if (auto_post_load) { - Post_Load_Processing(NULL); - } - - return ok; -} - -// Nework update macro for post loader. -#define UPDATE_NETWORK \ - if (network_callback) { \ - unsigned long time2 = TIMEGETTIME(); \ - if (time2 - time > 20) { \ - network_callback(); \ - time = time2; \ - } \ - } \ - -bool SaveLoadSystemClass::Post_Load_Processing (void(*network_callback)(void)) -{ - unsigned long time = TIMEGETTIME(); - - // Call PostLoad on each PersistClass that wanted post-load - PostLoadableClass * obj = PostLoadList.Remove_Head(); - while (obj) { - UPDATE_NETWORK; - obj->On_Post_Load(); - obj->Set_Post_Load_Registered(false); - obj = PostLoadList.Remove_Head(); - } - - return true; -} - -void SaveLoadSystemClass::Register_Sub_System (SaveLoadSubSystemClass * sys) -{ - WWASSERT(sys != NULL); - Link_Sub_System(sys); -} - - -void SaveLoadSystemClass::Unregister_Sub_System (SaveLoadSubSystemClass * sys) -{ - WWASSERT(sys != NULL); - Unlink_Sub_System(sys); -} - - -SaveLoadSubSystemClass * SaveLoadSystemClass::Find_Sub_System (uint32 chunk_id) -{ - // TODO: need a d-s that gives fast searching based on chunk_id!! - SaveLoadSubSystemClass * sys; - for ( sys = SubSystemListHead; sys != NULL; sys = sys->NextSubSystem ) { - if ( sys->Chunk_ID() == chunk_id ) { - break; - } - } - return sys; -} - -void SaveLoadSystemClass::Register_Persist_Factory(PersistFactoryClass * factory) -{ - WWASSERT(factory != NULL); - Link_Factory(factory); -} - -void SaveLoadSystemClass::Unregister_Persist_Factory(PersistFactoryClass * factory) -{ - WWASSERT(factory != NULL); - Unlink_Factory(factory); -} - -PersistFactoryClass * SaveLoadSystemClass::Find_Persist_Factory(uint32 chunk_id) -{ - // TODO: need a d-s that gives fast searching based on chunk_id!! - PersistFactoryClass * fact; - for ( fact = FactoryListHead; fact != NULL; fact = fact->NextFactory ) { - if ( fact->Chunk_ID() == chunk_id ) { - break; - } - } - return fact; -} - -bool SaveLoadSystemClass::Is_Post_Load_Callback_Registered(PostLoadableClass * obj) -{ - // obsolete! - bool retval = false; - - SLNode *list_node = NULL; - for ( list_node = PostLoadList.Head(); - retval == false && list_node != NULL; - list_node = list_node->Next()) - { - retval = (list_node->Data() == obj); - } - - return retval; -} - -void SaveLoadSystemClass::Register_Post_Load_Callback(PostLoadableClass * obj) -{ - WWASSERT(obj != NULL); - if (!obj->Is_Post_Load_Registered()) { - obj->Set_Post_Load_Registered(true); - PostLoadList.Add_Head(obj); - } -} - -void SaveLoadSystemClass::Register_Pointer (void *old_pointer, void *new_pointer) -{ - PointerRemapper.Register_Pointer(old_pointer,new_pointer); -} - -#ifdef WWDEBUG - -void SaveLoadSystemClass::Request_Pointer_Remap (void **pointer_to_convert,const char * file,int line) -{ - PointerRemapper.Request_Pointer_Remap(pointer_to_convert,file,line); -} - -void SaveLoadSystemClass::Request_Ref_Counted_Pointer_Remap (RefCountClass **pointer_to_convert,const char * file,int line) -{ - PointerRemapper.Request_Ref_Counted_Pointer_Remap(pointer_to_convert,file,line); -} - -#else - -void SaveLoadSystemClass::Request_Pointer_Remap (void **pointer_to_convert) -{ - PointerRemapper.Request_Pointer_Remap(pointer_to_convert); -} - -void SaveLoadSystemClass::Request_Ref_Counted_Pointer_Remap (RefCountClass **pointer_to_convert) -{ - PointerRemapper.Request_Ref_Counted_Pointer_Remap(pointer_to_convert); -} - -#endif - -void SaveLoadSystemClass::Link_Sub_System(SaveLoadSubSystemClass * sys) -{ - WWASSERT(sys != NULL); - if (sys != NULL) { - WWASSERT(sys->NextSubSystem == NULL); // sys should never be registered twice! - sys->NextSubSystem = SubSystemListHead; - SubSystemListHead = sys; - } -} - -void SaveLoadSystemClass::Unlink_Sub_System(SaveLoadSubSystemClass * sys) -{ - WWASSERT(sys != NULL); - SaveLoadSubSystemClass * cursys = SubSystemListHead; - SaveLoadSubSystemClass * prev = NULL; - - while (cursys != sys) { - prev = cursys; - cursys = cursys->NextSubSystem; - } - - if (prev == NULL) { - SubSystemListHead = sys->NextSubSystem; - } else { - prev->NextSubSystem = sys->NextSubSystem; - } - - sys->NextSubSystem = NULL; -} - - -void SaveLoadSystemClass::Link_Factory(PersistFactoryClass * fact) -{ - WWASSERT(fact != NULL); - if (fact != NULL) { - WWASSERT(fact->NextFactory == NULL); // factories should never be registered twice! - fact->NextFactory = FactoryListHead; - FactoryListHead = fact; - } -} - -void SaveLoadSystemClass::Unlink_Factory(PersistFactoryClass * fact) -{ - WWASSERT(fact != NULL); - - PersistFactoryClass * curfact = FactoryListHead; - PersistFactoryClass * prev = NULL; - - while (curfact != fact) { - prev = curfact; - curfact = curfact->NextFactory; - } - - if (prev == NULL) { - FactoryListHead = fact->NextFactory; - } else { - prev->NextFactory = fact->NextFactory; - } - - fact->NextFactory = NULL; -} - -void Force_Link_WWSaveLoad (void) -{ - FORCE_LINK( Twiddler ); - return ; -} \ No newline at end of file diff --git a/Generals/Code/Libraries/Source/WWVegas/WWSaveLoad/saveload.h b/Generals/Code/Libraries/Source/WWVegas/WWSaveLoad/saveload.h deleted file mode 100644 index df6be42d487..00000000000 --- a/Generals/Code/Libraries/Source/WWVegas/WWSaveLoad/saveload.h +++ /dev/null @@ -1,223 +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 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 : WWSaveLoad * - * * - * $Archive:: /Commando/Code/wwsaveload/saveload.h $* - * * - * Author:: Greg Hjelstrom * - * * - * $Modtime:: 9/19/01 4:13p $* - * * - * $Revision:: 12 $* - * * - *---------------------------------------------------------------------------------------------* - * Functions: * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - - -#if defined(_MSC_VER) -#pragma once -#endif - - -#ifndef SAVELOAD_H -#define SAVELOAD_H - -#include "always.h" -#include "pointerremap.h" -#include "bittype.h" -#include "SLIST.H" - -class RefCountClass; -class SaveLoadSubSystemClass; -class PersistFactoryClass; -class PersistClass; -class PostLoadableClass; -class ChunkSaveClass; -class ChunkLoadClass; - - -////////////////////////////////////////////////////////////////////////////////// -// -// WWSaveLoad -// -// The WWSaveLoad library is a framework for saving and loading. The main -// goals that we attempted to achieve in designing this system are: -// -// - Save things in a form that could adapt as our code evolves. We want -// to be able to load files which were created with a previous version of the -// application into the current version. -// - Use the same framework throughout all of our libraries with as small an -// impact on them as possible -// - Automate as much of the implementation of save-load as possible. -// - Make this a generic hunk of code which contains no commando-specific parts -// so that it can be used by other applications. -// - Make this system capable of generating the file formats for our level editor, -// the game's level definition file, and player save files. -// -// To achive this, we developed several core concepts: -// -// - Persistant Objects: Most of the state of the game is contained in the objects -// active at any given time. PersistClass is an abstract interface which will allow -// objects to be used with the save-load system. It was also important to keep the -// overhead caused by inheriting this class to an absolute minimum. -// -// - PersistFactories: We need an automatic "virtual-constructor" or "abstract-factory" -// system for all objects that get saved. This is the PersistFactoryClass and the -// automated SimplePersistFactory template. All objects that "persist" are derived from -// PersistClass and all concrete derived PersistClasses have an associated static -// instance of a PersistFactory which handles their saving and construction upon encountering -// them while loading. In certain cases these PersistFactories can also serve as -// a "shortcut" where we cheat by not actually telling the object to save but simply save -// a small piece of data that allows us to recreate an identical object when we load. This -// is used in WW3D sometimes; we just save a render object name and then ask the WW3D asset -// manager to recreate that model for us. -// -// - SaveLoadSubSystems: The overall file structure will be governed by many sub-systems -// (derived from SaveLoadSubSystemClass). The application in-effect creates file formats -// by simply having the sub-systems that it wants write into a file. In this way you can -// achieve things like saving only static data into one file and dynamic into another, etc. -// All persistant objects that get saved will be told to save by some sub-system. For -// example: in Commando, I have a PhysicsDynamicDataSubSystem which saves all of the -// dynamic physics objects. In saving those objects I use the built-in PersistFactories -// and am therefore completely safe from new object types being added to the system, it will just -// automatically work -// -// - Pointer re-mapping: A pointer remaping system is built into the save-load system. There -// are several things that happen in this system. Each object, as it is saved and loaded, -// registers with the system its old address and its new address. (the old address is saved -// and the new address is available once the object is created). This is automated by the -// SimplePersistFactory for all but classes that use multiple inheritance. During the load -// process a table is built which contains all of these pointer pairs (old address, new address). -// Whenever an object loads a pointer, it gives a "pointer to that pointer" to the save load system. -// Then, after all of the objects have been loaded, the system goes through that list of pointers -// and finds them in the pointer pair table. NOTE: use the macros for re-mapping your -// pointers to enable automatic debugging information when you build with WWDEBUG defined. -// -// - Chunks: The file format will be chunk based since that gives us the flexibility to -// add new data and remove obsolete data without necessarily losing the ability -// to read old files. We will use a "high-granularity" of chunks. In many cases, each -// member variable will be in its own chunk for maximum flexibility. To help soften -// the memory usage for this approach, we developed the concept of "micro-chunks". -// Micro-chunks are just like chunks in that they have an id and a size but -// each of these fields are only a single byte and they are never hierarchical. -// -// - ChunkID's: The chunk ID's used by Subsystems and PersistFactories must be unique -// but all others can be considered local to the object that is saving itself. Unique -// ids for the subsystems and factories are achieved by saveloadids.h defining ranges -// of ids for various libraries and then those libraries maintaining a single header -// file internally which gives unique id's within that range to all of their sub-systems -// and persist factories. Never re-use an id or you will break compatibility with older -// versions of your files... -// -////////////////////////////////////////////////////////////////////////////////// - - -////////////////////////////////////////////////////////////////////////////////// -// -// SaveLoadSystemClass -// -////////////////////////////////////////////////////////////////////////////////// -class SaveLoadSystemClass -{ -public: - - /* - ** Save-Load interface. To create a file, ask each sub-system to save itself. - ** To load a file just open it and pass it to the load method. - */ - static bool Save (ChunkSaveClass &csave, SaveLoadSubSystemClass & subsystem); - static bool Load (ChunkLoadClass &cload,bool auto_post_load = true); - static bool Post_Load_Processing (void(*network_callback)(void)); - /* - ** Look up the persist factory for a given chunk id - */ - static PersistFactoryClass * Find_Persist_Factory(uint32 chunk_id); - - /* - ** Post-Load interface. An object being loaded can ask for a callback after - ** all objects have been loaded and pointers re-mapped. - */ - static void Register_Post_Load_Callback(PostLoadableClass * obj); - - /* - ** Pointer Remapping interface. NOTE: use the macros defined below to - ** get debug info with your pointers when doing a debug build. - */ - static void Register_Pointer (void *old_pointer, void *new_pointer); - -#ifdef WWDEBUG - static void Request_Pointer_Remap (void **pointer_to_convert,const char * file = NULL,int line = 0); - static void Request_Ref_Counted_Pointer_Remap (RefCountClass **pointer_to_convert,const char * file = NULL,int line = 0); -#else - static void Request_Pointer_Remap (void **pointer_to_convert); - static void Request_Ref_Counted_Pointer_Remap (RefCountClass **pointer_to_convert); -#endif - -protected: - - /* - ** Internal SaveLoadSystem functions - */ - static void Register_Sub_System (SaveLoadSubSystemClass * subsys); - static void Unregister_Sub_System (SaveLoadSubSystemClass * subsys); - static SaveLoadSubSystemClass * Find_Sub_System (uint32 chunk_id); - - static void Register_Persist_Factory(PersistFactoryClass * factory); - static void Unregister_Persist_Factory(PersistFactoryClass * factory); - - static void Link_Sub_System(SaveLoadSubSystemClass * subsys); - static void Unlink_Sub_System(SaveLoadSubSystemClass * subsys); - static void Link_Factory(PersistFactoryClass * factory); - static void Unlink_Factory(PersistFactoryClass * factory); - - static bool Is_Post_Load_Callback_Registered(PostLoadableClass * obj); - - static SaveLoadSubSystemClass * SubSystemListHead; - static PersistFactoryClass * FactoryListHead; - static PointerRemapClass PointerRemapper; - static SList PostLoadList; - - /* - ** these are friends so that they can register themselves at construction time. - */ - friend class SaveLoadSubSystemClass; - friend class PersistFactoryClass; -}; - - -/* -** Use the following macros to automatically enable pointer-remap DEBUG code. Remember that -** in all cases you submit a pointer to the pointer you want re-mapped. -*/ -#ifdef WWDEBUG -#define REQUEST_POINTER_REMAP(pp) SaveLoadSystemClass::Request_Pointer_Remap(pp,__FILE__,__LINE__) -#define REQUEST_REF_COUNTED_POINTER_REMAP(pp) SaveLoadSystemClass::Request_Ref_Counted_Pointer_Remap(pp,__FILE__,__LINE__) -#else -#define REQUEST_POINTER_REMAP(pp) SaveLoadSystemClass::Request_Pointer_Remap(pp) -#define REQUEST_REF_COUNTED_POINTER_REMAP(pp) SaveLoadSystemClass::Request_Ref_Counted_Pointer_Remap(pp) -#endif - - -#endif //SAVELOAD_H - diff --git a/Generals/Code/Libraries/Source/WWVegas/WWSaveLoad/saveloadids.h b/Generals/Code/Libraries/Source/WWVegas/WWSaveLoad/saveloadids.h deleted file mode 100644 index f096c4a97a8..00000000000 --- a/Generals/Code/Libraries/Source/WWVegas/WWSaveLoad/saveloadids.h +++ /dev/null @@ -1,71 +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 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 : WWSaveLoad * - * * - * $Archive:: /Commando/Code/wwsaveload/saveloadids.h $* - * * - * Author:: Greg Hjelstrom * - * * - * $Modtime:: 5/04/01 8:42p $* - * * - * $Revision:: 9 $* - * * - *---------------------------------------------------------------------------------------------* - * Functions: * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - - -#if defined(_MSC_VER) -#pragma once -#endif - -#ifndef SAVELOADIDS_H -#define SAVELOADIDS_H - -////////////////////////////////////////////////////////////////////////////////// -// -// Chunk ID Ranges. -// Here are the ranges to use for SubSystem and PersistFactory chunk id's -// and also the chunk id's used by the save-load system itself. If you are -// creating a new library that is going to take advantage of this system, -// create a new range for it here. -// -////////////////////////////////////////////////////////////////////////////////// -enum -{ - CHUNKID_SAVELOAD_BEGIN = 0x00000100, - CHUNKID_SAVELOAD_DEFMGR, - CHUNKID_TWIDDLER, - CHUNKID_WW3D_BEGIN = 0x00010000, - CHUNKID_WWPHYS_BEGIN = 0x00020000, - CHUNKID_WWAUDIO_BEGIN = 0x00030000, - CHUNKID_COMBAT_BEGIN = 0x00040000, - CHUNKID_COMMANDO_EDITOR_BEGIN = 0x00050000, - CHUNKID_PHYSTEST_BEGIN = 0x00060000, - CHUNKID_COMMANDO_BEGIN = 0x00070000, - CHUNKID_WWMATH_BEGIN = 0x00080000, - CHUNKID_WWTRANSLATEDB_BEGIN = 0x00090000 -}; - - -#endif diff --git a/Generals/Code/Libraries/Source/WWVegas/WWSaveLoad/saveloadstatus.cpp b/Generals/Code/Libraries/Source/WWVegas/WWSaveLoad/saveloadstatus.cpp deleted file mode 100644 index c12d2c0edfd..00000000000 --- a/Generals/Code/Libraries/Source/WWVegas/WWSaveLoad/saveloadstatus.cpp +++ /dev/null @@ -1,57 +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 . -*/ - -#include "saveloadstatus.h" -#include "mutex.h" - -#define MAX_STATUS_TEXT_ID 2 - -static CriticalSectionClass text_mutex; -static StringClass status_text[MAX_STATUS_TEXT_ID]; - -void SaveLoadStatus::Set_Status_Text(const char* text,int id) -{ - CriticalSectionClass::LockClass m(text_mutex); - WWASSERT(id. -*/ - -#ifndef WWSAVELOADSTATUS_H -#define WWSAVELOADSTATUS_H - -#if defined(_MSC_VER) -#pragma once -#endif - -#include "always.h" -#include "wwstring.h" - -namespace SaveLoadStatus -{ - void Set_Status_Text(const char* text,int id); - - void Reset_Status_Count( void ); - void Inc_Status_Count( void ); - int Get_Status_Count( void ); - void Get_Status_Text(StringClass& text, int id); -}; - -#define INIT_STATUS(t) SaveLoadStatus::Set_Status_Text(t,0) -#define INIT_SUB_STATUS(t) SaveLoadStatus::Set_Status_Text(t,1) - -#endif diff --git a/Generals/Code/Libraries/Source/WWVegas/WWSaveLoad/saveloadsubsystem.cpp b/Generals/Code/Libraries/Source/WWVegas/WWSaveLoad/saveloadsubsystem.cpp deleted file mode 100644 index ca8115be5fb..00000000000 --- a/Generals/Code/Libraries/Source/WWVegas/WWSaveLoad/saveloadsubsystem.cpp +++ /dev/null @@ -1,54 +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 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 : WWSaveLoad * - * * - * $Archive:: /Commando/Code/wwsaveload/saveloadsubsystem.cpp $* - * * - * Author:: Greg Hjelstrom * - * * - * $Modtime:: 9/09/99 9:50a $* - * * - * $Revision:: 2 $* - * * - *---------------------------------------------------------------------------------------------* - * Functions: * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - - -#include "saveloadsubsystem.h" -#include "saveload.h" - - -SaveLoadSubSystemClass::SaveLoadSubSystemClass(void) : - NextSubSystem(NULL) -{ - // All Sub-Systems are automatically registered with the SaveLoadSystem - SaveLoadSystemClass::Register_Sub_System (this); - return ; -} - -SaveLoadSubSystemClass::~SaveLoadSubSystemClass (void) -{ - SaveLoadSystemClass::Unregister_Sub_System (this); - return ; -} diff --git a/Generals/Code/Libraries/Source/WWVegas/WWSaveLoad/saveloadsubsystem.h b/Generals/Code/Libraries/Source/WWVegas/WWSaveLoad/saveloadsubsystem.h deleted file mode 100644 index 500106f74c5..00000000000 --- a/Generals/Code/Libraries/Source/WWVegas/WWSaveLoad/saveloadsubsystem.h +++ /dev/null @@ -1,95 +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 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 : WWSaveLoad * - * * - * $Archive:: /Commando/Code/wwsaveload/saveloadsubsystem.h $* - * * - * Author:: Greg Hjelstrom * - * * - * $Modtime:: 6/12/00 4:25p $* - * * - * $Revision:: 7 $* - * * - *---------------------------------------------------------------------------------------------* - * Functions: * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - - -#if defined(_MSC_VER) -#pragma once -#endif - - -#ifndef SAVELOADSUBSYSTEM_H -#define SAVELOADSUBSYSTEM_H - - -#include "always.h" -#include "bittype.h" -#include "postloadable.h" - -class ChunkLoadClass; -class ChunkSaveClass; - - -////////////////////////////////////////////////////////////////////////////////// -// -// SaveLoadSubSystemClass -// -// Each SaveLoadSubSystem will automatically be registered with the SaveLoadSystem -// at construction time. The plan is to have a single static instance of each -// sub-system so that it automatically registers when the global constructors -// are executed. -// -// When an application wants to create a file it does so by asking the -// SaveLoadSystem to save the particular set of SaveLoadSubSystems that contain -// that data. -// -////////////////////////////////////////////////////////////////////////////////// -class SaveLoadSubSystemClass : public PostLoadableClass -{ -public: - - SaveLoadSubSystemClass (void); - virtual ~SaveLoadSubSystemClass (void); - - virtual uint32 Chunk_ID (void) const = 0; - -protected: - - virtual bool Contains_Data(void) const { return true; } - virtual bool Save (ChunkSaveClass &csave) = 0; - virtual bool Load (ChunkLoadClass &cload) = 0; - - virtual const char* Name() const = 0; - -private: - - SaveLoadSubSystemClass * NextSubSystem; // managed by SaveLoadSystem - - friend class SaveLoadSystemClass; -}; - - - -#endif \ No newline at end of file diff --git a/Generals/Code/Libraries/Source/WWVegas/WWSaveLoad/simpledefinitionfactory.h b/Generals/Code/Libraries/Source/WWVegas/WWSaveLoad/simpledefinitionfactory.h deleted file mode 100644 index d3127a163d3..00000000000 --- a/Generals/Code/Libraries/Source/WWVegas/WWSaveLoad/simpledefinitionfactory.h +++ /dev/null @@ -1,86 +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 . -*/ - - - -#ifndef __SIMPLE_DEFINITION_FACTORY_H -#define __SIMPLE_DEFINITION_FACTORY_H - -#include "definitionfactory.h" - -////////////////////////////////////////////////////////////////////////////////// -// -// SimpleDefinitionFactoryClass -// -// Template class to automate the creation of simple definition factories. -// -////////////////////////////////////////////////////////////////////////////////// -template -class SimpleDefinitionFactoryClass : public DefinitionFactoryClass -{ -public: - - ////////////////////////////////////////////////////////////// - // Public constructors/destructors - ////////////////////////////////////////////////////////////// - SimpleDefinitionFactoryClass (bool is_displayed = true) : - IsDisplayed (is_displayed) {} - - ////////////////////////////////////////////////////////////// - // Public methods - ////////////////////////////////////////////////////////////// - virtual DefinitionClass * Create (void) const; - virtual const char * Get_Name (void) const; - virtual uint32 Get_Class_ID (void) const; - virtual bool Is_Displayed (void) const { return IsDisplayed; } - -protected: - - ////////////////////////////////////////////////////////////// - // Protected member data - ////////////////////////////////////////////////////////////// - bool IsDisplayed; -}; - -template -inline DefinitionClass * -SimpleDefinitionFactoryClass::Create (void) const -{ - return W3DNEW T; -} - -template -inline const char * -SimpleDefinitionFactoryClass::Get_Name (void) const -{ - return name; -} - -template -inline uint32 -SimpleDefinitionFactoryClass::Get_Class_ID (void) const -{ - return class_id; -} - -#define DECLARE_DEFINITION_FACTORY(_class, _id, _name) \ -char _class ## Name[] = _name; \ -SimpleDefinitionFactoryClass<_class, _id, _class ## Name> \ - -#endif //__SIMPLE_DEFINITION_FACTORY_H - diff --git a/Generals/Code/Libraries/Source/WWVegas/WWSaveLoad/simpleparameter.h b/Generals/Code/Libraries/Source/WWVegas/WWSaveLoad/simpleparameter.h deleted file mode 100644 index 695e22f8598..00000000000 --- a/Generals/Code/Libraries/Source/WWVegas/WWSaveLoad/simpleparameter.h +++ /dev/null @@ -1,247 +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 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 : WWSaveLoad * - * * - * $Archive:: /Commando/Code/wwsaveload/simpleparameter.h $* - * * - * Author:: Patrick Smith * - * * - * $Modtime:: 7/16/01 11:12a $* - * * - * $Revision:: 17 $* - * * - *---------------------------------------------------------------------------------------------* - * Functions: * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - - -#if defined(_MSC_VER) -#pragma once -#endif - - - - -#ifndef __SIMPLE_PARAMETER_H -#define __SIMPLE_PARAMETER_H - -#include "always.h" -#include "parameter.h" -#include "vector2.h" -#include "vector3.h" -#include "matrix3d.h" -#include "rect.h" -#include - - -////////////////////////////////////////////////////////////////////////////////// -// -// SimpleParameterClass -// -////////////////////////////////////////////////////////////////////////////////// -template -class SimpleParameterClass : public ParameterClass -{ -public: - - /////////////////////////////////////////////////////////////////////// - // Public constructors/destructors - /////////////////////////////////////////////////////////////////////// - SimpleParameterClass (void *data, const char *name); - - ////////////////////////////////////////////////////////////////////////////// - // Public operators - ////////////////////////////////////////////////////////////////////////////// - bool operator== (const ParameterClass &src); - - /////////////////////////////////////////////////////////////////////// - // Public methods - /////////////////////////////////////////////////////////////////////// - const T & Get_Value (void) const; - void Set_Value (const T &new_value); - - // From Parameter class - ParameterClass::Type Get_Type (void) const; - void Copy_Value (const ParameterClass &src); - -private: - - /////////////////////////////////////////////////////////////////////// - // Private member data - /////////////////////////////////////////////////////////////////////// - T * m_Data; - T m_Min; - T m_Max; -}; - -////////////////////////////////////////////////////////////////////////////////// -// SimpleParameterClass -////////////////////////////////////////////////////////////////////////////////// -template inline -SimpleParameterClass::SimpleParameterClass (void *data, const char *name) -{ - Set_Name (name); - m_Data = (T *)data; - return ; -} - -////////////////////////////////////////////////////////////////////////////////// -// Get_Value -////////////////////////////////////////////////////////////////////////////////// -template inline bool -SimpleParameterClass::operator== (const ParameterClass &src) -{ - bool retval = false; - if (src.Get_Type () == Get_Type ()) { - retval = ((*m_Data) == *(((const SimpleParameterClass &)src).m_Data)); - } - - return retval; -} - -////////////////////////////////////////////////////////////////////////////////// -// Get_Value -////////////////////////////////////////////////////////////////////////////////// -template inline const T & -SimpleParameterClass::Get_Value (void) const -{ - return (*m_Data); -} - -////////////////////////////////////////////////////////////////////////////////// -// Set_Value -////////////////////////////////////////////////////////////////////////////////// -template inline void -SimpleParameterClass::Set_Value (const T &new_value) -{ - (*m_Data) = new_value; - Set_Modified (); - return ; -} - -////////////////////////////////////////////////////////////////////////////////// -// Get_Type -////////////////////////////////////////////////////////////////////////////////// -template inline ParameterClass::Type -SimpleParameterClass::Get_Type (void) const -{ - return type; -} - -////////////////////////////////////////////////////////////////////////////////// -// Copy_Value -////////////////////////////////////////////////////////////////////////////////// -template inline void -SimpleParameterClass::Copy_Value (const ParameterClass &src) -{ - if (Get_Type () == src.Get_Type ()) { - (*m_Data) = ((SimpleParameterClass &)src).Get_Value (); - } - - ParameterClass::Copy_Value (src); - return ; -} - -////////////////////////////////////////////////////////////////////////////////// -// -// Simple parameter types -// -////////////////////////////////////////////////////////////////////////////////// -typedef SimpleParameterClass BoolParameterClass; -typedef SimpleParameterClass Vector2ParameterClass; -typedef SimpleParameterClass Vector3ParameterClass; -typedef SimpleParameterClass Matrix3DParameterClass; -typedef SimpleParameterClass RectParameterClass; -typedef SimpleParameterClass ColorParameterClass; -typedef SimpleParameterClass StringsDBEntryParameterClass; - - -////////////////////////////////////////////////////////////////////////////////// -// -// RangedParameterClass -// -// Extends simple paramter types so they can have minimum/maximum values. -// -////////////////////////////////////////////////////////////////////////////////// -template -class RangedParameterClass : public SimpleParameterClass -{ -public: - /////////////////////////////////////////////////////////////////////// - // Public constructors/destructors - /////////////////////////////////////////////////////////////////////// - RangedParameterClass (void *data, const char *name) - : SimpleParameterClass (data, name) { } - - /////////////////////////////////////////////////////////////////////// - // Public methods - /////////////////////////////////////////////////////////////////////// - void Set_Range (const T &min, const T &max) { m_Min = min; m_Max = max; } - const T & Get_Min (void) const { return m_Min; } - const T & Get_Max (void) const { return m_Max; } - -private: - - /////////////////////////////////////////////////////////////////////// - // Private member data - /////////////////////////////////////////////////////////////////////// - T m_Min; - T m_Max; -}; - - -////////////////////////////////////////////////////////////////////////////////// -// IntParameterClass -////////////////////////////////////////////////////////////////////////////////// -class IntParameterClass : public RangedParameterClass -{ -public: - IntParameterClass (void *data, const char *name) - : RangedParameterClass (data, name) - { Set_Range (-1000000000L, 1000000000L); } -}; - -////////////////////////////////////////////////////////////////////////////////// -// FloatParameterClass -////////////////////////////////////////////////////////////////////////////////// -class FloatParameterClass : public RangedParameterClass -{ -public: - FloatParameterClass (void *data, const char *name) - : RangedParameterClass (data, name) - { Set_Range (-100000.0F, 100000.0F); } -}; - -////////////////////////////////////////////////////////////////////////////////// -// AngleParameterClass -////////////////////////////////////////////////////////////////////////////////// -class AngleParameterClass : public RangedParameterClass -{ -public: - AngleParameterClass (void *data, const char *name) - : RangedParameterClass (data, name) - { Set_Range (0.0F, 6.283185307F); } -}; - -#endif //__SIMPLE_PARAMETER_H - diff --git a/Generals/Code/Libraries/Source/WWVegas/WWSaveLoad/twiddler.cpp b/Generals/Code/Libraries/Source/WWVegas/WWSaveLoad/twiddler.cpp deleted file mode 100644 index 61dca2345f5..00000000000 --- a/Generals/Code/Libraries/Source/WWVegas/WWSaveLoad/twiddler.cpp +++ /dev/null @@ -1,280 +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 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 : WWSaveLoad * - * * - * $Archive:: /Commando/Code/wwsaveload/twiddler.cpp $* - * * - * Author:: Patrick Smith * - * * - * $Modtime:: 12/10/01 12:40p $* - * * - * $Revision:: 3 $* - * * - *---------------------------------------------------------------------------------------------* - * Functions: * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - - -#include "twiddler.h" -#include "RANDOM.H" -#include "saveloadids.h" -#include "simpledefinitionfactory.h" -#include "persistfactory.h" -#include "win.h" -#include "wwhack.h" -#include "systimer.h" - - -DECLARE_FORCE_LINK( Twiddler ) - -////////////////////////////////////////////////////////////////////////////////// -// Constants -////////////////////////////////////////////////////////////////////////////////// -enum -{ - CHUNKID_VARIABLES = 0x00000100, - CHUNKID_BASE_CLASS = 0x00000200, -}; - -enum -{ - VARID_DEFINTION_ID = 0x01, - VARID_INDIRECT_CLASSID, -}; - - -////////////////////////////////////////////////////////////////////////////////// -// -// Static factories -// -////////////////////////////////////////////////////////////////////////////////// -DECLARE_DEFINITION_FACTORY(TwiddlerClass, CLASSID_TWIDDLERS, "Twiddler") _TwiddlerFactory; -SimplePersistFactoryClass _TwiddlerPersistFactory; - - -////////////////////////////////////////////////////////////////////////////////// -// -// TwiddlerClass -// -////////////////////////////////////////////////////////////////////////////////// -TwiddlerClass::TwiddlerClass (void) - : m_IndirectClassID (0) - -{ - CLASSID_DEFIDLIST_PARAM (TwiddlerClass, m_DefinitionList, 0, m_IndirectClassID, "Preset List"); - return ; -} - - -////////////////////////////////////////////////////////////////////////////////// -// -// ~TwiddlerClass -// -////////////////////////////////////////////////////////////////////////////////// -TwiddlerClass::~TwiddlerClass (void) -{ - return ; -} - - -////////////////////////////////////////////////////////////////////////////////// -// -// Twiddle -// -////////////////////////////////////////////////////////////////////////////////// -DefinitionClass * -TwiddlerClass::Twiddle (void) const -{ - DefinitionClass *definition = NULL; - - if (m_DefinitionList.Count () > 0) { - - // - // Get a random index into our definition list - // - RandomClass randomizer (TIMEGETTIME ()); - int index = randomizer (0, m_DefinitionList.Count () - 1); - - // - // Lookup the definition this entry represents - // - int def_id = m_DefinitionList[index]; - definition = DefinitionMgrClass::Find_Definition (def_id); - } - - return definition; -} - - -////////////////////////////////////////////////////////////////////////////////// -// -// Create -// -////////////////////////////////////////////////////////////////////////////////// -PersistClass * -TwiddlerClass::Create (void) const -{ - PersistClass *retval = NULL; - - // - // Pick a random definition - // - DefinitionClass *definition = Twiddle (); - if (definition != NULL) { - - // - // Indirect the creation to the definition we randomly selected - // - retval = definition->Create (); - - } - - return retval; -} - - -////////////////////////////////////////////////////////////////////////////////// -// -// Get_Factory -// -////////////////////////////////////////////////////////////////////////////////// -const PersistFactoryClass & -TwiddlerClass::Get_Factory (void) const -{ - return _TwiddlerPersistFactory; -} - - -////////////////////////////////////////////////////////////////////////////////// -// -// Save -// -////////////////////////////////////////////////////////////////////////////////// -bool -TwiddlerClass::Save (ChunkSaveClass &csave) -{ - bool retval = true; - - csave.Begin_Chunk (CHUNKID_VARIABLES); - retval &= Save_Variables (csave); - csave.End_Chunk (); - - csave.Begin_Chunk (CHUNKID_BASE_CLASS); - retval &= DefinitionClass::Save (csave); - csave.End_Chunk (); - - return retval; -} - - -////////////////////////////////////////////////////////////////////////////////// -// -// Load -// -////////////////////////////////////////////////////////////////////////////////// -bool -TwiddlerClass::Load (ChunkLoadClass &cload) -{ - bool retval = true; - - while (cload.Open_Chunk ()) { - switch (cload.Cur_Chunk_ID ()) { - - case CHUNKID_VARIABLES: - retval &= Load_Variables (cload); - break; - - case CHUNKID_BASE_CLASS: - retval &= DefinitionClass::Load (cload); - break; - } - - cload.Close_Chunk (); - } - - return retval; -} - - -////////////////////////////////////////////////////////////////////////////////// -// -// Save_Variables -// -////////////////////////////////////////////////////////////////////////////////// -bool -TwiddlerClass::Save_Variables (ChunkSaveClass &csave) -{ - WRITE_MICRO_CHUNK (csave, VARID_INDIRECT_CLASSID, m_IndirectClassID) - - for (int index = 0; index < m_DefinitionList.Count (); index ++) { - - // - // Save this definition ID to the chunk - // - int def_id = m_DefinitionList[index]; - WRITE_MICRO_CHUNK (csave, VARID_DEFINTION_ID, def_id) - } - - return true; -} - - -////////////////////////////////////////////////////////////////////////////////// -// -// Load_Variables -// -////////////////////////////////////////////////////////////////////////////////// -bool -TwiddlerClass::Load_Variables (ChunkLoadClass &cload) -{ - // - // Start fresh - // - m_DefinitionList.Delete_All (); - - // - // Loop through all the microchunks that define the variables - // - while (cload.Open_Micro_Chunk ()) { - switch (cload.Cur_Micro_Chunk_ID ()) { - - READ_MICRO_CHUNK (cload, VARID_INDIRECT_CLASSID, m_IndirectClassID) - - case VARID_DEFINTION_ID: - { - // - // Read the definition ID from the chunk and add it - // to our list - // - int def_id = 0; - cload.Read (&def_id, sizeof (def_id)); - m_DefinitionList.Add (def_id); - } - break; - } - - cload.Close_Micro_Chunk (); - } - - return true; -} \ No newline at end of file diff --git a/Generals/Code/Libraries/Source/WWVegas/WWSaveLoad/twiddler.h b/Generals/Code/Libraries/Source/WWVegas/WWSaveLoad/twiddler.h deleted file mode 100644 index f8d85a2755b..00000000000 --- a/Generals/Code/Libraries/Source/WWVegas/WWSaveLoad/twiddler.h +++ /dev/null @@ -1,130 +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 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 : WWSaveLoad * - * * - * $Archive:: /Commando/Code/wwsaveload/twiddler.h $* - * * - * Author:: Patrick Smith * - * * - * $Modtime:: 6/27/00 2:34p $* - * * - * $Revision:: 2 $* - * * - *---------------------------------------------------------------------------------------------* - * Functions: * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - -#if defined(_MSC_VER) -#pragma once -#endif - -#ifndef __TWIDDLER_H -#define __TWIDDLER_H - -#include "definition.h" -#include "definitionclassids.h" - - -////////////////////////////////////////////////////////////////////////////////// -// -// TwiddlerClass -// -////////////////////////////////////////////////////////////////////////////////// -class TwiddlerClass : public DefinitionClass -{ -public: - - ///////////////////////////////////////////////////////////////////// - // Editable interface requirements - ///////////////////////////////////////////////////////////////////// - DECLARE_EDITABLE(TwiddlerClass, DefinitionClass); - - ///////////////////////////////////////////////////////////////////// - // Public constructors/destructors - ///////////////////////////////////////////////////////////////////// - TwiddlerClass (void); - virtual ~TwiddlerClass (void); - - ///////////////////////////////////////////////////////////////////// - // Public methods - ///////////////////////////////////////////////////////////////////// - - // - // Type identification - // - uint32 Get_Class_ID (void) const { return CLASSID_TWIDDLERS; } - PersistClass * Create (void) const; - - // - // From PersistClass - // - bool Save (ChunkSaveClass &csave); - bool Load (ChunkLoadClass &cload); - const PersistFactoryClass & Get_Factory (void) const; - - // - // Twiddler specific - // - virtual DefinitionClass * Twiddle (void) const; - virtual uint32 Get_Indirect_Class_ID (void) const; - virtual void Set_Indirect_Class_ID (uint32 class_id); - -private: - - ///////////////////////////////////////////////////////////////////// - // Private methods - ///////////////////////////////////////////////////////////////////// - bool Save_Variables (ChunkSaveClass &csave); - bool Load_Variables (ChunkLoadClass &cload); - - ///////////////////////////////////////////////////////////////////// - // Private member data - ///////////////////////////////////////////////////////////////////// - uint32 m_IndirectClassID; - DynamicVectorClass m_DefinitionList; -}; - - -///////////////////////////////////////////////////////////////////// -// Get_Indirect_Class_ID -///////////////////////////////////////////////////////////////////// -inline uint32 -TwiddlerClass::Get_Indirect_Class_ID (void) const -{ - return m_IndirectClassID; -} - - -///////////////////////////////////////////////////////////////////// -// Set_Indirect_Class_ID -///////////////////////////////////////////////////////////////////// -inline void -TwiddlerClass::Set_Indirect_Class_ID (uint32 class_id) -{ - m_IndirectClassID = class_id; - return ; -} - - -#endif //__TWIDDLER_H - diff --git a/Generals/Code/Libraries/Source/WWVegas/WWSaveLoad/wwsaveload.cpp b/Generals/Code/Libraries/Source/WWVegas/WWSaveLoad/wwsaveload.cpp deleted file mode 100644 index e6c179a80ac..00000000000 --- a/Generals/Code/Libraries/Source/WWVegas/WWSaveLoad/wwsaveload.cpp +++ /dev/null @@ -1,52 +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 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 : wwsaveload * - * * - * $Archive:: /Commando/Code/wwsaveload/wwsaveload.cpp $* - * * - * Original Author:: Greg Hjelstrom * - * * - * $Author:: Greg_h $* - * * - * $Modtime:: 3/28/00 9:18a $* - * * - * $Revision:: 2 $* - * * - *---------------------------------------------------------------------------------------------* - * Functions: * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - -#include "wwsaveload.h" -#include "definitionmgr.h" - - -void WWSaveLoad::Init(void) -{ -} - -void WWSaveLoad::Shutdown(void) -{ - _TheDefinitionMgr.Free_Definitions(); -} - - diff --git a/Generals/Code/Libraries/Source/WWVegas/WWSaveLoad/wwsaveload.h b/Generals/Code/Libraries/Source/WWVegas/WWSaveLoad/wwsaveload.h deleted file mode 100644 index 0c8a7d69e69..00000000000 --- a/Generals/Code/Libraries/Source/WWVegas/WWSaveLoad/wwsaveload.h +++ /dev/null @@ -1,60 +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 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 : WWSaveLoad * - * * - * $Archive:: /Commando/Code/wwsaveload/wwsaveload.h $* - * * - * Original Author:: Greg Hjelstrom * - * * - * $Author:: Greg_h $* - * * - * $Modtime:: 3/28/00 9:20a $* - * * - * $Revision:: 2 $* - * * - *---------------------------------------------------------------------------------------------* - * Functions: * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - -#if defined(_MSC_VER) -#pragma once -#endif - -#ifndef WWSAVELOAD_H -#define WWSAVELOAD_H - -/** -** WWSaveLoad -** The Init and Shutdown functions should be called once by the App. -*/ - -class WWSaveLoad -{ -public: - static void Init(void); - static void Shutdown(void); -}; - - -#endif - diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/CMakeLists.txt b/GeneralsMD/Code/Libraries/Source/WWVegas/CMakeLists.txt index 11dafc467f4..dad182a3d33 100644 --- a/GeneralsMD/Code/Libraries/Source/WWVegas/CMakeLists.txt +++ b/GeneralsMD/Code/Libraries/Source/WWVegas/CMakeLists.txt @@ -19,15 +19,11 @@ target_include_directories(z_wwcommon INTERFACE . WW3D2 WWAudio - WWMath - WWSaveLoad Wwutil ) add_subdirectory(WWAudio) -add_subdirectory(WWMath) add_subdirectory(Wwutil) -add_subdirectory(WWSaveLoad) add_subdirectory(WW3D2) add_subdirectory(WWDownload) @@ -38,8 +34,6 @@ target_include_directories(z_wwvegas INTERFACE . WW3D2 WWDownload - WWMath - WWSaveLoad Wwutil ) @@ -47,7 +41,5 @@ target_link_libraries(z_wwvegas INTERFACE core_wwvegas z_ww3d2 z_wwdownload - z_wwmath - z_wwsaveload z_wwutil ) diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWSaveLoad/CMakeLists.txt b/GeneralsMD/Code/Libraries/Source/WWVegas/WWSaveLoad/CMakeLists.txt deleted file mode 100644 index bdc2b6bba0d..00000000000 --- a/GeneralsMD/Code/Libraries/Source/WWVegas/WWSaveLoad/CMakeLists.txt +++ /dev/null @@ -1,47 +0,0 @@ -# Set source files -set(WWSAVELOAD_SRC - definition.cpp - definition.h - definitionclassids.h - definitionfactory.cpp - definitionfactory.h - definitionfactorymgr.cpp - definitionfactorymgr.h - definitionmgr.cpp - definitionmgr.h - editable.h - parameter.cpp - parameter.h - parameterlist.h - parametertypes.h - persist.h - persistfactory.cpp - persistfactory.h - pointerremap.cpp - pointerremap.h - postloadable.h - saveload.cpp - saveload.h - saveloadids.h - saveloadstatus.cpp - saveloadstatus.h - saveloadstatus.h - saveloadsubsystem.cpp - saveloadsubsystem.h - simpledefinitionfactory.h - simpleparameter.h - twiddler.cpp - twiddler.h - wwsaveload.cpp - wwsaveload.h -) - -# Targets to build. -add_library(z_wwsaveload STATIC) -set_target_properties(z_wwsaveload PROPERTIES OUTPUT_NAME wwsaveload) - -target_sources(z_wwsaveload PRIVATE ${WWSAVELOAD_SRC}) - -target_link_libraries(z_wwsaveload PRIVATE - z_wwcommon -)