psychopath/src/transform_stack.rs
Nathan Vegdahl caed4c67de Do depth-first instead of breadth-first ray tracing.
This simplifies a lot of code, and will make experimenting with
other things a lot more straightforward.
2022-08-01 15:26:38 -07:00

31 lines
622 B
Rust

use crate::math::Xform;
pub struct TransformStack {
stack: Vec<Xform>,
}
impl TransformStack {
pub fn new() -> TransformStack {
TransformStack { stack: Vec::new() }
}
pub fn clear(&mut self) {
self.stack.clear();
}
pub fn push(&mut self, xform: Xform) {
match self.stack.last() {
None => self.stack.push(xform),
Some(prev_xform) => self.stack.push(xform.compose(prev_xform)),
}
}
pub fn pop(&mut self) -> Option<Xform> {
self.stack.pop()
}
pub fn top(&self) -> Option<&Xform> {
self.stack.last()
}
}