vec3
This commit is contained in:
parent
e85fee46eb
commit
842f0d1f22
1 changed files with 48 additions and 5 deletions
53
src/main.rs
53
src/main.rs
|
|
@ -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;
|
||||
let (window_x, window_y) = pos.to_screen_space();
|
||||
d.draw_rectangle(window_x, window_y, POINT_SIZE, POINT_SIZE, Color::RED);
|
||||
|
|
@ -29,10 +44,38 @@ fn main() {
|
|||
while !rl.window_should_close() {
|
||||
let mut d = rl.begin_drawing(&thread);
|
||||
|
||||
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 });
|
||||
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,
|
||||
},
|
||||
);
|
||||
draw_point(
|
||||
&mut d,
|
||||
Vec3 {
|
||||
x: -0.5,
|
||||
y: 0.5,
|
||||
z: 1.0,
|
||||
},
|
||||
);
|
||||
|
||||
d.clear_background(Color::WHITE);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue