forked from vv/efemra
1
0
Fork 0
efemra/src/rendering/Camera.zig

33 lines
826 B
Zig

const std = @import("std");
const Vec4f = @import("../math/vec.zig").Vec4f;
const Mat4f = @import("../math/mat.zig").Mat4f;
const Quat = @import("../math/quat.zig").Quat;
const Self = @This();
var s_camera: Self = std.mem.zeroes(Self);
position: Vec4f,
rotation: Quat,
z_near: f32,
z_far: f32,
fov_y: f32,
pub fn get() Self {
return s_camera;
}
pub inline fn getProj(self: *const Self, aspect: f32) Mat4f {
return Mat4f.vkPerspective(std.math.degreesToRadians(f32, self.fov_y), aspect, self.z_near, self.z_far);
}
pub inline fn getView(self: *const Self) Mat4f {
const pos = self.position;
const rot = self.rotation;
return Mat4f.lookAt(pos, pos.add(rot.fwd()), rot.up());
}
pub inline fn getWorldToClip(self: *const Self, aspect: f32) Mat4f {
return self.getProj(aspect).mul(self.getView());
}