コード例 #1
0
        /// <summary>
        /// Create a simple Sphere object
        /// </summary>
        /// <param name="pos"></param>
        /// <param name="ori"></param>
        /// <returns></returns>
        private IObject SpawnPrimitive(Vector3 pos, Matrix ori)
        {
            ///Load a Model with a custom texture
            sm2 = new SimpleModel(factory,"Model\\ball");
            sm2.SetTexture(factory.CreateTexture2DColor(1,1,Color.White,false), TextureType.DIFFUSE);
            IMaterial m;
            if (forward)
            {
                ForwardXNABasicShader nd = new ForwardXNABasicShader();
                m = new ForwardMaterial(nd);
            }
            else
            {
                DeferredNormalShader nd = new DeferredNormalShader();
                m = new DeferredMaterial(nd);
            }

            PhysxPhysicWorld PhysxPhysicWorld = _mundo.PhysicWorld as PhysxPhysicWorld;

            ///First we create a shape description
            SphereShapeDescription SphereGeometry = new SphereShapeDescription(ballSize);
            ///then we create the physic object
            PhysxPhysicObject PhysxPhysicObject = new PhysxPhysicObject(SphereGeometry,
                0.5f, Matrix.CreateTranslation(pos), Vector3.One * ballSize);
            
            IObject o = new IObject(m, sm2, PhysxPhysicObject);
            return o;
        }
コード例 #2
0
        protected override void LoadContent(GraphicInfo GraphicInfo, GraphicFactory factory ,IContentManager contentManager)
        {
            PhysxPhysicWorld PhysxPhysicWorld = World.PhysicWorld as PhysxPhysicWorld;

            base.LoadContent(GraphicInfo, factory, contentManager);
            {
                SimpleModel simpleModel = new SimpleModel(factory, "Model//cenario");

                StillDesign.PhysX.Material material1 = PhysxPhysicWorld.CreatePhysicMaterial(
                    new StillDesign.PhysX.MaterialDescription()
                    {
                        Restitution = 0.3f,
                        DynamicFriction = 0.5f,
                        StaticFriction = 1,
                    }
                    );
                PhysxTriangleMesh tmesh = new PhysxTriangleMesh(PhysxPhysicWorld, simpleModel,
                    Matrix.Identity, Vector3.One, 1, material1);

                ForwardXNABasicShader shader = new ForwardXNABasicShader(ForwardXNABasicShaderDescription.Default());
                ForwardMaterial fmaterial = new ForwardMaterial(shader);
                IObject obj = new IObject(fmaterial, simpleModel, tmesh);
                this.World.AddObject(obj);
            }

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

            for (int i = 0; i < 10; i++)
            {

                StillDesign.PhysX.Material material2 = PhysxPhysicWorld.CreatePhysicMaterial(
                        new StillDesign.PhysX.MaterialDescription()
                        {
                            Restitution = PloobsEngine.Utils.StaticRandom.RandomBetween(0,1),
                            DynamicFriction = PloobsEngine.Utils.StaticRandom.RandomBetween(0, 1),
                            StaticFriction = PloobsEngine.Utils.StaticRandom.RandomBetween(0, 1),                            
                            RestitutionCombineMode = CombineMode.Max,
                        }
                        );

                ///Load a Model with a custom texture
                SimpleModel sm2 = new SimpleModel(factory, "Model\\ball");
                sm2.SetTexture(factory.CreateTexture2DColor(1, 1, Color.Green, false), TextureType.DIFFUSE);
                
                ForwardXNABasicShader nd = new ForwardXNABasicShader();
                IMaterial m = new ForwardMaterial(nd);
                
                SphereShapeDescription SphereGeometry = new SphereShapeDescription(5f);
                SphereGeometry.Material = material2;

                PhysxPhysicObject PhysxPhysicObject = new PhysxPhysicObject(SphereGeometry,
                    0.5f, Matrix.CreateTranslation(new Vector3(100,100,50 * i)), Vector3.One * 5f);

                IObject o = new IObject(m, sm2, PhysxPhysicObject);
                this.World.AddObject(o);
            }
            this.World.CameraManager.AddCamera(new CameraFirstPerson(GraphicInfo));
        }
