Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local db = require("debugging")
- local cdraw = require("cherry_drawing")
- local c3d = require("cherry_3d")
- local cmat = require("cherry_matrix")
- --set starting parameters
- local w,h = 60,40
- local display = {x=w*2,y=h*3}
- local objList = {
- cmat.newCube()
- }
- objList[1].rot = vector.new(-45,0,0)
- objList[1].loc = vector.new(0,0,4)
- objList[1].scale = vector.new(2,2,2)
- local camera = vector.new(0,0,20)
- --debugging toggles
- local endFrameCheck = false
- --engine start
- local frameCount = 0
- local maxFrames = 2000
- term.clear()
- local startTime = os.time()*50
- for i = 1, maxFrames do
- --Initialize stuff
- frameCount = frameCount + 1
- local frame = cdraw.makeFrame(w,h)
- local subw = frame.subw
- local subh = frame.subh
- local hw,hh = subw*0.5,subh*0.5
- --Apply transformations to objects here
- --objList[1].rot.x = math.cos(os.time()*10)*180
- objList[1].rot.y = math.sin(os.time()*5)*90
- --objList[1].rot.z = math.cos(os.time()*10)*180
- --objList[1].loc.x = math.cos(os.time()*10)*1
- --objList[1].loc.y = math.sin(os.time()*50)*1.5
- --objList[1].loc.z = math.cos(os.time()*10) + 5
- --Actual engine here
- for j = 1, #objList do
- local results = c3d.screenTransform(objList[j],display,camera,frame)
- cdraw.drawSolidObj(frame,results)
- --db.debug(1,1,textutils.serialize(results),colors.blue,colors.black)
- --cdraw.addWireObj(frame,results)
- c3d.screenTransform(objList[j],display,camera,frame)
- end
- --db.txt(1,1,frame.subPixCanvas,colors.blue)
- --local height,width = term.getSize()
- --db.txt(1,1,"Terminal size: "..height..", "..width)
- --read()
- --Final frame wrap up and draw
- db.txt(1,h+1,"Frame: "..frameCount)
- cdraw.drawFrame(1,1,frame)
- if endFrameCheck then
- --db.txt(1,1,textutils.serialize(results))
- read()
- else
- --sleep(0.35)
- os.queueEvent("FakeEvent") --Fake event to prevent `too long without yielding` error
- os.pullEvent("FakeEvent")
- end
- end
- local endTime = os.time()*50
- db.txt(1,h+1,"Done!")
- local runTime = endTime-startTime
- db.txt(1,h+2,"Drew ["..frameCount.."] frames in ["..math.floor(runTime).."] seconds!")
- db.txt(1,h+3,"Average FPS: "..math.floor(frameCount/runTime))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement