From a2a0b485ac66be452f7da84915a2de592e42eaaa Mon Sep 17 00:00:00 2001 From: enn0x Date: Thu, 16 May 2013 21:23:34 +0000 Subject: [PATCH] Bullet: experimental support for linear/angular soft body joints --- panda/src/bullet/bulletBodyNode.I | 22 ++++++++ panda/src/bullet/bulletSoftBodyNode.cxx | 67 ++++++++++++++++++++++++- panda/src/bullet/bulletSoftBodyNode.h | 16 ++++++ 3 files changed, 103 insertions(+), 2 deletions(-) diff --git a/panda/src/bullet/bulletBodyNode.I b/panda/src/bullet/bulletBodyNode.I index 655b731dbf..fbfa68d81d 100644 --- a/panda/src/bullet/bulletBodyNode.I +++ b/panda/src/bullet/bulletBodyNode.I @@ -217,6 +217,28 @@ set_friction(PN_stdfloat friction) { return get_object()->setFriction(friction); } +//////////////////////////////////////////////////////////////////// +// Function: BulletBodyNode::get_rolling_friction +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PN_stdfloat BulletBodyNode:: +get_rolling_friction() const { + + return get_object()->getRollingFriction(); +} + +//////////////////////////////////////////////////////////////////// +// Function: BulletBodyNode::set_rolling_friction +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE void BulletBodyNode:: +set_rolling_friction(PN_stdfloat friction) { + + return get_object()->setRollingFriction(friction); +} + //////////////////////////////////////////////////////////////////// // Function: BulletBodyNode::has_anisotropic_friction // Access: Published diff --git a/panda/src/bullet/bulletSoftBodyNode.cxx b/panda/src/bullet/bulletSoftBodyNode.cxx index e94dac9521..4441ad311c 100644 --- a/panda/src/bullet/bulletSoftBodyNode.cxx +++ b/panda/src/bullet/bulletSoftBodyNode.cxx @@ -680,7 +680,7 @@ append_anchor(int node, BulletRigidBodyNode *body, bool disable) { body->sync_p2b(); - btRigidBody *ptr =(btRigidBody *)body->get_object(); + btRigidBody *ptr = (btRigidBody *)body->get_object(); _soft->appendAnchor(node, ptr, disable); } @@ -698,7 +698,7 @@ append_anchor(int node, BulletRigidBodyNode *body, const LVector3 &pivot, bool d body->sync_p2b(); - btRigidBody *ptr =(btRigidBody *)body->get_object(); + btRigidBody *ptr = (btRigidBody *)body->get_object(); _soft->appendAnchor(node, ptr, LVecBase3_to_btVector3(pivot), disable); } @@ -1070,3 +1070,66 @@ make_tet_mesh(BulletSoftBodyWorldInfo &info, const char *ele, const char *face, return sbnode; } +//////////////////////////////////////////////////////////////////// +// Function: BulletSoftBodyNode::append_linear_joint +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void BulletSoftBodyNode:: +append_linear_joint(BulletBodyNode *body, int cluster, PN_stdfloat erp, PN_stdfloat cfm, PN_stdfloat split) { + + nassertv(body); + + btCollisionObject *ptr = body->get_object(); + + btSoftBody::LJoint::Specs ls; + ls.erp = erp; + ls.cfm = cfm; + ls.split = split; + ls.position = _soft->clusterCom(cluster); + + _soft->appendLinearJoint(ls, ptr); +} + +//////////////////////////////////////////////////////////////////// +// Function: BulletSoftBodyNode::append_linear_joint +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void BulletSoftBodyNode:: +append_linear_joint(BulletBodyNode *body, const LPoint3 &pos, PN_stdfloat erp, PN_stdfloat cfm, PN_stdfloat split) { + + nassertv(body); + + btCollisionObject *ptr = body->get_object(); + + btSoftBody::LJoint::Specs ls; + ls.erp = erp; + ls.cfm = cfm; + ls.split = split; + ls.position = LVecBase3_to_btVector3(pos); + + _soft->appendLinearJoint(ls, ptr); +} + +//////////////////////////////////////////////////////////////////// +// Function: BulletSoftBodyNode::append_angular_joint +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void BulletSoftBodyNode:: +append_angular_joint(BulletBodyNode *body, const LVector3 &axis, PN_stdfloat erp, PN_stdfloat cfm, PN_stdfloat split) { + + nassertv(body); + + btCollisionObject *ptr = body->get_object(); + + btSoftBody::AJoint::Specs as; + as.erp = erp; + as.cfm = cfm; + as.split = split; + as.axis = LVecBase3_to_btVector3(axis); + + _soft->appendAngularJoint(as, ptr); +} + diff --git a/panda/src/bullet/bulletSoftBodyNode.h b/panda/src/bullet/bulletSoftBodyNode.h index 30801dfd1c..2e0261c051 100644 --- a/panda/src/bullet/bulletSoftBodyNode.h +++ b/panda/src/bullet/bulletSoftBodyNode.h @@ -123,6 +123,22 @@ PUBLISHED: const LVector3 &pivot, bool disable=false); + // Links + void append_linear_joint(BulletBodyNode *body, int cluster, + PN_stdfloat erp=1.0, + PN_stdfloat cfm=1.0, + PN_stdfloat split=1.0); + + void append_linear_joint(BulletBodyNode *body, const LPoint3 &pos, + PN_stdfloat erp=1.0, + PN_stdfloat cfm=1.0, + PN_stdfloat split=1.0); + + void append_angular_joint(BulletBodyNode *body, const LVector3 &axis, + PN_stdfloat erp=1.0, + PN_stdfloat cfm=1.0, + PN_stdfloat split=1.0); + // Materials int get_num_materials() const; BulletSoftBodyMaterial get_material(int idx) const;