#include "glut.h"
GLfloat angle= 0.0f;
GLfloat width= 40.0f;
GLfloat height= 30.0f;
int x=0;
int y=0;
int z=0;
void drawBody()
{
glColor3f(0,0,1);
glBegin(GL_QUADS);
glVertex3f(-15,5,0);
glVertex3f(15,5,0);
glVertex3f(15,-20,0);
glVertex3f(-15,-20,0);
glEnd();
glColor3f(0,0,1);
glBegin(GL_QUADS);
glVertex3f(-15,5,10);
glVertex3f(15,5,10);
glVertex3f(15,-20,10);
glVertex3f(-15,-20,10);
glEnd();
glColor3f(0,0,1);
glBegin(GL_QUADS);
glVertex3f(15,5,10);
glVertex3f(15,5,0);
glVertex3f(15,-20,0);
glVertex3f(15,-20,10);
glEnd();
glColor3f(0,0,1);
glBegin(GL_QUADS);
glVertex3f(-15,5,10);
glVertex3f(-15,5,0);
glVertex3f(-15,-20,0);
glVertex3f(-15,-20,10);
glEnd();
glColor3f(0,0,1);
glBegin(GL_QUADS);
glVertex3f(-15,5,0);
glVertex3f(15,5,0);
glVertex3f(15,5,10);
glVertex3f(-15,5,10);
glEnd();
glColor3f(0,0,1);
glBegin(GL_QUADS);
glVertex3f(-15,-20,0);
glVertex3f(15,-20,0);
glVertex3f(15,-20,10);
glVertex3f(-15,-20,10);
glEnd();
}
void drawLimb()
{
glColor3f(1,0,0);
glBegin(GL_QUADS);
glVertex3f(-5,5,8);
glVertex3f(1,5,8);
glVertex3f(1,-15,8);
glVertex3f(-5,-15,8);
glEnd();
glColor3f(1,0,0);
glBegin(GL_QUADS);
glVertex3f(-5,5,2);
glVertex3f(1,5,2);
glVertex3f(1,-15,2);
glVertex3f(-5,-15,2);
glEnd();
glColor3f(1,0,0);
glBegin(GL_QUADS);
glVertex3f(1,5,8);
glVertex3f(1,5,2);
glVertex3f(1,-15,2);
glVertex3f(1,-15,8);
glEnd();
glColor3f(1,0,0);
glBegin(GL_QUADS);
glVertex3f(-5,5,8);
glVertex3f(-5,5,2);
glVertex3f(-5,-15,2);
glVertex3f(-5,-15,8);
glEnd();
glColor3f(1,0,0);
glBegin(GL_QUADS);
glVertex3f(-5,5,2);
glVertex3f(1,5,2);
glVertex3f(1,5,8);
glVertex3f(-5,5,8);
glEnd();
glColor3f(1,0,0);
glBegin(GL_QUADS);
glVertex3f(-5,-15,2);
glVertex3f(1,-15,2);
glVertex3f(1,-15,8);
glVertex3f(-5,-15,8);
glEnd();
}
void drawLimb2()
{
glColor3f(1,1,0);
glBegin(GL_QUADS);
glVertex3f(-5,5,10);
glVertex3f(5,5,10);
glVertex3f(5,-15,10);
glVertex3f(-5,-15,10);
glEnd();
glColor3f(1,1,0);
glBegin(GL_QUADS);
glVertex3f(-5,5,0);
glVertex3f(5,5,0);
glVertex3f(5,-15,0);
glVertex3f(-5,-15,0);
glEnd();
glColor3f(1,1,0);
glBegin(GL_QUADS);
glVertex3f(5,5,10);
glVertex3f(5,5,0);
glVertex3f(5,-15,0);
glVertex3f(5,-15,10);
glEnd();
glColor3f(1,1,0);
glBegin(GL_QUADS);
glVertex3f(-5,5,10);
glVertex3f(-5,5,0);
glVertex3f(-5,-15,0);
glVertex3f(-5,-15,10);
glEnd();
glColor3f(1,1,0);
glBegin(GL_QUADS);
glVertex3f(-5,5,0);
glVertex3f(5,5,0);
glVertex3f(5,5,10);
glVertex3f(-5,5,10);
glEnd();
glColor3f(1,1,0);
glBegin(GL_QUADS);
glVertex3f(-5,-15,0);
glVertex3f(5,-15,0);
glVertex3f(5,-15,10);
glVertex3f(-5,-15,10);
glEnd();
}
void drawHead()
{
glColor3f(1,0,1);
glutSolidSphere(9.5,36,25);
}
void MyDisplay()
{
glClear(GL_COLOR_BUFFER_BIT GL_DEPTH_BUFFER_BIT);
//glLoadIdentity();
glEnable(GL_DEPTH);
glPopMatrix();
glBegin(GL_LINES);
glColor3f(1,1,1);
glVertex3f(0,0,0);
glVertex3f(400,0,0);
glVertex3f(0,0,0);
glVertex3f(0,400,0);
glVertex3f(0,0,0);
glVertex3f(0,0,400);
glEnd();
glPushMatrix();
glTranslatef(::x,y,z);
glPushMatrix();
glTranslatef(-15, 0.0, 0.0);
drawLimb();
glPopMatrix();
glPushMatrix();
glTranslatef(-20, -15.0, 13);
glRotatef(90.0, 1.0, 0.0, 0.0);
drawLimb();
glPopMatrix();
glPushMatrix();
glTranslatef(-40, -60, -25);
drawLimb2();
glPopMatrix();
glPushMatrix();
glTranslatef(-15, -60, -25);
drawLimb2();
glPopMatrix();
glPushMatrix();
drawBody();
glPopMatrix();
glPushMatrix();
glTranslatef(20, 0.0, 0.0);
drawLimb();
glPopMatrix();
glPushMatrix();
glTranslatef(10, -14.0, 3);
glRotatef(50.0, 1.0, 0.0, 0.0);
drawLimb();
glPopMatrix();
glPushMatrix();
glTranslatef(-17, -5, -12);
drawHead();
glPopMatrix();
glutPostRedisplay();
glutSwapBuffers();
}
void Rescale(GLsizei w, GLsizei h)
{
glViewport(0,0,w,h);
}
void SetupRC()
{
GLfloat final = width / height;
glFrontFace(GL_CCW);
gluPerspective(50, final , 0, 1000);
gluLookAt(90,90,90,0,1,0,0,1,0);
glFlush();
}
void Keyboard(unsigned char key, int x, int y)
{
switch(key) //check which key is pressed
{
case 'a':
::x--; //add 1 to global x.
break;
case 'd':
::x++; //minus 1 to global x.
break;
case 'w':
::y++;
break;
case 's':
::y--;
break;
case 'q':
::z--;
break;
case 'e':
::z++;
break;
}
glutPostRedisplay();
}
void main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE GLUT_RGB GLUT_DEPTH);
glutInitWindowSize(640, 480);
glutCreateWindow("My Practical 6");
glutDisplayFunc(MyDisplay);
glutReshapeFunc(Rescale);
glutKeyboardFunc(Keyboard);
SetupRC();
glutMainLoop();
}