PDA

View Full Version : Help with Rotation in a hierarchy...



hmmwv19
11-05-2001, 02:25 AM
Okay, I'm working on a project where I've constructed a crude human model out of scaled wire cubes. I set them up so that there is a hierarchy of the objects (the hand is connected to the forearm which is connected to the bicep, etc) using the stack... however, when I try to do some animation tests, like rotating an arm for example, the entire arm changes it shape and becomes very "sheared" and streched out.

My through was that if I rotated the hips along the x axis for example, the legs would go with it. Then I could rotate the thigh, then the calf, then finally the foot, all on the x axis to produce a sort of kicking motion. What happens is the hips rotate fine, but then whe I try to roate the thigh, things get distorted. The same goes for the calf and foot as well. Here is an example of what I'm talking about:

...
glPushMatrix(); // Push: Beginhip
glTranslatef(0.0, -.7, 0);
glScalef(hipRatioX, hipRatioY, hipRatioZ);
glRotatef(testAnimate, 1.0, 0.0, 0.0);
glutWireCube(1.0);

// Left Thigh
glPushMatrix(); // Push: Begin left leg
glTranslatef(.34, -1.75, 0);
glRotatef(testAnimate, 1.0, 0.0, 0.0);
glScalef(thighRatioX, thighRatioY, thighRatioZ);
glutWireCube(1.0);

// Left calf
glPushMatrix();
glRotatef(testAnimate, 1.0, 0.0, 0.0);
glTranslatef(0, -0.92, 0);
glScalef(calfRatioX, calfRatioY, calfRatioZ);
glRotatef(testAnimate, 1.0, 0.0, 0.0);
glutWireCube(1.0);

// Left foot
glPushMatrix();
glTranslatef(0, -.55, .25);
glScalef(1, .1, 1.5);
glRotatef(testAnimate, 1.0, 0.0, 0.0);
glutWireCube(1.0);
glPopMatrix();
glPopMatrix();
glPopMatrix(); // Pop: End Left Leg

// other leg is drawn next

glPopMatrix(); // End Hip
...

Okay, so a couple of questions... are all the pushes and pops necessary... I mean, am I even using them correctly? Also can I rotate like this is a hierarchy and get the other body parts to move along with it with the method I am using? Do I have to use extra translates? I tried it but nothing changed. What would I have to change to make this work? Keep in mind that there are two pushes above the hip (the scence and torso pushed) and two pops below the hip as well.

I hope this made some sense.... any help at all would be greatly appreciated.

Thanks,
Jesse

11-05-2001, 03:32 AM
HI

About pushing matrices:
U use glPush/PopMatrix to save current matrix, NOT for making it valid for OpenGL. In your case, these lines are unnesssecccary:

...
glPushMatrix(); // if you earlier reset matrix or use it after, you dont have to do it
glTranslatef(0.0, -.7, 0);
glScalef(hipRatioX, hipRatioY, hipRatioZ);
glRotatef(testAnimate, 1.0, 0.0, 0.0);
glutWireCube(1.0);

// Left Thigh
glPushMatrix();
glTranslatef(.34, -1.75, 0);
glRotatef(testAnimate, 1.0, 0.0, 0.0);
glScalef(thighRatioX, thighRatioY, thighRatioZ);
glutWireCube(1.0);

// Left calf
glPushMatrix(); // No, wrong!!!!
glRotatef(testAnimate, 1.0, 0.0, 0.0);
glTranslatef(0, -0.92, 0);
glScalef(calfRatioX, calfRatioY, calfRatioZ);
glRotatef(testAnimate, 1.0, 0.0, 0.0);
glutWireCube(1.0);

// Left foot
glPushMatrix(); // wrong again
glTranslatef(0, -.55, .25);
glScalef(1, .1, 1.5);
glRotatef(testAnimate, 1.0, 0.0, 0.0);
glutWireCube(1.0);
glPopMatrix(); // ?????????
glPopMatrix(); // ????????????
glPopMatrix(); // Pop: End Left Leg

