Update main.rs

This commit is contained in:
bronku 2026-02-15 23:08:21 +01:00
parent 6f550065bd
commit e85fee46eb

View file

@ -8,16 +8,18 @@ struct Vec2 {
y: f32,
}
fn convert_coordinates(pos: Vec2) -> (i32, i32) {
impl Vec2 {
fn to_screen_space(self) -> (i32, i32) {
return (
((WINDOW_WIDTH as f32) * ((pos.x + 1.0) / 2.0)) as i32,
((WINDOW_HEIGHT as f32) * ((pos.y + 1.0) / 2.0)) as i32,
((WINDOW_WIDTH as f32) * ((self.x + 1.0) / 2.0)) as i32,
((WINDOW_HEIGHT as f32) * ((self.y + 1.0) / 2.0)) as i32,
);
}
}
fn draw_point(d: &mut RaylibDrawHandle, pos: Vec2) {
const POINT_SIZE: i32 = 3;
let (window_x, window_y) = convert_coordinates(pos);
let (window_x, window_y) = pos.to_screen_space();
d.draw_rectangle(window_x, window_y, POINT_SIZE, POINT_SIZE, Color::RED);
}