예제 #1
0
        public static SLAct createBox(float x, float y, float z, float density, bool fix)
        {
            Vector3          pos       = new Vector3(x, y, z);
            ActorDescription actorDesc = new ActorDescription();
            BodyDescription  bodyDesc  = new BodyDescription();

            actorDesc.SetToDefault();
            bodyDesc.SetToDefault();

            BoxShapeDescription capsuleDesc = new BoxShapeDescription()
            {
                LocalPose = Matrix.Translation(new Vector3(0, 0, 0)),
                //Name = mName
                // LocalRotation = Matrix.CreateRotationZ(45)
            };

            actorDesc.Shapes.Add(capsuleDesc);
            if (density > 0)
            {
                actorDesc.BodyDescription = bodyDesc;
                actorDesc.Density         = density;
            }
            actorDesc.GlobalPose = Matrix.Translation(pos);

            SLAct act = new SLAct(actorDesc);

            act.no_gravity = fix;
            return(act);
        }
예제 #2
0
        public void TestPhysicsMeshPoolConvexMesh()
        {
            XNAGame game = new XNAGame();

            var mesh = new RAMMesh();
            var data = mesh.GetCollisionData();

            var convex = new MeshCollisionData.Convex();

            convex.Positions = new List <Vector3>();
            Vector3[] pos      = CreatePyramidPositions();
            Vector3[] transpos = new Vector3[pos.Length];
            var       mat      = Matrix.CreateTranslation(20, 5, 20);

            Vector3.Transform(pos, ref mat, transpos);
            convex.Positions.AddRange(transpos);

            data.ConvexMeshes.Add(convex);

            PhysicsEngine           engine        = new PhysicsEngine();
            PhysicsDebugRendererXNA debugRenderer = null;



            game.InitializeEvent += delegate
            {
                engine.Initialize();
                debugRenderer = new PhysicsDebugRendererXNA(game, engine.Scene);
                debugRenderer.Initialize(game);

                var pool = new MeshPhysicsPool();

                var tMesh1 = pool.CreateConvexMesh(engine.Scene, mesh.GetCollisionData().ConvexMeshes[0]);
                var tMesh2 = pool.CreateConvexMesh(engine.Scene, mesh.GetCollisionData().ConvexMeshes[0]);
                Assert.AreEqual(tMesh1, tMesh2);


                var actorDesc = new ActorDescription(new ConvexShapeDescription()
                {
                    ConvexMesh = tMesh1
                });
                engine.Scene.CreateActor(actorDesc);
            };

            game.DrawEvent += delegate
            {
                debugRenderer.Render(game);
            };
            int frameNum = 0;

            game.UpdateEvent += delegate
            {
                engine.Update(game.Elapsed);
                //if (frameNum > 2) game.Exit();
                frameNum++;
            };


            game.Run();
        }
예제 #3
0
파일: Fluid.cs 프로젝트: mgq812/PhysX.NET
        public static PhysX.Fluid FluidWithEmitterAndDrain(Scene scene)
        {
            const int maximumParticles = 1000;

            var fluidEmitterDesc = new FluidEmitterDescription()
            {
                DimensionX   = 0.5f,
                DimensionY   = 0.5f,
                Rate         = 15,
                RelativePose =
                    Matrix.RotationAxis(new Vector3(0, 1, 0), (float)Math.PI) *
                    Matrix.Translation(-40, 10, -50),
                Shape       = EmitterShape.Rectangular,
                Type        = EmitterType.ConstantFlowRate,
                RandomAngle = 0.5f
            };

            fluidEmitterDesc.Flags |= (FluidEmitterFlag.Enabled | FluidEmitterFlag.Visualization);

            var fluidDesc = new FluidDescription()
            {
                Emitters         = { fluidEmitterDesc },
                Flags            = FluidFlag.Enabled | FluidFlag.Visualization,
                MaximumParticles = maximumParticles
            };

            fluidDesc.ParticleWriteData.AllocatePositionBuffer <Vector3>(maximumParticles);
            fluidDesc.ParticleWriteData.NumberOfParticles = maximumParticles;

            var fluid = scene.CreateFluid(fluidDesc);

            // Ledge
            {
                var boxShapeDesc = new BoxShapeDescription(5, 0.1f, 5);

                var drainActorDesc = new ActorDescription()
                {
                    GlobalPose = Matrix.RotationX(-0.5f) * Matrix.Translation(-40, 5, -52),
                    Shapes     = { boxShapeDesc }
                };

                var drianActor = scene.CreateActor(drainActorDesc);
            }

            // Drain
            {
                var boxShapeDesc = new BoxShapeDescription(5, 0.1f, 5);
                boxShapeDesc.Flags |= ShapeFlag.FluidDrain;

                var drainActorDesc = new ActorDescription()
                {
                    GlobalPose = Matrix.Translation(-40, 0, -55),
                    Shapes     = { boxShapeDesc }
                };

                var drianActor = scene.CreateActor(drainActorDesc);
            }

            return(fluid);
        }
예제 #4
0
        private void CreateBoxes(Nx.Material material)
        {
            for (int x = 0; x < XCount; x++)
                for (int y = 0; y < YCount; y++)
                    for (int z = 0; z < ZCount; z++)
                    {
                        var rigidBodyDesc = new BodyDescription();

                        var boxDesc = new BoxShapeDescription
                        {
                            Material = material,
                            Dimensions = new NxVector3(WidthX / 2, WidthY / 2, WidthZ / 2)
                        };

                        var actorDesc = new ActorDescription(boxDesc)
                        {
                            BodyDescription = rigidBodyDesc,
                            Density = 10.0f,
                            GlobalPose = NxMath.Matrix.Translation(
                                                   XOffset + x * XSpace - ((XCount - 1) * XSpace / 2),
                                                   YOffset + y * YSpace - ((YCount - 1) * YSpace / 2),
                                                   ZOffset + z * ZSpace - ((ZCount - 1) * ZSpace / 2)),
                            UserData = _boxModel
                        };

                        if (!actorDesc.IsValid())
                            throw new Exception("ActorDesc invalid!");

                        var actor = _scene.CreateActor(actorDesc);
                        if (actor == null)
                            throw new Exception("Actor invalid!");
                    }
        }
예제 #5
0
		public void DeletePairedActors()
		{
			using( CreateCoreAndScene() )
			{
				Actor actorA, actorB;
				{
					ActorDescription actorDesc = new ActorDescription()
					{
						Shapes = { new BoxShapeDescription( 5, 6, 7 ) }
					};

					actorA = this.Scene.CreateActor( actorDesc );
				}
				{
					ActorDescription actorDesc = new ActorDescription()
					{
						Shapes = { new BoxShapeDescription( 2, 5, 7 ) }
					};

					actorB = this.Scene.CreateActor( actorDesc );
				}

				this.Scene.SetActorPairFlags( actorA, actorB, ContactPairFlag.All );
				ContactPairFlag pairFlags = this.Scene.GetActorPairFlags( actorA, actorB );

				actorB.Dispose();
				actorA.Dispose();
			}
		}
        protected override void LoadContent(GraphicInfo GraphicInfo, GraphicFactory factory ,IContentManager contentManager)
        {
            PhysxPhysicWorld PhysxPhysicWorld = World.PhysicWorld as PhysxPhysicWorld;

            base.LoadContent(GraphicInfo, factory, contentManager);            

            var grid = VertexGrid.CreateGrid(100, 100, 0.3f, 100, 100);
            
            ClothModel ClothModel = new PloobsEngine.Modelo.ClothModel(factory, PhysxPhysicWorld,
                new ClothMeshDescription(), grid.Points,grid.TextCoords,grid.Indices, "Textures//meiofio");

            var clothDesc = new ClothDescription()
            {
                Friction = 0.5f,
                ClothMesh = ClothModel.ClothMesh,
                Flags = ClothFlag.Bending | ClothFlag.CollisionTwoway | ClothFlag.Visualization ,
                Thickness = 0.2f,                
                WindAcceleration = new StillDesign.PhysX.MathPrimitives.Vector3(10,0,10)
            };            
                        clothDesc.MeshData.AllocatePositions<Vector3>(grid.Points.Length );
            clothDesc.MeshData.AllocateIndices<int>(grid.Indices.Length );
            clothDesc.MeshData.AllocateNormals<Vector3>(grid.Points.Length );

            clothDesc.MeshData.MaximumVertices = grid.Points.Length ;
            clothDesc.MeshData.MaximumIndices = grid.Indices.Length ;

            clothDesc.MeshData.NumberOfVertices = grid.Points.Length ;
            clothDesc.MeshData.NumberOfIndices = grid.Indices.Length ;            
            
            PhysxClothObject PhysxClothObject = new PloobsEngine.Physics.PhysxClothObject(clothDesc,
                                                Matrix.CreateRotationX((float)Math.PI / 2f) * Matrix.CreateTranslation(0,10,0));

            
            ForwardXNABasicShader ForwardXNABasicShader = new PloobsEngine.Material.ForwardXNABasicShader();
            ClothMaterial ClothMaterial = new ClothMaterial(ForwardXNABasicShader);
            IObject IObject = new PloobsEngine.SceneControl.IObject(ClothMaterial, ClothModel, PhysxClothObject);
            
            World.AddObject(IObject);
            
                ///pra preender            
                CapsuleShapeDescription CapsuleShapeDescription = new StillDesign.PhysX.CapsuleShapeDescription();
                CapsuleShapeDescription.Height = 100;
                CapsuleShapeDescription.Radius = 0.15f;
                CapsuleShapeDescription.LocalPosition = new StillDesign.PhysX.MathPrimitives.Vector3(0, 0.15f + 0.5f * 10, 0);
                
                var actorDesc = new ActorDescription()
                {
                    GlobalPose = StillDesign.PhysX.MathPrimitives.Matrix.Translation(0,-0.2f,0),
                    Shapes = { CapsuleShapeDescription }
                };

                var actor = PhysxPhysicWorld.Scene.CreateActor(actorDesc);

                PhysxClothObject.Cloth.AttachToShape(actor.Shapes.First(), (ClothAttachmentFlag)0);                
            
                        
            BallThrowPhysx28 BallThrowBullet = new BallThrowPhysx28(this.World, GraphicFactory);
            this.AttachCleanUpAble(BallThrowBullet);
            this.World.CameraManager.AddCamera(new CameraFirstPerson(GraphicInfo));
        }
예제 #7
0
        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));
        }
예제 #8
0
        public static PhysX.HeightField HeightfieldGrid(Scene scene)
        {
            int rows    = 25;
            int columns = 25;

            var samples = new HeightFieldSample[rows * columns];

            for (int r = 0; r < rows; r++)
            {
                for (int c = 0; c < columns; c++)
                {
                    // Put a z and x curve together
                    double h = Math.Sin(c) * Math.Cos(r) * short.MaxValue;

                    var sample = new HeightFieldSample()
                    {
                        Height           = (short)h,
                        MaterialIndex0   = 0,
                        MaterialIndex1   = 1,
                        TessellationFlag = 0
                    };

                    samples[r * columns + c] = sample;
                }
            }

            var heightFieldDesc = new HeightFieldDescription()
            {
                NumberOfRows    = rows,
                NumberOfColumns = columns
            };

            heightFieldDesc.SetSamples(samples);

            var heightField = scene.Core.CreateHeightField(heightFieldDesc);

            //

            var heightFieldShapeDesc = new HeightFieldShapeDescription()
            {
                HeightField  = heightField,
                HoleMaterial = 2,
                // The max height of our samples is short.MaxValue and we want it to be 1
                HeightScale = 1.0f / (float)short.MaxValue,
                RowScale    = 3,
                ColumnScale = 3
            };

            heightFieldShapeDesc.LocalPosition = new Vector3(-0.5f * rows * 1 * heightFieldShapeDesc.RowScale, 0, -0.5f * columns * 1 * heightFieldShapeDesc.ColumnScale);

            var actorDesc = new ActorDescription()
            {
                GlobalPose = Matrix.Translation(100, 0, 0),
                Shapes     = { heightFieldShapeDesc }
            };

            var actor = scene.CreateActor(actorDesc);

            return(heightField);
        }
예제 #9
0
        public void Initialize()
        {
            if (Behaviour.RefNumber == 99) //flag waving guy
            {
                SetAction(Behaviour.Actions[7], true);
            }
            else
            {
                SetAction(Behaviour.Standing, true);
            }
            Position            = Instructions[InitialInstruction].Position;
            _currentInstruction = InitialInstruction;

            if (Instructions[_currentInstruction].AutoY)
            {
                StillDesign.PhysX.RaycastHit hit = PhysX.Instance.Scene.RaycastClosestShape(new StillDesign.PhysX.Ray(Position + new Vector3(0, 10, 0), Vector3.Down), StillDesign.PhysX.ShapesType.Static);
                Position = hit.WorldImpact;
            }

            ActorDescription actorDesc = new ActorDescription();

            actorDesc.BodyDescription = new BodyDescription(1);
            actorDesc.BodyDescription.MassSpaceInertia = new Vector3(1, 1, 1);
            actorDesc.BodyDescription.BodyFlags       |= BodyFlag.Kinematic;

            BoxShapeDescription box = new BoxShapeDescription(1.6f, 2.5f, 1.6f);

            box.Flags         = ShapeFlag.TriggerOnEnter;
            box.LocalPosition = new Vector3(0, 1, 0);
            actorDesc.Shapes.Add(box);
            _physXActor = PhysX.Instance.Scene.CreateActor(actorDesc);
            _physXActor.GlobalPosition = Position;
            _physXActor.UserData       = this;
        }
예제 #10
0
파일: Car.cs 프로젝트: EvGenius91/Game
        protected void iniPhysx(Vector3 startPosition)
        {
            BodyDescription boxBody = new BodyDescription();
            boxBody.AngularVelocity = new StillDesign.PhysX.MathPrimitives.Vector3(1, 0, 0);
            boxBody.Mass = 2000;

            //Material
            MaterialDescription materialDesc = new MaterialDescription();
            materialDesc.Restitution = 0.001f;
            materialDesc.StaticFriction = 0.5f;
            materialDesc.DynamicFriction = 0.5f;
            materialDesc.Name = "Test";
            this.game.scene.CreateMaterial(materialDesc);

            BoxShapeDescription boxShapeDesc = new BoxShapeDescription();
            boxShapeDesc.Dimensions = new StillDesign.PhysX.MathPrimitives.Vector3(20.5f, 6.4f, 34.0f);
            boxShapeDesc.Material = this.game.scene.Materials[1];
            boxShapeDesc.Mass = 2000;

            ActorDescription actor = new ActorDescription();

            actor.GlobalPose = StillDesign.PhysX.MathPrimitives.Matrix.Translation(startPosition.X, startPosition.Y, startPosition.Z);
            actor.BodyDescription = boxBody;
            actor.Shapes.Add(boxShapeDesc);

            this.actor = this.game.scene.CreateActor(actor);
            this.shape = this.actor.CreateShape(boxShapeDesc) as BoxShape;
        }
예제 #11
0
        /// <summary>
        /// Returns syntax for dispatching <paramref name="event"/> to <paramref name="actor"/>.
        /// </summary>
        /// <param name="event">
        /// The event.
        /// </param>
        /// <param name="actor">
        /// The actor description.
        /// </param>
        /// <returns>
        /// Syntax for dispatching <paramref name="event"/> to <paramref name="actor"/>.
        /// </returns>
        private static StatementSyntax GenerateActorBlock(
            ExpressionSyntax @event,
            ActorDescription actor)
        {
            var @var      = SF.IdentifierName("var");
            var grainType = actor.Type.GetTypeSyntax();
            var getGrain  =
                SF.InvocationExpression(SF.IdentifierName("GrainFactory").Member("GetGrain", grainType))
                .AddArgumentListArguments(SF.Argument(@event.Member("To").Member("Id")));
            var grain            = SF.VariableDeclarator("grain").WithInitializer(SF.EqualsValueClause(getGrain));
            var grainDeclaration = SF.LocalDeclarationStatement(SF.VariableDeclaration(@var).AddVariables(grain));

            var returnNull = SF.ReturnStatement(SF.LiteralExpression(SyntaxKind.NullLiteralExpression));

            var defaultSection = SF.SwitchSection().AddLabels(SF.DefaultSwitchLabel()).AddStatements(returnNull);
            var methodSwitch   =
                SF.SwitchStatement(@event.Member("Type"))
                .AddSections(
                    actor.Methods.Values.Where(_ => _.Visible)
                    .Select(method => GetMethodSwitchCase(@event, method))
                    .ToArray())
                .AddSections(defaultSection);
            var methodDispatcher = SF.Block().AddStatements(grainDeclaration, methodSwitch);

            return(methodDispatcher);
        }
예제 #12
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();
        }
예제 #13
0
        /// <summary>
        /// This method take a name of a file, created by this app and create a PhysX actor with all shapes saved on file.
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public bool LoadPxMesh(string name)
        {
            //Get the streams names from file
            var streams   = PxMeshDecoder.Load(name);
            var actorDesc = new ActorDescription();

            try
            {
                for (int i = 0; i < streams.Count; i++)
                {
                    actorDesc.Shapes.Add(GetPxMeshFromFile(streams[i], Matrix.Identity)); //Load the PxMesh present in file
                }
                actorDesc.GlobalPose = Matrix.CreateRotationY(0) * Matrix.CreateTranslation(Vector3.Zero);
                //actorDesc.GlobalPose = modelSceneNode.Model.Root.Transform;
                modelActor = PhysX.Instance.Scene.CreateActor(actorDesc);

                return(true);
            }
// ReSharper disable RedundantCatchClause
            catch (Exception)
            {
#if DEBUG
                throw;
#else
                return(false);
#endif
            }
// ReSharper restore RedundantCatchClause
        }
예제 #14
0
        protected void iniPhysx(Vector3 startPosition)
        {
            BodyDescription boxBody = new BodyDescription();

            boxBody.AngularVelocity = new StillDesign.PhysX.MathPrimitives.Vector3(1, 0, 0);
            boxBody.Mass            = 2000;

            //Material
            MaterialDescription materialDesc = new MaterialDescription();

            materialDesc.Restitution     = 0.001f;
            materialDesc.StaticFriction  = 0.5f;
            materialDesc.DynamicFriction = 0.5f;
            materialDesc.Name            = "Test";
            this.game.scene.CreateMaterial(materialDesc);


            BoxShapeDescription boxShapeDesc = new BoxShapeDescription();

            boxShapeDesc.Dimensions = new StillDesign.PhysX.MathPrimitives.Vector3(20.5f, 6.4f, 34.0f);
            boxShapeDesc.Material   = this.game.scene.Materials[1];
            boxShapeDesc.Mass       = 2000;

            ActorDescription actor = new ActorDescription();

            actor.GlobalPose      = StillDesign.PhysX.MathPrimitives.Matrix.Translation(startPosition.X, startPosition.Y, startPosition.Z);
            actor.BodyDescription = boxBody;
            actor.Shapes.Add(boxShapeDesc);

            this.actor = this.game.scene.CreateActor(actor);
            this.shape = this.actor.CreateShape(boxShapeDesc) as BoxShape;
        }
예제 #15
0
        public void DeletePairedActors()
        {
            using (CreateCoreAndScene())
            {
                Actor actorA, actorB;
                {
                    ActorDescription actorDesc = new ActorDescription()
                    {
                        Shapes = { new BoxShapeDescription(5, 6, 7) }
                    };

                    actorA = this.Scene.CreateActor(actorDesc);
                }
                {
                    ActorDescription actorDesc = new ActorDescription()
                    {
                        Shapes = { new BoxShapeDescription(2, 5, 7) }
                    };

                    actorB = this.Scene.CreateActor(actorDesc);
                }

                this.Scene.SetActorPairFlags(actorA, actorB, ContactPairFlag.All);
                ContactPairFlag pairFlags = this.Scene.GetActorPairFlags(actorA, actorB);

                actorB.Dispose();
                actorA.Dispose();
            }
        }
        /// <summary>
        /// The generate method.
        /// </summary>
        /// <param name="actor">
        /// The actor.
        /// </param>
        /// <returns>
        /// The <see cref="MethodDeclarationSyntax"/>.
        /// </returns>
        private static MethodDeclarationSyntax GenerateInvokeMethod(ActorDescription actor)
        {
            // Get the method with the correct type.
            var method =
                TypeUtil.GenericTypeMethod(
                    (IEventInvoker <IGrain> x) => x.Invoke(default(IGrain), default(Event)),
                    new[] { actor.Type });

            var methodDeclaration = method.GetMethodDeclarationSyntax();
            var parameters        = method.GetParameters();

            var @event =
                SF.IdentifierName(parameters.First(_ => typeof(Event) == _.ParameterType).Name);

            var instance =
                SF.IdentifierName(parameters.First(_ => actor.Type == _.ParameterType).Name);

            var switchCases    = GenerateSwitchCases(actor, m => GenerateDispatchBlockForMethod(m, instance, @event)).ToArray();
            var returnNull     = SF.ReturnStatement(SF.LiteralExpression(SyntaxKind.NullLiteralExpression));
            var defaultSection = SF.SwitchSection().AddLabels(SF.DefaultSwitchLabel()).AddStatements(returnNull);
            var kindSwitch     =
                SF.SwitchStatement(@event.Member((Event _) => _.Type))
                .AddSections(switchCases)
                .AddSections(defaultSection);

            return
                (methodDeclaration
                 .AddBodyStatements(kindSwitch));
        }
        public void TestSyncOnlineClient()
        {
            var conn = NetworkingUtilities.ConnectTCP(10045, "5.149.17.16");

            //var conn = NetworkingClientTest.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 client1 = clientSyncer.CreateActor(physicsEngine.Scene.CreateActor(actorDesc));

                client1.ID = 2; // Identify
            };

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

                clientSyncer.Update(game.Elapsed);
            };

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

            game.Run();

            physicsEngine.Dispose();
        }
예제 #18
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));
        }
