public static Actor CreateCog(StillDesign.PhysX.Scene scene)
        {
            var actorDesc = new ActorDescription();


            float radius  = 6f;
            float radius2 = 6.8f;

            for (int i = 0; i < 16; i++)
            {
                SphereShapeDescription desc = new SphereShapeDescription(0.6f);
                float angle = (i + 0.5f) * MathHelper.TwoPi * (1 / 16f);
                desc.LocalPosition = new Vector3(radius * (float)Math.Sin(angle), radius * (float)Math.Cos(angle), 0);
                actorDesc.Shapes.Add(desc);

                desc = new SphereShapeDescription(0.2f);
                desc.LocalPosition = new Vector3(radius2 * (float)Math.Sin(angle), radius2 * (float)Math.Cos(angle), 0);
                actorDesc.Shapes.Add(desc);
            }



            actorDesc.BodyDescription      = new BodyDescription();
            actorDesc.BodyDescription.Mass = 10;

            actorDesc.GlobalPose = Matrix.CreateRotationX(MathHelper.PiOver2);

            return(scene.CreateActor(actorDesc));
        }
示例#2
0
        public static void RunCharacterTest()
        {
            Core core = new Core();

            StillDesign.PhysX.Scene scene = core.CreateScene();

            ControllerManager manager = scene.CreateControllerManager();

            CapsuleControllerDescription desc = new CapsuleControllerDescription(2, 10);
            CapsuleController            capsuleController = manager.CreateController <CapsuleController>(desc);


            BoxShapeDescription boxShapeDesc = new BoxShapeDescription(1, 1, 1);
            ActorDescription    actorDesc    = new ActorDescription(boxShapeDesc);

            actorDesc.BodyDescription = new BodyDescription(1f);

            Actor actor = scene.CreateActor(actorDesc);

            //capsuleController.Move( Vector3.Up );

            // Update Physics
            scene.Simulate(1.0f / 60.0f);
            scene.FlushStream();
            scene.FetchResults(SimulationStatus.RigidBodyFinished, true);

            capsuleController.Move(Vector3.Up);

            core.Dispose();
        }
