This commit is contained in:
2025-11-20 08:45:15 -08:00
parent 0ea353b27d
commit b0668136d6
2 changed files with 79 additions and 1 deletions

View File

@@ -1,7 +1,8 @@
mod body;
mod push_solve;
mod face_crawler;
mod model;
mod push_solve;
mod minimum_difference;
pub mod physics;

View File

@@ -0,0 +1,77 @@
use strafesnet_common::integer::{Planar64, Planar64Vec3};
use crate::model::TransformedMesh;
// This algorithm is based on Lua code
// written by Trey Reynolds in 2021
// local function minimumDifference(
// queryP, radiusP,
// queryQ, radiusQ,
// exitRadius, testIntersection
// )
pub struct MinimumDifference{
distance:Planar64,
p_pos:Planar64Vec3,
p_norm:Planar64Vec3,
q_pos:Planar64Vec3,
q_norm:Planar64Vec3,
}
pub fn minimum_difference(p:&TransformedMesh,q:&TransformedMesh)->Option<MinimumDifference>{
// local initialAxis = queryQ() - queryP()
// local newPoint0 = queryP(initialAxis)
// local newPoint1 = queryQ(-initialAxis)
// local direction, a0, a1, b0, b1, c0, c1, d0, d1
// exitRadius = testIntersection and 0 or exitRadius or 1/0
// for _ = 1, 100 do
// direction, a0, a1, b0, b1, c0, c1, d0, d1 = reduceSimplex(newPoint0, newPoint1, a0, a1, b0, b1, c0, c1)
// local a, b, c, d = getRelativeSimplex(a0, a1, b0, b1, c0, c1, d0, d1)
// if a and b and c and d then
// if testIntersection then
// return true
// end
// local norm, dist, u0, u1, v0, v1, w0, w1 = expand(queryP, queryQ, a0, a1, b0, b1, c0, c1, d0, d1, 1e-5)
// if norm then
// local posP, posQ = decompose(Vector3.zero, u0, u1, v0, v1, w0, w1)
// return true, -dist - radiusP - radiusQ,
// posP - radiusP*norm, -norm,
// posQ + radiusQ*norm, norm
// end
// return nil
// end
// newPoint0 = queryP(-direction)
// newPoint1 = queryQ(direction)
// local newPoint = newPoint1 - newPoint0
// if -direction:Dot(newPoint) > (exitRadius + radiusP + radiusQ)*direction.magnitude then
// return false
// end
// if
// direction:Dot(newPoint - a) <= 0 or
// absDet(newPoint, a, b, c) < 1e-6
// then
// local norm = direction.unit
// local dist = a:Dot(norm)
// local hits = -dist < radiusP + radiusQ
// if testIntersection then
// return hits
// end
// if -dist <= exitRadius + radiusP + radiusQ then
// local posP, posQ = decompose(Vector3.zero, a0, a1, b0, b1, c0, c1)
// return hits, -dist - radiusP - radiusQ,
// posP - radiusP*norm, -norm,
// posQ + radiusQ*norm, norm
// end
// return false
// end
// end
// return nil
None
}