WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   Move Objects (https://forum.worldviz.com/showthread.php?t=263)

Johannes 01-06-2005 11:00 AM

Move Objects
 
Hi,
I'm trying to move a ball through a room.
I know that there are certain built in functions to move it, but as I want to be very flexible I want / have to write my own movement-function.

def moveIt2():
for i in range(1,10):
print 'hallo',i
x=x0+i*0.01
y=y0+i*0,03
ball.translate(x,y,6)
i=i+1
time.sleep(0.1)

But it does not seem to work.

Without the ball.translate(x,y,6) the Function seems to work. But it prints out the numbers as a whole after in this case 1 seconds

What would you recommend for moving an object?

I know about ball.goto(3,3,6,5) or the timer-funktion-based movement. But as I want to slow down the motion sometimes (and not change speed) I will need my own timer - this is why I tried the sleep-command.

Thank you,
Johannes

farshizzo 01-06-2005 11:12 AM

Hi,

Are you executing your moveIt2 function as a director function? If not then your function will stall the graphics frame until it is finished. To execute your code as a director function do the following:
Code:

viz.director(moveIt2)
This will execute your function asynchronously. Whenever you call the sleep command outside of a director function or thread you are effectively causing the graphics loop to sleep also.

Johannes 01-06-2005 12:50 PM

Thank you for answering so fast!

But I still get an error for the sleep-command:

Traceback (most recent call last):
File "basic_test1.py", line 41, in moveIt2
time.sleep(0.1)
TypeError: a float is required

farshizzo 01-06-2005 12:58 PM

Hi,

I'm not sure why you are getting that error. Try the following:
Code:

time.sleep(float(0.1))

Johannes 01-06-2005 01:34 PM

Found it, the error was at the line
y=y0+i*0,03
(Accidently a comma slipt in)


Short question to hierarchical Objects - guess (as I tried) this is not possible:

Say I want an object to move with it's shadow.

ball = viz.add('../resources/models/ball.wrl')
shadow = viz.add('../resources/models/shadow.wrl')
shadow.translate(0, 1, 0, viz.RELATIVE)
shadow.alpha(0.7)

shadowBall=ball.add(shadow)

farshizzo 01-06-2005 02:34 PM

Hi,

To attach the shadow to the ball you would do the following:
Code:

ball = viz.add('ball.wrl')
shadow = ball.add('shadow.wrl')

or you can leave it the way you have it but change the last line to the following:
Code:

shadow.parent(ball)

Johannes 01-07-2005 11:47 AM

Thank you, this works!

Johannes 01-19-2005 07:38 AM

Hi,
Is it correct if I conceptualize the director-function similar to starting a thread in Java?
Johannes

Quote:

Originally posted by farshizzo
Hi,

Are you executing your moveIt2 function as a director function? If not then your function will stall the graphics frame until it is finished. To execute your code as a director function do the following:
Code:

viz.director(moveIt2)
This will execute your function asynchronously. Whenever you call the sleep command outside of a director function or thread you are effectively causing the graphics loop to sleep also.


farshizzo 01-19-2005 10:15 AM

Hi,

Yes, the director function is basically a thread.


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

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