Exemple #1
0
        private void LoadVehiclePhysics(Scene scene)
        {
            // Create a 2 ton car with 4 wheels
            BodyDescription bodyDesc = new BodyDescription()
            {
                Mass = 2000
            };

            //bodyDesc.MassLocalPose = Matrix.CreateTranslation( 0, -1.5f, 0 ); // Seems not to be working

            ActorDesc = new ActorDescription()
            {
                BodyDescription = bodyDesc,
                Shapes          = { new BoxShapeDescription(5, 3, 7) },
                GlobalPose      = Matrix.Translation(-50, 5, -70)
            };

            VehicleBodyActor = scene.CreateActor(ActorDesc);
            VehicleBodyActor.SetCenterOfMassOffsetLocalPosition(new Vector3(0, -1.5f, 0)); // Move the COM to the bottom of the vehicle to stop it flipping over so much

            //

            WheelShapeDescription leftFrontDesc = new WheelShapeDescription()
            {
                Radius           = 0.8f,
                SuspensionTravel = 1,
                LocalPosition    = new Vector3(-2.5f, -1, 3)
            };

            WheelShapeDescription leftRearDesc = new WheelShapeDescription()
            {
                Radius           = 0.8f,
                SuspensionTravel = 1,
                LocalPosition    = new Vector3(-2.5f, -1, -3),
            };

            WheelShapeDescription rightFrontDesc = new WheelShapeDescription()
            {
                Radius           = 0.8f,
                SuspensionTravel = 1,
                LocalPosition    = new Vector3(2.5f, -1, 3)
            };

            WheelShapeDescription rightRearDesc = new WheelShapeDescription()
            {
                Radius           = 0.8f,
                SuspensionTravel = 1,
                LocalPosition    = new Vector3(2.5f, -1, -3)
            };

            this.LeftFront  = VehicleBodyActor.CreateShape(leftFrontDesc) as WheelShape;
            this.LeftRear   = VehicleBodyActor.CreateShape(leftRearDesc) as WheelShape;
            this.RightFront = VehicleBodyActor.CreateShape(rightFrontDesc) as WheelShape;
            this.RightRear  = VehicleBodyActor.CreateShape(rightRearDesc) as WheelShape;
        }
		private void LoadVehiclePhysics(Scene scene)
		{
			// Create a 2 ton car with 4 wheels
			BodyDescription bodyDesc = new BodyDescription()
			{
				Mass = 2000
			};
			//bodyDesc.MassLocalPose = Matrix.CreateTranslation( 0, -1.5f, 0 ); // Seems not to be working

			ActorDescription actorDesc = new ActorDescription()
			{
				BodyDescription = bodyDesc,
				Shapes = { new BoxShapeDescription(5, 3, 7) },
				GlobalPose = Matrix.Translation(-50, 5, -70)
			};

			_vehicleBodyActor = scene.CreateActor(actorDesc);
			_vehicleBodyActor.SetCenterOfMassOffsetLocalPosition(new Vector3(0, -1.5f, 0)); // Move the COM to the bottom of the vehicle to stop it flipping over so much

			//

			WheelShapeDescription leftFrontDesc = new WheelShapeDescription()
			{
				Radius = 0.8f,
				SuspensionTravel = 1,
				LocalPosition = new Vector3(-2.5f, -1, 3)
			};

			WheelShapeDescription leftRearDesc = new WheelShapeDescription()
			{
				Radius = 0.8f,
				SuspensionTravel = 1,
				LocalPosition = new Vector3(-2.5f, -1, -3),
			};

			WheelShapeDescription rightFrontDesc = new WheelShapeDescription()
			{
				Radius = 0.8f,
				SuspensionTravel = 1,
				LocalPosition = new Vector3(2.5f, -1, 3)
			};

			WheelShapeDescription rightRearDesc = new WheelShapeDescription()
			{
				Radius = 0.8f,
				SuspensionTravel = 1,
				LocalPosition = new Vector3(2.5f, -1, -3)
			};

			this.LeftFront = _vehicleBodyActor.CreateShape(leftFrontDesc) as WheelShape;
			this.LeftRear = _vehicleBodyActor.CreateShape(leftRearDesc) as WheelShape;
			this.RightFront = _vehicleBodyActor.CreateShape(rightFrontDesc) as WheelShape;
			this.RightRear = _vehicleBodyActor.CreateShape(rightRearDesc) as WheelShape;
		}
