From c56ebcc663d15ded86233d8caa11d00179e5ec16 Mon Sep 17 00:00:00 2001 From: rezural Date: Thu, 24 Dec 2020 17:58:37 +1100 Subject: refactor testbed to use harness --- examples2d/platform2.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'examples2d/platform2.rs') diff --git a/examples2d/platform2.rs b/examples2d/platform2.rs index 20b2e59..3b543db 100644 --- a/examples2d/platform2.rs +++ b/examples2d/platform2.rs @@ -60,13 +60,13 @@ pub fn init_world(testbed: &mut Testbed) { /* * Setup a callback to control the platform. */ - testbed.add_callback(move |_, physics, _, _, time| { + testbed.add_callback(move |_, physics, _, _, run_state| { let platform = physics.bodies.get_mut(platform_handle).unwrap(); let mut next_pos = *platform.position(); let dt = 0.016; - next_pos.translation.vector.y += (time * 5.0).sin() * dt; - next_pos.translation.vector.x += time.sin() * 5.0 * dt; + next_pos.translation.vector.y += (run_state.time * 5.0).sin() * dt; + next_pos.translation.vector.x += run_state.time.sin() * 5.0 * dt; if next_pos.translation.vector.x >= rad * 10.0 { next_pos.translation.vector.x -= dt; -- cgit 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/platform2.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples2d/platform2.rs') diff --git a/examples2d/platform2.rs b/examples2d/platform2.rs index 3b543db..5b84a18 100644 --- a/examples2d/platform2.rs +++ b/examples2d/platform2.rs @@ -60,7 +60,7 @@ pub fn init_world(testbed: &mut Testbed) { /* * Setup a callback to control the platform. */ - testbed.add_callback(move |_, physics, _, _, run_state| { + testbed.harness_mut().add_callback(move |physics, _, run_state, _| { let platform = physics.bodies.get_mut(platform_handle).unwrap(); let mut next_pos = *platform.position(); -- 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/platform2.rs | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) (limited to 'examples2d/platform2.rs') diff --git a/examples2d/platform2.rs b/examples2d/platform2.rs index 5b84a18..769161f 100644 --- a/examples2d/platform2.rs +++ b/examples2d/platform2.rs @@ -60,23 +60,25 @@ pub fn init_world(testbed: &mut Testbed) { /* * Setup a callback to control the platform. */ - testbed.harness_mut().add_callback(move |physics, _, run_state, _| { - let platform = physics.bodies.get_mut(platform_handle).unwrap(); - let mut next_pos = *platform.position(); + testbed + .harness_mut() + .add_callback(move |physics, _, run_state, _| { + let platform = physics.bodies.get_mut(platform_handle).unwrap(); + let mut next_pos = *platform.position(); - let dt = 0.016; - next_pos.translation.vector.y += (run_state.time * 5.0).sin() * dt; - next_pos.translation.vector.x += run_state.time.sin() * 5.0 * dt; + let dt = 0.016; + next_pos.translation.vector.y += (run_state.time * 5.0).sin() * dt; + next_pos.translation.vector.x += run_state.time.sin() * 5.0 * dt; - if next_pos.translation.vector.x >= rad * 10.0 { - next_pos.translation.vector.x -= dt; - } - if next_pos.translation.vector.x <= -rad * 10.0 { - next_pos.translation.vector.x += dt; - } + if next_pos.translation.vector.x >= rad * 10.0 { + next_pos.translation.vector.x -= dt; + } + if next_pos.translation.vector.x <= -rad * 10.0 { + next_pos.translation.vector.x += dt; + } - platform.set_next_kinematic_position(next_pos); - }); + platform.set_next_kinematic_position(next_pos); + }); /* * Run the simulation. -- 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/platform2.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples2d/platform2.rs') diff --git a/examples2d/platform2.rs b/examples2d/platform2.rs index 769161f..88f05f2 100644 --- a/examples2d/platform2.rs +++ b/examples2d/platform2.rs @@ -62,7 +62,7 @@ pub fn init_world(testbed: &mut Testbed) { */ testbed .harness_mut() - .add_callback(move |physics, _, run_state, _| { + .add_callback(move |physics, _, run_state| { let platform = physics.bodies.get_mut(platform_handle).unwrap(); let mut next_pos = *platform.position(); -- 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/platform2.rs | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) (limited to 'examples2d/platform2.rs') diff --git a/examples2d/platform2.rs b/examples2d/platform2.rs index 88f05f2..afd4d64 100644 --- a/examples2d/platform2.rs +++ b/examples2d/platform2.rs @@ -60,25 +60,23 @@ pub fn init_world(testbed: &mut Testbed) { /* * Setup a callback to control the platform. */ - testbed - .harness_mut() - .add_callback(move |physics, _, run_state| { - let platform = physics.bodies.get_mut(platform_handle).unwrap(); - let mut next_pos = *platform.position(); + testbed.add_callback(move |_, _, physics, _, run_state| { + let platform = physics.bodies.get_mut(platform_handle).unwrap(); + let mut next_pos = *platform.position(); - let dt = 0.016; - next_pos.translation.vector.y += (run_state.time * 5.0).sin() * dt; - next_pos.translation.vector.x += run_state.time.sin() * 5.0 * dt; + let dt = 0.016; + next_pos.translation.vector.y += (run_state.time * 5.0).sin() * dt; + next_pos.translation.vector.x += run_state.time.sin() * 5.0 * dt; - if next_pos.translation.vector.x >= rad * 10.0 { - next_pos.translation.vector.x -= dt; - } - if next_pos.translation.vector.x <= -rad * 10.0 { - next_pos.translation.vector.x += dt; - } + if next_pos.translation.vector.x >= rad * 10.0 { + next_pos.translation.vector.x -= dt; + } + if next_pos.translation.vector.x <= -rad * 10.0 { + next_pos.translation.vector.x += dt; + } - platform.set_next_kinematic_position(next_pos); - }); + platform.set_next_kinematic_position(next_pos); + }); /* * Run the simulation. -- cgit