Hi,
Can you try out the following sample script. It is a really simple script that has a ball bouncing around the room you are using. The calculations are done inside a director function. Let me know if this works for you.
Code:
import viz
import vizmat
viz.go()
myroom = viz.add('room.wrl')
ball = viz.add('ball.wrl')
myroom.collidemesh()
ball.collidesphere(0.25)
ball.vector = viz.Vector(1,1,1)
ball.translate(0,1,0)
def moveball():
while 1:
#Perform the collision check with the room
info = ball.collidingwith(myroom,1)
if info.intersected:
#Set the balls new vector to the reflection vector
ball.vector = viz.Vector(vizmat.ReflectionVector(ball.vector,info.normalVector))
#Create a vector of the normal of the collision
normal = viz.Vector(info.normalVector)
#Check dot product of velocity and normal
if ball.vector * normal < 0:
ball.vector *= -1
#Get the balls current position
pos = ball.get(viz.POSITION)
#Calculate the balls future position based on its velocity
futurePos = pos + (ball.vector * 0.02)
ball.translate(futurePos.get())
viz.waittime(0.01)
viz.director(moveball)