changed object to have a special position vec3, which stores how much to

move indices before rendering
This commit is contained in:
bronku 2026-02-16 13:58:39 +01:00
parent 713c5fc67b
commit 0f6b242ebf

View file

@ -4,6 +4,7 @@ use raylib::prelude::*;
#[derive(Debug, Clone)]
pub struct Object {
indices: Vec<Vec3>,
position: Vec3,
}
pub fn new_cube() -> Object {
@ -18,6 +19,7 @@ pub fn new_cube() -> Object {
Vec3(0.5, 0.5, 0.5),
Vec3(-0.5, 0.5, 0.5),
],
position: Vec3(0.0, 0.0, 0.0),
}
}
@ -30,15 +32,18 @@ fn draw_point(d: &mut RaylibDrawHandle, pos: &Vec3) {
impl Object {
pub fn draw_object(&self, d: &mut RaylibDrawHandle) {
for point in &self.indices {
draw_point(d, point)
let moved = Vec3(
point.0 + self.position.0,
point.1 + self.position.1,
point.2 + self.position.2,
);
draw_point(d, &moved);
}
}
pub fn move_by(&mut self, delta_pos: &Vec3) {
for point in &mut self.indices {
(point).0 += delta_pos.0;
(point).1 += delta_pos.1;
(point).2 += delta_pos.2;
}
(self.position).0 += delta_pos.0;
(self.position).1 += delta_pos.1;
(self.position).2 += delta_pos.2;
}
}