BLOK DISTROJ
This commit is contained in:
@@ -8,6 +8,7 @@ const vm = @import("vecmath");
|
||||
|
||||
const Blocks = @import("assets/Blocks.zig");
|
||||
const Chunks = @import("Chunks.zig");
|
||||
const Game = @import("Game.zig");
|
||||
const Iterator2 = math.Iterator2;
|
||||
|
||||
const AxisState = enum {
|
||||
@@ -175,6 +176,7 @@ mouse_sensitivity: f32 = 0.0003,
|
||||
vertical_fov_deg: f32 = 80,
|
||||
|
||||
movement_state: MovementState,
|
||||
maybe_raycast_hit: ?Chunks.RaycastHit = null,
|
||||
|
||||
pub const camera_height_vx = 1.62;
|
||||
|
||||
@@ -225,19 +227,38 @@ pub fn onMouseMove(self: *Player, dx: f32, dy: f32) void {
|
||||
self.yaw_turns = @mod(self.yaw_turns - dx * self.mouse_sensitivity, 1);
|
||||
}
|
||||
|
||||
pub fn onMouseDown(self: *Player, button: glfw.MouseButton, game: *Game) void {
|
||||
if (self.maybe_raycast_hit) |raycast_hit| {
|
||||
switch (button) {
|
||||
.left => {
|
||||
game.chunks.destroyVoxelAt(
|
||||
raycast_hit.voxel,
|
||||
game.engine,
|
||||
&game.blocks,
|
||||
game.allocator,
|
||||
) catch |err| {
|
||||
std.log.err("Error while destroying voxel {f}: {}", .{ raycast_hit.voxel, err });
|
||||
};
|
||||
},
|
||||
else => {},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn update(self: *Player, dt: f32, chunks: *const Chunks) void {
|
||||
defer self.resetAllButtons();
|
||||
|
||||
//const raycast_origin_sv = self.position_sv
|
||||
// .add(.init(0, 0, @intFromFloat(@round(c.sv_per_vx * camera_height_vx))));
|
||||
//const raycast_ray_sv = vm.Vector3
|
||||
// .init(0, raycast_length_sv, 0)
|
||||
// .rotate(.mulQuaternion(
|
||||
// .initRotation(.XY, self.yaw_turns),
|
||||
// .initRotation(.YZ, self.pitch_turns),
|
||||
// ))
|
||||
// .asVector3Int();
|
||||
//const raycast_hit = chunks.raycast(raycast_origin_sv, raycast_ray_sv);
|
||||
const raycast_origin_sv = self.position_sv
|
||||
.add(.init(0, 0, @intFromFloat(@round(c.sv_per_vx * camera_height_vx))));
|
||||
const raycast_ray_sv = vm.Vector3
|
||||
.init(0, raycast_length_sv, 0)
|
||||
.rotate(.mulQuaternion(
|
||||
.initRotation(.XY, self.yaw_turns),
|
||||
.initRotation(.YZ, self.pitch_turns),
|
||||
))
|
||||
.round()
|
||||
.asInt();
|
||||
self.maybe_raycast_hit = chunks.raycast(raycast_origin_sv, raycast_ray_sv);
|
||||
|
||||
// --- GATHER INPUTS -------------------------------------------------------
|
||||
|
||||
|
||||
Reference in New Issue
Block a user