3D Hell

Started by
2 comments, last by Ethereal Darkness 22 years, 5 months ago
hey all, im working on building a 3d engine/library and the one part of it that has seemed to stump me is 3d hierarchial rotation, i.e. you rotate your shoulder and your forarm and hand follows i have come up with a way to do it... rotate self->rotate joints below it using the rotation origin of the first object. the idea works well... but i think the rotations im doing are messed up, so i was wondering if anyone could point me in the direction of a turoial or some information on doing 3d hierarchial rotations using software only *no graphics libraries or other engines* thanks=)
Advertisement
Just to a web search on ''forward kinematics'' That''s the ''official'' term for what you''re describing.
I''m no 3D programmer, but surely if you just define your objects in relation to the object it is attached to, then you only need to transform one object and all the others are automatically transformed as a result...
Kylotan is right assuming that you do position your different objects in relation to some central object. I have done things like this for robot demos, here is a quick snippet. It''s in OpenGL and if you don''t understand push and pop techniques it''s probably hard to understand. Forward Kinematics is also something to look into for other types of physics simulations. I think there is a good tutorial somewhere on this website: OpenGL Effects

  //  This function calls the function to draw the rest of the robotvoid GLMain::DrawRobot(){		glPushMatrix();		glPushMatrix();				//  Rotate bust			glRotatef(bustXAngle, 1.0f, 0.0f, 0.0f);			glRotatef(bustYAngle, 0.0f, 1.0f, 0.0f);			//  Draw bust			DrawBust();			//  Draw head			DrawHead();			glPushMatrix();				glTranslatef(-6.5f, 0.0f, 0.0f);				//  Rotate left arm				glRotatef(leftArmAngle, 1.0f, 0.0f, 0.0f);				//  Draw left arm				DrawArm();				glPushMatrix();					glTranslatef(0.0f, -4.5f, 0.0f);					//  Rotate left forearm					glRotatef(leftForeArmAngle, 1.0f, 0.0f, 0.0f);					//  Draw left forearm					DrawForeArm();				glPopMatrix();							glPopMatrix();						glPushMatrix();				glTranslatef(6.5f, 0.0f, 0.0f);				//  Rotate right arm				glRotatef(rightArmAngle, 1.0f, 0.0f, 0.0f);					//  Draw right arm				DrawArm();				glPushMatrix();					glTranslatef(0.0f, -4.5f, 0.0f);					//  Rotate right forearm					glRotatef(rightForeArmAngle, 1.0f, 0.0f, 0.0f);					//  Draw right forearm					DrawForeArm();				glPopMatrix();			glPopMatrix();				//  Draw Pelvis				DrawPelvis();			glPushMatrix();								glTranslatef(-1.5f, -6.1f, 0.0f);				//  Rotate left thigh				glRotatef(leftThighAngle, 1.0f, 0.0f, 0.0f);				//  Draw left thigh				DrawThigh();								glPushMatrix();					glTranslatef(0.0f, -5.3f, 0.0f);					//  Rotate left leg					glRotatef(leftLegAngle, 1.0f, 0.0f, 0.0f);					//  Draw the left leg					DrawLeg();				glPopMatrix();			glPopMatrix();			glPushMatrix();								glTranslatef(1.5f, -6.1f, 0.0f);				//  Rotate right thigh				glRotatef(rightThighAngle, 1.0f, 0.0f, 0.0f);				//  Draw right thigh				DrawThigh();				glPushMatrix();					glTranslatef(0.0f, -5.3f, 0.0f);					//  Rotate left leg					glRotatef(rightLegAngle, 1.0f, 0.0f, 0.0f);					//  Draw the left leg					DrawLeg();				glPopMatrix();			glPopMatrix();						glPopMatrix();	glPopMatrix();}  


Well, maybe that wasn''t all that short, but you get the idea right? good!

This topic is closed to new replies.

Advertisement