// other leg is drawn next

glPopMatrix(); // End Hip


Sorry For Bad English

Jerry
11-05-2001, 05:16 AM
Hai...

I read your question and am also doubt in that area.

How you construct 3D object ?.

I want to know how i can render 3D object created by series of 2D medical images.I like to use marching cube algorithm to create triangle from 2D images.

How i can join triangles (output of the Marching cube algorithm )?
I read that use Normals for that .
I don't know how use it?

What is your project?. What algorithm if you use for 3D reconstruction ?


Waiting your suggestion or any code previously developed for your project.

Thanks in advance for your replay

Regards,
Jerry


Originally posted by hmmwv19:
Okay, I'm working on a project where I've constructed a crude human model out of scaled wire cubes. I set them up so that there is a hierarchy of the objects (the hand is connected to the forearm which is connected to the bicep, etc) using the stack... however, when I try to do some animation tests, like rotating an arm for example, the entire arm changes it shape and becomes very "sheared" and streched out.

My through was that if I rotated the hips along the x axis for example, the legs would go with it. Then I could rotate the thigh, then the calf, then finally the foot, all on the x axis to produce a sort of kicking motion. What happens is the hips rotate fine, but then whe I try to roate the thigh, things get distorted. The same goes for the calf and foot as well. Here is an example of what I'm talking about:

...
glPushMatrix(); // Push: Beginhip
glTranslatef(0.0, -.7, 0);
glScalef(hipRatioX, hipRatioY, hipRatioZ);
glRotatef(testAnimate, 1.0, 0.0, 0.0);
glutWireCube(1.0);

// Left Thigh
glPushMatrix(); // Push: Begin left leg
glTranslatef(.34, -1.75, 0);
glRotatef(testAnimate, 1.0, 0.0, 0.0);
glScalef(thighRatioX, thighRatioY, thighRatioZ);
glutWireCube(1.0);

// Left calf
glPushMatrix();
glRotatef(testAnimate, 1.0, 0.0, 0.0);
glTranslatef(0, -0.92, 0);
glScalef(calfRatioX, calfRatioY, calfRatioZ);
glRotatef(testAnimate, 1.0, 0.0, 0.0);
glutWireCube(1.0);

// Left foot
glPushMatrix();
glTranslatef(0, -.55, .25);
glScalef(1, .1, 1.5);
glRotatef(testAnimate, 1.0, 0.0, 0.0);
glutWireCube(1.0);
glPopMatrix();
glPopMatrix();
glPopMatrix(); // Pop: End Left Leg

// other leg is drawn next

glPopMatrix(); // End Hip
...

Okay, so a couple of questions... are all the pushes and pops necessary... I mean, am I even using them correctly? Also can I rotate like this is a hierarchy and get the other body parts to move along with it with the method I am using? Do I have to use extra translates? I tried it but nothing changed. What would I have to change to make this work? Keep in mind that there are two pushes above the hip (the scence and torso pushed) and two pops below the hip as well.

I hope this made some sense.... any help at all would be greatly appreciated.

Thanks,
Jesse

Korval
11-05-2001, 12:12 PM
Actually, your code's pushing and poping are absolutely correct. The reason things get distorted is that you are incorporating scales into your hierarchy. This is not a good idea. To solve this, you will have to adjust your glTranslate's to put the model together correctly without the scales.

Also, in order to render your cubes correctly, you should do the following:

glPushMatrix();
glScale(whatever you need for this part of the model)
glutWireCube(1.0f);
glPopMatrix();

The scales are for rendering only and should not be applied to the hierarchy.

I would suggest creating a simple set of classes for each body part. That way, each body part can apply the appropriate translates, rotates, and scales as necessary to render itself.

[This message has been edited by Korval (edited 11-05-2001).]