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 = 60, --Replace with x *0.5, where x is your displays width
- y = 60 --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 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("plum3D")
- local draw = require("plumDraw")
- --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.c1.loc.x = 0
- objList.c1.loc.y = 1
- --Save some stuff for FPS calculations
- local frames = 0
- local sTime = os.time()
- --local projMat = dt.makeProjectionMat(1,100,-135,135,-240,240)
- local projMat = dt.makeProjectionMat(90,1,100)
- --Main render loop
- for i = 1, 1000 do
- frames = frames + 1
- --mon.setCursorPos(1,1)
- term.setCursorPos(1,1)
- print("Frame: "..frames)
- --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
- --Transform everything in objList
- local projected = {}
- 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.08)
- os.queueEvent("FakeEvent") --Fake event to prevent `too long without yielding` error
- os.pullEvent("FakeEvent")
- --ar.clear()
- term.clear()
- --Render everything in objList with transformed points
- for name,projectedObj in pairs(projected) do
- draw.drawSolidObj(ar,projectedObj)
- --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