protected override void LoadContent(GraphicInfo GraphicInfo, GraphicFactory factory, IContentManager contentManager) { ///cast to out world instance PhysxPhysicWorld PhysxPhysicWorld = World.PhysicWorld as PhysxPhysicWorld; base.LoadContent(GraphicInfo, factory, contentManager); { SimpleModel simpleModel = new SimpleModel(factory, "Model//cenario"); ///Physic Triangle mesh (same as bepu) PhysxTriangleMesh tmesh = new PhysxTriangleMesh(PhysxPhysicWorld, simpleModel, Matrix.Identity, Vector3.One); ForwardXNABasicShader shader = new ForwardXNABasicShader(ForwardXNABasicShaderDescription.Default()); ForwardMaterial fmaterial = new ForwardMaterial(shader); IObject obj = new IObject(fmaterial, simpleModel, tmesh); this.World.AddObject(obj); } ///Ball Throw !!! BallThrowPhysx28 BallThrowBullet = new BallThrowPhysx28(this.World, GraphicFactory); this.AttachCleanUpAble(BallThrowBullet); this.World.CameraManager.AddCamera(new CameraFirstPerson(GraphicInfo)); }
public PhysxTriangleMesh(PhysxPhysicWorld PhysxPhysicWorld, IModelo model,Microsoft.Xna.Framework.Matrix localTransformation, Microsoft.Xna.Framework.Matrix worldTransformation, Microsoft.Xna.Framework.Vector3 scale, MaterialDescription MaterialDescription) { Microsoft.Xna.Framework.Vector3[] vertices = null; int[] indices = null; ExtractData(ref vertices, ref indices, model); TriangleMeshDesc meshDesc = new TriangleMeshDesc(); Vector3[] points = new Vector3[vertices.Count()]; for (int i = 0; i < vertices.Count(); i++) { points[i] = vertices[i].AsPhysX(); } meshDesc.Points = points; meshDesc.SetTriangles<int>(indices); //meshDesc.Triangles = indices; MemoryStream ms = new MemoryStream(); if(PhysxPhysicWorld.Cooking.CookTriangleMesh(meshDesc,ms)==false) { PloobsEngine.Engine.Logger.ActiveLogger.LogMessage("Cant Cook Model",Engine.Logger.LogLevel.FatalError); } ms.Position = 0; TriangleMesh triangleMesh = PhysxPhysicWorld.Physix.CreateTriangleMesh(ms); staticActor = PhysxPhysicWorld.Physix.CreateRigidStatic(worldTransformation.AsPhysX()); TriangleMeshGeometry TriangleMeshGeometry = new TriangleMeshGeometry(triangleMesh,new MeshScale(scale.AsPhysX(),Quaternion.Identity)); material = PhysxPhysicWorld.Physix.CreateMaterial(MaterialDescription.StaticFriction, MaterialDescription.DynamicFriction, MaterialDescription.Bounciness); aTriMeshShape = staticActor.CreateShape(TriangleMeshGeometry, material, localTransformation.AsPhysX()); this.Scale = scale; }
public ClothModel(GraphicFactory factory, PhysxPhysicWorld PhysxPhysicWorld, ClothMeshDescription clothMeshDesc, XNA.Vector3[] Points, XNA.Vector2[] TextCoords, int[] Indices, String diffuseTextureName = null) : base(factory, "Cloth", false) { this._diffuseName = diffuseTextureName; VerticesNum = Points.Length; IndicesNum = Indices.Length; clothMeshDesc.AllocateVertices <Vector3>(VerticesNum); clothMeshDesc.AllocateTriangles <int>(IndicesNum / 3); clothMeshDesc.VertexCount = VerticesNum; clothMeshDesc.TriangleCount = IndicesNum / 3; BatchInformation = new PloobsEngine.Modelo.BatchInformation(0, VerticesNum, IndicesNum / 3, 0, 0, VertexPositionNormalTexture.VertexDeclaration, VertexPositionNormalTexture.VertexDeclaration.VertexStride, PrimitiveType.TriangleList); BatchInformation.ModelLocalTransformation = XNA.Matrix.Identity; vertexPositionNormalTexture = new VertexPositionNormalTexture[VerticesNum]; BatchInformation.VertexBuffer = factory.CreateDynamicVertexBuffer(VertexPositionNormalTexture.VertexDeclaration, VerticesNum + (int)(1.2 * VerticesNum), BufferUsage.WriteOnly); BatchInformation.IndexBuffer = factory.CreateDynamicIndexBuffer(IndexElementSize.ThirtyTwoBits, IndicesNum + (int)(1.2 * IndicesNum), BufferUsage.WriteOnly); BatchInformation.IndexBuffer.SetData <int>(Indices); clothMeshDesc.VerticesStream.SetData(Points); clothMeshDesc.TriangleStream.SetData(Indices); for (int i = 0; i < BatchInformation.NumVertices; i++) { vertexPositionNormalTexture[i].TextureCoordinate = TextCoords[i]; vertexPositionNormalTexture[i].Position = Points[i]; } // We are using 32 bit integers for our indices, so make sure the 16 bit flag is removed. // 32 bits are the default, so this isn't technically needed, but it's good to show in a sample clothMeshDesc.Flags &= ~MeshFlag.Indices16Bit; //clothMeshDesc.Flags |= (MeshFlag)((int)clothMeshDesc.Flags | (int)ClothMeshFlag.Tearable); // Write the cooked data to memory using (var 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 = PhysxPhysicWorld.Core.CreateClothMesh(memoryStream); } modelRadius = Microsoft.Xna.Framework.BoundingSphere.CreateFromPoints(Points).Radius; LoadModel(factory, out BatchInformations, out TextureInformations); }
/// <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); }
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)); }
protected override void SetWorldAndRenderTechnich(out IRenderTechnic renderTech, out IWorld world) { PhysxPhysicWorld PhysxPhysicWorld = new PhysxPhysicWorld(new Vector3(0, -10, 0)); world = new IWorld(PhysxPhysicWorld, new SimpleCuller()); ForwardRenderTecnichDescription desc = ForwardRenderTecnichDescription.Default(); desc.BackGroundColor = Color.CornflowerBlue; renderTech = new ForwardRenderTecnich(desc); }
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); ForwardXNABasicShader shader = new ForwardXNABasicShader(ForwardXNABasicShaderDescription.Default()); ForwardMaterial fmaterial = new ForwardMaterial(shader); IObject obj = new IObject(fmaterial, simpleModel, tmesh); this.World.AddObject(obj); } { ///Load a Model with a custom texture SimpleModel sm2 = new SimpleModel(factory, "Model\\ball"); sm2.SetTexture(factory.CreateTexture2DColor(1, 1, Color.Aquamarine, false), TextureType.DIFFUSE); ForwardXNABasicShader nd = new ForwardXNABasicShader(); IMaterial m = new ForwardMaterial(nd); SphereShapeDescription SphereGeometry = new SphereShapeDescription(15f); PhysxGhostObject PhysxPhysicObject = new PhysxGhostObject(new Vector3(100, 100, 100), Matrix.Identity, Vector3.One * 15f); IObject o = new IObject(m, sm2, PhysxPhysicObject); this.World.AddObject(o); ///Physx Trigger !!! ///Just need to pass a shape to it ///WORKS THE SAME AS BEPU TRIGGER ///LOOK AT INTRODUCTION DEMOS PhysxTrigger PhysxTrigger = new PloobsEngine.Physics.PhysxTrigger( SphereGeometry, Matrix.CreateTranslation(new Vector3(100, 100, 100)), new PloobsEngine.Trigger.TriggerEvent("TriggerEvent", "TriggerEvent"), null, true, true, true); World.AddTrigger(PhysxTrigger); } BallThrowPhysx28 BallThrowBullet = new BallThrowPhysx28(this.World, GraphicFactory); this.AttachCleanUpAble(BallThrowBullet); this.World.CameraManager.AddCamera(new CameraFirstPerson(GraphicInfo)); ReciveMessage = new ReciveMessage(); }
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); ForwardXNABasicShader shader = new ForwardXNABasicShader(ForwardXNABasicShaderDescription.Default()); ForwardMaterial fmaterial = new ForwardMaterial(shader); IObject obj = new IObject(fmaterial, simpleModel, tmesh); this.World.AddObject(obj); } { ///Controller description ///YOu have BoxControllerDescription and SphereControllerDescription BoxControllerDescription desc = new BoxControllerDescription(1, 1, 1); desc.UpDirection = Axis.Y; desc.SlopeLimit = 0; desc.SkinWidth = 0.2f; desc.StepOffset = 0.5f; desc.InteractionFlag = CCTInteractionFlag.Include | CCTInteractionFlag.UseFilter; SimpleModel sm = new SimpleModel(factory, "..\\Content\\Model\\block"); sm.SetTexture(factory.CreateTexture2DColor(1, 1, Color.Blue), TextureType.DIFFUSE); ForwardXNABasicShader shader = new ForwardXNABasicShader(ForwardXNABasicShaderDescription.Default()); ForwardMaterial mat = new ForwardMaterial(shader); ///Character Object PhysxBoxCharacterObject PhysxCapsuleCharacterObject = new PhysxBoxCharacterObject(desc, new Vector3(50), Matrix.Identity, Vector3.One * 5); IObject marine = new IObject(mat, sm, PhysxCapsuleCharacterObject); this.World.AddObject(marine); marine.OnUpdate += new OnUpdate(marine_OnUpdate); } BallThrowPhysx28 BallThrowBullet = new BallThrowPhysx28(this.World, GraphicFactory); this.AttachCleanUpAble(BallThrowBullet); this.World.CameraManager.AddCamera(new CameraFirstPerson(GraphicInfo)); }
/// <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 SimpleModel sm2 = new SimpleModel(factory, "Model\\ball"); sm2.SetTexture(factory.CreateTexture2DColor(1, 1, Color.White, false), TextureType.DIFFUSE); ForwardXNABasicShader nd = new ForwardXNABasicShader(); IMaterial m = new ForwardMaterial(nd); PhysxPhysicWorld PhysxPhysicWorld = _mundo.PhysicWorld as PhysxPhysicWorld; SphereGeometry SphereGeometry = new PhysX.SphereGeometry(1); PhysxPhysicObject PhysxPhysicObject = new PloobsEngine.Physics3x.PhysxPhysicObject(PhysxPhysicWorld.Scene, SphereGeometry, 10, Matrix.Identity, Matrix.CreateTranslation(pos), Vector3.One, PloobsEngine.Physics.MaterialDescription.DefaultPhysxMaterial()); IObject o = new IObject(m, sm2, PhysxPhysicObject); return(o); }
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)); }
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, Matrix.Identity, Vector3.One, PloobsEngine.Physics.MaterialDescription.DefaultPhysxMaterial()); ForwardXNABasicShader shader = new ForwardXNABasicShader(ForwardXNABasicShaderDescription.Default()); ForwardMaterial fmaterial = new ForwardMaterial(shader); IObject obj = new IObject(fmaterial, simpleModel, tmesh); this.World.AddObject(obj); } BallThrowPhysx BallThrowBullet = new BallThrowPhysx(this.World, GraphicFactory); this.World.CameraManager.AddCamera(new CameraFirstPerson(GraphicInfo)); }
public static void CookTriangleMesh(PhysxPhysicWorld PhysxPhysicWorld, IModelo model, FileStream FileStream) { Microsoft.Xna.Framework.Vector3[] vertices = null; int[] indices = null; ExtractData(ref vertices, ref indices, model); TriangleMeshDesc meshDesc = new TriangleMeshDesc(); Vector3[] points = new Vector3[vertices.Count()]; for (int i = 0; i < vertices.Count(); i++) { points[i] = vertices[i].AsPhysX(); } meshDesc.Points = points; meshDesc.SetTriangles<int>(indices); if (PhysxPhysicWorld.Cooking.CookTriangleMesh(meshDesc, FileStream) == false) { PloobsEngine.Engine.Logger.ActiveLogger.LogMessage("Cant Cook Model", Engine.Logger.LogLevel.FatalError); } }
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)); }
protected override void LoadContent(GraphicInfo GraphicInfo, GraphicFactory factory, IContentManager contentManager) { PhysxPhysicWorld PhysxPhysicWorld = World.PhysicWorld as PhysxPhysicWorld; base.LoadContent(GraphicInfo, factory, contentManager); Texture2D tMap = factory.GetTexture2D("Textures//hmap_10243"); QuadTerrain q = new PloobsEngine.Material.QuadTerrain(factory, tMap, 33, 513, 10, 3f); ForwardTerrainMaterial mat = new ForwardTerrainMaterial(q); //Set various terrain stats. mat.diffuseScale = q.flatScale / 4; mat.detailScale = q.flatScale / 100; mat.detailMapStrength = 2; mat.textureBlend = factory.GetTexture2D("Textures//hmap_256blend"); mat.textureDetail = factory.GetTexture2D("Textures//coolgrass2DOT3"); mat.textureRed = factory.GetTexture2D("Textures//TexR"); mat.textureGreen = factory.GetTexture2D("Textures//TexG"); mat.textureBlue = factory.GetTexture2D("Textures//TexB"); mat.textureBlack = factory.GetTexture2D("Textures//TexBase"); mat.sunlightVector = Vector3.Normalize(new Vector3(.5f, .5f, .8f)); mat.sunlightColour = new Vector3(2.3f, 2f, 1.8f); float[,] f = q.getHeightMap(); int v = 513; var samples = new HeightFieldSample[v * v]; for (int r = 0; r < v; r++) { for (int c = 0; c < v; c++) { var sample = new HeightFieldSample() { Height = (short)f[r, c], //Height = 5, TessellationFlag = 1, MaterialIndex0 = 1, MaterialIndex1 = 0 }; samples[r * v + c] = sample; } } var heightFieldDesc = new HeightFieldDescription() { NumberOfRows = v, NumberOfColumns = v, ConvexEdgeThreshold = 0f, }; heightFieldDesc.SetSamples(samples); var heightField = PhysxPhysicWorld.Core.CreateHeightField(heightFieldDesc); heightFieldDesc.Dispose(); var heightFieldShapeDesc = new HeightFieldShapeDescription() { HeightField = heightField, HeightScale = 1.0f, RowScale = 1, ColumnScale = 1, }; heightFieldShapeDesc.LocalPose = StillDesign.PhysX.MathPrimitives.Matrix.Identity; var actorDesc = new ActorDescription() { GlobalPose = Matrix.Identity.AsPhysX(), Shapes = { heightFieldShapeDesc }, }; actor = PhysxPhysicWorld.Scene.CreateActor(actorDesc); IObject obj3 = new IObject(mat, null, new PhysxGhostObject()); this.World.AddObject(obj3); BallThrowPhysx28 BallThrowBullet = new BallThrowPhysx28(this.World, GraphicFactory); this.AttachCleanUpAble(BallThrowBullet); CameraFirstPerson CameraFirstPerson = new CameraFirstPerson(GraphicInfo); CameraFirstPerson.FarPlane = 20000; this.World.CameraManager.AddCamera(CameraFirstPerson); }
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); }
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)); }
protected override void LoadContent(GraphicInfo GraphicInfo, GraphicFactory factory, IContentManager contentManager) { PhysxPhysicWorld PhysxPhysicWorld = World.PhysicWorld as PhysxPhysicWorld; base.LoadContent(GraphicInfo, factory, contentManager); int w = 25; int h = 25; float hw = w / 2.0f; float hh = h / 2.0f; Vector3 p = new Vector3(0, 20, 0); var grid = VertexGrid.CreateGrid(w, h); 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.Gravity | ClothFlag.Bending | ClothFlag.CollisionTwoway | ClothFlag.Visualization, Thickness = 0.2f, }; 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.CreateTranslation(-hw, 0, -hh) * Matrix.CreateTranslation(p)); ForwardXNABasicShader ForwardXNABasicShader = new PloobsEngine.Material.ForwardXNABasicShader(); ClothMaterial ClothMaterial = new ClothMaterial(ForwardXNABasicShader); IObject IObject = new PloobsEngine.SceneControl.IObject(ClothMaterial, ClothModel, PhysxClothObject); World.AddObject(IObject); // Four corner boxes to hold it in place var positions = new[] { new StillDesign.PhysX.MathPrimitives.Vector3(0, 0, -hh), // Back new StillDesign.PhysX.MathPrimitives.Vector3(0, 0, hh), // Front new StillDesign.PhysX.MathPrimitives.Vector3(-hw, 0, 0), // Left new StillDesign.PhysX.MathPrimitives.Vector3(hw, 0, 0), // Right }; var sizes = new[] { new StillDesign.PhysX.MathPrimitives.Vector3(w, 1, 1), // Back new StillDesign.PhysX.MathPrimitives.Vector3(w, 1, 1), // Front new StillDesign.PhysX.MathPrimitives.Vector3(1, 1, h), // Left new StillDesign.PhysX.MathPrimitives.Vector3(1, 1, h), //Right }; ///pra preender for (int i = 0; i < 2; i++) { var actorDesc = new ActorDescription() { GlobalPose = StillDesign.PhysX.MathPrimitives.Matrix.Translation(positions[i] + p.AsPhysX()), Shapes = { new BoxShapeDescription(sizes[i]) } }; 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)); }
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++) { ///Different from others examples, we use a model to provide the vertices to the cloth ///Model must be "closed" 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, ///experiment changing this =P 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)); }
public PhysxTriangleMesh(PhysxPhysicWorld PhysxPhysicWorld, FileStream FileStream, Microsoft.Xna.Framework.Matrix localTransformation, Microsoft.Xna.Framework.Matrix worldTransformation, Microsoft.Xna.Framework.Vector3 scale, MaterialDescription MaterialDescription) { TriangleMesh triangleMesh = PhysxPhysicWorld.Physix.CreateTriangleMesh(FileStream); staticActor = PhysxPhysicWorld.Physix.CreateRigidStatic(worldTransformation.AsPhysX()); TriangleMeshGeometry TriangleMeshGeometry = new TriangleMeshGeometry(triangleMesh, new MeshScale(scale.AsPhysX(), Quaternion.Identity)); material = PhysxPhysicWorld.Physix.CreateMaterial(MaterialDescription.StaticFriction, MaterialDescription.DynamicFriction, MaterialDescription.Bounciness); aTriMeshShape = staticActor.CreateShape(TriangleMeshGeometry, material, localTransformation.AsPhysX()); this.Scale = scale; }
public PhysxStaticActor(PhysxPhysicWorld PhysxPhysicWorld ,Geometry geometry, Microsoft.Xna.Framework.Matrix localTransformation, Microsoft.Xna.Framework.Matrix worldTransformation, Microsoft.Xna.Framework.Vector3 scale, MaterialDescription MaterialDescription) { staticActor = PhysxPhysicWorld.Physix.CreateRigidStatic(worldTransformation.AsPhysX()); material = PhysxPhysicWorld.Physix.CreateMaterial(MaterialDescription.StaticFriction, MaterialDescription.DynamicFriction, MaterialDescription.Bounciness); Shape aTriMeshShape = staticActor.CreateShape(geometry, material, localTransformation.AsPhysX()); }
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)); }
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)); }
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); ///Cosntruct a grid of vertices to make a cloth int w = 50; int h = 50; float hw = w / 2.0f; float hh = h / 2.0f; Vector3 p = new Vector3(0, 70, 0); var grid = VertexGrid.CreateGrid(w, h); ///Cloth Model (Code inside the demo) ClothModel ClothModel = new PloobsEngine.Modelo.ClothModel(factory, PhysxPhysicWorld, new ClothMeshDescription(), grid.Points, grid.TextCoords, grid.Indices, "Textures//fabric"); ///Cloth Description var clothDesc = new ClothDescription() { Friction = 0.5f, ClothMesh = ClothModel.ClothMesh, Flags = ClothFlag.Gravity | ClothFlag.Bending | ClothFlag.CollisionTwoway | ClothFlag.Visualization | ClothFlag.SelfCollision, Thickness = 0.5f, }; ///Adding Cloth Vertices 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; ///Cloth Physic Model PhysxClothObject PhysxClothObject = new PloobsEngine.Physics.PhysxClothObject(clothDesc, Matrix.CreateTranslation(-hw, 0, -hh) * Matrix.CreateTranslation(p)); ForwardXNABasicShader ForwardXNABasicShader = new PloobsEngine.Material.ForwardXNABasicShader(); ClothMaterial ClothMaterial = new ClothMaterial(ForwardXNABasicShader); IObject IObject = new PloobsEngine.SceneControl.IObject(ClothMaterial, ClothModel, PhysxClothObject); World.AddObject(IObject); { SimpleModel simpleModel = new SimpleModel(factory, "Model//table", "Textures//wood_dark"); 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); shader.BasicEffect.EnableDefaultLighting(); } { 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, } ); { 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(5); SphereGeometry.Material = material2; PhysxPhysicObject PhysxPhysicObject = new PhysxPhysicObject(SphereGeometry, 0.5f, Matrix.CreateTranslation(new Vector3(0, 50, 0)), Vector3.One * 5f); IObject o = new IObject(m, sm2, PhysxPhysicObject); this.World.AddObject(o); nd.BasicEffect.EnableDefaultLighting(); PhysxPhysicObject.isMotionLess = true; } } BallThrowPhysx28 BallThrowBullet = new BallThrowPhysx28(this.World, GraphicFactory); BallThrowBullet.ballSize = 1; BallThrowBullet.Speed = 20; this.AttachCleanUpAble(BallThrowBullet); this.World.CameraManager.AddCamera(new CameraFirstPerson(GraphicInfo)); }