Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifdef __APPLE__
- #include <GLUT/glut.h>
- #else
- #include <GL/glut.h>
- #endif
- #include <stdlib.h>
- #include <GL/glut.h>
- #include <iostream>
- #include "constantes.h"
- using namespace std;
- /*Inicializa parâmetros de rendering*/
- void Inicializa(void) {
- angle = 60.0;
- glClearColor(1.0f, 1.0f,1.0f,1.0f);
- //Usada para criar o volume de visualização
- glMatrixMode(GL_PROJECTION);
- //Usada para permitir transformações (Trans., rot e scala)
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- glOrtho(-100.0, 100.0, -100.0, 100.0, -100.0, 100.0);
- gluLookAt(eyex, eyey, eyez, 0, 0, 0, 0, 1, 0);
- }
- /*Função usada para especificar o volume de visualização*/
- EspecificaParametrosVisualizacao(){
- //Usada para criar o volume de visualização
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- //Usada para permitir transformações (Trans., rot e scala)
- gluPerspective(angle, fAspect, 0.1, 500);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- gluLookAt(eyex, eyey, eyez, 0, 0, 0, 0, 1, 0);
- }
- /*Função callback chamada quando o tamanho da janela é alterado*/
- void AlteraTamanhoJanela(GLsizei w, GLsizei h){
- if(h == 0){
- h = 1;
- }
- glViewport(0 ,0, w, h);
- fAspect = (GLfloat)w / (GLfloat)h;
- EspecificaParametrosVisualizacao();
- }
- /*Função calback chamada para gerenciar eventos do mouse*/
- void GerenciaMouse(int button, int state, int x, int y){
- if (button == GLUT_LEFT_BUTTON){
- if(angle >= 10){
- angle -= 5;
- }
- }
- if (button == GLUT_RIGHT_BUTTON){
- if(angle <= 130){
- angle += 5;
- }
- }
- EspecificaParametrosVisualizacao();
- glutPostRedisplay();
- }
- /*Configura teclas para interagir com o objeto */
- void teclas(unsigned char tecla, GLint x, GLint y){
- switch(tecla){
- case 'a':{
- eyex -=5.0;
- break;
- }
- case 'd':{
- eyex +=5.0;
- break;
- }
- case 's':{
- eyey -= 5.0;
- break;
- }
- case 'w':{
- eyey += 5.0;
- break;
- }
- }
- EspecificaParametrosVisualizacao();
- glutPostRedisplay();
- }
- /*Função callbacl chamada para fazer o desenho*/
- void Desenha(void){
- glClear(GL_COLOR_BUFFER_BIT);
- glColor3f(0.0f, 0.0f, 1.0f);
- glBegin(GL_LINES);
- glVertex3i(-40, -40, 0);
- glVertex3i(-40, 40, 0);
- glVertex3i(-40, 40, 0);
- glVertex3i(40, 40, 0);
- glVertex3i(40, 40, 0);
- glVertex3i(40, -40, 0);
- glVertex3i(40, -40, 0);
- glVertex3i(-40, -40, 0);
- glVertex3i(-40, -40, 0);
- glVertex3i(-40, -40, -80);
- glVertex3i(-40, 40, 0);
- glVertex3i(-40, 40, -80);
- glVertex3i(40, 40, 0);
- glVertex3i(40, 40, -80);
- glVertex3i(40, -40, 0);
- glVertex3i(40, -40, -80);
- glVertex3i(-40, -40, -80);
- glVertex3i(-40, 40, -80);
- glVertex3i(-40, 40, -80);
- glVertex3i(40, 40, -80);
- glVertex3i(40, 40, -80);
- glVertex3i(40, -40, -80);
- glVertex3i(40, -40, -80);
- glVertex3i(-40, -40, -80);
- glEnd();
- glutSwapBuffers();
- }
- int main (int argc, char** argv) {
- /*Inicializaçãod a tela*/
- glutInit(&argc, argv);
- glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
- glutInitWindowSize(640, 400);
- glutInitWindowPosition(700,30);
- glutCreateWindow("TP_2");
- glutKeyboardFunc(teclas);
- glutDisplayFunc(Desenha);
- glutReshapeFunc(AlteraTamanhoJanela);
- glutMouseFunc(GerenciaMouse);
- Inicializa();
- glutMainLoop();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement