Fixed face culling

This commit is contained in:
Lorenzo Torres 2025-08-06 15:50:05 +02:00
parent 8a56f94b7f
commit fb031e8a66
4 changed files with 7 additions and 11 deletions

View file

@ -63,16 +63,12 @@ pub const Matrix = struct {
pub fn perspective(fov: f32, aspect: f32, near: f32, far: f32) Matrix { pub fn perspective(fov: f32, aspect: f32, near: f32, far: f32) Matrix {
const focal_length = 1.0 / tan(fov / 2.0); const focal_length = 1.0 / tan(fov / 2.0);
const x = focal_length / aspect;
const y = -focal_length;
const a = near / (far - near);
const b = far * a;
const projection = [4][4]f32{ const projection = [4][4]f32{
[4]f32{ x, 0.0, 0.0, 0.0 }, [4]f32{ focal_length / aspect, 0.0, 0.0, 0.0 },
[4]f32{ 0.0, y, 0.0, 0.0 }, [4]f32{ 0.0, -focal_length, 0.0, 0.0 },
[4]f32{ 0.0, 0.0, a, b }, [4]f32{ 0.0, 0.0, far / (far - near), 1.0 },
[4]f32{ 0.0, 0.0, 1.0, 0.0 }, [4]f32{ 0.0, 0.0, -(far * near) / (far - near), 0.0 },
}; };
return .{ return .{

View file

@ -18,7 +18,7 @@ up: @Vector(3, f32) = .{ 0.0, 1.0, 0.0 },
speed: f32 = 2.5, speed: f32 = 2.5,
pub fn getProjection(width: usize, height: usize) math.Matrix { pub fn getProjection(width: usize, height: usize) math.Matrix {
return math.Matrix.perspective(math.rad(40.0), (@as(f32, @floatFromInt(width)) / @as(f32, @floatFromInt(height))), 0.1, 100.0); return math.Matrix.perspective(math.rad(45.0), (@as(f32, @floatFromInt(width)) / @as(f32, @floatFromInt(height))), 0.1, 100.0);
} }
pub fn getView(self: Camera) math.Matrix { pub fn getView(self: Camera) math.Matrix {

View file

@ -313,7 +313,7 @@ pub fn GraphicsPipeline(comptime n: usize) type {
.polygonMode = c.VK_POLYGON_MODE_FILL, .polygonMode = c.VK_POLYGON_MODE_FILL,
.lineWidth = 1.0, .lineWidth = 1.0,
.cullMode = c.VK_CULL_MODE_BACK_BIT, .cullMode = c.VK_CULL_MODE_BACK_BIT,
.frontFace = c.VK_FRONT_FACE_COUNTER_CLOCKWISE, .frontFace = c.VK_FRONT_FACE_CLOCKWISE,
.depthBiasEnable = c.VK_FALSE, .depthBiasEnable = c.VK_FALSE,
}; };

View file

@ -45,7 +45,7 @@ fn init_mods() void {
export fn sideros_init(init: api.GameInit) callconv(.c) void { export fn sideros_init(init: api.GameInit) callconv(.c) void {
pool = ecs.Pool.init(allocator, .{ pool = ecs.Pool.init(allocator, .{
.camera = .{ .camera = .{
.position = .{ 0.0, 0.0, 40.0 }, .position = .{ 0.0, 0.0, 5.0 },
.target = .{ 0.0, 0.0, 0.0 }, .target = .{ 0.0, 0.0, 0.0 },
}, },
.renderer = undefined, .renderer = undefined,