use cgmath::{Matrix4,SquareMatrix,Vector3,Vector4}; use model::Model; pub enum SceneGraph { Translate(f32, f32, f32, Box), Model(Model), Many(Vec), } impl SceneGraph { pub fn traverse(&self, callback: &mut F) where F: FnMut(&Model, &[[f32;4];4]) -> () { self.go(callback, Matrix4::identity() * 0.01); } fn go(&self, callback: &mut F, mat: Matrix4) where F: FnMut(&Model, &[[f32;4];4]) -> () { match self { &SceneGraph::Model(ref m) => callback(m, &mat.into()), &SceneGraph::Many(ref graphs) => for g in graphs { g.go(callback, mat); }, &SceneGraph::Translate(x, y, z, ref rs) => rs.go(callback, mat * Matrix4::from_translation(Vector3::new(x, y, z))), } } }