]> Dogcows Code - chaz/rasterize/blobdiff - animate.lua
preliminary support for obj files
[chaz/rasterize] / animate.lua
index 476051ff8fb08accdd01018703df710b99e010f2..a1c7389f8af95fe33b24e95999812140de178078 100755 (executable)
 local size = {w = 640, h = 480}
 
 -- Set the number of frames to be rendered for the animation.
-local frames = 512
+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    = {x = 0, y = 1, z = 0}
+    local center    = vec_new(0, 1, 0)
     local distance  = 4
     local start     = math.pi
     local t = start + 2 * math.pi * frame / frames
-    local v = {
-        x = math.cos(t),
-        y = 0,
-        z = math.sin(t),
-    }
+    local v = vec_new(math.cos(t), 0, math.sin(t))
     return vec_add(vec_scale(v, distance), center)
 end
 
 -- Define the code to calculate where the focal point of the scene is.
 local look = function(frame)
-    return {x = 2, y = 1, z = 2}    -- keep focused on the buddha
+    -- keep the camera focused on the buddha
+    return vec_new(2, 1, 2)
 end
 
 -- Define the actual objects of the scene that will be rendered, in the
@@ -42,11 +39,11 @@ end
 local scene = [[
 L 0 1000000 0 1 1 1 1 1 1
 L 0 0 1000000 1 1 1 1 1 1
-g triangle.raw
-c 0.9 0.8 0.7 0.6 0.5 0.4 0.3 0.2 0.1
-t 2 0 -2
-s 1 1 1
+g ak47.obj
+c 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1
+M 0.9 0.9 0.9 128
 g dragon.raw
+M 0.3 0.3 0.3 5
 c 0.7 0.3 0.2 0.8 0.2 0.1 0.9 0.2 0.2
 t -2 -1 -2
 s 2 2 2
@@ -55,13 +52,10 @@ c 0.1 0.2 0.7 0.1 0.3 0.9 0.2 0.1 0.8
 t 2 -1.5 2
 s 10 10 10
 g bunny.raw
+M 0.2 0.2 0.2 1
 c 0.9 0.8 0.9 0.8 0.7 0.9 0.9 0.8 0.7
 t -2 -1 2
 s 10 10 10
-g teapot2.raw
-c 0 1 0 0 1 0 0 1 0
-t 0 -1 0
-s 0.6 0.6 0.6
 ]]
 
 -- Set the number of concurrent renderings (for multi-core machines).
@@ -74,12 +68,16 @@ local jobs = 6
 local fmt   = string.format
 local write = function(...) io.write(fmt(...)) end
 
+function vec_new(x, y, z)
+    return {x = x, y = y, z = z}
+end
+
 function vec_add(a, b)
-    return {x = a.x + b.x, y = a.y + b.y, z = a.z + b.z}
+    return vec_new(a.x + b.x, a.y + b.y, a.z + b.z)
 end
 
 function vec_scale(v, s)
-    return {x = v.x * s, y = v.y * s, z = v.z * s}
+    return vec_new(v.x * s, v.y * s, v.z * s)
 end
 
 function render(i)
This page took 0.022721 seconds and 4 git commands to generate.