Beispiel #1
0
        public Drawable3D(ProgramObject program)
        {
            this.program = program;

            projection_location = GL.GetUniformLocation(program.program_handle, "projectionMatrix");
            model_view_location = GL.GetUniformLocation(program.program_handle, "modelView");
            normal_location = GL.GetUniformLocation(program.program_handle, "normalMatrix");

            light_position_location = GL.GetUniformLocation(program.program_handle, "light_position");
            light_intensity_location = GL.GetUniformLocation(program.program_handle, "light_intensity");
            material_ka_location = GL.GetUniformLocation(program.program_handle, "material_ka");
            material_kd_location = GL.GetUniformLocation(program.program_handle, "material_kd");
            material_ks_location = GL.GetUniformLocation(program.program_handle, "material_ks");
            material_shine_location = GL.GetUniformLocation(program.program_handle, "material_shine");
            colored_location = GL.GetUniformLocation(program.program_handle, "colored");
            alpha_location = GL.GetUniformLocation(program.program_handle, "alpha");
            noise_location = GL.GetUniformLocation(program.program_handle, "noise");
            illumination_model_location = GL.GetUniformLocation(program.program_handle, "illum_model");
            roughness_location = GL.GetUniformLocation(program.program_handle, "fRoughness");
            reflect_location = GL.GetUniformLocation(program.program_handle, "reflecAtNormalIncidence");

            // Vertex Data
            GL.GenBuffers(1, out VBO_ID);
            GL.GenBuffers(1, out EBO_ID);
            GL.GenVertexArrays(1, out VAO_ID);

            // Normal Data
            GL.GenBuffers(1, out NVBO_ID);
            GL.GenBuffers(1, out NEBO_ID);
            GL.GenVertexArrays(1, out NVAO_ID);
        }
Beispiel #2
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();
        }
Beispiel #3
0
        public Cylinder(float radius, float height, int faces, Vector4 color, ProgramObject program)
            : base(1, program)
        {
            float step = 2 * (float)Math.PI / faces;
            float theta = (float) Math.PI / 4;

            Vertex[] base_vertices = new Vertex[faces];

            for (int i = 0; i < faces; i++, theta += step)
            {
                float x = radius * (float)Math.Cos(theta);
                float y = radius * (float)Math.Sin(theta);
                base_vertices[i] = new Vertex(x, y, 0, 1f);
                base_vertices[i].color = color;

                // Bottom normal pointing down and its texture
                base_vertices[i].normal = new Vector4(x, y, -100f, 0f);
                base_vertices[i].texture = new Vector4(new Vector2((184 + 128 * (float)Math.Cos(theta)) / 500, (188 + 128 * (float)Math.Sin(theta)) / 375));
                //Console.WriteLine(base_vertices[i].texture.ToString());
            }

            Vector2[][] textures = new Vector2[faces][];
            float mapping_step = (float) 1 / faces;
            Console.WriteLine("Start");
            for (int i = 0; i < faces; i++)
            {
                textures[i] = new Vector2[4];
                textures[i][0] = new Vector2(mapping_step * i, 0);
                textures[i][1] = new Vector2(mapping_step * (i + 1), 0);
                textures[i][2] = new Vector2(mapping_step * i, 1f);
                textures[i][3] = new Vector2(mapping_step * (i + 1), 1f);
                Console.WriteLine(textures[i].ToString());
            }
            Console.WriteLine("Finish");
            createSweep(
                base_vertices,
                color,
                new Func<int, int, Matrix4>(
                    delegate(int current, int steps)
                    {
                        return Matrix4.CreateTranslation(new Vector3(0f, 0f, height));
                    }
                ),
                new Func<int, int, Matrix4>(
                    delegate(int current, int steps)
                    {
                        return Matrix4.Identity;
                    }
                ),
                new Func<int, int, Matrix4>(
                    delegate(int current, int steps)
                    {
                        return Matrix4.Identity;
                    }
                ),
                textures
             );
        }
