From f7820139471178fd273c7698eba17cb4ee0cf00d Mon Sep 17 00:00:00 2001 From: rezural Date: Thu, 31 Dec 2020 13:24:29 +1100 Subject: make examples compile, code that accessed window & graphics via the callback is currently disabled, until that is added back in --- examples2d/sensor2.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'examples2d/sensor2.rs') diff --git a/examples2d/sensor2.rs b/examples2d/sensor2.rs index 959ecbf..c9edea0 100644 --- a/examples2d/sensor2.rs +++ b/examples2d/sensor2.rs @@ -69,7 +69,7 @@ pub fn init_world(testbed: &mut Testbed) { testbed.set_body_color(sensor_handle, Point3::new(0.5, 1.0, 1.0)); // Callback that will be executed on the main loop to handle proximities. - testbed.add_callback(move |_, physics, events, graphics, _| { + testbed.harness_mut().add_callback(move |physics, events, _, _| { while let Ok(prox) = events.proximity_events.try_recv() { let color = match prox.new_status { Proximity::WithinMargin | Proximity::Intersecting => Point3::new(1.0, 1.0, 0.0), @@ -80,10 +80,12 @@ pub fn init_world(testbed: &mut Testbed) { let parent_handle2 = physics.colliders.get(prox.collider2).unwrap().parent(); if parent_handle1 != ground_handle && parent_handle1 != sensor_handle { - graphics.set_body_color(parent_handle1, color); + // TODO: need a way to access graphics & window + // graphics.set_body_color(parent_handle1, color); } if parent_handle2 != ground_handle && parent_handle2 != sensor_handle { - graphics.set_body_color(parent_handle2, color); + // TODO: need a way to access graphics & window + // graphics.set_body_color(parent_handle2, color); } } }); -- cgit From e11ace383164de39dfaadcb00f258497b132cf1d Mon Sep 17 00:00:00 2001 From: rezural Date: Thu, 31 Dec 2020 13:31:30 +1100 Subject: cargo fmt --- examples2d/sensor2.rs | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) (limited to 'examples2d/sensor2.rs') diff --git a/examples2d/sensor2.rs b/examples2d/sensor2.rs index c9edea0..123f633 100644 --- a/examples2d/sensor2.rs +++ b/examples2d/sensor2.rs @@ -69,26 +69,28 @@ pub fn init_world(testbed: &mut Testbed) { testbed.set_body_color(sensor_handle, Point3::new(0.5, 1.0, 1.0)); // Callback that will be executed on the main loop to handle proximities. - testbed.harness_mut().add_callback(move |physics, events, _, _| { - while let Ok(prox) = events.proximity_events.try_recv() { - let color = match prox.new_status { - Proximity::WithinMargin | Proximity::Intersecting => Point3::new(1.0, 1.0, 0.0), - Proximity::Disjoint => Point3::new(0.5, 0.5, 1.0), - }; - - let parent_handle1 = physics.colliders.get(prox.collider1).unwrap().parent(); - let parent_handle2 = physics.colliders.get(prox.collider2).unwrap().parent(); - - if parent_handle1 != ground_handle && parent_handle1 != sensor_handle { - // TODO: need a way to access graphics & window - // graphics.set_body_color(parent_handle1, color); + testbed + .harness_mut() + .add_callback(move |physics, events, _, _| { + while let Ok(prox) = events.proximity_events.try_recv() { + let color = match prox.new_status { + Proximity::WithinMargin | Proximity::Intersecting => Point3::new(1.0, 1.0, 0.0), + Proximity::Disjoint => Point3::new(0.5, 0.5, 1.0), + }; + + let parent_handle1 = physics.colliders.get(prox.collider1).unwrap().parent(); + let parent_handle2 = physics.colliders.get(prox.collider2).unwrap().parent(); + + if parent_handle1 != ground_handle && parent_handle1 != sensor_handle { + // TODO: need a way to access graphics & window + // graphics.set_body_color(parent_handle1, color); + } + if parent_handle2 != ground_handle && parent_handle2 != sensor_handle { + // TODO: need a way to access graphics & window + // graphics.set_body_color(parent_handle2, color); + } } - if parent_handle2 != ground_handle && parent_handle2 != sensor_handle { - // TODO: need a way to access graphics & window - // graphics.set_body_color(parent_handle2, color); - } - } - }); + }); /* * Set up the testbed. -- cgit From 6f508e5d04e5652991f9feaad09231af84542ac1 Mon Sep 17 00:00:00 2001 From: rezural Date: Thu, 31 Dec 2020 15:23:25 +1100 Subject: remove redundant time :f32 from harness callbacks. it can be access via run_state.time --- examples2d/sensor2.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples2d/sensor2.rs') diff --git a/examples2d/sensor2.rs b/examples2d/sensor2.rs index 123f633..382581e 100644 --- a/examples2d/sensor2.rs +++ b/examples2d/sensor2.rs @@ -71,7 +71,7 @@ pub fn init_world(testbed: &mut Testbed) { // Callback that will be executed on the main loop to handle proximities. testbed .harness_mut() - .add_callback(move |physics, events, _, _| { + .add_callback(move |physics, events, _| { while let Ok(prox) = events.proximity_events.try_recv() { let color = match prox.new_status { Proximity::WithinMargin | Proximity::Intersecting => Point3::new(1.0, 1.0, 0.0), -- cgit From 34e79e9afc21ff0202d8a0338d0e8e038402a159 Mon Sep 17 00:00:00 2001 From: rezural Date: Sat, 2 Jan 2021 16:45:55 +1100 Subject: unify callbacks with & without graphics & window --- examples2d/sensor2.rs | 40 +++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 21 deletions(-) (limited to 'examples2d/sensor2.rs') diff --git a/examples2d/sensor2.rs b/examples2d/sensor2.rs index 382581e..9fdbf14 100644 --- a/examples2d/sensor2.rs +++ b/examples2d/sensor2.rs @@ -69,28 +69,26 @@ pub fn init_world(testbed: &mut Testbed) { testbed.set_body_color(sensor_handle, Point3::new(0.5, 1.0, 1.0)); // Callback that will be executed on the main loop to handle proximities. - testbed - .harness_mut() - .add_callback(move |physics, events, _| { - while let Ok(prox) = events.proximity_events.try_recv() { - let color = match prox.new_status { - Proximity::WithinMargin | Proximity::Intersecting => Point3::new(1.0, 1.0, 0.0), - Proximity::Disjoint => Point3::new(0.5, 0.5, 1.0), - }; - - let parent_handle1 = physics.colliders.get(prox.collider1).unwrap().parent(); - let parent_handle2 = physics.colliders.get(prox.collider2).unwrap().parent(); - - if parent_handle1 != ground_handle && parent_handle1 != sensor_handle { - // TODO: need a way to access graphics & window - // graphics.set_body_color(parent_handle1, color); - } - if parent_handle2 != ground_handle && parent_handle2 != sensor_handle { - // TODO: need a way to access graphics & window - // graphics.set_body_color(parent_handle2, color); - } + testbed.add_callback(move |_, _, physics, events, _| { + while let Ok(prox) = events.proximity_events.try_recv() { + let color = match prox.new_status { + Proximity::WithinMargin | Proximity::Intersecting => Point3::new(1.0, 1.0, 0.0), + Proximity::Disjoint => Point3::new(0.5, 0.5, 1.0), + }; + + let parent_handle1 = physics.colliders.get(prox.collider1).unwrap().parent(); + let parent_handle2 = physics.colliders.get(prox.collider2).unwrap().parent(); + + if parent_handle1 != ground_handle && parent_handle1 != sensor_handle { + // FIXME: need a way to access graphics & window in a loop + // graphics.set_body_color(parent_handle1, color); } - }); + if parent_handle2 != ground_handle && parent_handle2 != sensor_handle { + // FIXME: need a way to access graphics & window in a loop + // graphics.set_body_color(parent_handle2, color); + } + } + }); /* * Set up the testbed. -- cgit From 5ca82eeaee5c45d31cdbb5f963d0f93b19196ea8 Mon Sep 17 00:00:00 2001 From: rezural Date: Sun, 3 Jan 2021 19:54:56 +1100 Subject: enable graphics and windows related code in examples --- examples2d/sensor2.rs | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'examples2d/sensor2.rs') diff --git a/examples2d/sensor2.rs b/examples2d/sensor2.rs index 9fdbf14..3d5976d 100644 --- a/examples2d/sensor2.rs +++ b/examples2d/sensor2.rs @@ -69,7 +69,7 @@ pub fn init_world(testbed: &mut Testbed) { testbed.set_body_color(sensor_handle, Point3::new(0.5, 1.0, 1.0)); // Callback that will be executed on the main loop to handle proximities. - testbed.add_callback(move |_, _, physics, events, _| { + testbed.add_callback(move |_, mut graphics, physics, events, _| { while let Ok(prox) = events.proximity_events.try_recv() { let color = match prox.new_status { Proximity::WithinMargin | Proximity::Intersecting => Point3::new(1.0, 1.0, 0.0), @@ -78,14 +78,13 @@ pub fn init_world(testbed: &mut Testbed) { let parent_handle1 = physics.colliders.get(prox.collider1).unwrap().parent(); let parent_handle2 = physics.colliders.get(prox.collider2).unwrap().parent(); - - if parent_handle1 != ground_handle && parent_handle1 != sensor_handle { - // FIXME: need a way to access graphics & window in a loop - // graphics.set_body_color(parent_handle1, color); - } - if parent_handle2 != ground_handle && parent_handle2 != sensor_handle { - // FIXME: need a way to access graphics & window in a loop - // graphics.set_body_color(parent_handle2, color); + if let Some(graphics) = &mut graphics { + if parent_handle1 != ground_handle && parent_handle1 != sensor_handle { + graphics.set_body_color(parent_handle1, color); + } + if parent_handle2 != ground_handle && parent_handle2 != sensor_handle { + graphics.set_body_color(parent_handle2, color); + } } } }); -- cgit