Professional Documents
Culture Documents
Codigo Codeblocks
Codigo Codeblocks
#include <windows.h>
#include <stdlib.h>
#include<conio.h>
#include <GL/glut.h>
#include <math.h>
// declaracion de variables
// GLfloat ...;
void sol(void){
glColor3f(1.0,1.0,0.0);
glBegin(GL_POLYGON);
x = radio * sin(ang);
y = radio * cos(ang);
glVertex2f(x,y);
glEnd();
void luna(void){
GLfloat ang, radio = 0.15f, x, y;
glColor3f(1.0,1.0,1.0);
glBegin(GL_POLYGON);
x = radio * sin(ang);
y = radio * cos(ang);
glVertex2f(x,y);
glEnd();
glColor3f(1.0,0.0,0.0);
glBegin(GL_LINE_LOOP);
radio=1/(sqrt(((pow(cos(ang),2))/(pow(a,2)))+((pow(sin(ang),2))/(pow(b,2)))))
;
x = radio * sin(ang);
y = radio * cos(ang);
glVertex2f(x,y);
glEnd();
void giroLuna(){
glBegin(GL_LINE_LOOP);
radio=(1/(sqrt(((pow(cos(ang),2))/(pow(0.6,2)))+((pow(sin(ang),2))/(pow(1.2,2
))))))+5.0;
x = radio * sin(ang);
y = radio * cos(ang);
glTranslated(x,y,0.0);
luna();
glFlush();
glutSwapBuffers();
void giroLuna2(){
radio=1/(sqrt(((pow(cos(ang),2))/(pow(0.6,2)))+((pow(sin(ang),2))/(pow(1.2,2)
))));
x = radio * sin(ang);
y = radio * cos(ang);
glTranslated(x,y,0.0);
luna();
ang += 2*GL_PI/100;
ang=0.0f;
}
// dibujamos nuestra escena
void display(void){
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
// composicion de rotaciones
glRotatef(theta[0],1.0,0.0,0.0);
glRotatef(theta[1],0.0,1.0,0.0);
glRotatef(theta[2],0.0,0.0,1.0);
elipse(0.6,1.2);
sol();
giroLuna2();
glFlush();
glutSwapBuffers();
theta[eje] += 0.05;
if(theta[eje]>360){
theta[eje] -= 360;
display();
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if(w <=h){
glOrtho(-2.0,2.0,-
2.0*(GLfloat)h/(GLfloat)w,2.0*(GLfloat)h/(GLfloat)w, -10.0, 10.0);
else{
glOrtho(-2.0*(GLfloat)w/(GLfloat)h,2.0*(GLfloat)w/(GLfloat)h, -
2.0,2.0,-10.0,10.0);
glMatrixMode(GL_MODELVIEW);
glutPostRedisplay();
switch(tecla){
{
glutInit(&argc, argv);
glutInitWindowSize(1000,650);
glutReshapeFunc(myReshape);
glutDisplayFunc(display);
//glutIdleFunc(giroLuna2);
//glutKeyboardFunc(teclado);
/*glutMouseFunc(mouse);*/
glEnable(GL_DEPTH_TEST);
glutMainLoop();
return 0;
Cdigo 2:
#include <GL\glut.h>
#include <Math.h>
#define PI 3.14159265f
int refreshMillis = 5;
void initGL() {
// color de fondo
void display() {
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();
glBegin(GL_TRIANGLE_FAN);
glVertex2f(0.0f, 0.0f);
GLfloat angle;
glEnd();
glutSwapBuffers();
/**
xPos += xSpeed;
yPos += ySpeed;
xPos = xPosMax;
xSpeed = -xSpeed;
xPos = xPosMin;
xSpeed = -xSpeed;
yPos = yPosMax;
ySpeed = -ySpeed;
yPos = yPosMin;
ySpeed = -ySpeed;
}**/
void Transicion(){
display();
xPos += xSpeed;
yPos += ySpeed;
xPos = xPosMax;
xSpeed = -xSpeed;
xPos = xPosMin;
xSpeed = -xSpeed;
yPos = yPosMax;
ySpeed = -ySpeed;
yPos = yPosMin;
ySpeed = -ySpeed;
//----------------------------------------------
if (height == 0) height = 1;
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
xLeft = -1.0;
xRight = 1.0;
}else {
yBottom = -1.0;
yTop = 1.0;
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glutPostRedisplay();
switch (boton){
case GLUT_LEFT_BUTTON:
if (estado = GLUT_DOWN){
xPos += xSpeed;
yPos += ySpeed;
if(x == xPos){
x= xPosMin;
xSpeed = -xSpeed;
y =yPosMin;
ySpeed= -ySpeed;
else{
glutPostRedisplay();
default:
break;
switch (tecla){
case 27 : exit(0);
break;
default:
break;
}
}
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE);
glutInitWindowSize(windowWidth, windowHeight);
glutInitWindowPosition(windowPosX, windowPosY);
glutCreateWindow(title);
//glutDisplayFunc(display);
glutDisplayFunc(Transicion);
glutReshapeFunc(reshape);
glutKeyboardFunc(teclado);
glutMouseFunc(raton);
initGL();
glutMainLoop();
return 0;