Beispiel #4
0
        public Foot(float height, int num_steps, ProgramObject program)
            : base(num_steps, program)
        {
            Vertex[] vertices = new Vertex[]{
                new Vertex(new Vector4(1f, -1f, 0, 1f)),
                new Vertex(new Vector4(1f, 1f, 0, 1f)),
                new Vertex(new Vector4(-1f, 1f, 0, 1f)),
                new Vertex(new Vector4(-1f, -1f, 0, 1f)),
            };

            Vector2[][] textures = new Vector2[vertices.Length][];
            for (int i = 0; i < vertices.Length; i+=2)
            {
                textures[i] = new Vector2[4];
                textures[i][0] = new Vector2((i % 2) / 2, 0);
                textures[i][1] = new Vector2((i % 2) / 2 + 0.75f, 0);
                textures[i][2] = new Vector2((i % 2) / 2, 1f);
                textures[i][3] = new Vector2((i % 2) / 2 + 0.75f, 1f);
            }

            for (int i = 1; i < vertices.Length; i+= 2)
            {
                textures[i] = new Vector2[4];
                textures[i][0] = new Vector2((i % 2) / 2 + 0.75f, 0);
                textures[i][1] = new Vector2(1f, 0);
                textures[i][2] = new Vector2((i % 2) / 2 + 0.75f, 1f);
                textures[i][3] = new Vector2(1f, 1f);
            }

            float height_step = height / num_steps;

            createSweep(vertices, new Vector4(0, 1f, 0, 1f),
                new Func<int, int, Matrix4>(
                    delegate(int current, int steps)
                    {
                        return Matrix4.CreateTranslation(new Vector3(0, 0, (current + 1) * height_step));
                    }
                ),
                new Func<int, int, Matrix4>(
                    delegate(int current, int steps)
                    {
                        return Matrix4.Identity;
                    }
                ),
                new Func<int, int, Matrix4>(
                    delegate(int current, int steps)
                    {
                        current++;

                        float pend = 4 * 0.5f / (float)Math.Pow(steps * 0.1f, 2);
                        float scale_factor = (float)(pend * Math.Pow(current * 0.1f - steps * 0.1f / 2f, 2) + 0.5f);
                        return Matrix4.Scale(scale_factor, scale_factor, 1f);
                    }
                )
                , textures);
        }
Beispiel #5
0
        public static void addDrawable(Drawable2D drawable, BeginMode begin_mode, ProgramObject program)
        {
            DrawingInfo drawing_info = new DrawingInfo();
            drawing_info.begin_mode = begin_mode;
            drawing_info.program = program;

            GL.GenVertexArrays(1, out drawing_info.VAO_ID);
            GL.GenBuffers(1, out drawing_info.VBO_ID);

            objects.Add(drawable, drawing_info);
        }
Beispiel #6
0
Datei: Draw.cs Projekt: GNZ/CG
        public Draw(ProgramObject program, BeginMode begin_mode)
            : base(program, begin_mode)
        {
            /*Triangle t = new Triangle(new Vertex[]{
                new Vertex(new Vector4(0, 0, 0, 1f)),
                new Vertex(new Vector4(0.5f, 0.5f, 0, 1f)),
                new Vertex(new Vector4(0.5f, 0, 0, 1f)),
            });

            triangles.Add(t);*/

            //triangles.triangulate(sweep.polynet.faces.ToArray());
        }
Beispiel #7
0
        private void openGLControl1_Load(object sender, EventArgs e)
        {
            ProgramObject program = new ProgramObject(
               new VertexShader(Shaders.VERTEX_TRANSFORMATION_SHADER),
                   new FragmentShader(Shaders.DEFAULT_FRAGMENT_SHADER));

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

            openGLControl1.objects.Add(obj);

            openGLControl1.load();
        }
Beispiel #8
0
        public WavefrontObj(string path, ProgramObject program, Material material = null)
            : base(program)
        {
            this.material = material;
            SharpObjLoader obj = new SharpObjLoader(path, material);

            ebos = obj.ebos;

            toDraw = obj.vertices.ToArray();

            //draw_normals = true;

            base.fillArrayBuffer(false);
        }
