SOS! collision detection by bulletworld using C++


#1

last days I tried to use bullet in panda3d for collision detection.
Temporarily, I only need to know if two particular solids are contacted. (when they contacted, print a number is enough).
But I’m not familiar with both panda3d and bullet, and the C++ reference for bulletworld in panda3d main page is not very full, I use the following codes but it did not work well.

BulletContactResult br = physics_world->contact_test_pair(base1, wrist1);

int a = br.get_num_contacts();
cout << a << endl;

base1 and wrist1 are two PT(BulletRigidBodyNode) transformed from my model NodePath.
In my expectations, int a will be the number of the contacts of base1 and wrist1. And if a==0, they do not contatct. if a!=1, they contact.

But maybe I fully misunderstand the meaning of the function get_num_contacts()? the return number of a is unexpected. The value can be 1072,1399,983… and is much larger than my expect. (and seems associated with my original pos of base1 and wrist1)

Therefore, I think I misunderstand the function. So, what’s the correct mean? or is there any approach easier to realize the simple collision detection?

Please help,
Thanks in advance.


#2

ah ha, I solved the problem.
It’s a mistake.
My understanding of the function get_num_contacts() is true, and everything actually is correct.
The main problem is my misunderstanding of set_scale.
For a better view, I do set_scale for my two model at first and therefore they seems absolutely can’t contact at all. However, the real GeomNode of them, seems aren’t influenced by set_scale, is contacted. That’s the reason why I got values from get_num_contacts().

So, be careful to use set_scale, and get_num_contacts is a feasible way to do collision detection.

Continue to enjoy my panda3d, haha