WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rating: Thread Rating: 2 votes, 5.00 average. Display Modes
  #1  
Old 01-11-2005, 06:02 AM
Johannes Johannes is offline
Member
 
Join Date: Jan 2005
Posts: 143
Tried your example. Works, but it is only good for the case of one ball. Tried to change it (see below) to fit the more general purpose of more balls and objects:

I added after ball.translate(0,1,0):

collidables=[]
collidables.append(myroom)
collidables.append(ball)



I repaced info = ball.collidingwith(myroom,1) with

for objects in collidables:
#Perform the collision check with the object
info = ball.collidingwith(object,1)

and adjusted the indent.
Does not work.
Best,
Johannes

Here is the full changed Program
import viz
import vizmat

viz.go()

myroom = viz.add('../resources/models/room.wrl')
ball = viz.add('../resources/models/ball.wrl')


myroom.collidemesh()
ball.collidesphere(0.25)
ball.vector = viz.Vector(1,1,1)
ball.translate(0,1,0)

collidables=[]
collidables.append(myroom)
collidables.append(ball)

def moveball():
while 1:
info = ball.collidingwith(myroom,1)
#Perform the collision check with the room
if info.intersected:
#Set the balls new vector to the reflection vector
ball.vector = viz.Vector(vizmat.ReflectionVector(ball.vector,inf o.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
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 11:27 AM.


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