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");
            }
        }
        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 { }*/
        }
Beispiel #3
0
        /// <summary>
        /// Constructs a new demo.
        /// </summary>
        /// <param name="game">Game owning this demo.</param>
        public FishInABarrelDemo(DemosGame game)
            : base(game)
        {
            game.Camera.Position = new Vector3(0, 7, 30);

            var detector = new Box(new Vector3(0, 0, 0), 1.5f, 1.5f, 1.5f);
            detector.CollisionInformation.CollisionRules.Personal = CollisionRule.NoSolver;
            var acceptedTriggerEntity = new Box(new Vector3(5, 0, 0), 1.6f, .7f, .4f, 1);
            acceptedTrigger = acceptedTriggerEntity.CollisionInformation;

            detector.Tag = "noDisplayObject";
            acceptedTriggerEntity.Tag = "noDisplayObject";
            Space.Add(detector);
            Space.Add(acceptedTriggerEntity);

            var fish = game.Content.Load<Model>("fish");
            game.ModelDrawer.Add(new DisplayEntityModel(acceptedTriggerEntity, fish, game.ModelDrawer));

            var barrelAndPlatform = game.Content.Load<Model>("barrelAndPlatform");
            Vector3[] staticTriangleVertices;
            int[] staticTriangleIndices;
            TriangleMesh.GetVerticesAndIndicesFromModel(barrelAndPlatform, out staticTriangleVertices, out staticTriangleIndices);

            //Note that the final 'margin' parameter is optional, but can be used to specify a collision margin on triangles in the static triangle group.
            var fishDepositoryGroup = new StaticMesh(staticTriangleVertices, staticTriangleIndices);
            CollisionRules.AddRule(fishDepositoryGroup, detector, CollisionRule.NoBroadPhase);
            Space.Add(fishDepositoryGroup);
            game.ModelDrawer.Add(fishDepositoryGroup);

            movedBox = new Box(new Vector3(-4, 5, 0), 1, 1, 1, 1);
            detector.Space.Add(movedBox);
            detector.CollisionInformation.Events.InitialCollisionDetected += InitialCollisionDetected;
            detector.CollisionInformation.Events.CollisionEnded += CollisionEnded;
        }
Beispiel #4
0
        void HandleCollision(EntityCollidable sender, Collidable other, CollidablePairHandler pair)
        {
            if (soundEffect != null)
            {
                emitter.Position = body.Position / 5.0f;

            }
        }
        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();
        }
Beispiel #6
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();
     }
 }
Beispiel #7
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;
     }
 }
Beispiel #8
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();
         }
     }
 }
Beispiel #9
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();
         }
     }
 }
        /// <summary>
        /// [Utility] Recovers the object from collidable.
        /// </summary>
        /// <param name="collidable">The collidable.</param>
        /// <returns></returns>
        public static IObject RecoverObjectFromCollidable(BEPUphysics.Collidables.Collidable collidable)
        {
            IPhysicObject phy = (collidable.Tag as IPhysicObject);

            if (phy != null)
            {
                return(phy.ObjectOwner);
            }
            return(null);
        }
Beispiel #11
0
        public override void InitialCollisionDetected(BEPUphysics.Collidables.MobileCollidables.EntityCollidable sender, Collidable other, BEPUphysics.NarrowPhaseSystems.Pairs.CollidablePairHandler collisionPair)
        {
            base.InitialCollisionDetected(sender, other, collisionPair);

            if (other.Tag is CharacterSynchronizer)
            {
                ((other.Tag as CharacterSynchronizer).body.Tag as Creature).Poisoned = true;
                ((other.Tag as CharacterSynchronizer).body.Tag as Creature).Damage(0, mOwner as Creature);
            }
            World.Remove(this);
        }
Beispiel #12
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++;
     }
 }
        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();

            }
        }
Beispiel #14
0
        ///<summary>
        /// Initializes the manifold.
        ///</summary>
        ///<param name="newCollidableA">First collidable.</param>
        ///<param name="newCollidableB">Second collidable.</param>
        public override void Initialize(Collidable newCollidableA, Collidable newCollidableB)
        {
            convex = newCollidableA as ConvexCollidable;
            mesh = newCollidableB as StaticMesh;


            if (convex == null || mesh == null)
            {
                convex = newCollidableB as ConvexCollidable;
                mesh = newCollidableA as StaticMesh;
                if (convex == null || mesh == null)
                    throw new Exception("Inappropriate types used to initialize contact manifold.");
            }

        }
Beispiel #15
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();
     }
 }
Beispiel #16
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();
     }
 }
Beispiel #17
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 { }
 }
Beispiel #18
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;
                    }
            }
        }
        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;
        }
        ///<summary>
        /// Updates the time of impact for the pair.
        ///</summary>
        ///<param name="requester">Collidable requesting the update.</param>
        ///<param name="dt">Timestep duration.</param>
        public override void UpdateTimeOfImpact(Collidable requester, float dt)
        {
            var collidableA = CollidableA as ConvexCollidable;
            var collidableB = CollidableB as ConvexCollidable;
            var overlap = BroadPhaseOverlap;
            if (
                    (overlap.entryA.IsActive || overlap.entryB.IsActive) && //At least one has to be active.
                    (
                        (
                            collidableA.entity.PositionUpdateMode == PositionUpdateMode.Continuous &&   //If both are continuous, only do the process for A.
                            collidableB.entity.PositionUpdateMode == PositionUpdateMode.Continuous &&
                            overlap.entryA == requester
                        ) ||
                        (
                            collidableA.entity.PositionUpdateMode == PositionUpdateMode.Continuous ^   //If only one is continuous, then we must do it.
                            collidableB.entity.PositionUpdateMode == PositionUpdateMode.Continuous
                        )
                    )
                )
            {
                //Only perform the test if the minimum radii are small enough relative to the size of the velocity.
                //Discrete objects have already had their linear motion integrated, so don't use their velocity.
                Vector3 velocity;
                if (collidableA.entity.PositionUpdateMode == PositionUpdateMode.Discrete)
                    velocity = collidableB.entity.linearVelocity;
                else if (collidableB.entity.PositionUpdateMode == PositionUpdateMode.Discrete)
                    Vector3.Negate(ref collidableA.entity.linearVelocity, out velocity);
                else
                    Vector3.Subtract(ref collidableB.entity.linearVelocity, ref collidableA.entity.linearVelocity, out velocity);
                Vector3.Multiply(ref velocity, dt, out velocity);
                float velocitySquared = velocity.LengthSquared();

                var minimumRadiusA = collidableA.Shape.minimumRadius * MotionSettings.CoreShapeScaling;
                timeOfImpact = 1;
                if (minimumRadiusA * minimumRadiusA < velocitySquared)
                {
                    //Spherecast A against B.
                    RayHit rayHit;
                    if (GJKToolbox.CCDSphereCast(new Ray(collidableA.worldTransform.Position, -velocity), minimumRadiusA, collidableB.Shape, ref collidableB.worldTransform, timeOfImpact, out rayHit))
                        timeOfImpact = rayHit.T;
                }

                var minimumRadiusB = collidableB.Shape.minimumRadius * MotionSettings.CoreShapeScaling;
                if (minimumRadiusB * minimumRadiusB < velocitySquared)
                {
                    //Spherecast B against A.
                    RayHit rayHit;
                    if (GJKToolbox.CCDSphereCast(new Ray(collidableB.worldTransform.Position, velocity), minimumRadiusB, collidableA.Shape, ref collidableA.worldTransform, timeOfImpact, out rayHit))
                        timeOfImpact = rayHit.T;
                }

                //If it's intersecting, throw our hands into the air and give up.
                //This is generally a perfectly acceptable thing to do, since it's either sitting
                //inside another object (no ccd makes sense) or we're still in an intersecting case
                //from a previous frame where CCD took place and a contact should have been created
                //to deal with interpenetrating velocity.  Sometimes that contact isn't sufficient,
                //but it's good enough.
                if (timeOfImpact == 0)
                    timeOfImpact = 1;
            }

        }
