Superclass of pairs between collidables that generate contact points.
Inheritance: BEPUphysics.NarrowPhaseSystems.Pairs.NarrowPhasePair
        public override void collisionEvent(EntityCollidable eCollidable, Collidable collidable, CollidablePairHandler pairHandler)
        {
            // bool valid = false;

            if (collidable.Tag != null
                && collidable.Tag is CollisionBase)
            {
                SceneObject collidee = ((CollisionBase)collidable.Tag).Parent;
                if (collidee != null && !(collidee is Projectile) && Parent != null && Parent != collidee)
                {
                    if (collidee is Ship)
                    {
                        collidee.onCollide(this, Damage);
                        /*if (collidee is Ship)
                        {
                            valid = true;
                        }*/
                    }
                    else { }
                }
                else { }
            }
            else { }

            /*if (valid == true)
            {
                SceneObjectFactory.createExplosion(Position, Rotation);
            }
            else { }*/
        }
        private void Events_InitialCollisionDetected(EntityCollidable sender, Collidable info, CollidablePairHandler pair, ContactData contact)
        {
            try
            {
                //var contact = pair.Contacts[0].Contact;

                //if(contact.PenetrationDepth>2f)
                //DebugSystem.Instance.DebugCommandUI.Echo(contact.PenetrationDepth.ToString());

                // Select collisionInformation for object in contact with instead of the ships own collisionInformation
                Collidable candidate = (pair.BroadPhaseOverlap.EntryA == racerEntity.CollisionInformation ? pair.BroadPhaseOverlap.EntryB : pair.BroadPhaseOverlap.EntryA) as Collidable;
                if (candidate.Equals(Physics.currentTrackFloor))
                {

                    ReactToTrackHit(contact);
                }
                else if (candidate.Equals(Physics.currentTrackWall))
                {
                    ReactToWallHit(contact);
                }
                else
                {

                    ReactToShipShipCollision(contact, candidate);
                }
            }
            catch (Exception e)
            {
                // System.Diagnostic.Debug.WriteLine("Unfound pair");
            }
        }
示例#3
0
        ///<summary>
        /// Updates the pair handler's contacts.
        ///</summary>
        ///<param name="dt">Timestep duration.</param>
        protected virtual void UpdateContacts(float dt)
        {
            UpdateContainedPairs();
            //Eliminate old pairs.
            foreach (CollidablePair pair in subPairs.Keys)
            {
                if (!containedPairs.Contains(pair))
                {
                    pairsToRemove.Add(pair);
                }
            }
            for (int i = 0; i < pairsToRemove.Count; i++)
            {
                CollidablePairHandler toReturn = subPairs[pairsToRemove.Elements[i]];
                subPairs.Remove(pairsToRemove.Elements[i]);
                toReturn.CleanUp();
                toReturn.Factory.GiveBack(toReturn);
            }
            containedPairs.Clear();
            pairsToRemove.Clear();

            foreach (CollidablePairHandler pair in subPairs.Values)
            {
                if (pair.BroadPhaseOverlap.collisionRule < CollisionRule.NoNarrowPhaseUpdate) //Don't test if the collision rules say don't.
                {
                    pair.UpdateCollision(dt);
                }
            }
        }
示例#4
0
 void Events_InitialCollisionDetected(EntityCollidable sender, Collidable other, CollidablePairHandler pair)
 {
     if ("Environment".Equals(other.Tag))
     {
         // do something on collision
     }
 }