예제 #19
0
		public void CreateHeightfieldTest()
		{
			int rows = 25;
			int columns = 25;

			HeightFieldSample[] samples = new HeightFieldSample[ rows * columns ];
			for( int r = 0; r < rows; r++ )
			{
				for( int c = 0; c < columns; c++ )
				{
					// Put a z and x curve together
					double h = Math.Sin( c ) * Math.Cos( r ) * short.MaxValue;

					HeightFieldSample sample = new HeightFieldSample()
					{
						Height = (short)h,
						MaterialIndex0 = 0,
						MaterialIndex1 = 1,
						TessellationFlag = 0
					};

					samples[ r * columns + c ] = sample;
				}
			}

			HeightFieldDescription heightFieldDesc = new HeightFieldDescription()
			{
				NumberOfRows = rows,
				NumberOfColumns = columns
			};
			heightFieldDesc.SetSamples( samples );

			using (CreateCoreAndScene())
			{
				HeightField heightField = this.Core.CreateHeightField(heightFieldDesc);

				//

				HeightFieldShapeDescription heightFieldShapeDesc = new HeightFieldShapeDescription()
				{
					HeightField = heightField,
					HoleMaterial = 2,
					// The max height of our samples is short.MaxValue and we want it to be 1
					HeightScale = 1.0f / (float)short.MaxValue,
					RowScale = 3,
					ColumnScale = 3
				};
				heightFieldShapeDesc.LocalPosition = new Vector3(-0.5f * rows * 1 * heightFieldShapeDesc.RowScale, 0, -0.5f * columns * 1 * heightFieldShapeDesc.ColumnScale);

				ActorDescription actorDesc = new ActorDescription()
				{
					GlobalPose = Matrix.Translation(100, 0, 0),
					Shapes = { heightFieldShapeDesc }
				};

				Actor actor = this.Scene.CreateActor(actorDesc);
			}
		}
예제 #20
0
파일: Fluid.cs 프로젝트: dkushner/PhysX.NET
		public static PhysX.Fluid FluidWithEmitterAndDrain(Scene scene)
		{
			const int maximumParticles = 1000;

			var fluidEmitterDesc = new FluidEmitterDescription()
			{
				DimensionX = 0.5f,
				DimensionY = 0.5f,
				Rate = 15,
				RelativePose = 
					Matrix.RotationAxis(new Vector3(0, 1, 0), (float)Math.PI) *
					Matrix.Translation(-40, 10, -50),
				Shape = EmitterShape.Rectangular,
				Type = EmitterType.ConstantFlowRate,
				RandomAngle = 0.5f
			};
			fluidEmitterDesc.Flags |= (FluidEmitterFlag.Enabled | FluidEmitterFlag.Visualization);

			var fluidDesc = new FluidDescription()
			{
				Emitters = { fluidEmitterDesc },
				Flags = FluidFlag.Enabled | FluidFlag.Visualization,
				MaximumParticles = maximumParticles
			};
			fluidDesc.ParticleWriteData.AllocatePositionBuffer<Vector3>(maximumParticles);
			fluidDesc.ParticleWriteData.NumberOfParticles = maximumParticles;

			var fluid = scene.CreateFluid(fluidDesc);

			// Ledge
			{
				var boxShapeDesc = new BoxShapeDescription(5, 0.1f, 5);

				var drainActorDesc = new ActorDescription()
				{
					GlobalPose = Matrix.RotationX(-0.5f) * Matrix.Translation(-40, 5, -52),
					Shapes = { boxShapeDesc }
				};

				var drianActor = scene.CreateActor(drainActorDesc);
			}

			// Drain
			{
				var boxShapeDesc = new BoxShapeDescription(5, 0.1f, 5);
				boxShapeDesc.Flags |= ShapeFlag.FluidDrain;

				var drainActorDesc = new ActorDescription()
				{
					GlobalPose = Matrix.Translation(-40, 0, -55),
					Shapes = { boxShapeDesc }
				};

				var drianActor = scene.CreateActor(drainActorDesc);
			}

			return fluid;
		}
예제 #21
0
        public static Actor CreateGroundPlane()
        {
            // Create a plane with default descriptor
            var planeDesc = new PlaneShapeDescription();
            var actorDesc = new ActorDescription();

            actorDesc.Shapes.Add(planeDesc);
            return(PhysX.Instance.Scene.CreateActor(actorDesc));
        }
        /// <summary>
        /// You can put a scale (-1) operation in the global pose, it works! (not for convex meshes though!)
        /// NOTE: WARNING: scaling not supported!!! (still not supported, it has been delayed for several reasons)
        /// </summary>
        /// <param name="data"></param>
        /// <param name="scene"></param>
        /// <param name="globalPose"></param>
        /// <returns></returns>
        private ActorDescription createActorDesc(MeshCollisionData data, StillDesign.PhysX.Scene scene, Matrix globalPose)
        {
            // From PhysX SDK:
            //There are some performance implications of compound shapes that the user should be aware of:
            //You should avoid static actors being compounds; there's a limit to the number of triangles allowed in one actor's mesh shapes and subshapes exceeding the limit will be ignored.
            //TODO: is this about triangle meshes only? EDIT: i dont think so



            // Pull scaling out of the transformation
            Vector3    scale, translation;
            Quaternion rotation;

            globalPose.Decompose(out scale, out rotation, out translation);

            //globalPose = Matrix.CreateFromQuaternion(rotation) * Matrix.CreateTranslation(translation);
            var scaleMat = Matrix.Identity;// Matrix.CreateScale(scale);


            ActorDescription actorDesc = new ActorDescription();

            for (int i = 0; i < data.Boxes.Count; i++)
            {
                var box   = data.Boxes[i];
                var shape = new BoxShapeDescription(box.Dimensions);
                shape.LocalPose = box.Orientation * scaleMat;
                actorDesc.Shapes.Add(shape);
            }

            for (int i = 0; i < data.ConvexMeshes.Count; i++)
            {
                var convex = data.ConvexMeshes[i];
                var shape  = new ConvexShapeDescription();
                shape.ConvexMesh = MeshPhysicsPool.CreateConvexMesh(scene, convex);

                shape.Flags = ShapeFlag.Visualization;
                actorDesc.Shapes.Add(shape);
            }



            if (data.TriangleMesh != null)
            {
                TriangleMesh triangleMesh;
                triangleMesh = MeshPhysicsPool.CreateTriangleMesh(scene, data.TriangleMesh);

                TriangleMeshShapeDescription shapeDesc = new TriangleMeshShapeDescription();
                shapeDesc.TriangleMesh = triangleMesh;
                shapeDesc.Flags        = ShapeFlag.Visualization; // Vizualization enabled, obviously (not obviously enabled, obvious that this enables visualization)

                actorDesc.Shapes.Add(shapeDesc);
            }

            actorDesc.GlobalPose = globalPose;
            return(actorDesc);
        }
예제 #23
0
        public static Model LoadConvexMesh(Scene scene, Device device)
        {
            var torusModel = ColladaLoader.Load(@"Resources\Torus.DAE", device);

            var core = scene.Core;

            // Allocate memory for the points and triangles
            var convexMeshDesc = new ConvexMeshDescription()
            {
                PointCount = torusModel.VertexPositions.Length
            };

            convexMeshDesc.Flags |= ConvexFlag.ComputeConvex;
            convexMeshDesc.AllocatePoints <Vector3>(torusModel.VertexPositions.Length);

            // Write in the points and triangles
            // We only want the Position component of the vertex. Also scale down the mesh.
            foreach (var vertex in torusModel.VertexPositions)
            {
                var t        = SlimDX.Matrix.Scaling(0.1f, 0.1f, 0.1f);
                var position = SlimDX.Vector3.TransformCoordinate(vertex, t);

                convexMeshDesc.PointsStream.Write(position);
            }

            //

            // Cook to memory or to a file
            ConvexMesh convexMesh;

            using (var stream = new MemoryStream())
            {
                //FileStream stream = new FileStream( @"Convex Mesh.cooked", FileMode.CreateNew );

                Cooking.InitializeCooking(new ConsoleOutputStream());
                Cooking.CookConvexMesh(convexMeshDesc, stream);
                Cooking.CloseCooking();

                stream.Position = 0;

                convexMesh = core.CreateConvexMesh(stream);
            }
            var convexShapeDesc = new ConvexShapeDescription(convexMesh);

            var actorDesc = new ActorDescription()
            {
                BodyDescription = new BodyDescription(10.0f),
                GlobalPose      = Matrix.Translation(30, 30, 0)
            };

            actorDesc.Shapes.Add(convexShapeDesc);

            var actor = scene.CreateActor(actorDesc);

            return(torusModel);
        }
 public PhysxPhysicObject(ShapeDescription ShapeDescription, Matrix worldTransformation, Vector3 scale, String name = null)
 {
     Scale = scale;
     ActorDesc = new ActorDescription()
     {                
         Name = name,                
         GlobalPose = worldTransformation.AsPhysX(),
         Shapes = { ShapeDescription },
     };
 }
        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));
        }
예제 #26
0
 public PhysxPhysicObject(ShapeDescription ShapeDescription, Matrix worldTransformation, Vector3 scale, String name = null)
 {
     Scale     = scale;
     ActorDesc = new ActorDescription()
     {
         Name       = name,
         GlobalPose = worldTransformation.AsPhysX(),
         Shapes     = { ShapeDescription },
     };
 }
예제 #27
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;
        }
예제 #28
0
        public void TestTriangleMesh()
        {
            XNAGame game = new XNAGame();

            game.SpectaterCamera.CameraPosition = new Vector3(0, 0, -40);
            PhysicsEngine engine = new PhysicsEngine();

            //game.AddXNAObject(engine);



            game.InitializeEvent += delegate
            {
                engine.Initialize();

                PhysicsDebugRendererXNA debugRenderer = new PhysicsDebugRendererXNA(game, engine.Scene);

                game.AddXNAObject(debugRenderer);

                TangentVertex[] vertices;
                short[]         indices;
                BoxMesh.CreateUnitBoxVerticesAndIndices(out vertices, out indices);

                var positions = new Vector3[vertices.Length];
                for (int i = 0; i < positions.Length; i++)
                {
                    positions[i] = vertices[i].pos;
                }

                int[] intIndices = new int[indices.Length];
                for (int i = 0; i < intIndices.Length; i++)
                {
                    intIndices[i] = indices[i];
                }

                var triangleMesh = CreateTriangleMesh(positions, intIndices, engine.Scene);

                var triangleMeshShapeDesc = new TriangleMeshShapeDescription();
                triangleMeshShapeDesc.TriangleMesh = triangleMesh;

                var actorDesc = new ActorDescription(triangleMeshShapeDesc);

                var actor = engine.Scene.CreateActor(actorDesc);
            };

            game.UpdateEvent += delegate
            {
                engine.Update(game.Elapsed);
            };

            game.Run();

            engine.Dispose();
        }
예제 #29
0
        Actor CreateActorFromHeightmap(float[] heightmap)
        {
            HeightFieldSample[] samples = new HeightFieldSample[heightmap.Length];

            float min = float.MaxValue, max = float.MinValue;

            for(int i=0;i<heightmap.Length;i++)
            {
                if(heightmap[i] > max)
                    max = heightmap[i];
                if(heightmap[i] < min)
                    min = heightmap[i];
            }

            
            for(int i=0;i<heightmap.Length;i++)
            {
                short normValue = (short) ((float) ((heightmap[i] - min)/(max - min))*(float) short.MaxValue);

                samples[i] = new HeightFieldSample();
                samples[i].Height = normValue;
                samples[i].MaterialIndex0 = 0;
                samples[i].MaterialIndex1 = 1;
                samples[i].TessellationFlag = 0; // Might be important?
            }

            HeightFieldDescription heightFieldDescription = new HeightFieldDescription();

            // Might cause fun with MegaRegions
            heightFieldDescription.NumberOfRows = (int) Constants.RegionSize;
            heightFieldDescription.NumberOfColumns = (int) Constants.RegionSize;

            HeightField heightField = physicsCore.CreateHeightField(heightFieldDescription);

            HeightFieldShapeDescription heightFieldShapeDescription = new HeightFieldShapeDescription()
                                                                          {
                                                                              HeightField = heightField,
                                                                              HoleMaterial = 2,
                                                                              HeightScale = (max - min),
                                                                              RowScale = 1.0f,
                                                                              ColumnScale = 1.0f
                                                                          };

            heightFieldShapeDescription.LocalPosition = new Vector3(0, 0, min); // May need to move to ActorDescription.GlobalPos?

            ActorDescription actorDescription = new ActorDescription()
                                                    {
                                                        Shapes = {heightFieldShapeDescription}
                                                    };

            Actor actor = physicsScene.CreateActor(actorDescription);

            return actor;
        }
        private static TypeDeclarationSyntax GenerateClass(ActorDescription actor)
        {
            var producerType = SF.SimpleBaseType(actor.Type.GetTypeSyntax());
            var helperType   = SF.SimpleBaseType(typeof(EventProducerBase <>).MakeGenericType(actor.Type).GetTypeSyntax());

            return
                (SF.ClassDeclaration(GetClassName(actor))
                 .AddModifiers(SF.Token(SyntaxKind.PublicKeyword))
                 .AddBaseListTypes(helperType, producerType)
                 .AddMembers(GenerateMethods(actor).ToArray()));
        }
        /// <summary>
        /// Generates the class for the provided actor.
        /// </summary>
        /// <param name="actor">
        /// The actor.
        /// </param>
        /// <returns>
        /// The generated class.
        /// </returns>
        private static TypeDeclarationSyntax GenerateClass(ActorDescription actor)
        {
            var replayType = SF.SimpleBaseType(typeof(IEventInvoker <>).MakeGenericType(actor.Type).GetTypeSyntax());

            return
                (SF.ClassDeclaration(GetClassName(actor))
                 .AddModifiers(SF.Token(SyntaxKind.PublicKeyword))
                 .AddBaseListTypes(replayType)
                 .AddMembers(GenerateInvokeMethod(actor))
                 .AddMembers(GenerateGetTypeArgumentsMethod(actor)));
        }
예제 #32
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

			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;
		}
 protected override void DoHandleMessage(ActorDescription remoteActor, MessageEnvelope envelope)
 {
     envelope.HandledBy(this.Actor, GetAdmissibleMessageType(envelope.MessageType), this.Actor.Decoder, remoteActor,
                        (object o) =>
     {
         return(o
                .GetType()
                .GetMethod("OnSyncMessage")
                .MakeGenericMethod(GetAdmissibleMessageType(envelope.MessageType)));
     });
 }
예제 #34
0
        public static void AddCogToothShapes(ActorDescription actorDesc, Vector3 pos, Vector3 normal, Vector3 tangent)
        {
            SphereShapeDescription desc = new SphereShapeDescription(0.6f);

            desc.LocalPosition = pos;
            actorDesc.Shapes.Add(desc);

            desc = new SphereShapeDescription(0.2f);
            desc.LocalPosition = pos + 0.6f * normal;
            actorDesc.Shapes.Add(desc);
        }
예제 #35
0
        protected override void OnActorDataReceived(object sender, ActorDataReceivedEventArgs e)
        {
            var envelope = this.Decoder.Decode <MessageEnvelope>(e.Data, e.DataOffset, e.DataLength);

            if (envelope.Source == null)
            {
                envelope.Source = Endpoint.CreateEndpoint();
            }
            envelope.Source.AttachPath(e.RemoteActor.GetKey());

            if (envelope.Target != null)
            {
                envelope.Target.DetachPath();
            }

            bool handled = false;

            if (!handled)
            {
                if (envelope.Target != null)
                {
                    var target = envelope.Target.PeakPath();
                    if (!string.IsNullOrEmpty(target))
                    {
                        string remoteActorType, remoteActorName;
                        ActorDescription.Decode(target, out remoteActorType, out remoteActorName);
                        this.SendAsync(remoteActorType, remoteActorName, envelope.ToBytes(this.Encoder));
                        handled = true;
                    }
                }
            }

            if (!handled)
            {
                foreach (var handler in GetMessageHandlers())
                {
                    if (handler.CanHandleMessage(envelope))
                    {
                        handler.HandleMessage(e.RemoteActor, envelope);
                        handled = true;
                        break;
                    }
                }
            }

            if (!handled)
            {
                _log.WarnFormat("OnActorDataReceived, cannot handle message [{0}] from remote actor [{1}].",
                                envelope.MessageType, e.RemoteActor);
            }

            base.OnActorDataReceived(sender, e);
        }
        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));
        }
예제 #37
0
		public static Model LoadConvexMesh(Scene scene, Device device)
		{
			var torusModel = ColladaLoader.Load(@"Resources\Torus.DAE", device);

			var core = scene.Core;

			// Allocate memory for the points and triangles
			var convexMeshDesc = new ConvexMeshDescription()
			{
				PointCount = torusModel.VertexPositions.Length
			};
			convexMeshDesc.Flags |= ConvexFlag.ComputeConvex;
			convexMeshDesc.AllocatePoints<Vector3>(torusModel.VertexPositions.Length);

			// Write in the points and triangles
			// We only want the Position component of the vertex. Also scale down the mesh.
			foreach (var vertex in torusModel.VertexPositions)
			{
				var t = SlimDX.Matrix.Scaling(0.1f, 0.1f, 0.1f);
				var position = SlimDX.Vector3.TransformCoordinate(vertex, t);

				convexMeshDesc.PointsStream.Write(position);
			}

			//

			// Cook to memory or to a file
			ConvexMesh convexMesh;
			using (var stream = new MemoryStream())
			{
				//FileStream stream = new FileStream( @"Convex Mesh.cooked", FileMode.CreateNew );

				Cooking.InitializeCooking(new ConsoleOutputStream());
				Cooking.CookConvexMesh(convexMeshDesc, stream);
				Cooking.CloseCooking();

				stream.Position = 0;

				convexMesh = core.CreateConvexMesh(stream);
			}
			var convexShapeDesc = new ConvexShapeDescription(convexMesh);

			var actorDesc = new ActorDescription()
			{
				BodyDescription = new BodyDescription(10.0f),
				GlobalPose = Matrix.Translation(30, 30, 0)
			};
			actorDesc.Shapes.Add(convexShapeDesc);

			var actor = scene.CreateActor(actorDesc);

			return torusModel;
		}
예제 #38
0
        /// <summary>
        /// Returns syntax for dispatching <paramref name="event"/> to <paramref name="actor"/>.
        /// </summary>
        /// <param name="actor">
        /// The actor description.
        /// </param>
        /// <param name="event">
        /// The event.
        /// </param>
        /// <returns>
        /// Syntax for dispatching <paramref name="event"/> to <paramref name="actor"/>.
        /// </returns>
        private static SwitchSectionSyntax GetActorSwitch(
            ActorDescription actor,
            ExpressionSyntax @event)
        {
            var label =
                SF.CaseSwitchLabel(SF.LiteralExpression(SyntaxKind.StringLiteralExpression, SF.Literal(actor.Kind)));

            return
                (SF.SwitchSection()
                 .AddLabels(label)
                 .AddStatements(GenerateActorBlock(@event, actor)));
        }
예제 #39
0
        /// <summary>
        /// Returns the types referenced by the provided <paramref name="actor"/>.
        /// </summary>
        /// <param name="actor">
        /// The actor.
        /// </param>
        /// <returns>
        /// The types referenced by the provided <paramref name="actor"/>.
        /// </returns>
        public static IEnumerable <Type> GetTypes(ActorDescription actor)
        {
            foreach (var type in GetTypes(actor.Type))
            {
                yield return(type);
            }

            foreach (var type in actor.Methods.Values.SelectMany(GetTypes))
            {
                yield return(type);
            }
        }
 /// <summary>
 /// Generates switch cases for the provided actor.
 /// </summary>
 /// <param name="actor">
 /// The actor.
 /// </param>
 /// <param name="generateSwitchBlock">
 /// The function used to generate switch block statements for each method.
 /// </param>
 /// <returns>
 /// The switch cases for the provided actor.
 /// </returns>
 private static IEnumerable <SwitchSectionSyntax> GenerateSwitchCases(ActorDescription actor, Func <ActorMethodDescription, StatementSyntax> generateSwitchBlock)
 {
     return(actor.Methods.Values.Select(
                m =>
     {
         var label =
             SF.CaseSwitchLabel(SF.LiteralExpression(SyntaxKind.StringLiteralExpression, SF.Literal(m.Name)));
         return
         SF.SwitchSection()
         .AddLabels(label)
         .AddStatements(generateSwitchBlock(m));
     }));
 }
예제 #41
0
        private static Actor CreateBoxActor( Scene scene, float sizeX, float sizeY, float sizeZ )
        {
            var actorDesc = new ActorDescription();
            var bodyDesc = new BodyDescription();

            var boxDesc = new BoxShapeDescription( sizeX, sizeY, sizeZ );

            actorDesc.Shapes.Add( boxDesc );

            actorDesc.BodyDescription = bodyDesc;
            actorDesc.Density = 10;

            return scene.CreateActor( actorDesc );
        }
예제 #42
0
		public void ActorDeletion()
		{
			using( CreateCoreAndScene() )
			{
				ActorDescription actorDesc = new ActorDescription()
				{
					Shapes = { new BoxShapeDescription( 5, 6, 7 ) }
				};

				Actor actor = this.Scene.CreateActor( actorDesc );

				actor.Dispose();
			}
		}
 public void Init(string name, uint localId, ActorDescription desc, IServerNode node)
 {
     _name = name;
     _localId = localId;
     _fullName = string.Format("Actor<Name:{0}, LocalId:{1}, Type:{2}>",name, localId, GetType().Name);
     _description = desc;
     Node = node;
     Log = LogManager.GetLogger(_fullName);
     Fiber = new ServerFiber();
     _handlers = new Dictionary<uint, NetContractHandler>();
     foreach (NetContractDescription implementedContract in desc.ImplementedContracts)
     {
         _handlers.Add(implementedContract.TypeId, new NetContractHandler(node.Dispatcher, implementedContract.TypeId, this));
     }
     OnCreated();
 }
예제 #44
0
		public void DisposeCore()
		{
			{
				ConsoleOutputStream consoleOutputStream = new ConsoleOutputStream();

				Core core = new Core( new CoreDescription(), consoleOutputStream );

				Scene scene = core.CreateScene();

				Actor actorA, actorB;
				{
					ActorDescription actorDesc = new ActorDescription();

					actorDesc.Shapes.Add( new BoxShapeDescription( 5, 6, 7 ) );

					actorA = scene.CreateActor( actorDesc );
				}
				{
					ActorDescription actorDesc = new ActorDescription();

					actorDesc.Shapes.Add( new BoxShapeDescription( 2, 5, 7 ) );

					actorB = scene.CreateActor( actorDesc );
				}

				core.Dispose();
			}

			{
				ConsoleOutputStream consoleOutputStream = new ConsoleOutputStream();

				Core core = new Core( new CoreDescription(), consoleOutputStream );

				Scene scene = core.CreateScene();

				Actor actorA, actorB;
				{
					ActorDescription actorDesc = new ActorDescription();

					actorDesc.Shapes.Add( new BoxShapeDescription( 5, 6, 7 ) );

					actorA = scene.CreateActor( actorDesc );
				}

				core.Dispose();
			}
		}
예제 #45
0
파일: Wheel.cs 프로젝트: EvGenius91/Game
        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;
        }
