Переглянути джерело

Support for driving Bullet soft body joints, and rolling friction (Bullet 2.81 only).

enn0x 12 роки тому
батько
коміт
3a3b35e7c5

+ 2 - 0
panda/src/bullet/bulletBodyNode.I

@@ -217,6 +217,7 @@ set_friction(PN_stdfloat friction) {
   return get_object()->setFriction(friction);
   return get_object()->setFriction(friction);
 }
 }
 
 
+#if BT_BULLET_VERSION >= 281
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: BulletBodyNode::get_rolling_friction
 //     Function: BulletBodyNode::get_rolling_friction
 //       Access: Published
 //       Access: Published
@@ -238,6 +239,7 @@ set_rolling_friction(PN_stdfloat friction) {
 
 
   return get_object()->setRollingFriction(friction);
   return get_object()->setRollingFriction(friction);
 }
 }
+#endif
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: BulletBodyNode::has_anisotropic_friction
 //     Function: BulletBodyNode::has_anisotropic_friction

+ 2 - 0
panda/src/bullet/bulletBodyNode.h

@@ -94,8 +94,10 @@ PUBLISHED:
   INLINE PN_stdfloat get_friction() const;
   INLINE PN_stdfloat get_friction() const;
   INLINE void set_friction(PN_stdfloat friction);
   INLINE void set_friction(PN_stdfloat friction);
 
 
+#if BT_BULLET_VERSION >= 281
   INLINE PN_stdfloat get_rolling_friction() const;
   INLINE PN_stdfloat get_rolling_friction() const;
   INLINE void set_rolling_friction(PN_stdfloat friction);
   INLINE void set_rolling_friction(PN_stdfloat friction);
+#endif
 
 
   INLINE bool has_anisotropic_friction() const;
   INLINE bool has_anisotropic_friction() const;
   void set_anisotropic_friction(const LVecBase3 &friction);
   void set_anisotropic_friction(const LVecBase3 &friction);

+ 59 - 0
panda/src/bullet/bulletSoftBodyControl.I

