diff --git a/panda/src/bullet/bulletBodyNode.I b/panda/src/bullet/bulletBodyNode.I index fbfa68d81d..89e3988bd2 100644 --- a/panda/src/bullet/bulletBodyNode.I +++ b/panda/src/bullet/bulletBodyNode.I @@ -217,6 +217,7 @@ set_friction(PN_stdfloat friction) { return get_object()->setFriction(friction); } +#if BT_BULLET_VERSION >= 281 //////////////////////////////////////////////////////////////////// // Function: BulletBodyNode::get_rolling_friction // Access: Published @@ -238,6 +239,7 @@ set_rolling_friction(PN_stdfloat friction) { return get_object()->setRollingFriction(friction); } +#endif //////////////////////////////////////////////////////////////////// // Function: BulletBodyNode::has_anisotropic_friction diff --git a/panda/src/bullet/bulletBodyNode.h b/panda/src/bullet/bulletBodyNode.h index 6169d58ebf..63f359022f 100644 --- a/panda/src/bullet/bulletBodyNode.h +++ b/panda/src/bullet/bulletBodyNode.h @@ -94,8 +94,10 @@ PUBLISHED: INLINE PN_stdfloat get_friction() const; INLINE void set_friction(PN_stdfloat friction); +#if BT_BULLET_VERSION >= 281 INLINE PN_stdfloat get_rolling_friction() const; INLINE void set_rolling_friction(PN_stdfloat friction); +#endif INLINE bool has_anisotropic_friction() const; void set_anisotropic_friction(const LVecBase3 &friction); diff --git a/panda/src/bullet/bulletSoftBodyControl.I b/panda/src/bullet/bulletSoftBodyControl.I new file mode 100644 index 0000000000..e646f74a6e --- /dev/null +++ b/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; +} + diff --git a/panda/src/bullet/bulletSoftBodyControl.cxx b/panda/src/bullet/bulletSoftBodyControl.cxx new file mode 100644 index 0000000000..a06a9ee81c --- /dev/null +++ b/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))); +} + diff --git a/panda/src/bullet/bulletSoftBodyControl.h b/panda/src/bullet/bulletSoftBodyControl.h new file mode 100644 index 0000000000..53564ed1a7 --- /dev/null +++ b/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__ diff --git a/panda/src/bullet/bulletSoftBodyNode.cxx b/panda/src/bullet/bulletSoftBodyNode.cxx index 4441ad311c..d7aeb89cac 100644 --- a/panda/src/bullet/bulletSoftBodyNode.cxx +++ b/panda/src/bullet/bulletSoftBodyNode.cxx @@ -14,6 +14,7 @@ #include "bulletSoftBodyNode.h" #include "bulletSoftBodyConfig.h" +#include "bulletSoftBodyControl.h" #include "bulletSoftBodyMaterial.h" #include "bulletSoftBodyShape.h" #include "bulletSoftBodyWorldInfo.h" @@ -1118,7 +1119,7 @@ append_linear_joint(BulletBodyNode *body, const LPoint3 &pos, PN_stdfloat erp, P // Description: //////////////////////////////////////////////////////////////////// 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); @@ -1129,6 +1130,7 @@ append_angular_joint(BulletBodyNode *body, const LVector3 &axis, PN_stdfloat erp as.cfm = cfm; as.split = split; as.axis = LVecBase3_to_btVector3(axis); + as.icontrol = control; _soft->appendAngularJoint(as, ptr); } diff --git a/panda/src/bullet/bulletSoftBodyNode.h b/panda/src/bullet/bulletSoftBodyNode.h index 2e0261c051..a9ebe075b9 100644 --- a/panda/src/bullet/bulletSoftBodyNode.h +++ b/panda/src/bullet/bulletSoftBodyNode.h @@ -31,6 +31,7 @@ #include "pta_LVecBase3.h" class BulletSoftBodyConfig; +class BulletSoftBodyControl; class BulletSoftBodyMaterial; class BulletSoftBodyWorldInfo; @@ -137,7 +138,8 @@ PUBLISHED: void append_angular_joint(BulletBodyNode *body, const LVector3 &axis, PN_stdfloat erp=1.0, PN_stdfloat cfm=1.0, - PN_stdfloat split=1.0); + PN_stdfloat split=1.0, + BulletSoftBodyControl *control=NULL); // Materials int get_num_materials() const; diff --git a/panda/src/bullet/p3bullet_composite.cxx b/panda/src/bullet/p3bullet_composite.cxx index 85407ffd84..0a17d1ea29 100644 --- a/panda/src/bullet/p3bullet_composite.cxx +++ b/panda/src/bullet/p3bullet_composite.cxx @@ -35,6 +35,7 @@ #include "bulletSphericalConstraint.cxx" #include "bulletSoftBodyNode.cxx" #include "bulletSoftBodyConfig.cxx" +#include "bulletSoftBodyControl.cxx" #include "bulletSoftBodyMaterial.cxx" #include "bulletSoftBodyShape.cxx" #include "bulletSoftBodyWorldInfo.cxx"