near and far planes

Started by
6 comments, last by Malchivus 18 years, 9 months ago
I'm trying to set the near and far planes according to what model I render and I'm not sure how because this is an orthographic projection. I'm doing this using JOGL (Java API) and I was looking at glFrustrum and gluPerspective and if I understand all this correctly, it seems to be for perspective projections which is all the red book talks about in this context. My problem is that my models are being clipped either on the near or far planes and I'm trying to get them in my viewing volume correctly. Can I use these functions for orthographic projections? Any help much appreciated.
Advertisement
Try scaling the model down. ;)
If orthographic projection was what you wanted to do then you can search for the headline "Orthographic Projection" in this page (scroll down to about the middle of it): Red Book Chapter 3
Also, this site writes about it with the JOGL API: http://www.stud.ntnu.no/~johanno/appletviewer.jsp?task=tutorials&dir=tutorial01&nr=0
If you want to find out how big your model is you could iterate through each vertex and calculate its width based on the nearest and farthest vertex, then position it in the center.

[edit]oh, sorry, realized I forgot to mention, the handy function for orthographic projection is called glOrtho :)[/edit]

\Jimmy H
Yep, orthographic is what I wanted and as you can see by my mention of the redbook, I did read that part. That's what I'm referring to. I already know how big my model is and it should fit within the near and far plane values that I have given it. I did that when getting my centroid.

And when I use glOrtho, no matter what values I give the near and far plane, my model gets cliipped all the same.
Quote:Original post by Kalasjniekof
Try scaling the model down. ;)


I can scale, but because my near and far planes are so out of whack, doesn't matter what I scale too, it's being clipped.

I was mainly wondering if it was ok to use glFrustrum or gluPerspective w/ an orthographic projection.
Consider the following situatiuons:

1. If you try minimize the FOV angle in gluPerspective then everything will look bigger (since the view volume covers a smaller volume) and look nearly orthographic but not truly orthographic since you still look through a view volume shaped like a narrow cone. Mathematically, setting the FOV angle to 0 will make the view volume infinitely small and there'll be no real volume where objects are allowed to exist. So the result may depend on the clipping algorithm used. I don't know which algorithms OpenGL uses internally though.

2. Using glFrustum the left, right, top and bottom coordinates are aligned to the near plane, and the eye is a point behind the near plane so wherever the far plane is placed the view volume will still be shaped like a cone. In this situation too you could probably minimize the dimensions of the near plane to get a near ortographic view (narrow cone view volume).

Some of the elements in the matrices produced by glFrustum/glOrtho are constantly different from the corresponding element in the other matrix, I can't find a way of getting one of the produced matrices to simulate the other one but I don't have enough mathematical skills to say it's never possible.

It seems like there's a wrong value somewhere in the code if the model is clipped even though the model is scaled smaller and smaller.

\Jimmy H
Turns out I wasn't using the perspective matrix, I was still using the modelview matrix. Now I can manipulate it again. I don't understand it, but it works now. I was using code from examples I found in the red book.
don't know if this is something you already know but ...

the modelview and projection matrices are both the same things, they are, basically, multiplied together and then used to transform points, the neat thing is that since they are stored separately you can screw around with the modelview matrix and it won't require you to reset your perspective over and over again.
I just wanna get this done.

This topic is closed to new replies.

Advertisement