WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 10-11-2006, 03:56 PM
Jerry Jerry is offline
Member
 
Join Date: Jun 2004
Posts: 105
Intersect vs collision

Is it more efficient framewise to detect collisions with viz.intersect()
or physics collide callbacks?
Reply With Quote
  #2  
Old 10-11-2006, 05:04 PM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
viz.intersect() is different from physics collision callbacks. viz.intersect() returns collisions over a line. The physics callbacks are triggered when two objects collide. So it depends on what you need.

If you need line intersection tests, then viz.phys.intersectLine() will be much faster than viz.intersect. However, viz.phys.intersectLine() only returns results for objects that are part of the physics simulation. So you must define a collision volume for each node that should take part in the intersection test.

If you want know when two objects are colliding then you have two options. Use the physics collision callbacks. You must explicitly enable collision notifications for each object that you are interested in:
Code:
node.enable(viz.COLLIDE_NOTIFY)
Look at the duckcourt script for an example. The other option is to use the viz.phys.intersectNode command. This will return a list of all the nodes an object is colliding with. However, similar to the viz.phys.intersectLine() command, it only checks for collisions with objects that are part of the physics simulation.

In general it is more efficient to handle collision callbacks than to manually query for intersections every frame.
Reply With Quote
  #3  
Old 10-11-2006, 08:09 PM
Jerry Jerry is offline
Member
 
Join Date: Jun 2004
Posts: 105
line touching cylinder

I am trying to detect when an on the fly line is in contact
with a cylinder. Which method would be most efficient?
Reply With Quote
  #4  
Old 10-11-2006, 08:21 PM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
In this case collision callbacks won't work, so you need to manually call the intersect function yourself.
Reply With Quote
  #5  
Old 10-12-2006, 11:24 AM
Jerry Jerry is offline
Member
 
Join Date: Jun 2004
Posts: 105
FYI the collision callback method does work with an on-the-fly line if you
specify .collideBox(). It doesn't work with .collideMesh().
Reply With Quote
  #6  
Old 07-12-2007, 05:21 PM
mjabon mjabon is offline
Member
 
Join Date: Jul 2007
Posts: 63
Quote:
Originally Posted by farshizzo View Post
In this case collision callbacks won't work, so you need to manually call the intersect function yourself.
Why? Will the collision callbacks work while dragging something with the HD? That's what I'm trying to do....
Reply With Quote
  #7  
Old 07-13-2007, 12:39 PM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
Yes, the callbacks will still work when you are dragging an object. Like I mentioned above, you will need to explicitly enable collision notifications on an object for a callback to be triggered.
Reply With Quote
  #8  
Old 07-16-2007, 03:27 PM
mjabon mjabon is offline
Member
 
Join Date: Jul 2007
Posts: 63
Quote:
Originally Posted by farshizzo View Post
Yes, the callbacks will still work when you are dragging an object. Like I mentioned above, you will need to explicitly enable collision notifications on an object for a callback to be triggered.
I have enabled collision on everything but it still never registers the callback. I did this:

made a bunch of screws and said this for each one:
Code:
screw.collideCapsule()
screw.enable(viz.COLLIDE_NOTIFY)
I also made a box:
Code:
currentBox.collideMesh()					#make a collision mesh so we know when screws hit it
currentBox.enable(viz.COLLIDE_NOTIFY)
Then I did this:

Code:
def onCollide(e):
	print "collision!"
	global allM1Screws, allM2Screws
	#Did a screw hit the box?
	if ((e.obj2 in allM1Screws) or (e.obj2 in allM2Screws)):
		#Change color of box
		e.obj1.color( random.choice( [viz.RED,viz.GREEN,viz.SKYBLUE,viz.YELLOW,viz.ORANGE,viz.PURPLE] ) )

        
viz.callback( viz.COLLIDE_BEGIN_EVENT, onCollide )


viz.collision(viz.ON)
I never enter the collision callback code

Last edited by mjabon; 07-16-2007 at 03:28 PM. Reason: forgot something
Reply With Quote
  #9  
Old 07-17-2010, 02:57 AM
dwaik dwaik is offline
Member
 
Join Date: Feb 2010
Posts: 26
try doing this
currentBox.collideMesh()
currentBox.enable(viz.COLLIDE_NOTIFY)
currentBox.enable(viz.CONTACTS)
hope that was helpfull
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 02:11 PM.


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