View Single Post
  #5  
Old 02-11-2004, 10:11 AM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
Hi Luca,

1) I understand now. Try the following code. When you press the 'g' key the viewpoint will be given a forward velocity of 1 meter/second. Then I start a timer that will expire in 5 seconds. When that timer expires it will set the velocity back to 0, thus the viewpoint will have moved 5 meters forward. Hope that makes sense
Code:
import viz
viz.go()

STOP_MOVING = 0

def mytimer(num):
	
	if num == STOP_MOVING:
		viz.velocity(0,0,0)
	
	
def mykeyboard(key):
	
	if key == 'g':
		viz.velocity(0,0,1)
		viz.starttimer(STOP_MOVING,5)
	
viz.callback(viz.KEYBOARD_EVENT,mykeyboard)
viz.callback(viz.TIMER_EVENT,mytimer)
2) It's not really a bug of python. Floating point numbers are just inherently imprecise. This same type of error will occur in the C language, which python is based around. If you always need that sort of accuracy then you should probably round it.

3) I think so too, thanks FlyingWren!
Reply With Quote