2019-09-21 14:30:27 +00:00
|
|
|
#ifndef DUST3D_RAGDOLL_H
|
|
|
|
#define DUST3D_RAGDOLL_H
|
|
|
|
#include <QObject>
|
|
|
|
#include <BulletDynamics/Dynamics/btDynamicsWorld.h>
|
|
|
|
#include <BulletDynamics/Dynamics/btRigidBody.h>
|
|
|
|
#include <BulletCollision/CollisionShapes/btCollisionShape.h>
|
|
|
|
#include <BulletDynamics/ConstraintSolver/btTypedConstraint.h>
|
|
|
|
#include <LinearMath/btVector3.h>
|
|
|
|
#include <LinearMath/btScalar.h>
|
|
|
|
#include <BulletCollision/CollisionDispatch/btDefaultCollisionConfiguration.h>
|
|
|
|
#include <BulletCollision/BroadphaseCollision/btDbvtBroadphase.h>
|
|
|
|
#include <BulletDynamics/ConstraintSolver/btSequentialImpulseConstraintSolver.h>
|
|
|
|
#include <BulletDynamics/Dynamics/btDiscreteDynamicsWorld.h>
|
|
|
|
#include <BulletCollision/CollisionShapes/btBoxShape.h>
|
|
|
|
#include <QString>
|
|
|
|
#include <map>
|
|
|
|
#include <tuple>
|
|
|
|
#include <QStringList>
|
2020-02-19 11:05:16 +00:00
|
|
|
#include <QColor>
|
2019-09-21 14:30:27 +00:00
|
|
|
#include "rigger.h"
|
|
|
|
#include "jointnodetree.h"
|
|
|
|
|
|
|
|
class RagDoll : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2019-11-09 08:15:49 +00:00
|
|
|
RagDoll(const std::vector<RiggerBone> *rigBones,
|
|
|
|
const JointNodeTree *initialJointNodeTree=nullptr);
|
2019-09-21 14:30:27 +00:00
|
|
|
~RagDoll();
|
|
|
|
bool stepSimulation(float amount);
|
|
|
|
const JointNodeTree &getStepJointNodeTree();
|
2020-02-19 11:05:16 +00:00
|
|
|
const std::vector<std::tuple<QVector3D, QVector3D, float, float, QColor>> &getStepBonePositions();
|
2019-09-21 14:30:27 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
btDefaultCollisionConfiguration *m_collisionConfiguration = nullptr;
|
|
|
|
btCollisionDispatcher *m_collisionDispather = nullptr;
|
|
|
|
btDbvtBroadphase *m_broadphase = nullptr;
|
|
|
|
btSequentialImpulseConstraintSolver *m_constraintSolver = nullptr;
|
|
|
|
btDynamicsWorld *m_world = nullptr;
|
|
|
|
btCollisionShape *m_groundShape = nullptr;
|
|
|
|
btRigidBody *m_groundBody = nullptr;
|
|
|
|
float m_groundY = 0;
|
2020-02-19 11:05:16 +00:00
|
|
|
std::vector<std::pair<QVector3D, QVector3D>> m_boneInitialPositions;
|
2019-09-21 14:30:27 +00:00
|
|
|
|
|
|
|
std::map<QString, btCollisionShape *> m_boneShapes;
|
|
|
|
std::map<QString, btRigidBody *> m_boneBodies;
|
|
|
|
std::vector<btTypedConstraint *> m_boneConstraints;
|
|
|
|
|
|
|
|
std::map<QString, QVector3D> m_boneMiddleMap;
|
|
|
|
std::map<QString, float> m_boneLengthMap;
|
|
|
|
std::map<QString, float> m_boneRadiusMap;
|
|
|
|
|
|
|
|
JointNodeTree m_jointNodeTree;
|
|
|
|
JointNodeTree m_stepJointNodeTree;
|
|
|
|
std::vector<RiggerBone> m_bones;
|
2020-02-19 11:05:16 +00:00
|
|
|
std::vector<std::tuple<QVector3D, QVector3D, float, float, QColor>> m_stepBonePositions;
|
2019-09-21 14:30:27 +00:00
|
|
|
|
|
|
|
std::map<QString, int> m_boneNameToIndexMap;
|
|
|
|
std::map<QString, std::vector<QString>> m_chains;
|
|
|
|
|
|
|
|
btRigidBody *createRigidBody(btScalar mass, const btTransform &startTransform, btCollisionShape *shape);
|
|
|
|
void createDynamicsWorld();
|
2020-02-19 11:05:16 +00:00
|
|
|
void addConstraint(const RiggerBone &child, const RiggerBone &parent, bool isBorrowedParent=false);
|
2019-09-21 14:30:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|