Exemple #1
0
 public virtual void BOnTriggerStay(CollisionObject other, AlignedManifoldArray details)
 {
     Log.Debug("Stay with " + other.UserObject.ToString() + " fixedFrame " + BPhysicsWorld.Get.frameCount);
     if (other.UserObject is Unit unit)
     {
         unit.needSend    = true;
         unit.triggerType = "TriggerStay";
     }
 }
        public void GhostObjectPairsTest()
        {
            var world = _context.DiscreteDynamicsWorld;

            world.StepSimulation(1.0f / 60.0f);

            AlignedManifoldArray       manifoldArray = new AlignedManifoldArray();
            AlignedBroadphasePairArray pairArray     = _ghostObject.OverlappingPairCache.OverlappingPairArray;

            foreach (BroadphasePair pair in pairArray)
            {
                //unless we manually perform collision detection on this pair, the contacts are in the dynamics world paircache:
                BroadphasePair collisionPair = world.PairCache.FindPair(pair.Proxy0, pair.Proxy1);
                if (collisionPair == null)
                {
                    continue;
                }

                manifoldArray.Clear();

                if (collisionPair.Algorithm != null)
                {
                    collisionPair.Algorithm.GetAllContactManifolds(manifoldArray);
                }

                for (int j = 0; j < manifoldArray.Count; j++)
                {
                    PersistentManifold manifold = manifoldArray[j];
                    float directionSign         = manifold.Body0 == _ghostObject ? -1.0f : 1.0f;
                    for (int p = 0; p < manifold.NumContacts; p++)
                    {
                        ManifoldPoint pt = manifold.GetContactPoint(p);
                        if (pt.Distance < 0.0f)
                        {
                            Vector3 ptA       = pt.PositionWorldOnA;
                            Vector3 ptB       = pt.PositionWorldOnB;
                            Vector3 normalOnB = pt.NormalWorldOnB;
                        }
                    }
                }
            }

            manifoldArray.Dispose();
        }
Exemple #3
0
        static void TestGhostObjectPairs(PairCachingGhostObject ghostObject)
        {
            AlignedManifoldArray       manifoldArray = new AlignedManifoldArray();
            AlignedBroadphasePairArray pairArray     = ghostObject.OverlappingPairCache.OverlappingPairArray;
            int numPairs = pairArray.Count;

            for (int i = 0; i < numPairs; i++)
            {
                manifoldArray.Clear();

                BroadphasePair pair = pairArray[i];

                //unless we manually perform collision detection on this pair, the contacts are in the dynamics world paircache:
                BroadphasePair collisionPair = world.PairCache.FindPair(pair.Proxy0, pair.Proxy1);
                if (collisionPair == null)
                {
                    continue;
                }

                if (collisionPair.Algorithm != null)
                {
                    collisionPair.Algorithm.GetAllContactManifolds(manifoldArray);
                }

                for (int j = 0; j < manifoldArray.Count; j++)
                {
                    PersistentManifold manifold = manifoldArray[j];
                    float directionSign         = manifold.Body0 == ghostObject ? -1.0f : 1.0f;
                    for (int p = 0; p < manifold.NumContacts; p++)
                    {
                        ManifoldPoint pt = manifold.GetContactPoint(p);
                        if (pt.Distance < 0.0f)
                        {
                            Vector3 ptA       = pt.PositionWorldOnA;
                            Vector3 ptB       = pt.PositionWorldOnB;
                            Vector3 normalOnB = pt.NormalWorldOnB;
                            /// work here
                        }
                    }
                }
            }
        }
 public override void BOnTriggerEnter(CollisionObject other, AlignedManifoldArray details)
 {
     Debug.Log("Enter with " + other.UserObject + " fixedFrame " + GetWorld().FrameCount);
 }
 public override void BOnTriggerStay(CollisionObject other, AlignedManifoldArray details)
 {
     Debug.Log("Stay with " + other.UserObject + " fixedFrame " + BPhysicsWorld.Get().frameCount);
 }
Exemple #6
0
 public virtual void BOnTriggerStay(CollisionObject other, AlignedManifoldArray details)
 {
 }
 public void GetAllContactManifolds(AlignedManifoldArray manifoldArray)
 {
     btCollisionAlgorithm_getAllContactManifolds(_native, manifoldArray._native);
 }
        static void TestGhostObjectPairs(PairCachingGhostObject ghostObject)
        {
            AlignedManifoldArray manifoldArray = new AlignedManifoldArray();
            AlignedBroadphasePairArray pairArray = ghostObject.OverlappingPairCache.OverlappingPairArray;
            int numPairs = pairArray.Count;

            for (int i = 0; i < numPairs; i++)
            {
                manifoldArray.Clear();

                BroadphasePair pair = pairArray[i];

                //unless we manually perform collision detection on this pair, the contacts are in the dynamics world paircache:
                BroadphasePair collisionPair = world.PairCache.FindPair(pair.Proxy0, pair.Proxy1);
                if (collisionPair == null)
                    continue;

                if (collisionPair.Algorithm != null)
                    collisionPair.Algorithm.GetAllContactManifolds(manifoldArray);

                for (int j = 0; j < manifoldArray.Count; j++)
                {
                    PersistentManifold manifold = manifoldArray[j];
                    float directionSign = manifold.Body0 == ghostObject ? -1.0f : 1.0f;
                    for (int p = 0; p < manifold.NumContacts; p++)
                    {
                        ManifoldPoint pt = manifold.GetContactPoint(p);
                        if (pt.Distance < 0.0f)
                        {
                            Vector3 ptA = pt.PositionWorldOnA;
                            Vector3 ptB = pt.PositionWorldOnB;
                            Vector3 normalOnB = pt.NormalWorldOnB;
                            /// work here
                        }
                    }
                }
            }
        }
 public override void BOnTriggerEnter(CollisionObject other, AlignedManifoldArray manifoldArray)
 {
     Debug.Log("Enter with " + other.UserObject + " fixedFrame " + BPhysicsWorld.Get().frameCount);
 }
