View Single Post
  #3  
Old 02-18-2010, 10:25 AM
jvacare1 jvacare1 is offline
Member
 
Join Date: Aug 2009
Posts: 6
still a little bit of odd behavior

So now the script turns velocity off when the mouse is disabled. That fixes the problem of residual velocity, but there is still a strange issue when the mouse is re-enabled. It is as if the mouse's left button state of being pressed is being remembered through the mouse disabling / re-enabling.

Normal mouse navigation occurs when the left mouse button is held and the mouse is moved. If the left mouse button is released, mouse navigation seems to stop.

The odd behavior after the mouse state is enabled is that the MainView behaves as though the left mouse button is being pressed, even though it is not. Whatever direction the mouse pointer happens to be relative to the MainView, the MainView moves / rotates in that direction. (e.g. if the mouse pointer happens to be to the right and above the MainView center, the MainView will navigate forward and spin to the right). This is occuring even though the mouse isn't being touched at the time. If I subsequently press the left mouse button, the MainView navigates normally, and when the button is released, it returns to normal behavior.

Since the mouse is being disabled while the left mouse button is pressed, my guess is that that key state is being preserved through the disabling.

Is there a way to manually change the script's awareness of the left mouse button state? Or is there a better way to do that?

Thanks,

Jason

Code:
import viz, viztask, random, time, re, os
viz.go()
viz.gravity(viz.ON)

def NavigationLockDown():
  viz.velocity(0,0,0)
  viz.mouse(viz.OFF)

def NavigationUnlock():
  viz.mouse(viz.ON)

def HotSpotHandler(id, x, y, z):
  NavigationLockDown()
  viztask.schedule(PerformTrialTask())

def InitiateHotSpot():
  viz.callback(viz.HOTSPOT_EVENT, HotSpotHandler)
  viz.starthotspot(3, viz.RECTANGLE_HOTSPOT_IN, 0, 4, 2, .5)

def PerformTrialTask():
  viz.MainView.goto([0, 1.82, 4])
  viz.MainView.lookat(PitCover.getPosition())
  d = viz.Data
  PROMPT_TEXT = viz.addText('What will you do?', viz.SCREEN, scene=1)
  PROMPT_TEXT.setScale([.5, .5, 1])
  PROMPT_TEXT.translate(0.05, 0.9)
  Keys = ('a', 'j')
  while True:
    yield viztask.waitKeyDown(Keys, d)
    if (d.key == 'j'):
      NavigationUnlock()
      return

    elif (d.key == 'a'):
      NavigationUnlock()
      return

InitiateHotSpot()
Reply With Quote