|
@@ -0,0 +1,29 @@
|
|
|
+use cgmath::{Matrix4,SquareMatrix,Vector3,Vector4};
|
|
|
+use model::Model;
|
|
|
+
|
|
|
+pub enum SceneGraph {
|
|
|
+ Translate(f32, f32, f32, Box<SceneGraph>),
|
|
|
+ Model(Model),
|
|
|
+ Many(Vec<SceneGraph>),
|
|
|
+}
|
|
|
+
|
|
|
+impl SceneGraph {
|
|
|
+ pub fn traverse<F>(&self, callback: &mut F)
|
|
|
+ where F: FnMut(&Model, &[[f32;4];4]) -> ()
|
|
|
+ {
|
|
|
+ self.go(callback, Matrix4::identity() * 0.01);
|
|
|
+ }
|
|
|
+
|
|
|
+ fn go<F>(&self, callback: &mut F, mat: Matrix4<f32>)
|
|
|
+ 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))),
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|