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 --- examples3d/platform3.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'examples3d/platform3.rs') diff --git a/examples3d/platform3.rs b/examples3d/platform3.rs index 0975f39..1e8d330 100644 --- a/examples3d/platform3.rs +++ b/examples3d/platform3.rs @@ -65,7 +65,7 @@ pub fn init_world(testbed: &mut Testbed) { * Setup a callback to control the platform. */ let mut count = 0; - testbed.add_callback(move |_, physics, _, _, time| { + testbed.add_callback(move |_, physics, _, _, run_state| { count += 1; if count % 100 > 50 { return; @@ -75,8 +75,8 @@ pub fn init_world(testbed: &mut Testbed) { let mut next_pos = *platform.position(); let dt = 0.016; - next_pos.translation.vector.y += (time * 5.0).sin() * dt; - next_pos.translation.vector.z += time.sin() * 5.0 * dt; + next_pos.translation.vector.y += (run_state.time * 5.0).sin() * dt; + next_pos.translation.vector.z += run_state.time.sin() * 5.0 * dt; if next_pos.translation.vector.z >= rad * 10.0 { next_pos.translation.vector.z -= 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 --- examples3d/platform3.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples3d/platform3.rs') diff --git a/examples3d/platform3.rs b/examples3d/platform3.rs index 1e8d330..82ea8f4 100644 --- a/examples3d/platform3.rs +++ b/examples3d/platform3.rs @@ -65,7 +65,7 @@ pub fn init_world(testbed: &mut Testbed) { * Setup a callback to control the platform. */ let mut count = 0; - testbed.add_callback(move |_, physics, _, _, run_state| { + testbed.harness_mut().add_callback(move |physics, _, run_state, _| { count += 1; if count % 100 > 50 { return; -- 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/platform3.rs | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) (limited to 'examples3d/platform3.rs') diff --git a/examples3d/platform3.rs b/examples3d/platform3.rs index 82ea8f4..b71d307 100644 --- a/examples3d/platform3.rs +++ b/examples3d/platform3.rs @@ -65,29 +65,31 @@ pub fn init_world(testbed: &mut Testbed) { * Setup a callback to control the platform. */ let mut count = 0; - testbed.harness_mut().add_callback(move |physics, _, run_state, _| { - count += 1; - if count % 100 > 50 { - return; - } + testbed + .harness_mut() + .add_callback(move |physics, _, run_state, _| { + count += 1; + if count % 100 > 50 { + return; + } - if let Some(platform) = physics.bodies.get_mut(platform_handle) { - let mut next_pos = *platform.position(); + if let Some(platform) = physics.bodies.get_mut(platform_handle) { + 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.z += 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.z += run_state.time.sin() * 5.0 * dt; - if next_pos.translation.vector.z >= rad * 10.0 { - next_pos.translation.vector.z -= dt; - } - if next_pos.translation.vector.z <= -rad * 10.0 { - next_pos.translation.vector.z += dt; - } + if next_pos.translation.vector.z >= rad * 10.0 { + next_pos.translation.vector.z -= dt; + } + if next_pos.translation.vector.z <= -rad * 10.0 { + next_pos.translation.vector.z += 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 --- examples3d/platform3.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples3d/platform3.rs') diff --git a/examples3d/platform3.rs b/examples3d/platform3.rs index b71d307..944adae 100644 --- a/examples3d/platform3.rs +++ b/examples3d/platform3.rs @@ -67,7 +67,7 @@ pub fn init_world(testbed: &mut Testbed) { let mut count = 0; testbed .harness_mut() - .add_callback(move |physics, _, run_state, _| { + .add_callback(move |physics, _, run_state| { count += 1; if count % 100 > 50 { return; -- 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/platform3.rs | 40 +++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 21 deletions(-) (limited to 'examples3d/platform3.rs') diff --git a/examples3d/platform3.rs b/examples3d/platform3.rs index 944adae..7b5c986 100644 --- a/examples3d/platform3.rs +++ b/examples3d/platform3.rs @@ -65,31 +65,29 @@ pub fn init_world(testbed: &mut Testbed) { * Setup a callback to control the platform. */ let mut count = 0; - testbed - .harness_mut() - .add_callback(move |physics, _, run_state| { - count += 1; - if count % 100 > 50 { - return; - } - - if let Some(platform) = physics.bodies.get_mut(platform_handle) { - let mut next_pos = *platform.position(); + testbed.add_callback(move |_, _, physics, _, run_state| { + count += 1; + if count % 100 > 50 { + return; + } - let dt = 0.016; - next_pos.translation.vector.y += (run_state.time * 5.0).sin() * dt; - next_pos.translation.vector.z += run_state.time.sin() * 5.0 * dt; + if let Some(platform) = physics.bodies.get_mut(platform_handle) { + let mut next_pos = *platform.position(); - if next_pos.translation.vector.z >= rad * 10.0 { - next_pos.translation.vector.z -= dt; - } - if next_pos.translation.vector.z <= -rad * 10.0 { - next_pos.translation.vector.z += dt; - } + let dt = 0.016; + next_pos.translation.vector.y += (run_state.time * 5.0).sin() * dt; + next_pos.translation.vector.z += run_state.time.sin() * 5.0 * dt; - platform.set_next_kinematic_position(next_pos); + if next_pos.translation.vector.z >= rad * 10.0 { + next_pos.translation.vector.z -= dt; } - }); + if next_pos.translation.vector.z <= -rad * 10.0 { + next_pos.translation.vector.z += dt; + } + + platform.set_next_kinematic_position(next_pos); + } + }); /* * Run the simulation. -- cgit