alex/beta-minecraft-rust
Minecraft Beta 1.7.3 Rewrite
BRANCH main
SNAPSHOT Draw terrain GPU-driven from packed per-section buffers with GPU occlusion culling, add a render distance slider (2-128) with a quad/disk shape, cut chunk bookkeeping at high render distances, and fix a light underflow at y=0
DOWNLOAD
root crates common src interaction.rs
use glam::DVec3;
use crate::math::{cos, sin};
pub const REACH: f64 = 4.0;
pub const OFFSETS: [[i32; 3]; 6] = [
[0, -1, 0],
[0, 1, 0],
[0, 0, -1],
[0, 0, 1],
[-1, 0, 0],
[1, 0, 0],
];
pub fn adjacent([x, y, z]: [i32; 3], side: u8) -> Option<[i32; 3]> {
let &[dx, dy, dz] = OFFSETS.get(usize::from(side))?;
Some([x.checked_add(dx)?, y.checked_add(dy)?, z.checked_add(dz)?])
}
pub fn look(yaw: f32, pitch: f32) -> DVec3 {
let yaw = -yaw * std::f32::consts::PI / 180.0 - std::f32::consts::PI;
let pitch = -pitch * std::f32::consts::PI / 180.0;
let horizontal = -cos(pitch);
DVec3::new(
f64::from(sin(yaw) * horizontal),
f64::from(sin(pitch)),
f64::from(cos(yaw) * horizontal),
)
}