예제 #46
0
		public static void SimpleBoxes(Scene scene)
		{
			for (int x = 0; x < 5; x++)
			{
				BoxShapeDescription boxShapeDesc = new BoxShapeDescription(2, 3, 8);

				ActorDescription actorDesc = new ActorDescription()
				{
					Name = String.Format("Box {0}", x),
					BodyDescription = new BodyDescription(10.0f),
					GlobalPose = Matrix.Translation(100, 15 + 3 * x, 20),
					Shapes = { boxShapeDesc }
				};

				Actor actor = scene.CreateActor(actorDesc);
			}
		}
예제 #47
0
		public void RequiredMassSpaceInertia()
		{
			var shapeDescription = new SphereShapeDescription( 5 );
			shapeDescription.Flags |= ( ShapeFlag.TriggerOnEnter | ShapeFlag.TriggerOnLeave );

			var actorDesc = new ActorDescription()
			{
				BodyDescription = new BodyDescription( 1 )
				{
					MassSpaceInertia = new Vector3( 1, 1, 1 ),
					BodyFlags = BodyFlag.Kinematic
				},
				Shapes = { shapeDescription }
			};

			Assert.IsTrue( actorDesc.IsValid() );
		}
예제 #48
0
		public static PrismaticJoint PrismaticJointWithLimit(Scene scene)
		{
			Actor actorA, actorB;
			{
				BoxShapeDescription boxShapeDesc = new BoxShapeDescription(3, 3, 3);

				BodyDescription bodyDesc = new BodyDescription(10.0f);
				bodyDesc.BodyFlags |= BodyFlag.Kinematic;

				ActorDescription actorDesc = new ActorDescription()
				{
					BodyDescription = bodyDesc,
					GlobalPose = Matrix.Translation(70, 25, -65),
					Shapes = { boxShapeDesc }
				};
				actorA = scene.CreateActor(actorDesc);
			}
			{
				BoxShapeDescription boxShapeDesc = new BoxShapeDescription(3, 3, 3);

				ActorDescription actorDesc = new ActorDescription()
				{
					BodyDescription = new BodyDescription(10.0f),
					GlobalPose = Matrix.Translation(70, 15, -65),
					Shapes = { boxShapeDesc }
				};
				actorB = scene.CreateActor(actorDesc);
			}

			PrismaticJointDescription prismaticJointDesc = new PrismaticJointDescription()
			{
				Actor1 = actorA,
				Actor2 = actorB,
			};
			prismaticJointDesc.SetGlobalAnchor(new Vector3(70, 20, -65));
			prismaticJointDesc.SetGlobalAxis(new Vector3(0, 1, 0));

			PrismaticJoint prismaticJoint = scene.CreateJoint(prismaticJointDesc) as PrismaticJoint;

			LimitPlane limitPlane = new LimitPlane(new Vector3(0, 1, 0), new Vector3(-30, 8, -30), 0);
			prismaticJoint.AddLimitPlane(limitPlane);

			return prismaticJoint;
		}
        public ActorRepository(IOperationDispatcher dispatcher, IEnumerable<Actor> actorPrototypes)
        {
            Dispatcher = dispatcher;

            foreach (var entity in actorPrototypes)
            {
                Type type = entity.GetType();
                var attr = type.GetAttribute<ActorAttribute>();
                var contracts = new List<NetContractDescription>();
                foreach (Type netContractType in entity.GetType().GetInterfaces())
                {
                    uint typeId;
                    if(dispatcher.TryGetContractId(netContractType, out typeId))
                        contracts.Add(Dispatcher.GetContract(typeId));
                }
                var actorDescription = new ActorDescription(type, contracts, attr);
                _descriptionsByTypeId.Add(actorDescription.PrimaryContract.TypeId, actorDescription);

                Log.Info("Registered {0}", type, actorDescription);
            }
        }
예제 #50
0
		public static void CreateContactReport(Scene scene, Actor groundActor)
		{
			// Contact report
			// When the capsule actor hits the ground make it bounce by using the conact report
			{
				CapsuleShapeDescription capsuleShapeDesc = new CapsuleShapeDescription(1, 5);

				ActorDescription actorDesc = new ActorDescription()
				{
					GlobalPose = Matrix.Translation(-30, 20, 0),
					BodyDescription = new BodyDescription(10.0f),
					Name = "Report Capsule",
					Shapes = { capsuleShapeDesc }
				};

				var contactReportActor = scene.CreateActor(actorDesc);

				scene.SetActorPairFlags(contactReportActor, groundActor, ContactPairFlag.All);

				scene.UserContactReport = new ContactReport(contactReportActor, groundActor);
			}

			// Trigger Reports
			{
				BoxShapeDescription boxShapeDesc = new BoxShapeDescription(15, 8, 15);
				boxShapeDesc.Flags |= (ShapeFlag.TriggerOnEnter | ShapeFlag.TriggerOnLeave);

				ActorDescription actorDesc = new ActorDescription()
				{
					GlobalPose = Matrix.Translation(-30, 4, 0),
					Shapes = { boxShapeDesc }
				};
				scene.CreateActor(actorDesc);

				scene.UserTriggerReport = new TriggerReport();
			}

			scene.UserNotify = new Notify();
		}
예제 #51
0
        private Actor CreateActor(RigidBodyDescriptor descriptor, Scene scene)
        {
         
            var materialDesc = new MaterialDescription
            {
                DynamicFriction = 0.5f,
                StaticFriction = 0.5f,
                Restitution = 0.7f,
                FrictionCombineMode = CombineMode.Average,
                RestitutionCombineMode = CombineMode.Average
            };
            DefaultMaterial = scene.CreateMaterial(materialDesc);
            var boxDesc = new BoxShapeDescription
            {
                Material = DefaultMaterial,
                Dimensions = new Vector3(1, 1, 1)
            };
            ///////////////////////////////////////////////



            //resolve the motion type
            var rigidBodyDesc = descriptor.MotionType == MotionType.Static
                                    ? null
                                    : new BodyDescription();
            if (descriptor.MotionType == MotionType.Kinematic)
                rigidBodyDesc.BodyFlags = BodyFlag.Kinematic;

            HasDefaultShape = true;
            var actorDesc = new ActorDescription(boxDesc)
                                {
                                    BodyDescription = rigidBodyDesc,
                                    Density = 10.0f,
                                    GlobalPose = descriptor.Pose.ToPhysX(),
                                    UserData = descriptor.UserData
                                };
            return scene.CreateActor(actorDesc);
        }
예제 #52
0
		public void ReleaseJoint()
		{
			using( CreateCoreAndScene() )
			{
				Actor actorA, actorB;
				{
					ActorDescription actorDesc = new ActorDescription()
					{
						BodyDescription = new BodyDescription( 20 ),
						Shapes = { new BoxShapeDescription( 5, 6, 7 ) }
					};

					actorA = this.Scene.CreateActor( actorDesc );
				}
				{
					ActorDescription actorDesc = new ActorDescription()
					{
						BodyDescription = new BodyDescription( 20 ),
						Shapes = { new BoxShapeDescription( 2, 5, 7 ) }
					};

					actorB = this.Scene.CreateActor( actorDesc );
				}

				D6JointDescription d6JointDesc = new D6JointDescription()
				{
					Actor1 = actorA,
					Actor2 = actorB
				};

				d6JointDesc.SetGlobalAnchor( new Vector3( 5, 6, 7 ) );
				d6JointDesc.SetGlobalAxis( new Vector3( 0, 0, 1 ) );

				D6Joint d6 = this.Scene.CreateJoint( d6JointDesc ) as D6Joint;

				d6.Dispose();
			}
		}
예제 #53
0
		public void CreateDistanceJoint()
		{
			using( CreateCoreAndScene() )
			{
				Actor actorA, actorB;
				{
					ActorDescription actorDesc = new ActorDescription()
					{
						BodyDescription = new BodyDescription( 20 ),
						Shapes = { new BoxShapeDescription( 5, 6, 7 ) }
					};

					actorA = this.Scene.CreateActor( actorDesc );
				}
				{
					ActorDescription actorDesc = new ActorDescription()
					{
						BodyDescription = new BodyDescription( 20 ),
						Shapes = { new BoxShapeDescription( 5, 6, 7 ) }
					};

					actorB = this.Scene.CreateActor( actorDesc );
				}

				DistanceJointDescription distanceJointDesc = new DistanceJointDescription()
				{
					Actor1 = actorA,
					Actor2 = actorB
				};

				var distanceJoint = this.Scene.CreateJoint( distanceJointDesc ) as DistanceJoint;

				Assert.IsNotNull( distanceJoint );

				Update();
			}
		}
예제 #54
0
		public static RevoluteJoint RevoluteJoint(Scene scene)
		{
			BoxShapeDescription boxShapeDescA = new BoxShapeDescription(3, 3, 3);
			BoxShapeDescription boxShapeDescB = new BoxShapeDescription(3, 3, 3);

			ActorDescription actorDescA = new ActorDescription()
			{
				BodyDescription = new BodyDescription(10.0f),
				GlobalPose = Matrix.Translation(75, 1.5f, -55),
				Shapes = { boxShapeDescA }
			};
			Actor actorA = scene.CreateActor(actorDescA);

			ActorDescription actorDescB = new ActorDescription()
			{
				BodyDescription = new BodyDescription(10.0f),
				GlobalPose = Matrix.Translation(70, 1.5f, -55),
				Shapes = { boxShapeDescB }
			};
			Actor actorB = scene.CreateActor(actorDescB);

			//

			RevoluteJointDescription revoluteJointDesc = new RevoluteJointDescription()
			{
				Actor1 = actorA,
				Actor2 = actorB,
				Motor = new MotorDescription(20, 20.1f, true)
			};
			revoluteJointDesc.Flags |= RevoluteJointFlag.MotorEnabled;
			revoluteJointDesc.SetGlobalAnchor(new Vector3(73.5f, 1.5f, -55));
			revoluteJointDesc.SetGlobalAxis(new Vector3(1, 0, 0));

			RevoluteJoint revoluteJoint = scene.CreateJoint(revoluteJointDesc) as RevoluteJoint;

			return revoluteJoint;
		}
        /// <summary>
        /// Initializes a new instance of the <see cref="PhysxTriangleMesh"/> class.
        /// Cooks the Model on the fly
        /// </summary>
        /// <param name="PhysxPhysicWorld">The physx physic world.</param>
        /// <param name="model">The model.</param>
        /// <param name="worldTransformation">The world transformation.</param>
        /// <param name="scale">The scale.</param>
        /// <param name="density">The density.</param>
        /// <param name="material">The material.</param>
        public PhysxTriangleMesh(PhysxPhysicWorld PhysxPhysicWorld, IModelo model, Microsoft.Xna.Framework.Matrix worldTransformation, Microsoft.Xna.Framework.Vector3 scale, float density = 1,StillDesign.PhysX.Material material = null)
        {
            Microsoft.Xna.Framework.Vector3[] vertices = null;
            int[] indices = null;
            ExtractData(ref vertices, ref indices, model);


            TriangleMeshDescription meshDesc = new TriangleMeshDescription();
            meshDesc.AllocateVertices<Microsoft.Xna.Framework.Vector3>(vertices.Count());            
            meshDesc.VerticesStream.SetData<Microsoft.Xna.Framework.Vector3>(vertices);
            meshDesc.AllocateTriangles<int>(indices.Count());
            meshDesc.TriangleStream.SetData<int>(indices);
            meshDesc.Flags = 0;
            meshDesc.VertexCount = vertices.Count();
            meshDesc.TriangleCount = indices.Count();

            MemoryStream ms = new MemoryStream();
            Cooking.InitializeCooking();            
            if (Cooking.CookTriangleMesh(meshDesc, ms) == false)
            {
                PloobsEngine.Engine.Logger.ActiveLogger.LogMessage("Cant Cook Model",Engine.Logger.LogLevel.FatalError);
            }
            Cooking.CloseCooking();

            ms.Position = 0;
            TriangleMesh triangleMesh = PhysxPhysicWorld.Core.CreateTriangleMesh(ms);
            TriangleMeshShapeDescription bunnyShapeDesc = new TriangleMeshShapeDescription();
            if (material != null)
                bunnyShapeDesc.Material = material;
            bunnyShapeDesc.TriangleMesh = triangleMesh;                
            ActorDesc = new ActorDescription();
            ActorDesc.Shapes.Add(bunnyShapeDesc);            
            ActorDesc.BodyDescription= null;
            ActorDesc.GlobalPose = worldTransformation.AsPhysX();            
            this.Scale = scale;
        }
