PDA

View Full Version : What is the correct way to pan, zoom and rotate?



billy
01-08-2002, 02:15 AM
Hello,

I would like o know what is the correct way to pan, zoom and rotate an object:

1. Use only gluLookAt
2. Use glTranslate (to pan), glRotate (rotate) and glScale (to zoom)
3. Use glTranslate (to pan), glRotate (rotate) and change the projection matrix (to zoom).
4. Use glTranslate (to pan and zoom), glRotate (rotate).

Thanks in advance.

Billy. http://planeta.clix.pt/billy/

nemesis
01-08-2002, 02:23 AM
Hi billy,

I think there is no absolut correct way to do that, it depends. What exactly do you want to do?

-nemesis-

omaha_os3
01-08-2002, 02:26 AM
I would most definitely use #4. I'm not totally sure what you mean by zoom an object, because if I were to have a 'zoom' feature, I would say that you should decrease your field of view for the duration of the zoom, but that's for scene zooming, not object zooming.

Kilam Malik
01-08-2002, 02:34 AM
I never use glRotate because of the gimble lock. Build up a rotation matrix and multiply it with the actual rotation position (glGet on the actual matrix).

But it depends on the purpose of course.


Kilam.

billy
01-08-2002, 05:44 AM
This is for a CAD program. Every CAD package has a pan, zoom and rotate. This is to view a single object.

I have a orthographic projection.

The pan works quite well with glTranslate, I am finding out that glRotate is not the best to rotate object. I agree with you kilam. Maybe I can find a better solution using my own matrix.

Do you think I should use glScale to zoom?

Coconut
01-08-2002, 05:46 AM
I use glOrtho to zoom.

Kilam Malik
01-08-2002, 06:38 AM
I'm working on a CAD package too ;-) Here's how I do it:

Rotation:
I hold my own rotation matrix. When starting, it's a identity matrix. Every time the user rotates I calculate a rotation matrix from the user rotation. Then I multiply this onto the viewing matrix.

Zooming in ortho:
Do _not_ use glScale. This scales the normal vectors also! I always adjust the zoom by calling glOrtho with the extents of my scene translated to 2D.

Kilam.

Lyr
01-08-2002, 06:40 AM
Originally posted by billy:

1. Use only gluLookAt
2. Use glTranslate (to pan), glRotate (rotate) and glScale (to zoom)
3. Use glTranslate (to pan), glRotate (rotate) and change the projection matrix (to zoom).
4. Use glTranslate (to pan and zoom), glRotate (rotate).



2.
As far as I know the only Problem of glScale is that the light appears more bright. If you need lightening then I think you can enable GL_RESCALE_NORMALS for correct lightening because every vertex has to be scaled by the same value.
Another way (but I haven't tried this) is to divide the light by the scalefactor.

Correct me if I'm wrong.

billy
01-08-2002, 06:47 AM
Yes, I have noticed that when I use glScale, the render changes. This is because I am scaling the object but the light remains in the same position, right?

Kilam Malik
01-08-2002, 08:46 AM
The brightness change is because the brightness is the scalar product of the reversed light vector and the normal of the vertex. This vectors have to have length 1. As glScale scales normal vector, the brightness changes too.

Automatic normalization of OpenGL is not good, as it is awful slow. It has to normalize all normals of the object each frame. And this involves a square root...


Kilam.

Pat
01-08-2002, 10:44 AM
I highly recommend using quaternions for rotation. There a number of resources on the Web to get you started.

Pat

Lyr
01-08-2002, 11:42 AM
Originally posted by Kilam Malik:

This vectors have to have length 1. As glScale scales normal vector, the brightness changes too.


Yes, but every normal vector is scaled by the same value. So every normal vector has the same length.
glEnable( GL_RESCALE_NORMALS) doesn't mean to calculate the length of every normal.
GL_RESCALE_NORMALS means that every normal has the length 1, but is divided by the scaling factor of the modelview matrix. So you need a square root once per frame and some divisions for every vertex.
As far as I know the disadvantage of GL_RESCALE_NORMALS is that your whole scene has to be scaled by the same factor.

By the way. GL_RESCALE_NORMALS is availible since OpenGL 1.2 .

billy
01-09-2002, 12:13 AM
Does anyone know a good book or web page that explains how to use quaternions?


[This message has been edited by billy (edited 01-09-2002).]

Kilam Malik
01-09-2002, 02:03 AM
Mexx: I think I mixed it up with GL_AUTO_NORMALS.

billy: If you only want to rotate the object with the mouse, you do not need quaternions. The matrix multiply I described works perfect here. If you want to have animations e.g. from the current viewing matrix to a new view (most of the new CAD system have that now), it is easier to do with quaternions.

Kilam.

Relic
01-09-2002, 08:11 AM
Yup, GL_AUTO_NORMAL is for glMap and stuff. That's probably slow as is coordinate evaluation in general compared to static geometry.
But, for the correct lighting with glScale you need either GL_NORMALIZE (which is in OpenGL from the beginning) or GL_RESCALE_NORMAL which are both almost for free on modern geometry (T&L) accelerators.

"Does anyone know a good book or web page that explains how to use quaternions?"

Have you searched this forum for the links, there are plenty. http://www.opengl.org/discussion_boards/ubb/smile.gif

[This message has been edited by Relic (edited 01-09-2002).]

nurbs
01-09-2002, 12:58 PM
Hello Billy,

there is an example doing exactly what You want (pan, rotate, zoom, othrogrphic projection).
The rotations are done with quaternions. The files are called "trachball.h" and "trackball.c". According to the comments in the files, they are copyrighted by Silicon Graphics and the author is Gavin Bell. If You want I can send You a copy the files and an example how to use them with glut.

billy
01-10-2002, 03:19 AM
Thanks nurbs. Can you send it to billyaraujo@hotmail.com ?

ruixp
01-14-2002, 06:15 PM
hi,nubs
can u give your example?3x in advance.
my email is : ruixp@yahoo.com.cn

jerin3D
01-16-2002, 08:18 PM
[QUOTE]Originally posted by Kilam Malik:
[B]I never use glRotate because of the gimble lock. Build up a rotation matrix and multiply it with the actual rotation position (glGet on the actual matrix).


Hi,

What is the gimble lock u mean. I don't know.I rotate the object using glRotate().I am also want to use own rotation marix. How can i use it ? Pls send the steps or any sample code to me. My id is jerinjohn@hotmail.com

Thanx in advance


[This message has been edited by jerin3D (edited 01-16-2002).]