WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 03-23-2017, 10:37 AM
Lenticularis Lenticularis is offline
Member
 
Join Date: Jul 2016
Posts: 12
Question How to call Oculus Remote

Hi

I want to add an action by pressing a button on the Oculus Remote.
But how do I call the remote? And how do I associate a button press of the remote with an action?
The reference page about the Oculus HMD wasn't very helpful.
Reply With Quote
  #2  
Old 03-23-2017, 11:24 AM
Lenticularis Lenticularis is offline
Member
 
Join Date: Jul 2016
Posts: 12
To further clarify:

The ultimate goal is to use the remote as a replacement for all keyboard and mouse input. But for a start, I want to associate the press of the enter key on the remote with the left mouse button, in order to select options with the remote instead of the mouse.
Reply With Quote
  #3  
Old 03-23-2017, 11:57 PM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,471
Are you referring to selecting options within a GUI object? If so, take a look at the GUI canvas page and canvasExample.py script (File > Quick Open: type canvasExample). Using the GUI canvas, set the cursor style to viz.CANVAS_MOUSE_VIRTUAL and apply updates to the cursor based on oculus remote signals. The example script shows how to manually update the cursor position and send mouse button events using keypresses in the ManualCursorPositionTask and ManualCursorButtonTask functions. In your case you would change the keypress checks to button checks.
Reply With Quote
  #4  
Old 04-11-2017, 12:57 PM
Lenticularis Lenticularis is offline
Member
 
Join Date: Jul 2016
Posts: 12
Hi again

Thanks for your answer.
I'm referring to the canvas example script, yes.

I tried to change the keypresses to button checks but I can't get it working. Is there a mistake somewhere in my script?

I'd be really glad for any kind of advice.



Code:
import viz
import vizact
import vizcam
import vizdlg
import vizinfo
import viztask

###
canvas = viz.addGUICanvas()
canvas.setRenderWorldOverlay([800,600],50,3)
canvas.setPosition([0,0,0])

viz.mouse.setTrap(True)
viz.mouse.setVisible(False)
canvas.setMouseStyle(viz.CANVAS_MOUSE_VIRTUAL)
# Apply settings
viz.MainWindow.setDefaultGUICanvas(canvas)
###

import oculus
hmd = oculus.Rift()
viz.link(hmd.getSensor(), viz.MainView)

viz.go()

###########################
remoteEnter = viz.addButton(oculus.BUTTON_REMOTE_ENTER)
remoteUp = viz.addButton(oculus.BUTTON_REMOTE_UP)
remoteDown = viz.addButton(oculus.BUTTON_REMOTE_DOWN)
remoteLeft = viz.addButton(oculus.BUTTON_REMOTE_LEFT)
remoteRight = viz.addButton(oculus.BUTTON_REMOTE_RIGHT)
###########################

# Load environment models
worlds = [ viz.addChild('maze.osgb'), viz.addChild('gallery.osgb'), viz.addChild('dojo.osgb') ]
for i, model in enumerate(worlds):
	model.visible(i == 0)

controlPanel = vizinfo.InfoPanel(text='Navigate with WASD', title='Canvas Example')

controlPanel.addSeparator()
manual_cursor = controlPanel.addLabelItem('Manual Cursor',viz.addCheckbox())

######################
def ManualCursorPositionTask():
	"""Use arrow keys to manually move canvas cursor"""

	while True:

		pos = canvas.getCursorPosition(viz.CANVAS_CURSOR_PIXELS)
		inc = 250.0 * viz.getFrameElapsed()

#		if viz.key.isDown(viz.KEY_UP):
#			pos[1] += inc
#		if viz.key.isDown(viz.KEY_LEFT):
#			pos[0] -= inc
#		if viz.key.isDown(viz.KEY_DOWN):
#			pos[1] -= inc
#		if viz.key.isDown(viz.KEY_RIGHT):
#			pos[0] += inc
#
#		canvas.setCursorPosition(pos, viz.CANVAS_CURSOR_PIXELS)

		if remoteUp.get() == viz.DOWN:
			pos[1] += inc
		if remoteLeft.get() == viz.DOWN:
			pos[0] -= inc
		if remoteDown.get() == viz.DOWN:
			pos[1] -= inc
		if remoteRight.get() == viz.DOWN:
			pos[0] += inc

		canvas.setCursorPosition(pos, viz.CANVAS_CURSOR_PIXELS)

		yield viztask.waitFrame(1)

######################
def ManualCursorButtonTask():
	"""Use spacebar to manually simulate mouse press/release on canvas"""

	while True:

