PDA

View Full Version : sphere-cube-objects



pavlov123
01-07-2003, 10:13 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();

}
Pavlov123

JustHanging
01-08-2003, 02:03 AM
Heh, that must be the funniest web page I've seen for a while. Absurd text and pictures of a cube-headed penquin...

Cutting to the point, the cube being the parent object of the sphere means that when you rotate the cube, the sphere will rotate with it, as if it was nailed in place. You can accomplish this with opengl by moving the sphere drawing code inside the cube's push/popmatrix block. In pseudo:




pushMatrix
transformCube
drawCube

pushMatrix
transformSphere
drawSphere
popMatrix

popMatrix


You might need to adjust the sphere's position, since it is now expressed in the cube's coordinate system.

If you have some visibility problems that aren't fixed by this, you most likely need to enable the depth test.

Good luck,

-Ilkka

[This message has been edited by JustHanging (edited 01-08-2003).]

jwatte
01-08-2003, 08:25 AM
OpenGL doesn't really know about parent objects and child objects. That kind of knowledge is typically put at a higher level, in what's known as a "scene graph".

Popular scene graphics include Open Inventor (from SGI) or the Quake Engine (from Id), but there's many more out there.

Plug "scene graph object relation" into Google and I'm sure you'll get tons of relevant hits.