home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / mac / developm / source / povsrc.sit / MISC / HFSOMB.C < prev    next >
Encoding:
C/C++ Source or Header  |  1992-04-26  |  1.3 KB  |  53 lines

  1. /* Test file to create a Targa height field for POV-Ray -- Alexander Enzmann */
  2. /* This is a sombrero */
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <math.h>
  6. #include <float.h>
  7. #include "hftarga.c"
  8.  
  9. #define M_PI 3.1415926535897932384626
  10.  
  11. void
  12. main()
  13. {
  14.    float x, y, z;
  15.    float x0, z0;
  16.    float b_const, phase;
  17.    unsigned char r, g, b;
  18.  
  19.    /* Open the ouput file */
  20.    TargaOpen("hfsomb.tga", 160, 160);
  21.  
  22.    /* Adjust the characteristics of the surface */
  23.    b_const = 1.0;
  24.    phase = 0.0;
  25.  
  26.    /* Compute the height of the surface over a square area (80x80) */
  27.    for (x0=-40.0;x0<40.0;x0+=0.5) {
  28.       for (z0=-40.0;z0<40.0;z0+=0.5) {
  29.      /* Want a total of 4 ripples from the center to the edge */
  30.      x = x0 / 10.0;
  31.      z = z0 / 10.0;
  32.  
  33.      /* The height field ranges from 0->256, so use an offset of
  34.         128 for the zero level of the function */
  35.      y = 128;
  36.  
  37.      /* The range of the function is from -1 -> 1, so to make it fit
  38.         the height field box a scale of 127 is used. */
  39.      y += 127.0 * cos(2.0 * M_PI * sqrt(x * x + z * z) + phase) *
  40.               exp(-b_const * sqrt(x * x + z * z));
  41.  
  42.      /* Determine the values to write to the Targa file */
  43.      r = y;
  44.      g = (y - (float)r) * 256.0;
  45.      b = 0;
  46.      TargaWrite(r, g, b);
  47.      }
  48.       }
  49.  
  50.    /* Close em up and get outta here */
  51.    TargaClose();
  52. }
  53.