Cleaned up rendering module
This commit is contained in:
parent
473c4aeffb
commit
b1d092b6e3
10 changed files with 21 additions and 16 deletions
43
src/rendering/Camera.zig
Normal file
43
src/rendering/Camera.zig
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
const std = @import("std");
|
||||
const ecs = @import("ecs");
|
||||
const math = @import("math");
|
||||
|
||||
const Camera = @This();
|
||||
const UP = @Vector(3, f32){ 0.0, 1.0, 0.0 };
|
||||
|
||||
pub const Uniform = struct {
|
||||
proj: math.Matrix,
|
||||
view: math.Matrix,
|
||||
model: math.Matrix,
|
||||
};
|
||||
|
||||
position: @Vector(3, f32),
|
||||
target: @Vector(3, f32) = .{ 0.0, 0.0, 0.0 },
|
||||
front: @Vector(3, f32) = .{ 0.0, 0.0, 1.0 },
|
||||
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(45.0), (@as(f32, @floatFromInt(width)) / @as(f32, @floatFromInt(height))), 0.1, 100.0);
|
||||
}
|
||||
|
||||
pub fn getView(self: Camera) math.Matrix {
|
||||
return math.Matrix.lookAt(self.position, self.target, self.up);
|
||||
}
|
||||
|
||||
pub fn moveCamera(pool: *ecs.Pool) void {
|
||||
const input = pool.resources.input;
|
||||
const camera = pool.resources.camera;
|
||||
if (input.isKeyDown(.w)) {
|
||||
camera.position += (camera.front * (camera.speed * pool.resources.delta_time));
|
||||
}
|
||||
if (input.isKeyDown(.s)) {
|
||||
camera.position -= (camera.front * (camera.speed * pool.resources.delta_time));
|
||||
}
|
||||
if (input.isKeyDown(.a)) {
|
||||
camera.position -= math.normalize(math.cross(camera.front, camera.up)) * (camera.speed * pool.resources.delta_time);
|
||||
}
|
||||
if (input.isKeyDown(.d)) {
|
||||
camera.position += math.normalize(math.cross(camera.front, camera.up)) * (camera.speed * pool.resources.delta_time);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue