Skip to content

Commit e235fff

Browse files
committed
AABB backwards pass
1 parent 0ddf67b commit e235fff

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
@@ -203,31 +203,33 @@ impl Hub {
203203
}
204204

205205
fn update_graph(&mut self) {
206-
let mut cursor = self.nodes.cursor_alive();
207-
while let Some(mut item) = cursor.next() {
206+
let mut cursor = self.nodes.cursor();
207+
// forward pass: derive visibility, scene id, and world transform
208+
// from the parent `Node`
209+
while let Some((left, mut item, _)) = cursor.next() {
208210
if !item.visible {
209211
item.world_visible = false;
210212
continue
211213
}
212-
let (visibility, affilation, transform, bounds) = match item.parent {
214+
let (visibility, affilation, transform) = match item.parent {
213215
Some(ref parent_ptr) => {
214-
let parent = item.look_back(parent_ptr).unwrap();
216+
let parent = left.get(parent_ptr).unwrap();
215217
let transform = parent.world_transform.concat(&item.transform);
216-
let bounds = if parent.world_visible {
217-
let bounds = item.bounds.transform(&transform);
218-
parent.world_bounds = parent.world_bounds.union(&bounds);
219-
bounds
220-
} else {
221-
item.bounds
222-
};
223-
(parent.world_visible, parent.scene_id, transform, bounds)
218+
(parent.world_visible, parent.scene_id, transform)
224219
},
225-
None => (true, item.scene_id, item.transform, item.bounds),
220+
None => (true, item.scene_id, item.transform),
226221
};
227222
item.world_visible = visibility;
228223
item.scene_id = affilation;
229224
item.world_transform = transform;
230-
item.world_bounds = bounds;
225+
item.world_bounds = item.bounds.transform(&transform);
226+
}
227+
// backwards pass: accumulate bounding boxes of children
228+
while let Some((mut left, item, _)) = cursor.prev() {
229+
if let (true, Some(parent_ptr)) = (item.world_visible, item.parent.as_ref()) {
230+
let bounds = &mut left.get_mut(parent_ptr).unwrap().world_bounds;
231+
*bounds = item.world_bounds.union(bounds);
232+
}
231233
}
232234
}
233235
}

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)