Ejemplo n.º 1
0
            public override void OnContactNotify(ContactPair contactInformation, ContactPairFlag events)
            {
                ContactStreamIterator iter;

                using (iter = new ContactStreamIterator(contactInformation.ContactStream))
                {
                    while (iter.GoToNextPair())
                    {
                        while (iter.GoToNextPatch())
                        {
                            while (iter.GoToNextPoint())
                            {
                                // Test each of the available 'information' functions/properties

                                int       numberOfPairs            = iter.GetNumberOfPairs();
                                Shape     shapeA                   = iter.GetShapeA();
                                Shape     shapeB                   = iter.GetShapeB();
                                bool      isShapeADeleted          = iter.IsDeletedShapeA();
                                bool      isShapeBDeleted          = iter.IsDeletedShapeB();
                                ShapeFlag shapeFlags               = iter.GetShapeFlags();
                                int       numberOfPatches          = iter.GetNumberOfPatches();
                                int       numberOfPatchesRemaining = iter.GetNumberOfPatchesRemaining();
                                Vector3   patchNormal              = iter.GetPatchNormal();
                                int       numberOfPoints           = iter.GetNumberOfPoints();
                                int       numberOfPointsRemaining  = iter.GetNumberOfPointsRemaining();
                                Vector3   point            = iter.GetPoint();
                                float     separation       = iter.GetSeperation();
                                int       featureIndex0    = iter.GetFeatureIndex0();
                                int       featureIndex1    = iter.GetFeatureIndex1();
                                float     pointNormalForce = iter.GetPointNormalForce();

                                // First collision should be AB
                                if (IsPairContacting(shapeA, A, B) && IsPairContacting(shapeB, A, B))
                                {
                                    ABHitCallback();
                                }

                                // Second collision should be BC, but only if AB has happened
                                if (IsPairContacting(shapeA, B, C) && IsPairContacting(shapeB, B, C))
                                {
                                    BCHitCallback();
                                }
                            }
                        }
                    }
                }

                Assert.IsTrue(iter.IsDisposed);
            }