コード例 #3
0
        public override void AddObject(IPhysicObject obj)
        {
            if (obj is PhysxPhysicObject)
            {
                PhysxPhysicObject PhysxPhysicObject = obj as PhysxPhysicObject;
                if (PhysxPhysicObject.Actor == null)
                {
                    PhysxPhysicObject.Actor          = Scene.CreateActor(PhysxPhysicObject.ActorDesc, int.MaxValue);
                    PhysxPhysicObject.Actor.UserData = obj;

                    for (int i = 0; i < PhysxPhysicObject.ActorDesc.Shapes.Count; i++)
                    {
                        PhysxPhysicObject.Actor.Shapes[i].UserData = PhysxPhysicObject.ActorDesc.Shapes[i].UserData;
                    }
                }
                else
                {
                    PhysxPhysicObject.Actor.UserData = obj;
                }
            }

            else if (obj is PhysxClothObject)
            {
                PhysxClothObject PhysxPhysicObject = obj as PhysxClothObject;
                PhysxPhysicObject.Cloth          = Scene.CreateCloth(PhysxPhysicObject.ClothDesc);
                PhysxPhysicObject.Cloth.UserData = obj;
            }

            else if (obj is PhysxFluidObject)
            {
                PhysxFluidObject PhysxPhysicObject = obj as PhysxFluidObject;
                PhysxPhysicObject.Fluid          = Scene.CreateFluid(PhysxPhysicObject.FluidDesc);
                PhysxPhysicObject.Fluid.UserData = obj;
            }

            else if (obj is PhysxCapsuleCharacterObject)
            {
                PhysxCapsuleCharacterObject PhysxPhysicObject = obj as PhysxCapsuleCharacterObject;
                PhysxPhysicObject.Controller          = ControllerManager.CreateController <CapsuleController>(PhysxPhysicObject.CapsuleControllerDescription);
                PhysxPhysicObject.Controller.UserData = obj;
            }

            else if (obj is PhysxBoxCharacterObject)
            {
                PhysxBoxCharacterObject PhysxPhysicObject = obj as PhysxBoxCharacterObject;
                PhysxPhysicObject.Controller          = ControllerManager.CreateController <BoxController>((PhysxPhysicObject.BoxControllerDescription));
                PhysxPhysicObject.Controller.UserData = obj;
            }

            objs.Add(obj);
        }
コード例 #4
0
        protected override void LoadContent(GraphicInfo GraphicInfo, GraphicFactory factory ,IContentManager contentManager)
        {
            PhysxPhysicWorld PhysxPhysicWorld = World.PhysicWorld as PhysxPhysicWorld;

            base.LoadContent(GraphicInfo, factory, contentManager);
            {
                SimpleModel simpleModel = new SimpleModel(factory, "Model//block");
                simpleModel.SetTexture(factory.CreateTexture2DColor(1, 1, Color.Blue), TextureType.DIFFUSE);

                BoxShapeDescription SphereGeometry = new BoxShapeDescription(1000, 5, 1000);
                PhysxPhysicObject PhysxPhysicObject = new PhysxPhysicObject(SphereGeometry,
                    Matrix.Identity, new Vector3(1000, 5, 1000));

                ForwardXNABasicShader shader = new ForwardXNABasicShader(ForwardXNABasicShaderDescription.Default());
                ForwardMaterial fmaterial = new ForwardMaterial(shader);
                IObject obj = new IObject(fmaterial, simpleModel, PhysxPhysicObject);
                this.World.AddObject(obj);

                shader.BasicEffect.EnableDefaultLighting();
            }

            {
                ///very basic vehicle !!!
                ///no wheels also =P
                Vehicle Vehicle = new Vehicle(PhysxPhysicWorld.Scene);
                SimpleModel simpleModel = new SimpleModel(factory, "Model//block");
                simpleModel.SetTexture(factory.CreateTexture2DColor(1, 1, Color.Green));
                PhysxPhysicObject tmesh = new PhysxPhysicObject(Vehicle.VehicleBodyActor, new Vector3(5, 3, 7));

                ForwardXNABasicShader shader = new ForwardXNABasicShader(ForwardXNABasicShaderDescription.Default());
                ForwardMaterial fmaterial = new ForwardMaterial(shader);
                UserObject<Vehicle> obj = new UserObject<Vehicle>(fmaterial, simpleModel, tmesh,Vehicle);
                obj.OnUserUpdate += new Action<UserObject<StillDesign.PhysX.Samples.Vehicle>>(obj_OnUserUpdate);
                this.World.AddObject(obj);

            }

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

            this.World.CameraManager.AddCamera(new CameraFirstPerson(GraphicInfo));
        }
コード例 #5
0
        public override void RemoveObject(IPhysicObject obj)
        {
            if (obj is PhysxPhysicObject)
            {
                PhysxPhysicObject PhysxPhysicObject = obj as PhysxPhysicObject;
                PhysxPhysicObject.Actor.UserData = null;
                PhysxPhysicObject.Actor.Dispose();
            }
            else if (obj is PhysxClothObject)
            {
                PhysxClothObject PhysxPhysicObject = obj as PhysxClothObject;
                PhysxPhysicObject.Cloth.UserData = null;
                PhysxPhysicObject.Cloth.Dispose();
            }
            else if (obj is PhysxFluidObject)
            {
                PhysxFluidObject PhysxPhysicObject = obj as PhysxFluidObject;
                PhysxPhysicObject.Fluid.UserData = null;
                PhysxPhysicObject.Fluid.Dispose();
            }

            else if (obj is PhysxCapsuleCharacterObject)
            {
                PhysxCapsuleCharacterObject PhysxPhysicObject = obj as PhysxCapsuleCharacterObject;
                PhysxPhysicObject.Controller.UserData = null;
                PhysxPhysicObject.Controller.Dispose();
            }

            else if (obj is PhysxBoxCharacterObject)
            {
                PhysxBoxCharacterObject PhysxPhysicObject = obj as PhysxBoxCharacterObject;
                PhysxPhysicObject.Controller.UserData = null;
                PhysxPhysicObject.Controller.Dispose();
            }

            objs.Remove(obj);
        }
コード例 #6
0
        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));
        }
