PDA

View Full Version : drawing a head



pavlov123
01-07-2003, 11:24 AM
Hello ,
If i have a cube and a sphere an i want the cube to be the parent object and the sphere the child object how can i do it?Can someone gives me a sample code and explain i a few words what is the difference between a parent and a child object?
I have the above question.I want to draw a sphere an bahind the sphere a cube.The problem
is that i want when i rotate my draw 90...the sphere to ba half inside the cube.I don't want
to see two seperate schemes but one.The part of the sphere which will be inside the cube
i don't want to be visible.Can you give me the part of the code which gives me solution to this?

Imagine that i want to make a very very simple head.The cube will be the head an i want the spheres to
be the two eyes.when i see the face from the one side i want to see a sphere and behind the sphere the cube but when i rotate my scheme i want the face to looks like here
(i want to make a penguin)to see the penguin go to http://graphics.di.uoa.gr/Courses/exercise2002.html
and watch the head for example

please modify the code below

void Render()
{

glClear(GL_COLOR_BUFFER_BIT);
glClear(GL_DEPTH_BUFFER_BIT);
glFrontFace(GL_CCW);

glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
glTranslatef( 0.0, 0.0,-100.0 );

glRotatef(0.0,0.0,1.0,0.0);
glPushMatrix();
glTranslatef( -3.0, 17.0, 0.0);
glScalef(0.73,1.12,0.8);
glColor4f(0.15,0.15,0.15,1.0);
glutSolidCube(14.0);
glPopMatrix();

glPushMatrix();//
glTranslatef( -3.8, 21.5, 0.0 );
glScalef(0.36,0.36,0.36);
glColor4f(0.3,0.3,0.3,1.0);
glutSolidSphere(8,35,22);
glPopMatrix();

glutSwapBuffers();

}

Deiussum
01-07-2003, 11:29 AM
If i understand correctly, what you want is something like this:




void Render()
{

glClear(GL_COLOR_BUFFER_BIT);
glClear(GL_DEPTH_BUFFER_BIT);
glFrontFace(GL_CCW);

glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
glTranslatef( 0.0, 0.0,-100.0 );

glRotatef(0.0,0.0,1.0,0.0);
glPushMatrix();
glTranslatef( -3.0, 17.0, 0.0);
glScalef(0.73,1.12,0.8);
glColor4f(0.15,0.15,0.15,1.0);
glutSolidCube(14.0);
glPushMatrix();//
glTranslatef( -3.8, 21.5, 0.0 );
glScalef(0.36,0.36,0.36);
glColor4f(0.3,0.3,0.3,1.0);
glutSolidSphere(8,35,22);
glPopMatrix();
glPopMatrix();


glutSwapBuffers();

}


Also, from your other posts it sounds like maybe your problem was that you didn't enable depth testing, or you don't have a depth buffer. Be sure to do:

glEnable(GL_DEPTH_TEST);

If you are using Windows you should have a depth buffer by default. If you are using Linux and glut, you may need to include GLUT_DEPTH as one of the bits in glutInitDisplayMode.