|
@@ -1,13 +1,15 @@
|
|
-use cgmath::{Matrix4,SquareMatrix,Vector3,Vector4};
|
|
|
|
|
|
+use cgmath::{Matrix4,SquareMatrix,Vector3};
|
|
use model::Model;
|
|
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)
|
|
pub fn traverse<F>(&self, callback: &mut F)
|
|
where F: FnMut(&Model, &[[f32;4];4]) -> ()
|
|
where F: FnMut(&Model, &[[f32;4];4]) -> ()
|
|
{
|
|
{
|
|
@@ -15,7 +17,7 @@ impl SceneGraph {
|
|
}
|
|
}
|
|
|
|
|
|
fn go<F>(&self, callback: &mut F, mat: Matrix4<f32>)
|
|
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 {
|
|
match self {
|
|
&SceneGraph::Model(ref m) => callback(m, &mat.into()),
|
|
&SceneGraph::Model(ref m) => callback(m, &mat.into()),
|