コード例 #7
0
        protected override void LoadContent(GraphicInfo GraphicInfo, GraphicFactory factory, IContentManager contentManager)
        {
            PhysxPhysicWorld PhysxPhysicWorld = World.PhysicWorld as PhysxPhysicWorld;

            base.LoadContent(GraphicInfo, factory, contentManager);

            {
                SimpleModel simpleModel = new SimpleModel(factory, "Model//cenario");

                PhysxTriangleMesh tmesh = new PhysxTriangleMesh(PhysxPhysicWorld, simpleModel,
                                                                Matrix.Identity, Vector3.One);

                DeferredNormalShader shader    = new DeferredNormalShader();
                DeferredMaterial     fmaterial = new DeferredMaterial(shader);
                IObject obj = new IObject(fmaterial, simpleModel, tmesh);
                this.World.AddObject(obj);
            }

            PhysxPhysicObject frame;
            {
                var         boxShapeDesc = new BoxShapeDescription(3, 10, 3);
                SimpleModel SimpleModel  = new PloobsEngine.Modelo.SimpleModel(factory, "Model/block");
                SimpleModel.SetTexture(factory.CreateTexture2DColor(1, 1, Color.Red), TextureType.DIFFUSE);

                frame = new PloobsEngine.Physics.PhysxPhysicObject(boxShapeDesc, Matrix.CreateTranslation(50, 5, 50), new Vector3(3, 10, 3));
                DeferredNormalShader shader    = new DeferredNormalShader();
                DeferredMaterial     fmaterial = new DeferredMaterial(shader);
                IObject obj = new IObject(fmaterial, SimpleModel, frame);
                this.World.AddObject(obj);
            }

            //Create an attached emitter
            FluidEmitterDescription emitterDesc = new FluidEmitterDescription();

            emitterDesc.MaximumParticles       = 0;
            emitterDesc.DimensionX             = 8f;
            emitterDesc.DimensionY             = 8f;
            emitterDesc.Type                   = EmitterType.ConstantFlowRate;
            emitterDesc.Rate                   = 150.0f;
            emitterDesc.FluidVelocityMagnitude = 60.0f;
            emitterDesc.ParticleLifetime       = 8.0f;
            emitterDesc.Shape                  = EmitterShape.Rectangular;

            //attach to actor
            emitterDesc.Flags = FluidEmitterFlag.AddBodyVelocity | FluidEmitterFlag.Enabled | FluidEmitterFlag.Visualization;
            emitterDesc.RepulsionCoefficient = 0.02f;

            //emitterDesc.RelativePose = Phyx.Matrix.RotationX((float)Math.PI / 2);
            emitterDesc.RelativePose *= Phyx.Matrix.Translation(0, 20f, 0);

            emitterDesc.FrameShape = frame.Actor.Shapes[0];

            FluidDescription fluidDesc = new FluidDescription();

            fluidDesc.MaximumParticles            = 2500;
            fluidDesc.KernelRadiusMultiplier      = 5.0f;
            fluidDesc.RestParticlesPerMeter       = 5.0f;
            fluidDesc.MotionLimitMultiplier       = 0.9f;
            fluidDesc.PacketSizeMultiplier        = 16;
            fluidDesc.CollisionDistanceMultiplier = 0.12f;
            fluidDesc.Stiffness   = 50.0f;
            fluidDesc.Viscosity   = 40.0f;
            fluidDesc.RestDensity = 1000.0f;
            fluidDesc.Damping     = 0.0f;
            fluidDesc.RestitutionForStaticShapes     = 0.2f;
            fluidDesc.DynamicFrictionForStaticShapes = 0.05f;
            fluidDesc.Flags            = FluidFlag.Enabled | FluidFlag.Visualization;
            fluidDesc.SimulationMethod = FluidSimulationMethod.SmoothedParticleHydrodynamics;

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

            FluidMOdel       FluidMOdel       = new PloobsEngine.Modelo.FluidMOdel(factory, "teste", null, fluidDesc.MaximumParticles);
            PhysxFluidObject PhysxFluidObject = new PloobsEngine.Physics.PhysxFluidObject(fluidDesc);
            FluidShader      FluidShader      = new FluidShader();
            DeferredMaterial ForwardMaterial  = new DeferredMaterial(FluidShader);
            IObject          IObject          = new IObject(ForwardMaterial, FluidMOdel, PhysxFluidObject);

            this.World.AddObject(IObject);

            PhysxFluidObject.Fluid.CreateFluidEmitter(emitterDesc);

            #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
        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));
        }
コード例 #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));
        }
