Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ---@diagnostic disable: undefined-global
- --Dimensions of your display (AR goggle or equivalent display, not actual monitor).
- --Hardcoded for now bc no way to get size of AR goggles
- --If the renders aren't centered to your screen it's because these values are wrong.
- local screenAR = {
- x = 480 *0.5, --Replace 480 with your displays width
- y = 270 *0.5, --Replace 270 with your displays height
- aspectRatio = 270/480,
- }
- --Setup monitor and AR controller
- local mon = peripheral.find("monitor")
- local ar = peripheral.find("arController")
- local oldTerm = term.redirect(mon)
- mon.setTextScale(0.5)
- mon.setCursorPos(1,1)
- mon.clear()
- term.setCursorPos(1,1)
- ar.clear()
- --Get API's
- local dt = require("jig3DTex")
- local draw = require("jigARTex")
- --Prepare 3d objects to render
- local objList = {
- c1 = dt.newCube(),
- }
- --Set initial values objects
- objList.c1.loc.z = 3
- local rotVec = vector.new(2,2,2) --Will later be added each frame to c1's rotation vector to make it rotate
- objList.c1.useShader = true
- objList.c1.Name = "shrekConverted"
- --Main render loop
- local frames = 0
- local sTime = os.time()
- for i = 1, 1000 do
- frames = frames + 1
- local projected = {}
- --Object Manipulation stuff
- objList.c1.rot = objList.c1.rot:add(rotVec) --Animating the cube by rotating it with rotVec
- --Transform everything in objList
- for name,objectData in pairs(objList) do
- term.setCursorPos(1,2)
- print("Processing "..name)
- projected[name] = dt.processObject(objectData,screenAR)
- end
- mon.clear()
- mon.setCursorPos(1,1)
- mon.write("Frame:"..frames)
- sleep(0.1)
- ar.clear()
- ar.fill(0,0,75,20,0xE5D0CC)
- ar.drawString("Frame: "..frames, 5, 5, 0xBA1F33)
- --Render everything in objList with the now transformed points in projected = {...}
- for name,_ in pairs(projected) do
- --Change these to just grab all the data for [name] instead of just indexList / colorList?
- --draw.drawSolidObjTex(ar,projected[name],objList[name])
- draw.drawWireObj(ar,projected[name],objList[name].colorList)
- end
- end
- local eTime = os.time()
- --Prevent freezing when time goes from 23:99 or whatever tick to 00:00... this probably works?
- if eTime < sTime then eTime = eTime + sTime end
- --Display fps info
- local tTime = (eTime-sTime)/0.02
- local totalP = 0
- for name,ind in pairs(objList) do
- totalP = totalP + #objList[name].indexList
- end
- print("Finished scene with "..(totalP/3).." total polygons")
- print("Drew "..frames.." frames in "..tTime.." seconds")
- print("Average FPS: "..(frames/tTime))
Add Comment
Please, Sign In to add comment