Skip to content

Commit

Permalink
Added multi-device functional toggle button for compliance mode
Browse files Browse the repository at this point in the history
Added a slider toggle button for compliance supported by both PC and Touchscreen devices.
  • Loading branch information
disketflu committed Nov 29, 2021
1 parent f37a1af commit a36eafe
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 14 deletions.
6 changes: 3 additions & 3 deletions app/OrbitalCam.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ def OrbitalController(keyboard, mouse, cam_pos, cam_rot, cam_tgt, dt, width, hei
smoothed_dx += (delta_x - smoothed_dx) * 0.1
smoothed_dy += (delta_y - smoothed_dy) * 0.1

state_modified = False
speed = dt_sec * cam_rot_speed
cam_rot.x += smoothed_dy * speed
cam_rot.y += smoothed_dx * speed
if not (mouse.X() < 350 and mouse.X() > 30 and mouse.Y() < height and mouse.Y() > height - 150):
cam_rot.x += smoothed_dy * speed
cam_rot.y += smoothed_dx * speed

# clamp X

Expand Down
70 changes: 59 additions & 11 deletions app/poppy_api_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import requests
import socket
from math import pi
from statistics import median
import math
from OrbitalCam import OrbitalController

Expand Down Expand Up @@ -39,6 +40,10 @@ def lerp(k, a, b):

res_x, res_y = 1920, 1080

#initialize lists for toggle button (swipe style)
mousexlist = []
mouseylist = []

win = hg.NewWindow("Harfang - Poppy", res_x, res_y, 32)#, hg.WV_Fullscreen)
hg.RenderInit(win)
hg.RenderReset(res_x, res_y, hg.RF_MSAA8X | hg.RF_FlipAfterRender | hg.RF_FlushAfterRender | hg.RF_MaxAnisotropy)
Expand Down Expand Up @@ -71,6 +76,12 @@ def lerp(k, a, b):
target_tex = hg.LoadTextureFromAssets("Asset_2.png", 0)[0]
texture_asset2 = hg.MakeUniformSetTexture("s_texTexture", target_tex, 0)

target_tex = hg.LoadTextureFromAssets("switch-on.png", 0)[0]
texture_on = hg.MakeUniformSetTexture("s_texTexture", target_tex, 0)

target_tex = hg.LoadTextureFromAssets("switch-off.png", 0)[0]
texture_off = hg.MakeUniformSetTexture("s_texTexture", target_tex, 0)


# load shaders
render_state_quad = hg.ComputeRenderState(hg.BM_Alpha, hg.DT_Less, hg.FC_Disabled)
Expand Down Expand Up @@ -185,6 +196,7 @@ def get_v_from_dancing(id_robot):

# main loop
current_frame = 0
has_switched = False
while not hg.ReadKeyboard().Key(hg.K_Escape):
keyboard.Update()
mouse.Update()
Expand Down Expand Up @@ -418,19 +430,55 @@ def get_v_from_dancing(id_robot):
mat, hg.Vec3(0, 0, 0), hg.DTHA_Left, hg.DTVA_Top,
[font_color], [], text_render_state)

#toggle compliance mode
mat = hg.TransformationMat4(hg.Vec3(180, res_y - 70, 1), hg.Vec3(0, 0, 0), hg.Vec3(1, 1, 1))

pos = hg.GetT(mat)
axis_x = hg.GetX(mat) * 100 / 2
axis_y = hg.GetY(mat) * 40 / 2

toggle_vtx = hg.Vertices(vtx_layout, 4)
toggle_vtx.Begin(0).SetPos(pos - axis_x - axis_y).SetTexCoord0(hg.Vec2(0, 1)).End()
toggle_vtx.Begin(1).SetPos(pos - axis_x + axis_y).SetTexCoord0(hg.Vec2(0, 0)).End()
toggle_vtx.Begin(2).SetPos(pos + axis_x + axis_y).SetTexCoord0(hg.Vec2(1, 0)).End()
toggle_vtx.Begin(3).SetPos(pos + axis_x - axis_y).SetTexCoord0(hg.Vec2(1, 1)).End()
toggle_idx = [0, 3, 2, 0, 2, 1]


hg.DrawTriangles(view_id, toggle_idx, toggle_vtx, shader_for_plane, [], [texture_on if robot_status == 'get_value_from_real_robot' else texture_off], render_state_quad)

if mouse.Down(hg.MB_0):
mousexlist.append(mouse.X())
mouseylist.append(mouse.Y())
else:
mousexlist.clear()
mouseylist.clear()
has_switched = False

if len(mousexlist) > 20:
mousexlist.pop(0)
if len(mouseylist) > 20:
mouseylist.pop(0)

if len(mouseylist) > 0:
mouse_x = median(mousexlist)
mouse_y = median(mouseylist)
if mouse_x < 235 and mouse_x > 125 and mouse_y < res_y - 30 and mouse_y > res_y - 100 and not has_switched:
robot_status = 'send_value_to_robot' if robot_status == 'get_value_from_real_robot' else 'get_value_from_real_robot'
has_switched = True
mousexlist.clear()
mouseylist.clear()

mat = hg.TranslationMat4(hg.Vec3(250, res_y - 80, 1))
hg.SetS(mat, hg.Vec3(1, -1, 1))
hg.DrawText(view_id,
font,
"Compliance Mode", shader_font, "u_tex", 0,
mat, hg.Vec3(0, 0, 0), hg.DTHA_Left, hg.DTVA_Top,
[font_color_white], [], text_render_state)

view_id += 1

# ui choice get value from the robot or inverse
hg.ImGuiBeginFrame(res_x, res_y, dt, hg.ReadMouse(), hg.ReadKeyboard())
if hg.ImGuiBegin("Poppy"):
if hg.ImGuiButton('Choix: Bouger le vrai robot' if robot_status == 'get_value_from_real_robot' else 'Choix: Robot qui danse'):
if robot_status == 'get_value_from_real_robot':
robot_status = 'send_value_to_robot'
else:
robot_status = 'get_value_from_real_robot'

hg.ImGuiEnd()
hg.ImGuiEndFrame(view_id)

current_frame = hg.Frame()
hg.UpdateWindow(win)
Expand Down
Binary file added resources/switch-off.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/switch-on.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit a36eafe

Please sign in to comment.