예제 #56
0
        private void CreateTower(Nx.Material material, NxVector3 descriptor, int xCount, int yCount, int zCount, float xSpace, float ySpace, float zSpace, float xOffset, float yOffset, float zOffset)
        {
            for (int x = 0; x < xCount; x++)
                for (int y = 0; y < yCount; y++)
                    for (int z = 0; z < zCount; z++)
                    {
                        var rigidBodyDesc = new BodyDescription();

                        var boxDesc = new BoxShapeDescription
                                          {
                                              Material = material,
                                              Dimensions = new NxVector3(descriptor.X / 2, descriptor.Y / 2, descriptor.Z / 2)
                                          };

                        var actorDesc = new ActorDescription(boxDesc)
                                            {
                                                BodyDescription = rigidBodyDesc,
                                                Density = 10.0f,
                                                GlobalPose = NxMath.Matrix.Translation(
                                                                       xOffset + x * xSpace - ((xCount - 1) * xSpace / 2),
                                                                       yOffset + y * ySpace - ((yCount - 1) * ySpace / 2),
                                                                       zOffset + z * zSpace - ((zCount - 1) * zSpace / 2)),
                                                UserData = _boxModel
                                            };

                        if (!actorDesc.IsValid())
                            throw new Exception("ActorDesc invalid!");

                        var actor = _scene.CreateActor(actorDesc);
                        if (actor == null)
                            throw new Exception("Actor invalid!");
                    }
        }