Exemple #3
0
        protected override void iniPhysx()
        {
            BodyDescription bodyDesc = new BodyDescription();
            bodyDesc.Mass = 5;
            this.shapeDesc = new WheelShapeDescription();
            this.shapeDesc.Radius = this.Radius;
            shapeDesc.SuspensionTravel = 10;
            //shapeDesc.LocalPosition = localPosition;

            ActorDescription actorDesc = new ActorDescription();
            actorDesc.BodyDescription = bodyDesc;
            actorDesc.GlobalPose = StillDesign.PhysX.MathPrimitives.Matrix.Translation(100,30,0);
            actorDesc.Shapes.Add(shapeDesc);
            this.actor = game.scene.CreateActor(actorDesc);
            this.shape = actor.Shapes[0];
            //this.shape = this.actor.CreateShape(shapeDesc) as WheelShape;
        }
Exemple #4
0
        protected override void iniPhysx()
        {
            BodyDescription bodyDesc = new BodyDescription();

            bodyDesc.Mass              = 5;
            this.shapeDesc             = new WheelShapeDescription();
            this.shapeDesc.Radius      = this.Radius;
            shapeDesc.SuspensionTravel = 10;
            //shapeDesc.LocalPosition = localPosition;

            ActorDescription actorDesc = new ActorDescription();

            actorDesc.BodyDescription = bodyDesc;
            actorDesc.GlobalPose      = StillDesign.PhysX.MathPrimitives.Matrix.Translation(100, 30, 0);
            actorDesc.Shapes.Add(shapeDesc);
            this.actor = game.scene.CreateActor(actorDesc);
            this.shape = actor.Shapes[0];
            //this.shape = this.actor.CreateShape(shapeDesc) as WheelShape;
        }
