Added cursor input management
This commit is contained in:
parent
4a43e564d7
commit
fd7973173f
3 changed files with 63 additions and 2 deletions
|
|
@ -15,7 +15,31 @@ position: @Vector(3, f32),
|
|||
target: @Vector(3, f32),
|
||||
direction: @Vector(3, f32),
|
||||
right: @Vector(3, f32),
|
||||
front: @Vector(3, f32),
|
||||
up: @Vector(3, f32),
|
||||
speed: f32 = 2.5,
|
||||
|
||||
fn input(pool: *ecs.Pool) void {
|
||||
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, 10.0);
|
||||
}
|
||||
|
||||
fn getView(self: Camera) math.Matrix {
|
||||
math.lookAt(self.position, self.position + self.front, self.up);
|
||||
}
|
||||
|
||||
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