WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

 
 
Thread Tools Rating: Thread Rating: 2 votes, 5.00 average. Display Modes
Prev Previous Post   Next Post Next
  #10  
Old 01-10-2005, 04:51 PM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
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)
Reply With Quote
 

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 03:00 AM.


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