Allan Schaffer (allan)
Mon, 27 Oct 1997 18:05:07 -0800
I've read some of the other responses & suspect you're looking for
the basic perspective projection algorithm rather than anything
cartographic. This has come up a few times here on info-performer
before, so you might want to check the archives for better answers.
Archives at: ftp://sgigate.sgi.com/pub/Performer/monthly-archives
Off the top of my head, though:
In IRIS GL, there was a wonderful trick which could be used to
convert (x,y,z) in object-space coordinates to a screen (x,y). As
follows:
cmov(x,y,z);
getcpos(&x1, &y1);
The drawback of this is that it does require a read back from the
graphics pipe. And of course it's IRIS GL, whereas you're hopefully
using the OpenGL-based version of Performer. Furthermore it would
only work from within the Performer DRAW process.
In OpenGL, I -think- one of the more direct routines is:
gluProject()
gluProject transforms the specified object coordinates into
window coordinates using model, proj, and view. The result is
stored in winX, winY, and winZ. A return value of GL_TRUE
indicates success, and GL_FALSE indicates failure.
Likewise this would require you to query the graphics pipe (for the
modelview & projection matrices) and so would only work from within
the Performer DRAW process.
The basic algorithm is fairly simple & would be in any computer
graphics book. Let [XYZW] be a 4x1 vector containing the x,y,z world
coordinates and W=1. Let [M] be the current 4x4 modelview matrix.
Let [P] be the current 4x4 projection matrix.
[XYZW] x [M] x [P] = [X'Y'Z'W']
Where [X'Y'Z'W'] is a 1x4 vector containing the result. Clip this to
your viewport and you should have your answer.
Don't forget that window coordinates have a Z value too. That's for
the Z buffer, maybe you only care about X & Y though..
Sorry if this is all brutally obvious.
Allan
--
Allan Schaffer allan++at++sgi.com
Silicon Graphics http://reality.sgi.com/allan
=======================================================================
List Archives, FAQ, FTP: http://www.sgi.com/Technology/Performer/
Submissions: info-performer++at++sgi.com
Admin. requests: info-performer-request++at++sgi.com
This archive was generated by hypermail 2.0b2 on Mon Aug 10 1998 - 17:56:08 PDT