home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!cs.utexas.edu!sun-barr!ames!sgi!fido!koosh.asd.sgi.com!howardl
- From: howardl@koosh.asd.sgi.com (Howard Look)
- Newsgroups: comp.sys.sgi.misc
- Subject: Re: Help with matrix stack
- Date: 21 Jan 1993 22:45:30 GMT
- Organization: Silicon Graphics Inc., Mountain View, CA
- Lines: 66
- Distribution: comp
- Message-ID: <1jn92aINNh8s@fido.asd.sgi.com>
- References: <LAU.93Jan21125414@sunset.ai.sri.com>
- Reply-To: howardl@koosh.asd.sgi.com (Howard Look)
- NNTP-Posting-Host: koosh.asd.sgi.com
-
- In article <LAU.93Jan21125414@sunset.ai.sri.com>, lau@sunset.ai.sri.com
- (Stephen Lau) writes:
- |> ...
- |> I would like to call perspective() and lookat() and then somehow get
- |> this combined transformation matrix and use it to do my own coordinate
- |> transformations and clipping. Is this possible?
- |>
- |> I've tried calling perspective() and lookat() and then getmatrix(), but
- |> the resulting matrix doesn't transform it to window coordinates, only to
- |> local world coordinates. This is part of the way, but I'm missing the final
- |> step that then projects this to window coordinates.
- |>
-
- You must be in mult-matrix mode, that is mmode(MVIEWING). When in this
- mode, the
- perspective matrix is separated from the modeling-viewing matrix stack.
-
- Try this:
- getmatrix(modelViewMat);
- mmode(MPROJECTION);
- getmatrix(projMat);
- mmode(MVIEWING);
-
- Then use your favorite matrix mult routine to get M = Mmv * Mp.
-
- Here's a more detailed explanation that Kurt Akeley posted a while ago:
-
- 1. Transform your point by the current matrix (if in single matrix mode)
- or by the ModelView matrix followed by the Projection matrix (if in
- multiple matrix mode). Matrix mode is controlled by the mmode()
- command, which also controls which matrix is returned by getmatrix().
- Set the W component of your point to 1.0 prior to transformation.
-
- 2. Clip the resulting transformed point against all 6 clipping planes:
-
- if (x > w OR x < -w OR y > w OR ...)
- then the point does not have a screen coordinate
-
- 3. Project the transformed point by dividing each of x, y, and z by w.
-
- 4. Map the point to window coordinates using the equations:
-
- Xwin = Vsx * X + Vcx
- Ywin = Vsy * Y + Vcy
- Zwin = Vsz * Z + Vcz
-
- Vsx = (right-left+1)/2
- Vsy = (top-bottom+1)/2
- Vsz = (far-near+1)/2
- Vcx = (right+left)/2
- Vcy = (top+bottom)/2
- Vcz = (far+near)/2
-
- 5. Add the window offset to Xwin and Ywin to get screen coordinates.
- Z values are not affected by window position.
-
- I've written the Z viewport to be identical to the X and Y viewport operations,
- but some SGI machines are off by one on this mapping (no big deal usually).
- All computations should be done in floating point. If screen coordinates are
- to be coerced to integers (generally not a good idea) be sure to round toward
- nearest. If truncation is easier, add 0.5 to Vcx, Vcy, and Vcz.
-
-
-
-
-
-