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 --- examples3d/sensor3.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'examples3d/sensor3.rs') diff --git a/examples3d/sensor3.rs b/examples3d/sensor3.rs index 7b218fe..44c8d25 100644 --- a/examples3d/sensor3.rs +++ b/examples3d/sensor3.rs @@ -73,7 +73,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), @@ -84,10 +84,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 --- examples3d/sensor3.rs | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) (limited to 'examples3d/sensor3.rs') diff --git a/examples3d/sensor3.rs b/examples3d/sensor3.rs index 44c8d25..e734258 100644 --- a/examples3d/sensor3.rs +++ b/examples3d/sensor3.rs @@ -73,26 +73,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 --- examples3d/sensor3.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples3d/sensor3.rs') diff --git a/examples3d/sensor3.rs b/examples3d/sensor3.rs index e734258..db01265 100644 --- a/examples3d/sensor3.rs +++ b/examples3d/sensor3.rs @@ -75,7 +75,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 --- examples3d/sensor3.rs | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) (limited to 'examples3d/sensor3.rs') diff --git a/examples3d/sensor3.rs b/examples3d/sensor3.rs index db01265..37a8f5a 100644 --- a/examples3d/sensor3.rs +++ b/examples3d/sensor3.rs @@ -73,28 +73,30 @@ 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 |_, graphics, physics, events, _| { + let graphics = &graphics; + 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(); + + match graphics { + Some(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); + } } + None => {} } - }); + } + }); /* * 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 --- examples3d/sensor3.rs | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) (limited to 'examples3d/sensor3.rs') diff --git a/examples3d/sensor3.rs b/examples3d/sensor3.rs index 37a8f5a..4160248 100644 --- a/examples3d/sensor3.rs +++ b/examples3d/sensor3.rs @@ -73,8 +73,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 |_, graphics, physics, events, _| { - let graphics = &graphics; + 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), @@ -84,16 +83,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(); - match graphics { - Some(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); - } + 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); } - None => {} } } }); -- cgit