Ejemplo n.º 1
0
        private void openGLControl1_Load(object sender, EventArgs e)
        {
            program = new ProgramObject(
               new VertexShader(Shaders.VERTEX_SHADER_TEXTURE),
                   new FragmentShader(Shaders.FRAGMENT_SHADER_ILLUMINATION));

            cylinder = new Cylinder(1, 4, 100, new Vector4(), program);

            cylinder.transformation = Matrix4.CreateTranslation(0, 0, -2);

            Light light = new Light(new Spherical(5, MathHelper.PiOver2, 0));

            foot = new Foot(2f, 20, program);
            foot.colored = false;
            foot.light = light;

            cover = new Cover(0.25f, 1, program);
            cover.noise_texture = true;
            cover.colored = false;
            cover.light = light;

            foot.transformation = Matrix4.CreateTranslation(0, 0, -1);
            cover.transformation = Matrix4.CreateTranslation(0, 0, -1);

            LoadImageTexture.LoadTexture(@"..\..\texture.jpg");

            openGLControl1.objects.Add(foot);
            openGLControl1.objects.Add(cover);

            openGLControl1.light = light;

            openGLControl1.load();
        }
Ejemplo n.º 2
0
        private void openGLControl1_Load(object sender, EventArgs e)
        {
            ProgramObject program = new ProgramObject(
               new VertexShader(Shaders.VERTEX_SHADER_TEXTURE),
                   new FragmentShader(Shaders.FRAGMENT_SHADER_ILLUMINATION));

            Light light = new Light(new Spherical(5, MathHelper.PiOver2, 0));

            obj = new WavefrontObj(@"..\..\ashtray.obj", program, null);
            obj.transformation = Matrix4.Scale(0.15f) * Matrix4.CreateRotationX(MathHelper.PiOver2);
            obj.light = light;

            LoadImageTexture.LoadTexture(@"..\..\texture.jpg");

            openGLControl1.objects.Add(obj);
            openGLControl1.light = light;

            openGLControl1.load();
        }
Ejemplo n.º 3
0
        public static void refreshLight(Light light)
        {
            bool up = pressed_keys[(int)Keys.I];
            bool down = pressed_keys[(int)Keys.K];
            bool right = pressed_keys[(int)Keys.L];
            bool left = pressed_keys[(int)Keys.J];

            if (up)
                light.position.growTheta();

            if (down)
                light.position.shrinkTheta();

            if (right)
                light.position.growPhi();

            if (left)
                light.position.shrinkPhi();
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Carga las luces que van a ser utilizadas en la escena
        /// </summary>
        /// <param name="xmlScene">La escena en XML</param>
        private void LoadLights(XElement xmlScene = null)
        {
            if (xmlScene != null && xmlScene.Elements("light_list").Any())
            {
                // Obtenemos el elemento con las luces
                XElement xmlLights = xmlScene.Elements("light_list").First();

                foreach (XElement xmlLight in xmlLights.Elements("light"))
                {
                    Vector position = LoadXYZDouble(xmlLight.Elements("position").First());
                    Vector color = LoadColor(xmlLight.Elements("color").First());
                    XElement attenuation = xmlLight.Elements("attenuation").First();
                    float quadratic = LoadFloat(attenuation, "quadratic");
                    float linear = LoadFloat(attenuation, "linear");
                    float constant = LoadFloat(attenuation, "constant");

                    // Creamos la luz
                    if (SceneLights.Count <= lightLimit)
                    {
                        Light light = new Light(position,
                                                diffuse: color,
                                                constantAttenuation: new Vector(constant, constant, constant),
                                                linearAttenuation: new Vector(linear, linear, linear),
                                                quadraticAttenuation: new Vector(quadratic, quadratic, quadratic));
                        SceneLights.Add(light);
                    }
                }
            }
            else
            {
                Vector position = new Vector(0, 5, 0);
                Vector color = new Vector(1, 1, 1);     // Luz blanca
                float quadratic = 0;
                float linear = 0;
                float constant = 1;

                Light light = new Light(position,
                                        diffuse: color,
                                        constantAttenuation: new Vector(constant, constant, constant),
                                        linearAttenuation: new Vector(linear, linear, linear),
                                        quadraticAttenuation: new Vector(quadratic, quadratic, quadratic));
                SceneLights.Add(light);
            }
        }