Beispiel #9
0
Datei: Cover.cs Projekt: GNZ/CG
        public Cover(float height, float width, float lenght,float radius, int num_steps, ProgramObject program)
            : base(num_steps, program)
        {
            float x = width / 2;
            float y = lenght / 2;
            Vertex[] vertices = new Vertex[]{
               new Vertex(-x, -y + radius, 0, 1.0f),
               new Vertex(-x + radius, -y, 0, 1.0f),
               new Vertex(x - radius, -y, 0, 1.0f),
               new Vertex(x, -y + radius, 0, 1.0f),
               new Vertex(x, y - radius, 0, 1.0f),
               new Vertex(x - radius, y, 0, 1),
               new Vertex(-x + radius, y, 0, 1.0f),
               new Vertex(-x, y - radius, 0, 1.0f)
            };

            Vector2[][] textures = new Vector2[vertices.Length][];
            for (int i = 0; i < vertices.Length; i++)
            {
                textures[i] = new Vector2[4];
                textures[i][0] = new Vector2((i % 2) / 2, 0);
                textures[i][1] = new Vector2((i % 2) / 2 + 0.5f, 0);
                textures[i][2] = new Vector2((i % 2) / 2, 1f);
                textures[i][3] = new Vector2((i % 2) / 2 + 0.5f, 1f);
            }

            float height_step = height / num_steps;

            createSweep(vertices, new Vector4(0, 1f, 0, 1f),
                new Func<int, int, Matrix4>(
                    delegate(int current, int steps)
                    {
                        return Matrix4.CreateTranslation(new Vector3(0, 0, height_step));
                    }
                ),
                new Func<int, int, Matrix4>(
                    delegate(int current, int steps)
                    {
                        return Matrix4.Identity;
                    }
                ),
                new Func<int, int, Matrix4>(
                    delegate(int current, int steps)
                    {
                        return Matrix4.Identity;
                    }
                )
                , textures);
        }
Beispiel #10
0
        public Drawable3D(ProgramObject program, BeginMode begin_mode)
        {
            this.begin_mode = begin_mode;
            this.program = program;

            projection_location = GL.GetUniformLocation(program.program_handle, "projectionMatrix");
            model_view_location = GL.GetUniformLocation(program.program_handle, "modelView");
            normal_location = GL.GetUniformLocation(program.program_handle, "normalMatrix");

            light_position_location = GL.GetUniformLocation(program.program_handle, "light_position");
            light_intensity_location = GL.GetUniformLocation(program.program_handle, "light_intensity");
            material_ka_location = GL.GetUniformLocation(program.program_handle, "material_ka");
            material_kd_location = GL.GetUniformLocation(program.program_handle, "material_kd");
            material_ks_location = GL.GetUniformLocation(program.program_handle, "material_ks");
            material_shine_location = GL.GetUniformLocation(program.program_handle, "material_shine");
            colored_location = GL.GetUniformLocation(program.program_handle, "colored");
        }
Beispiel #11
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();
        }
Beispiel #12
0
Datei: Form1.cs Projekt: GNZ/CG
        private void OpenGLcontrol_load(object sender, EventArgs e)
        {
            ProgramObject prog = new ProgramObject(
                new VertexShader(Shaders.VERTEX_SHADER_TEXTURE),
                    new FragmentShader(Shaders.FRAGMENT_SHADER_ILLUMINATION));

            //Draw draw = new Draw(prog, BeginMode.LineLoop);

            /*Vertex[] vertices = new Vertex[]{
                new Vertex(new Vector4(0.5f, -0.5f, 0, 1f)),
                new Vertex(new Vector4(-0.5f, -0.5f, 0, 1f)),
                new Vertex(new Vector4(-0.5f, 0.5f, 0, 1f)),
                new Vertex(new Vector4(0.5f, 0.5f, 0, 1f)),
            };*/

               Cylinder sweepF = new Cylinder(50f,0.1f,4,new Vector4(1f, 0,0,1f),prog);
            openGLControl1.objects.Add(sweepF);

              Cover[] sweeps = new Cover[9];

            for (int i = 0; i < 9; i++)
            {
                sweeps[i] = new Cover(15, size, size, aux, 1, prog);
                sweeps[i].colored = true;
                openGLControl1.objects.Add(sweeps[i]);
            }

            //openGLControl1.objects.Add(sweep);

            //sweep.transformation = Matrix4.CreateTranslation(0, -0.65f, 0);
            //sweep2.transformation = Matrix4.CreateTranslation(0, 0, 0);
            sweeps[1].transformation = Matrix4.CreateTranslation(distance, 0.0f, 0.0f);
            sweeps[2].transformation = Matrix4.CreateTranslation(-distance, 0.0f, 0.0f);
            sweeps[3].transformation = Matrix4.CreateTranslation(0.0f, distance, 0);
            sweeps[4].transformation = Matrix4.CreateTranslation(0.0f, -distance, 0);
            sweeps[5].transformation = Matrix4.CreateTranslation(distance, distance, 0);
            sweeps[6].transformation = Matrix4.CreateTranslation(-distance, distance, 0);
            sweeps[7].transformation = Matrix4.CreateTranslation(-distance, -distance, 0);
            sweeps[8].transformation = Matrix4.CreateTranslation(distance, -distance, 0);

            openGLControl1.load();
        }
Beispiel #13
0
        private void OpenGLcontrol_load(object sender, EventArgs e)
        {
            ProgramObject program = new ProgramObject(
                new VertexShader(Shaders.VERTEX_TRANSFORMATION_SHADER),
                    new FragmentShader(Shaders.DEFAULT_FRAGMENT_SHADER));

            Foot foot = new Foot(2f, 20, program);
            Cover cover = new Cover(0.5f, 1, program);

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

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

            foot.wire_mode = true;
            cover.wire_mode = true;

            openGLControl1.load();
        }
Beispiel #14
0
        private void openGLControl1_Load(object sender, EventArgs e)
        {
            program = new ProgramObject(
               new VertexShader(Shaders.VERTEX_SHADER_TEXTURE),
                   new FragmentShader(Shaders.FRAGMENT_SHADER_TEXTURE));

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

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

            foot = new Foot(2f, 20, program);
            cover = new Cover(0.25f, 1, program);

            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.load();
        }
Beispiel #15
0
Datei: Foot.cs Projekt: GNZ/CG
        public Foot(float height, int num_steps, ProgramObject program)
            : base(num_steps, program)
        {
            Vertex[] vertices = new Vertex[]{
                new Vertex(new Vector4(1f, -1f, 0, 1f)),
                new Vertex(new Vector4(-1f, -1f, 0, 1f)),
                new Vertex(new Vector4(-1f, 1f, 0, 1f)),
                new Vertex(new Vector4(1f, 1f, 0, 1f)),
            };

            Vector2[][] textures = new Vector2[vertices.Length][];
            for (int i = 0; i < vertices.Length; i++)
            {
                textures[i] = new Vector2[4];
                textures[i][0] = new Vector2((i % 2) / 2, 0);
                textures[i][1] = new Vector2((i % 2) / 2 + 1f, 0);
                textures[i][2] = new Vector2((i % 2) / 2, 1f);
                textures[i][3] = new Vector2((i % 2) / 2 + 1f, 1f);
            }

            float height_step = height / num_steps;

            createSweep(vertices, new Vector4(0, 1f, 0, 1f),
                new Func<int, int, Matrix4>(
                    delegate(int current, int steps)
                    {
                        return Matrix4.CreateTranslation(new Vector3(0, 0, (current + 1) * height_step));
                    }
                ),
                new Func<int, int, Matrix4>(
                    delegate(int current, int steps)
                    {
                        return Matrix4.Identity;
                    }
                ),
                new Func<int, int, Matrix4>(
                    delegate(int current, int steps)
                    {
                        current++;

                        float pend = 4 * 0.5f / (float)Math.Pow(steps * 0.1f, 2);
                        float scale_factor = (float)(pend * Math.Pow(current * 0.1f - steps * 0.1f / 2f, 2) + 0.5f);
                        return Matrix4.Scale(scale_factor, scale_factor, 1f);
                    }
                )
                , textures);

            /*
            Vertex[][] toDraw = new Vertex[firstFace.Length + 2][];
            //indices = new int[firstFace.Length + 2];
            //count = new int[firstFace.Length + 2];

            // agregar caras extrudadas
            for (int i = 0; i < firstFace.Length; i++)
            {
                int messi = 0;
                toDraw[i] = new Vertex[(2 + 2 * steps)*4];
                HalfEdge current = polynet.halfEdges[firstFace[i]][firstFace[(i + 1) % firstFace.Length]];

                // first
                toDraw[i][messi++] = current.origin.position;

                for (int j = 0; j < steps; j++)
                {
                    // right (all parameters)
                    toDraw[i][messi++] = current.next.origin.position;
                    // left
                    toDraw[i][messi++] = current.prev.origin.position;

                    current = polynet.halfEdges[current.prev.origin][current.next.next.origin];

                }
                // latest
                toDraw[i][messi++] = current.next.next.origin.position;

            }*/
        }
