Skip to content

Commit fd9b355

Browse files
committed
AABB backwards pass
1 parent 76927ed commit fd9b355

3 files changed

Lines changed: 21 additions & 19 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ default = ["opengl"]
2121
[dependencies]
2222
cgmath = "0.14"
2323
collision = {path = "../collision"}
24-
froggy = "0.3"
24+
froggy = {path = "../froggy"}
2525
genmesh = "0.5"
2626
gfx = "0.16"
2727
image = "0.13"

src/lib.rs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -200,31 +200,33 @@ impl Hub {
200200
}
201201

202202
fn update_graph(&mut self) {
203-
let mut cursor = self.nodes.cursor_alive();
204-
while let Some(mut item) = cursor.next() {
203+
let mut cursor = self.nodes.cursor();
204+
// forward pass: derive visibility, scene id, and world transform
205+
// from the parent `Node`
206+
while let Some((left, mut item, _)) = cursor.next() {
205207
if !item.visible {
206208
item.world_visible = false;
207209
continue
208210
}
209-
let (visibility, affilation, transform, bounds) = match item.parent {
211+
let (visibility, affilation, transform) = match item.parent {
210212
Some(ref parent_ptr) => {
211-
let parent = item.look_back(parent_ptr).unwrap();
213+
let parent = left.get(parent_ptr).unwrap();
212214
let transform = parent.world_transform.concat(&item.transform);
213-
let bounds = if parent.world_visible {
214-
let bounds = item.bounds.transform(&transform);
215-
parent.world_bounds = parent.world_bounds.union(&bounds);
216-
bounds
217-
} else {
218-
item.bounds
219-
};
220-
(parent.world_visible, parent.scene_id, transform, bounds)
215+
(parent.world_visible, parent.scene_id, transform)
221216
},
222-
None => (true, item.scene_id, item.transform, item.bounds),
217+
None => (true, item.scene_id, item.transform),
223218
};
224219
item.world_visible = visibility;
225220
item.scene_id = affilation;
226221
item.world_transform = transform;
227-
item.world_bounds = bounds;
222+
item.world_bounds = item.bounds.transform(&transform);
223+
}
224+
// backwards pass: accumulate bounding boxes of children
225+
while let Some((mut left, item, _)) = cursor.prev() {
226+
if let (true, Some(parent_ptr)) = (item.world_visible, item.parent.as_ref()) {
227+
let bounds = &mut left.get_mut(parent_ptr).unwrap().world_bounds;
228+
*bounds = item.world_bounds.union(bounds);
229+
}
228230
}
229231
}
230232
}

src/render.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ impl Renderer {
305305
}
306306
let mut lights = Vec::new();
307307
let mut shadow_requests = Vec::new();
308-
for node in hub.nodes.iter_alive() {
308+
for node in &hub.nodes {
309309
if !node.visible || node.scene_id != Some(scene.unique_id) {
310310
continue
311311
}
@@ -377,7 +377,7 @@ impl Renderer {
377377
mx_vp: request.matrix.into(),
378378
num_lights: 0,
379379
});
380-
for node in hub.nodes.iter_alive() {
380+
for node in &hub.nodes {
381381
if !node.visible || node.scene_id != Some(scene.unique_id) {
382382
continue;
383383
}
@@ -435,7 +435,7 @@ impl Renderer {
435435
Some(ref request) => request.resource.clone(),
436436
None => shadow_default.clone(),
437437
};
438-
for node in hub.nodes.iter_alive() {
438+
for node in &hub.nodes {
439439
if !node.visible || node.scene_id != Some(scene.unique_id) {
440440
continue;
441441
}
@@ -480,7 +480,7 @@ impl Renderer {
480480

481481
// draw debug quads
482482
self.debug_quads.sync_pending();
483-
for quad in self.debug_quads.iter_alive() {
483+
for quad in &self.debug_quads {
484484
let pos = [
485485
if quad.pos[0] >= 0 {
486486
quad.pos[0]

0 commit comments

Comments
 (0)