filmore
23-05-2011 17:05:22
I'm trying to use Bullet physics and collision detection in my project, but I'm having some issues. Since all the documentation and bullet forums have C++ examples, I try and translate it to Python. I am unable to translate this snippet, though which will allow me to detect collisions
Specifically the lines with the 'static_cast'.
I modified a bit and came up with this code which works if I comment the obA and obB lines. However, I need those to specify the two objects that I'm interested in. I get this error when they are uncommented - "TypeError: No to_python (by-value) converter found for C++ type: void const *"
Another issue I have is that the setUserPointer method doesn't seem to work. I get this error for it - "AttributeError: 'btRigidBody' object has no attribute 'setUserPointer'"
//Assume world->stepSimulation or world->performDiscreteCollisionDetection has been called
int numManifolds = world->getDispatcher()->getNumManifolds();
for (int i=0;i<numManifolds;i++)
{
btPersistentManifold* contactManifold = world->getDispatcher()->getManifoldByIndexInternal(i);
btCollisionObject* obA = static_cast<btCollisionObject*>(contactManifold->getBody0());
btCollisionObject* obB = static_cast<btCollisionObject*>(contactManifold->getBody1());
int numContacts = contactManifold->getNumContacts();
for (int j=0;j<numContacts;j++)
{
btManifoldPoint& pt = contactManifold->getContactPoint(j);
if (pt.getDistance()<0.f)
{
const btVector3& ptA = pt.getPositionWorldOnA();
const btVector3& ptB = pt.getPositionWorldOnB();
const btVector3& normalOnB = pt.m_normalWorldOnB;
}
}
}
Specifically the lines with the 'static_cast'.
I modified a bit and came up with this code which works if I comment the obA and obB lines. However, I need those to specify the two objects that I'm interested in. I get this error when they are uncommented - "TypeError: No to_python (by-value) converter found for C++ type: void const *"
for i in range(numManifolds):
contactManifold = dispatcher.getManifoldByIndexInternal(i)
obA = contactManifold.getBody0()
obB = contactManifold.getBody1()
numContacts = contactManifold.getNumContacts()
for j in range(numContacts):
pt = contactManifold.getContactPoint(j)
if (pt.getDistance()<0):
print "collision"
Another issue I have is that the setUserPointer method doesn't seem to work. I get this error for it - "AttributeError: 'btRigidBody' object has no attribute 'setUserPointer'"