WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 01-06-2005, 12:00 PM
Johannes Johannes is offline
Member
 
Join Date: Jan 2005
Posts: 143
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
Reply With Quote
  #2  
Old 01-06-2005, 12:12 PM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
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.
Reply With Quote
  #3  
Old 01-06-2005, 01:50 PM
Johannes Johannes is offline
Member
 
Join Date: Jan 2005
Posts: 143
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
Reply With Quote
  #4  
Old 01-06-2005, 01:58 PM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
Hi,

I'm not sure why you are getting that error. Try the following:
Code:
time.sleep(float(0.1))
Reply With Quote
  #5  
Old 01-06-2005, 02:34 PM
Johannes Johannes is offline
Member
 
Join Date: Jan 2005
Posts: 143
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)
Reply With Quote
  #6  
Old 01-06-2005, 03:34 PM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
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)
Reply With Quote
  #7  
Old 01-07-2005, 12:47 PM
Johannes Johannes is offline
Member
 
Join Date: Jan 2005
Posts: 143
Thank you, this works!
Reply With Quote
  #8  
Old 01-19-2005, 08:38 AM
Johannes Johannes is offline
Member
 
Join Date: Jan 2005
Posts: 143
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.
Reply With Quote
  #9  
Old 01-19-2005, 11:15 AM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
Hi,

Yes, the director function is basically a thread.
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 07:17 PM.


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