View Single Post
  #2  
Old 06-27-2012, 01:32 PM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
There is no built-in torus shape in the physics engine, but you can approximate one using multiple sphere shapes. Here is a sample script that simulates a torus using 18 spheres:
Code:
import viz
import math
import vizact
import vizshape

viz.go()

viz.phys.enable()

ground = viz.addChild('ground.osgb')
ground.collidePlane()

RADIUS = 1.0
TUBE_RADIUS = 0.5

torus = vizshape.addTorus(radius=RADIUS,tubeRadius=TUBE_RADIUS)
for deg in range(0,360,20):
	x = math.sin(viz.radians(deg)) * RADIUS
	z = math.cos(viz.radians(deg)) * RADIUS
	torus.collideSphere(radius=TUBE_RADIUS,pos=(x,0,z))

ball = vizshape.addSphere(radius=0.6)
ball.collideSphere()

def Reset():
	torus.setPosition([0,2,10])
	ball.setPosition([0.6,5,10.6])

vizact.onkeydown('r',Reset)

Reset()
Reply With Quote