POV-Ray : Newsgroups : povray.general : just thought I'd share Server Time
31 May 2024 19:19:10 EDT (-0400)
  just thought I'd share (Message 1 to 1 of 1)  
From: Anthony D  Baye
Subject: just thought I'd share
Date: 19 Jan 2015 02:35:01
Message: <web.54bcb2b9dd918d75bd92286f0@news.povray.org>
I've been fiddling around with my animation macros the past couple days,
cleaning and commenting, among other things, and I thought I'd put them up for
anybody that wants to play with them.

The only ones you will probably use are the first and the last; the others are
background stuff.

to start, you use initAnimation:

initAnimation(<H,M,S>)

this sets up some environment stuff. Then use Timer wherever you want an effect.

Timer(Type, Start, Finish, Q)

Type is an integer 1 <= Type <= 5
1) Accelerating motion based on Delta-V
2) Accelerating motion based on a constant of Acceleration
3) Constant speed over time
4) Constant speed given distance
5) gives a scaled time-slice, Q is ignored.

Q is the constant associated with the Type

the way the macro is set up you can add calls together to form timelines, either
inline or as declared variables:

#declare timeline_1 = Timer(1, <0,0,1>, <0,0,5>, 50) +
Timer(3,<0,0,5>,<0,0,20>,50)...

will give you motion starting at 1 second, accelerating to 50 units per second
over 4 seconds, and continuing at 50 units per second for the next 15 seconds.
Add as many Timer calls as you like.

let me know what you think.

Regards,
A.D.B

--- Begin anim.inc ---
#version 3.7;
#ifndef(_ANIM_INC_)
    #declare _ANIM_INC_ = version;
#end

#ifdef(View_POV_Include_Stack)
   #debug "including anim.inc\n"
#end

/*****************************************************************************
* Name: initAnimation                                       Date: 9/14/2010  *
*                                                                            *
* Auth: Anthony D. Baye                                                      *
* Args: Time                                                                 *
* Desc: Takes the animation length as a ordered- triple in the form <h, m, s>*
*    Re-computes duration in seconds and defines a global constant "_TICK_". *
*    Also defines a flag for error-checking purposes.                        *
*       Ensures that the clock is running, before initializing animation     *
*    environment.                                                            *
 ****************************************************************************/
#macro initAnimation(Time)
    #if(clock_on)
        #local Seconds = Time.x*3600 + Time.y*60 + Time.z;
        #declare _TICK_ = (final_clock - initial_clock) / Seconds;

        #declare _ANIMATION_TIMER_ = version;
    #else
        #declare _TICK_ = 1;
        #warning "clock not running.\n"
    #end
#end

/****************************************************************************
* Name: eTime                                               Date: 9/14/2010 *
*                                                                           *
* Auth: Anthony D. Baye                                                     *
* Args: Time                                                                *
* Desc: Receives a time index as an ordered-triple, recomputes the time in  *
*       seconds and returns the corresponding number of ticks.              *
 ***************************************************************************/
#macro eTime(Time)
    #local Seconds = (Time.x*3600 + Time.y*60 + Time.z);
    (_TICK_*Seconds)
#end

/****************************************************************************
* Name: eClock                                              Date: 1/17/2015 *
*                                                                           *
* Auth: Anthony D. Baye                                                     *
* Args: Start, Finish                                                       *
* Desc: Recieves a pair of time indices as ordered triples, and performs    *
*       time-shifting and scaling computations.                             *
 ***************************************************************************/
#macro eClock(Start, Finish)
    #local D = (Finish - Start);
    ((clock - eTime(Start)) / eTime(D))
#end


/****************************************************************************
* Name: Timer                                               Date: 9/14/2010 *
*                                                                           *
* Auth: Anthony D. Baye                                                     *
* Args: Type, Start, Finish, speed                                          *
* Desc: Computes an event timer for an effect. Can be multiplied by a       *
*     direction-vector.                                                     *
*                                                                           *
*     Type: type of motion; accelerating/steady                             *
*     Start: Starting time index for event.                                 *
*     Finish: Ending time index for event.                                  *
*     speed: event speed in units per second.                               *
*           If type=1 this is Delta-V                                       *
*           If type=2 this is the acceleration                              *
*           If type=3 this is the speed                                     *
*           If type=5|6 Q is ignored.                                       *
 ***************************************************************************/
#macro Timer(Type, Start, Finish, Q)
    #ifdef(_ANIMATION_TIMER_)
        #local D = (Finish - Start);
        #local T = (D.x*3600 + D.y*60 + D.z);
        #local _RESULT = 0;
        #if((clock > eTime(Start)) & (clock <= eTime(Finish)))
            // While the clock is within proper range, return required value.
            #switch(Type)
            #case(1)
                // Given Delta-V.
                #local _RESULT = ((T*Q/2)*pow(eClock(Start, Finish),2));
                #break
            #case(2)
                // Given Acceleration.
                #local _RESULT = (((Q*T*T)/2)*pow(eClock(Start, Finish),2));
                #break
            #case(3)
                // Constant velocity over time.
                #local _RESULT = (T*Q*( eClock(Start, Finish) ) );
                #break
            #case(4)
                // Constant Distance over time.
                #local _RESULT = ( Q*( eClock(Start, Finish) ) );
                #break
            #case(5)
                // Normalized Time Scaling, 0 <= T <= final_clock
                #local _RESULT = eClock(Start, Finish);
                #break
            #end
        #else
        // Once the event is ended, return a value for the LAST frame.
        // this will prevent the object from snapping back to the origin.
        #if(clock > eTime(Finish))
            #switch(Type)
            #case(1)
                // distance travelled while changing velocities
                #local _RESULT = (T*Q/2);
                #break
            #case(2)
                // This is the distance travelled while accelerating
                #local _RESULT = ((Q*T*T)/2);
                #break
            #case(3)
                // This is the distance travelled at Speed (Q)
                #local _RESULT = (Q*T);
                #break
            #case(4)
                // Distance travelled over period (D)
                #local _RESULT = Q;
                #break
            #case(5)
                // max value of eClock(Start, Finish) is 1.
                #local _RESULT = 1;
                #break
            #end
        #else
            #local _RESULT = 0;
        #end
    #end

    #if(Type < 1 | Type > 5 | (Type - floor(Type)) != 0)
        #error "first parameter must be an integer: 1 <= Type <= 5\n"
    #end
    #else
        #warning concat ("Animation Timer not initialized.\n"
            "\tcall initAnimation(<H,M,S>) to initialize.\n")
        #local _RESULT = 0;
    #end
    _RESULT
#end


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.