Hello, I'm currently testing to see if I can do 3D. And I have a square with 2 polygons, but to make it 3D and apply a rotation matrix I would have to make a Z value. I have no idea how to do that. Any help appreciated!
polygons = { { verts = {{x=40, y=40}, {x=80, y=40}, {x=80, y=80}} }, { verts = {{x=40, y=40}, {x=40, y=80}, {x=80, y=80}} } } function _init() end function _update() end function _draw() cls() for i = 1, #polygons do if polygons[i] and polygons[i].verts then _drawPolygon(polygons[i]) end end end function _drawPolygon(polygon) local total_verts = #polygon.verts for i = 1, total_verts do local next_vert = (i % total_verts) + 1 local x1, y1 = polygon.verts[next_vert].x, polygon.verts[next_vert].y local x2, y2 = polygon.verts[i].x, polygon.verts[i].y line(x1, y1, x2, y2, 7) end end |
There's no native 3D so implementing this is up to you. Get out some graph paper and plot how a depth of some z value at a given x,y would impact the x and y screen coordinates where that vertex is actually drawn. You can also search for tutorials on existing methods for 3D projection on PICO-8. Good luck!
[Please log in to post a comment]