Beispiel #22
0
 ///<summary>
 /// Initializes the pair tester.
 ///</summary>
 ///<param name="shapeA">First shape in the pair.</param>
 ///<param name="shapeB">Second shape in the pair.</param>
 public void Initialize(Collidable shapeA, Collidable shapeB)
 {
     collidableA = (ConvexCollidable)shapeA;
     collidableB = (ConvexCollidable)shapeB;
     cachedSimplex = new CachedSimplex { State = SimplexState.Point };// new CachedSimplex(informationA.Shape, informationB.Shape, ref informationA.worldTransform, ref informationB.worldTransform);
 }
        ///<summary>
        /// Updates the time of impact for the pair.
        ///</summary>
        ///<param name="requester">Collidable requesting the update.</param>
        ///<param name="dt">Timestep duration.</param>
        public override void UpdateTimeOfImpact(Collidable requester, float dt)
        {
            //TODO: This conditional early outing stuff could be pulled up into a common system, along with most of the pair handler.
            var overlap = BroadPhaseOverlap;
            var convexMode = convex.entity == null ? PositionUpdateMode.Discrete : convex.entity.PositionUpdateMode;

            if (
                    (mobileMesh.IsActive || (convex.entity == null ? false : convex.entity.activityInformation.IsActive)) && //At least one has to be active.
                    (
                        (
                            convexMode == PositionUpdateMode.Continuous &&   //If both are continuous, only do the process for A.
                            mobileMesh.entity.PositionUpdateMode == PositionUpdateMode.Continuous &&
                            overlap.entryA == requester
                        ) ||
                        (
                            convexMode == PositionUpdateMode.Continuous ^   //If only one is continuous, then we must do it.
                            mobileMesh.entity.PositionUpdateMode == PositionUpdateMode.Continuous
                        )
                    )
                )
            {
                //TODO: This system could be made more robust by using a similar region-based rejection of edges.
                //CCD events are awfully rare under normal circumstances, so this isn't usually an issue.

                //Only perform the test if the minimum radii are small enough relative to the size of the velocity.
                Vector3 velocity;
                if (convex.entity != null)
                    Vector3.Subtract(ref convex.entity.linearVelocity, ref mobileMesh.entity.linearVelocity, out velocity);
                else
                    Vector3.Negate(ref mobileMesh.entity.linearVelocity, out velocity);
                Vector3.Multiply(ref velocity, dt, out velocity);
                float velocitySquared = velocity.LengthSquared();

                var minimumRadius = convex.Shape.minimumRadius * MotionSettings.CoreShapeScaling;
                timeOfImpact = 1;
                if (minimumRadius * minimumRadius < velocitySquared)
                {
                    TriangleSidedness sidedness = mobileMesh.Shape.Sidedness;
                    Matrix3X3 orientation;
                    Matrix3X3.CreateFromQuaternion(ref mobileMesh.worldTransform.Orientation, out orientation);
                    var triangle = Resources.GetTriangle();
                    triangle.collisionMargin = 0;
                    //Spherecast against all triangles to find the earliest time.
                    for (int i = 0; i < MeshManifold.overlappedTriangles.count; i++)
                    {
                        MeshBoundingBoxTreeData data = mobileMesh.Shape.TriangleMesh.Data;
                        int triangleIndex = MeshManifold.overlappedTriangles.Elements[i];
                        data.GetTriangle(triangleIndex, out triangle.vA, out triangle.vB, out triangle.vC);
                        Matrix3X3.Transform(ref triangle.vA, ref orientation, out triangle.vA);
                        Matrix3X3.Transform(ref triangle.vB, ref orientation, out triangle.vB);
                        Matrix3X3.Transform(ref triangle.vC, ref orientation, out triangle.vC);
                        Vector3.Add(ref triangle.vA, ref mobileMesh.worldTransform.Position, out triangle.vA);
                        Vector3.Add(ref triangle.vB, ref mobileMesh.worldTransform.Position, out triangle.vB);
                        Vector3.Add(ref triangle.vC, ref mobileMesh.worldTransform.Position, out triangle.vC);
                        //Put the triangle into 'localish' space of the convex.
                        Vector3.Subtract(ref triangle.vA, ref convex.worldTransform.Position, out triangle.vA);
                        Vector3.Subtract(ref triangle.vB, ref convex.worldTransform.Position, out triangle.vB);
                        Vector3.Subtract(ref triangle.vC, ref convex.worldTransform.Position, out triangle.vC);

                        RayHit rayHit;
                        if (GJKToolbox.CCDSphereCast(new Ray(Toolbox.ZeroVector, velocity), minimumRadius, triangle, ref Toolbox.RigidIdentity, timeOfImpact, out rayHit) &&
                            rayHit.T > Toolbox.BigEpsilon)
                        {

                            if (sidedness != TriangleSidedness.DoubleSided)
                            {
                                Vector3 AB, AC;
                                Vector3.Subtract(ref triangle.vB, ref triangle.vA, out AB);
                                Vector3.Subtract(ref triangle.vC, ref triangle.vA, out AC);
                                Vector3 normal;
                                Vector3.Cross(ref AB, ref AC, out normal);
                                float dot;
                                Vector3.Dot(ref normal, ref rayHit.Normal, out dot);
                                //Only perform sweep if the object is in danger of hitting the object.
                                //Triangles can be one sided, so check the impact normal against the triangle normal.
                                if (sidedness == TriangleSidedness.Counterclockwise && dot < 0 ||
                                    sidedness == TriangleSidedness.Clockwise && dot > 0)
                                {
                                    timeOfImpact = rayHit.T;
                                }
                            }
                            else
                            {
                                timeOfImpact = rayHit.T;
                            }
                        }
                    }
                    Resources.GiveBack(triangle);
                }



            }

        }
 /// <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);
 }
Beispiel #25
0
 /// <summary>
 /// Used to handle a collision event triggered by an entity specified above.
 /// </summary>
 /// <param name="sender">Entity that had an event hooked.</param>
 /// <param name="other">Entity causing the event to be triggered.</param>
 /// <param name="pair">Collision pair between the two objects in the event.</param>
 void HandleCollision(EntityCollidable sender, Collidable other, CollidablePairHandler pair)
 {
     //This type of event can occur when an entity hits any other object which can be collided with.
     //They aren't always entities; for example, hitting a StaticMesh would trigger this.
     //Entities use EntityCollidables as collision proxies; see if the thing we hit is one.
     var otherEntityInformation = other as EntityCollidable;
     if (otherEntityInformation != null)
     {
         //We hit an entity! remove it.
         space.Remove(otherEntityInformation.Entity);
         //Remove the graphics too.
         Components.Remove((EntityModel)otherEntityInformation.Entity.Tag);
     }
 }
Beispiel #26
0
 void Events_InitialCollisionDetected(EntityCollidable sender, Collidable other, CollidablePairHandler pair)
 {
     Explode();
 }
 private void OnCollision(EntityCollidable sender, Collidable other, CollidablePairHandler pair)
 {
     var otherEntity = other as EntityCollidable;
     if(otherEntity != null)
     {
         if(otherEntity.Tag is Box)
         {
             if(UsesLaserSound)
             {
                 (otherEntity.Tag as Box).PlayParticles();
                 MediaSystem.PlaySoundEffect(SFXOptions.Laser);
             }
             GameManager.CurrentLevel.DestroyBox((Box)otherEntity.Tag);
         }
     }
 }
Beispiel #28
0
 public virtual void CollisionEnded(EntityCollidable sender, Collidable other, CollidablePairHandler collisionPair)
 {
     if (other.Tag is CharacterSynchronizer)
     {
         CollidingObjects.Remove((other.Tag as CharacterSynchronizer).body.Tag as IGameObject);
     }
     else
     {
         CollidingObjects.Remove(other.Tag as IGameObject);
     }
 }
Beispiel #29
0
 public virtual void InitialCollisionDetected(EntityCollidable sender, Collidable other, CollidablePairHandler collisionPair)
 {
     if (other.Tag is CharacterSynchronizer)
     {
         CharacterSynchronizer synchronizer = (other.Tag as CharacterSynchronizer);
         CollidingObjects.Add(synchronizer.body.Tag as IGameObject);
     }
     else
     {
         CollidingObjects.Add(other.Tag as IGameObject);
     }
 }
Beispiel #30
0
 /// <summary>
 /// Computes the intersection, if any, between a ray and the objects in the character's bounding box.
 /// </summary>
 /// <param name="ray">Ray to test.</param>
 /// <param name="length">Length of the ray to use in units of the ray's length.</param>
 /// <param name="earliestHit">Earliest intersection location and information.</param>
 /// <param name="hitObject">Collidable intersected by the ray, if any.</param>
 /// <returns>Whether or not the ray hit anything.</returns>
 public bool RayCast(Ray ray, float length, out RayHit earliestHit, out Collidable hitObject)
 {
     earliestHit = new RayHit();
     earliestHit.T = float.MaxValue;
     hitObject = null;
     foreach (var collidable in character.Body.CollisionInformation.OverlappedCollidables)
     {
         //Check to see if the collidable is hit by the ray.
         float? t = ray.Intersects(collidable.BoundingBox);
         if (t != null && t < length)
         {
             //Is it an earlier hit than the current earliest?
             RayHit hit;
             if (collidable.RayCast(ray, length, SupportRayFilter, out hit) && hit.T < earliestHit.T)
             {
                 earliestHit = hit;
                 hitObject = collidable;
             }
         }
     }
     if (earliestHit.T == float.MaxValue)
         return false;
     return true;
 }
Beispiel #31
0
 /// <summary>
 /// Handle collision event triggered by entity
 /// </summary>
 /// <param name="sender">Entity that had an event hooked</param>
 /// <param name="other">Entity causing event to be triggered</param>
 /// <param name="pair">Collision pair between the two objects in the event</param>
 void HandleCollision(EntityCollidable sender, Collidable other, CollidablePairHandler pair)
 {
     var otherEntityInformation = other as EntityCollidable;
     if (otherEntityInformation != null)
     {
         // hit an entity, remove it
         _space.Remove(otherEntityInformation.Entity);
         // also remove graphics
         Components.Remove((EntityModel)otherEntityInformation.Entity.Tag);
     }
 }