///<summary>
        /// Initializes the pair handler.
        ///</summary>
        ///<param name="entryA">First entry in the pair.</param>
        ///<param name="entryB">Second entry in the pair.</param>
        public override void Initialize(BroadPhaseEntry entryA, BroadPhaseEntry entryB)
        {

            mesh = entryA as StaticMesh;
            convex = entryB as ConvexCollidable;

            if (mesh == null || convex == null)
            {
                mesh = entryB as StaticMesh;
                convex = entryA as ConvexCollidable;

                if (mesh == null || convex == null)
                    throw new Exception("Inappropriate types used to initialize pair.");
            }

            //Contact normal goes from A to B.
            broadPhaseOverlap.entryA = convex;
            broadPhaseOverlap.entryB = mesh;

            UpdateMaterialProperties(convex.entity != null ? convex.entity.material : null, mesh.material);

            base.Initialize(entryA, entryB);




        }
        ///<summary>
        /// Initializes the pair handler.
        ///</summary>
        ///<param name="entryA">First entry in the pair.</param>
        ///<param name="entryB">Second entry in the pair.</param>
        public override void Initialize(BroadPhaseEntry entryA, BroadPhaseEntry entryB)
        {


            box = entryA as ConvexCollidable<BoxShape>;
            sphere = entryB as ConvexCollidable<SphereShape>;

            if (box == null || sphere == null)
            {
                box = entryB as ConvexCollidable<BoxShape>;
                sphere = entryA as ConvexCollidable<SphereShape>;
                if (box == null || sphere == null)
                {
                    throw new Exception("Inappropriate types used to initialize pair.");
                }
            }

            //Reorder the entries so that the guarantee that the normal points from A to B is satisfied.
            broadPhaseOverlap.entryA = box;
            broadPhaseOverlap.entryB = sphere;
            
            base.Initialize(entryA, entryB);


        }
        ///<summary>
        /// Initializes the pair handler.
        ///</summary>
        ///<param name="entryA">First entry in the pair.</param>
        ///<param name="entryB">Second entry in the pair.</param>
        public override void Initialize(BroadPhaseEntry entryA, BroadPhaseEntry entryB)
        {

            mobileMesh = entryA as MobileMeshCollidable;
            convex = entryB as ConvexCollidable;

            if (mobileMesh == null || convex == null)
            {
                mobileMesh = entryB as MobileMeshCollidable;
                convex = entryA as ConvexCollidable;

                if (mobileMesh == null || convex == null)
                    throw new Exception("Inappropriate types used to initialize pair.");
            }


            //Contact normal goes from A to B.
            broadPhaseOverlap.entryA = convex;
            broadPhaseOverlap.entryB = mobileMesh;

            //It's possible that the convex does not have an entity if it is a proxy for a non-entity collidable.
            //Similarly, the mesh could be a query object.
            UpdateMaterialProperties(convex.entity != null ? convex.entity.material : null, mobileMesh.entity != null ? mobileMesh.entity.material : null);


            base.Initialize(entryA, entryB);

        }
        ///<summary>
        /// Initializes the pair handler.
        ///</summary>
        ///<param name="entryA">First entry in the pair.</param>
        ///<param name="entryB">Second entry in the pair.</param>
        public override void Initialize(BroadPhaseEntry entryA, BroadPhaseEntry entryB)
        {

            //Child initialization is responsible for setting up the entries.
            //Child initialization is responsible for setting up the manifold, if any.
            manifoldConstraintGroup.Initialize(EntityA, EntityB);

            base.Initialize(entryA, entryB);
        }
Beispiel #5
0
 /// <summary>
 /// Adds a broad phase overlap if the collision rules permit it.
 /// </summary>
 /// <param name="entryA">First entry of the overlap.</param>
 /// <param name="entryB">Second entry of the overlap.</param>
 protected internal void TryToAddOverlap(BroadPhaseEntry entryA, BroadPhaseEntry entryB)
 {
     CollisionRule rule;
     if ((rule = GetCollisionRule(entryA, entryB)) < CollisionRule.NoBroadPhase)
     {
         overlapAddLock.Enter();
         overlaps.Add(new BroadPhaseOverlap(entryA, entryB, rule));
         overlapAddLock.Exit();
     }
 }
        ///<summary>
        /// Initializes the pair handler.
        ///</summary>
        ///<param name="entryA">First entry in the pair.</param>
        ///<param name="entryB">Second entry in the pair.</param>
        public override void Initialize(BroadPhaseEntry entryA, BroadPhaseEntry entryB)
        {
            compoundInfoB = entryB as CompoundCollidable;
            if (compoundInfoB == null)
            {
                throw new Exception("Inappropriate types used to initialize pair.");
            }

            base.Initialize(entryA, entryB);
        }
        ///<summary>
        /// Initializes the pair handler.
        ///</summary>
        ///<param name="entryA">First entry in the pair.</param>
        ///<param name="entryB">Second entry in the pair.</param>
        public override void Initialize(BroadPhaseEntry entryA, BroadPhaseEntry entryB)
        {
            //Child initialization is responsible for setting up the entries.

            ContactManifold.Initialize(CollidableA, CollidableB);
            ContactConstraint.Initialize(EntityA, EntityB, this);

            base.Initialize(entryA, entryB);



        }
        ///<summary>
        /// Initializes the pair handler.
        ///</summary>
        ///<param name="entryA">First entry in the pair.</param>
        ///<param name="entryB">Second entry in the pair.</param>
        public override void Initialize(BroadPhaseEntry entryA, BroadPhaseEntry entryB)
        {
            boxA = entryA as ConvexCollidable<BoxShape>;
            boxB = entryB as ConvexCollidable<BoxShape>;

            if (boxA == null || boxB == null)
            {
                throw new Exception("Inappropriate types used to initialize pair.");
            }

            base.Initialize(entryA, entryB);

        }
        ///<summary>
        /// Initializes the pair handler.
        ///</summary>
        ///<param name="entryA">First entry in the pair.</param>
        ///<param name="entryB">Second entry in the pair.</param>
        public override void Initialize(BroadPhaseEntry entryA, BroadPhaseEntry entryB)
        {
            mesh = entryA as InstancedMesh;
            if (mesh == null)
            {
                mesh = entryB as InstancedMesh;
                if (mesh == null)
                {
                    throw new Exception("Inappropriate types used to initialize pair.");
                }
            }

            base.Initialize(entryA, entryB);
        }
        ///<summary>
        /// Initializes the pair handler.
        ///</summary>
        ///<param name="entryA">First entry in the pair.</param>
        ///<param name="entryB">Second entry in the pair.</param>
        public override void Initialize(BroadPhaseEntry entryA, BroadPhaseEntry entryB)
        {
            //Other member of the pair is initialized by the child.
            mobileMesh = entryA as MobileMeshCollidable;
            if (mobileMesh == null)
            {
                mobileMesh = entryB as MobileMeshCollidable;
                if (mobileMesh == null)
                {
                    throw new Exception("Inappropriate types used to initialize pair.");
                }
            }

            base.Initialize(entryA, entryB);
        }
        ///<summary>
        /// Initializes the pair handler.
        ///</summary>
        ///<param name="entryA">First entry in the pair.</param>
        ///<param name="entryB">Second entry in the pair.</param>
        public override void Initialize(BroadPhaseEntry entryA, BroadPhaseEntry entryB)
        {
            terrain = entryA as Terrain;
            if (terrain == null)
            {

                terrain = entryB as Terrain;
                if (terrain == null)
                {
                    throw new Exception("Inappropriate types used to initialize pair.");
                }
            }

            base.Initialize(entryA, entryB);
        }
        ///<summary>
        /// Initializes the pair handler.
        ///</summary>
        ///<param name="entryA">First entry in the pair.</param>
        ///<param name="entryB">Second entry in the pair.</param>
        public override void Initialize(BroadPhaseEntry entryA, BroadPhaseEntry entryB)
        {
            //Other member of the pair is initialized by the child.
            compoundInfo = entryA as CompoundCollidable;
            if (compoundInfo == null)
            {
                compoundInfo = entryB as CompoundCollidable;
                if (compoundInfo == null)
                {
                    throw new Exception("Inappropriate types used to initialize pair.");
                }
            }

            base.Initialize(entryA, entryB);
        }
        ///<summary>
        /// Initializes the pair handler.
        ///</summary>
        ///<param name="entryA">First entry in the pair.</param>
        ///<param name="entryB">Second entry in the pair.</param>
        public override void Initialize(BroadPhaseEntry entryA, BroadPhaseEntry entryB)
        {

            triangle = entryA as ConvexCollidable<TriangleShape>;
            convex = entryB as ConvexCollidable;

            if (triangle == null || convex == null)
            {
                triangle = entryB as ConvexCollidable<TriangleShape>;
                convex = entryA as ConvexCollidable;

                if (triangle == null || convex == null)
                    throw new Exception("Inappropriate types used to initialize pair.");
            }

            //Contact normal goes from A to B.
            broadPhaseOverlap.entryA = convex;
            broadPhaseOverlap.entryB = triangle;

            base.Initialize(entryA, entryB);

        }
Beispiel #14
0
 protected internal CollisionRule GetCollisionRule(BroadPhaseEntry entryA, BroadPhaseEntry entryB)
 {
     if (entryA.IsActive || entryB.IsActive)
         return CollisionRules.collisionRuleCalculator(entryA.collisionRules, entryB.collisionRules);
     return CollisionRule.NoBroadPhase;
 }
        public override void Initialize(BroadPhaseEntry entryA, BroadPhaseEntry entryB)
        {
            UpdateMaterialProperties();

            base.Initialize(entryA, entryB);
        }
