improve rolling friction using anisotropic direction, to avoid resting in an instable position

(for implicit capsule, cylinder and cone shape)
See Bullet/Demos/RollingFrictionDemo for an example
This commit is contained in:
erwin.coumans
2012-09-16 17:01:25 +00:00
parent 26c713423f
commit 22fb7d5c1e
8 changed files with 120 additions and 43 deletions

View File

@@ -138,6 +138,13 @@ public:
CO_USER_TYPE=32
};
enum AnisotropicFrictionFlags
{
CF_ANISOTROPIC_FRICTION_DISABLED=0,
CF_ANISOTROPIC_FRICTION = 1,
CF_ANISOTROPIC_ROLLING_FRICTION = 2
};
SIMD_FORCE_INLINE bool mergesSimulationIslands() const
{
///static objects, kinematic and object without contact response don't merge islands
@@ -148,14 +155,15 @@ public:
{
return m_anisotropicFriction;
}
void setAnisotropicFriction(const btVector3& anisotropicFriction)
void setAnisotropicFriction(const btVector3& anisotropicFriction, int frictionMode = CF_ANISOTROPIC_FRICTION)
{
m_anisotropicFriction = anisotropicFriction;
m_hasAnisotropicFriction = (anisotropicFriction[0]!=1.f) || (anisotropicFriction[1]!=1.f) || (anisotropicFriction[2]!=1.f);
bool isUnity = (anisotropicFriction[0]!=1.f) || (anisotropicFriction[1]!=1.f) || (anisotropicFriction[2]!=1.f);
m_hasAnisotropicFriction = isUnity?frictionMode : 0;
}
bool hasAnisotropicFriction() const
bool hasAnisotropicFriction(int frictionMode = CF_ANISOTROPIC_FRICTION) const
{
return m_hasAnisotropicFriction!=0;
return (m_hasAnisotropicFriction&frictionMode)!=0;
}
///the constraint solver can discard solving contacts, if the distance is above this threshold. 0 by default.

View File

@@ -104,6 +104,14 @@ public:
}
virtual btVector3 getAnisotropicRollingFrictionDirection() const
{
btVector3 aniDir(0,0,0);
aniDir[getUpAxis()]=1;
return aniDir;
}
virtual int calculateSerializeBufferSize() const;
///fills the dataBuffer and returns the struct name (and 0 on failure)

View File

@@ -109,6 +109,13 @@ public:
int getShapeType() const { return m_shapeType; }
///the getAnisotropicRollingFrictionDirection can be used in combination with setAnisotropicFriction
///See Bullet/Demos/RollingFrictionDemo for an example
virtual btVector3 getAnisotropicRollingFrictionDirection() const
{
return btVector3(1,1,1);
}
virtual void setMargin(btScalar margin) = 0;
virtual btScalar getMargin() const = 0;

View File

@@ -84,6 +84,11 @@ public:
return m_coneIndices[1];
}
virtual btVector3 getAnisotropicRollingFrictionDirection() const
{
return btVector3 (0,1,0);
}
virtual void setLocalScaling(const btVector3& scaling);
};
@@ -93,6 +98,12 @@ class btConeShapeX : public btConeShape
{
public:
btConeShapeX(btScalar radius,btScalar height);
virtual btVector3 getAnisotropicRollingFrictionDirection() const
{
return btVector3 (1,0,0);
}
};
///btConeShapeZ implements a Cone shape, around the Z axis
@@ -100,6 +111,12 @@ class btConeShapeZ : public btConeShape
{
public:
btConeShapeZ(btScalar radius,btScalar height);
virtual btVector3 getAnisotropicRollingFrictionDirection() const
{
return btVector3 (0,0,1);
}
};
#endif //BT_CONE_MINKOWSKI_H

View File

@@ -97,6 +97,13 @@ BT_DECLARE_ALIGNED_ALLOCATOR();
return m_upAxis;
}
virtual btVector3 getAnisotropicRollingFrictionDirection() const
{
btVector3 aniDir(0,0,0);
aniDir[getUpAxis()]=1;
return aniDir;
}
virtual btScalar getRadius() const
{
return getHalfExtentsWithMargin().getX();