Merge branch 'dev', version 3.1.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
ed622216f9
5 changed files with 133 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})
|
add_library(SC_3D_CollisionDetectionHelpers ${SC_3D_CollisionDetectionHelpers_SOURCES})
|
||||||
|
|
||||||
set_target_properties(SC_3D_CollisionDetectionHelpers PROPERTIES VERSION 3.0.1 SOVERSION 3)
|
set_target_properties(SC_3D_CollisionDetectionHelpers PROPERTIES VERSION 3.1.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 "")
|
||||||
|
|
|
@ -1,5 +1,11 @@
|
||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## Version 3.1.0
|
||||||
|
|
||||||
|
Add Vec3 helper functions.
|
||||||
|
|
||||||
|
Add Vec3 project and reflect functions.
|
||||||
|
|
||||||
## Version 3.0.1
|
## Version 3.0.1
|
||||||
|
|
||||||
Remove unnecessary header include in sc_sacd.cpp. This should fix builds that
|
Remove unnecessary header include in sc_sacd.cpp. This should fix builds that
|
||||||
|
|
|
@ -669,3 +669,29 @@ SC_SACD_AABB_Box SC_SACD_AABB_Combine(SC_SACD_AABB_Box a, SC_SACD_AABB_Box b) {
|
||||||
temp_b,
|
temp_b,
|
||||||
temp_c};
|
temp_c};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SC_SACD_Vec3 SC_SACD_Vec3_Sum(SC_SACD_Vec3 a, SC_SACD_Vec3 b) { return a + b; }
|
||||||
|
|
||||||
|
SC_SACD_Vec3 SC_SACD_Vec3_Difference(SC_SACD_Vec3 a, SC_SACD_Vec3 b) {
|
||||||
|
return a - b;
|
||||||
|
}
|
||||||
|
|
||||||
|
SC_SACD_Vec3 SC_SACD_Vec3_Mult(SC_SACD_Vec3 vec, float scalar) {
|
||||||
|
return vec * scalar;
|
||||||
|
}
|
||||||
|
|
||||||
|
SC_SACD_Vec3 SC_SACD_Vec3_Div(SC_SACD_Vec3 vec, float scalar) {
|
||||||
|
return vec / scalar;
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
return target * (upper_dot_product / lower_dot_product);
|
||||||
|
}
|
||||||
|
|
||||||
|
SC_SACD_Vec3 SC_SACD_Vec3_Reflect(SC_SACD_Vec3 vec, SC_SACD_Vec3 target) {
|
||||||
|
SC_SACD_Vec3 proj = SC_SACD_Vec3_Project(vec, target);
|
||||||
|
return proj * 2.0F - vec;
|
||||||
|
}
|
||||||
|
|
|
@ -136,6 +136,20 @@ SC_SACD_Generic_Box_To_AABB(SC_SACD_Generic_Box s);
|
||||||
SC_SACD_EXPORT SC_SACD_AABB_Box SC_SACD_AABB_Combine(SC_SACD_AABB_Box a,
|
SC_SACD_EXPORT SC_SACD_AABB_Box SC_SACD_AABB_Combine(SC_SACD_AABB_Box a,
|
||||||
SC_SACD_AABB_Box b);
|
SC_SACD_AABB_Box b);
|
||||||
|
|
||||||
|
SC_SACD_EXPORT SC_SACD_Vec3 SC_SACD_Vec3_Sum(SC_SACD_Vec3 a, SC_SACD_Vec3 b);
|
||||||
|
SC_SACD_EXPORT SC_SACD_Vec3 SC_SACD_Vec3_Difference(SC_SACD_Vec3 a,
|
||||||
|
SC_SACD_Vec3 b);
|
||||||
|
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);
|
||||||
|
|
||||||
|
/// Projects "vec" onto "target".
|
||||||
|
SC_SACD_EXPORT SC_SACD_Vec3 SC_SACD_Vec3_Project(SC_SACD_Vec3 vec,
|
||||||
|
SC_SACD_Vec3 target);
|
||||||
|
|
||||||
|
/// Reflects "vec" about "target".
|
||||||
|
SC_SACD_EXPORT SC_SACD_Vec3 SC_SACD_Vec3_Reflect(SC_SACD_Vec3 vec,
|
||||||
|
SC_SACD_Vec3 target);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
86
src/test.cpp
86
src/test.cpp
|
@ -754,6 +754,92 @@ int main() {
|
||||||
2.0F);
|
2.0F);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Test Sum/Diff/Mult/Div Vec3.
|
||||||
|
{
|
||||||
|
SC_SACD_Vec3 a{1.0F, 2.0F, 3.0F};
|
||||||
|
SC_SACD_Vec3 b{10.0F, 100.0F, 1000.0F};
|
||||||
|
|
||||||
|
SC_SACD_Vec3 vec_result = SC_SACD_Vec3_Sum(a, b);
|
||||||
|
CHECK_FLOAT(vec_result.x, 11.0F);
|
||||||
|
CHECK_FLOAT(vec_result.y, 102.0F);
|
||||||
|
CHECK_FLOAT(vec_result.z, 1003.0F);
|
||||||
|
|
||||||
|
vec_result = SC_SACD_Vec3_Difference(a, b);
|
||||||
|
CHECK_FLOAT(vec_result.x, -9.0F);
|
||||||
|
CHECK_FLOAT(vec_result.y, -98.0F);
|
||||||
|
CHECK_FLOAT(vec_result.z, -997.0F);
|
||||||
|
|
||||||
|
vec_result = SC_SACD_Vec3_Mult(a, 2.0F);
|
||||||
|
CHECK_FLOAT(vec_result.x, 2.0F);
|
||||||
|
CHECK_FLOAT(vec_result.y, 4.0F);
|
||||||
|
CHECK_FLOAT(vec_result.z, 6.0F);
|
||||||
|
|
||||||
|
vec_result = SC_SACD_Vec3_Div(a, 2.0F);
|
||||||
|
CHECK_FLOAT(vec_result.x, 0.5F);
|
||||||
|
CHECK_FLOAT(vec_result.y, 1.0F);
|
||||||
|
CHECK_FLOAT(vec_result.z, 1.5F);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test project.
|
||||||
|
{
|
||||||
|
SC_SACD_Vec3 a{2.0F, 3.0F, 4.0F};
|
||||||
|
SC_SACD_Vec3 target{0.0F, 1.0F, 0.0F};
|
||||||
|
|
||||||
|
SC_SACD_Vec3 result = SC_SACD_Vec3_Project(a, target);
|
||||||
|
CHECK_FLOAT(result.x, 0.0F);
|
||||||
|
CHECK_FLOAT(result.y, 3.0F);
|
||||||
|
CHECK_FLOAT(result.z, 0.0F);
|
||||||
|
|
||||||
|
target.x = 2.0F;
|
||||||
|
target.y = 0.0F;
|
||||||
|
result = SC_SACD_Vec3_Project(a, target);
|
||||||
|
CHECK_FLOAT(result.x, 2.0F);
|
||||||
|
CHECK_FLOAT(result.y, 0.0F);
|
||||||
|
CHECK_FLOAT(result.z, 0.0F);
|
||||||
|
|
||||||
|
target.x = 0.0F;
|
||||||
|
target.z = 9.0F;
|
||||||
|
result = SC_SACD_Vec3_Project(a, target);
|
||||||
|
CHECK_FLOAT(result.x, 0.0F);
|
||||||
|
CHECK_FLOAT(result.y, 0.0F);
|
||||||
|
CHECK_FLOAT(result.z, 4.0F);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test reflect.
|
||||||
|
{
|
||||||
|
SC_SACD_Vec3 a{2.0F, 3.0F, 4.0F};
|
||||||
|
SC_SACD_Vec3 target{0.0F, 3.0F, 0.0F};
|
||||||
|
|
||||||
|
SC_SACD_Vec3 result = SC_SACD_Vec3_Reflect(a, target);
|
||||||
|
CHECK_FLOAT(result.x, -2.0F);
|
||||||
|
CHECK_FLOAT(result.y, 3.0F);
|
||||||
|
CHECK_FLOAT(result.z, -4.0F);
|
||||||
|
|
||||||
|
target.x = 9.0F;
|
||||||
|
target.y = 0.0F;
|
||||||
|
|
||||||
|
result = SC_SACD_Vec3_Reflect(a, target);
|
||||||
|
CHECK_FLOAT(result.x, 2.0F);
|
||||||
|
CHECK_FLOAT(result.y, -3.0F);
|
||||||
|
CHECK_FLOAT(result.z, -4.0F);
|
||||||
|
|
||||||
|
target.x = 0.0F;
|
||||||
|
target.z = 110.0F;
|
||||||
|
|
||||||
|
result = SC_SACD_Vec3_Reflect(a, target);
|
||||||
|
CHECK_FLOAT(result.x, -2.0F);
|
||||||
|
CHECK_FLOAT(result.y, -3.0F);
|
||||||
|
CHECK_FLOAT(result.z, 4.0F);
|
||||||
|
|
||||||
|
target.y = 1.0F;
|
||||||
|
target.z = 1.0F;
|
||||||
|
|
||||||
|
result = SC_SACD_Vec3_Reflect(a, target);
|
||||||
|
CHECK_FLOAT(result.x, -2.0F);
|
||||||
|
CHECK_FLOAT(result.y, 4.0F);
|
||||||
|
CHECK_FLOAT(result.z, 3.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';
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue