9551

3D testing V10

Oct 29th, 2021 (edited)
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 18.61 KB | None | 0 0
  1. local toBlit = {}
  2. local chars = "0123456789abcdef"
  3. for i = 0, 15 do
  4.     toBlit[2^i] = chars:sub(i + 1, i + 1)
  5. end
  6. local function makeProjection(w,h,n,f)
  7.     --w = width
  8.     --h = height
  9.     --n = near plane
  10.     --f = far plane
  11.     return {
  12.         {2*n/w,0,0,0},
  13.         {0,2*n/h, 0,0},
  14.         {0,0,f/(f-n),-n*f/(f-n)},
  15.         {0,0,-1,0}
  16.     }
  17. end
  18. local makeIdentity = function()
  19.     return {
  20.         {1,0,0,0},
  21.         {0,1,0,0},
  22.         {0,0,1,0},
  23.         {0,0,0,1}
  24.     }
  25. end
  26. local makeTranslation = function(cords)
  27.     return {
  28.         {1,0,0,cords.x},
  29.         {0,1,0,cords.y},
  30.         {0,0,1,cords.z},
  31.         {0,0,0,1}
  32.     }
  33. end
  34. local function makeScale(scale)
  35.     return
  36.     {
  37.         {scale.x, 0, 0, 0},
  38.         {0, scale.y, 0, 0},
  39.         {0, 0, scale.z, 0},
  40.         {0, 0, 0, 1}
  41.     }        
  42. end
  43. local function makeRotation(eulers)
  44.     local x = math.rad(eulers.x)
  45.     local y = math.rad(eulers.y)
  46.     local z = math.rad(eulers.z)
  47.     local sx = math.sin(x)
  48.     local sy = math.sin(y)
  49.     local sz = math.sin(z)
  50.    
  51.     local cx = math.cos(x)
  52.     local cy = math.cos(y)
  53.     local cz = math.cos(z)
  54.     return
  55.     {
  56.         {cy * cz, -cy * sz, sy, 0},
  57.         {(sx * sy * cz) + (cx * sz), (-sx * sy * sz) + (cx * cz), -sx * cy, 0},
  58.         {(-cx * sy * cz) + (sx * sz), (cx * sy * sz) + (sx * cz), cx * cy, 0},
  59.         {0, 0, 0, 1,}
  60.     }
  61. end
  62. local function makePerspective(width, height, n, f, fov)
  63.     local aspectRatio = 3/2*height / width  
  64.     --local aspectRatio = height / width  
  65.     fov = math.rad(fov)
  66.     return
  67.     {
  68.         {aspectRatio/math.tan(fov*0.5),0,0,0},
  69.         {0,1/(math.tan(fov*0.5)),0,0},
  70.         {0,0,-f/(f-n),-f*n/(f-n)},
  71.         {0,0,-1,0}
  72.     },width,height
  73. end
  74. local function matmul(m1, m2)
  75.     if #m1[1] ~= #m2 then
  76.         error("Columns m1 must match rows m2",2)
  77.     end
  78.     local result = {}
  79.     for i = 1, #m1 do
  80.         result[i] = {}
  81.         for j = 1, #m2[1] do
  82.             local sum = 0
  83.             for k = 1, #m2 do sum = sum + (m1[i][k] * m2[k][j]) end
  84.             result[i][j] = sum
  85.         end
  86.     end
  87.     return result
  88. end
  89. local createSelfIndexArray = function()
  90.     return setmetatable({},
  91.         {
  92.             __index=function(t,k)
  93.                 local new = {}
  94.                 t[k]=new
  95.                 return new
  96.             end
  97.         }
  98.     )
  99. end
  100. local function interpolate(p1,p2,y)
  101.     return (((y-p1.y)*(p2.x-p1.x)) / (p2.y-p1.y) + p1.x)
  102. end
  103. local function interpolateY(a,b,y)
  104.     local ya = y - a.y
  105.     local ba = b.y - a.y
  106.     local x = a.x + (ya * (b.x - a.x)) / ba
  107.     local z = a.z + (ya * (b.z - a.z)) / ba
  108.     return x,z
  109. end
  110. local function interpolateZ(a,b,x)
  111.     local z = a.z + (x-a.x) * (((b.z-a.z)/(b.x-a.x)))
  112.     return z
  113. end
  114. local function switchXYArray(array)
  115.     local output = createSelfIndexArray()
  116.     for x,yout in pairs(array) do
  117.         if type(yout) == "table" then
  118.             for y,val in pairs(yout) do
  119.                 output[y][x] = val
  120.             end
  121.         end
  122.     end
  123.     return output
  124. end
  125. local function strInsert(string,add)
  126.     return string..add
  127. end
  128. local function drawLine(startX, startY, endX, endY, wdata, ZBUFFER, color)
  129.     local drawPixelInternal = function(x,y)
  130.         local interpolated = interpolate(wdata[1],wdata[2],y)
  131.         if not ZBUFFER[x][y] then ZBUFFER[x][y] = {w=math.huge} end
  132.         if interpolated < ZBUFFER[x][y].w or ZBUFFER[x][y].w == math.huge then
  133.             ZBUFFER[x][y] = {
  134.                 w=interpolated,
  135.                 color=color
  136.             }
  137.         end
  138.     end
  139.     local startX,startY,endX,endY = math.floor(startX),math.floor(startY),math.floor(endX),math.floor(endY)
  140.     if startX == endX and startY == endY then drawPixelInternal(startX, startY) return end
  141.     local minX = math.min(startX, endX)
  142.     local maxX, minY, maxY
  143.     if minX == startX then minY = startY maxX = endX maxY = endY
  144.     else minY = endY maxX = startX maxY = startY end
  145.     local xDiff,yDiff = maxX - minX,maxY - minY
  146.     if xDiff > math.abs(yDiff) then
  147.         local y,dy = minY,yDiff / xDiff
  148.         for x = minX, maxX do drawPixelInternal(x, math.floor(y+0.5)) y = y + dy end
  149.     else
  150.         local x,dx = minX,xDiff / yDiff
  151.         if maxY >= minY then for y = minY, maxY do drawPixelInternal(math.floor(x ), y) x = x + dx end
  152.         else for y = minY, maxY, -1 do drawPixelInternal(math.floor(x+0.5), y) x = x - dx end end
  153.     end
  154. end
  155. local function drawFlatTriangle(ZBUFFER,px1,px2,y,color,v1,v2,v3)
  156.     local xStart = math.ceil(px1 - 0.5)
  157.     local xEnd =   math.ceil(px2 - 0.5)
  158.     for x = xStart, xEnd do
  159.         if y > 0 and x > 0 then
  160.             local IX,IY = interpolateY(wdata[1],wdata[2],y)
  161.             local IZ = interpolateZ(IX,IY)
  162.             --[[peripheralWrapper.setCursorPos(x,y)
  163.             peripheralWrapper.setBackgroundColor(color)
  164.             peripheralWrapper.write(" ")]]
  165.         end
  166.     end
  167. end
  168. local function drawFlatTopTriangle(ZBUFFER,vec1,vec2,vec3,color)
  169.     local m1 = (vec3.x - vec1.x) / (vec3.y - vec1.y)
  170.     local m2 = (vec3.x - vec2.x) / (vec3.y - vec2.y)
  171.     local yStart = math.ceil(vec1.y - 0.5)
  172.     local yEnd =   math.ceil(vec3.y - 0.5)-1
  173.     for y = yStart, yEnd do
  174.         local px1 = m1 * (y + 0.5 - vec1.y) + vec1.x
  175.         local px2 = m2 * (y + 0.5 - vec2.y) + vec2.x
  176.         drawFlatTriangle( ZBUFFER,px1,px2,y,color)
  177.     end
  178. end
  179. local function drawFlatBottomTriangle( ZBUFFER,vec1,vec2,vec3,color)
  180.     local m1 = (vec2.x - vec1.x) / (vec2.y - vec1.y)
  181.     local m2 = (vec3.x - vec1.x) / (vec3.y - vec1.y)
  182.     local yStart = math.ceil(vec1.y-0.5)
  183.     local yEnd =   math.ceil(vec3.y-0.5)-1
  184.     for y = yStart, yEnd do
  185.         local px1 = m1 * (y + 0.5 - vec1.y) + vec1.x
  186.         local px2 = m2 * (y + 0.5 - vec1.y) + vec1.x
  187.         drawFlatTriangle( ZBUFFER,px1,px2,y,color)
  188.     end
  189. end
  190. local function proccesSolidTriangle(ZBUFFER,vec1,vec2,vec3,color)
  191.     local pv1 = vec1
  192.     local pv2 = vec2
  193.     local pv3 = vec3
  194.     if pv2.y < pv1.y then pv1,pv2 = pv2,pv1 end
  195.     if pv3.y < pv2.y then pv2,pv3 = pv3,pv2 end
  196.     if pv2.y < pv1.y then pv1,pv2 = pv2,pv1 end
  197.     if pv1.y == pv2.y then
  198.         if pv2.x < pv1.x then pv1,pv2 = pv2,pv1 end
  199.         drawFlatTopTriangle(ZBUFFER,pv1,pv2,pv3,color)
  200.     elseif pv2.y == pv3.y then
  201.         if pv3.x < pv2.x then pv3,pv2 = pv2,pv3 end
  202.         drawFlatBottomTriangle(ZBUFFER,pv1,pv2,pv3,color)
  203.     else
  204.         local alphaSplit = (pv2.y-pv1.y)/(pv3.y-pv1.y)
  205.         local vi ={
  206.             x = pv1.x + ((pv3.x - pv1.x) * alphaSplit),      
  207.             y = pv1.y + ((pv3.y - pv1.y) * alphaSplit), }
  208.         if pv2.x < vi.x then
  209.             drawFlatBottomTriangle(ZBUFFER,pv1,pv2,vi,color)
  210.             drawFlatTopTriangle(ZBUFFER,pv2,vi,pv3,color)
  211.         else
  212.             drawFlatBottomTriangle(ZBUFFER,pv1,vi,pv2,color)
  213.             drawFlatTopTriangle(ZBUFFER,vi,pv2,pv3,color)
  214.         end
  215.     end
  216. end
  217. local function createColor(whitelist,blacklist)
  218.     local cols,clist,cCount = {},{},0
  219.     local acls = whitelist or {}
  220.     local useall = not whitelist
  221.     local bcls = blacklist or {}
  222.     local clist = {}
  223.     for k,v in pairs(colors) do
  224.         if type(v) == "number" and useall or acls[v] and not bcls[v] then
  225.             table.insert(clist,v)
  226.         end
  227.     end
  228.     return setmetatable({},{
  229.         __index=function(t,k)
  230.             cCount = cCount + 1
  231.             local col = clist[cCount]
  232.             if cCount >= #clist then cCount = 0 end
  233.             t[k]=col
  234.             return col
  235.         end
  236.     })
  237. end
  238. local function createZBuffer()
  239.     local buffer = createSelfIndexArray()
  240.     buffer.stamp = "zbuffer"
  241.     return buffer
  242. end
  243. --[[local function createColor(clist)
  244.     local clist = clist or {}
  245.     local cCount = 0
  246.     return setmetatable({},{
  247.         __index=function(t,k)
  248.             cCount = cCount + 1
  249.             local col = clist[cCount]
  250.             if cCount >= #clist then cCount = 0 end
  251.             t[k]=col
  252.             return col
  253.         end
  254.     })
  255. end]]
  256. local function createPerspective(width,height,FOV)
  257.     return {makePerspective(width,height,100,10,FOV)}
  258. end
  259. local function createCamera(locVector,rotVector)
  260.     return {
  261.         loc=makeTranslation(-locVector),
  262.         rot=makeRotation(-rotVector)
  263.     }
  264. end
  265. local function getProcessingArgs()
  266.     return {
  267.         doCulling = true,
  268.         drawWireFrame = false,
  269.         drawTriangles = true
  270.     }
  271. end
  272. local function clip1(v1,v2,v3)
  273.     local alphaA = (-v1.z)/(v2.z-v1.pos.z)
  274.     local alphaB = (-v1.z)/(v2.z-v1.pos.z)
  275.     local v1a = interpolate(v1,v2,alphaA)
  276.     local v1b = interpolate(v1,v3,alphaB)
  277.     return {{v1a,v1,v2},{v1b,v1a,v2}}
  278. end
  279. local function clip2(v1,v2,v3)
  280.     local alpha1 = (-v1.z)/(v3.z-v1.z)
  281.     local alpha2 = (-v2.z)/(v3.z-v2.z)
  282.     local v1 = interpolate(v1,v3,alpha1)
  283.     local v2 = interpolate(v2,v3,alpha2)
  284.     return {{v1,v2,v3}}
  285. end
  286. local function clipCullTriangle(v1,v2,v3)
  287.     if v1.x > v1.w and v2.x > v2.w and v3.x > v3.w then return false
  288.     elseif v1.x > -v1.w and v2.x > -v2.w and v3.x > -v3.w then return false
  289.     elseif v1.y > v1.w and v2.y > v2.w and v3.y > v3.w then return false
  290.     elseif v1.y > -v1.w and v2.y > -v2.w and v3.y > -v3.w then return false
  291.     elseif v1.z > v1.w and v2.z > v2.w and v3.z > v3.w then return false
  292.     elseif v1.z > -v1.w and v2.z > -v2.w and v3.z > -v3.w then return false end
  293.     return v1,v2,v3
  294. end
  295. local function transform(objList,persperctive,camera)
  296.     local objectsInt = createSelfIndexArray()
  297.     for k,v in pairs(objList) do
  298.         objectsInt[k] = {main=v,vectors={},origins={},connections=v.connections}
  299.         local scale = makeScale(v.scale/(v.divider or 1))
  300.         local rot = makeRotation(v.rot)
  301.         local loc = makeTranslation(v.loc)
  302.         local tempObj = {}
  303.         for k1,v1 in ipairs(v.vertices) do
  304.             local model = matmul(loc, matmul(rot, matmul(scale, v1)))
  305.             local cam = matmul(camera.rot, matmul(camera.loc, model))
  306.             local projected = matmul(persperctive[1],cam)
  307.             table.insert(tempObj,projected)
  308.         end
  309.         for kc,vc in ipairs(v.connections) do
  310.             local v1 = vector.new(tempObj[vc[1]][1][1],tempObj[vc[1]][2][1],tempObj[vc[1]][3][1])
  311.             local v2 = vector.new(tempObj[vc[2]][1][1],tempObj[vc[2]][2][1],tempObj[vc[2]][3][1])
  312.             local v3 = vector.new(tempObj[vc[3]][1][1],tempObj[vc[3]][2][1],tempObj[vc[3]][3][1])
  313.             v1.w,v2.w,v3.w = tempObj[vc[1]][4][1],tempObj[vc[2]][4][1],tempObj[vc[3]][4][1]
  314.             --[[if clipCullTriangle(v1,v2,v3) then
  315.                 if v1.z < 0 then
  316.                     if v2.z < 0 then something[something] = clip2(v1,v2,v3)
  317.                     elseif v3.z < 0 then something[something] = clip2(v1,v3,v2)
  318.                     else something[something] = clip1(v1,v2,v3) end
  319.                 elseif v2.z < 0 then
  320.                     if v3.z < 0 then something[something] = clip2(v2,v3,v1)
  321.                     else something[something] = clip1(v2,v1,v3) end
  322.                 elseif v3.z < 0 then
  323.                     something[something] = clip2(v3,v1,v2)
  324.                 end
  325.             end]]
  326.         end
  327.         for k2,v2 in ipairs(tempObj) do
  328.             local projected = v2
  329.             local w = 1/projected[4][1]
  330.             projected[1][1] = (projected[1][1] * w  +1) * (persperctive[2] / 2)
  331.             projected[2][1] = (-projected[2][1] * w +1) * (persperctive[3] / 2)
  332.             table.insert(objectsInt[k].vectors,projected)
  333.             table.insert(objectsInt[k].origins,v2)
  334.         end
  335.     end
  336.     return objectsInt
  337. end
  338. local function drawTransformed(ZBUFFER,objects,arguments)
  339.     local term = termObj or term
  340.     if not arguments then
  341.         arguments = {
  342.             doCulling = true,
  343.             drawWireFrame = false,
  344.             drawTriangles = true
  345.         }
  346.     end
  347.     for k,vm in pairs(objects) do
  348.         for k,v in pairs(vm.connections) do
  349.             local v1 = vector.new(vm.origins[v[1]][1][1],vm.origins[v[1]][2][1],vm.origins[v[1]][3][1])
  350.             local v2 = vector.new(vm.origins[v[2]][1][1],vm.origins[v[2]][2][1],vm.origins[v[2]][3][1])
  351.             local v3 = vector.new(vm.origins[v[3]][1][1],vm.origins[v[3]][2][1],vm.origins[v[3]][3][1])
  352.             if ((v2:cross(v3)):dot(v1) >= 0) or not arguments.doCulling then
  353.                 if arguments.drawTriangles then
  354.                     proccesSolidTriangle(termObj,v1,v2,v3,vm.main.color[k])
  355.                 end
  356.                 if arguments.drawWireFrame then
  357.                     local wVecs1 = {
  358.                         vector.new(vm.vectors[v[1]][1][1],vm.vectors[v[1]][2][1],vm.vectors[v[1]][3][1]),
  359.                         vector.new(vm.vectors[v[2]][1][1],vm.vectors[v[2]][2][1],vm.vectors[v[2]][3][1])
  360.                     }
  361.                     local wVecs2 = {
  362.                         vector.new(vm.vectors[v[2]][1][1],vm.vectors[v[2]][2][1],vm.vectors[v[2]][3][1]),
  363.                         vector.new(vm.vectors[v[3]][1][1],vm.vectors[v[3]][2][1],vm.vectors[v[3]][3][1])
  364.                     }
  365.                     local wVecs3 = {
  366.                         vector.new(vm.vectors[v[3]][1][1],vm.vectors[v[3]][2][1],vm.vectors[v[3]][3][1]),
  367.                         vector.new(vm.vectors[v[1]][1][1],vm.vectors[v[1]][2][1],vm.vectors[v[1]][3][1])
  368.                     }
  369.                     drawLine(vm.vectors[v[1]][1][1],vm.vectors[v[1]][2][1],vm.vectors[v[2]][1][1],vm.vectors[v[2]][2][1],wVecs1,ZBUFFER,vm.main.color[k])
  370.                     drawLine(vm.vectors[v[2]][1][1],vm.vectors[v[2]][2][1],vm.vectors[v[3]][1][1],vm.vectors[v[3]][2][1],wVecs2,ZBUFFER,vm.main.color[k])
  371.                     drawLine(vm.vectors[v[3]][1][1],vm.vectors[v[3]][2][1],vm.vectors[v[1]][1][1],vm.vectors[v[1]][2][1],wVecs3,ZBUFFER,vm.main.color[k])
  372.                 end
  373.             end
  374.         end
  375.     end
  376.     return ZBUFFER
  377. end
  378. local convertBufferToDrawable = function(width,height,ZBUFFER,keepBuffer)
  379.     local switched = switchXYArray(ZBUFFER)
  380.     local output = {}
  381.     for i=1,height do
  382.         for ix=1,width do
  383.             if not output[i] then output[i] = "" end
  384.             if switched[i][ix] then
  385.                 output[i] = strInsert(output[i],toBlit[switched[i][ix].color])
  386.             else
  387.                 output[i] = strInsert(output[i],"f")
  388.             end
  389.         end
  390.     end
  391.     output.stamp = ZBUFFER.stamp
  392.     if not keepBuffer then
  393.         ZBUFFER = setmetatable(ZBUFFER,
  394.             {
  395.                 __index=function(t,k)
  396.                     local new = {}
  397.                     t[k]=new
  398.                     return new
  399.                 end
  400.             }
  401.         )
  402.         for k,v in pairs(ZBUFFER) do
  403.             ZBUFFER[k] = nil
  404.         end
  405.     end
  406.     return output
  407. end
  408. local drawConverted = function(termObject,drawData)
  409.     local obc = termObject.getBackgroundColor()
  410.     if drawData.stamp == "zbuffer" then
  411.         for i=1,#drawData do
  412.             termObject.setCursorPos(1,i)
  413.             termObject.blit((" "):rep(#drawData[i]),("f"):rep(#drawData[i]),drawData[i])
  414.         end
  415.         termObject.setBackgroundColor(obc)
  416.         return true
  417.     end
  418.     return false
  419. end
  420. local function newSquare()
  421.     local objData = {
  422.         scale = vector.new(1,1,1),
  423.         loc = vector.new(0,0,0),
  424.         rot = vector.new(0,0,0),
  425.         color = createColor(),
  426.         indexList = {1},
  427.         vertices = {
  428.             {{-0.5}, {-0.5}, {0}, {1}},
  429.             {{0.5}, {-0.5}, {0}, {1}},
  430.             {{-0.5},  {0.5}, {0}, {1}},
  431.             {{0.5},  {0.5}, {0}, {1}},
  432.         },
  433.         connections = {
  434.             {3,2,1},
  435.             {2,4,3},
  436.             {1,2,3},
  437.             {3,4,2},
  438.         }
  439.     }
  440.     for i,val in ipairs(objData.indexList) do
  441.         objData.indexList[i] = val*4-3
  442.     end
  443.     return objData
  444. end
  445. local function newCube()
  446.     local objData = {
  447.         scale = vector.new(1,1,1),
  448.         loc = vector.new(0,0,0),
  449.         rot = vector.new(0,0,0),
  450.         color = createColor(),
  451.         indexList = {1},
  452.         vertices = {
  453.             { { -0.5}, { -0.5}, {0.5}, {1} },  
  454.             { {0.5}, { -0.5}, {0.5}, {1} },
  455.             { { -0.5}, {0.5}, {0.5}, {1} },
  456.             { {0.5}, {0.5}, {0.5}, {1} },
  457.             { { -0.5}, { -0.5}, { -0.5}, {1}},
  458.             { {0.5}, { -0.5}, { -0.5}, {1}},
  459.             { { -0.5}, {0.5}, { -0.5}, {1}},
  460.             { {0.5}, {0.5}, { -0.5}, {1}}
  461.         },
  462.         connections = {{ 1,3,4 },{ 1,4,2 },{ 5,7,3 },{ 5,3,1 },{ 6,8,7 },{ 6,7,5 },{ 2,4,8 },{ 2,8,6 },{ 3,7,8 },{ 3,8,4 },{ 5,1,2 },{ 5,2,6 }}
  463.     }
  464.     for i,val in ipairs(objData.indexList) do
  465.         objData.indexList[i] = val*4-3
  466.     end
  467.     return objData
  468. end
  469. local function newPyramid()
  470.     local objData = {
  471.         scale = vector.new(1,1,1),
  472.         loc = vector.new(0,0,0),
  473.         rot = vector.new(0,0,0),
  474.         color = createColor(),
  475.         indexList = {1},
  476.         vertices = {
  477.             {{-0.5}, {-0.5}, {-0.5}, {1}},
  478.             {{0.5}, {-0.5}, {-0.5}, {1}},
  479.             {{-0.5}, {-0.5}, {0.5}, {1}},
  480.             {{0.5}, {-0.5}, {0.5}, {1}},
  481.             {{0}, {0.5}, {0}, {1}}
  482.         },
  483.         connections = {{3,2,1},{3,4,2},{2,5,1},{3,5,4},{4,5,2},{1,5,3}}
  484.     }
  485.     for i,val in ipairs(objData.indexList) do
  486.         objData.indexList[i] = val*4-3
  487.     end
  488.     return objData
  489. end
  490. local function newIcosahedron()
  491.     local objData = {
  492.         scale = vector.new(1,1,1),
  493.         loc = vector.new(0,0,0),
  494.         rot = vector.new(0,0,0),
  495.         color = createColor(),
  496.         indexList = {1},
  497.         divider = 30,
  498.         vertices = {
  499.             {{0},{30},{0},{1}},
  500.             {{26},{15},{0},{1}},
  501.             {{8},{15},{25},{1}},
  502.             {{-21},{15},{15},{1}},
  503.             {{-21},{15},{-15},{1}},
  504.             {{8},{15},{-25},{1}},
  505.             {{21},{-15},{15},{1}},
  506.             {{-8},{-15},{25},{1}},
  507.             {{-26},{-15},{0},{1}},
  508.             {{-8},{-15},{-25},{1}},
  509.             {{21},{-15},{-15},{1}},
  510.             {{0},{-30},{-15},{1}}
  511.         },
  512.         connections = {{1,2,3},{1,4,3},{1,4,5},{1,6,5},{1,6,2},{2,3,7},{8,3,7},{3,4,8},{9,4,8},{4,5,9},{10,5,9},{5,6,10},{11,6,10},{6,2,11},{7,2,11},{12,11,10},{12,9,10},{12,9,8},{12,7,8},{12,7,11}}        
  513.     }
  514.     for i,val in ipairs(objData.indexList) do
  515.         objData.indexList[i] = val*4-3
  516.     end
  517.     return objData
  518. end
  519. return {
  520.     transform = transform,
  521.     drawTransformed = drawTransformed,
  522.     objects = {
  523.         newSquare = newSquare,
  524.         newCube = newCube,
  525.         newPyramid = newPyramid,
  526.         newIcosahedron = newIcosahedron,
  527.     },
  528.     createColor = createColor,
  529.     createZBuffer = createZBuffer,
  530.     createPerspective = createPerspective,
  531.     createCamera = createCamera,
  532.     getProcessingArgs = getProcessingArgs,
  533.     convertBufferToDrawable = convertBufferToDrawable,
  534.     drawConverted = drawConverted,
  535.     convertBufferToDrawable = convertBufferToDrawable,
  536. }
  537.  
Add Comment
Please, Sign In to add comment