POV-Ray supports a simple but powerful animation system based on the
clock variable. clock is automatically incremented by
(1/(num_of_frames-1)) for every frame in an animation.
Because clock is just a number, it can be used to rotate or
translate any object in the POV-Ray scene, including the camera itself. In
fact, it can even be used as a texture modifier for some interesting
effects.
For our first example we'll create a magical sphere that rotates about the
origin. Not terribly original, but we'll be able to use it as the basis for
the next scene.
Click here to download the complete
scene file. The important lines are:
1 #declare ball=
2 sphere {
3 <3, 1, 0>, 1
4 texture {
5 T_Silver_1E
6 pigment {Yellow}
7 }
8 }
9
10 object {ball rotate 360*clock*y}
On line 3, we place the sphere 3 units from the origin along the positive X-axis
and 1 unit above. Normally we would create objects centered on the origin
because rotation and translations are done relative to the axis of
rotation. In this case, however, we want to simulate a revolution about the
origin.
We place the object with:
object {ball rotate 360*clock*y} . What
happens here? Remember that the
clock variable moves from 0 to 1 in
the number of frames in the total animation. For each frame of the
animation you'll then have the following values:
| Frame # | clock | Scene |
| 1 | 0 | object {ball rotate 0*y} |
| 2 | 0.11 | object {ball rotate 39.6*y} |
| 3 | 0.22 | object {ball rotate 79.2*y} |
| 4 | 0.33 | object {ball rotate 118.8*y} |
| 5 | 0.44 | object {ball rotate 158.4*y} |
| 6 | 0.56 | object {ball rotate 201.6*y} |
| 7 | 0.67 | object {ball rotate 241.2*y} |
| 8 | 0.78 | object {ball rotate 280.8*y} |
| 9 | 0.89 | object {ball rotate 320.4*y} |
| 10 | 1 | object {ball rotate 360*y} |
I'm rounding off the clock value in the chart. But, wait, you say.
Why doesn't the value run as 0, 0.1, 0.2, etc.? Wouldn't that make more
sense?
It depends. On a cyclic animation you would want the final frame to be
rendered with a clock value one increment before the last. This would prevent an apparent stutter
since the first frame is identical to the last. We can specify in our
rendering options whether or not the animation is cyclic. If it is, then
the final frame would be rendered a step behind the first, thus ensuring a
smooth animation. Our animation is cyclic, so we make our opts.ini:
Library_Path=/usr/local/lib/povray31/include
Output_File_Type=P
Width=320
Height=240
Initial_Frame=1
Final_Frame=10
Antialias=true
Subset_Start_Frame=1
Subset_End_Frame=10
Cyclic_Animation=on
Next, we kick off the rendering process with:
povray opts.ini -Iclock_example00.pov
You'll note that the name of my scene file is padded with a couple zeroes.
I did this because I use Gimp as a frontend
to an MPEG encoding program. Alas, it does not find all frames unless the
names are in the FILENAME####.ppm format.
You may be wondering why we used the format of (Multiplier x clock) instead
of just setting the initial and final clock as POV-Ray allows. The reason
is to allow more flexibility in the number of final frames. By doing it
this way we only need change the opts.ini if we wanted to increase the
number of total frames.
Click
here for the completed
animation in GIF format (~360k).
| Changing the Vantage Point |
As mentioned previously, any object can be rotated or translated with the
clock variable, including the camera. Moving the camera makes for a
much more dynamic scene for relatively little effort. Click
here for the
scene file to the Stonehenge demo.
As you can see, there are gratuitous clock references sprinkled
throughout. While the camera is moving around the perimeter of the henge,
it is also slowly rising. The focal point of the camera also changes to
better follow the eerie and mysterious glowing bubble objects. Woooo!
There are a few ways to assemble the individual frames into either and mpeg
or a GIF or PNG animation. The easiest method is to use the ImageMagick tools,
convert in particular, to create the video. For example, given a list
of filenames such as:
frame0001.ppm
frame0002.ppm
frame0003.ppm
...
You can create an mpeg using:
[kwan@omega] convert -delay 20 frame*.ppm foot.mpg
Or, to create an animated GIF:
[kwan@omega] convert -delay 20 frame*.ppm foot.gif
Or you can also use
the Gimp as
mentioned above.