What is the correct way to pan, zoom and rotate?

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/

Hi billy,

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

-nemesis-

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.

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.

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?

I use glOrtho to zoom.

1 Like

I’m working on a CAD package too :wink: 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.

Originally posted by billy:
[b]

  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).

[/b]

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.

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?

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.

I highly recommend using quaternions for rotation. There a number of resources on the Web to get you started.

Pat

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 .

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).]

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.

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.

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

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.

Thanks nurbs. Can you send it to billyaraujo@hotmail.com ?

hi,nubs
can u give your example?3x in advance.
my email is : ruixp@yahoo.com.cn

[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).]