--- This program that draws a scene multiple times from different camera angles
--- and positions. The rasters are saved in the `frames' directory, and if
--- ffmpeg is installed, they will also be combined into a video file. The
--- camera will make a full rotation along the X and Z axes, around a specified
--- point (center), all the while looking at some other point (look).
--- This must be called from the same directory where the rasterize program is.
-
-local size = {w = 640, h = 480} -- width and height of the viewport
-local frames = 512 -- number of animation frames
-
-local look = {x = 2, y = 1, z = 2} -- the point to look at
-local center = {x = 0, y = 1, z = 0} -- center of rotation
-local distance = 4 -- the distance from the center
-local start = math.pi -- where is the first frame
+-- This program automates the process of creating simple fly-by animations.
+-- The rasters are saved in the `frames' directory, and if ffmpeg is
+-- installed, the frames will also be combined into a video file. This script
+-- must be called from the same directory where the rasterize program is.
+
+-- Set the number of frames to be rendered for the animation.
+local frames = 360
+
+-- Define the code to calculate where the camera is, in world coordinates.
+local eye = function(frame)
+ -- just rotate around the center of the scene on the XZ plane
+ local center = vec_new(0, 1, 0)
+ local distance = 4
+ local start = math.pi
+ local t = start + 2 * math.pi * frame / frames
+ local v = vec_new(math.cos(t), 0, math.sin(t))
+ return vec_add(vec_scale(v, distance), center)
+end