10th October 2020, 6:22 PM
Started working on some basic 3d. Right now, it's looking to support camera position and rotation on one axis; the main reason for only one axis of rotation is because that way I can use complex numbers to easily handle rotation and it wont be as difficult as matrices. Whenever ROP (successor to PR3R) comes around is probably when I'm gonna make full 3d, since more processing power will be available and it'll be usable for far longer. Code is below
this hasn't been tested in any capacity i have no clue if it works lol
Code:
-- initialize camera vars & constants
b3d_pi = math.pi() -- defines pi if it becomes necessary
-- b3dcam_ is a prefix before properties of the camera
b3dcam_pos = {0,0,0} -- defined as a coordinate in 3d space (x,y,z)
b3dcam_rot = 0 -- defined in radians
--[[
camera only rotates on one axis (left or right)
this makes things easier on me and i dont have to implement proper 3d rotation
and complex numbers are cool and i can just use those :)
]]--
b3dcam_focallength = 100 -- defines a constant addition to perspective var to make things look right.
function b3d_camsetpos(x,y,z) -- puts camera to given xyz
b3dcam_pos = {x,y,z}
end
function b3d_cammove(x,y,z) -- moves camera by given xyz
b3dcam_pos = {b3dcam_pos[1] + x, b3dcam_pos[2] + y, b3dcam_pos[3] + z}
end
function b3d_camsetrot(r) -- puts camera to given rotation
b3dcam_rot = r
end
function b3d_camrot(r) -- rotates camera by given rotation
b3dcam_rot = b3dcam_rot + r
end
function b3d_drawobj(object,x,y,z)
local b3d_xrel = x - b3dcam_pos[1]
local b3d_yrel = y - b3dcam_pos[2]
local b3d_zrel = z - b3dcam_pos[3]
local b3d_camrot = complex.new(math.cos(b3dcam_rot),math.sin(b3dcam_rot))
for i in ipairs(object) do -- for all triangles/squares in given object table
local b3d_objtype = object[i][1][1]
if b3d_objtype == 0 then
local b3d_ptrans = {{object[i][2][1]+b3d_xrel,object[i][2][3]+b3d_zrel},{object[i][3][1]+b3d_xrel,object[i][3][3]+b3d_zrel},{object[i][4][1]+b3d_xrel,object[i][4][3]+b3d_zrel}} -- (x,z) format bc y is irrelevant
for g=1,3,1 do
local b3d_cmtrns = complex.new(b3d_ptrans[g][1],b3d_ptrans[g][2])
b3d_cmtrns = complex.mul(b3d_cmtrns,b3d_camrot)
b3d_ptrans[g] = {b3d_cmtrns.r,b3d_cmtrns.i}
end
elseif b3d_objtype == 1 then
for g=1,4,1 do
end
else
player.chat("Error: Invalid shape on entry ".. i .."!",0xff0000)
end
end
end
this hasn't been tested in any capacity i have no clue if it works lol
i failed the mario twitter challenge