[comp.sys.sgi] question on gl

avr@cs.purdue.EDU (Andrew V. Royappa) (04/02/91)

The gl graphics user's guide says that the perspective & viewing
transformations transforms the perspective pyramid into the box 
-1.0 <= x,y,z <= 1.0, to facilitate clipping. Is this in fact
the case, or are the box's bounds given by something else
e.g. -1.0<=x,y<=1.0 and 0.0<=z<=1.0 ? 

			Thanks,

				Andrew
				avr@purdue.edu
				{pur-ee,ucbvax,decvax}!purdue!avr

" ratcliffe) (04/02/91)

In article <14144@medusa.cs.purdue.edu> avr@cs.purdue.EDU (Andrew V. Royappa) writes:
>The gl graphics user's guide says that the perspective & viewing
>transformations transforms the perspective pyramid into the box 
>-1.0 <= x,y,z <= 1.0, to facilitate clipping. Is this in fact
>the case, 
yep--this *is* the case -1.0 to 1.0 for x, y, *and* z clipping.

>           or are the box's bounds given by something else
>e.g. -1.0<=x,y<=1.0 and 0.0<=z<=1.0 ? 
nope.  this is not the case.
--
                                             daveus rattus   

                                   yer friendly neighborhood ratman

                              KOYAANISQATSI

   ko.yan.nis.qatsi (from the Hopi Language)  n.  1. crazy life.  2. life
       in turmoil.  3. life out of balance.  4. life disintegrating.  
         5. a state of life that calls for another way of living.

tarolli@westcoast.esd.sgi.com (Gary Tarolli) (04/03/91)

In article <1991Apr2.150125.22972@odin.corp.sgi.com>, dave@sgi.com (dave "who can do? ratmandu!" ratcliffe) writes:
> In article <14144@medusa.cs.purdue.edu> avr@cs.purdue.EDU (Andrew V. Royappa) writes:
> >The gl graphics user's guide says that the perspective & viewing
> >transformations transforms the perspective pyramid into the box 
> >-1.0 <= x,y,z <= 1.0, to facilitate clipping. Is this in fact
> >the case, 
> yep--this *is* the case -1.0 to 1.0 for x, y, *and* z clipping.
> 

actually we clip against -w and +w, where w is normally 1.0 for orthographic
projections.  For perspective transformations, w is NOT 1.0, and instead of
transforming the pyramid into a unit box, we really do clip against the 
pyramid.  

--------------------
	Gary Tarolli

avr@cs.purdue.EDU (Andrew V. Royappa) (04/03/91)

>In article <1991Apr2.150125.22972@odin.corp.sgi.com>, dave@sgi.com (dave "who can do? ratmandu!" ratcliffe) writes:
>> In article <14144@medusa.cs.purdue.edu> avr@cs.purdue.EDU (Andrew V. Royappa) writes:
>> >The gl graphics user's guide says that the perspective & viewing
>> >transformations transforms the perspective pyramid into the box 
>> >-1.0 <= x,y,z <= 1.0, to facilitate clipping. Is this in fact
>> >the case, 
>> yep--this *is* the case -1.0 to 1.0 for x, y, *and* z clipping.
>> 
>
>actually we clip against -w and +w, where w is normally 1.0 for orthographic
>projections.  For perspective transformations, w is NOT 1.0, and instead of
>transforming the pyramid into a unit box, we really do clip against the 
>pyramid.  
>
>--------------------
>	Gary Tarolli
>
>

Huh. Well, I'm writing some simple 3D routines using X11, and decided
to use the gl transformations printed at the back of the manual. After
applying the MVP matrix to a line segment, I clip against 
-1.0<=x,y,z<=1.0. I see errors sometime even though the clip appears
to do exactly what I want it do. 

So then, should I clip against the cube only when using the ortho
projections, and against the pyramid when using perspective ?

If yes, could you please give me the exact bounds of the pyramid used by
gl ?

Thank you both for your help.

					Andrew

tarolli@westcoast.esd.sgi.com (Gary Tarolli) (04/03/91)

In article <14154@medusa.cs.purdue.edu>, avr@cs.purdue.EDU (Andrew V. Royappa) writes:
> 
> 
> >In article <1991Apr2.150125.22972@odin.corp.sgi.com>, dave@sgi.com (dave "who can do? ratmandu!" ratcliffe) writes:
> >> In article <14144@medusa.cs.purdue.edu> avr@cs.purdue.EDU (Andrew V. Royappa) writes:
> >> >The gl graphics user's guide says that the perspective & viewing
> >> >transformations transforms the perspective pyramid into the box 
> >> >-1.0 <= x,y,z <= 1.0, to facilitate clipping. Is this in fact
> >> >the case, 
> >> yep--this *is* the case -1.0 to 1.0 for x, y, *and* z clipping.
> >> 
> >
> >actually we clip against -w and +w, where w is normally 1.0 for orthographic
> >projections.  For perspective transformations, w is NOT 1.0, and instead of
> >transforming the pyramid into a unit box, we really do clip against the 
> >pyramid.  
> >
> 
> Huh. Well, I'm writing some simple 3D routines using X11, and decided
> to use the gl transformations printed at the back of the manual. After
> applying the MVP matrix to a line segment, I clip against 
> -1.0<=x,y,z<=1.0. I see errors sometime even though the clip appears
> to do exactly what I want it do. 
> 
> So then, should I clip against the cube only when using the ortho
> projections, and against the pyramid when using perspective ?
> 
> If yes, could you please give me the exact bounds of the pyramid used by
> gl ?
> 
If you are using ortho, you can safely clip against -1.0, 1.0 since this
is the value of w anyway.  But if you are using perspective, then things
get very tricky.  Most people clip in homogeneous space (x,y,z,w).  If you
don't then I believe it is very difficult to do things mathematically 
correct. Anyway, in homogeneous space you clip against -w and +w.  That is
the pyramid.  I suggest you look at Newman+Sproull or Foley and VanDam
for more info on homogeneous spaces and line clipping.  Its more tricky then
you think, and its even trickier then they allude to.  For example if
you try to clip in normalize device coords after division by w, what do
you do if w=0?  I think that's why most people clip in homogeneous space...
Good luck...


