WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   Intersect vs collision (https://forum.worldviz.com/showthread.php?t=783)

Jerry 10-11-2006 02:56 PM

Intersect vs collision
 
Is it more efficient framewise to detect collisions with viz.intersect()
or physics collide callbacks?

farshizzo 10-11-2006 04:04 PM

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.

Jerry 10-11-2006 07:09 PM

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?

farshizzo 10-11-2006 07:21 PM

In this case collision callbacks won't work, so you need to manually call the intersect function yourself.

Jerry 10-12-2006 10:24 AM

FYI the collision callback method does work with an on-the-fly line if you
specify .collideBox(). It doesn't work with .collideMesh().

mjabon 07-12-2007 04:21 PM

Quote:

Originally Posted by farshizzo (Post 3168)
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....

farshizzo 07-13-2007 11:39 AM

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.

mjabon 07-16-2007 02:27 PM

Quote:

Originally Posted by farshizzo (Post 4196)
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

dwaik 07-17-2010 01:57 AM

try doing this
currentBox.collideMesh()
currentBox.enable(viz.COLLIDE_NOTIFY)
currentBox.enable(viz.CONTACTS)
hope that was helpfull :D


All times are GMT -7. The time now is 11:28 AM.

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