Advertisement
jig487

test_cherry

Mar 25th, 2022 (edited)
620
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.28 KB | None | 0 0
  1. local db = require("debugging")
  2. local cdraw = require("cherry_drawing")
  3. local c3d = require("cherry_3d")
  4. local cmat = require("cherry_matrix")
  5.  
  6. --set starting parameters
  7. local w,h = 60,40
  8. local display = {x=w*2,y=h*3}
  9. local objList = {
  10.     cmat.newCube()
  11. }
  12. objList[1].rot = vector.new(-45,0,0)
  13. objList[1].loc = vector.new(0,0,4)
  14. objList[1].scale = vector.new(2,2,2)
  15.  
  16. local camera = vector.new(0,0,20)
  17.  
  18. --debugging toggles
  19. local endFrameCheck = false
  20.  
  21. --engine start
  22. local frameCount = 0
  23. local maxFrames = 2000
  24. term.clear()
  25. local startTime = os.time()*50
  26. for i = 1, maxFrames do
  27.         --Initialize stuff
  28.     frameCount = frameCount + 1
  29.     local frame = cdraw.makeFrame(w,h)
  30.     local subw = frame.subw
  31.     local subh = frame.subh
  32.     local hw,hh = subw*0.5,subh*0.5
  33.  
  34.         --Apply transformations to objects here
  35.     --objList[1].rot.x = math.cos(os.time()*10)*180
  36.     objList[1].rot.y = math.sin(os.time()*5)*90
  37.     --objList[1].rot.z = math.cos(os.time()*10)*180
  38.  
  39.     --objList[1].loc.x = math.cos(os.time()*10)*1
  40.     --objList[1].loc.y = math.sin(os.time()*50)*1.5
  41.     --objList[1].loc.z = math.cos(os.time()*10) + 5
  42.  
  43.         --Actual engine here
  44.     for j = 1, #objList do
  45.         local results = c3d.screenTransform(objList[j],display,camera,frame)
  46.         cdraw.drawSolidObj(frame,results)
  47.         --db.debug(1,1,textutils.serialize(results),colors.blue,colors.black)
  48.         --cdraw.addWireObj(frame,results)
  49.         c3d.screenTransform(objList[j],display,camera,frame)
  50.     end
  51.  
  52.     --db.txt(1,1,frame.subPixCanvas,colors.blue)
  53.     --local height,width = term.getSize()
  54.     --db.txt(1,1,"Terminal size: "..height..", "..width)
  55.     --read()
  56.    
  57.         --Final frame wrap up and draw
  58.     db.txt(1,h+1,"Frame: "..frameCount)
  59.     cdraw.drawFrame(1,1,frame)
  60.  
  61.     if endFrameCheck then
  62.         --db.txt(1,1,textutils.serialize(results))
  63.         read()
  64.     else
  65.         --sleep(0.35)
  66.         os.queueEvent("FakeEvent") --Fake event to prevent `too long without yielding` error
  67.         os.pullEvent("FakeEvent")
  68.     end
  69. end
  70. local endTime = os.time()*50
  71.  
  72. db.txt(1,h+1,"Done!")
  73. local runTime = endTime-startTime
  74. db.txt(1,h+2,"Drew ["..frameCount.."] frames in ["..math.floor(runTime).."] seconds!")
  75. db.txt(1,h+3,"Average FPS: "..math.floor(frameCount/runTime))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement