First pass at a scene graph representation
Getty Ritter
8 years ago
6 | 6 |
[dependencies]
|
7 | 7 |
glium = "*"
|
8 | 8 |
image = "*"
|
| 9 |
cgmath = "*"
|
9 | 10 |
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 |
}
|
1 | 1 |
#[macro_use]
|
2 | 2 |
extern crate glium;
|
3 | 3 |
extern crate image;
|
| 4 |
extern crate cgmath;
|
4 | 5 |
extern crate therm_util;
|
5 | 6 |
|
6 | 7 |
pub mod model;
|
| 8 |
pub mod graph;
|
7 | 9 |
|
8 | 10 |
#[cfg(test)]
|
9 | 11 |
mod tests {
|