28 #include "BulletDynamics/Dynamics/btRigidBody.h"
29 #include "BulletCollision/CollisionShapes/btCollisionShape.h"
30 #include "BulletCollision/CollisionDispatch/btCollisionWorld.h"
41 #define SKIP_CONTACT_UPDATE
49 btPersistentManifold* m) :
54 attachedRelativeOriginalPosition(attachedBody->getWorldTransform().inverse() *
57 contactNormal(attachedBody->getWorldTransform().inverse().getBasis() * cn),
66 assert(manifold == NULL || body == manifold->getBody0() || body == manifold->getBody1());
78 const btTransform tr =
attachedBody->getWorldTransform();
79 const btVector3 worldPos = tr * attachedRelativeOriginalPosition;
80 return worldPos-this->
attachedBody->getCenterOfMassPosition();
85 const btTransform tr =
attachedBody->getWorldTransform();
86 return tr * attachedRelativeOriginalPosition;
106 btScalar length = INFINITY;
108 int n = manifold->getNumContacts();
111 btVector3 newNormal = contactNormal;
115 for (
int p = 0; p < n; p++)
117 const btManifoldPoint& pt = manifold->getContactPoint(p);
120 btVector3 pos = useB ? pt.m_positionWorldOnA : pt.m_positionWorldOnB;
122 btScalar contactDist = (pos - newPos).length();
124 if (contactDist < length)
126 length = contactDist;
129 btScalar directionSign = useB ? btScalar(1.0) : btScalar(-1.0);
132 newNormal =
attachedBody->getWorldTransform().inverse().getBasis() * pt.m_normalWorldOnB * directionSign;
134 newNormal = pt.m_normalWorldOnB * directionSign;
136 dist = pt.getDistance();
141 std::cout <<
"Extra contacts!! " << p <<
" " << dist << std::endl;
160 attachedRelativeOriginalPosition =
attachedBody->getWorldTransform().inverse() *
163 if ((newNormal + contactNormal).length() < 0.5)
166 std::cout<<
"Reversed normal" << std::endl;
175 #ifndef SKIP_CONTACT_UPDATE
176 contactNormal = newNormal;
189 std::cout <<
"Manifold out of date!" << std::endl;
196 std::cerr <<
"Tried to update a static anchor" << std::endl;
207 const btTransform tr =
attachedBody->getWorldTransform();
208 btVector3 newNormal = (tr.getBasis() * contactNormal);
209 newNormal = newNormal.length() > 0.0 ? newNormal.normalize() : btVector3(0.0, 0.0, 0.0);
213 return contactNormal;
225 btScalar newDist = manifoldValues.first;
231 std::cout <<
"Old manifold was NULL" << std::endl;
245 btVector3 newNormal = manifoldValues.second;
246 if ((newNormal + contactNormal).length() < 0.5)
249 std::cout <<
"Reversed normal during anchor update" << std::endl;
257 #ifndef SKIP_CONTACT_UPDATE
266 std::cout <<
"Failed to update manifold!" << std::endl;
277 btScalar length = INFINITY;
278 btVector3 newNormal = contactNormal;
289 int n = m->getNumContacts();
293 for (
int p = 0; p < n; p++)
295 const btManifoldPoint& pt = m->getContactPoint(p);
298 btVector3 pos = useB ? pt.m_positionWorldOnA : pt.m_positionWorldOnB;
302 if (contactDist < length)
304 length = contactDist;
307 btScalar directionSign = useB ? btScalar(1.0) : btScalar(-1.0);
312 newNormal =
attachedBody->getWorldTransform().inverse().getBasis() * pt.m_normalWorldOnB * directionSign;
314 newNormal = pt.m_normalWorldOnB * directionSign;
318 dist = pt.getDistance();
322 std::cout <<
"Extra contacts!! " << p <<
" length " << length <<
" dist: " << dist << std::endl;
333 return std::make_pair<btScalar, btVector3> (length, newNormal);
virtual ~tgBulletSpringCableAnchor()
tgBulletSpringCableAnchor(btRigidBody *body, btVector3 pos, btVector3 cn=btVector3(0.0, 0.0, 0.0), bool perm=true, bool slide=false, btPersistentManifold *m=NULL)
virtual btVector3 getWorldPosition() const
btRigidBody *const attachedBody
bool updateManifold(btPersistentManifold *m)
Definitions of class tgBulletSpringCableAnchor, formerly muscleAnchor.
std::pair< btScalar, btVector3 > getManifoldDistance(btPersistentManifold *m) const
virtual btVector3 getContactNormal() const
virtual btVector3 getRelativePosition() const
virtual bool setWorldPosition(btVector3 &newPos)