@@ -0,0 +1,59 @@
+// Filename: bulletSoftBodyControl.I
+// Created by:  enn0x (04Mar10)
+//
+////////////////////////////////////////////////////////////////////
+//
+// PANDA 3D SOFTWARE
+// Copyright (c) Carnegie Mellon University.  All rights reserved.
+//
+// All use of this software is subject to the terms of the revised BSD
+// license.  You should have received a copy of this license along
+// with this source code in a file named "LICENSE."
+//
+////////////////////////////////////////////////////////////////////
+
+
+////////////////////////////////////////////////////////////////////
+//     Function: BulletSoftBodyControl::set_goal
+//       Access: Published
+//  Description:
+////////////////////////////////////////////////////////////////////
+INLINE void BulletSoftBodyControl::
+set_goal(PN_stdfloat goal) {
+
+  _goal = (btScalar)goal;
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: BulletSoftBodyControl::set_max_torque
+//       Access: Published
+//  Description:
+////////////////////////////////////////////////////////////////////
+INLINE void BulletSoftBodyControl::
+set_max_torque(PN_stdfloat maxtorque) {
+
+  _maxtorque = (btScalar)maxtorque;
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: BulletSoftBodyControl::set_angle
+//       Access: Published
+//  Description:
+////////////////////////////////////////////////////////////////////
+INLINE void BulletSoftBodyControl::
+set_angle(PN_stdfloat angle) {
+
+  _angle = (btScalar)angle;
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: BulletSoftBodyControl::set_sign
+//       Access: Published
+//  Description:
+////////////////////////////////////////////////////////////////////
+INLINE void BulletSoftBodyControl::
+set_sign(PN_stdfloat sign) {
+
+  _sign = (btScalar)sign;
+}
+

+ 66 - 0
panda/src/bullet/bulletSoftBodyControl.cxx

@@ -0,0 +1,66 @@
+// Filename: bulletSoftBodyControl.cxx
+// Created by:  enn0x (04Mar10)
+//
+////////////////////////////////////////////////////////////////////
+//
+// PANDA 3D SOFTWARE
+// Copyright (c) Carnegie Mellon University.  All rights reserved.
+//
+// All use of this software is subject to the terms of the revised BSD
+// license.  You should have received a copy of this license along
+// with this source code in a file named "LICENSE."
+//
+////////////////////////////////////////////////////////////////////
+
+#include "bulletSoftBodyControl.h"
+
+////////////////////////////////////////////////////////////////////
+//     Function: BulletSoftBodyControl::Constructor
+//       Access: Published
+//  Description:
+////////////////////////////////////////////////////////////////////
+BulletSoftBodyControl::
+BulletSoftBodyControl() {
+
+  _goal = 0.0;
+  _maxtorque = 0.0;
+
+  _angle = 0.0;
+  _sign = 0.0;
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: BulletSoftBodyControl::Destructor
+//       Access: Published
+//  Description:
+////////////////////////////////////////////////////////////////////
+INLINE BulletSoftBodyControl::
+~BulletSoftBodyControl() {
+
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: BulletSoftBodyControl::Prepare
+//       Access: Public
+//  Description:
+////////////////////////////////////////////////////////////////////
+void BulletSoftBodyControl::
+Prepare(btSoftBody::AJoint* joint) {
+
+  if (btFabs(_sign) > 0.0) {
+    joint->m_refs[0][0] = btCos(_angle * _sign);
+    joint->m_refs[0][2] = btSin(_angle * _sign);
+  }
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: BulletSoftBodyControl::Speed
+//       Access: Public
+//  Description:
+////////////////////////////////////////////////////////////////////
+btScalar BulletSoftBodyControl::
+Speed(btSoftBody::AJoint *, btScalar current) {
+
+  return (current + btMin(_maxtorque, btMax(-_maxtorque, _goal - current)));
+}
+

+ 65 - 0
panda/src/bullet/bulletSoftBodyControl.h

@@ -0,0 +1,65 @@
+// Filename: bulletSoftBodyControl.h
+// Created by:  enn0x (04Mar10)
+//
+////////////////////////////////////////////////////////////////////
+//
+// PANDA 3D SOFTWARE
+// Copyright (c) Carnegie Mellon University.  All rights reserved.
+//
+// All use of this software is subject to the terms of the revised BSD
+// license.  You should have received a copy of this license along
+// with this source code in a file named "LICENSE."
+//
+////////////////////////////////////////////////////////////////////
+
+#ifndef __BULLET_SOFT_BODY_CONTROL_H__
+#define __BULLET_SOFT_BODY_CONTROL_H__
+
+#include "pandabase.h"
+
+#include "bullet_includes.h"
+#include "bullet_utils.h"
+
+#include "luse.h"
+
+////////////////////////////////////////////////////////////////////
+//       Class : BulletSoftBodyControl
+// Description : 
+////////////////////////////////////////////////////////////////////
+class EXPCL_PANDABULLET BulletSoftBodyControl : public btSoftBody::AJoint::IControl {
+
+PUBLISHED:
+  BulletSoftBodyControl();
+  ~BulletSoftBodyControl();
+
+  // Motor
+  INLINE void set_goal(PN_stdfloat goal);
+  INLINE void set_max_torque(PN_stdfloat maxtorque);
+
+  //INLINE PN_stdfloat get_goal() const;
+  //INLINE PN_stdfloat get_max_torque() const;
+
+  // Steer
+  INLINE void set_angle(PN_stdfloat angle);
+  INLINE void set_sign(PN_stdfloat sign);
+
+  //INLINE PN_stdfloat get_angle() const;
+  //INLINE PN_stdfloat get_sign() const;
+
+public:
+  void Prepare(btSoftBody::AJoint* joint);
+  btScalar Speed(btSoftBody::AJoint *joint, btScalar current);
+
+private:
+  // Motor
+  btScalar _goal;
+  btScalar _maxtorque;
+
+  // Steer
+  btScalar _angle;
+  btScalar _sign;
+};
+
+#include "bulletSoftBodyControl.I"
+
+#endif // __BULLET_SOFT_BODY_CONTROL_H__

+ 3 - 1
panda/src/bullet/bulletSoftBodyNode.cxx

@@ -14,6 +14,7 @@
 
 
 #include "bulletSoftBodyNode.h"
 #include "bulletSoftBodyNode.h"
 #include "bulletSoftBodyConfig.h"
 #include "bulletSoftBodyConfig.h"
+#include "bulletSoftBodyControl.h"
 #include "bulletSoftBodyMaterial.h"
 #include "bulletSoftBodyMaterial.h"
 #include "bulletSoftBodyShape.h"
 #include "bulletSoftBodyShape.h"
 #include "bulletSoftBodyWorldInfo.h"
 #include "bulletSoftBodyWorldInfo.h"
@@ -1118,7 +1119,7 @@ append_linear_joint(BulletBodyNode *body, const LPoint3 &pos, PN_stdfloat erp, P
 //  Description: 
 //  Description: 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 void BulletSoftBodyNode::
 void BulletSoftBodyNode::
-append_angular_joint(BulletBodyNode *body, const LVector3 &axis, PN_stdfloat erp, PN_stdfloat cfm, PN_stdfloat split) {
+append_angular_joint(BulletBodyNode *body, const LVector3 &axis, PN_stdfloat erp, PN_stdfloat cfm, PN_stdfloat split, BulletSoftBodyControl *control) {
 
 
   nassertv(body);
   nassertv(body);
 
 
@@ -1129,6 +1130,7 @@ append_angular_joint(BulletBodyNode *body, const LVector3 &axis, PN_stdfloat erp
   as.cfm = cfm;
   as.cfm = cfm;
   as.split = split;
   as.split = split;
   as.axis = LVecBase3_to_btVector3(axis);
   as.axis = LVecBase3_to_btVector3(axis);
+  as.icontrol = control;
 
 
   _soft->appendAngularJoint(as, ptr);
   _soft->appendAngularJoint(as, ptr);
 }
 }

+ 3 - 1
panda/src/bullet/bulletSoftBodyNode.h

@@ -31,6 +31,7 @@
 #include "pta_LVecBase3.h"
 #include "pta_LVecBase3.h"
 
 
 class BulletSoftBodyConfig;
 class BulletSoftBodyConfig;
+class BulletSoftBodyControl;
 class BulletSoftBodyMaterial;
 class BulletSoftBodyMaterial;
 class BulletSoftBodyWorldInfo;
 class BulletSoftBodyWorldInfo;
 
 
@@ -137,7 +138,8 @@ PUBLISHED:
   void append_angular_joint(BulletBodyNode *body, const LVector3 &axis,
   void append_angular_joint(BulletBodyNode *body, const LVector3 &axis,
     PN_stdfloat erp=1.0,
     PN_stdfloat erp=1.0,
     PN_stdfloat cfm=1.0,
     PN_stdfloat cfm=1.0,
-    PN_stdfloat split=1.0);
+    PN_stdfloat split=1.0,
+    BulletSoftBodyControl *control=NULL);
 
 
   // Materials
   // Materials
   int get_num_materials() const;
   int get_num_materials() const;

+ 1 - 0
panda/src/bullet/p3bullet_composite.cxx

@@ -35,6 +35,7 @@
 #include "bulletSphericalConstraint.cxx"
 #include "bulletSphericalConstraint.cxx"
 #include "bulletSoftBodyNode.cxx"
 #include "bulletSoftBodyNode.cxx"
 #include "bulletSoftBodyConfig.cxx"
 #include "bulletSoftBodyConfig.cxx"
+#include "bulletSoftBodyControl.cxx"
 #include "bulletSoftBodyMaterial.cxx"
 #include "bulletSoftBodyMaterial.cxx"
 #include "bulletSoftBodyShape.cxx"
 #include "bulletSoftBodyShape.cxx"
 #include "bulletSoftBodyWorldInfo.cxx"
 #include "bulletSoftBodyWorldInfo.cxx"