Advertisement
9551

Untitled

Jul 24th, 2021
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.46 KB | None | 0 0
  1. local pers = peripheral.wrap("back")
  2. local c = pers.canvas()
  3. c.clear()
  4. local rgb = require("cRGB")
  5.  
  6. local cam,campos,offset,rotationZ,rotationX,rotationY,projection,projected,matrix = {},{},{},{},{},{},{},{},{}
  7. local width,height = c.getSize()
  8. local scale = 1
  9.  
  10. local matrix = {{1,0,0},{0,1,0}}
  11.  
  12. local function matmul(m1, m2)
  13.     if #m1[1] ~= #m2 then
  14.         error("Columns m1 must match rows m2",2)
  15.         return nil
  16.     end
  17.     local result = {}
  18.     for i = 1, #m1 do
  19.         result[i] = {}
  20.         for j = 1, #m2[1] do
  21.             local sum = 0
  22.             for k = 1, #m2 do
  23.                 sum = sum + (m1[i][k] * m2[k][j])
  24.             end
  25.         result[i][j] = sum
  26.         end
  27.     end
  28.     return result
  29. end
  30.  
  31. local function drawPoint(x,y)
  32.     local rect = c.addDot({(x*scale)+(width * 0.5),(y*scale)+(height * 0.5)})
  33.     rect.setColor(rgb.conv(colors.red))
  34. end
  35.  
  36. local points = {
  37.     { {5},{-5},{5}},
  38.     { {5},{5},{5}},
  39.     { {-5},{5},{5}},
  40.     { {-5},{-5},{5}},
  41.     { {5},{-5},{-5}},
  42.     { {5},{5},{-5}},
  43.     { {-5},{5},{-5}},
  44.     { {-5},{-5},{-5}}
  45. }
  46. local angle = 0
  47. local results = {}
  48. local rotation = {
  49.     { math.cos(angle), -math.sin(angle) },
  50.     { math.sin(angle), math.cos(angle) }
  51.   }
  52.  
  53. while true do
  54.     os.sleep(0.1)
  55.     c.clear()
  56.     for i=1,#points do
  57.         results[i] = matmul(rotation, points[i])
  58.         results[i] = matmul(matrix, points[i])
  59.         drawpoints(results[i][1][1], results[i][2][1])
  60.     end
  61. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement