dust3d/src/ragdoll.h

67 lines
2.5 KiB
C
Raw Normal View History

#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>
#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);
~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();
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;
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;
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);
};
#endif