WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   Push a button (https://forum.worldviz.com/showthread.php?t=2169)

snoopy78 07-20-2009 01:20 AM

Push a button
 
Hi,

I want to push a button with my mouse and afterthat my object should rotate for a special amount.

This works, but I had to push the button again and again.

Code:

def onButton(obj,state):
  if obj == scene3.btnLeftRotate1:
    if state == viz.DOWN:
      object1.rotate(-1,0,0,'',viz.RELATIVE_LOCAL)

viz.callback(viz.BUTTON_EVENT,onButton)


I want to push the button one-time with my mouse and as long as I hold the button pressed, the object should move on and on.

farshizzo 07-20-2009 09:39 AM

You can use the vizact library to enable a timer while the button is down. Here is a simple script showing how to do this:
Code:

import viz
import vizact
viz.go()

# Create model
model = viz.add('logo.ive',pos=(0,1,5))

# Create function to rotate model
def RotateModel():
        model.setEuler(90*viz.elapsed(),0,0,viz.REL_LOCAL)
       
# Create disabled timer to call RotateModel function
rotateTimer = vizact.ontimer(0,RotateModel)
rotateTimer.setEnabled(False)

# Create button
rotateButton = viz.addButton(pos=(0.9,0.1,0))

# Enable rotate timer while button is pressed
vizact.onbuttondown(rotateButton,rotateTimer.setEnabled,True)
vizact.onbuttonup(rotateButton,rotateTimer.setEnabled,False)



All times are GMT -7. The time now is 05:16 PM.

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