Merge branch 'dev', version 3.2.0
All checks were successful
Run UnitTest / build-and-run-UnitTest (push) Successful in 5s
All checks were successful
Run UnitTest / build-and-run-UnitTest (push) Successful in 5s
This commit is contained in:
commit
3cf5815c95
5 changed files with 80 additions and 1 deletions
|
@ -6,7 +6,7 @@ set(SC_3D_CollisionDetectionHelpers_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/src/sc_
|
|||
|
||||
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)
|
||||
|
||||
if(NOT DEFINED CMAKE_BUILD_TYPE OR "${CMAKE_BUILD_TYPE}" STREQUAL "")
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
# Changelog
|
||||
|
||||
## Version 3.2.0
|
||||
|
||||
Add Vec3 negate and normalize functions.
|
||||
|
||||
## Version 3.1.0
|
||||
|
||||
Add Vec3 helper functions.
|
||||
|
|
|
@ -684,6 +684,14 @@ SC_SACD_Vec3 SC_SACD_Vec3_Div(SC_SACD_Vec3 vec, float 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) {
|
||||
float upper_dot_product = SC_SACD_Dot_Product(vec, target);
|
||||
float lower_dot_product = SC_SACD_Dot_Product(target, target);
|
||||
|
|
|
@ -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_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".
|
||||
SC_SACD_EXPORT SC_SACD_Vec3 SC_SACD_Vec3_Project(SC_SACD_Vec3 vec,
|
||||
SC_SACD_Vec3 target);
|
||||
|
|
62
src/test.cpp
62
src/test.cpp
|
@ -840,6 +840,68 @@ int main() {
|
|||
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'
|
||||
<< "Checks passed: " << checks_passed << '\n';
|
||||
|
||||
|
|
Loading…
Reference in a new issue