예제 #57
0
		public void LoadPhysics()
		{
			Core _core = this.Core;
			Scene _scene = this.Scene;

			#region Some Boxes
			for( int x = 0; x < 5; x++ )
			{
				BoxShapeDescription boxShapeDesc = new BoxShapeDescription( 2, 3, 8 );
				
				ActorDescription actorDesc = new ActorDescription()
				{
					Name = String.Format( "Box {0}", x ),
					BodyDescription = new BodyDescription( 10.0f ),
					GlobalPose = Matrix.Translation( 100, 15 + 3 * x, 20 ),
					Shapes = { boxShapeDesc }
				};

				Actor actor = _scene.CreateActor( actorDesc );
			}
			#endregion

			//#region Cloth (Flag)
			//{
			//    // Create a Grid of Points
			//    VertexGrid grid = VertexGrid.CreateGrid( 10, 10 );

			//    ClothMeshDescription clothMeshDesc = new ClothMeshDescription();
			//        clothMeshDesc.AllocateVertices<Vector3>( grid.Points.Length );
			//        clothMeshDesc.AllocateTriangles<int>( grid.Indices.Length / 3 );

			//        clothMeshDesc.VertexCount = grid.Points.Length;
			//        clothMeshDesc.TriangleCount = grid.Indices.Length / 3;

			//        clothMeshDesc.VerticesStream.SetData( grid.Points );
			//        clothMeshDesc.TriangleStream.SetData( grid.Indices );

			//        // We are using 32 bit integers, so make sure the 16 bit flag is removed.
			//        // 32 bits are the default, so this isn't technically needed
			//        clothMeshDesc.Flags &= ~MeshFlag.Indices16Bit;

			//    // Write the cooked data to memory
			//    MemoryStream memoryStream = new MemoryStream();

			//    Cooking.InitializeCooking();
			//    Cooking.CookClothMesh( clothMeshDesc, memoryStream );
			//    Cooking.CloseCooking();

			//    // Need to reset the position of the stream to the beginning
			//    memoryStream.Position = 0;

			//    ClothMesh clothMesh = _core.CreateClothMesh( memoryStream );

			//    //

			//    ClothDescription clothDesc = new ClothDescription()
			//    {
			//        ClothMesh = clothMesh,
			//        Flags = ClothFlag.Gravity | ClothFlag.Bending | ClothFlag.CollisionTwoway | ClothFlag.Visualization,
			//        GlobalPose =
			//            Matrix.CreateFromYawPitchRoll( 0, (float)Math.PI / 2.0f, (float)Math.PI / 2.0f ) *
			//            Matrix.CreateTranslation( 0, 20, 0 )
			//    };
			//    clothDesc.MeshData.AllocatePositions<Vector3>( grid.Points.Length );
			//    clothDesc.MeshData.AllocateIndices<int>( grid.Indices.Length );

			//    clothDesc.MeshData.MaximumVertices = grid.Points.Length;
			//    clothDesc.MeshData.MaximumIndices = grid.Indices.Length;

			//    clothDesc.MeshData.NumberOfVertices = grid.Points.Length;
			//    clothDesc.MeshData.NumberOfIndices = grid.Indices.Length;

			//    _flag = _scene.CreateCloth( clothDesc );

			//    // Flag Pole
			//    ActorDescription flagPoleActorDesc = new ActorDescription()
			//    {
			//        GlobalPose = Matrix.CreateTranslation( 0, 10, 0 ),
			//        Shapes = { new BoxShapeDescription( 1.0f, 20.0f, 1.0f ) }
			//    };

			//    Actor flagPoleActor = _scene.CreateActor( flagPoleActorDesc );

			//    _flag.AttachToShape( flagPoleActor.Shapes[ 0 ], 0 );
			//    _flag.WindAcceleration = new Vector3( 10, 10, 10 );
			//    _flag.BendingStiffness = 0.1f;
			//}
			//#endregion
			
			#region Revolute Joint
			{
				BoxShapeDescription boxShapeDescA = new BoxShapeDescription( 3, 3, 3 );
				BoxShapeDescription boxShapeDescB = new BoxShapeDescription( 3, 3, 3 );

				ActorDescription actorDescA = new ActorDescription()
				{
					BodyDescription = new BodyDescription( 10.0f ),
					GlobalPose = Matrix.Translation( 75, 1.5f, 55 ),
					Shapes = { boxShapeDescA }
				};
				Actor actorA = _scene.CreateActor( actorDescA );

				ActorDescription actorDescB = new ActorDescription()
				{
					BodyDescription = new BodyDescription( 10.0f ),
					GlobalPose = Matrix.Translation( 70, 1.5f, 55 ),
					Shapes = { boxShapeDescB }
				};
				Actor actorB = _scene.CreateActor( actorDescB );

				//

				RevoluteJointDescription revoluteJointDesc = new RevoluteJointDescription()
				{
					Actor1 = actorA,
					Actor2 = actorB,
					Motor = new MotorDescription( 20, 20.1f, true )
				};
				revoluteJointDesc.Flags |= RevoluteJointFlag.MotorEnabled;
				revoluteJointDesc.SetGlobalAnchor( new Vector3( 73.5f, 1.5f, 55 ) );
				revoluteJointDesc.SetGlobalAxis( new Vector3( 1, 0, 0 ) );

				RevoluteJoint revoluteJoint = _scene.CreateJoint( revoluteJointDesc ) as RevoluteJoint;
			}
			#endregion

			#region Prismatic Joint with Limit
			{
				Actor actorA, actorB;
				{
					BoxShapeDescription boxShapeDesc = new BoxShapeDescription( 3, 3, 3 );

					BodyDescription bodyDesc = new BodyDescription( 10.0f );
						bodyDesc.BodyFlags |= BodyFlag.Kinematic;

					ActorDescription actorDesc = new ActorDescription()
					{
						BodyDescription = bodyDesc,
						GlobalPose = Matrix.Translation( 70, 25, 65 ),
						Shapes = { boxShapeDesc }
					};
					actorA = _scene.CreateActor( actorDesc );
				}
				{
					BoxShapeDescription boxShapeDesc = new BoxShapeDescription( 3, 3, 3 );

					ActorDescription actorDesc = new ActorDescription()
					{
						BodyDescription = new BodyDescription( 10.0f ),
						GlobalPose = Matrix.Translation( 70, 15, 65 ),
						Shapes = { boxShapeDesc }
					};
					actorB = _scene.CreateActor( actorDesc );
				}

				PrismaticJointDescription prismaticJointDesc = new PrismaticJointDescription()
				{
					Actor1 = actorA,
					Actor2 = actorB,
				};
				prismaticJointDesc.SetGlobalAnchor( new Vector3( 70, 20, 65 ) );
				prismaticJointDesc.SetGlobalAxis( new Vector3( 0, 1, 0 ) );

				PrismaticJoint prismaticJoint = _scene.CreateJoint( prismaticJointDesc ) as PrismaticJoint;

				LimitPlane limitPlane = new LimitPlane( new Vector3( 0, 1, 0 ), new Vector3( -30, 8, -30 ), 0 );
					prismaticJoint.AddLimitPlane( limitPlane );
			}
			#endregion
			
			#region Fluid
			{
				const int maximumParticles = 1000;

				FluidEmitterDescription fluidEmitterDesc = new FluidEmitterDescription()
				{
					DimensionX = 0.5f,
					DimensionY = 0.5f,
					Rate = 15,
					RelativePose = Matrix.Translation( -40, 10, 50 ),
					Shape = EmitterShape.Rectangular,
					Type = EmitterType.ConstantFlowRate,
					RandomAngle = 0.5f
				};
				fluidEmitterDesc.Flags |= ( FluidEmitterFlag.Enabled | FluidEmitterFlag.Visualization );

				FluidDescription fluidDesc = new FluidDescription()
				{
					Emitters = { fluidEmitterDesc },
					Flags = FluidFlag.Enabled | FluidFlag.Visualization,
					MaximumParticles = maximumParticles
				};
				fluidDesc.ParticleWriteData.AllocatePositionBuffer<Vector3>( maximumParticles );
				fluidDesc.ParticleWriteData.NumberOfParticles = maximumParticles;

				Fluid fluid = _scene.CreateFluid( fluidDesc );

				// Ledge
				{
					BoxShapeDescription boxShapeDesc = new BoxShapeDescription( 5, 0.1f, 5 );
					
					ActorDescription drainActorDesc = new ActorDescription()
					{
						GlobalPose = Matrix.RotationX( 0.5f ) * Matrix.Translation( -40, 5, 52 ),
						Shapes =  { boxShapeDesc }
					};

					Actor drianActor = _scene.CreateActor( drainActorDesc );
				}

				// Drain
				{
					BoxShapeDescription boxShapeDesc = new BoxShapeDescription( 5, 0.1f, 5 );
						boxShapeDesc.Flags |= ShapeFlag.FluidDrain;

					ActorDescription drainActorDesc = new ActorDescription()
					{
						GlobalPose = Matrix.Translation( -40, 0, 55 ),
						Shapes = { boxShapeDesc }
					};

					Actor drianActor = _scene.CreateActor( drainActorDesc );
				}
			}
			#endregion
			
			#region Force Field
			{
				BoxForceFieldShapeDescription boxForceFieldShapeDesc = new BoxForceFieldShapeDescription()
				{
					Size = new Vector3( 10, 10, 10 )
				};

				ForceFieldLinearKernelDescription kernelDesc = new ForceFieldLinearKernelDescription()
				{
					Constant = new Vector3( 0, 100.0f, 0 )
				};

				ForceFieldLinearKernel kernel = _scene.CreateForceFieldLinearKernel( kernelDesc );

				ForceFieldShapeGroupDescription shapeGroupDesc = new ForceFieldShapeGroupDescription()
				{
					Shapes = { boxForceFieldShapeDesc }
				};

				ForceFieldShapeGroup shapeGroup = _scene.CreateForceFieldShapeGroup( shapeGroupDesc );

				BoxForceFieldShape boxForceFieldShape = shapeGroup.CreateShape( boxForceFieldShapeDesc ) as BoxForceFieldShape;
				boxForceFieldShape.Pose = Matrix.Translation( 30, 5, 0 );

				ForceFieldDescription forceFieldDesc = new ForceFieldDescription()
				{
					Kernel = kernel,
					ShapeGroups = { shapeGroup }
				};
				ForceField forceField = _scene.CreateForceField( forceFieldDesc );
			}
			#endregion
			
			#region Heightfield
			{
				int rows = 25;
				int columns = 25;

				HeightFieldSample[] samples = new HeightFieldSample[ rows * columns ];
				for( int r = 0; r < rows; r++ )
				{
					for( int c = 0; c < columns; c++ )
					{
						// Put a z and x curve together
						double h = Math.Sin( c ) * Math.Cos( r ) * short.MaxValue;

						HeightFieldSample sample = new HeightFieldSample()
						{
							Height = (short)h,
							MaterialIndex0 = 0,
							MaterialIndex1 = 1,
							TessellationFlag = 0
						};

						samples[ r * columns + c ] = sample;
					}
				}

				HeightFieldDescription heightFieldDesc = new HeightFieldDescription()
				{
					NumberOfRows = rows,
					NumberOfColumns = columns
				};
				heightFieldDesc.SetSamples( samples );

				HeightField heightField = _core.CreateHeightField( heightFieldDesc );
				
				//

				HeightFieldShapeDescription heightFieldShapeDesc = new HeightFieldShapeDescription()
				{
					HeightField = heightField,
					HoleMaterial = 2,
					// The max height of our samples is short.MaxValue and we want it to be 1
					HeightScale = 1.0f / (float)short.MaxValue,
					RowScale = 3,
					ColumnScale = 3
				};
				heightFieldShapeDesc.LocalPosition = new Vector3( -0.5f * rows * 1 * heightFieldShapeDesc.RowScale, 0, -0.5f * columns * 1 * heightFieldShapeDesc.ColumnScale );

				ActorDescription actorDesc = new ActorDescription()
				{
					GlobalPose = Matrix.Translation( 100, 0, 0 ),
					Shapes = { heightFieldShapeDesc }
				};
				Actor actor = _scene.CreateActor( actorDesc );
			}
			#endregion
			
			//#region Convex Mesh
			//{
			//    ModelMesh mesh = _torusModel.Meshes.First();

			//    Matrix[] transforms = new Matrix[ _torusModel.Bones.Count ];
			//    _torusModel.CopyAbsoluteBoneTransformsTo( transforms );

			//    // Gets the vertices from the mesh
			//    VertexPositionNormalTexture[] vertices = new VertexPositionNormalTexture[ mesh.MeshParts[ 0 ].NumVertices ];
			//    mesh.VertexBuffer.GetData<VertexPositionNormalTexture>( vertices );

			//    //

			//    // Allocate memory for the points and triangles
			//    var convexMeshDesc = new ConvexMeshDescription()
			//    {
			//        PointCount = vertices.Length
			//    };
			//    convexMeshDesc.Flags |= ConvexFlag.ComputeConvex;
			//    convexMeshDesc.AllocatePoints<Vector3>( vertices.Length );

			//    // Write in the points and triangles
			//    // We only want the Position component of the vertex. Also scale down the mesh
			//    foreach( VertexPositionNormalTexture vertex in vertices )
			//    {
			//        Vector3 position = Vector3.Transform( vertex.Position, Matrix.CreateScale( 0.1f, 0.1f, 0.1f ) * transforms[ 0 ] );

			//        convexMeshDesc.PointsStream.Write( position );
			//    }

			//    //

			//    // Cook to memory or to a file
			//    MemoryStream stream = new MemoryStream();
			//    //FileStream stream = new FileStream( @"Convex Mesh.cooked", FileMode.CreateNew );

			//    Cooking.InitializeCooking( new ConsoleOutputStream() );
			//    Cooking.CookConvexMesh( convexMeshDesc, stream );
			//    Cooking.CloseCooking();

			//    stream.Position = 0;

			//    ConvexMesh convexMesh = _core.CreateConvexMesh( stream );

			//    ConvexShapeDescription convexShapeDesc = new ConvexShapeDescription( convexMesh );

			//    ActorDescription actorDesc = new ActorDescription()
			//    {
			//        BodyDescription = new BodyDescription( 10.0f ),
			//        GlobalPose = Matrix.CreateTranslation( 30, 30, 0 )
			//    };
			//    actorDesc.Shapes.Add( convexShapeDesc );

			//    _torusActor = _scene.CreateActor( actorDesc );
			//}
			//#endregion
			
			//#region SoftBody
			//if( false ) // Enable to view soft bodies, they run slowly
			//{
			//    XmlDocument doc = new XmlDocument();
			//        doc.Load( "Teapot.xml" );
				
			//    // Not how NxuStream are meant to used but what ever :S
			//    Vector3[] vertices = ReadVertices( doc.SelectSingleNode( "/NXUSTREAM2/NxuPhysicsCollection/NxSoftBodyMeshDesc/vertices" ) );
			//    int[] tetrahedraSingles = ReadTetrahedra( doc.SelectSingleNode( "/NXUSTREAM2/NxuPhysicsCollection/NxSoftBodyMeshDesc/tetrahedra" ) );

			//    var softBodyMeshDesc = new SoftBodyMeshDescription()
			//    {
			//        VertexCount = vertices.Length,
			//        TetrahedraCount = tetrahedraSingles.Length / 4 // Tetrahedras come in quadruples of ints
			//    };

			//    softBodyMeshDesc.AllocateVertices<Vector3>( softBodyMeshDesc.VertexCount );
			//    softBodyMeshDesc.AllocateTetrahedra<int>( softBodyMeshDesc.TetrahedraCount ); // Note: T is an int. T is the type of each point

			//    softBodyMeshDesc.VertexStream.SetData( vertices );
			//    softBodyMeshDesc.TetrahedraStream.SetData( tetrahedraSingles );

			//    MemoryStream memoryStream = new MemoryStream();

			//    Cooking.InitializeCooking();
			//    Cooking.CookSoftBodyMesh( softBodyMeshDesc, memoryStream );
			//    Cooking.CloseCooking();

			//    memoryStream.Position = 0;

			//    SoftBodyMesh softBodyMesh = _core.CreateSoftBodyMesh( memoryStream );

			//    SoftBodyDescription desc = new SoftBodyDescription()
			//    {
			//        GlobalPose = Matrix.CreateTranslation( -30, 20, -30 ),
			//        SoftBodyMesh = softBodyMesh
			//    };
			//    desc.Flags |= SoftBodyFlag.Visualization;

			//    desc.MeshData.AllocatePositions<Vector3>( vertices.Length );
			//    desc.MeshData.AllocateIndices<int>( tetrahedraSingles.Length );

			//    SoftBody softBody = _scene.CreateSoftBody( desc );
			//}
			//#endregion

			//#region Reports
			//// Contact report
			//// When the capsule actor hits the ground make it bounce by using the conact report
			//{
			//    CapsuleShapeDescription capsuleShapeDesc = new CapsuleShapeDescription( 1, 5 );
				
			//    ActorDescription actorDesc = new ActorDescription()
			//    {
			//        GlobalPose = Matrix.CreateTranslation( -30, 20, 0 ),
			//        BodyDescription = new BodyDescription( 10.0f ),
			//        Name = "Report Capsule",
			//        Shapes = { capsuleShapeDesc }
			//    };

			//    _contactReportActor = _scene.CreateActor( actorDesc );

			//    _scene.SetActorPairFlags( _contactReportActor, _groundActor, ContactPairFlag.All );

			//    _scene.UserContactReport = new ContactReport( this );
			//}

			//// Trigger Reports
			//{
			//    BoxShapeDescription boxShapeDesc = new BoxShapeDescription( 15, 8, 15 );
			//        boxShapeDesc.Flags |= ( ShapeFlag.TriggerOnEnter | ShapeFlag.TriggerOnLeave );

			//    ActorDescription actorDesc = new ActorDescription()
			//    {
			//        GlobalPose = Matrix.CreateTranslation( -30, 4, 0 ),
			//        Shapes = { boxShapeDesc }
			//    };
			//    _scene.CreateActor( actorDesc );

			//    _scene.UserTriggerReport = new TriggerReport( this );
			//}

			//_scene.UserNotify = new Notify( this );
			//#endregion

			//#region Wheel
			//{
			//    _basicVehicle = new Vehicle( this );
			//}
			//#endregion

			#region Controller
			{
				ControllerManager manager = _scene.CreateControllerManager();

				CapsuleControllerDescription capsuleControllerDesc = new CapsuleControllerDescription( 4, 3 );

				CapsuleController capsuleController = manager.CreateController<CapsuleController>( capsuleControllerDesc );
					capsuleController.Position = new Vector3( 0, 1.5f + 2, -15 );
					capsuleController.Actor.Name = "BoxController";
					capsuleController.SetCollisionEnabled( true );
			}
			#endregion
		}
        protected override void LoadContent(GraphicInfo GraphicInfo, GraphicFactory factory ,IContentManager contentManager)
        {
            PhysxPhysicWorld PhysxPhysicWorld = World.PhysicWorld as PhysxPhysicWorld;
            
            base.LoadContent(GraphicInfo, factory, contentManager);

            const int maximumParticles = 1000;
            var fluidEmitterDesc = new FluidEmitterDescription()
            {
                DimensionX = 0.5f,
                DimensionY = 0.5f,
                Rate = 15,
                RelativePose =
                    Phyx.Matrix.RotationAxis(new Phyx.Vector3(0, 1, 0), (float)Math.PI) *
                    Phyx.Matrix.Translation(-40, 10, -50),
                Shape = EmitterShape.Rectangular,
                Type = EmitterType.ConstantFlowRate,
                RandomAngle = 0.5f
            };
            fluidEmitterDesc.Flags |= (FluidEmitterFlag.Enabled | FluidEmitterFlag.Visualization);

            var fluidDesc = new FluidDescription()
            {
                Emitters = { fluidEmitterDesc },
                Flags = FluidFlag.Enabled | FluidFlag.Visualization | FluidFlag.Enabled,
                MaximumParticles = maximumParticles,
                
            };
            fluidDesc.ParticleWriteData.AllocatePositionBuffer<Vector3>(maximumParticles);
            fluidDesc.ParticleWriteData.NumberOfParticles = maximumParticles;
            
            fluid = PhysxPhysicWorld.Scene.CreateFluid(fluidDesc);

                       
            Texture2D tex = factory.GetTexture2D("Textures/Smoke");
            for (int i = 0; i < maximumParticles; i++)
            {
                Billboard3D Billboard3D = new Billboard3D(tex,Vector3.Zero,new Vector2(0.002f));
                Billboard3D.Enabled = false;
                CPUSphericalBillboardComponent.Billboards.Add(Billboard3D);
            }


            // Ledge
            {
                var boxShapeDesc = new BoxShapeDescription(5, 0.1f, 5);
                SimpleModel SimpleModel = new PloobsEngine.Modelo.SimpleModel(factory, "Model/block");
                SimpleModel.SetTexture(factory.CreateTexture2DColor(1, 1, Color.Red), TextureType.DIFFUSE);
                PhysxPhysicObject PhysxPhysicObject = new PloobsEngine.Physics.PhysxPhysicObject(boxShapeDesc,
                    (Phyx.Matrix.RotationX(-0.5f) * Phyx.Matrix.Translation(-40, 5, -52)).AsXNA(),new Vector3(5,0.1f,5));
                ForwardXNABasicShader shader = new ForwardXNABasicShader(ForwardXNABasicShaderDescription.Default());
                ForwardMaterial fmaterial = new ForwardMaterial(shader);
                IObject obj = new IObject(fmaterial, SimpleModel, PhysxPhysicObject);
                this.World.AddObject(obj);
            }

            // Drain
            {
                var boxShapeDesc = new BoxShapeDescription(5, 0.1f, 5);
                boxShapeDesc.Flags |= ShapeFlag.FluidDrain;

                var drainActorDesc = new ActorDescription()
                {
                    GlobalPose = Phyx.Matrix.Translation(-40, 0, -55),
                    Shapes = { boxShapeDesc }
                };

                var drianActor = PhysxPhysicWorld.Scene.CreateActor(drainActorDesc);
            }            

            BallThrowPhysx28 BallThrowBullet = new BallThrowPhysx28(this.World, GraphicFactory);
            this.AttachCleanUpAble(BallThrowBullet);

            this.World.CameraManager.AddCamera(new CameraFirstPerson(GraphicInfo));
        }
        protected override void LoadContent(GraphicInfo GraphicInfo, GraphicFactory factory ,IContentManager contentManager)
        {
            PhysxPhysicWorld PhysxPhysicWorld = World.PhysicWorld as PhysxPhysicWorld;
            
            base.LoadContent(GraphicInfo, factory, contentManager);

            const int maximumParticles = 1000;
            var fluidEmitterDesc = new FluidEmitterDescription()
            {
                DimensionX = 0.5f,
                DimensionY = 0.5f,
                Rate = 15,
                RelativePose =
                    Phyx.Matrix.RotationAxis(new Phyx.Vector3(0, 1, 0), (float)Math.PI) *
                    Phyx.Matrix.Translation(-40, 10, -50),
                Shape = EmitterShape.Rectangular,
                Type = EmitterType.ConstantFlowRate,
                RandomAngle = 0.5f
            };
            fluidEmitterDesc.Flags |= (FluidEmitterFlag.Enabled | FluidEmitterFlag.Visualization);

            var fluidDesc = new FluidDescription()
            {
                Emitters = { fluidEmitterDesc },
                Flags = FluidFlag.Enabled | FluidFlag.Visualization | FluidFlag.Enabled,
                MaximumParticles = maximumParticles,
                
            };
            fluidDesc.ParticleWriteData.AllocatePositionBuffer<Vector3>(maximumParticles);
            fluidDesc.ParticleWriteData.NumberOfParticles = maximumParticles;

            InstancedBilboardModel InstancedBilboardModel = new InstancedBilboardModel(factory, "teste", "Textures/Smoke", new BilboardInstance[] {new BilboardInstance() }, maximumParticles);
            PhysxFluidObject PhysxFluidObject = new PloobsEngine.Physics.PhysxFluidObject(fluidDesc);
            DeferredInstancedBilboardShader DeferredInstancedBilboardShader = new PloobsEngine.Material.DeferredInstancedBilboardShader(BilboardType.Spherical);
            DeferredInstancedBilboardShader.AlphaTestLimit = 0.2f;
            FluidMaterial DeferredMaterial = new FluidMaterial(DeferredInstancedBilboardShader,maximumParticles,new Vector2(0.2f));
            IObject IObject = new IObject(DeferredMaterial, InstancedBilboardModel, PhysxFluidObject);
            this.World.AddObject(IObject);


            // Ledge
            {
                var boxShapeDesc = new BoxShapeDescription(5, 0.1f, 5);
                SimpleModel SimpleModel = new PloobsEngine.Modelo.SimpleModel(factory, "Model/block");
                SimpleModel.SetTexture(factory.CreateTexture2DColor(1, 1, Color.Red), TextureType.DIFFUSE);

                PhysxPhysicObject PhysxPhysicObject = new PloobsEngine.Physics.PhysxPhysicObject(boxShapeDesc,
                    (Phyx.Matrix.RotationX(-0.5f) * Phyx.Matrix.Translation(-40, 5, -52)).AsXNA(),new Vector3(5,0.1f,5));
                DeferredNormalShader shader = new DeferredNormalShader();
                DeferredMaterial fmaterial = new DeferredMaterial(shader);
                IObject obj = new IObject(fmaterial, SimpleModel, PhysxPhysicObject);
                this.World.AddObject(obj);
            }

            // Drain
            {
                var boxShapeDesc = new BoxShapeDescription(5, 0.1f, 5);
                boxShapeDesc.Flags |= ShapeFlag.FluidDrain;

                var drainActorDesc = new ActorDescription()
                {
                    GlobalPose = Phyx.Matrix.Translation(-40, 0, -55),
                    Shapes = { boxShapeDesc }
                };

                var drianActor = PhysxPhysicWorld.Scene.CreateActor(drainActorDesc);
            }

            #region NormalLight
            DirectionalLightPE ld1 = new DirectionalLightPE(Vector3.Left, Color.White);
            DirectionalLightPE ld2 = new DirectionalLightPE(Vector3.Right, Color.White);
            DirectionalLightPE ld3 = new DirectionalLightPE(Vector3.Backward, Color.White);
            DirectionalLightPE ld4 = new DirectionalLightPE(Vector3.Forward, Color.White);
            DirectionalLightPE ld5 = new DirectionalLightPE(Vector3.Down, Color.White);
            float li = 0.5f;
            ld1.LightIntensity = li;
            ld2.LightIntensity = li;
            ld3.LightIntensity = li;
            ld4.LightIntensity = li;
            ld5.LightIntensity = li;
            this.World.AddLight(ld1);
            this.World.AddLight(ld2);
            this.World.AddLight(ld3);
            this.World.AddLight(ld4);
            this.World.AddLight(ld5);
            #endregion


            BallThrowPhysx28 BallThrowBullet = new BallThrowPhysx28(this.World, GraphicFactory,false);
            this.AttachCleanUpAble(BallThrowBullet);

            this.World.CameraManager.AddCamera(new CameraFirstPerson(GraphicInfo));
        }
