Compare commits

..

No commits in common. "ed622216f9e2347c8002d267412ac8c66927bb7e" and "0aa8d2b09a621b7d516bef3072814ae820aaec38" have entirely different histories.

5 changed files with 1 additions and 133 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})
set_target_properties(SC_3D_CollisionDetectionHelpers PROPERTIES VERSION 3.1.0 SOVERSION 3)
set_target_properties(SC_3D_CollisionDetectionHelpers PROPERTIES VERSION 3.0.1 SOVERSION 3)
target_compile_features(SC_3D_CollisionDetectionHelpers PUBLIC cxx_std_20)
if(NOT DEFINED CMAKE_BUILD_TYPE OR "${CMAKE_BUILD_TYPE}" STREQUAL "")

View file

@ -1,11 +1,5 @@
# Changelog
## Version 3.1.0
Add Vec3 helper functions.
Add Vec3 project and reflect functions.
## Version 3.0.1
Remove unnecessary header include in sc_sacd.cpp. This should fix builds that

View file

@ -669,29 +669,3 @@ SC_SACD_AABB_Box SC_SACD_AABB_Combine(SC_SACD_AABB_Box a, SC_SACD_AABB_Box b) {
temp_b,
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;
}

View file

@ -136,20 +136,6 @@ 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_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
}
#endif

View file

@ -754,92 +754,6 @@ int main() {
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'
<< "Checks passed: " << checks_passed << '\n';