changed object to have a special position vec3, which stores how much to
move indices before rendering
This commit is contained in:
parent
713c5fc67b
commit
0f6b242ebf
1 changed files with 11 additions and 6 deletions
|
|
@ -4,6 +4,7 @@ use raylib::prelude::*;
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Object {
|
pub struct Object {
|
||||||
indices: Vec<Vec3>,
|
indices: Vec<Vec3>,
|
||||||
|
position: Vec3,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_cube() -> Object {
|
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),
|
||||||
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 {
|
impl Object {
|
||||||
pub fn draw_object(&self, d: &mut RaylibDrawHandle) {
|
pub fn draw_object(&self, d: &mut RaylibDrawHandle) {
|
||||||
for point in &self.indices {
|
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) {
|
pub fn move_by(&mut self, delta_pos: &Vec3) {
|
||||||
for point in &mut self.indices {
|
(self.position).0 += delta_pos.0;
|
||||||
(point).0 += delta_pos.0;
|
(self.position).1 += delta_pos.1;
|
||||||
(point).1 += delta_pos.1;
|
(self.position).2 += delta_pos.2;
|
||||||
(point).2 += delta_pos.2;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue