jig487

PlumEngine

Nov 11th, 2021 (edited)
860
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.76 KB | None | 0 0
  1. --Dimensions of your display. Hardcoded for now bc no way to get size of AR goggles
  2. --If the renders aren't centered to your screen it's because these values are wrong.
  3. local display = {
  4.     x = 60, --Replace with x *0.5, where x is your displays width
  5.     y = 60  --Replace with y *0.5, where y is your displays height
  6.     --y = x because not messing with aspect ratio right now
  7. }
  8. --x = 480, y = 270
  9.  
  10.     --Setup monitor and AR controller
  11. local ar --= peripheral.find("arController")
  12. --local oldTerm = term.redirect(mon)    
  13. --mon.setTextScale(0.5)
  14. --mon.setCursorPos(1,1)
  15. --mon.clear()
  16. term.setCursorPos(1,1)
  17. term.clear()
  18. --ar.clear()
  19.  
  20.     --Get API's
  21. local dt = require("plum3D")
  22. local draw = require("plumDraw")
  23.  
  24.     --Load default objects
  25.     --BUG objects moving strangely
  26. local objList = {
  27.     c1 = dt.newCube(),
  28.     --c2 = dt.newCube(),
  29. }
  30.  
  31.     --Set initial values for location / rotation / scale
  32. objList.c1.loc.z = -3
  33. objList.c1.loc.x = 0
  34. objList.c1.loc.y = 1
  35.  
  36.     --Save some stuff for FPS calculations
  37. local frames = 0
  38. local sTime = os.time()
  39.  
  40. --local projMat = dt.makeProjectionMat(1,100,-135,135,-240,240)
  41. local projMat = dt.makeProjectionMat(90,1,100)
  42.  
  43.     --Main render loop
  44. for i = 1, 1000 do
  45.     frames = frames + 1
  46.     --mon.setCursorPos(1,1)
  47.     term.setCursorPos(1,1)
  48.     print("Frame: "..frames)
  49.  
  50.         --Animate objects
  51.     objList.c1.rot.y = os.time()*500
  52.     --objList.c2.rot.y = os.time()*500+500
  53.     objList.c1.rot.z = math.cos(os.time()/0.02)*20
  54.    
  55.         --Transform everything in objList
  56.     local projected = {}
  57.     for name,objectData in pairs(objList) do
  58.         projected[name] = dt.screenTransform(objectData,display,cam,projMat)
  59.     end
  60.         --Use EITHER sleep() or the fake events. Fake events give "uncapped" FPS, sleep() caps it
  61.         --if you are using player positon as the camera you don't need either of these.
  62.     sleep(0.08)
  63.     os.queueEvent("FakeEvent") --Fake event to prevent `too long without yielding` error
  64.     os.pullEvent("FakeEvent")
  65.     --ar.clear()
  66.     term.clear()
  67.  
  68.     --Render everything in objList with transformed points
  69.     for name,projectedObj in pairs(projected) do
  70.         draw.drawSolidObj(ar,projectedObj)
  71.         --draw.drawWireObj(ar,projectedObj)
  72.     end
  73. end
  74.  
  75.     --Calculate / display FPS
  76. local eTime = os.time()
  77.  
  78.     --Prevent freezing when time goes from 23:99 or whatever tick to 00:00
  79. if eTime < sTime then eTime = eTime + sTime end
  80.  
  81.     --Display fps info
  82. local tTime = (eTime-sTime)/0.02
  83. local totalP = 0
  84. for name,_ in pairs(objList) do
  85.     totalP = totalP + #objList[name].indexList
  86. end
  87.  
  88. print("Finished scene with "..(totalP/3).." total polygons")
  89. print("Drew "..frames.." frames in "..tTime.." seconds")
  90. print("Average FPS: "..(frames/tTime))
Add Comment
Please, Sign In to add comment