Exemple #5
0
        public VehicleChassis(Vehicle vehicle)
        {
            Vehicle = vehicle;

            Wheels = new List <VehicleWheel>();

            VehicleFile carFile = vehicle.Config;

            ActorDescription actorDesc = new ActorDescription();

            actorDesc.BodyDescription      = new BodyDescription();
            actorDesc.BodyDescription.Mass = carFile.Mass;
            var boxDesc = new BoxShapeDescription();

            boxDesc.Size          = carFile.BoundingBox.GetSize();
            boxDesc.LocalPosition = carFile.BoundingBox.GetCenter();
            boxDesc.Name          = PhysXConsts.VehicleBody;
            boxDesc.Flags        |= ShapeFlag.PointContactForce;
            actorDesc.Shapes.Add(boxDesc);

            foreach (Vector3 extraPoint in carFile.ExtraBoundingBoxPoints)
            {
                var extraDesc = new SphereShapeDescription(0.2f);
                extraDesc.LocalPosition = extraPoint;
                extraDesc.Mass          = 0;
                actorDesc.Shapes.Add(extraDesc);
            }

            using (UtilitiesLibrary lib = new UtilitiesLibrary())
            {
                Vector3 size          = carFile.Size;
                Vector3 inertiaTensor = lib.ComputeBoxInteriaTensor(Vector3.Zero, carFile.Mass, size);
                //actorDesc.BodyDescription.MassSpaceInertia = inertiaTensor;
            }


            TireFunctionDescription lngTFD = new TireFunctionDescription();

            lngTFD.ExtremumSlip   = 0.1f;
            lngTFD.ExtremumValue  = 4f;
            lngTFD.AsymptoteSlip  = 2.0f;
            lngTFD.AsymptoteValue = 3.2f;

            _rearLateralTireFn = new TireFunctionDescription();

            _rearLateralTireFn.ExtremumSlip   = 0.2f;
            _rearLateralTireFn.ExtremumValue  = 2.1f;
            _rearLateralTireFn.AsymptoteSlip  = 0.0013f * carFile.Mass;
            _rearLateralTireFn.AsymptoteValue = 0.02f;

            _frontLateralTireFn = _rearLateralTireFn;
            _frontLateralTireFn.ExtremumValue = 1.9f;

            MaterialDescription md = new MaterialDescription();

            md.Flags = MaterialFlag.DisableFriction;
            Material m = PhysX.Instance.Scene.CreateMaterial(md);

            int wheelIndex = 0;

            foreach (CWheelActor wheel in carFile.WheelActors)
            {
                WheelShapeDescription wheelDesc = new WheelShapeDescription();
                wheelDesc.InverseWheelMass            = 0.08f;
                wheelDesc.LongitudalTireForceFunction = lngTFD;
                wheelDesc.Flags    = WheelShapeFlag.ClampedFriction;
                wheelDesc.Material = m;

                wheelDesc.Radius           = wheel.IsDriven ? carFile.DrivenWheelRadius : carFile.NonDrivenWheelRadius;
                wheelDesc.SuspensionTravel = (wheel.IsFront ? carFile.SuspensionGiveFront : carFile.SuspensionGiveRear) * 18;

                float heightModifier = (wheelDesc.SuspensionTravel + wheelDesc.Radius) / wheelDesc.SuspensionTravel;

                SpringDescription spring = new SpringDescription();
                if (carFile.Mass > 3000)
                {
                    spring.SpringCoefficient = 10.5f * heightModifier * carFile.Mass;
                }
                else
                {
                    spring.SpringCoefficient = 6.5f * heightModifier * Math.Min(1000, carFile.Mass);
                }
                spring.DamperCoefficient = carFile.SuspensionDamping * 6f;

                wheelDesc.Suspension    = spring;
                wheelDesc.LocalPosition = wheel.Position;
                wheelDesc.Name          = (wheelIndex).ToString();
                wheelIndex++;

                wheelDesc.LateralTireForceFunction = wheel.IsFront ? _frontLateralTireFn : _rearLateralTireFn;
                actorDesc.Shapes.Add(wheelDesc);
            }

            _physXActor = PhysX.Instance.Scene.CreateActor(actorDesc);


            _heightOffset = _physXActor.Shapes[0].LocalPosition.Y * -2;
            if (_heightOffset < 0)
            {
                _heightOffset = 0;
            }

            foreach (Shape shape in _physXActor.Shapes)
            {
                shape.LocalPosition += new Vector3(0, _heightOffset, 0);
                if (shape is WheelShape)
                {
                    wheelIndex = int.Parse(shape.Name);
                    Wheels.Add(new VehicleWheel(this, carFile.WheelActors[wheelIndex], (WheelShape)shape, carFile.WheelActors[wheelIndex].IsLeft ? 0.17f : -0.17f)
                    {
                        Index = wheelIndex
                    });
                }
            }

            _physXActor.Group    = PhysXConsts.VehicleId;
            _physXActor.UserData = vehicle;

            _physXActor.WakeUp(60.0f);

            //_physXActor.RaiseBodyFlag(BodyFlag.DisableGravity);

            //set center of mass
            Vector3 massPos = carFile.CenterOfMass;

            massPos.Y = carFile.WheelActors[0].Position.Y - carFile.NonDrivenWheelRadius + _heightOffset + 0.35f;
            _massPos  = massPos;
            _physXActor.SetCenterOfMassOffsetLocalPosition(massPos);

            //a real power curve doesnt work too well :)
            List <float> power  = new List <float>(new float[] { 0.5f, 0.5f, 0.5f, 1f, 1f, 1.0f, 1.0f, 0 });
            List <float> ratios = new List <float>(new float[] { 3.227f, 2.360f, 1.685f, 1.312f, 1.000f, 0.793f });

            BaseGearbox gearbox = BaseGearbox.Create(false, ratios, 0.4f);

            Motor = new Motor(power, carFile.EnginePower, 6f, carFile.TopSpeed, gearbox);
            Motor.Gearbox.CurrentGear = 0;
        }
