コード例 #1
0
ファイル: Form1.cs プロジェクト: sandygk/System.Physics
        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!");
                    }
        }
コード例 #2
0
 public Ph.Joint AddJointActors(Ph.Actor A1, Ph.Actor A2, PhMath.Vector3 An1, PhMath.Vector3 An2)
 {
     Ph.FixedJointDescription desc = new Ph.FixedJointDescription();
     desc.Actor1       = A1;
     desc.Actor2       = A2;
     desc.LocalAnchor1 = An1;
     desc.LocalAnchor2 = An2;
     desc.JointFlags   = Ph.JointFlag.CollisionEnabled;
     desc.MaxForce     = 100f;
     return(Scene.CreateJoint(desc));
 }
コード例 #3
0
 public Ph.Actor AddBall(float radius, float mass, PhMath.Vector3 InitialPosition)
 {
     Ph.SphereShapeDescription BallDesc = new Ph.SphereShapeDescription();
     BallDesc.Mass   = mass;
     BallDesc.Radius = radius;
     Ph.ActorDescription ActorDec = new Ph.ActorDescription();
     ActorDec.Shapes.Add(BallDesc);
     ActorDec.BodyDescription = new Ph.BodyDescription(mass);
     ActorDec.GlobalPose      = PhMath.Matrix.Translation(InitialPosition);
     return(Scene.CreateActor(ActorDec));
 }
コード例 #4
0
        //dodano
        // bool @static = false
        // ActorDesc.BodyDescription = @static ? null : new Ph.BodyDescription(mass);   - ActorDesc.BodyDescription = new Ph.BodyDescription(mass);
        public Ph.Actor AddBox(float sizex, float sizey, float sizez, float mass, PhMath.Vector3 InitialPosition, bool @static = false)
        {
            Ph.BoxShapeDescription BoxDesc = new Ph.BoxShapeDescription();
            BoxDesc.Dimensions = new PhMath.Vector3(sizex, sizey, sizez);
            BoxDesc.Mass       = mass;

            Ph.ActorDescription ActorDesc = new Ph.ActorDescription();
            ActorDesc.Shapes.Add(BoxDesc);
            ActorDesc.BodyDescription = @static ? null : new Ph.BodyDescription(mass);
            ActorDesc.GlobalPose      = PhMath.Matrix.Translation(InitialPosition);
            return(Scene.CreateActor(ActorDesc));
        }
コード例 #5
0
        public Ph.Cloth AddCloth(WavefrontLoader.WFOGeometry G, PhMath.Vector3 InitialPosition)
        {
            Ph.ClothMeshDescription clothMeshDesc = new Ph.ClothMeshDescription();
            clothMeshDesc.AllocateVertices <WavefrontLoader.WFOVertex>(G.VertexCount);
            clothMeshDesc.AllocateTriangles <int>(G.IndexCount);

            clothMeshDesc.VertexCount   = G.VertexCount;
            clothMeshDesc.TriangleCount = G.IndexCount / 3;

            clothMeshDesc.VerticesStream.SetData(G.Vertices);
            clothMeshDesc.TriangleStream.SetData(G.Indices);

            clothMeshDesc.Flags &= ~Ph.MeshFlag.Indices16Bit;

            MemoryStream M = new MemoryStream();

            Ph.Cooking.InitializeCooking();
            Ph.Cooking.CookClothMesh(clothMeshDesc, M);
            Ph.Cooking.CloseCooking();
            M.Position = 0;

            Ph.ClothMesh CM = Core.CreateClothMesh(M);

            Ph.ClothDescription ClothDesc = new Ph.ClothDescription();
            ClothDesc.ClothMesh = CM;
            ClothDesc.Pressure  = 4f;
            ClothDesc.SelfCollisionThickness = 3.0f;
            ClothDesc.Friction            = 0.5f;
            ClothDesc.SleepLinearVelocity = 0.1f;
            ClothDesc.Thickness           = 1f;
            ClothDesc.Flags      = Ph.ClothFlag.Gravity | Ph.ClothFlag.Damping | Ph.ClothFlag.CollisionTwoway | Ph.ClothFlag.Pressure | Ph.ClothFlag.Bending;
            ClothDesc.GlobalPose = PhMath.Matrix.Translation(InitialPosition);
            ClothDesc.MeshData.AllocatePositions <WavefrontLoader.WFOVertex>(G.VertexCount);
            ClothDesc.MeshData.AllocateIndices <int>(G.IndexCount);
            ClothDesc.MeshData.AllocateNormals <SlimDX.Vector3>(G.VertexCount);
            ClothDesc.Thickness = 0.1f;
            ClothDesc.Density   = 0.1f;
            ClothDesc.MeshData.MaximumVertices = G.VertexCount;
            ClothDesc.MeshData.MaximumIndices  = G.IndexCount;

            ClothDesc.MeshData.NumberOfVertices = G.VertexCount;
            ClothDesc.MeshData.NumberOfIndices  = G.IndexCount;

            // if (ClothDesc.CheckValid() == 0) return null;
            return(Scene.CreateCloth(ClothDesc));
        }
