X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Frasterize;a=blobdiff_plain;f=animate.lua;h=fb4ca825ee0b764fb0c02ef699e7167a8166631c;hp=9917cb148f9f2187a920917b45abc4d321b5e653;hb=143da66e7f625b7f195a115b9740a748ee003534;hpb=e00aec23409a0f95317c110305e6448ec882bd0e diff --git a/animate.lua b/animate.lua index 9917cb1..fb4ca82 100755 --- a/animate.lua +++ b/animate.lua @@ -20,21 +20,18 @@ 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 @@ -77,12 +74,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)