jig487

JIG3D_Engine_Dev

Aug 23rd, 2021 (edited)
384
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.63 KB | None | 0 0
  1. ---@diagnostic disable: undefined-global
  2.  
  3. --Dimensions of your display (AR goggle or equivalent display, not actual monitor).
  4. --Hardcoded for now bc no way to get size of AR goggles
  5. --If the renders aren't centered to your screen it's because these values are wrong.
  6. local screenAR = {
  7.     x = 480 *0.5, --Replace 480 with your displays width
  8.     y = 270 *0.5,  --Replace 270 with your displays height
  9.     aspectRatio = 270/480,
  10. }
  11.  
  12.     --Setup monitor and AR controller
  13. local mon = peripheral.find("monitor")
  14. local ar = peripheral.find("arController")
  15. local oldTerm = term.redirect(mon)
  16. mon.setTextScale(0.5)
  17. mon.setCursorPos(1,1)
  18. mon.clear()
  19. term.setCursorPos(1,1)
  20. ar.clear()
  21.  
  22.     --Get API's
  23. local dt = require("jig3DTex")
  24. local draw = require("jigARTex")
  25.  
  26.     --Prepare 3d objects to render
  27. local objList = {
  28.     c1 = dt.newCube(),
  29. }
  30.  
  31.     --Set initial values objects
  32. objList.c1.loc.z = 3
  33. local rotVec = vector.new(2,2,2) --Will later be added each frame to c1's rotation vector to make it rotate
  34. objList.c1.useShader = true
  35. objList.c1.Name = "shrekConverted"
  36.  
  37. --Main render loop
  38. local frames = 0
  39. local sTime = os.time()
  40.  
  41. for i = 1, 1000 do
  42.  
  43.     frames = frames + 1
  44.     local projected = {}
  45.  
  46.         --Object Manipulation stuff
  47.     objList.c1.rot = objList.c1.rot:add(rotVec) --Animating the cube by rotating it with rotVec
  48.  
  49.         --Transform everything in objList
  50.     for name,objectData in pairs(objList) do
  51.         term.setCursorPos(1,2)
  52.         print("Processing "..name)
  53.         projected[name] = dt.processObject(objectData,screenAR)
  54.     end
  55.     mon.clear()
  56.     mon.setCursorPos(1,1)
  57.     mon.write("Frame:"..frames)
  58.     sleep(0.1)
  59.     ar.clear()
  60.     ar.fill(0,0,75,20,0xE5D0CC)
  61.     ar.drawString("Frame: "..frames, 5, 5, 0xBA1F33)
  62.  
  63.         --Render everything in objList with the now transformed points in projected = {...}
  64.     for name,_ in pairs(projected) do
  65.             --Change these to just grab all the data for [name] instead of just indexList / colorList?
  66.         --draw.drawSolidObjTex(ar,projected[name],objList[name])
  67.         draw.drawWireObj(ar,projected[name],objList[name].colorList)
  68.     end
  69. end
  70.  
  71. local eTime = os.time()
  72.     --Prevent freezing when time goes from 23:99 or whatever tick to 00:00... this probably works?
  73. if eTime < sTime then eTime = eTime + sTime end
  74.     --Display fps info
  75. local tTime = (eTime-sTime)/0.02
  76. local totalP = 0
  77.  
  78. for name,ind in pairs(objList) do
  79.     totalP = totalP + #objList[name].indexList
  80. end
  81.  
  82. print("Finished scene with "..(totalP/3).." total polygons")
  83. print("Drew "..frames.." frames in "..tTime.." seconds")
  84. print("Average FPS: "..(frames/tTime))
Add Comment
Please, Sign In to add comment