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

  1. /*** SOURCE5.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 <stdlib.h>
  9. #include <time.h>
  10.  
  11. unsigned nu = 20, nv = 60;
  12. FILE *arq;
  13.  
  14. /* Parametric equations that define the surface */
  15. float f1(float u, float v) { return (4 + 1.5*sin(u))*sin(v); }
  16. float f2(float u, float v) { return (4 + 1.5*sin(u))*cos(v); }
  17. float f3(float u, float v) { return 1.5*cos(u) + 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.  
  29.   fprintf(arq, "%u\n", (nu + 1)*(nv + 1));
  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.   for (i = 1; i <= (nu + 1)*(nv + 1); i++)
  36.     if (i % (nu + 1) == 1) {
  37.       color = 1 + random(15);
  38.       fprintf(arq, "%u %u\n", i, 0);
  39.     } else fprintf(arq, "%u %u\n", i, color);
  40.  
  41. }
  42.  
  43. /* ------------------------------------------------------------------------- */
  44.  
  45. void PrintMsg(void) {
  46.  
  47.   fprintf(arq, "\n%s", "Spring, F(u, v) = ((5+2*sin(u))*sin(v), "
  48.                      "(5+2*sin(u))*cos(v), 2*cos(u)+v)");
  49.   fprintf(arq, "\n%s", "Lenimar Nunes de Andrade, ccendm03@brufpb.bitnet\n");
  50. }
  51.  
  52. /* ------------------------------------------------------------------------- */
  53.  
  54. void main(void) {
  55.  
  56.   time_t x;
  57.  
  58.   srand ((unsigned) time(&x));
  59.   randomize();
  60.  
  61.   if ((arq = fopen("demo5.3dv", "wt")) == NULL) return;
  62.   CalcPoints(0, 6.2832, -7.5, 7.5);
  63.   PrintMsg();
  64.   fclose(arq);
  65. }
  66.  
  67. /* ------------------------------------------------------------------------- */
  68.  
  69. /*** END OF SOURCE5.C ***/
  70.