public OpenGLController(CSGL12Control glControl)
 {
     RotateX_Angle = 25.0f;
     RotateY_Angle = -45.0f;
     _zoomZ = 8;
     _speed = 1000;
     AllowAnimate = true;
     _cube3D = new Cube3D(glControl.GetGL());
     MyGLControl = glControl;
 }
Beispiel #2
0
        public void OpenGLStarted(CSGL12Control csgl12Control)
        {
            GL gl = csgl12Control.GetGL();

            if (null == gl)
            {
                return;
            }
            // evitar parpadeos
            if (true == gl.bwglSwapIntervalEXT)
            {
                gl.wglSwapIntervalEXT(1);
            }
        }
Beispiel #3
0
        public void OpenGLStarted(CSGL12Control csgl12Control)
        {
            GL gl = csgl12Control.GetGL();

            if (null == gl) { return; }

            // Basic drawing conditions

            gl.glEnable(GL.GL_CULL_FACE);
            gl.glCullFace(GL.GL_BACK);
            gl.glFrontFace(GL.GL_CCW);

            //Activar iluminación
            gl.glEnable(GL.GL_LIGHTING);
            gl.glEnable(GL.GL_LIGHT0); //Luz del tren
            gl.glEnable(GL.GL_NORMALIZE); //garantizar vectores de luz apropiados
            //Modelo de iluminación
            float[] lmKa = { 0.2f, 0.2f, 0.0f, 0.1f }; //intensidad luz ambiental (0.2, 0.2, 0.2, 1) default
            gl.glLightModelfv(GL.GL_LIGHT_MODEL_AMBIENT, lmKa); //definir luz ambiental
            gl.glLightModeli(GL.GL_LIGHT_MODEL_LOCAL_VIEWER, GL.GL_TRUE); //luz local o infinita
            gl.glLightModeli(GL.GL_LIGHT_MODEL_TWO_SIDE, GL.GL_FALSE); //iluminar una o dos caras
            //Luz del tren
            float[] light_pos = { 0.0f, 0.0f, 0.0f, 0.0f };//direccional
            float[] light_amb = { 1.0f, 1.0f, 1.0f, 1.0f };//white light
            float[] light_dif = { 1.0f, 1.0f, 1.0f, 1.0f };//white light
            float[] light_spe = { 1.0f, 1.0f, 1.0f, 1.0f };//white light
            float[] light_dir = { 1.0f, 0.0f, 0.0f};
            gl.glLightfv(GL.GL_LIGHT0, GL.GL_POSITION, light_pos); //posición de la luz
            gl.glLightfv(GL.GL_LIGHT0, GL.GL_AMBIENT, light_amb); //color luz ambiental
            gl.glLightfv(GL.GL_LIGHT0, GL.GL_DIFFUSE, light_dif); //color de luz difusa
            gl.glLightfv(GL.GL_LIGHT0, GL.GL_SPECULAR, light_spe); //color de brillo
            gl.glLightf(GL.GL_LIGHT0, GL.GL_SPOT_CUTOFF, 15.0f); //apertura de la luz
            gl.glLightfv(GL.GL_LIGHT0, GL.GL_SPOT_DIRECTION, light_dir);//direccion de la luz
            gl.glLightf(GL.GL_LIGHT0, GL.GL_SPOT_EXPONENT, 50.0f); //intensidad de la luz
            gl.glLightf(GL.GL_LIGHT0, GL.GL_LINEAR_ATTENUATION, 5.0f); //atenuacion de la luz

            gl.glShadeModel(GL.GL_SMOOTH);								// enable smooth shading
            gl.glClearColor(0.0f, 0.0f, 0.0f, 0.5f);					// black background
            gl.glClearDepth(1.0f);										// depth buffer setup
            gl.glEnable(GL.GL_DEPTH_TEST);								// enables depth testing
            gl.glDepthFunc(GL.GL_LEQUAL);								// type of depth testing
            gl.glHint(GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST);	// nice perspective calculations

            // evitar parpadeos
            if (true == gl.bwglSwapIntervalEXT)
            {
                gl.wglSwapIntervalEXT(1);
            }
        }
Beispiel #4
0
        public void Paint(object sender, PaintEventArgs e)
        {
            if (null == sender)
            {
                return;
            }
            if (false == (sender is CSGL12Control))
            {
                return;
            }

            //Sacar el control de GL y sus dimensiones
            CSGL12Control csgl12Control = (sender as CSGL12Control);
            GL            gl            = csgl12Control.GetGL();

            int clientWidth  = csgl12Control.ClientRectangle.Width;
            int clientHeight = csgl12Control.ClientRectangle.Height;

            if (clientWidth <= 0)
            {
                clientWidth = 1;
            }

            if (clientHeight <= 0)
            {
                clientHeight = 1;
            }

            //Asignar un viewport
            gl.glViewport(0, 0, clientWidth, clientHeight);

            //Limpiar la pantalla con un color de fondo
            gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
            gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);

            //Asignar la vista del modelo
            gl.glMatrixMode(GL.GL_PROJECTION);
            gl.glLoadIdentity();
            double aspectRatio = 1.0;

            if (0 != clientHeight)
            {
                aspectRatio = ((double)(clientWidth) / (double)(clientHeight));
            }

            double verticalFieldOfViewAngle = 45.0;

            gl.gluPerspective
            (
                verticalFieldOfViewAngle, // Field of view angle (Y angle; degrees)
                aspectRatio,              // width/height
                0.1,                      // distance to near clipping plane
                64000.0                   // distance to far clipping plane
            );

            gl.glMatrixMode(GL.GL_MODELVIEW);

            gl.glLoadIdentity();
            //aqui va tu dibujito feo

            // Forzar el dibujado de todo y cambiar el buffer de ser necesario
            gl.wglSwapBuffers(csgl12Control.GetHDC());
        }
Beispiel #5
0
        //Metodo OpenGLStartes
        public void OpenGLStarted(CSGL12Control csgl12Control)
        {
            //Se ejecuta cada vez que se inicia Open GL.

            //Extraer la clase donde esta OpenGL, yo la hago para manejar OpenGL
            GL gl = csgl12Control.GetGL();

            if (null == gl) { return; }

            gl.glEnable(GL.GL_CULL_FACE);
            gl.glCullFace(GL.GL_BACK);
            gl.glFrontFace(GL.GL_CCW);

            //Iluminación
            gl.glEnable(GL.GL_LIGHTING);
            gl.glEnable(GL.GL_LIGHT1);//Luz tren
            gl.glEnable(GL.GL_NORMALIZE);
            //Modelo de iluminación
            float[] lmKa = { 0.8f, 0.8f, 0.8f, 0.1f }; //intensidad luz ambiental (0.2, 0.2, 0.2, 1) default
            gl.glLightModelfv(GL.GL_LIGHT_MODEL_AMBIENT, lmKa); //definir luz ambiental
            gl.glLightModeli(GL.GL_LIGHT_MODEL_LOCAL_VIEWER, GL.GL_TRUE); //luz local o infinita
            gl.glLightModeli(GL.GL_LIGHT_MODEL_TWO_SIDE, GL.GL_TRUE); //iluminar una o dos caras

            gl.glShadeModel(GL.GL_SMOOTH);								// enable smooth shading
            gl.glClearColor(0.0f, 0.0f, 0.0f, 0.5f);					// black background
            gl.glClearDepth(1.0f);										// depth buffer setup
            gl.glEnable(GL.GL_DEPTH_TEST);								// enables depth testing
            gl.glDepthFunc(GL.GL_LEQUAL);								// type of depth testing
            gl.glHint(GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST);	// nice perspective calculations

            if (true == gl.bwglSwapIntervalEXT)
            {
                gl.wglSwapIntervalEXT(1);
            }
        }
