Ejemplo n.º 1
0
        public static void Initialise()
        {
            var eo = new ErrorOutput();

            Foundation = new Foundation(eo);
            PVD        = new Pvd(Foundation);
            Physics    = new PhysX.Physics(Foundation, false, PVD);

            PhysicsScene = Physics.CreateScene(); // TODO: SceneDesc

            PhysicsScene.SetVisualizationParameter(VisualizationParameter.Scale, 2.0f);
            PhysicsScene.SetVisualizationParameter(VisualizationParameter.CollisionShapes, true);
            PhysicsScene.SetVisualizationParameter(VisualizationParameter.JointLocalFrames, true);
            PhysicsScene.SetVisualizationParameter(VisualizationParameter.JointLimits, true);
            PhysicsScene.SetVisualizationParameter(VisualizationParameter.ActorAxes, true);

            PVD.Connect("localhost");
        }
Ejemplo n.º 2
0
        public PhysxPhysicsSystem(World world) : base(world)
        {
            // Setup PhysX infra here

            this.physxFoundation = new PxFoundation(new ConsoleErrorCallback());
            this.physxScale      = new PxTolerancesScale()
            {
                Length = 0.1f,
                Speed  = 98.1f
            };

#if DEBUG
            pvd = new Pvd(this.physxFoundation);
            pvd.Connect("localhost", 5425, TimeSpan.FromSeconds(2), InstrumentationFlag.Debug);
            this.physxPhysics = new PxPhysics(this.physxFoundation, this.physxScale, false, pvd);
#else
            this.physxPhysics = new PxPhysics(this.physxFoundation, this.physxScale);
#endif
            this.defaultMat = this.physxPhysics.CreateMaterial(0.5f, 0.5f, 0.1f);

            this.characterControlMat = this.physxPhysics.CreateMaterial(0.5f, 0.5f, 0f);
            this.characterControlMat.RestitutionCombineMode = CombineMode.Minimum;

            this.frictionlessMat = this.physxPhysics.CreateMaterial(0f, 0f, 0f);
            this.frictionlessMat.RestitutionCombineMode = CombineMode.Minimum;
            this.frictionlessMat.Flags = MaterialFlags.DisableFriction;

            var sceneDesc = new SceneDesc(this.physxScale)
            {
                BroadPhaseType          = BroadPhaseType.SweepAndPrune,
                Gravity                 = world.Gravity,
                Flags                   = SceneFlag.EnableStabilization,
                SolverType              = SolverType.TGS,
                FilterShader            = new DefaultFilterShader(),
                BounceThresholdVelocity = 0.2f * world.Gravity.Length()
            };

            this.physxScene = this.physxPhysics.CreateScene(sceneDesc);

#if DEBUG
            this.physxScene.SetVisualizationParameter(VisualizationParameter.ContactPoint, true);
            this.physxScene.SetVisualizationParameter(VisualizationParameter.ContactNormal, true);
            this.physxScene.SetVisualizationParameter(VisualizationParameter.ContactForce, true);
            this.physxScene.SetVisualizationParameter(VisualizationParameter.ContactError, true);

            var pvdClient = this.physxScene.GetPvdSceneClient();
            pvdClient.SetScenePvdFlags(SceneVisualizationFlags.TransmitContacts | SceneVisualizationFlags.TransmitConstraints | SceneVisualizationFlags.TransmitSceneQueries);
#endif

            var cookingParams = new CookingParams()
            {
                Scale           = this.physxScale,
                AreaTestEpsilon = 0.001f,
                MidphaseDesc    = new MidphaseDesc()
                {
                    Bvh33Desc = new Bvh33MidphaseDesc()
                    {
                        MeshCookingHint = MeshCookingHint.SimulationPerformance
                    }
                },
                BuildTriangleAdjacencies = true,
                MeshCookingHint          = MeshCookingHint.SimulationPerformance,
                MeshWeldTolerance        = 0.001f
            };

            this.cooker            = this.physxPhysics.CreateCooking(cookingParams);
            this.controllerManager = this.physxScene.CreateControllerManager();

            var contactProv = new ContactModifyProxy();
            this.contactProvider = contactProv;
            this.physxScene.ContactModifyCallback = contactProv;

            this.simCallback = new SimulationCallback();
            this.physxScene.SetSimulationEventCallback(simCallback);
        }