so basicaly i try to translate olc3d engine from cpp to lua in computercraft in minecraft i can translate the cube in x and y but z does not work this is the original olc3d engine that i try to copy https://github.com/OneLoneCoder/videos/blob/master/OneLoneCoder_olcEngine3D_Part1.cpp
function newLine()
xPos, yPos = term.getCursorPos()
term.setCursorPos(1,(yPos + 1))
end
paitutils2.newMonitor("left")
mesh = {
{vector.new(0.0,0.0,0.0),vector.new(0.0,1.0,0.0),vector.new(1.0,1.0,0.0)},
{vector.new(0.0,0.0,0.0),vector.new(1.0,1.0,0.0),vector.new(1.0,0.0,0.0)},
{vector.new(1.0,0.0,0.0),vector.new(1.0,1.0,0.0),vector.new(1.0,1.0,1.0)},
{vector.new(1.0,0.0,0.0),vector.new(1.0,1.0,1.0),vector.new(1.0,0.0,1.0)},
{vector.new(1.0,0.0,1.0),vector.new(1.0,1.0,1.0),vector.new(0.0,1.0,1.0)},
{vector.new(1.0,0.0,1.0),vector.new(0.0,1.0,1.0),vector.new(0.0,0.0,1.0)},
{vector.new(0.0,0.0,1.0),vector.new(0.0,1.0,1.0),vector.new(0.0,1.0,0.0)},
{vector.new(0.0,0.0,1.0),vector.new(0.0,1.0,0.0),vector.new(0.0,0.0,0.0)},
{vector.new(0.0,1.0,0.0),vector.new(0.0,1.0,1.0),vector.new(1.0,1.0,1.0)},
{vector.new(0.0,1.0,0.0),vector.new(1.0,1.0,1.0),vector.new(1.0,1.0,0.0)},
{vector.new(1.0,0.0,1.0),vector.new(0.0,0.0,1.0),vector.new(0.0,0.0,0.0)},
{vector.new(1.0,0.0,1.0),vector.new(0.0,0.0,0.0),vector.new(1.0,0.0,0.0)}
}
matrix = {{0,0,0,0},
{0,0,0,0},
{0,0,0,0},
{0,0,0,0}}
matproj = matrix
wysokosc = 80.0
szerokosc = 164.0
fnear = 0.1
ffar = 1000.0
ffov = 90.0
fasr = (wysokosc/szerokosc)* (7/5) --because 'pixel' is 7x5 pixels
ffovr = 1.0 / math.tan(ffov * 0.5 / 180.0 * math.pi)
w=1
--3dpespective matrix
matproj[1][1] = fasr * ffovr
matproj[2][2] = ffovr
matproj[3][3] = -ffar / (ffar - fnear)
matproj[4][3] = (-ffar * fnear)/(ffar - fnear)
matproj[3][4] = -1.0
matproj[4][4] = 0.0
function proj_mat(matrix ,trj)
proj_tri = vector.new()
--print(trj.x .." ".. trj.y .." " .. trj.z )
proj_tri.x = (trj.x * matrix[1][1]) + (trj.y * matrix[2][1]) + (trj.z * matrix[3][1] )+ w * matrix[4][1]
proj_tri.y = (trj.x * matrix[1][2]) + (trj.y * matrix[2][2]) + (trj.z * matrix[3][2] )+ w * matrix[4][2]
proj_tri.z = (trj.x * matrix[1][3]) + (trj.y * matrix[2][3]) + (trj.z * matrix[3][3] )+ w * matrix[4][3]
w = (trj.x * matrix[1][4]) + (trj.y * matrix[2][4]) + (trj.z * matrix[3][4] )+ w * matrix[4][4]
if not w == 0.0 then
proj_tri.x = proj_tri.x / w
proj_tri.y = proj_tri.y / w
proj_tri.z = proj_tri.z / w
end
print(proj_tri.x .." ".. proj_tri.y .." " .. proj_tri.z .." ".. trj.x .." ".. trj.y .. " " .. trj.z)
return(proj_tri)
end
peripheral.call("left","setBackgroundColor",colors.black)
peripheral.call("left","setCursorBlink",false)
peripheral.call("left","setTextScale",0.5)
peripheral.call("left","clear")
peripheral.call("left","setBackgroundColor",colors.red)
for i = 1 , 12 ,1 do
vert = {}
vert[1] = mesh[i][1]
vert[2] = mesh[i][2]
vert[3] = mesh[i][3]
--print(vert[1].x .." ".. vert[1].y.." " .. vert[1].z .. " "..vert[2].x .." ".. vert[2].y.." " .. vert[2].z .." ".. vert[3].x .." ".. vert[3].y.." " .. vert[3].z)
vert[1].z = vert[1].z + 3.0
vert[2].z = vert[2].z + 3.0 --translacja
vert[3].z = vert[3].z + 3.0
vert[1].x = vert[1].x + 0.25
vert[2].x = vert[2].x + 0.25 --translacja
vert[3].x = vert[3].x + 0.25
--vert[1].y = vert[1].y + 0.5
--vert[2].y = vert[2].y + 0.5 --translacja
--vert[3].y = vert[3].y + 0.5
--print(vert[1].x .." ".. vert[1].y.." " .. vert[1].z .. " | "..vert[2].x .." ".. vert[2].y.." " .. vert[2].z .." | ".. vert[3].x .." ".. vert[3].y.." " .. vert[3].z)
proj_vert = vector.new()
-- proj_vert[1] = proj_mat(rotx,vert[1])
-- proj_vert[2] = proj_mat(rotx,vert[2]) --rotate x
-- proj_vert[3] = proj_mat(rotx,vert[3])
proj_vert[1] = proj_mat(matproj,vert[1])
proj_vert[2] = proj_mat(matproj,vert[2]) --projekcja 3d na 2d
proj_vert[3] = proj_mat(matproj,vert[3])
--skalowanie
proj_vert[1].x = proj_vert[1].x * szerokosc
proj_vert[1].y = proj_vert[1].y * wysokosc + 1
proj_vert[2].x = proj_vert[2].x * szerokosc
proj_vert[2].y = proj_vert[2].y * wysokosc + 1
proj_vert[3].x = proj_vert[3].x * szerokosc
proj_vert[3].y = proj_vert[3].y * wysokosc + 1
paitutils2.drawLine(proj_vert[1].x,proj_vert[1].y,proj_vert[2].x,proj_vert[2].y)
paitutils2.drawLine(proj_vert[1].x,proj_vert[1].y,proj_vert[3].x,proj_vert[3].y)
paitutils2.drawLine(proj_vert[3].x,proj_vert[3].y,proj_vert[2].x,proj_vert[2].y)
term.setTextColor(colors.white)
--term.write("w["..w.."] ")
--newLine()
--term.write(" x[" .. proj_vert[1].x .. "] y[" .. proj_vert[1].y .. "] x2[" .. proj_vert[2].x .. "] y2[" .. proj_vert[2].y .."] \n")
--newLine()
--term.write(" x[" .. proj_vert[1].x .. "] y[" .. proj_vert[1].y .. "] x2[" .. proj_vert[3].x .. "] y2[" .. proj_vert[3].y .."] \n")
--newLine()
--term.write(" x[" .. proj_vert[3].x .. "] y[" .. proj_vert[3].y .. "] x2[" .. proj_vert[2].x .. "] y2[" .. proj_vert[2].y .."] \n")
--newLine()
end
if someone wants to try and replicate the setup it is a 6x8 advanced monitor as a display on the left and advanced computer on the right(it is important the monitor is on the left ).modpack is ftb revelation but it should work with just the computercraft mod instaled.