home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1996 September / macformat-041.iso / mac / Shareware City / Graphics / MacSPD / Sources / libinf.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-04-30  |  4.0 KB  |  165 lines  |  [TEXT/MMCC]

  1. /*
  2.  * libinf.c - general info routines.
  3.  *
  4.  * Author:  Eric Haines, 3D/Eye, Inc.
  5.  *
  6.  */
  7.  
  8. /*-----------------------------------------------------------------*/
  9. /* include section */
  10. /*-----------------------------------------------------------------*/
  11.  
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14. #include <math.h>
  15. #include <string.h>
  16.  
  17. #include "lib.h"
  18. #include "drv.h"
  19.  
  20.  
  21. /*-----------------------------------------------------------------*/
  22. /* defines/constants section */
  23. /*-----------------------------------------------------------------*/
  24.  
  25. #ifdef OUTPUT_TO_FILE
  26. FILE * gStdout_file = NULL;
  27. #endif /* OUTPUT_TO_FILE */
  28.  
  29.  
  30. /*-----------------------------------------------------------------*/
  31. /* Here are some local variables that are used to control things like
  32.    the current output file, current texture, ... */
  33. FILE *gOutfile       = stdout;
  34. char *gTexture_name  = NULL;
  35. int  gTexture_count  = 0;
  36. int  gObject_count   = 0;
  37. double gTexture_ior  = 1.0;
  38. int  gRT_out_format  = OUTPUT_NFF;
  39. int  gRT_orig_format = OUTPUT_NFF;
  40. int  gU_resolution   = OUTPUT_RESOLUTION;
  41. int  gV_resolution   = OUTPUT_RESOLUTION;
  42. COORD3 gBkgnd_color  = {0.0, 0.0, 0.0};
  43. COORD3 gFgnd_color   = {0.0, 0.0, 0.0};
  44. double gView_bounds[2][3];
  45. int gView_init_flag  = 0;
  46. char *gLib_version_str = LIB_VERSION;
  47.  
  48. surface_ptr gLib_surfaces = NULL;
  49. object_ptr gLib_objects   = NULL;
  50. light_ptr gLib_lights     = NULL;
  51.  
  52. viewpoint gViewpoint = {
  53.     {0, 0, -10},
  54.     {0, 0, 0},
  55.       {0, 1, 0},
  56.       45, 1, 1.0e-3, 10, 128, 128,
  57.     { {1, 0, 0, 0}, {0, 1, 0, 0}, {0, 0, 1, 0}, {0, 0, 0, 1} }
  58. };
  59.  
  60. /* Globals for tracking indentation level of output file */
  61. int      gTab_width = 4;
  62. int      gTab_level = 0;
  63.  
  64.  
  65.  
  66. /*-----------------------------------------------------------------*/
  67. void tab_indent PARAMS((void))
  68. {
  69.     int      k;
  70.     /* Q&D way to do it... */
  71.     for (k=0; k<gTab_width*gTab_level; k++)
  72.       putc(' ', gOutfile);
  73. } /* tab_printf */
  74.  
  75.  
  76. /*-----------------------------------------------------------------*/
  77. void tab_inc PARAMS((void))
  78. {
  79.     gTab_level++;
  80. } /* tab_inc */
  81.  
  82.  
  83. /*-----------------------------------------------------------------*/
  84. void tab_dec PARAMS((void))
  85. {
  86.     gTab_level--;
  87.     if (gTab_level < 0)
  88.     gTab_level = 0;
  89. } /* tab_dec */
  90.  
  91.  
  92. /* Library info functions */
  93.  
  94. /*-----------------------------------------------------------------*/
  95. char *
  96. lib_get_version_str PARAMS((void))
  97. {
  98.     return gLib_version_str;
  99. } /* lib_get_version_str */
  100.  
  101.  
  102. /*-----------------------------------------------------------------*/
  103. /* Routines to set/reset the various output parameters             */
  104. /*-----------------------------------------------------------------*/
  105. void lib_set_output_file (new_outfile)
  106. FILE *new_outfile;
  107. {
  108.     if (new_outfile == NULL)
  109.      gOutfile = stdout;
  110.     else
  111.       gOutfile = new_outfile;
  112. }
  113.  
  114. /*-----------------------------------------------------------------*/
  115. void lib_set_default_texture (default_texture)
  116. char *default_texture;
  117. {
  118.     gTexture_name = default_texture;
  119. }
  120.  
  121. /*-----------------------------------------------------------------*/
  122. void
  123. lib_set_raytracer(default_tracer)
  124. int default_tracer;
  125. {
  126.     if (default_tracer < OUTPUT_VIDEO ||
  127.      default_tracer > OUTPUT_DELAYED) {
  128.       fprintf(stderr, "Unknown renderer index: %d\n", default_tracer);
  129.     exit(1);
  130.     }
  131.     gRT_out_format = default_tracer;
  132. }
  133.  
  134. /*-----------------------------------------------------------------*/
  135. void
  136. lib_set_polygonalization(u_steps, v_steps)
  137.     int u_steps, v_steps;
  138. {
  139.     if ((u_steps > 0) && (v_steps > 0)) {
  140.     gU_resolution = u_steps;
  141.     gV_resolution = v_steps;
  142.     }
  143. }
  144.  
  145. /*-----------------------------------------------------------------*/
  146. void
  147. lookup_surface_stats(index, tcount, tior)
  148.     int index, *tcount;
  149.     double *tior;
  150. {
  151.     surface_ptr temp_ptr = gLib_surfaces;
  152.  
  153.     while (temp_ptr != NULL && temp_ptr->surf_index != index)
  154.        temp_ptr = temp_ptr->next;
  155.     if (temp_ptr != NULL) {
  156.       *tior = temp_ptr->ior;
  157.       if (*tior < 1.0) *tior = 1.0;
  158.       *tcount = temp_ptr->surf_index;
  159.     }
  160.     else {
  161.        *tior = 1.0;
  162.        *tcount = 0;
  163.     }
  164. }
  165.