Esempio n. 1
0
    private bool CheckCapsuleAndCapsule(HitableCapsule capsuleA, HitableCapsule capsuleB)
    {
        // 求两个线段离得最近的点,求点之间的距离
        // 距离小于半径之和就碰撞

        return(false);
    }
Esempio n. 2
0
    private bool CheckCapsuleAndSphere(HitableCapsule capsule, HitableSphere sphere)
    {
        var dx = sphere.Point.x - capsule.Point.x;
        var dy = sphere.Point.y - capsule.Point.y;
        var t  = (capsule.Vec.x * dx + capsule.Vec.y * dy) /
                 (capsule.Vec.x * capsule.Vec.x + capsule.Vec.y * capsule.Vec.y);

        t = Mathf.Clamp01(t);

        var mx = capsule.Vec.x * t + capsule.Point.x;
        var my = capsule.Vec.y * t + capsule.Point.y;

        var disSqrt = (mx - sphere.Point.x) * (mx - sphere.Point.x) +
                      (my - sphere.Point.y) * (my - sphere.Point.y);

        var radiusSum = capsule.Radius + sphere.Radius;

        if (disSqrt <= radiusSum * radiusSum)
        {
            return(true);
        }

        return(false);
    }
Esempio n. 3
0
 private bool CheckCapsuleAndCube(HitableCapsule capsule, HitableCube cube)
 {
     return(false);
 }