Beispiel #16
0
        private void glControl1_Load(object sender, EventArgs e)
        {
            program = new ProgramObject(
            new VertexShader(Shaders.VERTEX_TRANSF_SHADER), new FragmentShader(Shaders.DEFAULT_FRAGMENT_SHADER));
            GL.ClearColor(Color.Black);

            GL.GenVertexArrays(1, out VAO_ID);
            GL.GenBuffers(1, out VBO_ID);

            projection_location = GL.GetUniformLocation(program.program_handle, "projectionMatrix");
            model_view_location = GL.GetUniformLocation(program.program_handle, "modelView");

            GL.BindVertexArray(VAO_ID);
            GL.BindBuffer(BufferTarget.ArrayBuffer, VBO_ID);
            GL.EnableVertexAttribArray(0);
            GL.VertexAttribPointer(0, 4, VertexAttribPointerType.Float, false, 0, 0);
        }
Beispiel #17
0
 public Sweep(int steps, ProgramObject program)
     : base(program)
 {
     this.steps = steps;
 }
Beispiel #18
0
 public Car(string path, ProgramObject program, Material material = null)
     : base(path, program, material)
 {
     transformation = Matrix4.CreateRotationZ((float)Math.PI) * transformation;
 }
Beispiel #19
0
 public GlutDraw(ProgramObject program, Action primitive)
     : base(program)
 {
     this.glutPrimitive = primitive;
 }
Beispiel #20
0
        public Cover(float height, int num_steps, ProgramObject program)
            : base(num_steps, program)
        {
            float x = 2.0f;
            float y = 2.0f;
            float z = 2f;
            float aux = 0.15f;

            Vertex[] vertices = new Vertex[]{
               new Vertex(-x, -y + aux, z, 1.0f),
               new Vertex(-x + aux, -y, z, 1.0f),
               new Vertex(x - aux, -y, z, 1.0f),
               new Vertex(x, -y + aux, z, 1.0f),
               new Vertex(x, y - aux, z, 1.0f),
               new Vertex(x - aux, y, z, 1.0f),
               new Vertex(-x + aux, y, z, 1.0f),
               new Vertex(-x, y - aux, z, 1.0f)
            };

            float step = 2 * (float)Math.PI / vertices.Length;
            float theta = (float)Math.PI / 4;
            float radius = 2f;

            for (int i = 0; i < vertices.Length; i++, theta += step)
            {
                // Bottom normal pointing down and its texture
                vertices[i].texture = new Vector4(new Vector2((184 + 128 * (float)Math.Cos(theta)) / 500, (188 + 128 * (float)Math.Sin(theta)) / 375));
                //Console.WriteLine(base_vertices[i].texture.ToString());
            }

            Vector2[][] textures = new Vector2[vertices.Length][];
            for (int i = 0; i < vertices.Length; i++)
            {
                textures[i] = new Vector2[4];
                textures[i][0] = new Vector2((i % 2) / 2, 0);
                textures[i][1] = new Vector2((i % 2) / 2 + 0.5f, 0);
                textures[i][2] = new Vector2((i % 2) / 2, 1f);
                textures[i][3] = new Vector2((i % 2) / 2 + 0.5f, 1f);
            }

            float height_step = height / num_steps;

            createSweep(vertices, new Vector4(0, 1f, 0, 1f),
                new Func<int, int, Matrix4>(
                    delegate(int current, int steps)
                    {
                        return Matrix4.CreateTranslation(new Vector3(0, 0, height_step));
                    }
                ),
                new Func<int, int, Matrix4>(
                    delegate(int current, int steps)
                    {
                        return Matrix4.Identity;
                    }
                ),
                new Func<int, int, Matrix4>(
                    delegate(int current, int steps)
                    {
                        return Matrix4.Identity;
                    }
                )
                , textures);
        }
