Browse Source

Switched to using references for models

Getty Ritter 7 years ago
parent
commit
526efa1494
1 changed files with 9 additions and 7 deletions
  1. 9 7
      therm_model/src/graph.rs

+ 9 - 7
therm_model/src/graph.rs

@@ -1,13 +1,15 @@
-use cgmath::{Matrix4,SquareMatrix,Vector3,Vector4};
+use cgmath::{Matrix4,SquareMatrix,Vector3};
 use model::Model;
 
-pub enum SceneGraph {
-    Translate(f32, f32, f32, Box<SceneGraph>),
-    Model(Model),
-    Many(Vec<SceneGraph>),
+pub enum SceneGraph<'a> {
+    Translate(f32, f32, f32, Box<SceneGraph<'a>>),
+    Model(&'a Model),
+    Many(Vec<SceneGraph<'a>>),
 }
 
-impl SceneGraph {
+impl<'a> SceneGraph<'a> {
+    /// Call the supplied callback on every element of a scene graph
+    /// along with its calculated transform matrix
     pub fn traverse<F>(&self, callback: &mut F)
         where F: FnMut(&Model, &[[f32;4];4]) -> ()
     {
@@ -15,7 +17,7 @@ impl SceneGraph {
     }
 
     fn go<F>(&self, callback: &mut F, mat: Matrix4<f32>)
-        where F: FnMut(&Model, &[[f32;4];4]) -> ()
+        where F: FnMut(&'a Model, &[[f32;4];4]) -> ()
     {
         match self {
             &SceneGraph::Model(ref m) => callback(m, &mat.into()),