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;
        }
示例#2
0
        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);
        }
        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);

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