
//------------------------------------------------------------
// \archivo main.cpp
// \author Doglas Dembogurski
// \fecha 2-agosto-2008
// \Recontra copyright(c) 2008
// \Protector de Pantalla Utilizando una funcion matematica y Rotaciones
// \para dibujar figuras mientras dibuja la espira
//------------------------------------------------------------
#include
#include
#include
#include
#include
#include
#define HORIZONTAL 1024
#define VERTICAL 768
#define XINI 0
#define YINI 0
int VELOCIDAD = 2;
GLfloat anguloX = 0.0f;
GLfloat anguloY = 0.0f;
//----------Dibujar spirografo
//
int nPoints = 0;
double R = 0;
double G = 0;
double B = 0;
bool flag = true;
bool limit_flag = true;
void *font = GLUT_BITMAP_TIMES_ROMAN_24;
void *fonts[] =
{
GLUT_BITMAP_9_BY_15,
GLUT_BITMAP_TIMES_ROMAN_10,
GLUT_BITMAP_TIMES_ROMAN_24
};
char defaultMessage[] = "U.N.I. Graficos 2008";
char *message = defaultMessage;
void output(int x, int y, char *string){
int len, i;
glRasterPos2f(x, y);
len = (int) strlen(string);
for (i = 0; i < len; i++) {
glutBitmapCharacter(font, string[i]);
}
}
/** Esta funcion dibuja un Spirografo hasta un n incremental dado
* despues cambia de modalidad para dibujar funciones desconocidas
* la magia de los protectores de pantalla es que nunca se sabe lo
* que va a pasar.
*/
void dibujarEspira() {glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT);
//int nPoints = 1000;
double r1 = 60;
double r2 = 50;
double p = 70;
int i = 0;
glBegin(GL_LINES); //para crear lÃneas
int x1 = (int)(r1 + r2 - p);
int y1 = 0;
int x2;
int y2;
if(flag){
R++; G++; B--; if(R>200){ flag=false;}
}else{
R--; G--; B++; if(R<1){ flag=true;}
}
glColor3f(R /50, G ,B /50);
//glColor3f(R/50 , G ,anguloX);
// Dibujar una espira
for ( i = 0; i < nPoints; i++) {
double t = i * 0.3618 / 90;
x2 = (int)((r1+r2)* cos(t)-p * cos((r1+r2)*t/r2)) + 250;
y2 = (int)((r1+r2)* sin(t)-p * sin((r1+r2)*t/r2)) + 250;
glVertex2f(-1.0+((float) x1 / 250.0),1.0-((float) y1 /250.0));
glVertex2f(-1.0+((float) x2 / 250.0),1.0-((float) y2 /250.0));
if(nPoints > 8500){
// Aumentar la velocidad tal vez
VELOCIDAD = 50; // 50
}
x1 = x2;
y1 = y2;
}
glEnd();
//glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18,'A');
if(limit_flag){
nPoints+=VELOCIDAD;
if(nPoints > 15000){
glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT);
limit_flag = false;
}
}else{
nPoints-=VELOCIDAD;
if(nPoints < VELOCIDAD+1){ limit_flag = true;}
// Rotaciones mientras voy dibujando
glRotatef(anguloX, 1.0f, 0.0f, 0.0f);
glRotatef(anguloY, 0.0f, 1.0f, 0.0f);
gluPerspective(100 / 200, (GLfloat)HORIZONTAL/(GLfloat)VERTICAL, 1.0f, 20.0f);
glMatrixMode (GL_PROJECTION);
glPushMatrix();
glPopMatrix();
glFlush ();
glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT);
}
glutPostRedisplay();
//glFlush();
glutSwapBuffers();
anguloX+=0.1f;
anguloY+=0.1f;
}
void teclado(unsigned char key, int x, int y){
switch(key) {
case '+':
VELOCIDAD++;
break;
case '-':
VELOCIDAD--;
break;
case 'r':
case 'R':
R++;
break;
case 'e':
case 'E':
R--;
break;
case 'g':
case 'G':
G++;
case 'f':
case 'F':
G--;
case 'b':
case 'B':
B++;
case 'v':
case 'V':
B--;
break;
case 'x':
case 'X':
anguloX += 0.0f;
break;
case 'y':
case 'Y':
anguloY += 0.0f;
break;
case 27: // escape
exit(0);
break;
}
}
void idle(){
glutPostRedisplay();
dibujarEspira();
}
void letras(){
output(100, 100, message);
}
int main(int argc,char** argv) {
// inicializo glut
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DEPTH|GLUT_RGBA|GLUT_DOUBLE);
// Fijar tamaño de ventana
glutInitWindowSize(HORIZONTAL,VERTICAL);
glutInitWindowPosition(XINI,YINI);
// glutFullScreen(); // No funca el fullscreen
glutCreateWindow("Faculta de Ingenieria U.N.I. Graficos 2008");
glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT);
glutDisplayFunc(dibujarEspira);
//glutDisplayFunc(letras);
glutIdleFunc(idle);
glutKeyboardFunc(teclado);
// glutDisplayFunc(linea);
//}
//glutMouseFunc(rata);
glutMainLoop();
return 0;
}
No hay comentarios:
Publicar un comentario