Skip to content

Commit

Permalink
Merge pull request #2 from disketflu/master
Browse files Browse the repository at this point in the history
V1.2 : Added degree and jauges resizing + optimized orbitalcam for touchscreen devices
  • Loading branch information
astrofra authored Nov 15, 2021
2 parents 85c1466 + e580573 commit fa3b639
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 18 deletions.
49 changes: 37 additions & 12 deletions app/OrbitalCam.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
10 changes: 4 additions & 6 deletions app/poppy_api_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit fa3b639

Please sign in to comment.