示例#1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TerrainObject"/> class.
        /// </summary>
        /// <param name="gfactory">The gfactory.</param>
        /// <param name="heightmapTexture">The heighmap texture.</param>
        /// <param name="translation">The translation.</param>
        /// <param name="rotation">The rotation.</param>
        /// <param name="materialDesc">The material desc.</param>
        /// <param name="XSpacing">The X spacing.</param>
        /// <param name="ZSpacing">The Z spacing.</param>
        /// <param name="heightMultipler">The height multipler.</param>
        public TerrainObject(GraphicFactory gfactory, Texture2D heightmapTexture, Vector3 translation, Matrix?rotation = null, MaterialDescription materialDesc = null, float XSpacing = 1, float ZSpacing = 1, float heightMultipler = 10)
        {
            if (!rotation.HasValue)
            {
                rotation = Matrix.Identity;
            }

            if (materialDecription == null)
            {
                materialDecription = MaterialDescription.DefaultBepuMaterial();
            }

            this.heightMultipler = heightMultipler;

            //Used to calculate ther proportion of the xNormalized in the getHeightFast method
            xScale = XSpacing;
            zScale = ZSpacing;

            sourceImage = heightmapTexture;
            int xLength = sourceImage.Width;
            int yLength = sourceImage.Height;

            terrainWidth  = xLength;
            terrainHeight = yLength;

            this.rotation = rotation.Value;
            //this.scale = scale;

            Color[] colorData = new Color[xLength * yLength];
            sourceImage.GetData <Color>(colorData);

            var heightStore = new float[xLength, yLength];

            for (int i = 0; i < xLength; i++)
            {
                for (int j = 0; j < yLength; j++)
                {
                    Color color = colorData[j * xLength + i];
                    heightStore[i, j] = (color.R) / heightMultipler;

                    if (heightStore[i, j] > maxHeight)
                    {
                        maxHeight = heightStore[i, j];
                    }
                    if (heightStore[i, j] < minHeight)
                    {
                        minHeight = heightStore[i, j];
                    }
                }
            }
            //Create the terrain.
            BEPUphysics.CollisionShapes.TerrainShape shape = new BEPUphysics.CollisionShapes.TerrainShape(heightStore, BEPUphysics.CollisionShapes.QuadTriangleOrganization.BottomLeftUpperRight);

            terrain = new Terrain(shape, new BEPUphysics.MathExtensions.AffineTransform(new Vector3(XSpacing, 1, ZSpacing), Quaternion.CreateFromRotationMatrix(rotation.Value), new Vector3(-xLength * XSpacing / 2, 0, -yLength * ZSpacing / 2) + translation));
            terrain.ImproveBoundaryBehavior = true;

            SetMaterialDescription(materialDesc);
        }
示例#2
0
        public TerrainObject(GraphicFactory gfactory, Vector3 translation, Matrix rotation, float[,] heights, MaterialDescription materialDesc, BEPUphysics.CollisionShapes.QuadTriangleOrganization triangleorientation = BEPUphysics.CollisionShapes.QuadTriangleOrganization.BottomLeftUpperRight)
        {
            terrainWidth  = heights.GetLength(0);
            terrainHeight = heights.GetLength(1);

            //Create the terrain.
            BEPUphysics.CollisionShapes.TerrainShape shape = new BEPUphysics.CollisionShapes.TerrainShape(heights, triangleorientation);

            terrain = new Terrain(shape, new BEPUphysics.MathExtensions.AffineTransform(Vector3.One, Quaternion.CreateFromRotationMatrix(rotation), translation));
            terrain.ImproveBoundaryBehavior = true;

            SetMaterialDescription(materialDesc);
        }
        public TerrainObject(GraphicFactory gfactory, Vector3 translation, Matrix rotation, float[,] heights, MaterialDescription materialDesc,BEPUphysics.CollisionShapes.QuadTriangleOrganization triangleorientation = BEPUphysics.CollisionShapes.QuadTriangleOrganization.BottomLeftUpperRight )
        {
            terrainWidth = heights.GetLength(0);
            terrainHeight = heights.GetLength(1);

            //Create the terrain.
            BEPUphysics.CollisionShapes.TerrainShape shape = new BEPUphysics.CollisionShapes.TerrainShape(heights, triangleorientation);

            terrain = new Terrain(shape, new BEPUphysics.MathExtensions.AffineTransform(Vector3.One, Quaternion.CreateFromRotationMatrix(rotation), translation));
            terrain.ImproveBoundaryBehavior = true;

            SetMaterialDescription(materialDesc);
        }
        /// <summary>
        /// Create a Terrain Physic Object
        /// </summary>
        /// <param name="gfactory">The gfactory.</param>
        /// <param name="heighmapName">Name of the heighmap texture</param>
        /// <param name="translation">The translation.</param>
        /// <param name="rotation">The rotation.</param>
        /// <param name="materialDesc">The material desc.</param>
        /// <param name="XSpacing">The X spacing.</param>
        /// <param name="ZSpacing">The Z spacing.</param>
        /// <param name="heightMultipler">Default 10 - controla a altura, menor mais alto</param>
        public TerrainObject(GraphicFactory gfactory, String heighmapName, Vector3 translation, Matrix? rotation = null, MaterialDescription materialDesc = null, float XSpacing = 1, float ZSpacing = 1, float heightMultipler = 10)
        {
            if (!rotation.HasValue)
                rotation = Matrix.Identity;

            if (materialDecription == null)
                materialDecription = MaterialDescription.DefaultBepuMaterial();


            //Used to calculate ther proportion of the xNormalized in the getHeightFast method
            xScale = XSpacing;
            zScale = ZSpacing;


            this.heightMultipler = heightMultipler;
            this.image = heighmapName;

            sourceImage = gfactory.GetTexture2D(image);
            int xLength = sourceImage.Width;
            int yLength = sourceImage.Height;

            terrainWidth = xLength;
            terrainHeight = yLength;


            this.rotation = rotation.Value;
            //this.scale = scale;

            Color[] colorData = new Color[xLength * yLength];
            sourceImage.GetData<Color>(colorData);

            var heightStore = new float[xLength, yLength];
            for (int i = 0; i < xLength; i++)
            {
                for (int j = 0; j < yLength; j++)
                {
                    Color color = colorData[j * xLength + i];
                    heightStore[i, j] = (color.R) / heightMultipler;

                    if (heightStore[i, j] > maxHeight)
                    {
                        maxHeight = heightStore[i, j];
                    }
                    if (heightStore[i, j] < minHeight)
                    {
                        minHeight = heightStore[i, j];
                    }

                }
            }
            //Create the terrain.
            BEPUphysics.CollisionShapes.TerrainShape shape = new BEPUphysics.CollisionShapes.TerrainShape(heightStore, BEPUphysics.CollisionShapes.QuadTriangleOrganization.BottomLeftUpperRight);

            terrain = new Terrain(shape, new BEPUphysics.MathExtensions.AffineTransform(new Vector3(XSpacing, 1, ZSpacing), Quaternion.CreateFromRotationMatrix(rotation.Value), new Vector3(-xLength * XSpacing / 2, 0, -yLength * ZSpacing / 2) + translation));
            terrain.ImproveBoundaryBehavior = true;

            SetMaterialDescription(materialDesc);

        }