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