-
Hi, I was trying to use the Collision Manager to compute the collision between two objects (as a toy example) sphere = fcl.Sphere(0.1)
sphere_obj = fcl.CollisionObject(sphere)
M_sphere = fcl.Transform3f.Identity()
box = fcl.Box(6.0, 4.0, 1.0)
box_obj = fcl.CollisionObject(box)
M_box = fcl.Transform3f.Identity()
M_box.setTranslation(np.array([0.0, 1.0, 0.0]))
box_obj.setTransform(M_box)
collision_manager = fcl.DynamicAABBTreeCollisionManager()
collision_manager.registerObject(box_obj)
collision_manager.setup()
# first scenario
callback = fcl.CollisionCallBackDefault()
M_sphere.setTranslation(np.array([1, 2, 0.0]))
sphere_obj.setTransform(M_sphere)
collision_manager.collide(sphere_obj, callback)
is_collision = callback.data.result.isCollision()
print("Is collision: ", is_collision)
# second scenario
callback.data.result.clear()
M_sphere.setTranslation(np.array([4, 2, 0.0]))
sphere_obj.setTransform(M_sphere)
collision_manager.collide(sphere_obj, callback)
is_collision = callback.data.result.isCollision()
print("Is collision: ", is_collision)
# third scenario
callback.data.result.clear()
M_sphere.setTranslation(np.array([1, 2, 0.0]))
sphere_obj.setTransform(M_sphere)
collision_manager.collide(sphere_obj, callback)
is_collision = callback.data.result.isCollision()
print("Is collision: ", is_collision) However, I get the collision results as "True, False, False". Since the third scenario is the same as the first scenario the output should be "True, False, True". Can someone help me understand what is wrong in the code? When I create a new Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hi @lwygzh, callback.data.result.clear()
callback.data.done = False I will do a PR on the Best, Edit: This is the PR: #509 |
Beta Was this translation helpful? Give feedback.
Hi @lwygzh,
Thank you for checking out hppfcl!
The broadphase collision callback has a boolean field,
done
which tells whether or not the process of collision detection should continue or not.When resetting the callback, you should therefore do:
I will do a PR on the
devel
branch to have acallback.data.clear()
method which handles both clearing the collision result and the boolean.Best,
Louis
Edit: This is the PR: #509
With it, you won't have to call
clear
for the callback's data as it will be automatically cleared by the broadphase manager when callingmanager.collide(callback)
.