Beispiel #21
0
Datei: Sweep.cs Projekt: GNZ/CG
 public Sweep(int steps, ProgramObject program)
     : base(program, BeginMode.TriangleStrip)
 {
     this.steps = steps;
 }
Beispiel #22
0
Datei: Lab8.cs Projekt: GNZ/CG
        private void openGLControl1_Load(object sender, EventArgs e)
        {
            ProgramObject program = new ProgramObject(
                new VertexShader(Shaders.VERTEX_SHADER_TEXTURE),
                    new FragmentShader(Shaders.FRAGMENT_SHADER_ILLUMINATION));

            // Constants
            int num = 10;
            float radius = 1.0f;
            float height = radius * 4f;
            cylinder = new Cylinder(radius, height, num, new Vector4(0, 1f, 0, 1f), program);
            //cylinder.colored = false;

            cover = new Cover(0.5f,10f,20f,0.5f, 5, program);
            cover.colored = false;

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

            /*** 3D AXES ***/

            /* X */
            cone_x = new Cone(0.1f, 0.2f, 10, new Vector4(1, 0, 0, 1f), program);
            cone_x.transformation = Matrix4.CreateRotationY((float)Math.PI / 2);
            cone_x.transformation *= Matrix4.CreateTranslation(1f, 0f, 0f);
            x_axis = new Cylinder(0.05f, 1f,  10,new Vector4(1, 0, 0, 1f), program);
            x_axis.transformation = Matrix4.CreateRotationY((float)Math.PI / 2);

            /* Y */
            cone_y = new Cone(0.1f, 0.2f, 10, new Vector4(0, 1f, 0, 1f), program);
            cone_y.transformation = Matrix4.CreateRotationX((float)-Math.PI / 2);
            cone_y.transformation *= Matrix4.CreateTranslation(0f, 1f, 0f);
            y_axis = new Cylinder(0.05f, 1f, 10, new Vector4(0, 1f, 0, 1f), program);
            y_axis.transformation = Matrix4.CreateRotationX((float)-Math.PI / 2);

            /* Z */
            cone_z = new Cone(0.1f, 0.2f, 10, new Vector4(0, 0, 1f, 1f), program);
            cone_z.transformation = Matrix4.CreateTranslation(0f, 0f, 1f);

            z_axis = new Cylinder(0.05f, 1f, 10, new Vector4(0, 0, 1f, 1f), program);

            /**************/
            floor = new Cylinder(100f, 0.1f, 4,new Vector4(0.5f, 0.5f, 0.5f, 1f), program);

            // Load texture
            Utilities.LoadImageTexture.LoadTexture(@"..\..\texture.jpg");

            // Add the objects to the selector
            objectSelector1.AddObject(cone_x);
            objectSelector1.AddObject(cone_y);
            objectSelector1.AddObject(cone_z);
            objectSelector1.AddObject(x_axis);
            objectSelector1.AddObject(y_axis);
            objectSelector1.AddObject(z_axis);
            objectSelector1.AddObject(foot);
            objectSelector1.AddObject(cover);
            objectSelector1.AddObject(cylinder);
            objectSelector1.AddObject(floor);

            objectSelector1.open_gl_control = openGLControl1;

            objectSelector1.SelectedIndices.Add(6);
            objectSelector1.SelectedIndices.Add(7);
            objectSelector1.SelectedIndices.Add(9);

            openGLControl1.load();
        }
