#!/usr/bin/env lua
--- Render a scene from different angles.
+--
+-- CS5600 University of Utah
+-- Charles McGarvey
+-- mcgarvey@eng.utah.edu
+--
+
+-- Render a scene multiple times from different angles, like a camera
+-- rotating around the object of a scene.
-local slices = 64
-local distance = 4
-local height = 1
-local look = {x = -2, y = -1, z = -2}
local size = {w = 640, h = 480}
+local slices = 512
+
+local center = {x = 0, y = 1, z = 0}
+local look = {x = -2, y = -1, z = -2}
+local distance = 4
+local start = math.pi
+
local scene = [[
g teapot2.raw
c 1.0 1.0 0.0 1.0 1.0 0.0 1.0 1.0 0.0
s 10.0 10.0 10.0
]]
-local concurrent = 3
+function vec_add(a, b)
+ return {x = a.x + b.x, y = a.y + b.y, z = a.z + b.z}
+end
function vec_scale(v, s)
return {x = v.x * s, y = v.y * s, z = v.z * s}
]], size.w, size.h, v.x, v.y, v.z, look.x, look.y, look.z, size.w/size.h, scene))
local a, b = coroutine.yield()
out:close()
- os.rename("stdin.bmp", string.format("r/out%03d.bmp", i))
+ os.rename("stdin.bmp", string.format("anim%04d.bmp", i))
if a == null then
break
else
end
local threads = {}
-for i = 1,concurrent do
+local jobs = 3
+for i = 1,jobs do
table.insert(threads, coroutine.wrap(render))
end
for i = 0,(slices-1) do
- local t = 2 * i * math.pi / slices
+ local t = start + 2 * i * math.pi / slices
local v = {
x = math.cos(t),
y = 0,
z = math.sin(t),
}
- v = vec_scale(v, distance)
- v.y = v.y + height
- threads[(i % concurrent) + 1](i, v)
+ v = vec_add(vec_scale(v, distance), center)
+ threads[(i % jobs) + 1](i, v)
end
for k,v in ipairs(threads) do