this is my code which makes two cones hierarchically aligned about the positive z-axis. i want to look at it as if the cones are facing away from my, that is as if they were aligned about the negative z-axis. i would be very thankful if you could or someone could help. i really need it working.
GLint angle[6];
GLPoint::GLPoint(GLdouble _x=0,GLdouble _y=0,GLdouble _z=0)
{
x = _x;
y = _y;
z = _z;
}
void GLPoint::operator()(GLdouble _x=0,GLdouble _y=0,GLdouble _z=0)
{
x = _x;
y = _y;
z = _z;
}
void GLPoint::Display()
{
cout<<x<<" “<<y<<” "<<z<<endl;
}
//Initialisation of background clor and drawing color
void myInit()
{
glClearColor(0.75,0.75,0.75,0.0); //set background clour
glColor3d(0.0,0.0,0.0); // set drawing colour
glPointSize(2.0);
glLineWidth(2.0);
}
void setWindow(GLdouble left,GLdouble right,GLdouble bottom,GLdouble top,GLdouble near,GLdouble far)
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(left,right,bottom,top,near,far);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(20,60,70,0,0,0,0,1,0);
}
void setViewport(GLint left,GLint right,GLint bottom,GLint top)
{
glViewport(left,bottom,right-left,top-bottom);
}
void Reshape(GLint w, GLint h)
{
setViewport (0,w,0,h);
setWindow(-10,100,-30,100,-100,100);
}
void drawDot(GLPoint &P)
{
glBegin(GL_POINTS);
glVertex3d(P.x,P.y,P.z);
glEnd();
}
void myMouse(int button,int state,int x,int y)
{
if(state==GLUT_DOWN && button==GLUT_LEFT_BUTTON){
for(int i=3;i<=5;i++){
angle[i]= rand()%120;
cout<<“angle[”<<i<<“]=”<<angle[i]<<endl;
}
}
else if(button==GLUT_RIGHT_BUTTON){
glClear(GL_COLOR_BUFFER_BIT);
glFlush();
}
glutPostRedisplay();
}
void co_ordinate(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
glColor3d(1.0,0.0,0.0);
glBegin(GL_LINES);
glVertex3d(0,0,0);
glVertex3d(10,0,0);
glEnd();
glTranslated((10-2),0,0);
glRotated(90,0,1,0);
glutWireCone(0.4,2,12,9);
glPopMatrix();
glPushMatrix();
glColor3d(0.0,1.0,0.0);
glBegin(GL_LINES);
glVertex3d(0,0,0);
glVertex3d(0,10,0);
glEnd();
glTranslated(0,(10-2),0);
glRotated(-90,1,0,0);
glutWireCone(0.4,2,12,9);
glPopMatrix();
glPushMatrix();
glColor3d(0.0,0.0,1.0);
glBegin(GL_LINES);
glVertex3d(0,0,0);
glVertex3d(0,0,10);
glEnd();
glTranslated(0,0,(10-2));
glutWireCone(0.4,2,12,9);
glPopMatrix();
}
void Robot_Display()
{
GLdouble L1=30; //Upper_Arm Length
GLdouble L2=45; //Lower_Arm Length
//Initial VM position is at origin pointing in direction(0,0,1)
co_ordinate();
GLUquadricObj *qobj1 = gluNewQuadric();
GLUquadricObj *qobj2 = gluNewQuadric();
gluQuadricDrawStyle(qobj1,GLU_FILL);
gluQuadricDrawStyle(qobj2,GLU_FILL);
glPushMatrix();
glTranslated(80,90,20);
glRotated(angle[0],1,0,0);
glRotated(angle[1],0,1,0);
glRotated(angle[2],0,0,1);
glPushMatrix();
glColor3d(0.20,0.20,0.20);
gluCylinder(qobj1,6,4,L1,10,10);
glPopMatrix();
glTranslated(0,0,L1);
glRotated(angle[3],1,0,0);
glRotated(angle[4],0,1,0);
glRotated(angle[5],0,0,1);
glColor3d(0.50,0.50,1.0);
gluCylinder(qobj1,4,2,L2,10,10);
glPopMatrix();
glutSwapBuffers();
}