--------------------
	Gary Tarolli

bruceh@sgi.com (Bruce R. Holloway) (04/03/91)

In article <14154@medusa.cs.purdue.edu> avr@cs.purdue.edu (Andrew V. Royappa) writes:
>>> 
>>> In article <14144@medusa.cs.purdue.edu> avr@cs.purdue.EDU (Andrew V. Royappa) writes:
>>>>
>>>>The gl graphics user's guide says that the perspective & viewing
>>>>transformations transforms the perspective pyramid into the box 
>>>>-1.0 <= x,y,z <= 1.0, to facilitate clipping. Is this in fact
>>>>the case, 
>>
>>actually we clip against -w and +w, where w is normally 1.0 for orthographic
>>projections.  For perspective transformations, w is NOT 1.0, and instead of
>>transforming the pyramid into a unit box, we really do clip against the 
>>pyramid.  
>>
>>	Gary Tarolli
>
>Huh. Well, I'm writing some simple 3D routines using X11, and decided
>to use the gl transformations printed at the back of the manual. After
>applying the MVP matrix to a line segment, I clip against 
>-1.0<=x,y,z<=1.0. I see errors sometime even though the clip appears
>to do exactly what I want it do. 
>
>So then, should I clip against the cube only when using the ortho
>projections, and against the pyramid when using perspective ?
>
>If yes, could you please give me the exact bounds of the pyramid used by
>gl ?

The most popular texts on computer graphics do describe clipping in the
intervals -1 <= x,y <= 1 and 0 <= z <= 1.  When the original Geometry
Engine(tm) chip was designed, all three axes were treated equally for
simplicity, and this is the way SGI has always done it.  I've heard that
Jim Blinn has suggested that in some cases the most efficient way is to
use the intervals 0 <= x,y,z <= 1.  In other words, you might be able to
save a few floating-point ALU cycles.  Anyway, you can use any of these
methods, it's just that your projection matrix will be a little different.

Clipping may be done the same for both orthographic & perspective
projections and generally precedes the perspective division step in the
calculation.  The coordinates following perspective division are what must
map into the canonical view volume.  Here's how that works.  It is required
that -1 <= (x/w) <= +1, so if w > 0, -w <= x <= +w.  Thus, the requirement
may be expressed as the two conditions w + x >= 0 and w - x >= 0, without
actually investing any time in the perspective division until it is
determined that the point is inside the view volume.  (It's a bit of a
tangent, but I can explain separately why w > 0 for the projection
matrices we use, if necessary.)

Regards, bruceh

avr@cs.purdue.EDU (Andrew V. Royappa) (04/03/91)

OK, I've read the articles by Bruce Holloway & Gary Tolling. The
articles were somewhat dense; unfortunately, so am I. I'm
still not sure what I'm doing wrong. 

Here's what I`m doing, for *perspective* projection:

(1) extend from 3D to 4D coordinates; multiply by MVP matrices given at
back of gl user's guide. 

(2) divide 4D result by w to return to 3D

(3) clip resulting geometry against -1.0<=x,y,z<=1.0

Now, I'm interested in correctness more than speed (as I'm doing this
in software, over X, I'm obviously not interested in speed).

Since bruceh says that the gl matrices guarantee w > 0, I don't see
any problem regarding correctness with the division in step (2). The
only modelling  matrices (the "M" of the "MVP" above) that I use are
translate, scale and rotate. What could I still be doing wrong ?

Well, this discussion is helping me understand this stuff a lot
better.

				Thanks again,

					Andrew

bruceh@sgi.com (Bruce R. Holloway) (04/04/91)

In article <14168@medusa.cs.purdue.edu> avr@cs.purdue.edu (Andrew V. Royappa) writes:
>
>OK, I've read the articles by Bruce Holloway & Gary Tarolli...
>
>Here's what I`m doing, for *perspective* projection:
>
>(1) extend from 3D to 4D coordinates; multiply by MVP matrices given at
>back of gl user's guide. 
>
>(2) divide 4D result by w to return to 3D
>
>(3) clip resulting geometry against -1.0<=x,y,z<=1.0

Well, both Gary & I said to clip before doing the perspective division.

>Since bruceh says that the gl matrices guarantee w > 0, I don't see
>any problem regarding correctness with the division in step (2). The
>only modelling  matrices (the "M" of the "MVP" above) that I use are
>translate, scale and rotate. What could I still be doing wrong ?

I guess what I said about w > 0 was unclear.  If the near plane is in front
of the eye (which our perspective() & window() routines force you to do)
and if you extend from 3D to 4D by introducing some w > 0, then after
clipping against the near plane it is guaranteed that the transformed w > 0.
You should clip so that -w <= x,y,z <= +w before dividing.

Regards, bruceh