GFX update :D

This commit is contained in:
Astronand committed 2026-10-04 19:45:35 -04:00
1 parent 05ca0f10a2
commit c1b4ef2644
70 files changed
+1398 -5174

No files matched your search

+124
View File
@@ -0,0 +1,124 @@
local args={...}
if #args<1 then print("Usage: render3d [file.obj]") end
local fs=require("fs")
local vec=require("vector")
local gfx=syscall.devctl(1,"gfx")
local file = fs.readAllText(args[1])
local obj={v={},f={}}
local lines=string.split(file, "\n")
for i=1, #lines do
local line=lines[i]
if line:sub(1,2)=="v " then
line=line:sub(3)
local s=string.split(line, " ")
obj.v[#obj.v+1]=vec(tonumber(s[1]),tonumber(s[2]),tonumber(s[3]))
elseif line:sub(1,2)=="f " then
line=line:sub(3)
local s=string.split(line, " ")
local vs={}
for c=1, #s do
local v=string.split(s[c], "/")
vs[#vs+1]=tonumber(v[1])
end
obj.f[#obj.f+1]=vec(table.unpack(vs))
end
end
print("Vertices")
for i=1, #obj.v do
print(obj.v[i])
end
print("Faces")
for i=1, #obj.f do
print(obj.f[i])
end
local function projectPoint(point, cameraPos, cameraRot, fov, width, height)
local p=point-cameraPos
local pitch=cameraRot.x
local yaw=cameraRot.y
local cp=math.cos(pitch)
local sp=math.sin(pitch)
local cy=math.cos(yaw)
local sy=math.sin(yaw)
local right=vec(
cy,
0,
-sy
)
local up=vec(
sy*sp,
cp,
cy*sp
)
local forward=vec(
-sy*cp,
sp,
-cy*cp
)
local x=p:dot(right)
local y=p:dot(up)
local z=p:dot(forward)
if z<=0 then
return nil
end
local aspect=width/height
local f=1/math.tan(fov*0.5)
local sx=(x*f/aspect)/z
local sy=(y*f)/z
return vec(
(sx+1)*0.5*width,
(1-sy)*0.5*height
),z
end
local proj={}
local camera=vec(0,0,3)
local rot=vec(0,0,0)
local w,h=gfx.size()
local fov=math.rad(90)
for i=1, #obj.v do
proj[i]={}
proj[i].p,proj[i].z=projectPoint(obj.v[i],camera,rot,fov,w,h)
end
print("Projected")
for i=1, #proj do
print(proj[i].p)
end
gfx.setMode(true)
for i=#obj.f, 1, -1 do
local f=obj.f[i]
local c=math.random(0,0xffffff)
for p=1, #f do
if p~=#f then
print(tostring(proj[f[p]].p.x)..","..tostring(proj[f[p]].p.y).." > "..tostring(proj[f[p+1]].p.x)..","..tostring(proj[f[p+1]].p.y))
gfx.line(proj[f[p]].p.x,proj[f[p]].p.y,proj[f[p+1]].p.x,proj[f[p+1]].p.y,c)
else
print(tostring(proj[f[p]].p.x)..","..tostring(proj[f[p]].p.y).." > "..tostring(proj[f[1]].p.x)..","..tostring(proj[f[1]].p.y))
gfx.line(proj[f[p]].p.x,proj[f[p]].p.y,proj[f[1]].p.x,proj[f[1]].p.y,c)
end
end
end
while true do
sleep(5)
end
@@ -0,0 +1,40 @@
# Blender 5.2.2 LTS
# www.blender.org
mtllib box.mtl
o Cube
v 1.000000 1.000000 -1.000000
v 1.000000 -1.000000 -1.000000
v 1.000000 1.000000 1.000000
v 1.000000 -1.000000 1.000000
v -1.000000 1.000000 -1.000000
v -1.000000 -1.000000 -1.000000
v -1.000000 1.000000 1.000000
v -1.000000 -1.000000 1.000000
vn -0.0000 1.0000 -0.0000
vn -0.0000 -0.0000 1.0000
vn -1.0000 -0.0000 -0.0000
vn -0.0000 -1.0000 -0.0000
vn 1.0000 -0.0000 -0.0000
vn -0.0000 -0.0000 -1.0000
vt 0.625000 0.500000
vt 0.875000 0.500000
vt 0.875000 0.750000
vt 0.625000 0.750000
vt 0.375000 0.750000
vt 0.625000 1.000000
vt 0.375000 1.000000
vt 0.375000 0.000000
vt 0.625000 0.000000
vt 0.625000 0.250000
vt 0.375000 0.250000
vt 0.125000 0.500000
vt 0.375000 0.500000
vt 0.125000 0.750000
s 0
usemtl Material
f 1/1/1 5/2/1 7/3/1 3/4/1
f 4/5/2 3/4/2 7/6/2 8/7/2
f 8/8/3 7/9/3 5/10/3 6/11/3
f 6/12/4 2/13/4 4/5/4 8/14/4
f 2/13/5 1/1/5 3/4/5 4/5/5
f 6/11/6 5/10/6 1/1/6 2/13/6