cube
This commit is contained in:
parent
27615d4a70
commit
05d5e55118
1 changed files with 23 additions and 9 deletions
32
src/main.rs
32
src/main.rs
|
|
@ -1,3 +1,5 @@
|
||||||
|
use std::{clone, ops};
|
||||||
|
|
||||||
use raylib::prelude::*;
|
use raylib::prelude::*;
|
||||||
|
|
||||||
const WINDOW_WIDTH: i32 = 640;
|
const WINDOW_WIDTH: i32 = 640;
|
||||||
|
|
@ -14,6 +16,7 @@ impl Vec2 {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, Debug)]
|
||||||
struct Vec3(f64, f64, f64);
|
struct Vec3(f64, f64, f64);
|
||||||
|
|
||||||
impl Vec3 {
|
impl Vec3 {
|
||||||
|
|
@ -39,23 +42,34 @@ fn draw_points(d: &mut RaylibDrawHandle, points: &[Vec3]) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn move_by(points: &mut [Vec3], delta_pos: &Vec3) {
|
||||||
|
for point in points {
|
||||||
|
(*point).0 += delta_pos.0;
|
||||||
|
(*point).1 += delta_pos.1;
|
||||||
|
(*point).2 += delta_pos.2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const CUBE: [Vec3; 8] = [
|
const CUBE: [Vec3; 8] = [
|
||||||
Vec3(-0.5, -0.5, 1.0),
|
Vec3(-0.5, -0.5, -0.5),
|
||||||
Vec3(0.5, -0.5, 1.0),
|
Vec3(0.5, -0.5, -0.5),
|
||||||
Vec3(0.5, 0.5, 1.0),
|
Vec3(0.5, 0.5, -0.5),
|
||||||
Vec3(-0.5, 0.5, 1.0),
|
Vec3(-0.5, 0.5, -0.5),
|
||||||
Vec3(-0.5, -0.5, 1.5),
|
Vec3(-0.5, -0.5, 0.5),
|
||||||
Vec3(0.5, -0.5, 1.5),
|
Vec3(0.5, -0.5, 0.5),
|
||||||
Vec3(0.5, 0.5, 1.5),
|
Vec3(0.5, 0.5, 0.5),
|
||||||
Vec3(-0.5, 0.5, 1.5),
|
Vec3(-0.5, 0.5, 0.5),
|
||||||
];
|
];
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let (mut rl, thread) = raylib::init().size(WINDOW_WIDTH, WINDOW_HEIGHT).build();
|
let (mut rl, thread) = raylib::init().size(WINDOW_WIDTH, WINDOW_HEIGHT).build();
|
||||||
|
|
||||||
|
let mut c = CUBE.clone();
|
||||||
|
move_by(&mut c, &Vec3(0.0, 0.0, 2.0));
|
||||||
|
|
||||||
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_points(&mut d, &CUBE);
|
draw_points(&mut d, &c);
|
||||||
d.clear_background(Color::WHITE);
|
d.clear_background(Color::WHITE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue