Exemplo n.º 1
0
    static public CollisionInfo CircleOBB(CircleCollision3D circle, ObjectBoundingBoxCollision3D rect)
    {
        //transform circle into obb space transform.InverseTransformPoint(cirecle.postion);
        //then do circle AABB
        Vector3 halfExtend  = (rect.posMax - rect.posMin) / 2;
        Vector3 circleInOBB = rect.GetComponent <Particle3D>().GetWorldToObject().MultiplyPoint(circle.center);//rect.transform.InverseTransformPoint(circle.center);
        Vector3 circleBox   = new Vector3(
            Mathf.Max(-halfExtend.x, Mathf.Min(circleInOBB.x, halfExtend.x)),
            Mathf.Max(-halfExtend.y, Mathf.Min(circleInOBB.y, halfExtend.y)),
            Mathf.Max(-halfExtend.z, Mathf.Min(circleInOBB.z, halfExtend.z)));

        Vector3 distanceVec = circleInOBB - circleBox;
        float   distanceSQ  = Vector3.Dot(distanceVec, distanceVec);

        //Debug.DrawLine(circleBox, circle.center);


        if (distanceSQ <= (circle.radius * circle.radius))
        {
            //return true;
            //Debug.Log("circ obb collision");
            float distance = Mathf.Sqrt(distanceSQ);
            return(new CollisionInfo(circle, rect, rect.transform.TransformVector(-distanceVec).normalized, circle.radius - distance));
        }

        return(null);
    }
Exemplo n.º 2
0
        public CollisionInfo(ObjectBoundingBoxCollision3D colA, ObjectBoundingBoxCollision3D colB, Vector3 normal, float penetration)
        {
            RigidBodyA = colA.GetComponent <Particle3D>();
            RigidBodyB = colB.GetComponent <Particle3D>();


            RelativeVelocity = RigidBodyB.velocity - RigidBodyA.velocity;

            contacts[0].normal      = normal;
            contacts[0].penetration = penetration;
            contacts[0].restitution = Mathf.Min(RigidBodyA.restitution, RigidBodyB.restitution);
        }