Ejemplo n.º 2
0
        public override void OnContactNotify(ContactPair contactInfo, ContactPairFlag events)
        {
            using (ContactStreamIterator iter = new ContactStreamIterator(contactInfo.ContactStream))
            {
                //if we are looking at the player car
                if (contactInfo.ActorB.Group == PhysXConsts.VehicleId)
                {
                    Vehicle vehicle = (Vehicle)contactInfo.ActorB.UserData;

                    while (iter.GoToNextPair())
                    {
                        while (iter.GoToNextPatch())
                        {
                            while (iter.GoToNextPoint())
                            {
                                if (contactInfo.ActorA.Group == PhysXConsts.TrackId && iter.GetShapeB() is WheelShape)
                                {
                                    continue; //we dont want to know each time a wheel is touching the ground
                                }
                                Vector3 pos = iter.GetPoint();

                                if (contactInfo.ActorA.UserData is NonCar)
                                {
                                    HandleNonCarCollision(vehicle, (NonCar)contactInfo.ActorA.UserData, pos, iter.GetPatchNormal(), contactInfo.NormalForce, events);
                                    return;
                                }

                                float force = contactInfo.NormalForce.Length(); // iter.GetPointNormalForce();
                                if (force == 0)
                                {
                                    continue;
                                }

                                //GameConsole.WriteEvent(force.ToString());

                                if (force > 0)
                                {
                                    if (contactInfo.ActorA.Group == PhysXConsts.VehicleId)
                                    {
                                        Vehicle vehicle2 = (Vehicle)contactInfo.ActorA.UserData;
                                        //2 vehicle collision
                                        force = iter.GetPointNormalForce();
                                        Vector3 normal = contactInfo.NormalForce;
                                        normal.Normalize();
                                        if (vehicle.Driver is CpuDriver && vehicle2.Driver is PlayerDriver)
                                        {
                                            ((CpuDriver)vehicle.Driver).OnPlayerHit(force);
                                        }
                                        else if (vehicle2.Driver is CpuDriver && vehicle.Driver is PlayerDriver)
                                        {
                                            ((CpuDriver)vehicle2.Driver).OnPlayerHit(force);
                                        }

                                        // stop cars rearing up if they are both trying to push each other.
                                        if (vehicle.Chassis.Wheels.Find(a => !a.IsRear && a.InAir) != null)
                                        {
                                            vehicle.Chassis.Actor.AddForceAtPosition(Vector3.Down * 0.35f * force, pos, ForceMode.Force);
                                        }
                                        if (vehicle2.Chassis.Wheels.Find(a => !a.IsRear && a.InAir) != null)
                                        {
                                            vehicle2.Chassis.Actor.AddForceAtPosition(Vector3.Down * 0.35f * force, pos, ForceMode.Force);
                                        }

                                        vehicle.OnCollision(force * 2, pos, normal, true);
                                        vehicle2.OnCollision(force * 2, pos, normal, true);
                                    }
                                    else
                                    {
                                        Vector3 normal = contactInfo.NormalForce;
                                        normal.Normalize();
                                        if (iter.GetPointNormalForce() != 0)
                                        {
                                            force = iter.GetPointNormalForce();
                                        }

                                        vehicle.OnCollision(force, pos, iter.GetPatchNormal(), true);
                                        //return;
                                    }
                                }
                            }
                        }
                    }
                }

                // a non-car object sliding along the track
                else if (contactInfo.ActorB.Group == PhysXConsts.NonCarId && contactInfo.ActorA.Group == PhysXConsts.TrackId)
                {
                    if (contactInfo.ActorB.LinearVelocity.Length() > 4)
                    {
                        while (iter.GoToNextPair())
                        {
                            while (iter.GoToNextPatch())
                            {
                                while (iter.GoToNextPoint())
                                {
                                    Vector3 pos = iter.GetPoint();

                                    GameVars.SparksEmitter.Update(pos);
                                }
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
			public override void OnContactNotify( ContactPair contactInformation, ContactPairFlag events )
			{
				ContactStreamIterator iter;
				using( iter = new ContactStreamIterator( contactInformation.ContactStream ) )
				{
					while( iter.GoToNextPair() )
					{
						while( iter.GoToNextPatch() )
						{
							while( iter.GoToNextPoint() )
							{
								// Test each of the available 'information' functions/properties

								int numberOfPairs = iter.GetNumberOfPairs();
								Shape shapeA = iter.GetShapeA();
								Shape shapeB = iter.GetShapeB();
								bool isShapeADeleted = iter.IsDeletedShapeA();
								bool isShapeBDeleted = iter.IsDeletedShapeB();
								ShapeFlag shapeFlags = iter.GetShapeFlags();
								int numberOfPatches = iter.GetNumberOfPatches();
								int numberOfPatchesRemaining = iter.GetNumberOfPatchesRemaining();
								Vector3 patchNormal = iter.GetPatchNormal();
								int numberOfPoints = iter.GetNumberOfPoints();
								int numberOfPointsRemaining = iter.GetNumberOfPointsRemaining();
								Vector3 point = iter.GetPoint();
								float separation = iter.GetSeperation();
								int featureIndex0 = iter.GetFeatureIndex0();
								int featureIndex1 = iter.GetFeatureIndex1();
								float pointNormalForce = iter.GetPointNormalForce();

								// First collision should be AB
								if( IsPairContacting( shapeA, A, B ) && IsPairContacting( shapeB, A, B ) )
								{
									ABHitCallback();
								}

								// Second collision should be BC, but only if AB has happened
								if( IsPairContacting( shapeA, B, C ) && IsPairContacting( shapeB, B, C ) )
								{
									BCHitCallback();
								}
							}
						}
					}
				}

				Assert.IsTrue( iter.IsDisposed );
			}
Ejemplo n.º 4
0
        public override void OnContactNotify(ContactPair contactInfo, ContactPairFlag events)
        {
            using (ContactStreamIterator iter = new ContactStreamIterator(contactInfo.ContactStream))
            {
                //if we are looking at the player car
                if (contactInfo.ActorB.Group == PhysXConsts.VehicleId)
                {
                    Vehicle vehicle = (Vehicle)contactInfo.ActorB.UserData;

                    while (iter.GoToNextPair())
                    {
                        while (iter.GoToNextPatch())
                        {
                            while (iter.GoToNextPoint())
                            {
                                if (contactInfo.ActorA.Group == PhysXConsts.TrackId && iter.GetShapeB() is WheelShape)
                                    continue; //we dont want to know each time a wheel is touching the ground

                                Vector3 pos = iter.GetPoint();

                                if (contactInfo.ActorA.UserData is NonCar)
                                {
                                    HandleNonCarCollision(vehicle, (NonCar)contactInfo.ActorA.UserData, pos, iter.GetPatchNormal(), contactInfo.NormalForce, events);
                                    return;
                                }

                                float force = contactInfo.NormalForce.Length(); // iter.GetPointNormalForce();
                                if (force == 0) continue;

                                //GameConsole.WriteEvent(force.ToString());

                                if (force > 0)
                                {
                                    if (contactInfo.ActorA.Group == PhysXConsts.VehicleId)
                                    {
                                        Vehicle vehicle2 = (Vehicle)contactInfo.ActorA.UserData;
                                        //2 vehicle collision
                                        force = iter.GetPointNormalForce();
                                        Vector3 normal = contactInfo.NormalForce;
                                        normal.Normalize();
                                        if (vehicle.Driver is CpuDriver && vehicle2.Driver is PlayerDriver)
                                        {
                                            ((CpuDriver)vehicle.Driver).OnPlayerHit(force);
                                        }
                                        else if (vehicle2.Driver is CpuDriver && vehicle.Driver is PlayerDriver)
                                        {
                                            ((CpuDriver)vehicle2.Driver).OnPlayerHit(force);
                                        }

                                        // stop cars rearing up if they are both trying to push each other.
                                        if (vehicle.Chassis.Wheels.Find(a => !a.IsRear && a.InAir) != null)
                                        {
                                            vehicle.Chassis.Actor.AddForceAtPosition(Vector3.Down * 0.35f * force, pos, ForceMode.Force);
                                        }
                                        if (vehicle2.Chassis.Wheels.Find(a => !a.IsRear && a.InAir) != null)
                                        {
                                            vehicle2.Chassis.Actor.AddForceAtPosition(Vector3.Down * 0.35f * force, pos, ForceMode.Force);
                                        }

                                        vehicle.OnCollision(force * 2, pos, normal, true);
                                        vehicle2.OnCollision(force * 2, pos, normal, true);
                                    }
                                    else
                                    {
                                        Vector3 normal = contactInfo.NormalForce;
                                        normal.Normalize();
                                        if (iter.GetPointNormalForce() != 0)
                                            force = iter.GetPointNormalForce();

                                        vehicle.OnCollision(force, pos, iter.GetPatchNormal(), true);
                                        //return;
                                    }
                                }
                            }
                        }
                    }
                }

                // a non-car object sliding along the track
                else if (contactInfo.ActorB.Group == PhysXConsts.NonCarId && contactInfo.ActorA.Group == PhysXConsts.TrackId)
                {
                    if (contactInfo.ActorB.LinearVelocity.Length() > 4)
                    {
                        while (iter.GoToNextPair())
                        {
                            while (iter.GoToNextPatch())
                            {
                                while (iter.GoToNextPoint())
                                {
                                    Vector3 pos = iter.GetPoint();

                                    GameVars.SparksEmitter.Update(pos);
                                }
                            }
                        }
                    }
                }
            }
        }