public override void SetToRestState()
 {
     if (nativeVehicle != IntPtr.Zero)
     {
         PhysXNativeVehicle.SetToRestState(nativeVehicle);
     }
 }
 public override Radian GetEngineRotationSpeed()
 {
     if (nativeVehicle != IntPtr.Zero)
     {
         return(PhysXNativeVehicle.GetEngineRotationSpeed(nativeVehicle));
     }
     return(0);
 }
 public override int GetTargetGear()
 {
     if (nativeVehicle != IntPtr.Zero)
     {
         return(PhysXNativeVehicle.GetTargetGear(nativeVehicle));
     }
     return(0);
 }
 void PopFromWorld()
 {
     if (nativeVehicle != IntPtr.Zero)
     {
         PhysXNativeVehicle.Destroy(nativeVehicle);
         nativeVehicle = IntPtr.Zero;
     }
 }
        protected override void OnUpdate()
        {
            base.OnUpdate();

            if (nativeVehicle != IntPtr.Zero)
            {
                PhysXNativeVehicle.Update(nativeVehicle, Scene.StepSize);
            }
        }
 public override bool[] AreWheelsInAir()
 {
     bool[] result = new bool[WheelCount];
     if (nativeVehicle != IntPtr.Zero)
     {
         for (int n = 0; n < WheelCount; n++)
         {
             result[n] = PhysXNativeVehicle.IsWheelInAir(nativeVehicle, n);
         }
     }
     return(result);
 }
 public override float[] GetWheelsTireFriction()
 {
     float[] result = new float[WheelCount];
     if (nativeVehicle != IntPtr.Zero)
     {
         for (int n = 0; n < WheelCount; n++)
         {
             result[n] = PhysXNativeVehicle.GetWheelTireFriction(nativeVehicle, n);
         }
     }
     return(result);
 }
 public override float[] GetWheelsSuspensionJounce()
 {
     float[] result = new float[WheelCount];
     if (nativeVehicle != IntPtr.Zero)
     {
         for (int n = 0; n < WheelCount; n++)
         {
             result[n] = PhysXNativeVehicle.GetWheelSuspensionJounce(nativeVehicle, n);
         }
     }
     return(result);
 }
 public override Radian[] GetWheelsRotationAngle()
 {
     Radian[] result = new Radian[WheelCount];
     if (nativeVehicle != IntPtr.Zero)
     {
         for (int n = 0; n < WheelCount; n++)
         {
             result[n] = PhysXNativeVehicle.GetWheelRotationAngle(nativeVehicle, n);
         }
     }
     return(result);
 }
        public override void StartGearChange(int gear)
        {
            if (gear < -1)
            {
                gear = -1;
            }
            int maxNumber = GetMaxGearNumber();

            if (gear > maxNumber)
            {
                gear = maxNumber;
            }

            if (nativeVehicle != IntPtr.Zero)
            {
                PhysXNativeVehicle.StartGearChange(nativeVehicle, gear);
            }
        }
        public unsafe override void SetInputData(InputDataTypes inputType, InputSmoothingSettings smoothingSettings,
                                                 Pair <float, float>[] steerVsForwardSpeedTable, float accel, float brake, float steer, float handbrake)
        {
            if (steerVsForwardSpeedTable.Length > 8)
            {
                Log.Fatal("PhysXPhysicsVehicle: SetInputData: The amount of steer vs forward speed table item can't be more than 8.");
            }

            if (nativeVehicle != IntPtr.Zero)
            {
                float[] smoothingSettings2 = new float[]
                {
                    smoothingSettings.RiseRateAccel,
                    smoothingSettings.RiseRateBrake,
                    smoothingSettings.RiseRateSteer,
                    smoothingSettings.RiseRateHandbrake,
                    smoothingSettings.FallRateAccel,
                    smoothingSettings.FallRateBrake,
                    smoothingSettings.FallRateSteer,
                    smoothingSettings.FallRateHandbrake
                };

                float[] steerVsForwardSpeedTable2 = new float[steerVsForwardSpeedTable.Length * 2];
                for (int n = 0; n < steerVsForwardSpeedTable.Length; n++)
                {
                    steerVsForwardSpeedTable2[n * 2 + 0] = steerVsForwardSpeedTable[n].First;
                    steerVsForwardSpeedTable2[n * 2 + 1] = steerVsForwardSpeedTable[n].Second;
                }

                fixed(float *pSmoothingSettings = smoothingSettings2, pSteerVsForwardSpeedTable = steerVsForwardSpeedTable2)
                {
                    PhysXNativeVehicle.SetInputData(nativeVehicle, inputType == InputDataTypes.Digital, pSmoothingSettings,
                                                    steerVsForwardSpeedTable.Length, pSteerVsForwardSpeedTable, accel, brake, steer, handbrake);
                }
            }
        }
 void CallMethod(string message, int parameter1, double parameter2, double parameter3, out int result1,
                 out double result2, out double result3)
 {
     PhysXNativeVehicle.CallMethod(nativeVehicle, message, parameter1, parameter2, parameter3, out result1, out result2,
                                   out result3);
 }
        void PushToWorld()
        {
            PhysXPhysicsScene scene    = (PhysXPhysicsScene)Scene;
            PhysXBody         baseBody = (PhysXBody)BaseBody;

            IntPtr generalData         = PhysXNativeVehicleInitData.Create();
            IntPtr wheelFrontLeftData  = PhysXNativeVehicleInitData.Create();
            IntPtr wheelFrontRightData = PhysXNativeVehicleInitData.Create();
            IntPtr wheelRearLeftData   = PhysXNativeVehicleInitData.Create();
            IntPtr wheelRearRightData  = PhysXNativeVehicleInitData.Create();

            //Chassis mass
            PhysXNativeVehicleInitData.SetParameter(generalData, "massChassis", InitData.MassChassis);

            //Differential
            PhysXNativeVehicleInitData.SetParameter(generalData, "differentialType", (float)(int)InitData.DifferentialType);
            PhysXNativeVehicleInitData.SetParameter(generalData, "differentialFrontRearSplit", InitData.DifferentialFrontRearSplit);
            PhysXNativeVehicleInitData.SetParameter(generalData, "differentialFrontLeftRightSplit", InitData.DifferentialFrontLeftRightSplit);
            PhysXNativeVehicleInitData.SetParameter(generalData, "differentialRearLeftRightSplit", InitData.DifferentialRearLeftRightSplit);
            PhysXNativeVehicleInitData.SetParameter(generalData, "differentialCenterBias", InitData.DifferentialCenterBias);
            PhysXNativeVehicleInitData.SetParameter(generalData, "differentialFrontBias", InitData.DifferentialFrontBias);
            PhysXNativeVehicleInitData.SetParameter(generalData, "differentialRearBias", InitData.DifferentialRearBias);

            //Engine
            {
                PhysXNativeVehicleInitData.SetParameter(generalData, "enginePeakTorque", InitData.EnginePeakTorque);
                PhysXNativeVehicleInitData.SetParameter(generalData, "engineMaxRPM", InitData.EngineMaxRPM);
                PhysXNativeVehicleInitData.SetParameter(generalData, "engineDampingRateFullThrottle",
                                                        InitData.EngineDampingRateFullThrottle);
                PhysXNativeVehicleInitData.SetParameter(generalData, "engineDampingRateZeroThrottleClutchEngaged",
                                                        InitData.EngineDampingRateZeroThrottleClutchEngaged);
                PhysXNativeVehicleInitData.SetParameter(generalData, "engineDampingRateZeroThrottleClutchDisengaged",
                                                        InitData.EngineDampingRateZeroThrottleClutchDisengaged);

                if (InitData.EngineTorqueCurve.Count == 0)
                {
                    Log.Fatal("PhysXPhysicsVehicle: PushToWorld: EngineTorqueCurve is not configured.");
                }
                if (InitData.EngineTorqueCurve.Count > 8)
                {
                    Log.Fatal("PhysXPhysicsVehicle: PushToWorld: EngineTorqueCurve can't have more than 8 values.");
                }
                for (int n = 0; n < InitData.EngineTorqueCurve.Count; n++)
                {
                    InitDataClass.EngineTorqueCurveItem item = InitData.EngineTorqueCurve[n];
                    PhysXNativeVehicleInitData.SetParameter(generalData, string.Format("engineTorqueCurveTorque{0}", n),
                                                            item.NormalizedTorque);
                    PhysXNativeVehicleInitData.SetParameter(generalData, string.Format("engineTorqueCurveRev{0}", n),
                                                            item.NormalizedRev);
                }
            }

            //Gears
            {
                if (InitData.Gears.Count == 0)
                {
                    Log.Fatal("PhysXPhysicsVehicle: PushToWorld: The gears are not defined.");
                }
                if (InitData.FindGearByNumber(0) == null)
                {
                    Log.Fatal("PhysXPhysicsVehicle: PushToWorld: Neutral gear is not defined.");
                }
                if (InitData.FindGearByNumber(-1) == null)
                {
                    Log.Fatal("PhysXPhysicsVehicle: PushToWorld: Reverse gear is not defined.");
                }

                foreach (PhysicsVehicle.InitDataClass.GearItem gearItem in InitData.Gears)
                {
                    if (gearItem.Number < -1)
                    {
                        Log.Fatal("PhysXPhysicsVehicle: PushToWorld: Gear number can't be less than -1.");
                    }
                    if (gearItem.Number > 30)
                    {
                        Log.Fatal("PhysXPhysicsVehicle: PushToWorld: Gear number can't be more than 30.");
                    }

                    if (gearItem.Number < 0 && gearItem.Ratio >= 0)
                    {
                        Log.Fatal("PhysXPhysicsVehicle: PushToWorld: Reverse gear ratio must be less than zero.");
                    }
                    if (gearItem.Number == 0 && gearItem.Ratio != 0)
                    {
                        Log.Fatal("PhysXPhysicsVehicle: PushToWorld: Neutral gear ratio must be zero.");
                    }
                    if (gearItem.Number > 0 && gearItem.Ratio < 0)
                    {
                        Log.Fatal("PhysXPhysicsVehicle: PushToWorld: Forward gear ratios must be greater than zero.");
                    }

                    if (gearItem.Number >= 2)
                    {
                        PhysicsVehicle.InitDataClass.GearItem nextGearItem = InitData.FindGearByNumber(gearItem.Number - 1);
                        if (nextGearItem == null || gearItem.Ratio > nextGearItem.Ratio)
                        {
                            Log.Fatal("PhysXPhysicsVehicle: PushToWorld: Forward gear ratios must be a descending sequence of gear ratios.");
                        }
                    }

                    PhysXNativeVehicleInitData.SetParameter(generalData, string.Format("gear{0}", gearItem.Number), gearItem.Ratio);
                }
                PhysXNativeVehicleInitData.SetParameter(generalData, "gearsSwitchTime", InitData.GearsSwitchTime);
            }

            //Clutch
            PhysXNativeVehicleInitData.SetParameter(generalData, "clutchStrength", InitData.ClutchStrength);

            //Ackermann steer accuracy
            PhysXNativeVehicleInitData.SetParameter(generalData, "ackermannSteerAccuracy", InitData.AckermannSteerAccuracy);

            //Wheels
            InitWheelData(wheelFrontLeftData, InitData.WheelFrontLeft);
            InitWheelData(wheelFrontRightData, InitData.WheelFrontRight);
            InitWheelData(wheelRearLeftData, InitData.WheelRearLeft);
            InitWheelData(wheelRearRightData, InitData.WheelRearRight);

            //Tire settings
            {
                int n = 0;
                foreach (InitDataClass.TireFrictionMultiplierItem frictionItem in InitData.TireFrictionMultipliers)
                {
                    PhysXNativeVehicleInitData.SetParameter(generalData,
                                                            string.Format("tireFrictionMaterial{0}", n), frictionItem.SurfaceMaterialName);
                    PhysXNativeVehicleInitData.SetParameter(generalData,
                                                            string.Format("tireFrictionValue{0}", n), frictionItem.Value);
                    n++;
                }
            }

            nativeVehicle = PhysXNativeVehicle.Create(scene.nativeScene, baseBody.nativeBody, generalData,
                                                      wheelFrontLeftData, wheelFrontRightData, wheelRearLeftData, wheelRearRightData);

            PhysXNativeVehicleInitData.Destroy(generalData);
            PhysXNativeVehicleInitData.Destroy(wheelFrontLeftData);
            PhysXNativeVehicleInitData.Destroy(wheelFrontRightData);
            PhysXNativeVehicleInitData.Destroy(wheelRearLeftData);
            PhysXNativeVehicleInitData.Destroy(wheelRearRightData);

            OnUpdateAutoGearSettings();
        }