home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / netds / rpc / mandel / calc.c next >
Encoding:
C/C++ Source or Header  |  1996-06-12  |  2.2 KB  |  85 lines

  1.  
  2. /****************************************************************************
  3.                    Microsoft RPC Version 2.0
  4.            Copyright Microsoft Corp. 1992, 1993, 1994- 1996
  5.                         mandel Example
  6.  
  7.     FILE:       calc.c
  8.  
  9.     PURPOSE:    Server side of the RPC distributed application Mandel
  10.  
  11.     FUNCTIONS:  MandelCalc() - Do the calculations for the Windows
  12.                                Mandelbrot Set distributed drawing program.
  13.  
  14. ****************************************************************************/
  15.  
  16. #include <stdlib.h>
  17. #include <stdio.h>
  18. #include <windows.h>
  19.  
  20. #ifdef RPC
  21. #include "mdlrpc.h"
  22. #endif
  23. #include "mandel.h"
  24.  
  25.  
  26. short calcmand(double, double, short);
  27.  
  28.  
  29. void MandelCalc(PCPOINT    pcptLL,
  30.                 PLONGRECT  prcDraw,
  31.                 double     precision,
  32.                 DWORD      ulThreshold,
  33.                 LINEBUF *  pbBuf)
  34. {
  35.     DWORD   h, height, width;
  36.     double  dreal, dimag, dimag2;
  37.     short   maxit = 0;
  38.     short * pbPtr;
  39.  
  40.     pbPtr = *pbBuf;   // LINEBUF is an array of shorts
  41.  
  42.     dreal = pcptLL->real + ((double)prcDraw->xLeft * precision);
  43.     dimag = pcptLL->imag + ((double)prcDraw->yBottom * precision);
  44.  
  45.     maxit = (short) ulThreshold;
  46.  
  47.     height = (prcDraw->yTop - prcDraw->yBottom) + 1;
  48.     width = (prcDraw->xRight - prcDraw->xLeft) + 1;
  49.  
  50.     for ( ; width > 0; --width, dreal += precision) {
  51.         for (dimag2 = dimag, h = height; h > 0; --h, dimag2 += precision) {
  52.             if ((dreal > 4.0) || (dreal < -4.0) ||
  53.                 (dimag2 > 4.0) || (dimag2 < -4.0))
  54.                 *(pbPtr++) = 0;
  55.             else
  56.                 *(pbPtr++) = calcmand(dreal, dimag2, maxit);
  57.         }
  58.     }
  59. }
  60.  
  61.  
  62. /* C version of the assembly language program */
  63. short calcmand(double dreal,
  64.                double dimag,
  65.                short  maxit)
  66. {
  67.     double x, y, xsq, ysq;
  68.     short k;
  69.  
  70.     k = maxit;
  71.     x = dreal;
  72.     y = dimag;
  73.  
  74.     while (1) {
  75.         xsq = x * x;
  76.         ysq = y * y;
  77.         y = 2.0 * x * y + dimag;
  78.         x = (xsq - ysq) + dreal;
  79.         if (--k == 0)
  80.             return((short) (maxit - k));
  81.         if ((xsq + ysq) > 4.0)
  82.             return((short) (maxit - k));
  83.     }
  84. }
  85.