Debian Codegraph @

thirdparty/jolt_physics/Jolt/Skeleton/SkeletonPose.h

raw symbols SCIP
1 // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
2 // SPDX-FileCopyrightText: 2021 Jorrit Rouwe
3 // SPDX-License-Identifier: MIT
4
5 #pragma once
6
7 #include <Jolt/Skeleton/Skeleton.h>
8 #include <Jolt/Skeleton/SkeletalAnimation.h>
9
10 JPH_NAMESPACE_BEGIN
11
12 #ifdef JPH_DEBUG_RENDERER
13 class DebugRenderer;
14 #endif // JPH_DEBUG_RENDERER
15
16 /// Instance of a skeleton, contains the pose the current skeleton is in
17 class JPH_EXPORT SkeletonPose
18 {
19 public:
20 JPH_OVERRIDE_NEW_DELETE
21
22 using JointState = SkeletalAnimation::JointState;
23 using JointStateVector = Array<JointState>;
24 using Mat44Vector = Array<Mat44>;
25
26 ///@name Skeleton
27 ///@{
28 void SetSkeleton(const Skeleton *inSkeleton);
29 const Skeleton * GetSkeleton() const { return mSkeleton; }
30 ///@}
31
32 /// Extra offset applied to the root (and therefore also to all of its children)
33 void SetRootOffset(RVec3Arg inOffset) { mRootOffset = inOffset; }
34 RVec3 GetRootOffset() const { return mRootOffset; }
35
36 ///@name Properties of the joints
37 ///@{
38 uint GetJointCount() const { return (uint)mJoints.size(); }
39 const JointStateVector & GetJoints() const { return mJoints; }
40 JointStateVector & GetJoints() { return mJoints; }
41 const JointState & GetJoint(int inJoint) const { return mJoints[inJoint]; }
42 JointState & GetJoint(int inJoint) { return mJoints[inJoint]; }
43 ///@}
44
45 ///@name Joint matrices
46 ///@{
47 const Mat44Vector & GetJointMatrices() const { return mJointMatrices; }
48 Mat44Vector & GetJointMatrices() { return mJointMatrices; }
49 const Mat44 & GetJointMatrix(int inJoint) const { return mJointMatrices[inJoint]; }
50 Mat44 & GetJointMatrix(int inJoint) { return mJointMatrices[inJoint]; }
51 ///@}
52
53 /// Convert the joint states to joint matrices
54 void CalculateJointMatrices();
55
56 /// Convert joint matrices to joint states
57 void CalculateJointStates();
58
59 /// Outputs the joint matrices in local space (ensure that outMatrices has GetJointCount() elements, assumes that values in GetJoints() is up to date)
60 void CalculateLocalSpaceJointMatrices(Mat44 *outMatrices) const;
61
62 #ifdef JPH_DEBUG_RENDERER
63 /// Draw settings
64 struct DrawSettings
65 {
66 bool mDrawJoints = true;
67 bool mDrawJointOrientations = true;
68 bool mDrawJointNames = false;
69 };
70
71 /// Draw current pose
72 void Draw(const DrawSettings &inDrawSettings, DebugRenderer *inRenderer, RMat44Arg inOffset = RMat44::sIdentity()) const;
73 #endif // JPH_DEBUG_RENDERER
74
75 private:
76 RefConst<Skeleton> mSkeleton; ///< Skeleton definition
77 RVec3 mRootOffset { RVec3::sZero() }; ///< Extra offset applied to the root (and therefore also to all of its children)
78 JointStateVector mJoints; ///< Local joint orientations (local to parent Joint)
79 Mat44Vector mJointMatrices; ///< Local joint matrices (local to world matrix)
80 };
81
82 JPH_NAMESPACE_END