示例#3
0
        public static Actor CreateDynamicSphereActor(StillDesign.PhysX.Scene scene, float radius, float mass)
        {
            ActorDescription actorDesc = new ActorDescription(new SphereShapeDescription(radius));

            actorDesc.BodyDescription = new BodyDescription(mass);

            return(scene.CreateActor(actorDesc));
        }
        public Actor CreateActorStatic(StillDesign.PhysX.Scene scene, MeshCollisionData data, Matrix globalPose)
        {
            ActorDescription actorDesc = createActorDesc(data, scene, globalPose);

            if (actorDesc.Shapes.Count == 0)
            {
                return(null);
            }
            return(scene.CreateActor(actorDesc));
        }
        public Actor CreateActorDynamic(StillDesign.PhysX.Scene scene, MeshCollisionData data, Matrix globalPose)
        {
            ActorDescription actorDesc = createActorDesc(data, scene, globalPose);

            actorDesc.BodyDescription = new BodyDescription(10f); //TODO mass

            if (actorDesc.Shapes.Count == 0)
            {
                return(null);
            }
            return(scene.CreateActor(actorDesc));
        }
        public void InitDynamic()
        {
            if (actor != null)
            {
                return;
            }
            SphereShapeDescription shapeDescription = new SphereShapeDescription(Radius);
            ActorDescription       actorDescription = new ActorDescription(shapeDescription);

            actorDescription.BodyDescription = new BodyDescription(2f);

            actorDescription.GlobalPose = Matrix.CreateTranslation(Center);

            actor = scene.CreateActor(actorDescription);
        }
        public void TestSyncOnlineServer()
        {
            var server = new ServerPacketManagerNetworked(10045, 10046);


            var serverSyncer = new ServerSyncer(server);



            server.Start();


            var physicsEngine = new PhysicsEngine();

            StillDesign.PhysX.Scene serverScene = null;

            PhysicsDebugRendererXNA debugRenderer;
            PhysicsDebugRendererXNA debugRendererServer;
            var game = new XNAGame();
            ServerSyncedActor server1 = null;

            game.InitializeEvent += delegate
            {
                physicsEngine.Initialize();
                serverScene = physicsEngine.CreateScene(physicsEngine.Scene.Gravity, true);


                debugRenderer = new PhysicsDebugRendererXNA(game, physicsEngine.Scene);
                game.AddXNAObject(debugRenderer);
                debugRendererServer = new PhysicsDebugRendererXNA(game, serverScene);
                game.AddXNAObject(debugRendererServer);

                ActorDescription       actorDesc;
                SphereShapeDescription shape;

                shape     = new SphereShapeDescription(1);
                actorDesc = new ActorDescription(shape);
                actorDesc.BodyDescription = new BodyDescription(10);

                server1 = serverSyncer.CreateActor(serverScene.CreateActor(actorDesc));
                ((WorldPhysxSyncActor)server1.Actor).Actor.AddForce(Vector3.UnitX * 200, ForceMode.Impulse);
                server1.ID = 2; // Identify
            };

            game.UpdateEvent += delegate
            {
                physicsEngine.Update(game);
                physicsEngine.UpdateScene(game.Elapsed, serverScene);

                serverSyncer.Update(game.Elapsed);

                if (game.Keyboard.IsKeyDown(Keys.Up))
                {
                    ((WorldPhysxSyncActor)server1.Actor).Actor.AddForce(Vector3.UnitX * 200, ForceMode.Force);
                }
                if (game.Keyboard.IsKeyDown(Keys.Down))
                {
                    ((WorldPhysxSyncActor)server1.Actor).Actor.AddForce(-Vector3.UnitX * 200, ForceMode.Force);
                }
            };

            game.Run();

            physicsEngine.Dispose();
        }
        public void TestSyncDirect()
        {
            var client = new ClientSyncedActor();
            var server = new ServerSyncedActor();

            var physicsEngine = new PhysicsEngine();

            StillDesign.PhysX.Scene serverScene = null;

            PhysicsDebugRendererXNA debugRenderer;
            PhysicsDebugRendererXNA debugRendererServer;
            var   game          = new XNAGame();
            float totalTime     = 0;
            float timeSinceTick = 0;
            float tickRate      = 1 / 30f;
            int   tickNumber    = 0;
            float packetLoss    = 0.25f;

            var rand = new Random();

            game.InitializeEvent += delegate
            {
                physicsEngine.Initialize();
                serverScene = physicsEngine.CreateScene(physicsEngine.Scene.Gravity, true);


                debugRenderer = new PhysicsDebugRendererXNA(game, physicsEngine.Scene);
                game.AddXNAObject(debugRenderer);
                debugRendererServer = new PhysicsDebugRendererXNA(game, serverScene);
                game.AddXNAObject(debugRendererServer);

                ActorDescription       actorDesc;
                SphereShapeDescription shape;

                shape     = new SphereShapeDescription(1);
                actorDesc = new ActorDescription(shape);
                actorDesc.BodyDescription = new BodyDescription(10);

                server.Actor = new WorldPhysxSyncActor(serverScene.CreateActor(actorDesc));
                ((WorldPhysxSyncActor)server.Actor).Actor.AddForce(Vector3.UnitX * 200, ForceMode.Impulse);

                shape     = new SphereShapeDescription(1);
                actorDesc = new ActorDescription(shape);
                actorDesc.BodyDescription = new BodyDescription(10);

                client.Actor =
                    new WorldPhysxSyncActor(physicsEngine.Scene.CreateActor(actorDesc));
            };

            game.UpdateEvent += delegate
            {
                physicsEngine.Update(game);
                physicsEngine.UpdateScene(game.Elapsed, serverScene);
                totalTime     += game.Elapsed;
                timeSinceTick += game.Elapsed;
                int totalMiliseconds = (int)(totalTime * 1000);

                while (timeSinceTick > tickRate)
                {
                    timeSinceTick -= tickRate;
                    //Do a tick
                    tickNumber++;
                    server.Tick();
                    var p = new UpdateEntityPacket();
                    p.Positie     = server.Positie;
                    p.RotatieQuat = server.RotatieQuat;
                    if (rand.NextDouble() < 1 - packetLoss)
                    {
                        client.AddEntityUpdate(tickNumber, p);
                    }
                }

                client.Process(totalMiliseconds, tickRate);
            };

            game.Run();

            physicsEngine.Dispose();
        }
        public void TestSyncOnline()
        {
            var server  = new ServerPacketManagerNetworked(10045, 10046);
            var success = new AutoResetEvent(false);



            var serverSyncer = new ServerSyncer(server);



            server.Start();

            var conn = NetworkingUtilities.ConnectTCP(10045, "127.0.0.1");

            conn.Receiving = true;
            var client = new ClientPacketManagerNetworked(conn);

            var clientSyncer = new ClientSyncer(client);



            var physicsEngine = new PhysicsEngine();

            StillDesign.PhysX.Scene serverScene = null;

            PhysicsDebugRendererXNA debugRenderer;
            PhysicsDebugRendererXNA debugRendererServer;
            var game = new XNAGame();

            game.InitializeEvent += delegate
            {
                physicsEngine.Initialize();
                serverScene = physicsEngine.CreateScene(physicsEngine.Scene.Gravity, true);


                debugRenderer = new PhysicsDebugRendererXNA(game, physicsEngine.Scene);
                game.AddXNAObject(debugRenderer);
                debugRendererServer = new PhysicsDebugRendererXNA(game, serverScene);
                game.AddXNAObject(debugRendererServer);

                ActorDescription       actorDesc;
                SphereShapeDescription shape;

                shape     = new SphereShapeDescription(1);
                actorDesc = new ActorDescription(shape);
                actorDesc.BodyDescription = new BodyDescription(10);

                var server1 = serverSyncer.CreateActor(serverScene.CreateActor(actorDesc));
                ((WorldPhysxSyncActor)server1.Actor).Actor.AddForce(Vector3.UnitX * 200, ForceMode.Impulse);

                shape     = new SphereShapeDescription(1);
                actorDesc = new ActorDescription(shape);
                actorDesc.BodyDescription = new BodyDescription(10);

                var client1 = clientSyncer.CreateActor(physicsEngine.Scene.CreateActor(actorDesc));

                client1.ID = server1.ID;                         // Identify
            };

            game.UpdateEvent += delegate
            {
                physicsEngine.Update(game);
                physicsEngine.UpdateScene(game.Elapsed, serverScene);

                serverSyncer.Update(game.Elapsed);
                clientSyncer.Update(game.Elapsed);
            };

            client.SyncronizeRemotePacketIDs();
            client.WaitForUDPConnected();

            game.Run();

            physicsEngine.Dispose();
        }
        public void TestSyncOffline()
        {
            var serverpm = new SimpleServerPacketManager();
            var clientpm = serverpm.CreateClient();


            var clientSyncer = new ClientSyncer(clientpm);
            var serverSyncer = new ServerSyncer(serverpm);

            var physicsEngine = new PhysicsEngine();

            StillDesign.PhysX.Scene serverScene = null;

            PhysicsDebugRendererXNA debugRenderer;
            PhysicsDebugRendererXNA debugRendererServer;
            var   game          = new XNAGame();
            float totalTime     = 0;
            float timeSinceTick = 0;
            float tickRate      = 1 / 30f;
            int   tickNumber    = 0;
            float packetLoss    = 0.25f;


            var rand = new Random();

            game.InitializeEvent += delegate
            {
                physicsEngine.Initialize();
                serverScene = physicsEngine.CreateScene(physicsEngine.Scene.Gravity, true);


                debugRenderer = new PhysicsDebugRendererXNA(game, physicsEngine.Scene);
                game.AddXNAObject(debugRenderer);
                debugRendererServer = new PhysicsDebugRendererXNA(game, serverScene);
                game.AddXNAObject(debugRendererServer);

                ActorDescription       actorDesc;
                SphereShapeDescription shape;

                shape     = new SphereShapeDescription(1);
                actorDesc = new ActorDescription(shape);
                actorDesc.BodyDescription = new BodyDescription(10);

                var server = serverSyncer.CreateActor(serverScene.CreateActor(actorDesc));
                ((WorldPhysxSyncActor)server.Actor).Actor.AddForce(Vector3.UnitX * 200, ForceMode.Impulse);

                shape     = new SphereShapeDescription(1);
                actorDesc = new ActorDescription(shape);
                actorDesc.BodyDescription = new BodyDescription(10);

                var client = clientSyncer.CreateActor(physicsEngine.Scene.CreateActor(actorDesc));

                client.ID = server.ID;                         // Identify
            };

            game.UpdateEvent += delegate
            {
                physicsEngine.Update(game);
                physicsEngine.UpdateScene(game.Elapsed, serverScene);

                serverSyncer.Update(game.Elapsed);
                clientSyncer.Update(game.Elapsed);
            };

            game.Run();

            physicsEngine.Dispose();
        }
        private void InitTestScene(StillDesign.PhysX.Scene scene)
        {
            ActorDescription actorDesc;
            Actor            actor;

            CapsuleShapeDescription capsuleShapeDesc = new CapsuleShapeDescription(1, 3);

            actorDesc = new ActorDescription(capsuleShapeDesc);
            actorDesc.BodyDescription = new BodyDescription(1f);

            actor = scene.CreateActor(actorDesc);
            actor.GlobalOrientation = Matrix.CreateRotationX(MathHelper.PiOver2);



            BoxShapeDescription boxShapeDesc = new BoxShapeDescription(40, 1, 1);

            actorDesc = new ActorDescription(boxShapeDesc);
            actorDesc.BodyDescription = new BodyDescription(1f);

            actor = scene.CreateActor(actorDesc);
            actor.GlobalPosition = new Vector3(0, 4, 0);


            boxShapeDesc = new BoxShapeDescription(1, 1, 1);

            actorDesc = new ActorDescription(boxShapeDesc);
            actorDesc.BodyDescription = new BodyDescription(40f);

            actor = scene.CreateActor(actorDesc);
            actor.GlobalPosition = new Vector3(15, 40, 0);

            boxShapeDesc = new BoxShapeDescription(1, 1, 1);

            actorDesc = new ActorDescription(boxShapeDesc);
            actorDesc.BodyDescription = new BodyDescription(1f);

            actor = scene.CreateActor(actorDesc);
            actor.GlobalPosition = new Vector3(-13, 5, 0);

            boxShapeDesc = new BoxShapeDescription(1, 1, 1);

            actorDesc = new ActorDescription(boxShapeDesc);
            actorDesc.BodyDescription = new BodyDescription(1f);

            actor = scene.CreateActor(actorDesc);
            actor.GlobalPosition = new Vector3(-7, 5, 0);

            boxShapeDesc = new BoxShapeDescription(1, 1, 1);

            actorDesc = new ActorDescription(boxShapeDesc);
            actorDesc.BodyDescription = new BodyDescription(1f);

            actor = scene.CreateActor(actorDesc);
            actor.GlobalPosition = new Vector3(-10, 5, 0);

            boxShapeDesc = new BoxShapeDescription(1, 1, 1);

            actorDesc = new ActorDescription(boxShapeDesc);
            actorDesc.BodyDescription = new BodyDescription(1f);

            actor = scene.CreateActor(actorDesc);
            actor.GlobalPosition = new Vector3(-4, 5, 0);
        }