From 842f0d1f22cb8516702da8768d984fae74cc613d Mon Sep 17 00:00:00 2001 From: bronku Date: Sun, 15 Feb 2026 23:24:49 +0100 Subject: [PATCH] vec3 --- src/main.rs | 53 ++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 48 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index 3a5d68d..b646e01 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,8 +16,23 @@ impl Vec2 { ); } } +struct Vec3 { + x: f32, + y: f32, + z: f32, +} +impl Vec3 { + fn to_screen_space(self) -> (i32, i32) { + const FOCAL_LENGTH: f32 = 1.0; + let camera_pos = Vec2 { + x: FOCAL_LENGTH * self.x / self.z, + y: FOCAL_LENGTH * self.y / self.z, + }; + return camera_pos.to_screen_space(); + } +} -fn draw_point(d: &mut RaylibDrawHandle, pos: Vec2) { +fn draw_point(d: &mut RaylibDrawHandle, pos: Vec3) { const POINT_SIZE: i32 = 3; let (window_x, window_y) = pos.to_screen_space(); d.draw_rectangle(window_x, window_y, POINT_SIZE, POINT_SIZE, Color::RED); @@ -29,10 +44,38 @@ fn main() { while !rl.window_should_close() { let mut d = rl.begin_drawing(&thread); - draw_point(&mut d, Vec2 { x: -0.5, y: -0.5 }); - draw_point(&mut d, Vec2 { x: 0.5, y: -0.5 }); - draw_point(&mut d, Vec2 { x: 0.5, y: 0.5 }); - draw_point(&mut d, Vec2 { x: -0.5, y: 0.5 }); + draw_point( + &mut d, + Vec3 { + x: -0.5, + y: -0.5, + z: 1.0, + }, + ); + draw_point( + &mut d, + Vec3 { + x: 0.5, + y: -0.5, + z: 1.0, + }, + ); + draw_point( + &mut d, + Vec3 { + x: 0.5, + y: 0.5, + z: 1.0, + }, + ); + draw_point( + &mut d, + Vec3 { + x: -0.5, + y: 0.5, + z: 1.0, + }, + ); d.clear_background(Color::WHITE); }