コード例 #10
0
        protected override void LoadContent(GraphicInfo GraphicInfo, GraphicFactory factory ,IContentManager contentManager)
        {
            PhysxPhysicWorld PhysxPhysicWorld = World.PhysicWorld as PhysxPhysicWorld;
            
            base.LoadContent(GraphicInfo, factory, contentManager);

            const int maximumParticles = 3000;

            ///Remember
            ///There are 2 math apis (XNA AND PHYSX)
            ///Sometimes we need to convert between then
            ///Use the extension methods AsPhysx() in XNA API and AsXNA in Physx APi

            ///emitter
            var fluidEmitterDesc = new FluidEmitterDescription()
            {
                DimensionX = 1.5f,
                DimensionY = 1.5f,
                Rate = 65,
                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);

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

            
            ///create and add the fluid to the world
            fluid = PhysxPhysicWorld.Scene.CreateFluid(fluidDesc);

            
            ///Use Billboards to render the fuild particles (dummy way)
            Texture2D tex = factory.GetTexture2D("Textures/Smoke");
            for (int i = 0; i < maximumParticles; i++)
            {
                Billboard3D Billboard3D = new Billboard3D(tex,Vector3.Zero,new Vector2(0.001f));
                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, -20, -55),
                    Shapes = { boxShapeDesc }
                };

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

            BallThrowPhysx28 BallThrowBullet = new BallThrowPhysx28(this.World, GraphicFactory);
            BallThrowBullet.ballSize = 1f;
            BallThrowBullet.Speed = 25;
            this.AttachCleanUpAble(BallThrowBullet);

            CameraFirstPerson CameraFirstPerson = new CameraFirstPerson(GraphicInfo);
            CameraFirstPerson.Position = new Vector3(-35, 8, -52);
            CameraFirstPerson.LeftRightRot = MathHelper.ToRadians(125);
            this.World.CameraManager.AddCamera(CameraFirstPerson);
        }
コード例 #11
0
        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));
        }
コード例 #12
0
        protected override void LoadContent(GraphicInfo GraphicInfo, GraphicFactory factory ,IContentManager contentManager)
        {
            PhysxPhysicWorld PhysxPhysicWorld = World.PhysicWorld as PhysxPhysicWorld;

            base.LoadContent(GraphicInfo, factory, contentManager);

            for (int i = 0; i < 3; i++)
            {
                ClothMeshDescription ClothMeshDescription = new ClothMeshDescription();
                ClothMeshDescription.WeldingDistance = 0.0001f;
                ClothMeshDescription.Flags = (MeshFlag)(int)ClothMeshFlag.WeldVertices;


                ClothModel ClothModel = new PloobsEngine.Modelo.ClothModel(factory, PhysxPhysicWorld,
                    ClothMeshDescription, "Model//ball", Vector3.One * 25, "Textures//meiofio");

                var clothDesc = new ClothDescription()
                {
                    Friction = 0.5f,
                    ClothMesh = ClothModel.ClothMesh,
                    Pressure = 0.9f,
                    Flags = ClothFlag.Bending | ClothFlag.CollisionTwoway | ClothFlag.Visualization | ClothFlag.Pressure | ClothFlag.Gravity | ClothFlag.SelfCollision | ClothFlag.TriangleCollision,
                    Thickness = 0.4f,
                };


                clothDesc.MeshData.AllocatePositions<Vector3>(ClothModel.VerticesNum);
                clothDesc.MeshData.AllocateIndices<int>(ClothModel.IndicesNum);
                clothDesc.MeshData.AllocateNormals<Vector3>(ClothModel.VerticesNum);

                clothDesc.MeshData.MaximumVertices = ClothModel.VerticesNum;
                clothDesc.MeshData.MaximumIndices = ClothModel.IndicesNum;

                clothDesc.MeshData.NumberOfVertices = ClothModel.VerticesNum;
                clothDesc.MeshData.NumberOfIndices = ClothModel.IndicesNum;

                PhysxClothObject PhysxClothObject = new PloobsEngine.Physics.PhysxClothObject(clothDesc,
                                                    Matrix.CreateTranslation(100, 50, i * 100));


                ForwardXNABasicShader ForwardXNABasicShader = new PloobsEngine.Material.ForwardXNABasicShader();
                ClothMaterial ClothMaterial = new ClothMaterial(ForwardXNABasicShader);
                //ClothMaterial.RasterizerState.FillMode = FillMode.WireFrame;
                IObject IObject = new PloobsEngine.SceneControl.IObject(ClothMaterial, ClothModel, PhysxClothObject);
                World.AddObject(IObject);

                ForwardXNABasicShader.BasicEffect.EnableDefaultLighting();
            }

            {
                SimpleModel simpleModel = new SimpleModel(factory, "Model//block");
                simpleModel.SetTexture(factory.CreateTexture2DColor(1, 1, Color.Blue), TextureType.DIFFUSE);

                BoxShapeDescription SphereGeometry = new BoxShapeDescription(1000, 5, 1000);
                PhysxPhysicObject PhysxPhysicObject = new PhysxPhysicObject(SphereGeometry,
                    Matrix.Identity, new Vector3(1000, 5, 1000));

                ForwardXNABasicShader shader = new ForwardXNABasicShader(ForwardXNABasicShaderDescription.Default());
                ForwardMaterial fmaterial = new ForwardMaterial(shader);
                IObject obj = new IObject(fmaterial, simpleModel, PhysxPhysicObject);
                this.World.AddObject(obj);

                shader.BasicEffect.EnableDefaultLighting();
            }


            BallThrowPhysx28 BallThrowBullet = new BallThrowPhysx28(this.World, GraphicFactory);
            this.AttachCleanUpAble(BallThrowBullet);
            this.World.CameraManager.AddCamera(new CameraFirstPerson(GraphicInfo));
        }
コード例 #13
0
        protected override void LoadContent(GraphicInfo GraphicInfo, GraphicFactory factory, IContentManager contentManager)
        {
            PhysxPhysicWorld PhysxPhysicWorld = World.PhysicWorld as PhysxPhysicWorld;
            base.LoadContent(GraphicInfo, factory, contentManager);

            {
                SimpleModel simpleModel = new SimpleModel(factory, "Model//cenario");

                PhysxTriangleMesh tmesh = new PhysxTriangleMesh(PhysxPhysicWorld, simpleModel,
                    Matrix.Identity, Vector3.One);

                DeferredNormalShader shader = new DeferredNormalShader();
                DeferredMaterial fmaterial = new DeferredMaterial(shader);
                IObject obj = new IObject(fmaterial, simpleModel, tmesh);
                this.World.AddObject(obj);
            }

            PhysxPhysicObject frame;
            {
                var boxShapeDesc = new BoxShapeDescription(3, 10, 3);
                SimpleModel SimpleModel = new PloobsEngine.Modelo.SimpleModel(factory, "Model/block");
                SimpleModel.SetTexture(factory.CreateTexture2DColor(1, 1, Color.Red), TextureType.DIFFUSE);

                frame = new PloobsEngine.Physics.PhysxPhysicObject(boxShapeDesc, Matrix.CreateTranslation(50, 5, 50), new Vector3(3, 10, 3));
                DeferredNormalShader shader = new DeferredNormalShader();
                DeferredMaterial fmaterial = new DeferredMaterial(shader);
                IObject obj = new IObject(fmaterial, SimpleModel, frame);
                this.World.AddObject(obj);
            }

            //Create an attached emitter
            FluidEmitterDescription emitterDesc = new FluidEmitterDescription();
            emitterDesc.MaximumParticles = 0;
            emitterDesc.DimensionX = 8f;
            emitterDesc.DimensionY = 8f;
            emitterDesc.Type = EmitterType.ConstantFlowRate;
            emitterDesc.Rate = 150.0f;
            emitterDesc.FluidVelocityMagnitude = 60.0f;
            emitterDesc.ParticleLifetime = 8.0f;
            emitterDesc.Shape = EmitterShape.Rectangular;

            //attach to actor
            emitterDesc.Flags = FluidEmitterFlag.AddBodyVelocity | FluidEmitterFlag.Enabled | FluidEmitterFlag.Visualization;
            emitterDesc.RepulsionCoefficient = 0.02f;

            //emitterDesc.RelativePose = Phyx.Matrix.RotationX((float)Math.PI / 2);
            emitterDesc.RelativePose *= Phyx.Matrix.Translation(0, 20f, 0);

            emitterDesc.FrameShape = frame.Actor.Shapes[0];

            FluidDescription fluidDesc = new FluidDescription();
            fluidDesc.MaximumParticles = 2500;
            fluidDesc.KernelRadiusMultiplier = 5.0f;
            fluidDesc.RestParticlesPerMeter = 5.0f;
            fluidDesc.MotionLimitMultiplier = 0.9f;
            fluidDesc.PacketSizeMultiplier = 16;
            fluidDesc.CollisionDistanceMultiplier = 0.12f;
            fluidDesc.Stiffness = 50.0f;
            fluidDesc.Viscosity = 40.0f;
            fluidDesc.RestDensity = 1000.0f;
            fluidDesc.Damping = 0.0f;
            fluidDesc.RestitutionForStaticShapes = 0.2f;
            fluidDesc.DynamicFrictionForStaticShapes = 0.05f;
            fluidDesc.Flags = FluidFlag.Enabled | FluidFlag.Visualization;
            fluidDesc.SimulationMethod = FluidSimulationMethod.SmoothedParticleHydrodynamics;

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

            FluidMOdel FluidMOdel = new PloobsEngine.Modelo.FluidMOdel(factory, "teste", null, fluidDesc.MaximumParticles);
            PhysxFluidObject PhysxFluidObject = new PloobsEngine.Physics.PhysxFluidObject(fluidDesc);
            FluidShader FluidShader = new FluidShader();
            DeferredMaterial ForwardMaterial = new DeferredMaterial(FluidShader);
            IObject IObject = new IObject(ForwardMaterial, FluidMOdel, PhysxFluidObject);
            this.World.AddObject(IObject);

            PhysxFluidObject.Fluid.CreateFluidEmitter(emitterDesc);

            #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));
        }
