PDA

View Full Version : Getting back to previous coordinate for rotation



m3the01
02-06-2005, 03:24 PM
Im very new to opengl so im very sorry if this question is to basic.

Say i have a crane which has to 4 joints in it.

(joint1)___1____(join2)___2____(joint3&4)___4_____
(note pretend _____3____ is just above ___4____ in the above diagram, could get it located right)

Now i have joings 1, 2 and 3 working great. Staying within there ranges. Ive gltranslated to get ____4_____ to its correct alignment with 3. But the problem is joint 4 which controls ______4________ is now rotation about the end of _____3________ which is no good.

How can i get both joints 3 and 4 to rotate at the end of _________2_________? Ive got joint 3 for ________3________ perfect at the end of _________2_______.

Sorry if its unclear, i tried to make it as simple as possible

thanks for any help,

Basically looking on how to get the point of rotation moved back to the end of _________2_________(here).

thanks again

zeckensack
02-06-2005, 05:15 PM
I'm not sure I understood your description. Sections _3_ and _4_ are both attached to the same rigid endpoint but should be able to rotate independently, right?

I think you can solve your problem with glPushMatrix and glPopMatrix. PushMatrix duplicates your current transformation matrix, so that you can "undo" later changes with PopMatrix.


//do transforms for joint 1
glRotatef(...);
draw_segment_1();
glTranslatef(...);

//do transforms for joint 2
glRotatef(...);
draw_segment_2();
glTranslatef(...);

//remember the transformation matrix as it is now
glPushMatrix();

//do transforms for joint 3
glRotatef(...);
draw_segment_3();

//restore the matrix to what it was at the time of PushMatrix
glPopMatrix();

//do transforms for joint 4
glRotatef(...);
draw_segment_4();edit:
As the names suggest, PushMatrix and PopMatrix are stack operations. The usual rules apply:
1)Know the maximum depth of your stack
glGetIntegerv(GL_MODELVIEW_STACK_DEPTH,&somewhere);
2)Use Push and Pop only in matched pairs.

m3the01
02-06-2005, 05:59 PM
Yeah thats exactly it,

So pop takes me back one step? So then all i would really need to do is pop twice.

Also would you mind if i pm'd you about a unrelated german DHL question? I see your from germany and i have a quick question. I dont speak german so im in kinda a pickle.

thanks again for your help,