예제 #1
0
        /// <summary>Initializes a new grid consisting of one or more quads</summary>
        /// <param name="graphicsDevice">Graphics device the grid will be created on</param>
        /// <param name="min">
        ///   Lesser coordinates of the world region that will be covered by the grid
        /// </param>
        /// <param name="max">
        ///   Greater coordinates of the world region that will be covered by the grid
        /// </param>
        /// <param name="segmentsX">
        ///   Number of segments the grid will have on the X axis
        /// </param>
        /// <param name="segmentsZ">
        ///   Number of segments the grid will have on the Z axis
        /// </param>
        public WaterGrid(
            GraphicsDevice graphicsDevice,
            Vector2 min, Vector2 max,
            int segmentsX, int segmentsZ
            ) :
            base(graphicsDevice, getIndexCount(segmentsX, segmentsZ))
        {
            this.graphicsDevice = graphicsDevice;

            // Create and fill the vertex buffer
            {
                WaterVertex[] vertices = buildVertexArray(min, max, segmentsX, segmentsZ);
                this.vertexCount  = vertices.Length;
                this.vertexBuffer = new VertexBuffer(
                    graphicsDevice, typeof(WaterVertex), vertices.Length, BufferUsage.None
                    );
                this.vertexBuffer.SetData <WaterVertex>(vertices);
            }

            // Create and fill the index buffer
            {
                short[] indices = TriangleStripIndexBuilder.BuildAlternatingStrip(
                    segmentsX, segmentsZ
                    );
                this.indexCount  = indices.Length;
                this.indexBuffer = new IndexBuffer(
                    graphicsDevice, typeof(short), indices.Length, BufferUsage.None
                    );
                this.indexBuffer.SetData <short>(indices);
            }
        }
예제 #2
0
 /// <summary>
 ///   Calculates the number of indices required for the water surface
 /// </summary>
 /// <param name="segmentsX">Number of segments in X direction</param>
 /// <param name="segmentsZ">Number of segments in Z direction</param>
 /// <returns>The number of indices required</returns>
 private static int getIndexCount(int segmentsX, int segmentsZ)
 {
     return(TriangleStripIndexBuilder.CountAlternatingStripIndices(segmentsX, segmentsZ));
 }