Beispiel #1
0
    private void CollisionCapsuleBox()
    {
        FixedList128 <float3> verticesOBB = ColPhysics.GetAABBVerticesOBB(posB, extentsB);

        verticesOBB = ColPhysics.GetRotatedVerticesOBB(verticesOBB, posB, rotB);
        FixedList128 <float3> normalAxesOBB = ColPhysics.GetAxisNormalsOBB(verticesOBB[0], verticesOBB[1], verticesOBB[3], verticesOBB[4]);
        FixedList128 <float>  exte          = new FixedList128 <float>();

        exte.Add(extentsB.x);
        exte.Add(extentsB.y);
        exte.Add(extentsB.z);

        float3x2 capsuleTips    = ColPhysics.GetCapsuleEndPoints(posA, rotA, extentsA.y * 2);
        float3x2 capsuleSpheres = ColPhysics.GetCapsuleEndSpheres(capsuleTips.c0, capsuleTips.c1, extentsA.x);

        if (ColPhysics.CapsuleIntersectsBox(capsuleSpheres, posB, extentsA.x, normalAxesOBB, exte, out float distance))
        {
            isColliding = true;

            if (resolveCollisions)
            {
                ColPhysics.ResolveSphereBoxCollision(ref posA, extentsA.x, ref posB, distance);
            }
        }
    }
Beispiel #2
0
    private void CollisionSphereBox()
    {
        float3 spherePos    = posA;
        float3 obbPos       = posB;
        float3 obbRot       = rotB;
        float3 obbHalfSize  = extentsB;
        float  sphereRadius = extentsA.x;

        FixedList128 <float3> vertices = ColPhysics.GetAABBVerticesOBB(obbPos, obbHalfSize);   // calculated once at startup forever stored with entity

        vertices = ColPhysics.GetRotatedVerticesOBB(vertices, obbPos, obbRot);
        FixedList128 <float> extents = new FixedList128 <float>(); // calculated once at startup forever stored with entity

        extents.Add(extentsB.x);
        extents.Add(extentsB.y);
        extents.Add(extentsB.z);

        FixedList128 <float3> axisNormals = ColPhysics.GetAxisNormalsOBB(vertices[0], vertices[1], vertices[3], vertices[4]);

        if (ColPhysics.SphereIntersectsBox(spherePos, sphereRadius, obbPos, axisNormals, extents, out float distance))
        {
            isColliding = true;

            if (resolveCollisions)
            {
                ColPhysics.ResolveSphereBoxCollision(ref spherePos, sphereRadius, ref obbPos, distance);
                posA = spherePos;
                posB = obbPos;
            }
        }
    }
Beispiel #3
0
    private void CollisionBoxBox()
    {
        FixedList128 <float3> verticesA = ColPhysics.GetAABBVerticesOBB(posA, extentsA);
        FixedList128 <float3> verticesB = ColPhysics.GetAABBVerticesOBB(posB, extentsB);

        verticesA = ColPhysics.GetRotatedVerticesOBB(verticesA, posA, rotA);
        verticesB = ColPhysics.GetRotatedVerticesOBB(verticesB, posB, rotB);
        FixedList512 <float3> projectionAxes = ColPhysics.GetProjectionAxesOBBSAT(verticesA, verticesB);

        if (ColPhysics.BoxIntersectsBox(projectionAxes, verticesA, verticesB, out float minOverlap, out float3 mtvAxis))
        {
            isColliding = true;

            if (resolveCollisions)
            {
                ColPhysics.ResolveBoxCollision(ref posA, ref posB, minOverlap, mtvAxis);
            }
        }
    }