WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rating: Thread Rating: 6 votes, 5.00 average. Display Modes
  #1  
Old 05-20-2013, 12:27 PM
jacky jacky is offline
Member
 
Join Date: Jun 2011
Posts: 13
Mainview can't go back to original point

Hi all,

I created two boxes. One box connected to the sensor with 3DOF orientation and the other one connected to the Mainview. I linked the two boxes with function viz.grab(). The mouse's buttons were used to make mainview forward or backward along the direction of mainview. The space key was used to make the boxes back to the original point with positions (0,0,0) and euler (0,0,0). But it did not work. I didn't the reason. If someone know, please tell me. Thanks very much.

Code:
"""
key commands:
	r						- reset the position and orientation of mainview,
							  place the mainview at the original point
	mouse's left button	    - move the mainview forward 
	mouse's right button	- move the mainview backward
	up array				- move the mainview forward
	down array			    - move the mainview backward
	4						- move the mainview forward
	1						- move the mainview backward
	5						- move the mainview up along the +Y axis( increase eyeheight)
	2						- move the mainview down along the -Y axis(decrease eyeheight)

"""

import viz
import vizact
import math
import vizinput

viz.setMultiSample(4)
eyeheight=1.65
viz.eyeheight(eyeheight)

#sensor_place=['Sensor facing FORWARD','Sensor facing LEFT']
#place=vizinput.choose('Select Sensor Config',sensor_place)

display_mode=['2D_Fullscreen','Sony Hmz-T1']
i = vizinput.choose('Select Display Mode', display_mode )
if i==0:
	viz.go()
else:
	viz.go(viz.FULLSCREEN)
	import sony
	hmd=sony.HMZT1()


#load the 3 space sensor information
import threespace_api as ts_api
device_list, unknown_list = ts_api.getAvailableComPorts()
for device_port in device_list:
	com_port, friendly_name, device_type=device_port
	if device_type=="USB":
		device=ts_api.TSSensor(com_port=com_port)
	elif device_type=='DNG':
		device=ts_api.TSDongle(com_port=com_port)
		#device=dng_device[0]
	elif device_type=='WL':
		device=ts_api.TSWLSensor(com_port=com_port)

#load the environment model
environment=viz.addChild('gallery.osgb')

#make mouse invisible and activate mainview's collision
viz.mouse.setVisible(viz.OFF)
viz.mouse.setOverride()
viz.MainView.collision(viz.ON)
viz.MainView.collisionBuffer(0.5)
#viz.MainView.gravity(0)
	
box_scale=0.0001
box_pos=[0,eyeheight,0] #box1 and box2 must be in the same position

box2_sensor=viz.addChild('crate.osgb') #link box2 to 3 space sensor
box2_sensor.setPosition(box_pos)
box2_sensor.setScale([box_scale]*3)

box1_view=viz.addChild('crate.osgb') 
box1_view.setPosition(box_pos)
box1_view.setScale([box_scale]*3)

#link mainview to box1 in Vizard
link2=viz.link(box1_view,viz.MainView) 

#link box1 to box2
link=viz.grab( box2_sensor, box1_view )

#reset the mainview to the original position
def reset_mainview():
    global link,link2
    link2.remove()
    link.remove()
    link=None
    link2=None
    pos=environment.getPosition()
    pos[1]=pos[1]+eyeheight
    euler=environment.getEuler()
    box1_view.setPosition(pos)
    box1_view.setEuler(euler)
    box2_sensor.setPosition(pos)
    #viz.MainView.setPosition(0,0,0)
    #viz.MainView.setEuler(0,0,0)
    link2=viz.link(box1_view,viz.MainView,srcFlag=viz.ABS_GLOBAL)
    link=viz.grab(box2_sensor,box1_view)


vizact.onkeydown(' ',reset_mainview)

degree=180/math.pi
#link the rotation of mainview to the 3 space sensor.
#def connect_USB_Forward():
#	sensor_euler=device.getFiltTaredOrientEuler() #[pitch,yaw,roll] in radians
#	yaw=sensor_euler[1]*degree
#	pitch=sensor_euler[0]*degree
#	roll=sensor_euler[2]*degree
#	box2_sensor.setEuler(yaw,-pitch,-roll)

#link the rotation of mainview to the 3 space sensor every frame
def connect():
	sensor_euler=device.getFiltTaredOrientEuler() #[pitch,yaw,roll] in radians
	yaw=sensor_euler[1]*degree
	pitch=sensor_euler[0]*degree
	roll=sensor_euler[2]*degree
	box2_sensor.setEuler(yaw,pitch,roll)


vizact.ontimer(0,connect)

#move the mainview along the view direction
param=0.02 # the step of increase or decrease distance 

def move_forward():
	pos=viz.MainView.getPosition()
	yaw=viz.MainView.getEuler()[0]*(math.pi)/180
	#pos=box1_view.getPosition()
	#yaw=box1_view.getEuler()[0]*(math.pi)/180
	cos=math.cos(yaw)
	sin=math.sin(yaw)
	pos[2]=pos[2]+param*cos
	pos[0]=pos[0]+param*sin
	viz.MainView.setPosition(pos)

def move_backward():
	pos=viz.MainView.getPosition()
	yaw=viz.MainView.getEuler()[0]*(math.pi)/180
	cos=math.cos(yaw)
	sin=math.sin(yaw)
	pos[2]=pos[2]-param*cos
	pos[0]=pos[0]-param*sin
	viz.MainView.setPosition(pos)
	
#move the mainview along y axis

vizact.whilemousedown(viz.MOUSEBUTTON_LEFT,move_forward)
vizact.whilemousedown(viz.MOUSEBUTTON_RIGHT,move_backward)

vizact.onkeydown(viz.KEY_UP,move_forward)
vizact.onkeydown(viz.KEY_DOWN,move_backward)
vizact.onkeydown('4',move_forward)
vizact.onkeydown('1',move_backward)
If I changed the function move_forward() like below, It also didn't work and the mouse's button can't work either.

Code:
def move_forward():
	pos=box1_view.getPosition()
	yaw=box1_view.getEuler()[0]*(math.pi)/180
	cos=math.cos(yaw)
	sin=math.sin(yaw)
	pos[2]=pos[2]+param*cos
	pos[0]=pos[0]+param*sin
	box1_view.setPosition(pos)
	box2_sensor.setPosition(pos)
Reply With Quote
  #2  
Old 06-04-2013, 05:22 AM
Frank Verberne Frank Verberne is offline
Member
 
Join Date: Mar 2008
Location: Netherlands
Posts: 148
As far as I can see, you commented out the two most important lines of reset_mainview(), namely:
#viz.MainView.setPosition(0,0,0)
#viz.MainView.setEuler(0,0,0)
Have you tried deleting the comments signs (#)?
Reply With Quote
Reply


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
3ds Exported .IVE Model mirrors movement of Mainview Felix Vizard 9 05-18-2012 10:17 AM
MainView and getEuler shivanangel Vizard 1 01-20-2012 11:31 AM
Link MainView to instable platform sleiN13 Vizard 2 01-10-2011 01:33 AM
data glove navigation arielasso Vizard 6 10-24-2007 03:15 PM
looking at a point vadrian Vizard 5 06-07-2005 06:43 PM


All times are GMT -7. The time now is 01:16 AM.


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