コード例 #1
0
        protected override PhysicsScene OnCreateScene(string description, int numThreads, uint[] affinityMasks)
        {
            if (MainScene == null)
            {
                numThreads = Math.Min(Environment.ProcessorCount, mainSceneMaxThreads);
            }

            PhysXPhysicsScene scene = new PhysXPhysicsScene(description);

            scene.Create(numThreads, affinityMasks);
            return(scene);
        }
コード例 #2
0
        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();
        }
コード例 #3
0
        //

        public PhysXPhysicsVehicle(PhysXPhysicsScene scene, PhysXBody baseBody)
            : base(scene, baseBody)
        {
        }
コード例 #4
0
ファイル: PhysXPhysicsWorld.cs プロジェクト: whztt07/SDK
        protected override PhysicsScene OnCreateScene( string description, int numThreads, uint[] affinityMasks )
        {
            if( MainScene == null )
                numThreads = Math.Min( Environment.ProcessorCount, mainSceneMaxThreads );

            PhysXPhysicsScene scene = new PhysXPhysicsScene( description );
            scene.Create( numThreads, affinityMasks );
            return scene;
        }
コード例 #5
0
ファイル: PhysXBody.cs プロジェクト: whztt07/SDK
 //
 public PhysXBody( PhysXPhysicsScene scene )
     : base(scene)
 {
     this.scene = scene;
 }
コード例 #6
0
        protected override void OnDestroyScene(PhysicsScene scene)
        {
            PhysXPhysicsScene scene2 = (PhysXPhysicsScene)scene;

            scene2.Destroy();
        }
コード例 #7
0
ファイル: PhysXPhysicsVehicle.cs プロジェクト: whztt07/SDK
 //
 public PhysXPhysicsVehicle( PhysXPhysicsScene scene, PhysXBody baseBody )
     : base(scene, baseBody)
 {
 }