POV-Ray : Newsgroups : povray.newusers : Controlling Speed along a spline : Re: Controlling Speed along a spline Server Time
30 Jul 2024 04:12:39 EDT (-0400)
  Re: Controlling Speed along a spline  
From: Jim Charter
Date: 5 Oct 2004 18:44:50
Message: <416323e2$1@news.povray.org>
Bathurstfreak wrote:

> I'm a first time POVRay user, working on my first animation, but I need to
> control the speed of a vehicle along a spline. What determines how far the
> car travels between each frame? Is it based on the distance between each
> point on the spline? Can I get linear deceleration around a corner for
> example? I realise these are based on chosen framerate and other such
> things.
> 
> 
Well I am not the best one to be answering this since I don't do 
animation but here is what I know:

there is a sample file showing animation along a spline called 
followspline.pov in the src directory

splines are usually accessed My_Spline ( Value )
where Value is 0 < Value < 1
so that 0 represents one end of the spline and 1 the other
you more the camera along from frame to frame by using the clock value
there

When you access the spline in this way you might expect that
My_Spline ( 0/5 )
My_Spline ( 1/5 )
My_Spline ( 2/5 )
...
My_Spline ( 5/5 )

would return points on the spline at equal distances between each other
but it does not necessarily do that

The only way I have found to ensure that it does is by defining the 
spline in a careful way

the syntax for defining the spline is
#local My_Spline =
spline {
Value0, Pt0
Value1, Pt1
Value2, Pt2
...
ValueN, PtN
}
where again Value* is 0 < Value* < 1
the trick is to make Value0 Value1 Value2 ...
reflect the same proportion to the whole that
the length to corresponding points makes to the whole
length of the spline being defined

I do it like this:
Given the points used to define the spline in an array called Points
#declare Points = array [10] {
P0,P1,P2,...P9 };

#macro DefineSpline ()
         #local TLen=0;
         #local i=1;#while(i<dimension_size(Points,1))
                 #local TLen = TLen + vlength ( Points[i] - 
Points[i-1] 					);
         #local i=i+1;#end


         spline { natural_spline
                #local Len=0;
                Len/TLen, Points[0]
                #local i=1;#while(i<dimension_size(Points,1))
                        #local Len = Len + vlength ( 
Points[i] - 								Points[i-1] );
                        Len/TLen, Points[i]
                #local i=i+1;#end
         }

#end


//then
#local CameraSpline = DefineSpline ()

;now if I do
#local i=0;#while(i<10)
	sphere { CameraSpline( i/10 ) ... }
#local i=i+1;#end

should give spheres equally spaced along the spline

(this works at least when the points used to define the spline are 
numerous and reasonably smoothly "connected")

once you have achieved a constant change of distance you should be
able to control your change of speed by controlling the change of i
which would, for the camera, be a factor of clock

I was sure I saw somewhere a macro for producing a spline that parsed 
with equal distances but I cannot find it now

-Jim
(waiting for the cavalry to arrive)


Post a reply to this message

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