]> Dogcows Code - chaz/rasterize/commitdiff
rotate script now more intuitive, maybe
authorCharles McGarvey <chazmcgarvey@brokenzipper.com>
Sun, 12 Feb 2012 05:44:22 +0000 (22:44 -0700)
committerCharles McGarvey <chazmcgarvey@brokenzipper.com>
Sun, 12 Feb 2012 05:44:22 +0000 (22:44 -0700)
rotate.lua

index ea383448142beaef8da64bdc8748089229c3c92e..4334dd8f714da36a755502833e74e648d7c51443 100755 (executable)
@@ -1,12 +1,22 @@
 #!/usr/bin/env lua
 
 #!/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 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
 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
 ]]
 
 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}
 
 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()
 ]], 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
         if a == null then
             break
         else
@@ -61,20 +73,20 @@ U3
 end
 
 local threads = {}
 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
     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),
     }
     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
 end
 
 for k,v in ipairs(threads) do
This page took 0.024544 seconds and 4 git commands to generate.