示例#1
0
        private void ContactProcess(object sender, Game.Newt.v1.NewtonDynamics1.Api.CContactProcessEventArgs e)
        {
            #region Get Keys

            string key = _currentCollidingKey;
            if (key == null)
            {
                throw new ApplicationException("ContactProcess was called before ContactBegin");
            }
            else if (!_collisionListeners.ContainsKey(key))
            {
                throw new ApplicationException("There is no listener for this material pair, but how did this callback get set up???: " + key);
            }

            #endregion

            // See if I should duck out early
            CollisionEventProps eventProps = _collisionListeners[key];
            if (eventProps.HasRaisedContactEvent || eventProps.HasContactCancelled)       // if they cancelled in the begin event, but for some reason this process event still fires, I don't want them to see it
            {
                if (eventProps.HasContactCancelled)
                {
                    e.AllowCollision = false;
                }
                return;
            }

            // Remember that I've raised the event to the outside (so they only get informed once)
            eventProps.HasRaisedContactEvent = true;

            // Validate
            if (eventProps.CollisionBody1 == null || eventProps.CollisionBody2 == null)
            {
                throw new ApplicationException("Received a collision contact event without the start event");
            }

            if (eventProps.CollisionEnd != null)
            {
                // Raise an event to the outside
                CollisionEndEventArgs args = new CollisionEndEventArgs(e.Material, e.Contact, eventProps.Material1, eventProps.Material2);
                args.Body1 = eventProps.CollisionBody1;
                args.Body2 = eventProps.CollisionBody2;

                eventProps.CollisionEnd(this, args);

                e.AllowCollision = args.AllowCollision;
            }

            if (!e.AllowCollision)
            {
                eventProps.HasContactCancelled = true;
            }
        }
        private void ContactProcess(object sender, Game.Newt.v1.NewtonDynamics1.Api.CContactProcessEventArgs e)
        {
            #region Get Keys

            string key = _currentCollidingKey;
            if (key == null)
            {
                throw new ApplicationException("ContactProcess was called before ContactBegin");
            }
            else if (!_collisionListeners.ContainsKey(key))
            {
                throw new ApplicationException("There is no listener for this material pair, but how did this callback get set up???: " + key);
            }

            #endregion

            // See if I should duck out early
            CollisionEventProps eventProps = _collisionListeners[key];
            if (eventProps.HasRaisedContactEvent || eventProps.HasContactCancelled)       // if they cancelled in the begin event, but for some reason this process event still fires, I don't want them to see it
            {
                if (eventProps.HasContactCancelled)
                {
                    e.AllowCollision = false;
                }
                return;
            }

            // Remember that I've raised the event to the outside (so they only get informed once)
            eventProps.HasRaisedContactEvent = true;

            // Validate
            if (eventProps.CollisionBody1 == null || eventProps.CollisionBody2 == null)
            {
                throw new ApplicationException("Received a collision contact event without the start event");
            }

            if (eventProps.CollisionEnd != null)
            {
                // Raise an event to the outside
                CollisionEndEventArgs args = new CollisionEndEventArgs(e.Material, e.Contact, eventProps.Material1, eventProps.Material2);
                args.Body1 = eventProps.CollisionBody1;
                args.Body2 = eventProps.CollisionBody2;

                eventProps.CollisionEnd(this, args);

                e.AllowCollision = args.AllowCollision;
            }

            if (!e.AllowCollision)
            {
                eventProps.HasContactCancelled = true;
            }
        }
示例#3
0
        public void CollideWithAsteroid(Asteroid asteroid, CollisionEndEventArgs e)
        {
            // Figure out the impulse










        }
        private void Collision_Ship_Asteroid(object sender, CollisionEndEventArgs e)
        {
            Ship ship = null;
            Asteroid asteroid = null;
            if (e.Body1 is Ship)
            {
                ship = (Ship)e.Body1;
                asteroid = (Asteroid)e.Body2;
            }
            else
            {
                ship = (Ship)e.Body2;
                asteroid = (Asteroid)e.Body1;
            }

            ship.CollideWithAsteroid(asteroid, e);
        }
        private void Collision_Ship_Mineral(object sender, CollisionEndEventArgs e)
        {

            // They all return 0's
            //Point3D contactPoint = e.ContactPositionWorld;
            //Vector3D contactNormal = e.ContactNormalWorld;
            //Vector3D contactForce = e.ContactForceWorld;


            Ship ship = null;
            Mineral mineral = null;
            if (e.Body1 is Ship)
            {
                ship = (Ship)e.Body1;
                mineral = (Mineral)e.Body2;
            }
            else
            {
                ship = (Ship)e.Body2;
                mineral = (Mineral)e.Body1;
            }

            if (ship.CollideWithMineral(mineral))
            {
                // The ship is taking the mineral
                e.AllowCollision = false;
                _map.RemoveItem(mineral);
            }
        }