pan in 3D

Hi. I need to pan my 3D scene without disturbing its angle, just like moving as if it were a 2D image. I tried using glTranslate after glLoadIdentity but it disturbs the angle. Are there any suggestions to solve this problem?

Just compute every vertex with the pan value.

No ?

I will need to change all my code to do that. That would be too difficult. The thing I exactly want is to be able to move the scene simultaneously with mouse drag. Many programs have this property. Any other suggestion?

gltranslate should work. Perhaps the change in angle is due to the perspective, in which case you could use glortho

Yes, angle change is due to perspective. if I use glortho I lose 3D look. Is there a way of using glortho without disturbing angles? Any other suggestions?

Originally posted by chowe6685:
gltranslate should work. Perhaps the change in angle is due to the perspective, in which case you could use glortho

you cannot have it both ways. Part of the way we perceive 3d is through parallex. Close one eye and line your finger up with a far away tree/pole/anything. Then switch eyes. The finger will appear to jump. This is a side effect of perspective, if the angles don’t change it will look less 3d.

You should be able to get the effect you are looking for by monkeying with the view frustum, but that would produce some weird behavior. Could you explain why you want to do this? What you are explaining is not a particularly common need.

I am trying to code a CAD modelling program. User will need to ‘pan’ or ‘zoom window’ some part of the model. Therefore I need accurate movements. What I want is to be able to drag the scene with mouse. this resembles a scroolbar control.

Originally posted by endash:
Could you explain why you want to do this? What you are explaining is not a particularly common need.

In most CAD programs you edit the scene in a ortho mode and preview in the perspective view.

When you need to be accurate you do drawing in ortho mode.

Also maybe want to look at multiple views, ortho would be work windows, the perspective would be a preview of the changes being done in the ortho window.

[This message has been edited by nexusone (edited 02-20-2004).]

I need to edit my scene in 3D so I cannot use ortho mode. Any other suggestions? Will the method of changing vertex coordinates work for what I want?

Originally posted by nexusone:
In most CAD programs you edit the scene in a ortho mode and preview in the perspective view.

You need to do a translate on the modelview matrix, but this needs to be on the opposite end of the matrix from a normal translate. It needs to be a premultiply not a post multiply (or is it the other way around…). Anyhoo, no matter, here is what you do:

glGet the modelview matrix, loadidentity on the modelview translate along the x & y axis, multmatrix the one you got back on the modelview and you will have panned correctly in 3D.

can you please give some code example. Is that what you mean?

GLdouble modelMatrix[16];
glGetDoublev(GL_MODELVIEW_MATRIX, modelMatrix);
glLoadIdentity();
glTranslated(panx,pany,0);
glMultMatrixd(modelMatrix);
RenderScene();

I tried but it does not work. It disturbs the angle.

Originally posted by dorbie:
[b]glGet the modelview matrix, loadidentity on the modelview translate along the x & y axis, multmatrix the one you got back on the modelview and you will have panned correctly in 3D.

[/b]

Yes, that’s it exactly, you only need to use floats, and it won’t disturb the angle. The eye will pan in x y in isolation of other stuff, ofcourse if you do subsequent viewing xforms they won’t know about this. It’ll behave as if you didn’t pan unless you keep reapplying this and they pan will always remain in eye space.

You could just apply the pan translate before all viewing xforms to save the load matrix. You get the same result.

P.S. make sure you’re on the modelview matrix.

[This message has been edited by dorbie (edited 02-21-2004).]