Exemple #6
0
        public VehicleChassis(Vehicle vehicle)
        {
            Vehicle = vehicle;

            Wheels = new List<VehicleWheel>();

            VehicleFile carFile = vehicle.Config;

            ActorDescription actorDesc = new ActorDescription();

            actorDesc.BodyDescription = new BodyDescription();
            actorDesc.BodyDescription.Mass = carFile.Mass;
            var boxDesc = new BoxShapeDescription();
            boxDesc.Size = carFile.BoundingBox.GetSize();
            boxDesc.LocalPosition = carFile.BoundingBox.GetCenter();
            boxDesc.Name = PhysXConsts.VehicleBody;
            boxDesc.Flags |= ShapeFlag.PointContactForce;
            actorDesc.Shapes.Add(boxDesc);

            foreach (Vector3 extraPoint in carFile.ExtraBoundingBoxPoints)
            {
                var extraDesc = new SphereShapeDescription(0.2f);
                extraDesc.LocalPosition = extraPoint;
                extraDesc.Mass = 0;
                actorDesc.Shapes.Add(extraDesc);
            }

            using (UtilitiesLibrary lib = new UtilitiesLibrary())
            {
                Vector3 size = carFile.Size;
                Vector3 inertiaTensor = lib.ComputeBoxInteriaTensor(Vector3.Zero, carFile.Mass, size);
                //actorDesc.BodyDescription.MassSpaceInertia = inertiaTensor;
            }

            TireFunctionDescription lngTFD = new TireFunctionDescription();
            lngTFD.ExtremumSlip = 0.1f;
            lngTFD.ExtremumValue = 4f;
            lngTFD.AsymptoteSlip = 2.0f;
            lngTFD.AsymptoteValue = 3.2f;

            _rearLateralTireFn = new TireFunctionDescription();

            _rearLateralTireFn.ExtremumSlip = 0.2f;
            _rearLateralTireFn.ExtremumValue = 2.1f;
            _rearLateralTireFn.AsymptoteSlip = 0.0013f * carFile.Mass;
            _rearLateralTireFn.AsymptoteValue = 0.02f;

            _frontLateralTireFn = _rearLateralTireFn;
            _frontLateralTireFn.ExtremumValue = 1.9f;

            MaterialDescription md = new MaterialDescription();
            md.Flags = MaterialFlag.DisableFriction;
            Material m = PhysX.Instance.Scene.CreateMaterial(md);

            int wheelIndex = 0;

            foreach (CWheelActor wheel in carFile.WheelActors)
            {
                WheelShapeDescription wheelDesc = new WheelShapeDescription();
                wheelDesc.InverseWheelMass = 0.08f;
                wheelDesc.LongitudalTireForceFunction = lngTFD;
                wheelDesc.Flags = WheelShapeFlag.ClampedFriction;
                wheelDesc.Material = m;

                wheelDesc.Radius = wheel.IsDriven ? carFile.DrivenWheelRadius : carFile.NonDrivenWheelRadius;
                wheelDesc.SuspensionTravel = (wheel.IsFront ? carFile.SuspensionGiveFront : carFile.SuspensionGiveRear) * 18;

                float heightModifier = (wheelDesc.SuspensionTravel + wheelDesc.Radius) / wheelDesc.SuspensionTravel;

                SpringDescription spring = new SpringDescription();
                if (carFile.Mass > 3000)
                    spring.SpringCoefficient = 10.5f * heightModifier * carFile.Mass;
                else
                    spring.SpringCoefficient = 6.5f * heightModifier * Math.Min(1000, carFile.Mass);
                spring.DamperCoefficient = carFile.SuspensionDamping * 6f;

                wheelDesc.Suspension = spring;
                wheelDesc.LocalPosition = wheel.Position;
                wheelDesc.Name = (wheelIndex).ToString();
                wheelIndex++;

                wheelDesc.LateralTireForceFunction = wheel.IsFront ? _frontLateralTireFn : _rearLateralTireFn;
                actorDesc.Shapes.Add(wheelDesc);
            }

            _physXActor = PhysX.Instance.Scene.CreateActor(actorDesc);

            _heightOffset = _physXActor.Shapes[0].LocalPosition.Y * -2;
            if (_heightOffset < 0) _heightOffset = 0;

            foreach (Shape shape in _physXActor.Shapes)
            {
                shape.LocalPosition += new Vector3(0, _heightOffset, 0);
                if (shape is WheelShape)
                {
                    wheelIndex = int.Parse(shape.Name);
                    Wheels.Add(new VehicleWheel(this, carFile.WheelActors[wheelIndex], (WheelShape)shape, carFile.WheelActors[wheelIndex].IsLeft ? 0.17f : -0.17f) { Index = wheelIndex });
                }
            }

            _physXActor.Group = PhysXConsts.VehicleId;
            _physXActor.UserData = vehicle;

            _physXActor.WakeUp(60.0f);

            //_physXActor.RaiseBodyFlag(BodyFlag.DisableGravity);

            //set center of mass
            Vector3 massPos = carFile.CenterOfMass;
            massPos.Y = carFile.WheelActors[0].Position.Y - carFile.NonDrivenWheelRadius + _heightOffset + 0.35f;
            _massPos = massPos;
            _physXActor.SetCenterOfMassOffsetLocalPosition(massPos);

            //a real power curve doesnt work too well :)
            List<float> power = new List<float>(new float[] { 0.5f, 0.5f, 0.5f, 1f, 1f, 1.0f, 1.0f, 0 });
            List<float> ratios = new List<float>(new float[] { 3.227f, 2.360f, 1.685f, 1.312f, 1.000f, 0.793f });

            BaseGearbox gearbox = BaseGearbox.Create(false, ratios, 0.4f);
            Motor = new Motor(power, carFile.EnginePower, 6f, carFile.TopSpeed, gearbox);
            Motor.Gearbox.CurrentGear = 0;
        }