Ejemplo n.º 1
0
        public Image(String path)
        {
            if (!System.IO.File.Exists(path))
            {
                Console.Error.Write("File not found:" + path);
                return;
            }

            _path = path;
            _id   = TexUtil.CreateTextureFromFile(path, out _width, out _height);
            color = new Color4(255, 255, 255, 255);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// [Re-]generate the terrain data.
        /// </summary>
        /// <param name="iterations">Number of subdivision iteratons.</param>
        /// <param name="roughness">Roughness parameter.</param>
        /// <param name="param">Optional text parameter.</param>
        private void Regenerate(int iterations, float roughness, string param)
        {
            // !!!{{ TODO: add terrain regeneration code here (to reflect the given terrain parameters)

            scene.Reset();

            // dummy rectangle, facing to the camera
            // notice that your terrain is supposed to be placed
            // in the XZ plane (elevation increases along the positive Y axis)
            scene.AddVertex(new Vector3(-0.5f, roughness, -0.5f)); // 0
            scene.AddVertex(new Vector3(-0.5f, 0.0f, +0.5f));      // 1
            scene.AddVertex(new Vector3(+0.5f, 0.0f, -0.5f));      // 2
            scene.AddVertex(new Vector3(+0.5f, 0.0f, +0.5f));      // 3

            scene.SetNormal(0, (Vector3.UnitY + roughness * (Vector3.UnitX + Vector3.UnitZ)).Normalized());
            scene.SetNormal(1, (Vector3.UnitY + roughness * 0.5f * (Vector3.UnitX + Vector3.UnitZ)).Normalized());
            scene.SetNormal(2, (Vector3.UnitY + roughness * 0.5f * (Vector3.UnitX + Vector3.UnitZ)).Normalized());
            scene.SetNormal(3, Vector3.UnitY);

            float txtExtreme = 1.0f + iterations;

            scene.SetTxtCoord(0, new Vector2(0.0f, 0.0f));
            scene.SetTxtCoord(1, new Vector2(0.0f, txtExtreme));
            scene.SetTxtCoord(2, new Vector2(txtExtreme, 0.0f));
            scene.SetTxtCoord(3, new Vector2(txtExtreme, txtExtreme));

            scene.SetColor(0, Vector3.UnitX);                 // red
            scene.SetColor(1, Vector3.UnitY);                 // green
            scene.SetColor(2, Vector3.UnitZ);                 // blue
            scene.SetColor(3, new Vector3(1.0f, 1.0f, 1.0f)); // white

            scene.AddTriangle(1, 2, 0);                       // last vertex is red
            scene.AddTriangle(2, 1, 3);                       // last vertex is white

            // this function uploads the data to the graphics card
            PrepareData();

            // load a texture
            if (textureId > 0)
            {
                GL.DeleteTexture(textureId);
                textureId = 0;
            }
            textureId = TexUtil.CreateTextureFromFile("cgg256.png", "../../cgg256.png");

            // simulation / hovercraft [re]initialization?
            InitSimulation(false);

            // !!!}}
        }