// JULIAN ARMANDO AGUILAR JUAREZ
// PROYECTO PELOTA
#include <GL/glut.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#define WIDTH 620
#define HEIGHT 450
void reshape(int width, int height){
glViewport(0,0,width,height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-WIDTH/2,WIDTH/2-1,-HEIGHT/2,HEIGHT/2-1,-1,1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void init(void){
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPointSize(2.0);
}
void Timer(int ex)
{
glutPostRedisplay();
glutTimerFunc(30,Timer,0);
}
int j=20;
void circle(int p,int m)
{
int x=0,y,g,t;
t=m;
y=t;
g=3-2*t;
while(x<=y)
{
glVertex2i(x,y+p);
glVertex2i(y,x+p);
glVertex2i(-x,y+p);
glVertex2i(-y,x+p);
glVertex2i(-x,-y+p);
glVertex2i(-y,-x+p);
glVertex2i(y,-x+p);
glVertex2i(x,-y+p);
if(g<0)
g=g+4*x+6;
else
{
g=g+4*(x-y)+10;
y--;
}
x++;
}
}
int t=100,flag=0;
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glColor3f(0.0,0.0,1.0);
glBegin(GL_POINTS);
circle(j,t);
if(flag==0)
{
if((j+t)<=200)
{
j=j+10;
}
if((j+t)>=200){
flag=1;
}
}
if(flag==1)
{
j=j-10;
if((j-t)<=-220)
{
flag=0;
}
}
glEnd();
glutSwapBuffers();
}
void idle(void){
/* do nothing */
}
int main(int argc, char **argv){
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
glutInitWindowPosition(0,0);
glutInitWindowSize(WIDTH,HEIGHT);
glutCreateWindow(argv[0]);
init();
glutIdleFunc(idle);
glutReshapeFunc(reshape);
glutDisplayFunc(display);
glutTimerFunc(0,Timer,0);
glutMainLoop();
return(1);
}
RESULTADO
No hay comentarios:
Publicar un comentario