Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local pers = peripheral.wrap("back")
- local c = pers.canvas()
- c.clear()
- local rgb = require("cRGB")
- local cam,campos,offset,rotationZ,rotationX,rotationY,projection,projected,matrix = {},{},{},{},{},{},{},{},{}
- local width,height = c.getSize()
- local scale = 1
- local matrix = {{1,0,0},{0,1,0}}
- local function matmul(m1, m2)
- if #m1[1] ~= #m2 then
- error("Columns m1 must match rows m2",2)
- return nil
- end
- local result = {}
- for i = 1, #m1 do
- result[i] = {}
- for j = 1, #m2[1] do
- local sum = 0
- for k = 1, #m2 do
- sum = sum + (m1[i][k] * m2[k][j])
- end
- result[i][j] = sum
- end
- end
- return result
- end
- local function drawPoint(x,y)
- local rect = c.addDot({(x*scale)+(width * 0.5),(y*scale)+(height * 0.5)})
- rect.setColor(rgb.conv(colors.red))
- end
- local points = {
- { {5},{-5},{5}},
- { {5},{5},{5}},
- { {-5},{5},{5}},
- { {-5},{-5},{5}},
- { {5},{-5},{-5}},
- { {5},{5},{-5}},
- { {-5},{5},{-5}},
- { {-5},{-5},{-5}}
- }
- local angle = 0
- local results = {}
- local rotation = {
- { math.cos(angle), -math.sin(angle) },
- { math.sin(angle), math.cos(angle) }
- }
- while true do
- os.sleep(0.1)
- c.clear()
- for i=1,#points do
- results[i] = matmul(rotation, points[i])
- results[i] = matmul(matrix, points[i])
- drawpoints(results[i][1][1], results[i][2][1])
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement