TrabalhosGratuitos.com - Trabalhos, Monografias, Artigos, Exames, Resumos de livros, Dissertações
Pesquisar

Exercicio de Computação Gráfica Câmera e Rotação

Por:   •  29/10/2016  •  Trabalho acadêmico  •  1.368 Palavras (6 Páginas)  •  322 Visualizações

Página 1 de 6

Crie um código que use uma câmera para rotacionar e navegar em uma cena.

#include <windows.h>

#include <GL/gl.h>

#include <GL/glu.h>

#include <GL/glut.h>

#include <stdio.h>

#include <glaux.h>

#include <math.h>

// Angulo de rotação para a camera

double angle =0;

//direção da camera

double lx=0.0,lz=-1.0;

// posições x e z da camera

double x=0.0,z=5.0;

GLuint texture_id[1];

int ix=3, iy=3, iz=3;

//função de carregamento da imagem

int LoadBMP(char *filename)

{

#define SAIR {fclose(fp_arquivo); return -1;}

#define CTOI(C) (*(int*)&C)

GLubyte *image;

GLubyte Header[0x54];

GLuint DataPos, imageSize;

GLsizei Width,Height;

int retorno = 0;

int nb = 0;

int t = 0;

int i = 0;

// Abre o arquivo e efetua a leitura do Header do arquivo BMP

FILE * fp_arquivo = fopen(filename,"rb");

if (!fp_arquivo)

return -1;

if (fread(Header,1,0x36,fp_arquivo)!=0x36)

SAIR;

if (Header[0]!='B' || Header[1]!='M')

SAIR;

if (CTOI(Header[0x1E])!=0)

SAIR;

if (CTOI(Header[0x1C])!=24)

SAIR;

// Recupera a informação dos atributos de

// altura e largura da imagem

Width = CTOI(Header[0x12]);

Height = CTOI(Header[0x16]);

( CTOI(Header[0x0A]) == 0 ) ? ( DataPos=0x36 ) : ( DataPos = CTOI(Header[0x0A]) );

imageSize=Width*Height*3;

// Efetua a Carga da Imagem

image = (GLubyte *)malloc(imageSize);

retorno = fread(image,1,imageSize,fp_arquivo);

if (retorno !=imageSize)

{

free (image);

SAIR;

}

// Inverte os valores de R e B

for ( i = 0; i < imageSize; i += 3 )

{

t = image[i];

image[i] = image[i+2];

image[i+2] = t;

}

// Tratamento da textura para o OpenGL

glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);

glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);

glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);

glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT);

glTexEnvf ( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );

// Faz a geraçao da textura na memória

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, Width, Height, 0, GL_RGB, GL_UNSIGNED_BYTE, image);

fclose (fp_arquivo);

free (image);

return 1;

}

void init(void)

{

glShadeModel(GL_SMOOTH);

// habilita luz e transparencia

glEnable(GL_BLEND);

glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

glEnable(GL_LIGHTING);

glEnable(GL_LIGHT0);

glEnable(GL_LIGHT1);

glEnable(GL_DEPTH_TEST);

glClearColor(0.0, 0.0, 0.0, 0.0);

// gera um objeto de textura, para o vetor e carrega com a imagem

glEnable ( GL_TEXTURE_2D );

glPixelStorei ( GL_UNPACK_ALIGNMENT, 1 );

glGenTextures ( 1, texture_id );

glBindTexture ( GL_TEXTURE_2D, texture_id[0] );

LoadBMP ("wood.bmp");

}

...

Baixar como (para membros premium)  txt (8.6 Kb)   pdf (78.1 Kb)   docx (15.5 Kb)  
Continuar por mais 5 páginas »
Disponível apenas no TrabalhosGratuitos.com