public static VertexGrid CreateGrid(int rows, int columns, float scale  = 1,float texXScale = 30f, float texYScale = 30f)
        {
            int numVertsX = rows + 1;
            int numVertsZ = columns + 1;

            VertexGrid grid = new VertexGrid(new Vector3[numVertsX * numVertsZ], new int[rows * columns * 2 * 3], new Vector2[numVertsX * numVertsZ]);

            {
                for (int r = 0; r < numVertsX; r++)
                {
                    for (int c = 0; c < numVertsZ; c++)
                    {
                        grid.Points[r * numVertsZ + c] = new Vector3(r * scale, 0, c * scale);
                        //grid.TextCoords[r * numVertsZ + c] = new Vector2((float)r, (float)c);
                        grid.TextCoords[r * numVertsZ + c] = new Vector2((float)r / texXScale, (float)c / texYScale);                                                
                    }
                }
            }

            {
                int count = 0;
                int vi = 0;
                for (int z = 0; z < columns; z++)
                {
                    for (int x = 0; x < rows; x++)
                    {
                        // First triangle
                        grid.Indices[count++] = vi;
                        grid.Indices[count++] = vi + 1;
                        grid.Indices[count++] = vi + numVertsX;

                        // Second triangle
                        grid.Indices[count++] = vi + numVertsX;
                        grid.Indices[count++] = vi + 1;
                        grid.Indices[count++] = vi + numVertsX + 1;

                        vi++;
                    }
                    vi++;
                }
            }

            return grid;
        }
        public static VertexGrid CreateGrid(int rows, int columns, float scale = 1, float texXScale = 30f, float texYScale = 30f)
        {
            int numVertsX = rows + 1;
            int numVertsZ = columns + 1;

            VertexGrid grid = new VertexGrid(new Vector3[numVertsX * numVertsZ], new int[rows * columns * 2 * 3], new Vector2[numVertsX * numVertsZ]);

            {
                for (int r = 0; r < numVertsX; r++)
                {
                    for (int c = 0; c < numVertsZ; c++)
                    {
                        grid.Points[r * numVertsZ + c] = new Vector3(r * scale, 0, c * scale);
                        //grid.TextCoords[r * numVertsZ + c] = new Vector2((float)r, (float)c);
                        grid.TextCoords[r * numVertsZ + c] = new Vector2((float)r / texXScale, (float)c / texYScale);
                    }
                }
            }

            {
                int count = 0;
                int vi    = 0;
                for (int z = 0; z < columns; z++)
                {
                    for (int x = 0; x < rows; x++)
                    {
                        // First triangle
                        grid.Indices[count++] = vi;
                        grid.Indices[count++] = vi + 1;
                        grid.Indices[count++] = vi + numVertsX;

                        // Second triangle
                        grid.Indices[count++] = vi + numVertsX;
                        grid.Indices[count++] = vi + 1;
                        grid.Indices[count++] = vi + numVertsX + 1;

                        vi++;
                    }
                    vi++;
                }
            }

            return(grid);
        }
Example #3
0
        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));
        }
        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 = 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);

            ///Cloth Model (Code inside the demo)
            ClothModel ClothModel = new PloobsEngine.Modelo.ClothModel(factory, PhysxPhysicWorld,
                                                                       new ClothMeshDescription(), grid.Points, grid.TextCoords, grid.Indices, "Textures//meiofio");

            ///Cloth Description
            var clothDesc = new ClothDescription()
            {
                Friction  = 0.5f,
                ClothMesh = ClothModel.ClothMesh,
                Flags     = ClothFlag.Gravity | ClothFlag.Bending | ClothFlag.CollisionTwoway | ClothFlag.Visualization,
                Thickness = 0.2f,
            };

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


            ///Fixing the Cloth to some fixed Points
            // 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
            };

            ///To Hold
            for (int i = 0; i < 2; i++)
            {
                ///Create e Actor DIRECTELY without a PLOOBS Object.
                ///Ploobs does not know it "exists"
                var actorDesc = new ActorDescription()
                {
                    GlobalPose = StillDesign.PhysX.MathPrimitives.Matrix.Translation(positions[i] + p.AsPhysX()),
                    Shapes     = { new BoxShapeDescription(sizes[i]) }
                };

                ///When you create the actor, you are automagically adding it to the world
                var actor = PhysxPhysicWorld.Scene.CreateActor(actorDesc);

                ///Attach one to another
                PhysxClothObject.Cloth.AttachToShape(actor.Shapes.First(), (ClothAttachmentFlag)0);
            }

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

            BallThrowBullet.ballSize = 1;
            BallThrowBullet.Speed    = 20;
            this.AttachCleanUpAble(BallThrowBullet);
            this.World.CameraManager.AddCamera(new CameraFirstPerson(GraphicInfo));
        }
Example #5
0
        protected override void LoadContent(GraphicInfo GraphicInfo, GraphicFactory factory, IContentManager contentManager)
        {
            PhysxPhysicWorld PhysxPhysicWorld = World.PhysicWorld as PhysxPhysicWorld;

            base.LoadContent(GraphicInfo, factory, contentManager);

            ///grid
            var grid = VertexGrid.CreateGrid(100, 100, 0.3f, 100, 100);

            ///model
            ClothModel ClothModel = new PloobsEngine.Modelo.ClothModel(factory, PhysxPhysicWorld,
                                                                       new ClothMeshDescription(), grid.Points, grid.TextCoords, grid.Indices, "Textures//logo_texture");

            ///description
            ///NOW WITH WIND =P
            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);

            ForwardXNABasicShader.BasicEffect.EnableDefaultLighting();

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