PDA

View Full Version : objects-childs-parents



pavlov123
01-07-2003, 11:07 AM
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?

Red15
01-07-2003, 01:13 PM
All you simply do is _not_ pop your matrix, or at least not pop your translation matrix.
(Can't remember the right command right now).

Then just place your second object.
Example:



void DrawArm() {
glPushMatrix();
{
glTranslatef(arm->x, arm->y, arm->z);
glRotatef(arm->xr, 1.0, 0.0, 0.0);
glRotatef(arm->yr, 0.0, 1.0, 0.0);
glRotatef(arm->zr, 0.0, 0.0, 1.0);
glCallList(arm);
glPushMatrix();
{
glTranslatef(larm->x, larm->y, larm->z);
glRotatef(larm->xr, 1.0, 0.0, 0.0);
glRotatef(larm->yr, 0.0, 1.0, 0.0);
glRotatef(larm->zr, 0.0, 0.0, 1.0);
glCallList(larm);
}
glPopMatrix();
}
glPopMatrix();
}


This type of linking/animation is the opposite of IK which you probably know from 3DS Max.

Good Luck.

[This message has been edited by Red15 (edited 01-07-2003).]

[This message has been edited by Red15 (edited 01-07-2003).]

[This message has been edited by Red15 (edited 01-07-2003).]