Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <GL/glut.h>
- static int year = 0, day = 0;
- // Inicializa parâmetros de rendering
- void init(){
- glClearColor(0.0, 0.0, 0.0, 0.0);
- }
- //Função Callback chamada para fazer o desenho
- void display(){
- glClear(GL_COLOR_BUFFER_BIT);
- glColor3f(1.0, 1.0, 1.0);
- glBegin(GL_TRIANGLE_STRIP);
- glVertex2f(0.0, 0.0);
- glVertex2f(-0.5, 1.);
- glVertex2f(0.5, 1.);
- glEnd();
- glBegin(GL_TRIANGLE_STRIP);
- glVertex2f(0.0, 0.0);
- glVertex2f(-0.5, -1.);
- glVertex2f(0.5, -1.);
- glEnd();
- glBegin(GL_TRIANGLE_STRIP);
- glVertex2f(0.0, 0.0);
- glVertex2f(1, -0.5);
- glVertex2f(1, 0.5);
- glEnd();
- glBegin(GL_TRIANGLE_STRIP);
- glTranslatef((GLfloat) day, 0,0);
- glRotatef((GLfloat) day, .0, 0.0, 1.0);
- glVertex2f(0.0, 0.0);
- glVertex2f(-1, -0.5);
- glVertex2f(-1, 0.5);
- glEnd();
- glLineWidth(3.);
- glBegin(GL_LINE_STRIP);
- glVertex2f(.0, .0);
- glVertex2f(.0, -2.0);
- glEnd();
- // glPushMatrix();
- // glRotatef((GLfloat) year, 1.0, 0.0, 0.0);
- // glRotatef((GLfloat) day, 0.0, 0.0, 1.0);
- // glutWireSphere(1.0, 20, 16); /* Desenha o Sol */
- // glPopMatrix();
- //
- // glPushMatrix();
- // glRotatef((GLfloat) year, 0.0, 1.0, 0.0);
- // glTranslatef(2.0, -1.0, 0.0); /* Translada a partir do novo sistema de coordenadas resultante da rotação */
- // glRotatef((GLfloat) day, 0.0, 1.0, 0.0);
- // glutWireSphere(0.2, 10, 8); /* Desenha um planeta */
- // glPopMatrix();
- //
- // /* Criar segundo planeta */
- // glPushMatrix();
- // glRotatef((GLfloat) year, 0.0, -1.0, 0.0);
- // glTranslatef(-2.0, 1.0, 0.0); /* Translada a partir do novo sistema de coordenadas resultante da rotação */
- // glRotatef((GLfloat) day, 0.0, 1.0, 0.0);
- // glutWireSphere(0.2, 10, 8); /* Desenha um planeta */
- // glPopMatrix();
- glutSwapBuffers();
- }
- void reshape(int w, int h){
- glViewport(0, 0, (GLsizei) w, (GLsizei) h);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- gluPerspective(60.0, (GLfloat) w/(GLfloat) h, 1.0, 20.0);
- gluLookAt(0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); //Posição da Câmera
- }
- void keyboard(unsigned char key, int x, int y){
- switch (key){
- case 'd':
- day = (day + 10) % 360; //% valor do resto
- glutPostRedisplay(); // Redesenha a cena com novas coordenadas, é executado no glutMainLoop;
- break;
- case 'D':
- day = (day - 10) % 360;
- glutPostRedisplay();
- break;
- case 'y':
- year = (year + 5) % 360;
- glutPostRedisplay();
- break;
- case 'Y':
- year = (year - 5) % 360;
- glutPostRedisplay();
- break;
- case 27:
- exit(0);
- break;
- default:
- break;
- }
- }
- int main(int argc, char *argv[]) {
- /* inicializa o sitema GLUT */
- glutInit(&argc, argv);
- glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
- glutInitWindowSize(500,500);
- glutInitWindowPosition(100,100);
- glutCreateWindow("Rotação de planetas");
- //chama a funcao init e inicia as propriedades View Port
- init();
- /* Callback para mostrar objetos na tela */
- glutDisplayFunc(display);
- glutReshapeFunc(reshape);
- glutKeyboardFunc(keyboard);
- glutMainLoop();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement