From 0f6b242ebfb6bd193d82a53090fe3aba2e58769c Mon Sep 17 00:00:00 2001 From: bronku Date: Mon, 16 Feb 2026 13:58:39 +0100 Subject: [PATCH] changed object to have a special position vec3, which stores how much to move indices before rendering --- src/object.rs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/object.rs b/src/object.rs index 99bbaf9..c4d98ef 100644 --- a/src/object.rs +++ b/src/object.rs @@ -4,6 +4,7 @@ use raylib::prelude::*; #[derive(Debug, Clone)] pub struct Object { indices: Vec, + 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; } }