WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 03-24-2021, 10:21 PM
tianmoran tianmoran is offline
Member
 
Join Date: Nov 2016
Posts: 16
Touch Controller Problem

Hi I would like to use the touch controller to control the movement of a scooter.

The ideal scene would be each time I load a road scene and the rider starts accelerating then rides the scooter to the end point at a constant speed. However, I am currently encountering two problems:

1) When I start running the script, only part of the scene can be loaded;
2) It seems the touch button events can not be detected as the text 'done' I inserted can not be printed out.

Can someone help me out with this pls?????



Code:
###### Import packages
import viz
import sys
import vizconnect
import vizconfig
import vizact
import vizshape
import viztask
import vizinput
import vizinfo
import time
import random											        	   
import oculus														
import numpy
import steamvr
import math
from numpy import *

hmd = oculus.Rift()
touch = hmd.getRightTouchController()


viz.go()

##### Parameters
viz.setMultiSample(4)
viz.fov(60)
viz.go()

ini_x =6
ini_y = -4.2
ini_z = -145

os_x = 0
os_y = 0
os_z = -5


ground_x =6
ground_y = -4.2
ground_z = -145

v = [15,25,35]
a = 4.1667

con = 3
trialNo = 15
trial = v * trialNo

##### Set up mainview
viz.MainView.move([ini_x + os_x, ini_y + os_y, ini_z + os_z])
view = viz.MainView

# Setup navigation node and link to main view
navigationNode = viz.addGroup()
viewLink = viz.link(navigationNode, view)
viewLink.preMultLinkable(hmd.getSensor())

# Apply user profile eye height to view
profile = hmd.getProfile()
if profile:
	navigationNode.setPosition([ground_x,ground_y+profile.eyeHeight,ground_z])
else:
	navigationNode.setPosition([ground_x,ground_y+1.8,ground_z])


##### Create skylight
viz.MainView.getHeadLight().disable()
sky_light = viz.addLight(euler=(0,90,0))
sky_light.position(0,0,-1,0)
sky_light.color(viz.WHITE)
sky_light.ambient([0.9,0.9,1])


##### Create sky
sky = viz.add(viz.ENVIRONMENT_MAP,'sky.jpg')
skybox = viz.add('skydome.dlc')
skybox.texture(sky)


# Setup Oculus Rift HMD
if not hmd.getSensor():
	sys.exit('Oculus Rift not detected')



# Check if HMD supports position tracking
supportPositionTracking = hmd.getSensor().getSrcMask() & viz.LINK_POS
if supportPositionTracking:

	# Add camera bounds model
	camera_bounds = hmd.addCameraBounds()
	camera_bounds.visible(False)

	# Change color of bounds to reflect whether position was tracked
	def CheckPositionTracked():
		if hmd.getSensor().getStatus() & oculus.STATUS_POSITION_TRACKED:
			camera_bounds.color(viz.GREEN)
		else:
			camera_bounds.color(viz.RED)
	vizact.onupdate(0, CheckPositionTracked)


#viz.setMultiSample(8)


### Import the Scooter model
scooter = viz.add('G:/ScooterProject/ChengZM/ChengZM_res/scooter.dae')
scooter.setPosition([ground_x-0.25,ground_y,ground_z+2.15])
scooter.setEuler([90,0,0])


def UpdateView(m_s,a, up_lim):
	yaw,pitch,roll = viewLink.getEuler()
	m = viz.Matrix.euler(yaw,0,0)
	p = viz.MainView.getPosition()				
	dm = m_s + viz.getFrameElapsed() * a 
	print('m0', m)
	
	if dm <= up_lim:			### accelerating
		if p[0] < (ground_x-0.25)+1.5 and p[0] > (ground_x-0.25)-1.5:
			print('InIf')
			if touch.isButtonDown(oculus.BUTTON_INDEX):
				m.preTrans([0,0,dm])
				print('done')
			if touch.isButtonDown(oculus.BUTTON_HAND):
				m.preTrans([0,0,-dm])

		elif p[0] >= (ground_x-0.25)+1.5 or p[0] <= (ground_x-0.25)-1.5:
			if touch.isButtonDown(oculus.BUTTON_INDEX):
				m.preTrans([0,0,dm])
			if touch.isButtonDown(oculus.BUTTON_HAND):
				m.preTrans([0,0,-dm])
								
	else:			### constant speed movement
		if p[0] < (ground_x-0.25)+1.5 and p[0] > (ground_x-0.25)-1.5:
			if touch.isButtonDown(oculus.BUTTON_INDEX):
				m.preTrans([0,0,up_lim])
			if touch.isButtonDown(oculus.BUTTON_HAND):
				m.preTrans([0,0,-up_lim])

		elif p[0] >= (ground_x-0.25)+1.5 or p[0] <= (ground_x-0.25)-1.5:
			if touch.isButtonDown(oculus.BUTTON_INDEX):
				m.preTrans([0,0,up_lim])
			if touch.isButtonDown(oculus.BUTTON_HAND):
				m.preTrans([0,0,-up_lim])
	navigationNode.setPosition(m.getPosition(), viz.REL_PARENT)
	scooter.setPosition(m.getPosition(), viz.REL_PARENT)
	return p, dm


def sta_timer():
	for i in range(3):
		timer_3D = viz.addText3D(str(i),pos=[ground_x,ground_y+profile.eyeHeight,ground_z+20])
		timer_3D.fontSize(10) 
		timer_3D.resolution(1)
		yield viztask.waitTime(1)
		timer_3D.visible(viz.OFF)
		

def Sct_dis():

	#viz.collision(viz.ON)

	##### Experiment starts
	##### Randomize trials
	random.shuffle(trial)
	for i in range(len(trial)):
		for j in range(2):
			yield viz.waitTime(1)			
			### Import the road model
			if j == 0:				### the first part in this trial
				road_model =  viz.add('G:/ScooterProject/ChengZM/ChengZM_res/RoadTY-only.dae')   ########## should be the reference road
				road_model.setEuler([90,0,0])
				road_model.setPosition([0,-5,-5])
			elif j == 1:			### the second part in this trial
				road_model =  viz.add('G:/ScooterProject/ChengZM/ChengZM_res/RoadTY-only.dae')   ########## should be the free road
				road_model.setEuler([90,0,0])
				road_model.setPosition([0,-5,-5])
			
			yield viz.waitTime(2)

			### Setup arrow key navigation
			up_lim = trial[i]
			m_s = 0.01
			### Exp starts
			sta_timer()
			
			
			
			final_p = 0
			timer1 = vizact.ontimer(0,UpdateView(m_s, a, up_lim))
			vizact.ontimer(0,UpdateView(m_s, a, up_lim))
			while final_p < 30:
				startTime = viz.tick()
				timer1.setEnabled(viz.ON)
				pp, ss = UpdateView(m_s, a, up_lim)
				final_p = pp[2]
				final_s = ss

			timer1.setEnabled(viz.OFF)
			yield viz.waitTime(3)
			
			### data record

			

		#viz.OFF()
			
	viz.quit()
viztask.schedule(Sct_dis())
Reply With Quote
Reply

Tags
pretrans, scene load, touch controller

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

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 Touch Controller Buttons iamnoone87 Vizard 1 06-21-2019 06:26 AM
steamvr controller for htc vive unresponsive zumbay Vizard 2 05-25-2018 11:02 PM
Oculus Rift DK2 + gamepad controller rdkirkden Vizard 4 07-17-2017 02:27 AM
Touch functionality Joran Vizard 4 04-25-2012 08:51 AM


All times are GMT -7. The time now is 09:30 PM.


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