57 lines
1.6 KiB
C++
57 lines
1.6 KiB
C++
#ifndef RAGDOLL_CLASS
|
|
#define RAGDOLL_CLASS
|
|
|
|
#include <vector>
|
|
|
|
#include <glm/glm.hpp>
|
|
|
|
#include "t.h"
|
|
|
|
class CharacterBody;
|
|
class CollisionMesh;
|
|
class Physics;
|
|
class p;
|
|
struct BallJoint;
|
|
|
|
// Splits a character's rig into rigid bodies joined by ball joints.
|
|
// Each part collides using the rig triangles skinned mostly to its bones.
|
|
class Ragdoll {
|
|
public:
|
|
struct Part {
|
|
t_package transform; // scale is the part's bounding box, orientation starts at identity
|
|
p* body = nullptr;
|
|
CollisionMesh* mesh = nullptr;
|
|
glm::vec3 restPosition = glm::vec3(0.0f);
|
|
};
|
|
|
|
// rigMatrix is the model matrix the rig was being drawn with
|
|
Ragdoll(CharacterBody& characterBody, const glm::mat4& rigMatrix, Physics& physics);
|
|
|
|
// Takes its parts and joints back out of the physics
|
|
~Ragdoll();
|
|
Ragdoll(const Ragdoll&) = delete;
|
|
Ragdoll& operator=(const Ragdoll&) = delete;
|
|
|
|
// Call once a frame after the physics steps
|
|
void Update(float dt);
|
|
|
|
// Bone matrices in world space, draw the rig with an identity model matrix
|
|
std::vector<glm::mat4> GetBoneMatrices() const;
|
|
|
|
const std::vector<Part*>& GetParts() const { return parts; }
|
|
|
|
private:
|
|
void Reset();
|
|
|
|
Physics* physics = nullptr;
|
|
std::vector<Part*> parts;
|
|
std::vector<BallJoint*> joints;
|
|
std::vector<int> boneParts; // part index of each bone
|
|
std::vector<glm::mat4> restBones; // world space bone matrices at the moment of going limp
|
|
std::vector<glm::mat4> restInverses; // inverse of each part's starting transform
|
|
int group = 0;
|
|
float settleTimer = 0.0f;
|
|
};
|
|
|
|
#endif
|