From 3acf8a068d0ba0cc34dcbc1dd4e8fbb744bca00f Mon Sep 17 00:00:00 2001 From: disketflu <91607630+disketflu@users.noreply.github.com> Date: Wed, 10 Nov 2021 15:28:42 +0100 Subject: [PATCH 1/6] V1.2 : Added degree and jauges resizing + optimized orbitalcam for touchscreen devices --- app/OrbitalCam.py | 4 ++++ app/poppy_api_rest.py | 10 ++++------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/app/OrbitalCam.py b/app/OrbitalCam.py index 8c13bf8..0a26e73 100644 --- a/app/OrbitalCam.py +++ b/app/OrbitalCam.py @@ -17,6 +17,10 @@ def OrbitalController(keyboard, mouse, cam_pos, cam_rot, cam_tgt, dt, width, hei speed = dt_sec * cam_rot_speed delta_x = mouse.DtX() delta_y = -mouse.DtY() + if delta_x > 40 or delta_x < -40: + delta_x = 0 + if delta_y > 40 or delta_y < -40: + delta_y = 0 cam_rot.x += delta_y * speed cam_rot.y += delta_x * speed diff --git a/app/poppy_api_rest.py b/app/poppy_api_rest.py index bc29095..a3810df 100644 --- a/app/poppy_api_rest.py +++ b/app/poppy_api_rest.py @@ -322,8 +322,7 @@ def get_v_from_dancing(id_robot): p = rangeadjust_clamp(abs(m["acc"]), 0, 9999, 0, 1) # texture quad - quad_width = 140 - quad_height = 140 + quad_width = quad_height = res_y * 0.12 pos_in_pixel = hg.iVec2(int(res_x - quad_width*1.1), int((res_y*0.05) + (res_y*0.9)/len(hg_motors) * id + (quad_height*1.2)/2)) #setup quad vertices @@ -354,12 +353,11 @@ def get_v_from_dancing(id_robot): hg.DrawLines(view_id, vtx, shader_for_line) # draw percent - quad_width = 80 - quad_height = 40 - pos_in_pixel.x -= 30 + pos_in_pixel.x -= int(res_y / 35) pos_in_pixel.y -= 10 mat = hg.TranslationMat4(hg.Vec3(pos_in_pixel.x, pos_in_pixel.y, 1)) - hg.SetS(mat, hg.Vec3(1, -1, 1)) + hg.SetS(mat, hg.Vec3(res_y/1080, -res_y/1080, res_y/1080)) + hg.DrawText(view_id, font, '{n} °'.format(n = int(rangeadjust_clamp(v, -180, 180, 0, 360))), shader_font, "u_tex", 0, From e65e58ae5861574461124d8fe0067e79e97879ea Mon Sep 17 00:00:00 2001 From: disketflu <91607630+disketflu@users.noreply.github.com> Date: Wed, 10 Nov 2021 16:08:37 +0100 Subject: [PATCH 2/6] Update OrbitalCam.py --- app/OrbitalCam.py | 47 +++++++++++++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 16 deletions(-) diff --git a/app/OrbitalCam.py b/app/OrbitalCam.py index 0a26e73..f8c3baa 100644 --- a/app/OrbitalCam.py +++ b/app/OrbitalCam.py @@ -1,34 +1,49 @@ import harfang as hg +import statistics d = 5 cam_rot_speed = 0.5 k_wheel = 10 +dtxl = [] +dtyl = [] + +smoothed_dx = 0 +smoothed_dy = 0 def OrbitalController(keyboard, mouse, cam_pos, cam_rot, cam_tgt, dt, width, height): global d + global dtxl, dtyl, smoothed_dx, smoothed_dy dt_sec = hg.time_to_sec_f(dt) k_ar = hg.ComputeAspectRatioX(width, height).x + delta_x = mouse.DtX() if mouse.Down(hg.MB_0) else 0 + delta_y = -mouse.DtY() if mouse.Down(hg.MB_0) else 0 + print(delta_x) + dtxl.append(delta_x) + dtyl.append(delta_y) + if len(dtxl) > 5: + dtxl.pop(0) + if len(dtyl) > 5: + dtyl.pop(0) + delta_x = statistics.median(dtxl) + delta_y = statistics.median(dtyl) + + smoothed_dx += (delta_x - smoothed_dx) * 0.1 + smoothed_dy += (delta_y - smoothed_dy) * 0.1 + state_modified = False - if mouse.Down(hg.MB_0): - speed = dt_sec * cam_rot_speed - delta_x = mouse.DtX() - delta_y = -mouse.DtY() - if delta_x > 40 or delta_x < -40: - delta_x = 0 - if delta_y > 40 or delta_y < -40: - delta_y = 0 - cam_rot.x += delta_y * speed - cam_rot.y += delta_x * speed - - # clamp X - if cam_rot.x > 1.57: - cam_rot.x = 1.57 - if cam_rot.x < 0: - cam_rot.x = 0 + speed = dt_sec * cam_rot_speed + cam_rot.x += smoothed_dy * speed + cam_rot.y += smoothed_dx * speed + + # clamp X + if cam_rot.x > 1.57: + cam_rot.x = 1.57 + if cam_rot.x < 0: + cam_rot.x = 0 if keyboard.Down(hg.K_LAlt): if mouse.Down(hg.MB_0): From 5868b5c7387ee17eea805110b3ba8e3d469cf825 Mon Sep 17 00:00:00 2001 From: disketflu <91607630+disketflu@users.noreply.github.com> Date: Wed, 10 Nov 2021 16:21:59 +0100 Subject: [PATCH 3/6] Update OrbitalCam.py --- app/OrbitalCam.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/app/OrbitalCam.py b/app/OrbitalCam.py index f8c3baa..7255f19 100644 --- a/app/OrbitalCam.py +++ b/app/OrbitalCam.py @@ -12,16 +12,18 @@ smoothed_dx = 0 smoothed_dy = 0 +smoothed_rotx = 0 + + def OrbitalController(keyboard, mouse, cam_pos, cam_rot, cam_tgt, dt, width, height): global d - global dtxl, dtyl, smoothed_dx, smoothed_dy + global dtxl, dtyl, smoothed_dx, smoothed_dy, smoothed_rotx dt_sec = hg.time_to_sec_f(dt) k_ar = hg.ComputeAspectRatioX(width, height).x delta_x = mouse.DtX() if mouse.Down(hg.MB_0) else 0 delta_y = -mouse.DtY() if mouse.Down(hg.MB_0) else 0 - print(delta_x) dtxl.append(delta_x) dtyl.append(delta_y) if len(dtxl) > 5: @@ -40,11 +42,14 @@ def OrbitalController(keyboard, mouse, cam_pos, cam_rot, cam_tgt, dt, width, hei cam_rot.y += smoothed_dx * speed # clamp X + if cam_rot.x > 1.57: cam_rot.x = 1.57 if cam_rot.x < 0: cam_rot.x = 0 + + if keyboard.Down(hg.K_LAlt): if mouse.Down(hg.MB_0): z_value = -mouse.DtY() * 5 From e828a2ed157178edd192d8efe4ac44b9cce8e6d4 Mon Sep 17 00:00:00 2001 From: disketflu <91607630+disketflu@users.noreply.github.com> Date: Mon, 15 Nov 2021 15:42:44 +0100 Subject: [PATCH 4/6] Updated import statistics to only import median --- app/OrbitalCam.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/OrbitalCam.py b/app/OrbitalCam.py index 7255f19..3796b4a 100644 --- a/app/OrbitalCam.py +++ b/app/OrbitalCam.py @@ -1,5 +1,5 @@ import harfang as hg -import statistics +from statistics import median d = 5 @@ -30,8 +30,8 @@ def OrbitalController(keyboard, mouse, cam_pos, cam_rot, cam_tgt, dt, width, hei dtxl.pop(0) if len(dtyl) > 5: dtyl.pop(0) - delta_x = statistics.median(dtxl) - delta_y = statistics.median(dtyl) + delta_x = median(dtxl) + delta_y = median(dtyl) smoothed_dx += (delta_x - smoothed_dx) * 0.1 smoothed_dy += (delta_y - smoothed_dy) * 0.1 From 1d0f647fa0f30b14f918fe74fc3507e45e9d96dc Mon Sep 17 00:00:00 2001 From: disketflu <91607630+disketflu@users.noreply.github.com> Date: Mon, 15 Nov 2021 15:56:53 +0100 Subject: [PATCH 5/6] Changed 1.57 to PI/2 --- app/OrbitalCam.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/OrbitalCam.py b/app/OrbitalCam.py index 3796b4a..687f4a5 100644 --- a/app/OrbitalCam.py +++ b/app/OrbitalCam.py @@ -1,5 +1,6 @@ import harfang as hg from statistics import median +from math import pi d = 5 @@ -43,8 +44,8 @@ def OrbitalController(keyboard, mouse, cam_pos, cam_rot, cam_tgt, dt, width, hei # clamp X - if cam_rot.x > 1.57: - cam_rot.x = 1.57 + if cam_rot.x > pi/2: + cam_rot.x = pi/2 if cam_rot.x < 0: cam_rot.x = 0 From e580573e77e9504f722b9564e1a96b254aad5195 Mon Sep 17 00:00:00 2001 From: disketflu <91607630+disketflu@users.noreply.github.com> Date: Mon, 15 Nov 2021 15:58:38 +0100 Subject: [PATCH 6/6] Added padding spaces to math formulas --- app/poppy_api_rest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/poppy_api_rest.py b/app/poppy_api_rest.py index a3810df..0e1d1a6 100644 --- a/app/poppy_api_rest.py +++ b/app/poppy_api_rest.py @@ -356,7 +356,7 @@ def get_v_from_dancing(id_robot): pos_in_pixel.x -= int(res_y / 35) pos_in_pixel.y -= 10 mat = hg.TranslationMat4(hg.Vec3(pos_in_pixel.x, pos_in_pixel.y, 1)) - hg.SetS(mat, hg.Vec3(res_y/1080, -res_y/1080, res_y/1080)) + hg.SetS(mat, hg.Vec3(res_y / 1080, -res_y / 1080, res_y / 1080)) hg.DrawText(view_id, font,