home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / 3DVIS10.ZIP / SOURCE6.C < prev    next >
Text File  |  1996-02-29  |  2KB  |  72 lines

  1. /*** SOURCE6.C - Creates a .3DV file with the definition of a surface
  2.          by Lenimar N. Andrade, ccendm03@brufpb.bitnet
  3.       Dep. of Mathematics - Universidade Federal da Paraíba - Brazil ***/
  4.  
  5. #include <stdio.h>
  6. #include <math.h>
  7. #include <conio.h>
  8. #include <time.h>
  9. #include <stdlib.h>
  10.  
  11. unsigned nu = 25, nv = 80;
  12. FILE *arq;
  13.  
  14. /* Parametric equations that define the surface */
  15. float f1(float u, float v) { return u*sin(v); }
  16. float f2(float u, float v) { return u*cos(v); }
  17. float f3(float u, float v) { return v; }
  18.  
  19. /* ------------------------------------------------------------------------- */
  20.  
  21. void CalcPoints(float umin, float umax, float vmin, float vmax) {
  22.  
  23.   float u, v, incrU, incrV;
  24.   unsigned i, color;
  25.  
  26.   incrU = (umax - umin)/nu;
  27.   incrV = (vmax - vmin)/nv;
  28.   fprintf(arq, "%u\n", (nu + 1)*(nv + 1));
  29.  
  30.   for (v = vmin; v < vmax + incrV/2; v += incrV)
  31.     for (u = umin; u < umax + incrU/2; u+= incrU)
  32.       fprintf(arq, "%6.3f %6.3f %6.3f\n", f1(u, v), f2(u, v), f3(u, v));
  33.  
  34.   fprintf(arq, "%u\n", (nu + 1)*(nv + 1));
  35.  
  36.   for (i = 1; i <= (nu + 1)*(nv + 1); i++)
  37.     if (i % (nu + 1) == 1) {
  38.       color = 1 + random(15);
  39.       fprintf(arq, "%u %u\n", i, 0);
  40.     }
  41.     else
  42.       fprintf(arq, "%u %u\n", i, color);
  43.  
  44. }
  45.  
  46. /* ------------------------------------------------------------------------- */
  47.  
  48. void PrintMsg(void) {
  49.  
  50.   fprintf(arq, "\n%s", "Helicoid, F(u, v) = (u*cos(v), u*sin(v), v)");
  51.   fprintf(arq, "\n%s", "Lenimar Nunes de Andrade, ccendm03@brufpb.bitnet\n");
  52. }
  53.  
  54. /* ------------------------------------------------------------------------- */
  55.  
  56. void main(void) {
  57.  
  58.   time_t x;
  59.  
  60.   srand ((unsigned) time(&x));
  61.   randomize();
  62.  
  63.   if ((arq = fopen("demo6.3dv", "wt")) == NULL) return;
  64.   CalcPoints(-5, 5, -5, 5);
  65.   PrintMsg();
  66.   fclose(arq);
  67. }
  68.  
  69. /* ------------------------------------------------------------------------- */
  70.  
  71. /*** END OF SOURCE6.C ***/
  72.