#1
|
|||
|
|||
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 |
#2
|
|||
|
|||
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) |
#3
|
|||
|
|||
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 |
#4
|
|||
|
|||
Hi,
I'm not sure why you are getting that error. Try the following: Code:
time.sleep(float(0.1)) |
#5
|
|||
|
|||
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) |
#6
|
|||
|
|||
Hi,
To attach the shadow to the ball you would do the following: Code:
ball = viz.add('ball.wrl') shadow = ball.add('shadow.wrl') Code:
shadow.parent(ball) |
#7
|
|||
|
|||
Thank you, this works!
|
#8
|
|||
|
|||
Hi,
Is it correct if I conceptualize the director-function similar to starting a thread in Java? Johannes Quote:
|
#9
|
|||
|
|||
Hi,
Yes, the director function is basically a thread. |
|
|