use glam_det::nums::*;
use glam_det::{UnitQuat, UnitQuatx4, UnitVec3x4, Vec3, Vec3x4};
use crate::collision_tasks::{ShapeTester, ShapeWideTester};
use crate::convex_contact_manifold::{Convex4ContactManifoldWide, ConvexContactManifold};
use crate::shapes::{Capsule, CapsuleWide, InfinitePlane, InfinitePlaneWide};
use crate::traits::{ContactContext, ContactManifoldWide, CreateShapeWide, PairTest, PairWideTest};
use crate::ShapeContainer;
impl PairWideTest<CapsuleWide, InfinitePlaneWide> for ShapeWideTester {
#[inline]
fn should_reset_manifold_before_test() -> bool {
false
}
#[inline]
fn test(
a: &CapsuleWide,
_b: &InfinitePlaneWide,
contact_context: &ContactContext,
manifold: &mut Convex4ContactManifoldWide,
) {
let y_axis = contact_context.orientation_a * UnitVec3x4::Y;
let capsule_in_b = contact_context.orientation_b.inverse() * (-*contact_context.offset_b);
let capsule_axis_in_b = contact_context.orientation_b.inverse() * y_axis;
let capsule_top_center_in_b = capsule_in_b + capsule_axis_in_b * a.half_height;
let capsule_bottom_center_in_b = capsule_in_b + capsule_axis_in_b * (-a.half_height);
manifold.depth[0] = a.radius - capsule_top_center_in_b.y;
manifold.depth[1] = a.radius - capsule_bottom_center_in_b.y;
manifold.contact_exists[0] = manifold.depth[0].gt(-contact_context.speculative_margin);
manifold.contact_exists[1] = manifold.depth[1].gt(-contact_context.speculative_margin);
manifold.normal = contact_context.orientation_b * InfinitePlaneWide::NORMAL;
manifold.offset_a[0] = y_axis * a.half_height - manifold.normal * a.radius;
manifold.offset_a[1] = y_axis * (-a.half_height) - manifold.normal * a.radius;
manifold.feature_id[0] = u32x4::ZERO;
manifold.feature_id[1] = u32x4::ONE;
}
}
impl_pair_narrowphase!(Capsule, InfinitePlane, CapsuleWide, InfinitePlaneWide, 2);