Hello all,
I am pretty new to OpenGL, and I was wondering how could I get my little program
to work.
Let’s say I want to draw a robot’s ARM, at which end FOREARM is attached. On the end of the FOREARM we have a FINGER. On my way to draw a FINGER I am using many glTranslatef() and glRotatef(), but these operations will
be constant - the only variable element will be the FINGER itself.
Here’s the pseudo-code, later I’ll try to
explain what I want to achieve.
// – CODE BEGIN –
glGetDoublev(GL_MODELVIEW_MATRIX,m_modelview_matrix) // Save the current matrix
// Star Drawing Robot’s ARM
gluCylinder(…) // Draw an Arm
glTranslatef(…) // Move to the ‘end’ of the arm
glRotatef(…) // Rotate the ‘end’ of the arm
// Start Drawing Robot’s FOREARM
gluCylinder(…) // Draw a Forearm
glTranslatef(…) // Move to the end of the forearm
glRotatef(…) // Rotate the ‘end’
// Start Drawing Robot’s FINGER
gluCylinder(…) // Draw a Finger
// – CODE END –
I want to be able to get the coordinates (the angles of rotation are not so important)
of the FINGER according to the begining of the ARM, so I could simply draw the ARM and FOREARM from a CallList, then start drawing the fingers ‘manually’
// Draw the Robot’s ARM and FOREARM using stored Call List
glCallList(Stored_Call_List_For_ARM_FOREARM);
glLoadMatrixd(m_modelview_matrix);
glTranslatef(Calculated_X,Calculated_Y, Calculated_Z);
// Draw Robot’s Fingers
gluCylinder(…) // Draw a Finger
I don’t know how to get the ‘local’ values
of transformation between one point and another. I tried subtracting values of current matrix M[12], M[13], M[14] from the one stored on the beginning of the ARM, but it only works when I don’t rotate the beginning of the ARM.
Then I tried to follow the transformations
made from the beginning of the ARM until the
FINGER (to get the local coordinates in the Beginning-Of-The-ARM-is-a-(0,0,0)-point of the FINGER), but it didn’t work either.
Maybe I just made a mistake somewhere,
or maybe there’s a simplier, better way to
do what I want to achieve.
sighs I hope I’ve explained my problem well … I’m on the end of the rope …