diff --git a/app/OrbitalCam.py b/app/OrbitalCam.py index 8c13bf8..687f4a5 100644 --- a/app/OrbitalCam.py +++ b/app/OrbitalCam.py @@ -1,30 +1,55 @@ import harfang as hg +from statistics import median +from math import pi d = 5 cam_rot_speed = 0.5 k_wheel = 10 +dtxl = [] +dtyl = [] + +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, 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 + dtxl.append(delta_x) + dtyl.append(delta_y) + if len(dtxl) > 5: + dtxl.pop(0) + if len(dtyl) > 5: + dtyl.pop(0) + delta_x = median(dtxl) + delta_y = 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() - 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 > pi/2: + cam_rot.x = pi/2 + if cam_rot.x < 0: + cam_rot.x = 0 + + if keyboard.Down(hg.K_LAlt): if mouse.Down(hg.MB_0): diff --git a/app/poppy_api_rest.py b/app/poppy_api_rest.py index bc29095..0e1d1a6 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,