This commit is contained in:
bronku 2026-02-15 23:24:49 +01:00
parent e85fee46eb
commit 842f0d1f22

View file

@ -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; const POINT_SIZE: i32 = 3;
let (window_x, window_y) = pos.to_screen_space(); let (window_x, window_y) = pos.to_screen_space();
d.draw_rectangle(window_x, window_y, POINT_SIZE, POINT_SIZE, Color::RED); d.draw_rectangle(window_x, window_y, POINT_SIZE, POINT_SIZE, Color::RED);
@ -29,10 +44,38 @@ fn main() {
while !rl.window_should_close() { while !rl.window_should_close() {
let mut d = rl.begin_drawing(&thread); let mut d = rl.begin_drawing(&thread);
draw_point(&mut d, Vec2 { x: -0.5, y: -0.5 }); draw_point(
draw_point(&mut d, Vec2 { x: 0.5, y: -0.5 }); &mut d,
draw_point(&mut d, Vec2 { x: 0.5, y: 0.5 }); Vec3 {
draw_point(&mut d, Vec2 { x: -0.5, y: 0.5 }); 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); d.clear_background(Color::WHITE);
} }