示例#1
0
        protected virtual bool OnContactProcess(CContactProcessEventArgs pEventArgs)
        {
            if (m_ContactProcess != null)
            {
                m_ContactProcess(this, pEventArgs);
            }

            return(pEventArgs.AllowCollision);
        }
示例#2
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;
            }
        }
		protected virtual bool OnContactProcess(CContactProcessEventArgs pEventArgs)
		{
			if (m_ContactProcess != null)
			{
				m_ContactProcess(this, pEventArgs);
			}

            return pEventArgs.AllowCollision;
		}