From: Charles McGarvey Date: Sun, 12 Feb 2012 05:44:22 +0000 (-0700) Subject: rotate script now more intuitive, maybe X-Git-Tag: project3~11 X-Git-Url: https://git.dogcows.com/gitweb?a=commitdiff_plain;h=db44364a1fabda81d3f6c842c4e4778eac6495a5;p=chaz%2Frasterize rotate script now more intuitive, maybe --- diff --git a/rotate.lua b/rotate.lua index ea38344..4334dd8 100755 --- a/rotate.lua +++ b/rotate.lua @@ -1,12 +1,22 @@ #!/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 @@ -30,7 +40,9 @@ t -2.0 -1.0 2.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} @@ -50,7 +62,7 @@ U3 ]], 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 @@ -61,20 +73,20 @@ U3 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