home *** CD-ROM | disk | FTP | other *** search
- /*==============================================================================
- Project: POV
-
- File: Animate.c
-
- Description:
- Routines to handle the clock animation variable prompting for POV-Ray.
- ------------------------------------------------------------------------------
- Author:
- Eduard [esp] Schwan
- ------------------------------------------------------------------------------
- from Persistence of Vision(tm) Ray Tracer
- Copyright 1996 Persistence of Vision Team
- ------------------------------------------------------------------------------
- NOTICE: This source code file is provided so that users may experiment
- with enhancements to POV-Ray and to port the software to platforms other
- than those supported by the POV-Ray Team. There are strict rules under
- which you are permitted to use this file. The rules are in the file
- named POVLEGAL.DOC which should be distributed with this file. If
- POVLEGAL.DOC is not available or for more info please contact the POV-Ray
- Team Coordinator by leaving a message in CompuServe's Graphics Developer's
- Forum. The latest version of POV-Ray may be found there as well.
-
- This program is based on the popular DKB raytracer version 2.12.
- DKBTrace was originally written by David K. Buck.
- DKBTrace Ver 2.0-2.12 were written by David K. Buck & Aaron A. Collins.
- ------------------------------------------------------------------------------
- Change History:
- 930226 [esp] Created
- 930605 [esp] Changed initial frame # from zero to one
- 930707 [esp] Checked for frame 1 to 1, avoid div by zero
- 930708 [esp] Changed clock value display from 3 to 5 digits
- 930728 [esp] Added frameValS/frameValE
- 930816 [esp] Added pAnimPtr to SetCurrFrameVal & made it set curr clock val too
- 931001 [esp] version 2.0 finished (Released on 10/4/93)
- 931119 [djh] 2.0.1 source conditionally compiles for PPC machines, keyword __powerc
- ==============================================================================*/
-
- #define ANIMATE_C
-
-
- /*==== Animate header ====*/
- #include "Animate.h"
-
- /*==== Standard C headers ====*/
- #include <stdlib.h> // malloc
-
- /*==== Macintosh-specific headers ====*/
- #include <types.h>
- #include <memory.h> // NewPtr
-
-
-
-
- /*==== defs ====*/
-
-
- /*==== vars ====*/
-
- static short gCurrFrameVal;
- static float gCurrentClockVal;
-
-
- //-----------------------------------------------------------
- // Calculate a clock value based on currFrameVal, etc.
- float CalcClockVal(AnimPtr_t pAnimPtr, short currFrameVal)
- {
- double tCurrClockVal;
-
- // if frames are related to clocks, and frame is this, what's clock?
- if (currFrameVal == 1)
- {
- // If Frame(1), just return clock(0), so we don't divide by zero!
- tCurrClockVal = pAnimPtr->clockVal0;
- }
- else
- {
- // THE MOST USEFUL CALCULATION IN THE WORLD! :-)
- tCurrClockVal = pAnimPtr->clockVal0
- + ( (double)currFrameVal - (double)pAnimPtr->frameVal0)
- * ( (double)pAnimPtr->clockValN - pAnimPtr->clockVal0 )
- / ( (double)pAnimPtr->frameValN - (double)pAnimPtr->frameVal0);
- }
-
- return tCurrClockVal;
-
- } // CalcClockVal
-
-
- //-----------------------------------------------------------
- // Set local current frame value (and calculate current clock value too)
- void SetCurrFrameVal(AnimPtr_t pAnimPtr, short newFrameVal)
- {
- gCurrFrameVal = newFrameVal;
- gCurrentClockVal = CalcClockVal(pAnimPtr, newFrameVal); // calc. curr clock
- } // SetCurrFrameVal
-
-
- //-----------------------------------------------------------
- // Return local current frame value
- short GetCurrFrameVal(void)
- {
- return gCurrFrameVal;
- } // GetCurrFrameVal
-
-
- //-----------------------------------------------------------
- // Return local current clock value
- float GetCurrClockVal(void)
- {
- return gCurrentClockVal;
- } // GetCurrClockVal
-
-
- //-----------------------------------------------------------
- // Increment Frame counter if not already finished, and recalculate
- // new clock value. Return true if already at last frame
- Boolean IncToNextFrame(AnimPtr_t pAnimPtr)
- {
- Boolean nextFrameOK = false;
- short frameVal;
-
- frameVal = GetCurrFrameVal();
-
- // before last frame?
- if (frameVal < pAnimPtr->frameValE)
- { // go to next frame
- frameVal++; // go to next
- SetCurrFrameVal(pAnimPtr, frameVal); // save it & calc curr clock val
- nextFrameOK = true;
- }
-
- return nextFrameOK;
- } // IncToNextFrame
-
-