Skip to content

Commit

Permalink
Simplify face_contains
Browse files Browse the repository at this point in the history
  • Loading branch information
VirxEC committed May 11, 2024
1 parent 99b50b3 commit 96654f4
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/simulation/geometry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,13 @@ impl Tri {
/// This is used instead of bullet's method because it's much faster:
/// <https://gamedev.stackexchange.com/a/152476>
fn face_contains(u: Vec3A, v: Vec3A, n: Vec3A, w: Vec3A) -> bool {
let gamma = u.cross(w).dot(n) / n.dot(n);
let beta = w.cross(v).dot(n) / n.dot(n);
let dot_n = n.dot(n);

let gamma = u.cross(w).dot(n) / dot_n;
let beta = w.cross(v).dot(n) / dot_n;
let alpha = 1. - gamma - beta;

let gba = Vec3A::new(gamma, beta, alpha);
gba.cmple(Vec3A::ONE).all() && gba.cmpge(Vec3A::ZERO).all()
(gamma >= 0. && beta >= 0. && alpha >= 0.) && (gamma <= 1. && beta <= 1. && alpha <= 1.)
}

/// Instead of using bullet's method,
Expand Down

0 comments on commit 96654f4

Please sign in to comment.