1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- // SPDX-FileCopyrightText: 2021 Jorrit Rouwe
- // SPDX-License-Identifier: MIT
- #include <Jolt.h>
- #include <Skeleton/SkeletonPose.h>
- #ifdef JPH_DEBUG_RENDERER
- #include <Renderer/DebugRenderer.h>
- #endif // JPH_DEBUG_RENDERER
- namespace JPH {
- void SkeletonPose::SetSkeleton(const Skeleton *inSkeleton)
- {
- mSkeleton = inSkeleton;
- mJoints.resize(mSkeleton->GetJointCount());
- mJointMatrices.resize(mSkeleton->GetJointCount());
- }
- void SkeletonPose::CalculateJointMatrices()
- {
- for (int i = 0; i < (int)mJoints.size(); ++i)
- {
- mJoints[i].ToMatrix(mJointMatrices[i]);
- int parent = mSkeleton->GetJoint(i).mParentJointIndex;
- if (parent >= 0)
- {
- JPH_ASSERT(parent < i, "Bones must be ordered: parents first");
- mJointMatrices[i] = mJointMatrices[parent] * mJointMatrices[i];
- }
- }
- }
- #ifdef JPH_DEBUG_RENDERER
- void SkeletonPose::Draw(const DrawSettings &inDrawSettings, DebugRenderer *inRenderer) const
- {
- const Skeleton::JointVector &joints = mSkeleton->GetJoints();
- for (int b = 0; b < mSkeleton->GetJointCount(); ++b)
- {
- if (inDrawSettings.mDrawJoints)
- {
- int parent = joints[b].mParentJointIndex;
- if (parent >= 0)
- inRenderer->DrawLine(mJointMatrices[parent].GetTranslation(), mJointMatrices[b].GetTranslation(), Color::sGreen);
- }
- if (inDrawSettings.mDrawJointOrientations)
- inRenderer->DrawCoordinateSystem(mJointMatrices[b], 0.05f);
- if (inDrawSettings.mDrawJointNames)
- inRenderer->DrawText3D(mJointMatrices[b].GetTranslation(), joints[b].mName, Color::sWhite, 0.05f);
- }
- }
- #endif // JPH_DEBUG_RENDERER
- } // JPH
|