Exemple #10
0
 public virtual void BOnTriggerEnter(CollisionObject other, AlignedManifoldArray details)
 {
     //Debug.LogWarning("BOnTriggerEnter: " + ((BRigidBody)other.UserObject).name);
 }
 public override void BOnTriggerStay(CollisionObject other, AlignedManifoldArray manifoldArray)
 {
     Debug.Log("Stay with " + other.UserObject + " fixedFrame " + BPhysicsWorld.Get().frameCount);
 }
 public override void BOnTriggerEnter(CollisionObject other, AlignedManifoldArray manifoldArray)
 {
     Log.Debug("Enter with " + other.UserObject + " fixedFrame " + BPhysicsWorld.Get.frameCount);
 }
Exemple #13
0
 public override void BOnTriggerEnter(CollisionObject other, AlignedManifoldArray details)
 {
     Debug.LogError("Enter with "); // + other.UserObject + " fixedFrame " + BPhysicsWorld.Get().frameCount);
 }
Exemple #14
0
        /// <summary>
        /// It is from bullet_character_controller
        /// </summary>
        public static int GhostGetPenetrationFixVector(PairCachingGhostObject ghost, AlignedManifoldArray manifoldArray,
            out Vector3 correction)
        {
            // Here we must refresh the overlapping paircache as the penetrating movement itself or the
            // previous recovery iteration might have used setWorldTransform and pushed us into an object
            // that is not in the previous cache contents from the last timestep, as will happen if we
            // are pushed into a new AABB overlap. Unhandled this means the next convex sweep gets stuck.
            //
            // Do this by calling the broadphase's setAabb with the moved AABB, this will update the broadphase
            // paircache and the ghostobject's internal paircache at the same time.    /BW

            var ret = 0;
            var pairArray = ghost.OverlappingPairCache.OverlappingPairArray;
            BulletSharp.Math.Vector3 aabb_min, aabb_max, t;

            ghost.CollisionShape.GetAabb(ghost.WorldTransform, out aabb_min, out aabb_max);
            BtEngineDynamicsWorld.Broadphase.SetAabb(ghost.BroadphaseHandle, aabb_min, aabb_max,
                BtEngineDynamicsWorld.Dispatcher);
            BtEngineDynamicsWorld.Dispatcher.DispatchAllCollisionPairs(ghost.OverlappingPairCache,
                BtEngineDynamicsWorld.DispatchInfo, BtEngineDynamicsWorld.Dispatcher);

            correction = Vector3.Zero;
            var numPairs = ghost.OverlappingPairCache.NumOverlappingPairs;
            for (var i = 0; i < numPairs; i++)
            {
                manifoldArray.Clear();
                // do not use commented code: it prevents to collision skips.
                //var pair = pairArray[i];
                //var collisionPair = Global.BtEngineDynamicsWorld.PairCache.FindPair(pair.Proxy0, pair.Proxy1);
                var collisionPair = pairArray[i];

                if(collisionPair == null)
                {
                    continue;
                }

                collisionPair.Algorithm?.GetAllContactManifolds(manifoldArray);

                foreach (var manifold in manifoldArray)
                {
                    var directionSign = manifold.Body0 == ghost ? -1.0f : 1.0f;
                    var cont0 = (EngineContainer) manifold.Body0.UserObject;
                    var cont1 = (EngineContainer) manifold.Body1.UserObject;
                    if(cont0.CollisionType == COLLISION_TYPE.Ghost && cont1.CollisionType == COLLISION_TYPE.Ghost)
                    {
                        continue;
                    }
                    for(var k = 0; k < manifold.NumContacts; k++)
                    {
                        var pt = manifold.GetContactPoint(k);
                        var dist = pt.Distance;

                        if(dist < 0.0f)
                        {
                            t = pt.NormalWorldOnB * dist * directionSign;
                            correction += t.ToOpenTK();
                            ret++;
                        }
                    }
                }
            }

            return ret;
        }
 public virtual void BOnTriggerStay(CollisionObject other, AlignedManifoldArray details)
 {
 }