POV-Ray : Newsgroups : povray.animations : Math Question : Re: Math Question Server Time
1 Jul 2024 02:22:33 EDT (-0400)
  Re: Math Question  
From: ScubaDude
Date: 20 Nov 2005 18:40:00
Message: <web.438108911fdfabe8739122c80@news.povray.org>
"Josh" <s### [at] acom> wrote:
> I've got a Key Frame animation utility I've written.
>
> Unfortunately it only works in straight lines, that is to say it calculates
> the variables for each frame by dividing the starting and ending values by
> the number of frames.
>
> This is fine but I want to be able to start the movement faster and end it
> slower, and vice versa, possibly even have it faster at the beginning and
> and with it slower in the middle.
>
> Example of what I am doing at the moment.
>
> Start Value for Camera X is -100
> End Value for Camera X is 1095
> There are 150 frames, so I increment the Camera X by +7.96 per frame, a
> straight line.
>
> What formular can I use to have the camera start faster and slow to a halt?

I was in the same situation and came up with this macro for use with my
Myst-ripoff elevator (put on hold, like everything else, because of
hurricane Katrina).
********************************************************

// move macro
//
// returns a real value based on the clock, smoothly transitioning from
StartPt to EndPt,
// from StartTime to EndTime following a sine function. usefull for
accelerating an
// object smoothly from StartPt to the mid-point then decelerating it
smoothly to EndPt.
// If clock <= StartPt, StartPt is returned. If clock >= EndPt, EndPt is
returned.
// requires math.inc
//
// inputs:
//   StartPt = real: the initial value
//     EndPt = real: the final value
// StartTime = real: the initial clock time
//   EndTime = real: the final clock time
//
// output:
// ObjMoverNum = real: the value of the variable at a particular clock time.
//
// example 1:
//-----------
// #include "math.inc"
// ObjMover (0, 10, 0.25, 0.75)
// sphere {
//   <ObjMoverNum, 0, 0>, 1
// }
//-----------
// creates a sphere which sits at the origin until clock>0.25, then moves
along the x-axis,
// arriving at <10,0,0> when clock=0.75, then staying at that point until
clock=1.
//
// example 2:
//-----------
// #include "math.inc"
// ObjMover (-30, 30, 0, 1)
// union {
//   cylinder {
//     <0, 0, 0>,
//     <0, -5, 0>,
//     0.1
//   }
//   sphere {
//     <0, -5, 0>, 0.3
//   }
//   rotate <0, 0, ObjMoverNum>
// }
//-----------
// creates a pendulum which swings smoothly from -30 degrees to 30 degrees
around the z-axis
// as the clock moves from 0 to 1.

#macro ObjMover (StartPt, EndPt, StartTime, EndTime)
  #local      Dist = EndPt - StartPt;
  #local  Duration = EndTime - StartTime;
  #local   ClockSc = 0.5 / Duration;
  #local HalfwayPt = (StartPt + EndPt)/2;
  #local   Clocker = ((clock - StartTime) * ClockSc) - 0.25;
  #if (clock>=StartTime)
    #if (clock<=EndTime)
      #declare ObjMoverNum = HalfwayPt+(sind (Clocker*360) * (Dist/2));
    #else
      #declare ObjMoverNum = EndPt;
    #end
  #else
    #declare ObjMoverNum = StartPt;
  #end
#end

********************************************************

Hope you find it handy,

Eric


Post a reply to this message

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