From 6f550065bd54fa5162a5a243af0b95697a532de6 Mon Sep 17 00:00:00 2001 From: bronku Date: Sun, 15 Feb 2026 23:06:29 +0100 Subject: [PATCH] vec2 --- src/main.rs | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/main.rs b/src/main.rs index 46d5a29..94dfd75 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,16 +3,21 @@ use raylib::prelude::*; const WINDOW_WIDTH: i32 = 640; const WINDOW_HEIGHT: i32 = 480; -fn convert_coordinates(pos_x: f32, pos_y: f32) -> (i32, i32) { +struct Vec2 { + x: f32, + y: f32, +} + +fn convert_coordinates(pos: Vec2) -> (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) * ((pos.x + 1.0) / 2.0)) as i32, + ((WINDOW_HEIGHT as f32) * ((pos.y + 1.0) / 2.0)) as i32, ); } -fn draw_point(d: &mut RaylibDrawHandle, pos_x: f32, pos_y: f32) { +fn draw_point(d: &mut RaylibDrawHandle, pos: Vec2) { const POINT_SIZE: i32 = 3; - let (window_x, window_y) = convert_coordinates(pos_x, pos_y); + let (window_x, window_y) = convert_coordinates(pos); d.draw_rectangle(window_x, window_y, POINT_SIZE, POINT_SIZE, Color::RED); } @@ -22,10 +27,10 @@ fn main() { while !rl.window_should_close() { let mut d = rl.begin_drawing(&thread); - draw_point(&mut d, -0.5, -0.5); - draw_point(&mut d, 0.5, -0.5); - draw_point(&mut d, 0.5, 0.5); - draw_point(&mut d, -0.5, 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, Vec2 { x: -0.5, y: 0.5 }); d.clear_background(Color::WHITE); }