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

This commit is contained in:
enn0x 2013-05-22 09:51:34 +00:00
parent 1e28f892be
commit 3a3b35e7c5
8 changed files with 201 additions and 2 deletions

View File

@ -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

View File

@ -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);

View File

@ -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;
}

View File

@ -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)));
}

View File

@ -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__

View File

@ -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);
}

View File

@ -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;

View File

@ -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"