implemented primitive building

Commit 58f67b026b2c · mgecumshooter · 2026-10-24 12:51 +0300

Changeset
58f67b026b2c81f51ef6948ad28808c50110d9b3

View source at this commit

Comments

No comments yet.

Log in to comment

Diff

diff --git a/src/main.rs b/src/main.rs
--- a/src/main.rs
+++ b/src/main.rs
@@ -110,6 +110,46 @@
 	    
 	}
 	
+	if rl.is_mouse_button_pressed(MouseButton::MOUSE_BUTTON_RIGHT) {
+	    let (voxel, normal) = util::raycast(plr.get_eye_pos(), plr.get_look_dir(), 16f32, &world);
+	    match voxel {
+		Some(vox) => {
+		    let mut mx = 0f32;
+		    let mut my = 0f32;
+		    let mut mz = 0f32;
+		    match normal {
+			Some(nm) => {
+			    mx = nm.x;
+			    my = nm.y;
+			    mz = nm.z;
+			}
+			None => {}
+		    }
+		    let gx = vox.x as i32 + mx as i32;
+		    let gy = vox.y as i32 + my as i32;
+		    let gz = vox.z as i32 + mz as i32;
+
+		    let chunk_coord = (
+			gx.div_euclid(CHUNK_SIZE as i32),
+			gy.div_euclid(CHUNK_SIZE as i32),
+			gz.div_euclid(CHUNK_SIZE as i32),
+		    );
+
+		    if let Some(chunk) = world.get_mut(chunk_coord) {
+			let local_x = gx.rem_euclid(CHUNK_SIZE as i32) as usize;
+			let local_y = gy.rem_euclid(CHUNK_SIZE as i32) as usize;
+			let local_z = gz.rem_euclid(CHUNK_SIZE as i32) as usize;
+
+			let idx = chunk.voxel_idx(local_x, local_y, local_z);
+			chunk.voxels[idx] = Voxel::from_kind(VoxelKind::Stone);
+			chunk.dirty = true; // иначе меш не перестроится
+		    }
+		}
+		None => {}
+	    }
+	    
+	}
+	
         if rend_tex.width() != rl.get_render_width() || rend_tex.height() != rl.get_render_height()
         {
             unsafe { rlb::ffi::rlUnloadTexture(normal_tex_id) };