Update main.rs
This commit is contained in:
parent
6f550065bd
commit
e85fee46eb
1 changed files with 8 additions and 6 deletions
10
src/main.rs
10
src/main.rs
|
|
@ -8,16 +8,18 @@ struct Vec2 {
|
||||||
y: f32,
|
y: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn convert_coordinates(pos: Vec2) -> (i32, i32) {
|
impl Vec2 {
|
||||||
|
fn to_screen_space(self) -> (i32, i32) {
|
||||||
return (
|
return (
|
||||||
((WINDOW_WIDTH as f32) * ((pos.x + 1.0) / 2.0)) as i32,
|
((WINDOW_WIDTH as f32) * ((self.x + 1.0) / 2.0)) as i32,
|
||||||
((WINDOW_HEIGHT as f32) * ((pos.y + 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) {
|
fn draw_point(d: &mut RaylibDrawHandle, pos: Vec2) {
|
||||||
const POINT_SIZE: i32 = 3;
|
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);
|
d.draw_rectangle(window_x, window_y, POINT_SIZE, POINT_SIZE, Color::RED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue