コード例 #1
0
    public override dNewtonCollision Create(NewtonWorld world)
    {
        dNewtonCollisionScene collider = new dNewtonCollisionScene(world.GetWorld());

        SetMaterial(collider);
        return(collider);
    }
コード例 #2
0
    public NewtonBodyCollision(NewtonBody body)
    {
        List <ColliderShapePair> colliderList = new List <ColliderShapePair>();

        TraverseColliders(body.gameObject, colliderList, body.gameObject, body);

        if (body.m_isScene)
        {
            m_collidersArray = new ColliderShapePair[colliderList.Count + 1];
            NewtonSceneCollider   sceneCollider = body.gameObject.AddComponent <NewtonSceneCollider>();
            dNewtonCollisionScene sceneShape    = (dNewtonCollisionScene)sceneCollider.Create(body.m_world);

            m_collidersArray[0].m_shape    = sceneShape;
            m_collidersArray[0].m_collider = sceneCollider;

            int index = 1;
            sceneShape.BeginAddRemoveCollision();
            foreach (ColliderShapePair pair in colliderList)
            {
                m_collidersArray[index] = pair;
                sceneShape.AddCollision(pair.m_shape);
                index++;
            }
            sceneShape.EndAddRemoveCollision();
        }
        else if (colliderList.Count == 0)
        {
            m_collidersArray = new ColliderShapePair[1];
            NewtonCollider collider = body.gameObject.AddComponent <NewtonNullCollider>();
            m_collidersArray[0].m_collider = collider;
            m_collidersArray[0].m_shape    = collider.Create(body.m_world);
        }
        else if (colliderList.Count == 1)
        {
            m_collidersArray    = new ColliderShapePair[1];
            m_collidersArray[0] = colliderList[0];
        }
        else
        {
            m_collidersArray = new ColliderShapePair[colliderList.Count + 1];
            NewtonCompoundCollider   compoundCollider = body.gameObject.AddComponent <NewtonCompoundCollider>();
            dNewtonCollisionCompound compoundShape    = (dNewtonCollisionCompound)compoundCollider.Create(body.m_world);

            m_collidersArray[0].m_shape    = compoundShape;
            m_collidersArray[0].m_collider = compoundCollider;

            int index = 1;
            compoundShape.BeginAddRemoveCollision();
            foreach (ColliderShapePair pair in colliderList)
            {
                m_collidersArray[index] = pair;
                compoundShape.AddCollision(pair.m_shape);
                index++;
            }
            compoundShape.EndAddRemoveCollision();
        }
    }
コード例 #3
0
    public NewtonBodyCollision(NewtonBody body)
    {
        if (body.m_world.GetWorld() == null)
        {
            throw new NullReferenceException("Native world instance is null. The World component was probably destroyed");
        }

        List <ColliderShapePair> colliderList = new List <ColliderShapePair>();

        TraverseColliders(body.gameObject, colliderList, body.gameObject, body);

        if (body.m_isScene)
        {
            m_collidersArray = new ColliderShapePair[colliderList.Count + 1];
            NewtonSceneCollider   sceneCollider = body.gameObject.AddComponent <NewtonSceneCollider>();
            dNewtonCollisionScene sceneShape    = (dNewtonCollisionScene)sceneCollider.Create(body.m_world);

            m_collidersArray[0].m_shape    = sceneShape;
            m_collidersArray[0].m_collider = sceneCollider;

            int index = 1;
            sceneShape.BeginAddRemoveCollision();
            foreach (ColliderShapePair pair in colliderList)
            {
                m_collidersArray[index] = pair;
                sceneShape.AddCollision(pair.m_shape);
                index++;
            }
            sceneShape.EndAddRemoveCollision();
        }
        else if (colliderList.Count == 0)
        {
            m_collidersArray = new ColliderShapePair[1];
            NewtonCollider collider = body.gameObject.AddComponent <NewtonNullCollider>();
            m_collidersArray[0].m_collider = collider;
            m_collidersArray[0].m_shape    = collider.Create(body.m_world);
        }
        else if (colliderList.Count == 1)
        {
            m_collidersArray    = new ColliderShapePair[1];
            m_collidersArray[0] = colliderList[0];
        }
        else
        {
            m_collidersArray = new ColliderShapePair[colliderList.Count + 1];
            NewtonCompoundCollider   compoundCollider = body.gameObject.AddComponent <NewtonCompoundCollider>();
            dNewtonCollisionCompound compoundShape    = (dNewtonCollisionCompound)compoundCollider.Create(body.m_world);

            m_collidersArray[0].m_shape    = compoundShape;
            m_collidersArray[0].m_collider = compoundCollider;

            int index = 1;
            compoundShape.BeginAddRemoveCollision();
            foreach (ColliderShapePair pair in colliderList)
            {
                m_collidersArray[index] = pair;
                compoundShape.AddCollision(pair.m_shape);
                index++;
            }
            compoundShape.EndAddRemoveCollision();
        }
    }
コード例 #4
0
        public NewtonBodyCollision(NewtonBody body)
        {
            if (body.World.GetWorld() == null)
            {
                throw new NullReferenceException("Native world instance is null. The World component was probably destroyed");
            }

            m_Body = body;

            List <NewtonCollider> colliderList = new List <NewtonCollider>();

            TraverseColliders(body.gameObject, colliderList, body.gameObject, body);

            if (body.IsScene)
            {
                NewtonSceneCollider   sceneCollider = body.gameObject.AddComponent <NewtonSceneCollider>();
                dNewtonCollisionScene sceneShape    = (dNewtonCollisionScene)sceneCollider.Create(body.World);
                sceneCollider.SetShape(sceneShape);

                m_RootCollider = sceneCollider;
                m_Colliders.Add(sceneCollider);

                sceneShape.BeginAddRemoveCollision();
                foreach (NewtonCollider collider in colliderList)
                {
                    m_Colliders.Add(collider);
                    collider.m_ParentHandle = sceneShape.AddCollision(collider.GetShape());
                }
                sceneShape.EndAddRemoveCollision();
            }
            else if (colliderList.Count == 0)
            {
                NewtonCollider collider = body.gameObject.AddComponent <NewtonNullCollider>();
                collider.SetShape(collider.Create(body.World));

                m_RootCollider = collider;
                m_Colliders.Add(collider);
            }
            else if (colliderList.Count == 1)
            {
                m_RootCollider = colliderList[0];
                m_Colliders.Add(colliderList[0]);
            }
            else
            {
                NewtonCompoundCollider   compoundCollider = body.gameObject.AddComponent <NewtonCompoundCollider>();
                dNewtonCollisionCompound compoundShape    = (dNewtonCollisionCompound)compoundCollider.Create(body.World);
                compoundCollider.SetShape(compoundShape);

                m_RootCollider = compoundCollider;
                m_Colliders.Add(compoundCollider);

                compoundShape.BeginAddRemoveCollision();
                foreach (NewtonCollider collider in colliderList)
                {
                    m_Colliders.Add(collider);
                    collider.m_ParentHandle = compoundShape.AddCollision(collider.GetShape());
                }
                compoundShape.EndAddRemoveCollision();
            }
        }