Fixed face culling
This commit is contained in:
parent
8a56f94b7f
commit
fb031e8a66
4 changed files with 7 additions and 11 deletions
12
src/math.zig
12
src/math.zig
|
|
@ -63,16 +63,12 @@ pub const Matrix = struct {
|
|||
|
||||
pub fn perspective(fov: f32, aspect: f32, near: f32, far: f32) Matrix {
|
||||
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{
|
||||
[4]f32{ x, 0.0, 0.0, 0.0 },
|
||||
[4]f32{ 0.0, y, 0.0, 0.0 },
|
||||
[4]f32{ 0.0, 0.0, a, b },
|
||||
[4]f32{ 0.0, 0.0, 1.0, 0.0 },
|
||||
[4]f32{ focal_length / aspect, 0.0, 0.0, 0.0 },
|
||||
[4]f32{ 0.0, -focal_length, 0.0, 0.0 },
|
||||
[4]f32{ 0.0, 0.0, far / (far - near), 1.0 },
|
||||
[4]f32{ 0.0, 0.0, -(far * near) / (far - near), 0.0 },
|
||||
};
|
||||
|
||||
return .{
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ up: @Vector(3, f32) = .{ 0.0, 1.0, 0.0 },
|
|||
speed: f32 = 2.5,
|
||||
|
||||
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 {
|
||||
|
|
|
|||
|
|
@ -313,7 +313,7 @@ pub fn GraphicsPipeline(comptime n: usize) type {
|
|||
.polygonMode = c.VK_POLYGON_MODE_FILL,
|
||||
.lineWidth = 1.0,
|
||||
.cullMode = c.VK_CULL_MODE_BACK_BIT,
|
||||
.frontFace = c.VK_FRONT_FACE_COUNTER_CLOCKWISE,
|
||||
.frontFace = c.VK_FRONT_FACE_CLOCKWISE,
|
||||
.depthBiasEnable = c.VK_FALSE,
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ fn init_mods() void {
|
|||
export fn sideros_init(init: api.GameInit) callconv(.c) void {
|
||||
pool = ecs.Pool.init(allocator, .{
|
||||
.camera = .{
|
||||
.position = .{ 0.0, 0.0, 40.0 },
|
||||
.position = .{ 0.0, 0.0, 5.0 },
|
||||
.target = .{ 0.0, 0.0, 0.0 },
|
||||
},
|
||||
.renderer = undefined,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue