WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 09-27-2009, 12:14 PM
vTony vTony is offline
Member
 
Join Date: Sep 2008
Posts: 7
Setting Collidebox Dimensions

Hello, I am trying to manually set the dimensions of an object's collidebox. As a simple test, I tried setting the dimensions of the collidebox to the size of the object's bounding box. This works for box.wrl, but with the file tree.3ds (located at https://www.stanford.edu/~tony516/tree.3DS), I get strange results. The tree on the left (which uses the default arguments for collidebox, behaves normally, but the tree on the right shoots up into the air.

Quote:
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()
tree2.collidebox(tree2.getBoundingBox())

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)
Thanks in advance for any help!

Last edited by vTony; 09-27-2009 at 12:17 PM.
Reply With Quote
  #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
  #3  
Old 09-29-2009, 02:57 PM
vTony vTony is offline
Member
 
Join Date: Sep 2008
Posts: 7
That fixed it. Thanks!
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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Tiling in a cluster setting vijaykiran Vizard 5 10-30-2009 11:41 AM
problem in setting the orientation of bones bharatbhushan Vizard 0 06-30-2009 04:30 AM
error while setting material properties. Chandan Vizard 1 10-25-2006 09:31 AM
Setting the viewpoint with tracking VAmanda Vizard 3 10-26-2005 02:02 PM
Setting up a 'reaction area' Karthi Vizard 4 01-29-2004 04:39 PM


All times are GMT -7. The time now is 02:57 AM.


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