Beispiel #23
0
        private void openGLControl1_Load(object sender, EventArgs e)
        {
            ProgramObject program = new ProgramObject(
                new VertexShader(Shaders.VERTEX_TRANSFORMATION_SHADER),
                    new FragmentShader(Shaders.DEFAULT_FRAGMENT_SHADER));

            Glut.glutInit();

            // Cubo Grande
            GlutDraw big_cube = new GlutDraw(program, () => { Glut.glutWireCube(5f); });
            big_cube.transformation = Translation(2.5f, 2.5f, 2.5f);

            // Cono X
            GlutDraw cone_x = new GlutDraw(program, () => { Glut.glutWireCone(0.5, 0.75, 10, 10); });
            cone_x.transformation = Matrix4.CreateRotationY(MathHelper.PiOver2) * Translation(2.5f, 0,0);

            // Cono Y
            GlutDraw cone_y = new GlutDraw(program, () => { Glut.glutWireCone(0.5, 0.75, 10, 10); });
            cone_y.transformation = Matrix4.CreateRotationX(-MathHelper.PiOver2) * Translation(0,2.5f, 0);

            // Cono Z
            GlutDraw cone_z = new GlutDraw(program, () => { Glut.glutWireCone(0.5, 0.75, 10, 10); });
            cone_z.transformation = Translation(0, 0, 2.5f);

            // Tetera
            GlutDraw teapot = new GlutDraw(program, () => { Glut.glutWireTeapot(1); });
            teapot.transformation = Matrix4.Scale(0.5f) * Matrix4.CreateRotationZ(MathHelper.PiOver2) * Translation(5, 5, 5);

            // Esfera
            GlutDraw sphere = new GlutDraw(program, () => { Glut.glutWireSphere(1f, 10, 10); });
            sphere.transformation = Matrix4.CreateRotationY(MathHelper.PiOver2) * Translation(0, 5, 5);

            // Cono
            GlutDraw cone = new GlutDraw(program, () => { Glut.glutWireCone(1, 2, 10, 10); });
            cone.transformation = Matrix4.CreateRotationY(MathHelper.PiOver2) * Translation(5,5,0);

            // Cubo Chico
            GlutDraw small_cube = new GlutDraw(program, () => { Glut.glutWireCube(1); });
            small_cube.transformation = Translation(5, 0, 5);

            // Cilindro
            GlutDraw cylinder = new GlutDraw(program, () => { Glut.glutWireCylinder(0.5, 2, 10, 10); });
            cylinder.transformation = Matrix4.CreateRotationY(MathHelper.PiOver2) * Translation(5, 0, 0);

            // Toroide
            GlutDraw torus = new GlutDraw(program, () => { Glut.glutWireTorus(0.5, 0.75, 10, 10); });
            torus.transformation = Translation(0, 0, 5);

            // Dodecaedro
            GlutDraw dodecaedron = new GlutDraw(program, () => { Glut.glutWireDodecahedron(); });
            dodecaedron.transformation = Translation(0, 5, 0);

            openGLControl1.objects.Add(big_cube);
            openGLControl1.objects.Add(cone_x);
            openGLControl1.objects.Add(cone_y);
            openGLControl1.objects.Add(cone_z);
            openGLControl1.objects.Add(teapot);
            openGLControl1.objects.Add(sphere);
            openGLControl1.objects.Add(cone);
            openGLControl1.objects.Add(small_cube);
            openGLControl1.objects.Add(cylinder);
            openGLControl1.objects.Add(torus);
            openGLControl1.objects.Add(dodecaedron);

            openGLControl1.setSphericalCamera(new SphericalCamera(new Spherical(15, MathHelper.PiOver3, MathHelper.PiOver6)));

            openGLControl1.load();
        }