Beispiel #6
0
        public void Paint(object sender, PaintEventArgs e)
        {
            if (null == sender)
            {
                return;
            }
            if (false == (sender is CSGL12Control))
            {
                return;
            }
            //Sacar el control de GL y sus dimensiones
            CSGL12Control csgl12Control = (sender as CSGL12Control);
            GL            gl            = csgl12Control.GetGL();
            int           clientWidth   = csgl12Control.ClientRectangle.Width;
            int           clientHeight  = csgl12Control.ClientRectangle.Height;

            if (clientWidth <= 0)
            {
                clientWidth = 1;
            }
            if (clientHeight <= 0)
            {
                clientHeight = 1;
            }
            //Asignar un viewport
            gl.glViewport(0, 0, clientWidth, clientHeight);
            //Limpiar la pantalla con un color de fondo
            gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f); // NEGRO
            //gl.glClearColor(1.0f, 1.0f, 0.0f, 0.0f); // AMARILLO
            //gl.glClearColor(0.0f, 0.0f, 1.0f, 1.0f); // AZUL
            gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);

            //Proyección
            gl.glMatrixMode(GL.GL_PROJECTION);
            //El efecto de la proyeccion ortogonal es que podremos ver profundidad
            //VOy a poner aqui GL IDENTITY para que no se pierda el dibujo cuando
            //mueva la pantalla una vez realiada la proyeccion ortogonal
            gl.glLoadIdentity();
            //gl.glOrtho(0, 10, 0 , 5, -1, 1);

            gl.glMatrixMode(GL.GL_MODELVIEW);

            // CLASE DE DIBUJOS BASICOS ***************************************

            //aqui va tu dibujito feo
            //gl.glLoadIdentity();

            //Punto en el centro de la pantalla
            //gl.glBegin(GL.GL_POINTS);

            //GL_LINES Agarra los vertices de par en par y los denomina extremos de una linea
            //Se toman en el orden que se declaran
            //gl.glBegin(GL.GL_LINES);

            //GL_TRIANGLES agarra de tres en tres puntos y dibuja un triangulo en medio
            //gl.glBegin(GL.GL_TRIANGLES);

            //GL_QUADS hace lo mismo pero con puntos de cuatro en cuatro
            //el orden de los puntos sigue importando por que es como hará la geometría
            //el resultado es un cuadrilatero
            //gl.glBegin(GL.GL_QUADS);

            //TRIANGLE STRIP Y QUADSTRIP dibujan figuras regulares pero que se tocan y
            //provocan franjas vacias

            //LINE STRIP hace lineas que se tocan
            //gl.glBegin(GL.GL_LINE_STRIP);

            //GlColor me acepta colores RGB
            //gl.glColor3f(1.0f, 0, 0);

            //acepta tres flotantes
            //gl.glVertex3f(0, 0, 0);
            //3fv acepta arreglos de flotantes

            //gl.glColor3f(1.0f, 0, 1.0f);
            //gl.glVertex3f(-0.5f, 0.5f, 0);

            //gl.glColor3f(1.0f, 1.0f, 0);
            //float[] a = { 0.5f, 0.5f, 0 };
            //gl.glVertex3fv(a);

            //gl.glVertex3f(0, 0.5f, 0);

            //gl.glColor3f(1.0f, 0, 1.0f);
            //gl.glVertex3f(0.5f, 0.0f, 0);

            //gl.glColor3f(1.0f, 1.0f, 0);
            //gl.glVertex3f(-0.5f, -0.5f, 0);

            //iv acepta un arreglo de enteros

            //FIN DE LA CLASE DE DIBUJOS BASICOS **************************************

            //VAMOS AELABORAR UN ALGORITMO PARA PINTAR 100 PUNTOS EN UN ARREGLO FRACTAL

            //MOVER LA CAMARA
            //gl.gluLookAt(
            //    0, .5, .5,
            //    0, 0, 0,
            //    0, 1, 0
            //    );

            gl.glBegin(GL.GL_POINTS);
            //gl.glBegin(GL.GL_TRIANGLES);

            //Damos tres puntos iniciales
            float[] a = { -1f, 1f, -1f };
            float[] b = { 0, 1f, 0 };
            float[] c = { 0, -1f, 1f };

            gl.glVertex3fv(a);
            gl.glVertex3fv(b);
            gl.glVertex3fv(c);

            int    loteria;
            float  lottoHoy    = 1;
            float  lottoAyer   = 1;
            float  lottoAntier = 1;
            Random r           = new Random();

            float[] x = a;
            float[] y = { 0, 0, 0 };

            for (int i = 0; i < 9000; i++)
            {
                if (i > 0)
                {
                    if (i > 1)
                    {
                        lottoAntier = lottoAyer;
                    }
                    lottoAyer = lottoHoy;
                }

                loteria = r.Next(0, 3);
                Debug.WriteLine(loteria);
                //lottoHoy = loteria / 2.0f;
                lottoHoy = loteria / 2;
                //Debug.WriteLine(lottoHoy);

                //gl.glColor3f(lottoHoy, lottoAyer, lottoAntier);

                switch (loteria)
                {
                case 0:
                    //if (i > 0)
                    //{
                    //    if (i > 1)
                    //    {
                    //        lottoAntier = lottoAyer;
                    //    }
                    //    lottoAyer = lottoHoy;
                    //}
                    y[0] = (a[0] + x[0]) / 2;
                    y[1] = (a[1] + x[1]) / 2;
                    y[2] = (a[2] + x[2]) / 2;
                    //gl.glColor3f(1.0f, 0.0f, 0); //ROJO
                    gl.glColor3f(lottoHoy, lottoAyer, lottoAntier);
                    //gl.glColor3f(lottoHoy, lottoAyer, lottoAntier);
                    gl.glVertex3fv(y);
                    x = y;
                    break;

                case 1:
                    //if (i > 0)
                    //{
                    //    if (i > 1)
                    //    {
                    //        lottoAntier = lottoAyer;
                    //    }
                    //    lottoAyer = lottoAyer;
                    //}
                    y[0] = (b[0] + x[0]) / 2;
                    y[1] = (b[1] + x[1]) / 2;
                    y[2] = (b[2] + x[2]) / 2;
                    //gl.glColor3f(0.0f, 1.0f, 0); //VERDE
                    gl.glColor3f(lottoAntier, lottoHoy, lottoAyer);
                    //gl.glColor3f(lottoHoy, lottoAyer, lottoAntier);
                    gl.glVertex3fv(y);
                    x = y;
                    break;

                case 2:
                    //if (i > 0)
                    //{
                    //    if (i > 1)
                    //    {
                    //        lottoAntier = lottoHoy;
                    //    }
                    //    lottoAyer = lottoHoy;
                    //}
                    y[0] = (c[0] + x[0]) / 2;
                    y[1] = (c[1] + x[1]) / 2;
                    y[2] = (c[2] + x[2]) / 2;
                    //gl.glColor3f(0.0f, 0.0f, 1.0f); //AZUL
                    gl.glColor3f(lottoAyer, lottoAntier, lottoHoy);
                    //gl.glColor3f(lottoHoy, lottoAyer, lottoAntier);
                    gl.glVertex3fv(y);
                    x = y;
                    break;

                default:
                    break;
                }
            }

            gl.glEnd();

            // Forzar el dibujado de todo y cambiar el buffer de ser necesario
            gl.wglSwapBuffers(csgl12Control.GetHDC());
        }
 public void OpenGLStarted(CSGL12Control csgl12Control)
 {
 }
        void LoadCSGL(GL gl,CSGL12Control csglControl1)
        {
            int clientWidth=csglControl1.ClientRectangle.Width;
            int clientHeight=csglControl1.ClientRectangle.Height;
            if(clientWidth<=0)
                clientWidth=1;
            if(clientHeight<=0)
                clientHeight=1;
            gl.glViewport(0,0,clientWidth,clientHeight);
            gl.glMatrixMode(GL.GL_PROJECTION);
            gl.glLoadIdentity();

            double aspectRatio = 1.0;
            if (0 != clientHeight)
            {
                aspectRatio = (clientWidth / (double)(clientHeight));
            }

            gl.gluPerspective(45.0f, aspectRatio, 0.1f, 100.0f);
            gl.glMatrixMode(GL.GL_MODELVIEW);
            gl.glLoadIdentity();
        }