![]() |
|
#1
|
|||
|
|||
|
Hi folks,
I have been working on code to control the canvas mouse cursor using a joystick. Below is the code i have come up with. The issues i'm having are that I cannot figure out how to bind the mouse click to a button on the joystick. Also i'm sure my beginners code needs tidying up but i cannot figure out where. For some reason when making a 'psoitive' movement (i.e. x+ and y+) the cursor movement seems to jump a little and is not smooth however in reverse when move towarsd 0,0 on the canvas it works perfectly smooth. I cannot see what i need to change in my code. Can hear my brain sizzling at this stage!! Any help is super appreciated! Code:
jx = 0.000
jy = 0.000
def UpdateJoystickMovement():
e = viz.elapsed()
x,y,z = joystick.getPosition()
print 'Cursor is at ' + str(canvas.getCursorPosition())
print 'XY: ' + str(x) + '-' + str(y)
global jx
global jy
if x > 0:
if x < jx:
jx = jx
else:
jx = (x+jx/1000)
elif x < 0:
if x > jx:
jx = jx
else:
jx = (jx+x/1000)
if y > 0:
if y < jy:
jy = jy
else:
jy = (y+jy/1000)
elif y < 0:
if y > jy:
jy = jy
else:
jy = (jy+y/1000)
canvas.setCursorPosition([jx,jy])
vizact.ontimer(0, UpdateJoystickMovement)
|
| Tags |
| canvas, click, cursor, joystick |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| joystick position | nmohandes | Vizard | 2 | 01-16-2012 11:03 AM |
| Mouse bug in V3 and V4 | Renato Lima | Vizard | 2 | 05-11-2011 07:38 PM |
| Mouse event: how to detect no mouse move event, how to set mouse position? | Zhi | Vizard | 3 | 04-11-2011 07:25 PM |
| how to remove velocity when mouse is disabled? | jvacare1 | Vizard | 2 | 02-18-2010 11:25 AM |
| Navigating an avatar using mouse position(2D) in 3D environment | james007 | Vizard | 1 | 10-16-2009 12:29 PM |