コード例 #6
0
ファイル: Form1.cs プロジェクト: fasteng/System.Physics
        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!");
                        }
                    }
                }
            }
        }
コード例 #7
0
        protected override void LoadContent(GraphicInfo GraphicInfo, GraphicFactory factory, IContentManager contentManager)
        {
            PhysxPhysicWorld PhysxPhysicWorld = World.PhysicWorld as PhysxPhysicWorld;

            base.LoadContent(GraphicInfo, factory, contentManager);

            // Create a simple fluid description with fluids and visualization enabled
            FluidDescription fluidDesc = new FluidDescription()
            {
                Flags = FluidFlag.Enabled | FluidFlag.Visualization,
            };

            // Store our particle positions somewhere (as our particle generation function below generates and unknown number of particles at runtime we need a list instead of an array)
            var particlePositions = new List <Phyx.Vector3>();

            // Move all the particles by this offset
            Phyx.Vector3 position = new Phyx.Vector3(0, 20, 0);

            // Number of particles in the x, y and z directions
            int   sideNum  = 10;
            float distance = 1f;

            float radius = sideNum * distance * 0.5f;

            for (int i = 0; i < sideNum; i++)
            {
                for (int j = 0; j < sideNum; j++)
                {
                    for (int k = 0; k < sideNum; k++)
                    {
                        Phyx.Vector3 p = new Phyx.Vector3(i * distance, j * distance, k * distance);

                        if ((p - new Phyx.Vector3(radius, radius, radius)).Length() < radius)
                        {
                            p += position - new Phyx.Vector3(radius, radius, radius);

                            particlePositions.Add(p);
                        }
                    }
                }
            }

            // Allocate memory for the initial particle positions to be stored in
            // And then set the position buffer
            fluidDesc.InitialParticleData.AllocatePositionBuffer <Phyx.Vector3>(particlePositions.Count);
            fluidDesc.InitialParticleData.NumberOfParticles = particlePositions.Count;
            fluidDesc.InitialParticleData.PositionBuffer.SetData(particlePositions.ToArray());

            // Allocate memory for PhysX to store the position of each particle
            fluidDesc.ParticleWriteData.AllocatePositionBuffer <Phyx.Vector3>(particlePositions.Count);
            fluidDesc.ParticleWriteData.NumberOfParticles = particlePositions.Count;

            InstancedBilboardModel          InstancedBilboardModel          = new InstancedBilboardModel(factory, "teste", "Textures/Smoke", new BilboardInstance[] { new BilboardInstance() }, particlePositions.Count);
            PhysxFluidObject                PhysxFluidObject                = new PloobsEngine.Physics.PhysxFluidObject(fluidDesc);
            DeferredInstancedBilboardShader DeferredInstancedBilboardShader = new PloobsEngine.Material.DeferredInstancedBilboardShader(BilboardType.Spherical);

            DeferredInstancedBilboardShader.AlphaTestLimit = 0.2f;
            FluidMaterial DeferredMaterial = new FluidMaterial(DeferredInstancedBilboardShader, particlePositions.Count, new Vector2(0.2f));
            IObject       IObject          = new IObject(DeferredMaterial, InstancedBilboardModel, PhysxFluidObject);

            this.World.AddObject(IObject);


            // Ledge
            {
                var         boxShapeDesc = new BoxShapeDescription(10, 0.2f, 10);
                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.RotationZ(0.3f) *
                                                                                                  Phyx.Matrix.Translation(0, 5, 0)).AsXNA(), new Vector3(10, 0.2f, 10));
                DeferredNormalShader shader    = new DeferredNormalShader();
                DeferredMaterial     fmaterial = new DeferredMaterial(shader);
                IObject obj = new IObject(fmaterial, SimpleModel, PhysxPhysicObject);
                this.World.AddObject(obj);
            }

            #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));
        }
