🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.sys.sgi.misc
2 messages
2 total messages Started by Stephen Lau Thu, 21 Jan 1993 20:54
Help with matrix stack
#247
Author: Stephen Lau
Date: Thu, 21 Jan 1993 20:54
28 lines
1683 bytes
I'm trying to use the matrix stack to construct a transformation
matrix that converts an object's coordinates to window coordinates.

I've done it manually, constructing my own matrices and converting
the coordinates, but what I really want to do is to utilize some
of the GL calls, namely perspective, rotate, translate, scale and
lookat.

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. 

Any help would be most appreciated.

Steve

-------------------------------------------------------------------------------
Stephen Lau                 lau@ai.sri.com| 
SRI International                         | "Frosted milk with cereal and juice
333 Ravenswood Ave., Menlo Park, CA. 94025|  forms a complete breakfast!"
(415) 859-2925              (415) 326-6200|            - Ren & Stimpy     
-------------------------------------------------------------------------------
Re: Help with matrix stack
#248
Author: Howard Look
Date: Thu, 21 Jan 1993 22:45
61 lines
2911 bytes
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.
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads