Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Dimensions of your display. 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 display = {
- x = 480, --Replace with x *0.5, where x is your displays width
- y = 270 --Replace with y *0.5, where y is your displays height
- --y = x because not messing with aspect ratio right now
- }
- --x = 480, y = 270
- --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)
- term.clear()
- ar.clear()
- --Get API's
- local dt = require("jig3DV1")
- local draw = require("jigARV1")
- --We later offset the camera when we get the players position BY the starting position so we always start at 0,0 instead of fuck off wherever you are
- local camOffset = dt.getPlayerData("jig487")
- camOffset.loc.y = camOffset.loc.y - 1.62
- --Load default objects
- --BUG objects moving strangely
- local objList = {
- c1 = dt.newCube(),
- --c2 = dt.newCube(),
- }
- --Set initial values for location / rotation / scale
- objList.c1.loc.z = -3
- --objList.c2.loc.z = -5
- --objList.c2.rot.y = 90
- --Save some stuff for FPS calculations
- local frames = 0
- local sTime = os.time()
- --Setting cam to 0 for testing purposes
- local cam = {
- loc = vector.new(0,0,-0.5),
- rot = vector.new(0,180,0),
- }
- local emptyDepthBuffer = dt.makeDepthBuffer(display)
- --local projMat = dt.makeProjectionMat(1,100,-135,135,-240,240)
- local projMat = dt.makeProjectionMat(90,1,100)
- --Main render loop
- for i = 1, 1 do
- frames = frames + 1
- mon.setCursorPos(1,1)
- print("Frame: "..frames)
- local projected = {}
- --Animate objects
- --objList.c1.rot.y = os.time()*500
- --objList.c2.rot.y = os.time()*500+500
- --objList.c1.rot.z = math.cos(os.time()/0.02)*20
- --Set camera rotation / position and apply location offset
- --local cam = dt.getPlayerData("jig487")
- --cam.loc = cam.loc:sub(camOffset.loc)
- --cam.loc.x = -cam.loc.x
- --Transform everything in objList
- for name,objectData in pairs(objList) do
- projected[name] = dt.screenTransform(objectData,display,cam,projMat)
- end
- --Use EITHER sleep() or the fake events. Fake events give "uncapped" FPS, sleep() caps it
- --if you are using player positon as the camera you don't need either of these.
- sleep(0.5)
- --os.queueEvent("FakeEvent") --Fake event to prevent `too long without yielding` error
- --os.pullEvent("FakeEvent")
- ar.clear()
- local depthBuffer = emptyDepthBuffer
- --Render everything in objList with transformed points
- for name,projectedObj in pairs(projected) do
- draw.drawSolidObj(ar,projectedObj,depthBuffer)
- --draw.drawWireObj(ar,projectedObj)
- end
- end
- --Calculate / display FPS
- local eTime = os.time()
- --Prevent freezing when time goes from 23:99 or whatever tick to 00:00
- if eTime < sTime then eTime = eTime + sTime end
- --Display fps info
- local tTime = (eTime-sTime)/0.02
- local totalP = 0
- for name,_ 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