示例#5
0
        private void CollisionDetectedHandler(EntityCollidable sender, Collidable other, CollidablePairHandler pair)
        {
            EntityCollidable otherEntityCollidable = other as EntityCollidable;
            Terrain otherTerrain = other as Terrain;
            if (otherEntityCollidable != null &&
                otherEntityCollidable.Entity != null &&
                otherEntityCollidable.Entity.Tag != null)
            {
                int actorId = (int)(otherEntityCollidable.Entity.Tag);
                if (actorId == mOwnerActorId)
                    return;
                Actor actorHit = GameResources.ActorManager.GetActorById(actorId);
                IDamagable damage = actorHit.GetBehaviorThatImplementsType<IDamagable>();
                if (damage != null)
                {
                    damage.TakeDamage(mDamage);
                }

                Impact();
            }
            else if (otherTerrain != null)
            {
                Impact();
            }
        }
        protected void TryToAdd(Collidable a, Collidable b, Material materialA, Material materialB)
        {
            CollisionRule rule;

            if ((rule = CollisionRules.collisionRuleCalculator(a.collisionRules, b.collisionRules)) < CollisionRule.NoNarrowPhasePair)
            {
                //Clamp the rule to the parent's rule.  Always use the more restrictive option.
                //Don't have to test for NoNarrowPhasePair rule on the parent's rule because then the parent wouldn't exist!
                if (rule < CollisionRule)
                {
                    rule = CollisionRule;
                }
                var pair = new CollidablePair(a, b);
                if (!subPairs.ContainsKey(pair))
                {
                    CollidablePairHandler newPair = NarrowPhaseHelper.GetPairHandler(ref pair, rule);
                    if (newPair != null)
                    {
                        newPair.UpdateMaterialProperties(materialA, materialB);  //Override the materials, if necessary.
                        newPair.Parent = this;
                        subPairs.Add(pair, newPair);
                    }
                }
                containedPairs.Add(pair);
            }
        }
示例#7
0
        void HandleCollision(EntityCollidable sender, Collidable other, CollidablePairHandler pair)
        {
            if (soundEffect != null)
            {
                emitter.Position = body.Position / 5.0f;

            }
        }
示例#8
0
 protected void HandleCollision(EntityCollidable sender, Collidable other, CollidablePairHandler pair)
 {
     GameEntity ge = other.Tag as GameEntity;
     if (ge != null && ge.Name == "player")
     {
         Game.DrinkBeer(physicalData.Position);
         Entity.KillEntity();
     }
 }
示例#9
0
 protected void HandleCollision(EntityCollidable sender, Collidable other, CollidablePairHandler pair)
 {
     GameEntity ge = other.Tag as GameEntity;
     if (ge != null && ge.Name == "punch")
     {
         Game.PunchProp();
         Entity.Dead = true;
     }
 }
        void HandleCollision(EntityCollidable sender, Collidable other, CollidablePairHandler pair)
        {
            Console.WriteLine("Got here!");

            emitter.Position = body.Position / 5; ;
            listener.Position = XNAGame.Instance.Camera.Position / 5;
            soundEffectInstance.Apply3D(listener, emitter);
            soundEffectInstance.Play();
        }
示例#11
0
 public override void InitialCollisionDetected(EntityCollidable sender, Collidable other, CollidablePairHandler collisionPair)
 {
     if (other.Tag is CharacterSynchronizer)
     {
         if ((other.Tag as CharacterSynchronizer).body.Tag is Creature)
         {
             ((other.Tag as CharacterSynchronizer).body.Tag as Creature).Die();
         }
     }
 }
示例#12
0
 public override void CollisionEnded(EntityCollidable sender, Collidable other, CollidablePairHandler collisionPair)
 {
     if (other.Tag is CharacterSynchronizer)
     {
         if ((other.Tag as CharacterSynchronizer).body.Tag is PlayerCreature)
         {
             OnExit();
         }
     }
 }
示例#13
0
 public static bool PairIsColliding(CollidablePairHandler pair)
 {
     foreach (var contactInformation in pair.Contacts)
     {
         if (contactInformation.Contact.PenetrationDepth >= 0)
         {
             return true;
         }
     }
     return false;
 }
示例#14
0
 //Removes the coin from the game if it contacts the character
 //coin is sender , other is whatever hits it
 public void coinHit(EntityCollidable sender, Collidable other, CollidablePairHandler pair)
 {
     var otherEntityInformation = other as EntityCollidable;
     if (otherEntityInformation != null && otherEntityInformation.Entity.Tag == cube)
     {
         Components.Remove((CoinModel)sender.Entity.Tag);
         space.Remove(sender.Entity);
         Console.WriteLine("removed ring");
         numRingsHit++;
     }
 }
示例#15
0
        public override void InitialCollisionDetected(EntityCollidable sender, Collidable other, CollidablePairHandler collisionPair)
        {
            base.InitialCollisionDetected(sender, other, collisionPair);

            //Console.WriteLine(other.Tag + " " + mRunTimer);
            if ((other.Tag is CharacterSynchronizer || other.Tag is PhysicsProp) && mRunTimer > 0.0f)
            {
                float totalImpulse = 0;
                foreach (ContactInformation c in collisionPair.Contacts)
                {
                    totalImpulse += c.NormalImpulse;
                }

                //Console.WriteLine(totalImpulse);

                int damage = 0;
                if (totalImpulse > 150.0f)
                {
                    damage = 2;
                }
                else if (totalImpulse > 45.0f)
                {
                    damage = 1;
                }

                Entity hitEntity;
                if (other.Tag is CharacterSynchronizer)
                {
                    hitEntity = (other.Tag as CharacterSynchronizer).body;
                }
                else
                {
                    hitEntity = (other.Tag as PhysicsProp).Entity;
                }

                Vector3 impulseVector = Vector3.Zero;
                Vector3 impulseDirection = hitEntity.Position - Creature.Position;
                if (impulseDirection != Vector3.Zero)
                {
                    impulseVector = Vector3.Normalize(impulseDirection);
                }

                impulseVector.Y = 0.45f;
                impulseVector.Normalize();
                impulseVector *= damage * DamageImpulseMultiplier;
                hitEntity.ApplyLinearImpulse(ref impulseVector);

                if (other.Tag is CharacterSynchronizer)
                {
                    ((other.Tag as CharacterSynchronizer).body.Tag as Creature).Damage(damage, Creature);
                    ((other.Tag as CharacterSynchronizer).body.Tag as Creature).AllowImpulse();
                }
            }
        }
        void HandleCollision(EntityCollidable sender, Collidable other, CollidablePairHandler pair)
        {
            if (soundEffect != null)
            {
                emitter.Position = body.Position / 5.0f;
                listener.Position = XNAGame.Instance.Camera.Position / 5.0f;
                soundEffectInstance.Apply3D(listener, emitter);
                soundEffectInstance.Play();

            }
        }
        public void InitialCollisionDetected(EntityCollidable sender, Collidable other, CollidablePairHandler collisionPair)
        {
            if (other == acceptedTrigger)
            {
                //If the detector collided with the accepted trigger, move the box.
                movedBox.Position = new Vector3(4, 5, 0);
                movedBox.Orientation = Quaternion.Identity;
                movedBox.LinearVelocity = Vector3.Zero;
                movedBox.AngularVelocity = Vector3.Zero;

            }
        }
 private void InitialCollisionDetectedHandler(EntityCollidable sender, Collidable other, CollidablePairHandler pair)
 {
     EntityCollidable otherEntityCollidable = other as EntityCollidable;
     if (otherEntityCollidable != null &&
         otherEntityCollidable.Entity != null &&
         otherEntityCollidable.Entity.Tag != null &&
         mTriggerSet &&
         GameResources.ActorManager.IsPlayer((int)(otherEntityCollidable.Entity.Tag)))
     {
         mTriggerSet = false;
         GameResources.LoadNewLevelDelegate(mLevelName);
     }
 }
示例#19
0
 private void InitialCollisionDetectedHandler(EntityCollidable sender, Collidable other, CollidablePairHandler pair)
 {
     EntityCollidable otherEntityCollidable = other as EntityCollidable;
     if (otherEntityCollidable != null &&
         otherEntityCollidable.Entity != null &&
         otherEntityCollidable.Entity.Tag != null &&
         mTriggerSet &&
         GameResources.ActorManager.IsPlayer((int)(otherEntityCollidable.Entity.Tag)))
     {
         PlayerView finder = GameResources.ActorManager.GetPlayerViewOfAvatar((int)(otherEntityCollidable.Entity.Tag));
         finder.AvatarDesc.ObtainItem(Item);
         mTriggerSet = false;
         Owner.Despawn();
     }
 }
示例#20
0
 protected void HandleCollision(EntityCollidable sender, Collidable other, CollidablePairHandler pair)
 {
     GameEntity ge = other.Tag as GameEntity;
     if (ge != null && ge.Name != "player" && ge.Name != "derper")
     {
         if (ge.Name == "prop")
         {
             if (player)
             {
                 Game.PunchObject(ge);
             }
             else
             {
                 Game.AddStupid(0);
             }
         }
         Entity.KillEntity();
     }
 }
        ///<summary>
        /// Constructs a new nonconvex manifold constraint.
        ///</summary>
        public NonConvexContactManifoldConstraint(CollidablePairHandler pairHandler)
            : base(pairHandler)
        {
            //All of the constraints are always in the solver group.  Some of them are just deactivated sometimes.
            //This reduces some bookkeeping complications.

            penetrationConstraints = new RawList<ContactPenetrationConstraint>(4);
            frictionConstraints = new RawList<ContactFrictionConstraint>(4);

            for (int i = 0; i < 4; i++)
            {
                var penetrationConstraint = new ContactPenetrationConstraint();
                penetrationConstraintPool.Push(penetrationConstraint);
                Add(penetrationConstraint);

                var frictionConstraint = new ContactFrictionConstraint();
                frictionConstraintPool.Push(frictionConstraint);
                Add(frictionConstraint);
            }
        }
示例#22
0
 public override void collisionEvent(EntityCollidable eCollidable, Collidable collidable, CollidablePairHandler pairHandler)
 {
     if (collidable.Tag != null
         && collidable.Tag is CollisionBase)
     {
         SceneObject collidee = ((CollisionBase)collidable.Tag).Parent;
         if (collidee != null && !(collidee is Projectile) && collidee != Parent)
         {
             collidee.onCollide(this, Damage);
         }
         else
         {
             // Was another laser or parent
             if (collidee != null && collidee is Projectile)
             {
                 LogCat.updateValue("Collide", "With projectile!");
             }
             else { }
         }
     }
     else { }
 }
示例#23
0
 public override void InitialCollisionDetected(EntityCollidable sender, Collidable other, CollidablePairHandler collisionPair)
 {
     if (mRopeLimit == null)
     {
         base.InitialCollisionDetected(sender, other, collisionPair);
         // If hit physics object link projectile to it then grapple to projectile, otherwise set projectile to kinematic and grapple to projectile
         if (other.Tag is CharacterSynchronizer)
         {
             StickToEntity((other.Tag as CharacterSynchronizer).body);
             ((other.Tag as CharacterSynchronizer).body.Tag as Creature).Damage(0, (mOwner as Creature));
         }
         else if (other.Tag is IEntityOwner)
         {
             StickToEntity((other.Tag as IEntityOwner).Entity);
         }
         else
         {
             Entity.BecomeKinematic();
         }
         CreateRope();
     }
 }
示例#24
0
 public override void InitialCollisionDetected(EntityCollidable sender, Collidable other, CollidablePairHandler collisionPair)
 {
     if (other.Tag is CharacterSynchronizer && !mLoaded)
     {
         CharacterSynchronizer synchronizer = (other.Tag as CharacterSynchronizer);
         if (synchronizer.body.Tag is PlayerCreature)
         {
             // Check that the player has the requested part.
             bool hasCorrectPart = false;
             foreach (Creature.PartAttachment partAttachment in (synchronizer.body.Tag as Creature).PartAttachments)
             {
                 if (partAttachment != null && partAttachment.Part.GetType() == PartType)
                 {
                     hasCorrectPart = true;
                     break;
                 }
             }
             if (hasCorrectPart)
             {
                 // Load the next level.
                 mLoaded = true;
                 // TODO: Investigate last frame object additions to next world.
                 World.Clear();
                 // TODO: Make scale globally accessible or modifiable.
                 if (LevelManager.Exists(mNextLevel))
                 {
                     World.AddLevelFromFile(mNextLevel, Vector3.Zero, Quaternion.Identity, new Vector3(8.0f, 0.01f, 8.0f));
                 }
                 else
                 {
                     InputAction.IsMouseLocked = false;
                     ChimeraGame.PopState();
                     ChimeraGame.PushState(new SuccessMenu(ChimeraGame.Game));
                 }
             }
         }
     }
 }
        /// <summary>
        /// Raises the appropriate ParentObject collision events depending on its CollisionType value
        /// </summary>
        /// <param name="sender">The current ISpaceObject instance</param>
        /// <param name="other">The ISpaceObject instance which collided</param>
        /// <param name="pair"/>
        protected void OnCollisionDetected(Collidable sender, Collidable other, CollidablePairHandler pair)
        {
            if (sender.Tag == null || other.Tag == null)
                return;

            ICollisionObject senderCollisionObject = (ICollisionObject) sender.Tag;
            ICollisionObject otherCollisionObject = (ICollisionObject) other.Tag;

            switch (ParentObject.CollisionType)
            {
                case CollisionType.Trigger:
                    {
                        ParentObject.OnCollisionTrigger(senderCollisionObject, otherCollisionObject);
                        break;
                    }
                case CollisionType.Collide:
                    {
                        var collisionPoint = new CollisionPoint
                                                 {
                                                     ContactObject = otherCollisionObject,
                                                     ContactPoint = pair.Contacts[0].Contact.Position,
                                                     ContactTime = pair.TimeOfImpact,
                                                     Material = null,
                                                     SurfaceNormal = pair.Contacts[0].Contact.Normal
                                                 };

                        ParentObject.OnCollisionReact(senderCollisionObject, otherCollisionObject, collisionPoint, ref _collisionHandled);
                        break;
                    }
                default:
                case CollisionType.None:
                    {
                        break;
                    }
            }
        }
        ///<summary>
        /// Constructs a new convex contact manifold constraint.
        ///</summary>
        public ConvexContactManifoldConstraint(CollidablePairHandler pairHandler)
            :base(pairHandler)
        {
            //All of the constraints are always in the solver group.  Some of them are just deactivated sometimes.
            //This reduces some bookkeeping complications.


            penetrationConstraints = new RawList<ContactPenetrationConstraint>(4);


            //Order matters in this adding process.  Sliding friction computes some information used by the twist friction, and both use penetration impulses.
            for (int i = 0; i < 4; i++)
            {
                var penetrationConstraint = new ContactPenetrationConstraint();
                Add(penetrationConstraint);
                penetrationConstraintPool.Push(penetrationConstraint);
            }
            slidingFriction = new SlidingFrictionTwoAxis();
            Add(slidingFriction);
            twistFriction = new TwistFrictionConstraint();
            Add(twistFriction);


        }
示例#27
0
        protected void onCollision(EntityCollidable sender, Collidable other, CollidablePairHandler pair)
        {
            if(!(other.Tag is Box))
                return;

            joint.Motor.Settings.Servo.Goal = -0.7f;
            if(!pressed)
                MediaSystem.PlaySoundEffect(SFXOptions.Machine_Button_Press);
            pressed = true;
        }
示例#28
0
 static bool DefaultCCDFilter(Entity entity, Collidable other, CollidablePairHandler pair)
 {
     return pair.broadPhaseOverlap.collisionRule < CollisionRule.NoSolver;
 }
示例#29
0
 internal static bool PairAllowsCCD(Entity entity, CollidablePairHandler pair)
 {
     var other = (pair.broadPhaseOverlap.entryA == entity.CollisionInformation ? pair.broadPhaseOverlap.entryB : pair.broadPhaseOverlap.entryA) as Collidable;
     return CCDFilter(entity, other, pair);
 }
示例#30
0
 private void Events_ContactCreated(EntityCollidable sender, Collidable other, BEPUphysics.NarrowPhaseSystems.Pairs.CollidablePairHandler pair, BEPUphysics.CollisionTests.ContactData contact)
 {
     this.Collided.Execute(other, pair.Contacts);
 }
 /// <summary>
 /// Raises the appropriate ParentObject collision events depending on its CollisionType value
 /// </summary>
 /// <param name="sender">The current ISpaceObject instance</param>
 /// <param name="other">The ISpaceObject instance which collided</param>
 /// <param name="pair"/>
 private void OnStaticMeshCollisionDetected(StaticMesh sender, Collidable other, CollidablePairHandler pair)
 {
     OnCollisionDetected(sender, other, pair);
 }
示例#32
0
 internal void AddPair(CollidablePairHandler pair, ref int index)
 {
     index = pairs.Count;
     pairs.Add(pair);
 }
示例#33
0
 internal void RemovePair(CollidablePairHandler pair, ref int index)
 {
     if (pairs.Count > index)
     {
         pairs.FastRemoveAt(index);
         if (pairs.Count > index)
         {
             var endPair = pairs.Elements[index];
             if (endPair.CollidableA == this)
                 endPair.listIndexA = index;
             else
                 endPair.listIndexB = index;
         }
     }
     index = -1;
 }
示例#34
0
 internal ContactCollection(CollidablePairHandler pair)
 {
     this.pair = pair;
 }