Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Desafio: verificar o modelview
- */
- #include <iostream>
- #include <GL/freeglut.h>
- static int year = 0, day = 0;
- void init (void)
- {
- /* selecionar cor de fundo (preto) */
- glClearColor(0.0, 0.0, 0.0, 0.0);
- //Definindo os limites da Porta de Visao (ViewPort)
- }
- //desenha as transformacoes
- void display(void){
- glClear(GL_COLOR_BUFFER_BIT);
- glColor3f(1.0, 1.0, 1.0);
- glPushMatrix(); //Sun
- glRotatef(year, 1.0, 0.0, 0.0);
- glRotatef(day, 0.0, 0.0, 1.0);
- glutWireSphere(1.0, 20, 16);
- glPopMatrix();
- glPushMatrix();// Planet 1
- glRotatef(year, 0.0, 1.0, 0.0);
- glTranslatef(2.0, 0.0, 0.0);
- glRotatef(day, 0.0, 1.0, 0.0);
- glutWireSphere(0.2, 10, 8);
- glPopMatrix();
- glPushMatrix(); // Planet 2
- glRotatef(year, 0.0, 1.0, 0.0);
- glTranslatef(4.0, 0.0, 0.0);
- glRotatef(day, 0.0, 1.0, 0.0);
- glutWireSphere(0.2, 10, 8);
- glPopMatrix();
- glPushMatrix(); // Moon 1
- glRotatef(year, 0.0, 1.0, 0.0);
- glTranslatef(4.0, 0.0, 0.0);
- glRotatef(day*0.1, 0.0, 1.0, 0.0);
- glTranslatef(0.5, 0.0, 0.0);
- glutWireSphere(0.1, 10, 8);
- glPopMatrix();
- glPushMatrix(); // Moon 2
- glRotatef(year, 0.0, 1.0, 0.0);
- glTranslatef(4.0, 0.0, 0.0);
- glRotatef(day*0.1, 0.0, 0, 1.0);
- glTranslatef(0.5, 0.0, 0.0);
- glutWireSphere(0.1, 10, 8);
- glPopMatrix();
- glutSwapBuffers();
- }
- void keyboard(unsigned char key, int x, int y) {
- switch (key) {
- case 'd':
- day = (day + 10) % 360;
- glutPostRedisplay();
- 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;
- }
- }
- void reshape(int w, int h){
- glViewport (0, 0, w, h);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- gluPerspective(120.0, w/h, 1.0, 20.0);
- gluLookAt (0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
- }
- void update(int value){
- glutTimerFunc(10, update, 1);
- day += year++;
- glutPostRedisplay();
- }
- int main(int argc, char** argv) {
- /* inicializa o sitema GLUT */
- glutInit(&argc, argv);
- glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
- glutInitWindowSize(1000,1000);
- glutInitWindowPosition(100, 100);
- glutCreateWindow("Rotação de Planetas");
- //chama a funcao init e inicia as propriedades View Port
- init();
- glutDisplayFunc(display);
- glutTimerFunc(10, update, 1);
- glutReshapeFunc(reshape);
- glutKeyboardFunc(keyboard);
- glutMainLoop();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement