Hello,
I'm very new at this so please excuse my stupidity.
I'm trying to draw an arm of a robot. But openGL is only drawing the first object I draw correctly. The rest of them are black, not connected to the first object, but connected to each other.
When I remove the glpush/popmatrix functions from the code, they start attaching to each other, are the right color, but each object drawn after the other gets smaller and smaller.
I don't know why....I've been fooling around with this for too long and it still isn't working. Oh, I am using glut in visual c++...in case that information matters.
Any suggestions on how I could get this to work will be very, very, appreaciated!
The following are some snippets from my code if it helps:
***********************
From the display function.
**************************
glPushMatrix();
glLoadIdentity();
gluPerspective(65.0, 1/1, 1.0, 20.0);
glTranslatef(0.0, 0.0, -5.0);
glRotatef( SceneRotateX, 1.0, 0.0, 0.0);
glRotatef( SceneRotateY, 0.0, 1.0, 0.0);
// This is where I draw the arm.
arm.am_DrawArm(0.0f, 0.0f, 0.0f);
glPopMatrix();
******************************
The am_DrawArm function
******************************
void CArmModel::am_DrawArm(float xpos, float ypos, float zpos)
{
glPushMatrix();
glTranslatef(-myRobot[UPPER_ARM].length, 0.0, 0.0);
glRotatef(myRobot[UPPER_ARM].rotation, 0.0, 0.0, 1.0);
am_Shoulder(myRobot[SHOULDER].length/2.0, 0.0, 0.0);
am_UpperArm(myRobot[UPPER_ARM].length/2.0, 0.0, 0.0);
am_Elbow(myRobot[UPPER_ARM].length/2.0, 0.0, 0.0);
am_LowerArm(myRobot[LOWER_ARM].length/2.0, 0.0, 0.0);
.....
glPopMatrix();
}
***************************
the arm functions
***************************
**************************************************************
I wouldn't thing that commenting out the glPushMatrix and glPopMatrix should work, but it sort of does. Of course when I draw the fingers, commenting them out doestn't work.
**************************************************************
void CArmModel::am_Shoulder(float xpos, float ypos, float zpos)
{
glTranslatef(xpos, ypos, zpos);
//glPushMatrix();
glColor3f(0.99,0.77,0.72);
glScalef(myRobot[SHOULDER].length, myRobot[SHOULDER].height,
myRobot[SHOULDER].width);
glutSolidSphere(0.6,100,100);
//glPopMatrix();
}
void CArmModel::am_UpperArm(float xpos, float ypos, float zpos)
{
glTranslatef(xpos, ypos, zpos);
// glPushMatrix();
glColor3f(0.99,0.72,0.67);
glScalef(myRobot[UPPER_ARM].length, myRobot[UPPER_ARM].height,
myRobot[UPPER_ARM].width);
glutSolidCube(1.0);
// glPopMatrix();
}
void CArmModel::am_Elbow(float xpos, float ypos, float zpos)
{
glTranslatef(xpos, ypos, zpos);
// glPushMatrix();
glColor3f(0.99,0.77,0.72);
glScalef(myRobot[ELBOW].length, myRobot[ELBOW].height,
myRobot[ELBOW].width);
glutSolidSphere(0.55,100,100);
// glPopMatrix();
}
void CArmModel::am_LowerArm(float xpos, float ypos, float zpos)
{
glRotatef(myRobot[LOWER_ARM].rotation, 0.0, 0.0, 1.0);
glTranslatef(xpos, ypos, zpos);
// glPushMatrix();
glColor3f(0.99,0.75,0.70);
glScalef(myRobot[LOWER_ARM].length, myRobot[LOWER_ARM].height,
myRobot[LOWER_ARM].width);
glutSolidCube(1.0);
// glPopMatrix();
}
.......
evolutional - Added source tags
[Edited by - evolutional on September 15, 2004 12:10:15 PM]