OpenGl and Rotating images

DukeLeto
Unregistered
 
Post: #1
This is probably an easy question, but It has me stumped...

I have 3 objects on the screen in a line that I would like to rotate as a group around a point. I'm able to rotate the objects individually, but their location does not chage. How can I rotate the objects around a point so that they will remain in a line once the rotation is complete?

Example
Stating image:
Code:
- - -

I can do this:
Code:
| | |

but I can't determine how to do this:
Code:
/
/
/



Thanks.
Quote this message in a reply
Moderator
Posts: 335
Joined: 2002.04
Post: #2
the openGL rotation function only changes each object's rotation about its own axis, the rotation of the objects around a central point requires moving the objects. If you're in 2D, the formula is

x = radius * cos(angle) + centre_x
y = radius * sin(angle) + centre_y

you'd move the objects to these positions and use the glrotate to turn them in the right direction (as you're already doing)
Quote this message in a reply
drzeip
Unregistered
 
Post: #3
I may be wrong but can't you just call glRotate before calling glTranslate and then the translate call will be affected by the rotate call as the matrix won't have been reset?

e.g.

Code:
glRotate( 30.f , 0.f , 0.f , 1.f );
drawObject();
glTranslate(  -1.f , 0.f , 1.f ); // move to left object
drawObject();
glTranslate(  2.f , 0.f , 1.f ); // move to right object
drawObject();

I think......
Quote this message in a reply
Member
Posts: 70
Joined: 2004.06
Post: #4
Yes, you can do that. It's how I would have done it.

Matrix calls are cumulative, that is each call will act on the state left over from the previous one. You can use push and pop or load the identity matrix again to get a fresh one. Something that got me for a while was that any modifications (translate, rotate etc) you wanted to do to the objects had to be done before you drew it. This was backwards to what I was used to but it is entirely logical.

By the way, in your example you changed the z coordinate as well as the x one. You should not do it more than once, because otherwise (due to it being cumulative) you went und up having translated two units forward on the z-axis, which I doubt it what you intended.
Quote this message in a reply
drzeip
Unregistered
 
Post: #5
Oops you're right I didn't mean to do that!! Stuff like that is fairly standard with my coding... Mad
Quote this message in a reply
Member
Posts: 233
Joined: 2003.05
Post: #6
Use Zwilink's method if the actual coordinates of the moving objects are needed at some point.

For example, in SpaceBarrage I was going to avoid calculating everything and just use OpenGL's rotate methods (and I mostly did), but then I wanted to have the ships break into pieces I suddenly needed to know the coordinates of each point on the rotated ship. You can't get those with just OpenGL calls. Smile

"Pay no attention to that man behind the curtain." - Wizard of Oz
Quote this message in a reply
Moderator
Posts: 771
Joined: 2003.04
Post: #7
Well... you can get the current transformation matrix and multiply it by your point, so if you have a "vector x matrix" fuction you can do most of your stuff with gl calls.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  OpenGL ES Loading images techy 4 3,814 Dec 24, 2009 02:01 PM
Last Post: techy
  Origin problems - rotating shapes frances_farmer 1 2,460 Feb 10, 2007 08:08 AM
Last Post: unknown
  Rotating a point in 3D Joseph Duchesne 1 2,509 Dec 19, 2006 12:43 PM
Last Post: unknown
  rotating objects ferum 11 3,866 Dec 19, 2005 02:28 PM
Last Post: ferum
  rotating... MACnus 4 3,629 Mar 25, 2005 07:46 PM
Last Post: phydeaux