コード例 #1
0
        /// <summary>
        /// Constructor of BufferManager class. Create two IndexBuffers,which are swaped when we need to do operations.
        /// Create also VertexBuffer ,which represent a list of 3D vertices to be streamed to the graphics device
        /// <param name="vertices">Array where vertices from terrain are store.</param>
        /// <param name="device">GraphicsDevice</param>
        /// </summary>
        internal BufferManager(VertexMultitextured[] vertices, GraphicsDevice device)
        {
            _device = device;

            VertexBuffer = new VertexBuffer(device, VertexMultitextured.VertexDeclaration, vertices.Length, BufferUsage.WriteOnly);
            VertexBuffer.SetData(vertices);

            _IndexBuffers = new IndexBuffer[]
                    {
                            new IndexBuffer(_device, IndexElementSize.ThirtyTwoBits,  1000000, BufferUsage.WriteOnly),
                            new IndexBuffer(_device, IndexElementSize.ThirtyTwoBits,  1000000, BufferUsage.WriteOnly)
                    };
        }
コード例 #2
0
ファイル: EnvBilb.cs プロジェクト: MenosGrandes/mrowisko-pbl
        /// <summary>
        /// 
        /// </summary>
        /// <param name="objMap"></param>
        /// <param name="terrainVertices"></param>
        /// <param name="terrainWidth"></param>
        /// <param name="terrainLength"></param>
        /// <param name="heightData"></param>
        public void GenerateObjPositions(VertexMultitextured[] terrainVertices, int terrainWidth, int terrainLength, float[,] heightData)
        {
            Color[] objMapColors = new Color[objMap.Width * objMap.Height];
            objMap.GetData(objMapColors);

            int[,] noiseData = new int[objMap.Width, objMap.Height];
            for (int x = 0; x < objMap.Width; x++)
                for (int y = 0; y < objMap.Height; y++)
                    noiseData[x, y] = objMapColors[y + x * objMap.Height].R;

            this.envBilbList = new List<Vector3>();
            Random random = new Random();

            for (int x = 0; x < terrainWidth; x++)
            {
                for (int y = 0; y < terrainLength; y++)
                {
                    float terrainHeight = heightData[x, y];
                    if ((terrainHeight > 1) && (terrainHeight <30))
                    {

                        float flatness = Vector3.Dot(terrainVertices[x + y * terrainWidth].Normal, new Vector3(0, -1, 0));
                        float minFlatness = (float)Math.Cos(MathHelper.ToRadians(15));
                        if (flatness > minFlatness)
                        {

                            float relx = (float)x / (float)terrainWidth;
                            float rely = (float)y / (float)terrainLength;

                            float noiseValueAtCurrentPosition = noiseData[(int)(relx * objMap.Width), (int)(rely * objMap.Height)];
                            float density;
                            if (noiseValueAtCurrentPosition > 200)
                                density = 3;
                            else if (noiseValueAtCurrentPosition > 100)
                                density = 2;
                            else if (noiseValueAtCurrentPosition > 1)
                                density = 1;
                            else
                                density = 0;

                            for (int currDetail = 0; currDetail < density; currDetail++)
                            {
                                float rand1 = (float)random.Next(1000000) / 10000000.0f;
                                float rand2 = (float)random.Next(1000000) / 10000000.0f;
                                Vector3 position = new Vector3((float)x - rand1, 0, (float)y - rand2);
                                position.Y = heightData[x, y];
                                envBilbList.Add(position );
                            }
                        }
                    }
                }
            }
        }