예제 #60
0
		protected override void LoadPhysics(Scene scene)
		{
			CCDSkeleton ccdSkeletonForBox;

			// Create a CCD Skeleton
			{
				Vector3 size = new Vector3(5, 5, 5);

				int[] indices =
				{
					0, 1, 3,
					0, 3, 2,
					3, 7, 6,
					3, 6, 2,
					1, 5, 7,
					1, 7, 3,
					4, 6, 7,
					4, 7, 5,
					1, 0, 4,
					5, 1, 4,
					4, 0, 2,
					4, 2, 6
				};

				Vector3[] vertices =
				{
					new Vector3( size.X, -size.Y, -size.Z ),
					new Vector3( size.X, -size.Y, size.Z ),
					new Vector3( size.X, size.Y, -size.Z ),
					new Vector3( size.X,  size.Y,  size.Z ),
					new Vector3( -size.X, -size.Y, -size.Z ),
					new Vector3( -size.X, -size.Y, size.Z ),
					new Vector3( -size.X,  size.Y, -size.Z ),
					new Vector3( -size.X,  size.Y,  size.Z )
				};

				TriangleMeshDescription triangleMeshDesc = new TriangleMeshDescription();
				triangleMeshDesc.AllocateVertices<Vector3>(vertices.Length);
				triangleMeshDesc.AllocateTriangles<int>(indices.Length);

				triangleMeshDesc.VerticesStream.SetData(vertices);
				triangleMeshDesc.TriangleStream.SetData(indices);

				triangleMeshDesc.VertexCount = vertices.Length;
				triangleMeshDesc.TriangleCount = indices.Length / 3;

				ccdSkeletonForBox = scene.Core.CreateCCDSkeleton(triangleMeshDesc);

				// Enable CCD and CCD Visualization
				scene.Core.SetParameter(PhysicsParameter.ContinuousCollisionDetection, true);
				scene.Core.SetParameter(PhysicsParameter.VisualizeContinuousCollisionDetectionTests, true);
			}

			// Create a large 2 polygon triangle mesh plane
			// For CCD to work/be used many conditions must be met (check the docs for full list)
			// One of those conditions is that one of the objects must be a triangle mesh or a convex mesh (for static-dynamic)
			{
				Vector3[] vertices = 
				{
					new Vector3( -100, 5, -100 ),
					new Vector3( -100, 5, 100 ),
					new Vector3( 100, 5, -100 ),
					new Vector3( 100, 5, 100 ),
				};

				int[] indices =
				{
					0, 1, 2,
					1, 3, 2
				};

				TriangleMeshDescription triangleMeshDesc = new TriangleMeshDescription();
				triangleMeshDesc.TriangleCount = indices.Length / 3;
				triangleMeshDesc.VertexCount = vertices.Length;

				triangleMeshDesc.AllocateTriangles<int>(triangleMeshDesc.TriangleCount);
				triangleMeshDesc.AllocateVertices<Vector3>(triangleMeshDesc.VertexCount);

				triangleMeshDesc.TriangleStream.SetData(indices);
				triangleMeshDesc.VerticesStream.SetData(vertices);

				TriangleMesh triangleMesh;
				using (MemoryStream s = new MemoryStream())
				{
					Cooking.InitializeCooking();
					Cooking.CookTriangleMesh(triangleMeshDesc, s);
					Cooking.CloseCooking();

					s.Position = 0;
					triangleMesh = scene.Core.CreateTriangleMesh(s);
				}

				TriangleMeshShapeDescription triangleMeshShapeDesc = new TriangleMeshShapeDescription()
				{
					TriangleMesh = triangleMesh,
					Flags = ShapeFlag.Visualization
				};

				ActorDescription actorDesc = new ActorDescription()
				{
					Shapes = { triangleMeshShapeDesc }
				};

				Actor actor = scene.CreateActor(actorDesc);
			}

			// Make 20 boxes fall down
			for (int x = 0; x < 20; x++)
			{
				BoxShapeDescription boxShapeDesc = new BoxShapeDescription(2, 3, 8);
				// Assign the CCD Skeleton to the shape
				boxShapeDesc.CCDSkeleton = ccdSkeletonForBox;

				ActorDescription actorDesc = new ActorDescription()
				{
					Name = String.Format("Box {0}", x),
					BodyDescription = new BodyDescription(10.0f),
					GlobalPose = Matrix.Translation(0, 15 + 3 * x, 0),
					Shapes = { boxShapeDesc }
				};

				Actor actor = scene.CreateActor(actorDesc);
			}
		}