WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 09-16-2004, 11:17 AM
ChrisB ChrisB is offline
Member
 
Join Date: May 2004
Location: Hamilton, Ontario
Posts: 4
Send a message via ICQ to ChrisB
Viewpoint Manipulation

Hi,

I'm working on an experiment in vizard where I want the user to be stationary in the environment, and only be able to rotate left and right to survey the room. I want to use the left and right arrow keys to control the rotation, but I find that when using a callback function to adjust the viewpoint angle on a keypress, the program runs too choppy . What I have is something similar to this:

def GetUserInput(input):
global myView
global angle
if input == viz.KEY_LEFT:
angle = angle - 1
myView.rotate(0,1,0,angle)
elif input == viz.KEY_RIGHT:
angle = angle + 1
myView.rotate(0, 1, 0, angle)

Increasing the angle of rotation makes it faster but choppier. I went through some of the help files, and it recommended the use of the viz.iskeydown() for when a user would be holding down a key. I was hoping to use something like this:

while viz.iskeydown(viz.KEY_LEFT) == 1:
angle = angle - 2
myView.rotate(0,1,0,angle/delayfactor)

(or alternatively a spinto option)

but when this happens there seems to be some blocking occuring, it waits until you have released the direction key, before rotating the viewpoint afterwards, with the amount of rotation depending on how long you held the key down for.

Maybe I am totally going about this the wrong way though, is there an easier method, or am I just missing something? I tried putting the while loop in a director function as well thinking that would not be blocking but it had the same effect, the screen only rotates after you release the key, not while you're holding it down.
Reply With Quote
  #2  
Old 09-16-2004, 11:25 AM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
Hi,

The trick is to use a timer to check if the key is down. Here's some sample code:
Code:
view = viz.get(viz.MAIN_VIEWPOINT)
ROTATION_SPEED = 20.0 #Degrees/second

def ontimer(num):
	if viz.iskeydown(viz.KEY_RIGHT):
		view.rotate(0,1,0,ROTATION_SPEED*viz.elapsed(),viz.HEAD_ORI,viz.RELATIVE_LOCAL)
	elif viz.iskeydown(viz.KEY_LEFT):
		view.rotate(0,1,0,-ROTATION_SPEED*viz.elapsed(),viz.HEAD_ORI,viz.RELATIVE_LOCAL)

viz.callback(viz.TIMER_EVENT,ontimer)
viz.starttimer(0,0.01,viz.FOREVER)
Reply With Quote
Reply

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


All times are GMT -7. The time now is 04:10 PM.


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