#ifndef RAGDOLL_CLASS #define RAGDOLL_CLASS #include #include #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 GetBoneMatrices() const; const std::vector& GetParts() const { return parts; } private: void Reset(); Physics* physics = nullptr; std::vector parts; std::vector joints; std::vector boneParts; // part index of each bone std::vector restBones; // world space bone matrices at the moment of going limp std::vector restInverses; // inverse of each part's starting transform int group = 0; float settleTimer = 0.0f; }; #endif