View Full Version : Simple rotation question
02-12-2008, 06:49 AM
This is my first post of many to come, I'm sure. :)
I have a model loaded in OpenGL that I want to rotate about a specific point. Right now, when I rotate the model (a beam) about Y, it rotates about a point located at the center of the beam.
I really want it to rotate about a point at the end of the beam. AFAIK, I cannot use glTranslatef followed by glRotatef because the point of rotation must be fixed in space.
The only solution I can come up with so far is to add a point at the desired point of rotation, and then rotate the beam in the point's coordinate system.
Is this the right idea? Any suggestions would be great.
02-12-2008, 07:11 AM
Something like this should work (or the reverse order, I can't check now) :
glTranslate( - endpoint_to_center_of_view)
02-12-2008, 07:12 AM
center = (cx,cy,cz)
02-12-2008, 07:43 AM
Thank you for the responses! Let me give that a shot and we'll see what happens. :)
02-13-2008, 07:27 AM
I'm now realizing that it was a huge mistake to make assumptions and write code to implement the behavior I'm looking for, without fully understanding how OpenGL works.
I'm taking a step back and would just like to confirm that I am thinking about things correctly.
Please take a look at the PDF below:
Basically, I have 3 links, a, b, and c. a and b are pinned, and b and c are pinned. If I rotate b, then c should follow, as in (2). If I then rotate a, then b and c should follow, as in (3). If I rotate c, then a and b should keep their current orientation, as in (3).
In general, it almost looks like the algorithm is -- do whatever transformation the link's parent did, followed by its own transformation.
(3) shows two ways of thinking side-by-side. The one on the left (with a faint X through it) is what I believe is incorrect thinking. The one on the right is correct.
(4) shows the transformations that I think should be applied to c to get the desired effect.
Can anyone please glance at the PDF and let me know if I'm on the right track? Thanks!
EDIT -- Can anyone also add input about how pushing and popping the modelview matrix could affect things? I think than in my example, the same modelview matrix would be used
02-13-2008, 03:22 PM
maybe you can try something like this,
i just that a snap look of your pdf, one thing that you should remember, a is only depends on rotA, b depends on rotA and rotB, and c depends on rotA, rotB, and rotC.
in step(2) even though it's only b that moving, you can't only use rotB in your formula, but you have to include rotA as well.
02-14-2008, 07:42 AM
Yeah, I spoke with my friend that knows OpenGL pretty well, and I think I now know how to approach the problem. I'm going to start rewriting the code today to deal with the linked models, and hopefully I'll come up with something suitable. Thank you for your help!
Powered by vBulletin® Version 4.2.2 Copyright © 2014 vBulletin Solutions, Inc. All rights reserved.