prepare for 'custom' multi body creation.

This commit is contained in:
erwin coumans
2015-04-22 18:09:00 -07:00
parent b64f5feba4
commit 51938d642e
7 changed files with 118 additions and 60 deletions

View File

@@ -0,0 +1,42 @@
#ifndef CUSTOM_MULTIBODY_CALLBACK_H
#define CUSTOM_MULTIBODY_CALLBACK_H
#ifdef USE_EIGEN
typedef Eigen::Quaternion<double> QuaternionType;
typedef Eigen::Vector3d<double> Vector3dType;
typedef double ScalarType;
#else
typedef btQuaternion QuaternionType;
typedef btVector3 Vector3dType;
typedef btScalar ScalarType;
#endif
class CustomMultiBodyCreationCallback
{
public:
virtual ~CustomMultiBodyCreationCallback() {}
enum {
RevoluteJoint=1,
PrismaticJoint,
FixedJoint,
};
virtual int allocateMultiBodyBase(int urdfLinkIndex, int totalNumJoints,ScalarType baseMass, const Vector3dType& localInertiaDiagonal, bool isFixedBase) const =0;
virtual void addLinkAndJoint(int jointType, int linkIndex, // 0 to num_links-1
int parentIndex,
double mass,
const Vector3dType& inertia,
const QuaternionType &rotParentFrameToLinkFrame, // rotate points in parent frame to this frame, when q = 0
const Vector3dType& jointAxisInLinkFrame, // in Link frame
const Vector3dType& parentComToThisJointOffset, // vector from parent COM to joint frame, in Parent frame
const Vector3dType& thisJointToThisComOffset) = 0; // vector from joint frame to my COM, in Link frame);
// @todo: Decide if we need this link mapping?
// virtual void addLinkMapping(int urdfLinkIndex, int mbLinkIndex) const = 0;
};
#endif //CUSTOM_MULTIBODY_CALLBACK_H

View File

@@ -0,0 +1,64 @@
#include "MultiBodyCustomURDFDemo.h"
#include "BulletDynamics/Featherstone/btMultiBodyLinkCollider.h"
#include "../CommonInterfaces/CommonMultiBodyBase.h"
#include "../Importers/ImportURDFDemo/URDF2Bullet.h"
#include "CustomMultiBodyCreationCallback.h"
struct MultiBodyCustomURDFDemo : public CommonMultiBodyBase
{
btMultiBody* m_multiBody;
public:
MultiBodyCustomURDFDemo(struct GUIHelperInterface* helper);
virtual ~MultiBodyCustomURDFDemo();
virtual void initPhysics();
virtual void stepSimulation(float deltaTime);
};
MultiBodyCustomURDFDemo::MultiBodyCustomURDFDemo(struct GUIHelperInterface* helper)
:CommonMultiBodyBase(helper)
{
}
MultiBodyCustomURDFDemo::~MultiBodyCustomURDFDemo()
{
}
void MultiBodyCustomURDFDemo::initPhysics()
{
int upAxis = 2;
m_guiHelper->setUpAxis(upAxis);
createEmptyDynamicsWorld();
m_guiHelper->createPhysicsDebugDrawer(m_dynamicsWorld);
m_dynamicsWorld->getDebugDrawer()->setDebugMode(
//btIDebugDraw::DBG_DrawConstraints
+btIDebugDraw::DBG_DrawWireframe
+btIDebugDraw::DBG_DrawContactPoints
+btIDebugDraw::DBG_DrawAabb
);//+btIDebugDraw::DBG_DrawConstraintLimits);
}
void MultiBodyCustomURDFDemo::stepSimulation(float deltaTime)
{
m_dynamicsWorld->stepSimulation(deltaTime);
}
class ExampleInterface* MultiBodyCustomURDFDofCreateFunc(struct PhysicsInterface* pint, struct GUIHelperInterface* helper, int option)
{
return new MultiBodyCustomURDFDemo(helper);
}

View File

@@ -0,0 +1,6 @@
#ifndef MULTI_DOF_CUSTOM_URDF_DEMO_H
#define MULTI_DOF_CUSTOM_URDF_DEMO_H
class ExampleInterface* MultiBodyCustomURDFDofCreateFunc(struct PhysicsInterface* pint, struct GUIHelperInterface* helper, int option);
#endif //MULTI_DOF_CUSTOM_URDF_DEMO_H