vec2
This commit is contained in:
parent
91bcc8884f
commit
6f550065bd
1 changed files with 14 additions and 9 deletions
23
src/main.rs
23
src/main.rs
|
|
@ -3,16 +3,21 @@ use raylib::prelude::*;
|
||||||
const WINDOW_WIDTH: i32 = 640;
|
const WINDOW_WIDTH: i32 = 640;
|
||||||
const WINDOW_HEIGHT: i32 = 480;
|
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 (
|
return (
|
||||||
((WINDOW_WIDTH as f32) * ((pos_x + 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,
|
((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;
|
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);
|
d.draw_rectangle(window_x, window_y, POINT_SIZE, POINT_SIZE, Color::RED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -22,10 +27,10 @@ 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, -0.5, -0.5);
|
draw_point(&mut d, Vec2 { x: -0.5, y: -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, 0.5, 0.5);
|
draw_point(&mut d, Vec2 { x: 0.5, y: 0.5 });
|
||||||
draw_point(&mut d, -0.5, 0.5);
|
draw_point(&mut d, Vec2 { x: -0.5, y: 0.5 });
|
||||||
|
|
||||||
d.clear_background(Color::WHITE);
|
d.clear_background(Color::WHITE);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue