use std::ops::Neg;
use glam_det::nums::num_traits::*;
use glam_det::nums::{f32x4, u32x4};
use glam_det::{Dot, Mat3x4, UnitQuat, UnitQuatx4, Vec3, Vec3x4};
use super::common::NormalizeExt;
use crate::collision_tasks::{ShapeTester, ShapeWideTester};
use crate::convex_contact_manifold::Convex4ContactManifoldWide;
use crate::shapes::{Capsule, CapsuleWide, Sphere, SphereWide};
use crate::traits::{ContactContext, ContactManifoldWide, CreateShapeWide, PairTest, PairWideTest};
use crate::{ConvexContactManifold, ShapeContainer};
impl PairWideTest<SphereWide, CapsuleWide> for ShapeWideTester {
#[inline]
fn should_reset_manifold_before_test() -> bool {
false
}
#[inline]
fn test(
a: &SphereWide,
b: &CapsuleWide,
contact_context: &ContactContext,
manifold: &mut Convex4ContactManifoldWide,
) {
let Mat3x4 { x_axis, y_axis, .. } = Mat3x4::from_quat(*contact_context.orientation_b);
let point = y_axis
.dot(contact_context.offset_b) .neg() .clamp(-b.half_height, b.half_height) * y_axis + contact_context.offset_b;
let (internal_length, normal) = point.normalize_and_length_or(x_axis, f32x4::ZERO);
manifold.normal = normal.neg().as_unit_vec3x4_unchecked();
manifold.depth[0] = a.radius + b.radius - internal_length;
manifold.feature_id[0] = u32x4::ZERO;
manifold.offset_a[0] = manifold.normal * (-a.radius);
manifold.contact_exists[0] = manifold.depth[0].gt(-contact_context.speculative_margin);
}
}
impl_pair_narrowphase!(Sphere, Capsule, SphereWide, CapsuleWide, 1);