POV-Ray : Newsgroups : povray.animations : Spline-based animation : Re: Spline-based animation Server Time
3 May 2024 08:57:32 EDT (-0400)
  Re: Spline-based animation  
From: Chris B
Date: 7 Oct 2008 07:52:29
Message: <48eb4d7d$1@news.povray.org>
> HelveticaFanatic wrote:
>
>> How can I ensure that a camera moving along a spline for an animation 
>> will
>> go at the correct speed? I'm using natural splines and can't seem to get
>> spacing right. I wrote a script to check the spline between different
>> clock points and divide the difference, but then then I wanted it to
>> return the midpoints which are really off from the actual midpoints. What
>> can I do? Thanks.

I'd suggest taking small bites along the spline, use vlength() on the 
difference between two successing points and keep a cumulative total of the 
distance travelled from the start of the spline. Use that distance in your 
camera speed calculations.

For example, to get a constant speed

// +kfi0 +kff10
camera {location <0,0,-10> look_at 0 }
light_source {<-10,20,50>, rgb 4}

#declare MySpline = spline {
    cubic_spline
    -.25, <-1, 0, 0>
    0.00, < 3, 0, 0>
    0.10, < 3, 3, 0>
    0.50, <-3, 3, 0>
    0.75, <-2,-1,-3>
    1.00, < 2,-1,-3>
    1.25, < 0, 0, 1>
}

#declare FinalFrameDistance = 25;
#declare ThisFrameDistance = clock * FinalFrameDistance;
// Initialise some working variables
#declare CumulativeDistance = 0;
#declare SplineIndex = 0;
#declare ThisPoint = MySpline(0);
#declare LastPoint = MySpline(0);
// Loop round till we're the right distance through the spline
#while (CumulativeDistance<ThisFrameDistance & SplineIndex<=1)
   #declare ThisPoint = MySpline(SplineIndex);
  // Add the length of this little bite of the spline
   #declare CumulativeDistance = CumulativeDistance + 
vlength(ThisPoint-LastPoint);
   #declare LastPoint = ThisPoint;
   #declare SplineIndex = SplineIndex + 0.001;
#end

sphere {ThisPoint,0.2 pigment {rgb <1,0,0>}}

or, for a constant acceleration:

#declare Acceleration = 40;
#declare AverageSpeed = Acceleration*clock/2;
#declare ThisFrameDistance = AverageSpeed*clock;

Regards,
Chris B.


Post a reply to this message

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