gdritter repos thermidor / 44668a0
First pass at a scene graph representation Getty Ritter 7 years ago
3 changed file(s) with 32 addition(s) and 0 deletion(s). Collapse all Expand all
66 [dependencies]
77 glium = "*"
88 image = "*"
9 cgmath = "*"
910 therm_util = { path = "../therm_util" }
1 use cgmath::{Matrix4,SquareMatrix,Vector3,Vector4};
2 use model::Model;
3
4 pub enum SceneGraph {
5 Translate(f32, f32, f32, Box<SceneGraph>),
6 Model(Model),
7 Many(Vec<SceneGraph>),
8 }
9
10 impl SceneGraph {
11 pub fn traverse<F>(&self, callback: &mut F)
12 where F: FnMut(&Model, &[[f32;4];4]) -> ()
13 {
14 self.go(callback, Matrix4::identity() * 0.01);
15 }
16
17 fn go<F>(&self, callback: &mut F, mat: Matrix4<f32>)
18 where F: FnMut(&Model, &[[f32;4];4]) -> ()
19 {
20 match self {
21 &SceneGraph::Model(ref m) => callback(m, &mat.into()),
22 &SceneGraph::Many(ref graphs) => for g in graphs {
23 g.go(callback, mat);
24 },
25 &SceneGraph::Translate(x, y, z, ref rs) =>
26 rs.go(callback, mat * Matrix4::from_translation(Vector3::new(x, y, z))),
27 }
28 }
29 }
11 #[macro_use]
22 extern crate glium;
33 extern crate image;
4 extern crate cgmath;
45 extern crate therm_util;
56
67 pub mod model;
8 pub mod graph;
79
810 #[cfg(test)]
911 mod tests {