Alright iv got my robot put together and now i need to add lighting to give it its 3d effect, also i need to make the robot walk in a circle around the origin… can anyone help me with either of these? iv defined the lighting already correctly i think but its not working the way i wanted it to haha, thanks!
#include <stdlib.h>
#include <GL/glut.h>
GLsizei wh = 800,ww = 800;
void init();
void reshape(GLsizei w, GLsizei h);
void Robot();
void torso();
void head();
void upperRightArm();
void upperLeftArm();
void upperRightLeg();
void upperLeftLeg();
void lowerRightArm();
void lowerLeftArm();
void lowerRightLeg();
void lowerLeftLeg();
//Define lighting variables
GLfloat light0_pos[] ={1.,2.,3.,1.};
GLfloat diffuse0[]={0.,0,0,1};
GLfloat ambient0[]={.5,.5,.5,1};
GLfloat specular0[]={1,1,1,1};
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);
/*
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_NORMALIZE);
glLightfv(GL_LIGHT0,GL_POSITION,light0_pos);
glLightfv(GL_LIGHT0,GL_AMBIENT,ambient0);
glLightfv(GL_LIGHT0,GL_DIFFUSE,diffuse0);
glLightfv(GL_LIGHT0,GL_SPECULAR,specular0);
*/
}
void reshape(GLsizei w, GLsizei h)
{
/* adjust clipping box */
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0, (GLdouble)w, 0.0, (GLdouble)h, -300.0, 300.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()
{
/*
//Lighting of the ball
GLfloat ambient[]={.0,.0,.3,1};
GLfloat diffuse[]={0,0,.3,1};
GLfloat specular[]={0,0,.3,1};
//Material
glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT,ambient);
glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,diffuse);
glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,specular);
*/
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glPushMatrix();
glTranslatef(400,400,0.);
torso();
glPushMatrix();
head();
glPopMatrix();
/////////Attach Right Arms
glPushMatrix();
upperRightArm();
glPushMatrix();
lowerRightArm();
glPopMatrix();
glPopMatrix();
////////Attach Left Arms
glPushMatrix();
upperLeftArm();
glPushMatrix();
lowerLeftArm();
glPopMatrix();
glPopMatrix();
////////Attach Right Legs
glPushMatrix();
upperRightLeg();
glPushMatrix();
lowerRightLeg();
glPopMatrix();
glPopMatrix();
////////Attach Left Legs
glPushMatrix();
upperLeftLeg();
glPushMatrix();
lowerLeftLeg();
glPopMatrix();
glPopMatrix();
glPopMatrix();
glutSwapBuffers();
glFlush();
}
void torso()
{
glNormal3f(0,0,0);
glColor3f(1.0,0.,.0);
glutSolidCube(150);
}
void head()
{
glTranslatef(0,110,0.);
glScalef(1,1.5,2);
glColor3f(.0,1.,.0);
glutSolidCube(75);
}
void upperRightArm()
{
glTranslatef(-110,37,0);
glColor3f(.5,.5,.0);
glutSolidCube(75);
}
void upperLeftArm()
{
glTranslatef(110,37,0);
glColor3f(.5,.5,.0);
glutSolidCube(75);
}
void upperRightLeg()
{
glTranslatef(-38,-110,0);
glColor3f(.5,.5,.0);
glutSolidCube(70);
}
void upperLeftLeg()
{
glTranslatef(38,-110,0);
glColor3f(.5,.5,.0);
glutSolidCube(70);
}
void lowerRightArm()
{
glTranslatef(0,-60,0);
glScalef(-.8,2.5,1);
glColor3f(.0,.5,1.0);
glutSolidCube(50);
}
void lowerLeftArm()
{
glTranslatef(0,-60,0);
glScalef(-.8,2.5,1);
glColor3f(.0,.5,1.0);
glutSolidCube(50);
}
void lowerRightLeg()
{
glTranslatef(0,-60,0);
glScalef(1,3,1);
glColor3f(1.5,.0,1.0);
glutSolidCube(50);
}
void lowerLeftLeg()
{
glTranslatef(0,-60,0);
glScalef(1,3,1);
glColor3f(1.5,.0,1.);
glutSolidCube(50);
}