home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Applications / POV-Ray 3.0.2 / src / MacSource / Animate.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-07-14  |  4.2 KB  |  136 lines  |  [TEXT/CWIE]

  1. /*==============================================================================
  2. Project:    POV
  3.  
  4. File:    Animate.c
  5.  
  6. Description:
  7. Routines to handle the clock animation variable prompting for POV-Ray.
  8. ------------------------------------------------------------------------------
  9. Author:
  10.     Eduard [esp] Schwan
  11. ------------------------------------------------------------------------------
  12.     from Persistence of Vision(tm) Ray Tracer
  13.     Copyright 1996 Persistence of Vision Team
  14. ------------------------------------------------------------------------------
  15.     NOTICE: This source code file is provided so that users may experiment
  16.     with enhancements to POV-Ray and to port the software to platforms other 
  17.     than those supported by the POV-Ray Team.  There are strict rules under
  18.     which you are permitted to use this file.  The rules are in the file
  19.     named POVLEGAL.DOC which should be distributed with this file. If 
  20.     POVLEGAL.DOC is not available or for more info please contact the POV-Ray
  21.     Team Coordinator by leaving a message in CompuServe's Graphics Developer's
  22.     Forum.  The latest version of POV-Ray may be found there as well.
  23.  
  24.     This program is based on the popular DKB raytracer version 2.12.
  25.     DKBTrace was originally written by David K. Buck.
  26.     DKBTrace Ver 2.0-2.12 were written by David K. Buck & Aaron A. Collins.
  27. ------------------------------------------------------------------------------
  28. Change History:
  29.     930226    [esp]    Created
  30.     930605    [esp]    Changed initial frame # from zero to one
  31.     930707    [esp]    Checked for frame 1 to 1, avoid div by zero
  32.     930708    [esp]    Changed clock value display from 3 to 5 digits
  33.     930728    [esp]    Added frameValS/frameValE
  34.     930816    [esp]    Added pAnimPtr to SetCurrFrameVal & made it set curr clock val too
  35.     931001    [esp]    version 2.0 finished (Released on 10/4/93)
  36.     931119    [djh]    2.0.1 source conditionally compiles for PPC machines, keyword __powerc
  37. ==============================================================================*/
  38.  
  39. #define ANIMATE_C
  40.  
  41.  
  42. /*==== Animate header ====*/
  43. #include "Animate.h"
  44.  
  45. /*==== Standard C headers ====*/
  46. #include <stdlib.h>        // malloc
  47.  
  48. /*==== Macintosh-specific headers ====*/
  49. #include <types.h>
  50. #include <memory.h>        // NewPtr
  51.  
  52.  
  53.  
  54.  
  55. /*==== defs ====*/
  56.  
  57.  
  58. /*==== vars ====*/
  59.  
  60. static short    gCurrFrameVal;
  61. static float    gCurrentClockVal;
  62.  
  63.  
  64. //-----------------------------------------------------------
  65. // Calculate a clock value based on currFrameVal, etc.
  66. float CalcClockVal(AnimPtr_t pAnimPtr, short currFrameVal)
  67. {
  68.     double        tCurrClockVal;
  69.  
  70.     // if frames are related to clocks, and frame is this, what's clock?
  71.     if (currFrameVal == 1)
  72.     {
  73.         // If Frame(1), just return clock(0), so we don't divide by zero!
  74.         tCurrClockVal = pAnimPtr->clockVal0;
  75.     }
  76.     else
  77.     {
  78.         // THE MOST USEFUL CALCULATION IN THE WORLD! :-)
  79.         tCurrClockVal = pAnimPtr->clockVal0
  80.             + (    (double)currFrameVal        - (double)pAnimPtr->frameVal0)
  81.             * (    (double)pAnimPtr->clockValN - pAnimPtr->clockVal0        )
  82.             / (    (double)pAnimPtr->frameValN - (double)pAnimPtr->frameVal0);
  83.     }
  84.  
  85.     return tCurrClockVal;
  86.  
  87. } // CalcClockVal
  88.  
  89.  
  90. //-----------------------------------------------------------
  91. // Set local current frame value (and calculate current clock value too)
  92. void SetCurrFrameVal(AnimPtr_t pAnimPtr, short newFrameVal)
  93. {
  94.     gCurrFrameVal        = newFrameVal;
  95.     gCurrentClockVal    = CalcClockVal(pAnimPtr, newFrameVal); // calc. curr clock
  96. } // SetCurrFrameVal
  97.  
  98.  
  99. //-----------------------------------------------------------
  100. // Return local current frame value
  101. short GetCurrFrameVal(void)
  102. {
  103.     return gCurrFrameVal;
  104. } // GetCurrFrameVal
  105.  
  106.  
  107. //-----------------------------------------------------------
  108. // Return local current clock value
  109. float GetCurrClockVal(void)
  110. {
  111.     return gCurrentClockVal;
  112. } // GetCurrClockVal
  113.  
  114.  
  115. //-----------------------------------------------------------
  116. // Increment Frame counter if not already finished, and recalculate
  117. // new clock value.  Return true if already at last frame
  118. Boolean IncToNextFrame(AnimPtr_t pAnimPtr)
  119. {
  120.     Boolean    nextFrameOK = false;
  121.     short    frameVal;
  122.  
  123.     frameVal = GetCurrFrameVal();
  124.  
  125.     // before last frame?
  126.     if (frameVal < pAnimPtr->frameValE)
  127.     {    // go to next frame
  128.         frameVal++; // go to next
  129.         SetCurrFrameVal(pAnimPtr, frameVal); // save it & calc curr clock val
  130.         nextFrameOK = true;
  131.     }
  132.  
  133.     return nextFrameOK;
  134. } // IncToNextFrame
  135.  
  136.