#		yield viztask.waitKeyDown(' ', priority=viz.PRIORITY_GUI_HANDLER-1)
#
#		canvas.sendMouseButtonEvent(viz.MOUSEBUTTON_LEFT, viz.DOWN)
#
#		yield viztask.waitKeyUp(' ', priority=viz.PRIORITY_GUI_HANDLER-1)
#
#		canvas.sendMouseButtonEvent(viz.MOUSEBUTTON_LEFT, viz.UP)

		yield viztask.waitButtonDown(remoteEnter, priority=viz.PRIORITY_GUI_HANDLER-1)

		canvas.sendMouseButtonEvent(viz.MOUSEBUTTON_LEFT, viz.DOWN)

		yield viztask.waitButtonUp(remoteEnter, priority=viz.PRIORITY_GUI_HANDLER-1)

		canvas.sendMouseButtonEvent(viz.MOUSEBUTTON_LEFT, viz.UP)

def ToggleManualCursorTask():
	"""Handle toggling of manual cursor mode"""

	notice_panel = vizinfo.InfoPanel('Arrow keys control cursor.\nSpacebar simulates button press.', title='Manual Cursor Enabled', align=viz.ALIGN_RIGHT_TOP, key=None, icon=False)
	notice_panel.visible(False)

	while True:

		yield viztask.waitButtonDown(manual_cursor)

		# Enable manual cursor control
		UpdateMouseStyle()
		pos_task = viztask.schedule(ManualCursorPositionTask())
		button_task = viztask.schedule(ManualCursorButtonTask())
		notice_panel.visible(True)

		yield viztask.waitButtonUp(manual_cursor)

		# Disable manual cursor control
		UpdateMouseStyle()
		pos_task.remove()
		button_task.remove()
		notice_panel.visible(False)

viztask.schedule(ToggleManualCursorTask())
Reply With Quote
  #5  
Old 04-12-2017, 03:38 AM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,471
First get a handle to the remote controller:

Code:
hmd = oculus.Rift()
remote = hmd.getRemoteController()
Then in the function that updates the cursor check the remote controller button states:

Code:
if remote.isButtonDown(oculus.BUTTON_REMOTE_UP):
	pos[1] += inc
if remote.isButtonDown(oculus.BUTTON_REMOTE_LEFT):
	pos[0] -= inc
if remote.isButtonDown(oculus.BUTTON_REMOTE_DOWN):
	pos[1] -= inc
if remote.isButtonDown(oculus.BUTTON_REMOTE_RIGHT):
	pos[0] += inc
Does this work for you?
Reply With Quote
  #6  
Old 04-13-2017, 12:43 PM
Lenticularis Lenticularis is offline
Member
 
Join Date: Jul 2016
Posts: 12
That's exactly what I was looking for, thanks!

But how would you change the ManualCursorButtonTask function?
Code:
def ManualCursorButtonTask():
	"""Use spacebar to manually simulate mouse press/release on canvas"""

	while True:

		yield viztask.waitKeyDown(' ', priority=viz.PRIORITY_GUI_HANDLER-1)

		canvas.sendMouseButtonEvent(viz.MOUSEBUTTON_LEFT, viz.DOWN)

		yield viztask.waitKeyUp(' ', priority=viz.PRIORITY_GUI_HANDLER-1)

		canvas.sendMouseButtonEvent(viz.MOUSEBUTTON_LEFT, viz.UP)
Reply With Quote
  #7  
Old 04-13-2017, 11:24 PM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,471
Try using the viztask.waitSensorDown and viztask.waitSensorUp commands:

Code:
def ManualCursorButtonTask():

	while True:
		yield viztask.waitSensorDown(remote, oculus.BUTTON_REMOTE_ENTER, priority=viz.PRIORITY_GUI_HANDLER-1)
		canvas.sendMouseButtonEvent(viz.MOUSEBUTTON_LEFT, viz.DOWN)
		yield viztask.waitSensorUp(remote, oculus.BUTTON_REMOTE_ENTER, priority=viz.PRIORITY_GUI_HANDLER-1)
		canvas.sendMouseButtonEvent(viz.MOUSEBUTTON_LEFT, viz.UP)
Reply With Quote
  #8  
Old 04-20-2017, 12:32 PM
Lenticularis Lenticularis is offline
Member
 
Join Date: Jul 2016
Posts: 12
Thanks very much!
Reply With Quote
Reply

Tags
action, button, oculus, oculus remote


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Oculus Rift + Vizard help required sukhpreet Vizard 1 01-03-2017 11:52 AM
Xbox controller and Oculus DK2 prilpi Vizard 17 03-28-2016 06:00 AM
3D text oculus for right to left languages bbb Vizard 2 01-16-2016 08:02 AM
Multiple post-process effects with oculus rift lklab Vizard 2 03-13-2015 02:48 PM
Oculus runtime disrupts clustering to mirror DK2 display performlabrit Vizard 1 01-23-2015 08:00 AM


All times are GMT -7. The time now is 08:19 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Copyright 2002-2023 WorldViz LLC