home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / graphics / 13110 < prev    next >
Encoding:
Text File  |  1992-12-22  |  3.9 KB  |  118 lines

  1. Newsgroups: comp.graphics
  2. Path: sparky!uunet!think.com!rpi!gatech!willis1.cis.uab.edu!sloan
  3. From: sloan@willis.cis.uab.edu (Kenneth Sloan)
  4. Subject: Re: Ordered triplets->homogenized vectors
  5. Message-ID: <1992Dec22.051616.1811@cis.uab.edu>
  6. Sender: sloan@cis.uab.edu (Kenneth Sloan)
  7. Organization: CIS, University of Alabama at Birmingham
  8. References: <38000@uflorida.cis.ufl.edu>
  9. Date: Tue, 22 Dec 1992 05:16:16 GMT
  10. Lines: 106
  11.  
  12. In article <38000@uflorida.cis.ufl.edu> sdk@reef.cis.ufl.edu (Steven "Scrib" Kuck) writes:
  13. >I have having some problems doing 3d clipping to a canonical view volume.
  14.  
  15. Your problem is not with clipping - it is with the perspective
  16. transform.  The bottom line is tha you must clip against a "hither"
  17. plane *before* doing the perspective transform.  You have noticed one
  18. classic problem - but have not (yet) run across a more subtle (but
  19. infinitely more amusing) classic problem.
  20.  
  21. >My points are represented in camera relative points with +Z into the
  22. >screen.  The problem stems that I need to convert these points from
  23. >x,y,z ordered triplets to homogenized vertices.  The equation I'm using
  24. >is from the Texas Instruments 3D Graphics Library documention, and
  25. >looks like this:
  26.  
  27. Beware of cookbooks.  You need a graphics textbook.  For this
  28. subject, I recommend Newman&Sproull - but any decent text will do.
  29.  
  30. >
  31. >given an ordered triplet of ( x, y, z, 1 ), convert to a homogenized
  32. >vector of ( x, y, z, w ).
  33. >
  34. >x = D * x / Sx
  35. >y = D * y / Sy
  36. >z = a * z + b
  37. >w = z
  38. >
  39. >D = distance to the viewport
  40. >Sx = viewport half-width
  41. >Sy = viewport half-height
  42. >a  = z-input scaling constant
  43. >b  = z-input translating constant
  44. >
  45. > a = 1 + ( N/F ) 
  46. >     -----------
  47. >     1 - ( N/F )
  48. >
  49. > b = -2 * N
  50. >     -------
  51. >     1 - ( N/F )
  52. >
  53. >where N is near-clipping plane distance and F is the far clipping plane dist.
  54. >
  55. >Okay, now that that is out of the way, the problem becomes rather apparent.
  56. >In order to convert back to an ordered triplet, where the fourth element
  57. >is 1, you divide by "w", i.e.
  58. >
  59. >[ x, y, z, w ] == [ x /w , y/w, z/w, 1 ]
  60. >
  61. >Now, when I convert TO homogenous vectors and I have an initial Z value of
  62. >0,
  63.  
  64. STOP!  Think! 
  65.  
  66. Question: What does it mean for a point fo have "an initial Z value
  67.           of 0"?  
  68.  
  69. Answer: this point is directly alongside the eyepoint.  It is neither in
  70. front of, nor behind the eye.  In order to "see" this point, you would
  71. need a 180deg field of view.
  72.  
  73. Question: Where in the image plane will this point project?
  74.  
  75. Answer: either the projected x value, or the projected y value, or both,
  76. will be infinite.  This looks bad.
  77.  
  78. Extra Credit Question: what about points with an initial Z value *less
  79. than* 0?
  80.  
  81. >... then W becomes zero, and when I try to divide out by W, I get a divide
  82. >by zero....
  83.  
  84.  
  85. Which turns out to be correct, more or less.  Not the answer you want -
  86. but correct nonetheless.  
  87.  
  88. So...how to avoid this.
  89.  
  90.   "Doctor, Doctor: it hurst when I do this"
  91.  
  92.   "Don't do that!"
  93.  
  94. You cannot allow points with "an initial Z value of 0" to be turned into
  95. homogenous co-ordinates in the first place.  If you do, you lose.
  96. So...you must obviously CLIP BEFORE PERSPECTIVE.  
  97.  
  98. Back to our Extra Credit Question.  After a little thought (or perhaps
  99. some experimentation) you will discover that you cannot apply the
  100. perspective transformation to points with an initial Z value *less than
  101. or equal* to 0.  You must CLIP BEFORE PERSPECTIVE.
  102.  
  103. Next, you will decide that it is bad news to divide by even very small
  104. positive values.  Instead of clipping against Z==0.0, you should clip
  105. against Z==hither - where the value of "hither" depends on other
  106. parameters.  All we know so far is that "hither" should be larger than
  107. the smallest number you feel comfortable dividing by.
  108.  
  109. See Newman&Sproull.
  110.  
  111.  
  112.  
  113. -- 
  114. Kenneth Sloan                   Computer and Information Sciences
  115. sloan@cis.uab.edu               University of Alabama at Birmingham
  116. (205) 934-2213                  115A Campbell Hall, UAB Station 
  117. (205) 934-5473 FAX              Birmingham, AL 35294-1170
  118.