cord={
{x=5,y=5,z=5},
{x=5,y=-5,z=5},
{x=-5,y=-5,z=5},
{x=-5,y=5,z=5},
{x=0,y=0,z=0}
}
pt={
{1,2},
{2,3},
{3,4},
{4,1},
{1,5},
{2,5},
{3,5},
{4,5}
}
card={}
for i=1,#cord do
card[i]={x=0,y=0,z=0}
end
rad={x=0,y=0,z=0}
cent={x=0,y=0,z=0}
size=5
function zsort(p1,p2)
return p1.z>p2.z
end
ofsz=100
function roct(mass,center,r1,r2,r3)
for i=1,#cord do
local a,b,c
local a1,b1,c1
local a2,b2,c2
local a3,b2,c3
local mass1={}
mass1[i]={x=0,y=0,z=0}
a = mass[i].x
b = mass[i].y
c = mass[i].z
a1 = a*math.cos(r3)-b*math.sin(r3)
b1 = a*math.sin(r3)+b*math.cos(r3)
c1 = c
c2 = c1*math.cos(r2)-a1*math.sin(r2)
a2 = c1*math.sin(r2)+a1*math.cos(r2)
b2 = b1
b3 = b2*math.cos(r1)-c2*math.sin(r1)
c3 = b2*math.sin(r1)+c2*math.cos(r1)
a3 = a2
card[i].z=c3*size
fov=180
k =fov/(card[i].z + cent.z+ofsz)
card[i].x = 120+ math.floor((a3*size + cent.x) * k)
card[i].y = 68+ math.floor((b3*size + cent.y) * k)
end
end
n1=120
n2=68
n3=200
roat=false
function TIC()
cls()
for i=1,#cord do
if btn(0)and roat==false then cent.y=cent.y-1 end
if btn(1)and roat==false then cent.y=cent.y+1 end
if btn(2)and roat==false then cent.x=cent.x-1 end
if btn(3)and roat==false then cent.x=cent.x+1 end
if btn(4)and roat==false then cent.z=cent.z-1 end
if btn(5)and roat==false then cent.z=cent.z+1 end
end
if btnp(7)and roat==false then roat=true
elseif btnp(7)and roat==true then roat=false end
roct(cord,cent,rad.x,rad.y,rad.z)
if roat==true then
if btn(0)then rad.x=rad.x+0.01 end
if btn(1)then rad.x=rad.x-0.01 end
if btn(2)then rad.y=rad.y+0.01 end
if btn(3)then rad.y=rad.y-0.01 end
if btn(4)then rad.z=rad.z+0.01 end
if btn(5)then rad.z=rad.z-0.01 end
end
for i=1,#pt do
line(card[pt[i][1]].x,card[pt[i][1]].y,
card[pt[i][2]].x,card[pt[i][2]].y,2)
end
end
Кароч, в целом, есть один такой довольно интересный способ.
Ты такой берёшь матрицу камеры, берёшь какую-нибудь объёмную фигурку и умножаешь каждую вершинку этой фигурки на матрицу.
Ты такой берёшь два компонента x-y получившихся векторов — это их положение на экране. Берёшь z-компонент — это их глубина. И вот нам есть на чём сортировать.