diff --git a/src/gameobject.rs b/src/gameobject.rs index 9fe6477..890cc16 100644 --- a/src/gameobject.rs +++ b/src/gameobject.rs @@ -19,10 +19,10 @@ pub trait Childbearing { // TODO remove this impl Node { pub fn find_node(&mut self, name: &str) -> Option { - match self.children.iter().find(|node| node.borrow().name == name) { - Some(node) => Some(Rc::clone(node)), - None => None - } + self.children + .iter() + .find(|node| node.borrow().name == name) + .map(|node| Rc::clone(node)) } } @@ -30,7 +30,7 @@ macro_rules! impl_childbearing { ($t:ty, $e:path) => { impl Childbearing<$t> for Node { fn add_child(&mut self, name: &str, child: $t) { - self.children.push(Rc::new(RefCell::new(Node::new(name.to_string(), $e(child))))); + self.children.push(Rc::new(RefCell::new(Node::new(name.to_string(), $e(Box::new(child)))))); } } } @@ -50,8 +50,8 @@ impl Node { pub enum GameObject { Null, - Camera(Camera), - Mesh(Mesh), + Camera(Box), + Mesh(Box), } impl GameObject { diff --git a/src/main.rs b/src/main.rs index 2da4b1e..c702c46 100644 --- a/src/main.rs +++ b/src/main.rs @@ -93,19 +93,7 @@ fn main() { GameObject::Mesh(mesh) => mesh, _ => panic!("cube is not a mesh"), }; - let mut transform = cube.get_transform(); - if device_manager.is_pressed(&device::Key::W) { - transform.position.z += 1.0 * delta; - } else if device_manager.is_pressed(&device::Key::S) { - transform.position.z -= 1.0 * delta; - } - if device_manager.is_pressed(&device::Key::A) { - transform.rotation.x += 1.0 * delta; - } else if device_manager.is_pressed(&device::Key::D) { - transform.rotation.x -= 1.0 * delta; - } - - cube.set_transform(transform); + // TODO, do this over the whole scene tree let mvp = glm::perspective::(4.0/3.0, 45.0_f32.to_radians(), 0.2, 100.0); let mvp = glm::translate::(&mvp, &cube.get_transform().position); let mvp = glm::rotate_x(&mvp, cube.get_transform().rotation.x);