barbs example: end recursion by scale check, not iteration count
This commit is contained in:
parent
004f665e4b
commit
2017d9a605
@ -97,9 +97,15 @@ impl BarbsCtxt {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn depth_check(&self, xform: &Transform, iters: usize) -> bool {
|
||||||
|
// Assume all scales are the same (for now)
|
||||||
|
let (s, _, _) = xform.get_scale();
|
||||||
|
return s < 0.005;
|
||||||
|
}
|
||||||
|
|
||||||
pub fn barb(&mut self, iters: usize, xform: Transform, bound: [usize; 4]) {
|
pub fn barb(&mut self, iters: usize, xform: Transform, bound: [usize; 4]) {
|
||||||
|
|
||||||
if iters <= 0 {
|
if self.depth_check(&xform, iters) {
|
||||||
self.faces.extend_from_slice(&[
|
self.faces.extend_from_slice(&[
|
||||||
bound[0], bound[2], bound[1],
|
bound[0], bound[2], bound[1],
|
||||||
bound[0], bound[3], bound[2],
|
bound[0], bound[3], bound[2],
|
||||||
@ -118,7 +124,7 @@ impl BarbsCtxt {
|
|||||||
|
|
||||||
pub fn main(&mut self, iters: usize, xform: Transform, bound: [usize; 4]) {
|
pub fn main(&mut self, iters: usize, xform: Transform, bound: [usize; 4]) {
|
||||||
|
|
||||||
if iters <= 0 {
|
if self.depth_check(&xform, iters) {
|
||||||
self.faces.extend_from_slice(&[
|
self.faces.extend_from_slice(&[
|
||||||
bound[0], bound[2], bound[1],
|
bound[0], bound[2], bound[1],
|
||||||
bound[0], bound[3], bound[2],
|
bound[0], bound[3], bound[2],
|
||||||
|
|||||||
@ -48,6 +48,13 @@ impl Transform {
|
|||||||
pub fn transform(&self, verts: &Vec<Vertex>) -> Vec<Vertex> {
|
pub fn transform(&self, verts: &Vec<Vertex>) -> Vec<Vertex> {
|
||||||
verts.iter().map(|v| self.mtx * v).collect()
|
verts.iter().map(|v| self.mtx * v).collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns X, Y, and Z scale factors for this transformation.
|
||||||
|
pub fn get_scale(&self) -> (f32, f32, f32) {
|
||||||
|
(self.mtx.column(0).norm(),
|
||||||
|
self.mtx.column(1).norm(),
|
||||||
|
self.mtx.column(2).norm())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Mul for Transform {
|
impl Mul for Transform {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user