View Single Post
  #2  
Old 09-28-2009, 04:19 PM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
Please use the [code][/code] tags when posting code. It will preserve indentation which is necessary for running Python code.

Regarding your question, you need to reset the position of the tree before retrieving it's bounding box. Here is a modified version of your code:
Code:
import viz, vizact

def setOnGround(obj):
	ymin = obj.getBoundingBox().ymin
	pos = obj.getPosition()
	obj.setPosition(pos[0], pos[1]-ymin, pos[2])

def enablePhysics():
	viz.phys.enable()
	ground.collidePlane()
	tree1.collidebox()
	
	#Zero position before retrieving bounding box
	pos = tree2.getPosition()
	tree2.setPosition(0,0,0)
	
	#Get objects bounding box
	bb = tree2.getBoundingBox()
	
	#Restore position
	tree2.setPosition(pos)
	
	#Use bounding box for collision
	tree2.collidebox(bb.size,pos=bb.center)

viz.go()
viz.clearcolor(viz.SKYBLUE)
viz.MainView.move(0,0,-15)
ground = viz.add('tut_ground.wrl')
tree1 = viz.add('tree.3ds')
tree2 = viz.add('tree.3ds')
tree1.scale([.2]*3)
tree2.scale([.2]*3)
tree1.setPosition(-10, 0, 15)
tree2.setPosition(10, 0, 15)
setOnGround(tree1)
setOnGround(tree2)
vizact.onkeydown('1', enablePhysics)
Reply With Quote