
Perspective and Orthographic Problem
Posted Thursday, 25 September, 2008 - 11:15 by phoenix inHi everybody,
I have a problem in switching between orthographic and perspective projection. My code runs well with GL.Ortho but if I replace it with Glu.Perspective, it doesn't work. My Render() function is here:
public void Render()
{
thisTransformation.getRenamed(matrix);
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
GL.MatrixMode(MatrixMode.Projection);
GL.PushMatrix();
GL.LoadIdentity();
GL.Ortho(-width / 2, width / 2, -height / 2, height / 2, -1000, 1000); // works fine
// Glu.Perspective(45, width / height, 0.1, 100); // problem
GL.MatrixMode(MatrixMode.Modelview);
GL.PushMatrix();
GL.LoadIdentity();
GL.MultMatrixf(matrix);
GL.Enable(EnableCap.DepthTest);
#region draw something here
// draw something ....
#endregion
GL.MatrixMode(MatrixMode.Projection);
GL.PopMatrix();
GL.MatrixMode(MatrixMode.Modelview);
GL.PopMatrix();
GL.Flush();
this.Invalidate();
}
Any suggestion ?


Comments
Re: Perspective and Orthographic Problem
How far off into the scene is the object you are trying to render? It might be too-close. First time I changed from Ortho to Perspective it felt like going from human perspective to ant perspective :)
Try moving the object further into the scene - GL.Translate(0, 0, -500) - negative z means into scene (since z axis vector points towards your eyes)
Re: Perspective and Orthographic Problem
I did what you said but it seems like i have the same result when i don't change the GL.Translate. Do you think that the matrix (GL.MultMatrixf(matrix)) which is relative to the arcball effects something to this ? Have you ever used the arcball method for the three transformations ?
Re: Perspective and Orthographic Problem
I don't know what the arcball is.
The GL.MultMatrixf()-call may very well change things drastically.
What three transformations do you mean?
Re: Perspective and Orthographic Problem
Three transformations are translation, scale and rotation. Using arcball method you can easily do transformations with mouse.
Re: Perspective and Orthographic Problem
So how can you do three transformations without using arcball (another way is trackball) ?
Re: Perspective and Orthographic Problem
I often use OpenGLs builtin transformation methods:
GL.Translate(..)
GL.Scale(..)
GL.Rotate(..)
Running them one at a time gives you a lot of freedom.
For example, you can use Translate(x,y,0) to move the model in x,y-plane in combination with mouse coordinates with left mouse button, and Rotate(angle,0,1,0) to spin it around y-axis with right mouse button. And then maybe middle button = zoom which means Translate(0,0,z) to move the model along the z-axis.
Re: Perspective and Orthographic Problem
But I think that way is not a good choice. You can't rotate and zoom the whole scene smoothly with mouse.
Re: Perspective and Orthographic Problem
I think you will have to explain that with a little bit more detail. Most viewers (all?) I've ever used have rotated- and zoomed the scene using the mouse, more or less smoothly (depending on how heavy the model is..).
Re: Perspective and Orthographic Problem
// Glu.Perspective(45, width / height, 0.1, 100); // problem
Are width and height ints?
If they are you'll not be getting a useful value back from width / height. You'll need to cast one to a float first.
Re: Perspective and Orthographic Problem
I changed width / height to ((double)width)/ (double)height :
Glu.Perspective(45,((double)width)/ (double)height, 0.1, 100);
But nothing changed much. I still see only a line like what i said above.