Beispiel #16
0
 /// <summary>
 /// Removes an entry from the broad phase.
 /// </summary>
 /// <param name="entry">Entry to remove.</param>
 public abstract void Remove(BroadPhaseEntry entry);
 ///<summary>
 /// Gets a narrow phase pair for a given pair of entries.
 ///</summary>
 ///<param name="entryA">First entry in the pair.</param>
 /// <param name="entryB">Second entry in the pair.</param>
 /// <param name="rule">Collision rule governing the pair.</param>
 ///<returns>A INarrowPhasePair for the overlap.</returns>
 public static NarrowPhasePair GetPair(BroadPhaseEntry entryA, BroadPhaseEntry entryB, CollisionRule rule)
 {
     BroadPhaseOverlap overlap = new BroadPhaseOverlap(entryA, entryB, rule);
     return GetPair(ref overlap);
 }
 ///<summary>
 /// Gets a narrow phase pair for a given pair of entries.
 ///</summary>
 ///<param name="entryA">First entry in the pair.</param>
 /// <param name="entryB">Second entry in the pair.</param>
 ///<returns>A INarrowPhasePair for the overlap.</returns>
 public static NarrowPhasePair GetPair(BroadPhaseEntry entryA, BroadPhaseEntry entryB)
 {
     BroadPhaseOverlap overlap = new BroadPhaseOverlap(entryA, entryB);
     return GetPair(ref overlap);
 }
Beispiel #19
0
 /// <summary>
 /// Adds an entry to the broad phase.
 /// </summary>
 /// <param name="entry">Entry to add.</param>
 public abstract void Add(BroadPhaseEntry entry);
 internal EventStoragePairRemoved(BroadPhaseEntry other)
 {
     this.other = other;
 }
 void RemoveFriction(EntityCollidable sender, BroadPhaseEntry other, NarrowPhasePair pair)
 {
     var collidablePair = pair as CollidablePairHandler;
     if (collidablePair != null)
     {
         //The default values for InteractionProperties is all zeroes- zero friction, zero bounciness.
         //That's exactly how we want the character to behave when hitting objects.
         collidablePair.UpdateMaterialProperties(new InteractionProperties());
     }
 }
 /// <summary>
 /// Recovers iobject from broad phase entry.
 /// </summary>
 /// <param name="entry">The entry.</param>
 /// <returns></returns>
 public static IObject RecoverObjectFromBroadPhase(BroadPhaseEntry entry)
 {
     IPhysicObject phyObj = null;
     if (entry is Collidable)
     {
         Collidable collidable = (entry as Collidable);
         phyObj = collidable.Tag as IPhysicObject;
         return phyObj.ObjectOwner;
     }
     else
     {
         return null;
     }
     
 }
 /// <summary>
 /// Recovers physicobject from broad phase entry.
 /// </summary>
 /// <param name="entry">The entry.</param>
 /// <returns></returns>
 public static IPhysicObject RecoverIPhysicObjectFromBroadPhase(BroadPhaseEntry entry)
 {
     IPhysicObject phyObj = null;
     if (entry is Collidable)
     {
         Collidable collidable = (entry as Collidable);
         phyObj = collidable.Tag as IPhysicObject;
     }
     return phyObj;
 }      
 ///<summary>
 /// Initializes the pair.
 ///</summary>
 ///<param name="entryA">First entry in the pair.</param>
 ///<param name="entryB">Second entry in the pair.</param>
 public abstract void Initialize(BroadPhaseEntry entryA, BroadPhaseEntry entryB);
Beispiel #25
0
 public override void Remove(BroadPhaseEntry entry)
 {
     entries.Remove(entry);
 }
 internal EventStoragePairUpdated(BroadPhaseEntry other, NarrowPhasePair pair)
 {
     this.other = other;
     this.pair = pair;
 }
 ///<summary>
 /// Constructs a new ray cast result.
 ///</summary>
 ///<param name="hitData">Ray cast hit data.</param>
 ///<param name="hitObject">Object hit by the ray.</param>
 public RayCastResult(RayHit hitData, BroadPhaseEntry hitObject)
 {
     HitData = hitData;
     HitObject = hitObject;
 }
        ///<summary>
        /// Initializes the pair handler.
        ///</summary>
        ///<param name="entryA">First entry in the pair.</param>
        ///<param name="entryB">Second entry in the pair.</param>
        public override void Initialize(BroadPhaseEntry entryA, BroadPhaseEntry entryB)
        {
            mesh = (MobileMeshCollidable)entryB;

            base.Initialize(entryA, entryB);
        }
Beispiel #29
0
 bool SupportRayFilterFunction(BroadPhaseEntry entry)
 {
     //Only permit an object to be used as a support if it fully collides with the character.
     return CollisionRules.CollisionRuleCalculator(entry.CollisionRules, character.Body.CollisionInformation.CollisionRules) == CollisionRule.Normal;
 }
        ///<summary>
        /// Initializes the pair handler.
        ///</summary>
        ///<param name="entryA">First entry in the pair.</param>
        ///<param name="entryB">Second entry in the pair.</param>
        public override void Initialize(BroadPhaseEntry entryA, BroadPhaseEntry entryB)
        {
            //Child initialization is responsible for setting up the entries.
            //Child initialization is responsible for setting up the material.
            //Child initialization is responsible for setting up the manifold.
            //Child initialization is responsible for setting up the constraint.

            if (!suppressEvents)
            {
                CollidableA.EventTriggerer.OnPairCreated(CollidableB, this);
                CollidableB.EventTriggerer.OnPairCreated(CollidableA, this);
            }
        }