コード例 #8
0
ファイル: Conversion.cs プロジェクト: fasteng/System.Physics
 public static Vector3 ToStandard(this NXMath.Vector3 vector3)
 {
     return(new Vector3(vector3.X, vector3.Y, vector3.Z));
 }
コード例 #9
0
        protected override void LoadContent(GraphicInfo GraphicInfo, GraphicFactory factory ,IContentManager contentManager)
        {
            PhysxPhysicWorld PhysxPhysicWorld = World.PhysicWorld as PhysxPhysicWorld;            
            base.LoadContent(GraphicInfo, factory, contentManager);

            // Create a simple fluid description with fluids and visualization enabled
            FluidDescription fluidDesc = new FluidDescription()
            {
                Flags = FluidFlag.Enabled | FluidFlag.Visualization,
            };

            // Store our particle positions somewhere (as our particle generation function below generates and unknown number of particles at runtime we need a list instead of an array)
            var particlePositions = new List<Phyx.Vector3>();

            // Move all the particles by this offset
            Phyx.Vector3 position = new Phyx.Vector3(0, 20, 0);

            // Number of particles in the x, y and z directions
            int sideNum = 10;
            float distance = 1f;

            float radius = sideNum * distance * 0.5f;

            for (int i = 0; i < sideNum; i++)
            {
                for (int j = 0; j < sideNum; j++)
                {
                    for (int k = 0; k < sideNum; k++)
                    {
                        Phyx.Vector3 p = new Phyx.Vector3(i * distance, j * distance, k * distance);

                        if ((p - new Phyx.Vector3(radius, radius, radius)).Length() < radius)
                        {
                            p += position - new Phyx.Vector3(radius, radius, radius);

                            particlePositions.Add(p);
                        }
                    }
                }
            }

            // Allocate memory for the initial particle positions to be stored in
            // And then set the position buffer
            fluidDesc.InitialParticleData.AllocatePositionBuffer<Phyx.Vector3>(particlePositions.Count);
            fluidDesc.InitialParticleData.NumberOfParticles = particlePositions.Count;
            fluidDesc.InitialParticleData.PositionBuffer.SetData(particlePositions.ToArray());

            // Allocate memory for PhysX to store the position of each particle
            fluidDesc.ParticleWriteData.AllocatePositionBuffer<Phyx.Vector3>(particlePositions.Count);
            fluidDesc.ParticleWriteData.NumberOfParticles = particlePositions.Count;

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


            // Ledge
            {
                var boxShapeDesc = new BoxShapeDescription(10, 0.2f, 10);
                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.RotationZ(0.3f) *
                        Phyx.Matrix.Translation(0, 5, 0)).AsXNA(), new Vector3(10, 0.2f, 10));
                DeferredNormalShader shader = new DeferredNormalShader();
                DeferredMaterial fmaterial = new DeferredMaterial(shader);
                IObject obj = new IObject(fmaterial, SimpleModel, PhysxPhysicObject);
                this.World.AddObject(obj);                        
            }

            #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));
        }