home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / sys / sgi / misc / 346 < prev    next >
Encoding:
Internet Message Format  |  1993-01-21  |  2.8 KB

  1. Path: sparky!uunet!cs.utexas.edu!sun-barr!ames!sgi!fido!koosh.asd.sgi.com!howardl
  2. From: howardl@koosh.asd.sgi.com (Howard Look)
  3. Newsgroups: comp.sys.sgi.misc
  4. Subject: Re: Help with matrix stack
  5. Date: 21 Jan 1993 22:45:30 GMT
  6. Organization: Silicon Graphics Inc., Mountain View, CA
  7. Lines: 66
  8. Distribution: comp
  9. Message-ID: <1jn92aINNh8s@fido.asd.sgi.com>
  10. References: <LAU.93Jan21125414@sunset.ai.sri.com>
  11. Reply-To: howardl@koosh.asd.sgi.com (Howard Look)
  12. NNTP-Posting-Host: koosh.asd.sgi.com
  13.  
  14. In article <LAU.93Jan21125414@sunset.ai.sri.com>, lau@sunset.ai.sri.com
  15. (Stephen Lau) writes:
  16. |> ...
  17. |> I would like to call perspective() and lookat() and then somehow get
  18. |> this combined transformation matrix and use it to do my own coordinate
  19. |> transformations and clipping. Is this possible?
  20. |> 
  21. |> I've tried calling perspective() and lookat() and then getmatrix(), but
  22. |> the resulting matrix doesn't transform it to window coordinates, only to
  23. |> local world coordinates. This is part of the way, but I'm missing the final
  24. |> step that then projects this to window coordinates. 
  25. |> 
  26.  
  27. You must be in mult-matrix mode, that is mmode(MVIEWING). When in this
  28. mode, the
  29. perspective matrix is separated from the modeling-viewing matrix stack.
  30.  
  31. Try this:
  32. getmatrix(modelViewMat);
  33. mmode(MPROJECTION);
  34. getmatrix(projMat);
  35. mmode(MVIEWING);
  36.  
  37. Then use your favorite matrix mult routine to get M = Mmv * Mp.
  38.  
  39. Here's a more detailed explanation that Kurt Akeley posted a while ago:
  40.  
  41.     1.    Transform your point by the current matrix (if in single matrix mode)
  42.     or by the ModelView matrix followed by the Projection matrix (if in
  43.     multiple matrix mode).  Matrix mode is controlled by the mmode()
  44.     command, which also controls which matrix is returned by getmatrix().
  45.     Set the W component of your point to 1.0 prior to transformation.
  46.  
  47.     2.    Clip the resulting transformed point against all 6 clipping planes:
  48.  
  49.         if (x > w OR x < -w OR y > w OR ...)
  50.         then the point does not have a screen coordinate
  51.  
  52.     3.    Project the transformed point by dividing each of x, y, and z by w.
  53.  
  54.     4.    Map the point to window coordinates using the equations:
  55.  
  56.         Xwin = Vsx * X + Vcx
  57.         Ywin = Vsy * Y + Vcy
  58.         Zwin = Vsz * Z + Vcz
  59.  
  60.         Vsx = (right-left+1)/2
  61.         Vsy = (top-bottom+1)/2
  62.         Vsz = (far-near+1)/2
  63.         Vcx = (right+left)/2
  64.         Vcy = (top+bottom)/2
  65.         Vcz = (far+near)/2
  66.  
  67.     5.    Add the window offset to Xwin and Ywin to get screen coordinates.
  68.     Z values are not affected by window position.
  69.  
  70. I've written the Z viewport to be identical to the X and Y viewport operations,
  71. but some SGI machines are off by one on this mapping (no big deal usually).
  72. All computations should be done in floating point.  If screen coordinates are
  73. to be coerced to integers (generally not a good idea) be sure to round toward
  74. nearest.  If truncation is easier, add 0.5 to Vcx, Vcy, and Vcz.
  75.  
  76.  
  77.  
  78.  
  79.  
  80.