ClubEnsayos.com - Ensayos de Calidad, Tareas y Monografias
Buscar

Animation


Enviado por   •  27 de Marzo de 2017  •  Documentos de Investigación  •  1.523 Palabras (7 Páginas)  •  211 Visitas

Página 1 de 7

/*

* Animation.cpp: 3D Shapes with animation

*/

// #include <windows.h> // for MS Windows

#include <GL/glut.h> // GLUT, include glu.h and gl.h

/* Global variables */

char title[] = "3D Shapes with animation";

GLfloat anglePyramid = 0.0f; // Rotational angle for pyramid [NEW]

GLfloat angleCube = 0.0f; // Rotational angle for cube [NEW]

int refreshMills = 15; // refresh interval in milliseconds [NEW]

/* Initialize OpenGL Graphics */

void initGL() {

glClearColor(0.0f, 0.0f, 0.0f, 1.0f); // Set background color to black and opaque

glClearDepth(1.0f); // Set background depth to farthest

glEnable(GL_DEPTH_TEST); // Enable depth testing for z-culling

glDepthFunc(GL_LEQUAL); // Set the type of depth-test

glShadeModel(GL_SMOOTH); // Enable smooth shading

glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Nice perspective corrections

}

/* Handler for window-repaint event. Called back when the window first appears and

whenever the window needs to be re-painted. */

void display() {

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear color and depth buffers

glMatrixMode(GL_MODELVIEW); // To operate on model-view matrix

// Render a color-cube consisting of 6 quads with different colors

glLoadIdentity(); // Reset the model-view matrix

glTranslatef(1.5f, 0.0f, -7.0f); // Move right and into the screen

glRotatef(angleCube, 1.0f, 1.0f, 1.0f); // Rotate about (1,1,1)-axis [NEW]

glBegin(GL_QUADS); // Begin drawing the color cube with 6 quads

// Top face (y = 1.0f)

// Define vertices in counter-clockwise (CCW) order with normal pointing out

glColor3f(0.0f, 1.0f, 0.0f); // Green

glVertex3f( 1.0f, 1.0f, -1.0f);

glVertex3f(-1.0f, 1.0f, -1.0f);

glVertex3f(-1.0f, 1.0f, 1.0f);

glVertex3f( 1.0f, 1.0f, 1.0f);

// Bottom face (y = -1.0f)

glColor3f(1.0f, 0.5f, 0.0f); // Orange

glVertex3f( 1.0f, -1.0f, 1.0f);

glVertex3f(-1.0f, -1.0f, 1.0f);

glVertex3f(-1.0f, -1.0f, -1.0f);

glVertex3f( 1.0f, -1.0f, -1.0f);

// Front face (z = 1.0f)

glColor3f(1.0f, 0.0f, 0.0f); // Red

glVertex3f( 1.0f, 1.0f, 1.0f);

glVertex3f(-1.0f, 1.0f, 1.0f);

glVertex3f(-1.0f, -1.0f, 1.0f);

glVertex3f( 1.0f, -1.0f, 1.0f);

// Back face (z = -1.0f)

glColor3f(1.0f, 1.0f, 0.0f); // Yellow

glVertex3f( 1.0f, -1.0f, -1.0f);

glVertex3f(-1.0f, -1.0f, -1.0f);

glVertex3f(-1.0f, 1.0f, -1.0f);

glVertex3f( 1.0f, 1.0f, -1.0f);

// Left face (x = -1.0f)

glColor3f(0.0f, 0.0f, 1.0f); // Blue

glVertex3f(-1.0f, 1.0f, 1.0f);

glVertex3f(-1.0f, 1.0f, -1.0f);

glVertex3f(-1.0f, -1.0f, -1.0f);

glVertex3f(-1.0f, -1.0f, 1.0f);

// Right face (x = 1.0f)

glColor3f(1.0f, 0.0f, 1.0f); // Magenta

glVertex3f(1.0f, 1.0f, -1.0f);

glVertex3f(1.0f, 1.0f, 1.0f);

glVertex3f(1.0f, -1.0f, 1.0f);

glVertex3f(1.0f, -1.0f, -1.0f);

glEnd(); // End of drawing color-cube

// Render a pyramid consists of 4 triangles

glLoadIdentity(); // Reset the model-view matrix

glTranslatef(-1.5f, 0.0f, -6.0f); // Move left and into the screen

glRotatef(anglePyramid, 1.0f, 1.0f,

...

Descargar como (para miembros actualizados) txt (7 Kb) pdf (50 Kb) docx (14 Kb)
Leer 6 páginas más »
Disponible sólo en Clubensayos.com