File tree Expand file tree Collapse file tree 1 file changed +26
-8
lines changed Expand file tree Collapse file tree 1 file changed +26
-8
lines changed Original file line number Diff line number Diff line change @@ -252,10 +252,20 @@ def get_thumb_values(state):
252252 magL = sqrt (LX * LX + LY * LY )
253253 magR = sqrt (RX * RX + RY * RY )
254254
255- normLX = LX / magL
256- normLY = LY / magL
257- normRX = RX / magR
258- normRY = RY / magR
255+ if magL != 0 :
256+ normLX = LX / magL
257+ normLY = LY / magL
258+ else : # if magL == 0 the stick is centered, there is no direction
259+ normLX = 0
260+ normLY = 0
261+
262+ if magR != 0 :
263+ normRX = RX / magR
264+ normRY = RY / magR
265+ else : # if magR == 0 the stick is centered, there is no direction
266+ normRX = 0
267+ normRY = 0
268+
259269
260270 normMagL = 0
261271 normMagR = 0
@@ -396,8 +406,12 @@ def get_events():
396406
397407 magL = sqrt (LX * LX + LY * LY )
398408
399- normLX = LX / magL
400- normLY = LY / magL
409+ if magL != 0 :
410+ normLX = LX / magL
411+ normLY = LY / magL
412+ else : # if magL == 0 the stick is centered, there is no direction
413+ normLX = 0
414+ normLY = 0
401415
402416 normMagL = 0
403417
@@ -429,8 +443,12 @@ def get_events():
429443
430444 magR = sqrt (RX * RX + RY * RY )
431445
432- normRX = RX / magR
433- normRY = RY / magR
446+ if magR != 0 :
447+ normRX = RX / magR
448+ normRY = RY / magR
449+ else : # if magR == 0 the stick is centered, there is no direction
450+ normRX = 0
451+ normRY = 0
434452
435453 normMagR = 0
436454
You can’t perform that action at this time.
0 commit comments