home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / graphics / 12266 < prev    next >
Encoding:
Text File  |  1992-11-24  |  3.9 KB  |  137 lines

  1. Xref: sparky comp.graphics:12266 comp.graphics.visualization:1809 comp.graphics.explorer:341 comp.sys.sgi:16805 comp.graphics.animation:1098 comp.windows.x.intrinsics:563
  2. Path: sparky!uunet!olivea!sgigate!odin!bananapc.csd.sgi.com!ciemo
  3. From: ciemo@bananapc.csd.sgi.com (Dave Ciemiewicz)
  4. Newsgroups: comp.graphics,comp.graphics.visualization,comp.graphics.explorer,comp.sys.sgi,comp.graphics.animation,comp.windows.x.intrinsics
  5. Subject: Re: Help needed about the Normal System.
  6. Message-ID: <1992Nov24.022611.24903@odin.corp.sgi.com>
  7. Date: 24 Nov 92 02:26:11 GMT
  8. References: <1992Nov20.200847.4985@ringer.cs.utsa.edu>
  9. Sender: news@odin.corp.sgi.com (Net News)
  10. Organization: Silicon Graphics, Customer Support Division
  11. Lines: 123
  12. Nntp-Posting-Host: bananapc.csd.sgi.com
  13.  
  14. In article <1992Nov20.200847.4985@ringer.cs.utsa.edu>, cqu@ringer.cs.utsa.edu (Chang-ning Qu) writes:
  15. |>  ...
  16. |>    The problem is that we couldn't get correct illumination
  17. |> when displaying in draw-solid and draw-lighted, they are just
  18. |> reversed (lighted sides to be dark and dark becoming lighted)!
  19. |>    
  20. |>     The normal system of the original code seems using
  21. |> 
  22. |>        -->      x1-x2     -(y1-y2)
  23. |>         n  = ( --------,  --------, 0 )
  24. |>                  NORM       NORM
  25. |> 
  26.  
  27. There is a feature of the GL called TWOSIDED lighting that might be
  28. biting you with respect to the Render module.  The GL has this notion
  29. of polygons being drawn "backfacing" or "frontfacing".  This face
  30. orientation is determined by the traversal order of the polygon
  31. vertices when drawing the object.  When the "face" orientation of the
  32. polygon is frontfacing (pointing toward from screen), the lighting
  33. MATERIAL is used.  When the polygon face orientation is backfacing
  34. (pointing away from the screen), the BACKMATERIAL is used.  The normal
  35. is used by the lighting computations to determine how to "light" the
  36. BACKMATERIAL or MATERIAL of the polygon.  See lmbind(3G) for more
  37. details.
  38.  
  39. To guarantee that you get the orientation and lighting normals line up,
  40. you need to use the same traversal order for the vertices that you would
  41. use in computing the normal.
  42.  
  43. Attached is a cxGeo module program which illustrates
  44.  
  45. Create a module which has passes "cxGeo* Scalar &" to the sendCubeGeom()
  46. function.  Connect this to a Geometry output port.  This module will
  47. only generate a cube geometry data set when you manually fire the 
  48. module.  There are no inputs to the module which would cause to fire
  49. on it's own.
  50.  
  51.                         --- Dave
  52. ----- gencube.c ------------------------------------------------------------
  53.  
  54. #include <cx/DataTypes.h>
  55. #include <cx/DataAccess.h>
  56. #include <cx/Geometry.h>
  57.  
  58. static float cubepoints[] = {
  59.     -1, -1, -1,
  60.     -1, -1,  1,
  61.     -1,  1, -1,
  62.     -1,  1,  1,
  63.      1, -1, -1,
  64.      1, -1,  1,
  65.      1,  1, -1,
  66.      1,  1,  1
  67. };
  68.  
  69.  
  70. static long cubefaces[] = {
  71.     0, 1, 3, 2, -1,
  72.     0, 4, 5, 1, -1,
  73.     0, 2, 6, 4, -1,
  74.     1, 5, 7, 3, -1,
  75.     2, 3, 7, 6, -1,
  76. /*
  77.     4, 5, 7, 6, -1    
  78. */
  79.     4, 6, 7, 5, -1
  80. };
  81.  
  82.  
  83. static float cubefacenormals[] = {
  84.     -1,  0,  0,
  85.      0, -1,  0,
  86.      0,  0, -1,
  87.      0,  0,  1,
  88.      0,  1,  0,
  89.      1,  0,  0
  90. };
  91.  
  92.  
  93. static float cubefacecolors[] = {
  94.      1,  0,  0,
  95.      0,  1,  0,
  96.      0,  0,  1,
  97.      1,  1,  0,
  98.      1,  0,  1,
  99.      0,  1,  1
  100. };
  101.  
  102.  
  103. void
  104. sendCubeGeom(cxGeometry **geom)
  105. {
  106.     /* Initialize geometry library first time module is called */
  107.     static int initgeom = 1;
  108.     if (initgeom)
  109.     {
  110.         initgeom = 0;
  111.         cxGeoInit();
  112.     }
  113.  
  114.  
  115.     /* Create new geometry buffer */
  116.     *geom = cxGeoNew();
  117.     cxGeoBufferSelect(*geom);
  118.  
  119.     cxGeoRoot();
  120.     cxGeoDelete();
  121.  
  122.     cxGeoPolysDefine(8, cubepoints, 30, cubefaces);
  123.     cxGeoNormalAdd(6, cubefacenormals, CX_GEO_PER_FACE);
  124.     cxGeoColorAdd(6, cubefacecolors, CX_GEO_PER_FACE);
  125.  
  126.     cxGeoBufferClose(*geom);
  127. }
  128.  
  129.  
  130. -- 
  131.  
  132.     __   * __   _  __  ___            
  133.    /  \ / / /  / \/  \/   \     He was a man like any other man, however, not
  134.   /    /  \/  /  /\  /    /    quite like any other man.
  135.   \___/\__/\_/  /_/ / \__/    
  136.                *        
  137.