You are on page 1of 3

// 3DAnimations.cpp : Defines the entry point for the console application.

//

#include<glut.h>
#define ROTATEX 1
#define ROTATEY 2
#define ROTATEZ 3
#define ROTATEXY 4
#define ROTATEXZ 5
#define ROTATEYZ 6

float angle = 0.0;


float x=0, y=0, z=0;
int clock = 0;

void init()
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-2.0*80/60.0, 2.0*80/60.0, -2.0, 2.0, 2, -2);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0.0, 0.0, 4.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);//c
glClearColor(1.0f, 1.0f, 1.0f, 0.0f);//background is white
}

void displayWire(void)
{
glPushMatrix();
glColor3d(1, 0, 0);
glTranslated(2, 0, 0);
glRotated(angle, x, y, z);
glutWireSphere(0.55, 30, 10);
glPopMatrix();

glPushMatrix();
glColor3d(0.6, 1, 0);
glTranslated(-2, 0, 0);
glRotated(angle, x, y, z);
glutWireTeapot(0.55);
glPopMatrix();

glPushMatrix();
glColor3d(1, 0, 1);
glTranslated(-2, -1, 0);
glRotated(angle, x, y, z);
glutWireCube(0.6);
glPopMatrix();

glPushMatrix();
glColor3d(0, 0.6, 0.4);
glTranslated(0, 0, 0);
glRotated(angle, x, y, z);
glutWireCone(0.5, 1.8, 100, 10);
glPopMatrix();

glPushMatrix();
glColor3d(0.6, 0.2, 0.4);
glTranslated(0, 1.0, 0);
glRotated(angle, x, y, z);
glutWireTorus(0.1, 0.3, 10, 10);
glPopMatrix();

//glPushMatrix();
// glColor3d(0.6, 0.8, 0.4);
// glTranslated(1, 0.6, 0);
// glRotated(angle, x, y, z);
// GLUquadricObj*qobj;
// qobj = gluNewQuadric();
// gluQuadricDrawStyle(qobj, GLU_LINE()
// glutWireTorus(0.1, 0.3, 10, 10);
//glPopMatrix();

void processMenuEvents(int option)


{
switch(option)
{
case ROTATEX : x=1.0;y=0.0;z=0.0; break;
case ROTATEY : x=0.0;y=1.0;z=0.0; break;
case ROTATEZ : x=0.0;y=0.0;z=1.0; break;
case ROTATEXY : x=1.0;y=1.0;z=0.0; break;
case ROTATEXZ : x=1.0;y=0.0;z=1.0; break;
case ROTATEYZ : x=0.0;y=1.0;z=1.0; break;
}
}

void renderScene(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
displayWire();
angle+=0.3;
glutSwapBuffers();
}

void main(int argc, char **argv)


{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGBA);
glutInitWindowSize(800, 600);
glutInitWindowPosition(100, 100);
glutCreateWindow("Transormation trestbed wireframes animated");
glutDisplayFunc(renderScene);
glutIdleFunc(renderScene);
init();
glViewport(0, 0, 800, 600);

glutCreateMenu(processMenuEvents);//menu
glutAddMenuEntry("Rotate X", ROTATEX);
glutAddMenuEntry("Rotate Y", ROTATEY);
glutAddMenuEntry("Rotate Z", ROTATEZ);
glutAddMenuEntry("Rotate XY", ROTATEXY);
glutAddMenuEntry("Rotate XZ", ROTATEXZ);
glutAddMenuEntry("Rotate YZ", ROTATEYZ);
glutAttachMenu(GLUT_RIGHT_BUTTON);
glutMainLoop();
}

You might also like