View Full Version : Rotation question!!
03-26-2001, 01:42 AM
How can I do rotation about center of the screen. I am developing an application that has interface just like 3dstudio max i.e. I can do zooming and roatation etc to the view. What i want to do is when i rotate the view by any degrees and then do a windowed zoom, that part should be zoomed and then when i rotate the view, it should rotate around the center of the screen. currently thart part is zoomed but it does not rotate around the center of the screen. it instead rotates arounfd the point where it was previously rotating which is now out of the screen. How can i fix this?
03-26-2001, 03:41 AM
glRotate rotates around the (0, 0, 0) point
any other rotating must be done with glTranslate and then glRotate see the RedBook
03-26-2001, 03:58 AM
I know that but the problem is once we translate and then we rotate, this problem occurs because the object is translated first then rotated, but if we rotate first and then translate this problem is over but if the rotation angle > 0 and then we translate, it doesent rotte arund the center any more ( by center I mean the screen center instead it rotates around the world center which in fact is somewhere inside the screen)
rotation = glRotatef(angle, x, y, z)
03-26-2001, 04:46 AM
with gl Rotate you always rotate around the point where your camera is right now. To rotate around the screencenter you have to move your camera there, rotate and move your camera back again. It is infact well described i the red book
07-05-2001, 01:05 AM
I would appreciate if you could explain it to me. Actually I read about it but I couldnt Understand... can someone explain?
07-07-2001, 03:04 AM
OK, I will give it a try.
First realize that there are two kinds of transformations possible on the modelview matrix: Viewing transformations, and Modeling transformations.
When building a scene you need to specify both, and the order of things is important. Set up your view first, and then start drawing.
gluLookAt can be used to set up the camera, so to speak (remember that in the purest sense there is no camera here). You can point it anywhere you want, but it is a mistake to think that the center coordinates specified in the routine automatically become the point of rotation (unless specified otherwise the center of rotation is (0, 0, 0), see below)
In most cases you'll probably want to point at the center of rotation, but you don't have to.
To make sure you are looking at the scene correctly, always call glLoadIdentity before gluLookAt.
When your camera is set up it is time to place your models.
(this only applies to basic shapes, complex (combined) shapes are not the scope of this post)
The center of the screen is your main reference point (after all, when you call glLoadIdentity, you know this is where your action starts http://www.opengl.org/discussion_boards/ubb/smile.gif)
glTranslatef(x, y, z);
will move the reference point to (x, y, z).
Every translation or rotation afterward will now be performed from this new point.
A good strategy to draw your scene is:
Go to the origin;
Translate to the coordinates of the first object to be drawn;
Perform rotation to give the object its proper orientation;
Draw the object;
Go back to the origin;
Translate to the coordinates of the second object...;
and so on...
To return to the origin you call glLoadIdentity every time, to realign the coordinate system.
Putting it all together
Abovementioned strategy is sound, but a call to glLoadIdentity will also destroy your viewing transformation, and that is undesirable (in most cases anyway). Before you begin drawing it is wise to save your viewing transformation. This is accomplished by putting your drawing code in between glPushMatrix() and glPopMatrix()
There is a lot more to say about this topic, but these are the basics. I hope it is useful to you. If you need it I can provide you with some sample code.
Powered by vBulletin® Version 4.2.2 Copyright © 2014 vBulletin Solutions, Inc. All rights reserved.