Merge branch 'dev', version 3.2.0
All checks were successful
Run UnitTest / build-and-run-UnitTest (push) Successful in 5s

This commit is contained in:
Stephen Seo 2024-05-10 13:25:09 +09:00
commit 3cf5815c95
5 changed files with 80 additions and 1 deletions

View file

@ -6,7 +6,7 @@ set(SC_3D_CollisionDetectionHelpers_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/src/sc_
add_library(SC_3D_CollisionDetectionHelpers ${SC_3D_CollisionDetectionHelpers_SOURCES}) add_library(SC_3D_CollisionDetectionHelpers ${SC_3D_CollisionDetectionHelpers_SOURCES})
set_target_properties(SC_3D_CollisionDetectionHelpers PROPERTIES VERSION 3.1.0 SOVERSION 3) set_target_properties(SC_3D_CollisionDetectionHelpers PROPERTIES VERSION 3.2.0 SOVERSION 3)
target_compile_features(SC_3D_CollisionDetectionHelpers PUBLIC cxx_std_20) target_compile_features(SC_3D_CollisionDetectionHelpers PUBLIC cxx_std_20)
if(NOT DEFINED CMAKE_BUILD_TYPE OR "${CMAKE_BUILD_TYPE}" STREQUAL "") if(NOT DEFINED CMAKE_BUILD_TYPE OR "${CMAKE_BUILD_TYPE}" STREQUAL "")

View file

@ -1,5 +1,9 @@
# Changelog # Changelog
## Version 3.2.0
Add Vec3 negate and normalize functions.
## Version 3.1.0 ## Version 3.1.0
Add Vec3 helper functions. Add Vec3 helper functions.

View file

@ -684,6 +684,14 @@ SC_SACD_Vec3 SC_SACD_Vec3_Div(SC_SACD_Vec3 vec, float scalar) {
return vec / scalar; return vec / scalar;
} }
SC_SACD_Vec3 SC_SACD_Vec3_Negate(SC_SACD_Vec3 vec) {
return SC_SACD_Vec3{-vec.x, -vec.y, -vec.z};
}
SC_SACD_Vec3 SC_SACD_Vec3_Normalize(SC_SACD_Vec3 vec) {
return vec / SC_SACD_Vec3_Length(vec);
}
SC_SACD_Vec3 SC_SACD_Vec3_Project(SC_SACD_Vec3 vec, SC_SACD_Vec3 target) { SC_SACD_Vec3 SC_SACD_Vec3_Project(SC_SACD_Vec3 vec, SC_SACD_Vec3 target) {
float upper_dot_product = SC_SACD_Dot_Product(vec, target); float upper_dot_product = SC_SACD_Dot_Product(vec, target);
float lower_dot_product = SC_SACD_Dot_Product(target, target); float lower_dot_product = SC_SACD_Dot_Product(target, target);

View file

@ -142,6 +142,11 @@ SC_SACD_EXPORT SC_SACD_Vec3 SC_SACD_Vec3_Difference(SC_SACD_Vec3 a,
SC_SACD_EXPORT SC_SACD_Vec3 SC_SACD_Vec3_Mult(SC_SACD_Vec3 vec, float scalar); SC_SACD_EXPORT SC_SACD_Vec3 SC_SACD_Vec3_Mult(SC_SACD_Vec3 vec, float scalar);
SC_SACD_EXPORT SC_SACD_Vec3 SC_SACD_Vec3_Div(SC_SACD_Vec3 vec, float scalar); SC_SACD_EXPORT SC_SACD_Vec3 SC_SACD_Vec3_Div(SC_SACD_Vec3 vec, float scalar);
SC_SACD_EXPORT SC_SACD_Vec3 SC_SACD_Vec3_Negate(SC_SACD_Vec3 vec);
/// Turns vec into a unit vector and returns the unit vector.
SC_SACD_EXPORT SC_SACD_Vec3 SC_SACD_Vec3_Normalize(SC_SACD_Vec3 vec);
/// Projects "vec" onto "target". /// Projects "vec" onto "target".
SC_SACD_EXPORT SC_SACD_Vec3 SC_SACD_Vec3_Project(SC_SACD_Vec3 vec, SC_SACD_EXPORT SC_SACD_Vec3 SC_SACD_Vec3_Project(SC_SACD_Vec3 vec,
SC_SACD_Vec3 target); SC_SACD_Vec3 target);

View file

@ -840,6 +840,68 @@ int main() {
CHECK_FLOAT(result.z, 3.0F); CHECK_FLOAT(result.z, 3.0F);
} }
// Test negate.
{
SC_SACD_Vec3 vec{1.0F, 2.0F, 3.0F};
vec = SC_SACD_Vec3_Negate(vec);
CHECK_FLOAT(vec.x, -1.0F);
CHECK_FLOAT(vec.y, -2.0F);
CHECK_FLOAT(vec.z, -3.0F);
}
// Test normalize.
{
SC_SACD_Vec3 vec{1.0F, 0.0F, 0.0F};
vec = SC_SACD_Vec3_Normalize(vec);
CHECK_FLOAT(vec.x, 1.0F);
CHECK_FLOAT(vec.y, 0.0F);
CHECK_FLOAT(vec.z, 0.0F);
vec.x = 0.0F;
vec.y = -1.0F;
vec = SC_SACD_Vec3_Normalize(vec);
CHECK_FLOAT(vec.x, 0.0F);
CHECK_FLOAT(vec.y, -1.0F);
CHECK_FLOAT(vec.z, 0.0F);
vec.y = 0.0F;
vec.z = 0.7F;
vec = SC_SACD_Vec3_Normalize(vec);
CHECK_FLOAT(vec.x, 0.0F);
CHECK_FLOAT(vec.y, 0.0F);
CHECK_FLOAT(vec.z, 1.0F);
vec.x = 1.0F;
vec = SC_SACD_Vec3_Normalize(vec);
CHECK_FLOAT(vec.x, std::sqrt(0.5F));
CHECK_FLOAT(vec.y, 0.0F);
CHECK_FLOAT(vec.z, std::sqrt(0.5F));
vec.x = 1.0F;
vec.y = 1.0F;
vec.z = 1.0F;
vec = SC_SACD_Vec3_Normalize(vec);
CHECK_FLOAT(vec.x, std::sqrt(1.0F / 3.0F));
CHECK_FLOAT(vec.y, std::sqrt(1.0F / 3.0F));
CHECK_FLOAT(vec.z, std::sqrt(1.0F / 3.0F));
vec.x = 1.0F;
vec.y = -1.0F;
vec.z = -1.0F;
vec = SC_SACD_Vec3_Normalize(vec);
CHECK_FLOAT(vec.x, std::sqrt(1.0F / 3.0F));
CHECK_FLOAT(vec.y, -std::sqrt(1.0F / 3.0F));
CHECK_FLOAT(vec.z, -std::sqrt(1.0F / 3.0F));
vec.x = 1.0F;
vec.y = 2.0F;
vec.z = 3.0F;
vec = SC_SACD_Vec3_Normalize(vec);
CHECK_FLOAT(vec.x, std::sqrt(1.0F / 14.0F));
CHECK_FLOAT(vec.y, std::sqrt(4.0F / 14.0F));
CHECK_FLOAT(vec.z, std::sqrt(9.0F / 14.0F));
}
std::cout << "Checks checked: " << checks_checked << '\n' std::cout << "Checks checked: " << checks_checked << '\n'
<< "Checks passed: " << checks_passed << '\n'; << "Checks passed: " << checks_passed << '\n';