コード例 #14
0
        protected override void LoadContent(GraphicInfo GraphicInfo, GraphicFactory factory, IContentManager contentManager)
        {
            PhysxPhysicWorld PhysxPhysicWorld = World.PhysicWorld as PhysxPhysicWorld;

            base.LoadContent(GraphicInfo, factory, contentManager);

            const int maximumParticles = 3000;

            ///Remember
            ///There are 2 math apis (XNA AND PHYSX)
            ///Sometimes we need to convert between then
            ///Use the extension methods AsPhysx() in XNA API and AsXNA in Physx APi

            ///emitter
            var fluidEmitterDesc = new FluidEmitterDescription()
            {
                DimensionX   = 1.5f,
                DimensionY   = 1.5f,
                Rate         = 65,
                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);

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

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


            ///create and add the fluid to the world
            fluid = PhysxPhysicWorld.Scene.CreateFluid(fluidDesc);


            ///Use Billboards to render the fuild particles (dummy way)
            Texture2D tex = factory.GetTexture2D("Textures/Smoke");

            for (int i = 0; i < maximumParticles; i++)
            {
                Billboard3D Billboard3D = new Billboard3D(tex, Vector3.Zero, new Vector2(0.001f));
                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, -20, -55),
                    Shapes     = { boxShapeDesc }
                };

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

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

            BallThrowBullet.ballSize = 1f;
            BallThrowBullet.Speed    = 25;
            this.AttachCleanUpAble(BallThrowBullet);

            CameraFirstPerson CameraFirstPerson = new CameraFirstPerson(GraphicInfo);

            CameraFirstPerson.Position     = new Vector3(-35, 8, -52);
            CameraFirstPerson.LeftRightRot = MathHelper.ToRadians(125);
            this.World.CameraManager.AddCamera(CameraFirstPerson);
        }
コード例 #15
0
        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));
        }
コード例 #16
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));
        }