home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / s / sndppr3w.zip / FILE.C < prev    next >
C/C++ Source or Header  |  1992-01-24  |  3KB  |  134 lines

  1. /* File.C
  2. ** 4/26/91
  3. ** mjs
  4. */
  5.  
  6. /*
  7.     12/06/91 -- Vivid output modified for 2.0 format (equals signs
  8.         and semicolons removed)  Stephen Coy
  9.  
  10. */
  11.  
  12. #include "sp.h"
  13.  
  14. static char *tri_prefix;
  15. static char *vert_str;
  16. static char *norm_str;
  17. static char *tri_suffix;
  18. static void output_triangles(void);
  19.  
  20. /************************************************************************/
  21. /* Triangle output routines    */
  22.  
  23. /* Raw output format    */
  24. void raw_out()
  25. {
  26.     tri_prefix = "";
  27.     vert_str = "%7.4f %7.4f %7.4f ";
  28.     norm_str = "%7.4f %7.4f %7.4f\n";
  29.     tri_suffix = "\n";
  30.     output_triangles();
  31. }
  32.  
  33. /* NFF (MTV) output format    */
  34. void nff_out()
  35. {
  36.     tri_prefix = "pp 3\n";
  37.     vert_str = "%7.4f %7.4f %7.4f ";
  38.     norm_str = "%7.4f %7.4f %7.4f\n";
  39.     tri_suffix = "\n";
  40.     output_triangles();
  41. }
  42.  
  43. /* Rayshade output format    */
  44. void rsh_out()
  45. {
  46.     tri_prefix = "triangle\n";
  47.     vert_str = "%7.4f %7.4f %7.4f ";
  48.     norm_str = "%7.4f %7.4f %7.4f\n";
  49.     tri_suffix = "\n";
  50.     output_triangles();
  51. }
  52.  
  53. /* Vivid output format    */
  54. void viv_out()
  55. {
  56.     tri_prefix = "patch {\n";
  57.     vert_str = "\tvertex %7.4f %7.4f %7.4f " ;
  58.     norm_str = " normal %7.4f %7.4f %7.4f\n" ;
  59.     tri_suffix = "}\n\n";
  60.     output_triangles();
  61. }
  62.  
  63. /* Vivid output format    */
  64. void viv1_out()
  65. {
  66.     tri_prefix = "patch = {\n";
  67.     vert_str = "\tvertex = %7.4f %7.4f %7.4f; " ;
  68.     norm_str = " normal = %7.4f %7.4f %7.4f;\n" ;
  69.     tri_suffix = "}\n\n";
  70.     output_triangles();
  71. }
  72.  
  73. /* DKBTrace (STAR) output format    */
  74. void dkb_out()
  75. {
  76.     tri_prefix = "SMOOTH_TRIANGLE\n";
  77.     vert_str = "< %7.4f %7.4f %7.4f > " ;
  78.     norm_str = "< %7.4f %7.4f %7.4f >\n";
  79.     tri_suffix = "END_TRIANGLE\n\n";
  80.     output_triangles();
  81. }
  82.  
  83. /* PoV Ray output format    */
  84. void pov_out()
  85. {
  86.     tri_prefix = "smooth_triangle\n";
  87.     vert_str = "< %7.4f %7.4f %7.4f > " ;
  88.     norm_str = "< %7.4f %7.4f %7.4f >\n";
  89.     tri_suffix = "end_triangle\n\n";
  90.     output_triangles();
  91. }
  92.  
  93. /* Output triangles with normals    */
  94. void output_triangles()
  95. {
  96.     Triangle *t;
  97.  
  98.     t = t_root;
  99.     while(t != NULL) {
  100.         printf(tri_prefix);
  101.  
  102.         printf(vert_str, t->p1->x,  t->p1->y,  t->p1->z );
  103.         printf(norm_str, t->p1->nx, t->p1->ny, t->p1->nz);
  104.  
  105.         printf(vert_str, t->p2->x,  t->p2->y,  t->p2->z );
  106.         printf(norm_str, t->p2->nx, t->p2->ny, t->p2->nz);
  107.  
  108.         printf(vert_str, t->p3->x,  t->p3->y,  t->p3->z );
  109.         printf(norm_str, t->p3->nx, t->p3->ny, t->p3->nz);
  110.  
  111.         printf(tri_suffix);
  112.  
  113.         t = t->next;        /* step to next in list    */
  114.     }
  115. }
  116.  
  117. /************************************************************************/
  118. /* Read a new triangle from stdin, saving the coordinates in the global
  119. ** variables.  Return TRUE if good data was read, else return FALSE.
  120. ** This is a *very* simple routine that expects *very* simple input data.
  121. ** It would be nice if it were intelligent enough to scan a ready-to-run
  122. ** tracer input file and pull out the data of interest, but...
  123. */
  124.  
  125. int read_triangle()
  126. {
  127. if(3 != (scanf(" %f%f%f \n",&new_v1.x, &new_v1.y, &new_v1.z))) return(FALSE);
  128. if(3 != (scanf(" %f%f%f \n",&new_v2.x, &new_v2.y, &new_v2.z))) return(FALSE);
  129. if(3 != (scanf(" %f%f%f \n",&new_v3.x, &new_v3.y, &new_v3.z))) return(FALSE);
  130.     return(TRUE);
  131. }
  132.  
  133. /*** eof ****************************************************************/
  134.