#include "stdafx.h"
#include <stdlib.h>
#include <GL/glut.h>
// giv: I'm on Windows...
#pragma comment (lib, "opengl32.lib")
#pragma comment (lib, "glu32.lib")
GLsizei wh = 800,ww = 800;
void init();
void reshape(GLsizei w, GLsizei h);
void Robot();
void torso();
void head();
//void upperRightArm();
//void upperLeftArm();
void upperArm();
void upperRightLeg();
void upperLeftLeg();
//void lowerRightArm();
//void lowerLeftArm();
void lowerArm();
void lowerRightLeg();
void lowerLeftLeg();
void main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(ww,wh);
glutInitWindowPosition(200,150);
glutCreateWindow("Robot");
glutReshapeFunc(reshape);
glutDisplayFunc(Robot);
init();
glEnable(GL_DEPTH_TEST);
glutMainLoop();
}
void init()
{
glClearColor (0.0, 0.7, 1.0, 1.0);
glColor3f(0.,0.,1.);
glMatrixMode(GL_PROJECTION); //set the clipping space
glLoadIdentity();
glOrtho(-2.,2.0,-2.,2.,-2.,2.);
glMatrixMode(GL_MODELVIEW);
glutReshapeFunc(reshape);
}
void reshape(GLsizei w, GLsizei h)
{
/* adjust clipping box */
glViewport (0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
// giv: maximize the viewing frustum, but beware of setting
// near plane too close, or far plane too far..
gluPerspective(65.0, (GLfloat) w/(GLfloat) h, 1.0, 2000.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
/* adjust viewport and clear */
//glViewport(0,0,w,h);
glClearColor (0.0, 0.7, 1.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT);
glFlush();
/* set global size for use by drawing routine */
ww = w;
wh = h;
}
void Robot()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// giv: you already set it reshape()...
/*glMatrixMode (GL_PROJECTION);
glLoadIdentity ();*/
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
// giv: you missed this - this is logically the final transformation each
// vertex gets multiplied by, that transforms it into the camera frame
// Check out Edward Angel's 'Interactive Computer Graphics. Second Edition.
// A top down approach to OpenGL'. In particular Chapter 4, section 9.
gluLookAt(
25, 25, 75,
0, 0, 0,
0, 1, 0);
glPushMatrix();
// giv: put the torso right at the center of the world (0,0,0)
torso();
glPushMatrix();
// giv: put the head slightly above the torso
glTranslatef(0,9,0.);
head();
glPopMatrix();
/////////Attach Right Arms
glPushMatrix();
glTranslatef(-15, -2, 0);
//upperRightArm();
upperArm();
glTranslatef(0, -17, 1);
//lowerRightArm();
lowerArm();
glPopMatrix();
//////////Attach Left Arms
//glPushMatrix();
// upperLeftArm();
// glPushMatrix();
// lowerLeftArm();
// glPopMatrix();
glPushMatrix();
glTranslatef(15, -2, 0);
//upperRightArm();
upperArm();
glTranslatef(0, -17, 1);
//lowerRightArm();
lowerArm();
glPopMatrix();
// ////////Attach Right Legs
// glPushMatrix();
// upperRightLeg();
// glPushMatrix();
// lowerRightLeg();
// glPopMatrix();
// ////////Attach Left Legs
// glPushMatrix();
// upperLeftLeg();
// glPushMatrix();
// lowerLeftLeg();
// glPopMatrix();
// glPopMatrix();
// // Igor's
// glPopMatrix();
// glPopMatrix();
//glPopMatrix();
glPopMatrix();
glutSwapBuffers();
glFlush();
}
void torso()
{
glPushMatrix();
glRotatef(90, 1, 0, 0);
glColor3f(1.0,0.,.0);
GLUquadric *q=gluNewQuadric();
gluCylinder(q, 10, 10, 50, 50, 50);
//glTranslatef(400,400,0.);
gluDeleteQuadric(q);
//glutSolidCube(3.5);
glPopMatrix();
}
void head()
{
// giv: the 2 commented out don't really make sense
//glTranslatef(400,520,0.); - translates the head way out of the camera view
glRotatef(-90,1.,0.,0.);
//glScalef(20,40,20); - makes the head way to big
glColor3f(.0,1.,.0);
glutSolidCube(/*7*/15);
}
//void upperRightArm()
//{
// glColor3f(.5,.5,.0);
// //glutSolidCube(10);
//
// GLUquadric *q=gluNewQuadric();
// gluCylinder(q, 3, 3, 20, 50, 50);
// //glTranslatef(400,400,0.);
// gluDeleteQuadric(q);
//}
//void upperLeftArm()
void upperArm()
{
glPushMatrix();
glRotatef(90, 1, 0, 0);
glColor3f(.5,.5,.0);
//glutSolidCube(10);
GLUquadric *q=gluNewQuadric();
gluCylinder(q, 3, 3, 15, 50, 50);
//glTranslatef(400,400,0.);
gluDeleteQuadric(q);
glPopMatrix();
}
void upperRightLeg()
{
glColor3f(.5,.5,.0);
glutSolidCube(50);
}
void upperLeftLeg()
{
glColor3f(.5,.5,.0);
glutSolidCube(50);
}
//void lowerRightArm()
//{
// glColor3f(.5,.0,1.0);
// glutSolidCube(50);
//}
//
//void lowerLeftArm()
//{
// glColor3f(.0,1.5,1.0);
// glutSolidCube(50);
//}
void lowerArm()
{
glPushMatrix();
glRotatef(55, 1, 0, 0);
glColor3f(.5,.5,.0);
//glutSolidCube(10);
GLUquadric *q=gluNewQuadric();
gluCylinder(q, 3, 3, 10, 50, 50);
//glTranslatef(400,400,0.);
gluDeleteQuadric(q);
glPopMatrix();
}
void lowerRightLeg()
{
glColor3f(1.5,.0,1.0);
glutSolidCube(50);
}
void lowerLeftLeg()
{
glColor3f(.5,.5,.5);
glutSolidCube(50);
}