From 759c94bcbf0f7b95c793d7a47e4c9d2580efdf4c Mon Sep 17 00:00:00 2001 From: Mamadou Babaei Date: Fri, 3 Mar 2023 12:57:03 +0100 Subject: [PATCH] use rotators instead of quats --- .../SGVirtualHandAnimInstanceProxy.cpp | 14 ++- .../GameFramework/SGVirtualHand.cpp | 87 +------------------ .../SGVirtualHandAnimInstanceProxy.h | 3 +- .../SenseGlove/GameFramework/SGVirtualHand.h | 2 - 4 files changed, 9 insertions(+), 97 deletions(-) diff --git a/Source/SenseGlove/Private/SenseGlove/Animation/SGVirtualHandAnimInstanceProxy.cpp b/Source/SenseGlove/Private/SenseGlove/Animation/SGVirtualHandAnimInstanceProxy.cpp index 97fa2aed..783dd9ec 100644 --- a/Source/SenseGlove/Private/SenseGlove/Animation/SGVirtualHandAnimInstanceProxy.cpp +++ b/Source/SenseGlove/Private/SenseGlove/Animation/SGVirtualHandAnimInstanceProxy.cpp @@ -45,8 +45,6 @@ #include "Math/Rotator.h" #include "SenseGlove/GameFramework/SGVirtualHand.h" -#include "SGCore/SGHandPose.h" -#include "SGLog/SGLog.h" FSGVirtualHandAnimInstanceProxy::FSGVirtualHandAnimInstanceProxy() : FAnimInstanceProxy() @@ -93,10 +91,8 @@ void FSGVirtualHandAnimInstanceProxy::PreEvaluateAnimation(UAnimInstance* InAnim return; } - // BonesRotations.Empty(); - // BonesRotations = Hand->GetFingersBonesRotations(); - BonesTransforms.Empty(); - BonesTransforms = Hand->GetFingersBonesTransforms(); + BonesRotations.Empty(); + BonesRotations = Hand->GetFingersBonesRotations(); } bool FSGVirtualHandAnimInstanceProxy::Evaluate(FPoseContext& Output) @@ -132,10 +128,10 @@ bool FSGVirtualHandAnimInstanceProxy::Evaluate(FPoseContext& Output) FComponentSpacePoseContext PoseContext(Output.AnimInstanceProxy); PoseContext.Pose.InitPose(Output.Pose); - for (const TTuple& Bone: BonesTransforms) + for (const TTuple& Bone: BonesRotations) { FName BoneName(Bone.Key); - FTransform BoneTransform(Bone.Value); + FRotator BoneRotation(Bone.Value); const int32 BoneIndex = GetRequiredBones().GetPoseBoneIndexForBoneName(BoneName); ensureAlwaysMsgf(BoneIndex != INDEX_NONE, TEXT("Invalid finger bone index!")); @@ -147,7 +143,7 @@ bool FSGVirtualHandAnimInstanceProxy::Evaluate(FPoseContext& Output) FAnimNode_ModifyBone BoneController; BoneController.BoneToModify = MoveTemp(BoneReference); - BoneController.Rotation = BoneTransform.Rotator(); + BoneController.Rotation = MoveTemp(BoneRotation); BoneController.RotationMode = EBoneModificationMode::BMM_Replace; BoneController.RotationSpace = EBoneControlSpace::BCS_ParentBoneSpace; BoneController.ScaleMode = EBoneModificationMode::BMM_Ignore; diff --git a/Source/SenseGlove/Private/SenseGlove/GameFramework/SGVirtualHand.cpp b/Source/SenseGlove/Private/SenseGlove/GameFramework/SGVirtualHand.cpp index 4e6dca87..68b11e66 100644 --- a/Source/SenseGlove/Private/SenseGlove/GameFramework/SGVirtualHand.cpp +++ b/Source/SenseGlove/Private/SenseGlove/GameFramework/SGVirtualHand.cpp @@ -374,85 +374,6 @@ TMap ASGVirtualHand::GetFingersBonesRotations() const TArray> HandAngles = HandPose->GetHandAngles(); - for (int32 FingerIndex = 0; FingerIndex < HandAngles.Num(); ++FingerIndex) - { - const TArray& FingerJointAngles = HandAngles[FingerIndex]; - - for (int32 JointIndex = 0; JointIndex < FingerJointAngles.Num(); ++JointIndex) - { - // const FVector& FingerJointAngle{FingerJointAngles[JointIndex]}; - // FRotator RefBoneRotation{GetFingerBoneRefRotation(FingerIndex, JointIndex)}; - // FName BoneName{GetFingerBoneName(FingerIndex, JointIndex)}; - // FRotator BoneRotation{(RefBoneRotation.Vector() + FingerJointAngle).Rotation()}; - // Rotations.Emplace(MoveTemp(BoneName), MoveTemp(BoneRotation)); - - // const FVector& FingerJointAngle{FingerJointAngles[JointIndex]}; - // FQuat FingerJointQuat(FingerJointAngle.Rotation().Quaternion()); - // - // FRotator RefBoneRotation{GetFingerBoneRefRotation(FingerIndex, JointIndex)}; - // FQuat RefBoneQuat(RefBoneRotation.Quaternion()); - // - // FQuat BoneWorldQuat{FingerJointQuat * RefBoneQuat}; - // - // FRotator BoneRotation{BoneWorldQuat.Rotator()}; - // - // FName BoneName{GetFingerBoneName(FingerIndex, JointIndex)}; - // Rotations.Emplace(MoveTemp(BoneName), MoveTemp(BoneRotation)); - // - // const FVector& FingerJointAngle{FingerJointAngles[JointIndex]}; - // const FTransform& RefBoneTransform{GetFingerBoneRefTransform(FingerIndex, JointIndex)}; - // // const FVector ComponentSpaceVector{RefBoneTransform.TransformPosition(FingerJointAngle)}; - // FQuat ComponentSpaceQuat = RefBoneTransform.GetRotation() * FingerJointAngle.Rotation().Quaternion(); - // FRotator BoneRotation{ComponentSpaceQuat.Rotator()}; - // FName BoneName{GetFingerBoneName(FingerIndex, JointIndex)}; - // Rotations.Emplace(MoveTemp(BoneName), MoveTemp(BoneRotation)); - - - // const FVector& FingerJointAngle{FingerJointAngles[JointIndex]}; - // const FTransform& RefBoneTransform{GetFingerBoneRefTransform(FingerIndex, JointIndex)}; - // - // FVector BoneSpaceVector = RefBoneTransform.InverseTransformPosition(FingerJointAngle); - // FRotator BoneSpaceRotator = BoneSpaceVector.Rotation(); - // FRotator BoneRotation = RefBoneTransform.Rotator().RotateVector(BoneSpaceRotator.Vector()).Rotation(); - // - // FName BoneName{GetFingerBoneName(FingerIndex, JointIndex)}; - // - // SGLOG(BoneName, FingerJointAngle, BoneRotation, BoneSpaceRotator); - // - // Rotations.Emplace(MoveTemp(BoneName), MoveTemp(BoneSpaceRotator)); - - const FVector& JointAngle{FMath::RadiansToDegrees(FingerJointAngles[JointIndex])}; - const FQuat JointRotation{FQuat::MakeFromEuler(JointAngle)}; - - const FTransform& BoneRefTransform{GetFingerBoneRefTransform(FingerIndex, JointIndex)}; - - FQuat NewBoneRotation{BoneRefTransform.GetRotation() * JointRotation}; - FTransform NewBoneTransform{BoneRefTransform}; - NewBoneTransform.SetRotation(NewBoneRotation); - - FName BoneName{GetFingerBoneName(FingerIndex, JointIndex)}; - - SGLOG(BoneName, JointRotation.Rotator(), BoneRefTransform.Rotator(), NewBoneTransform.Rotator()); - - Rotations.Emplace(MoveTemp(BoneName), MoveTemp(NewBoneRotation)); - } - } - - return MoveTemp(Rotations); -} - -TMap ASGVirtualHand::GetFingersBonesTransforms() -{ - TMap Transforms; - - const USGHandPose* HandPose = GetHandPose(); - if (!IsValid(HandPose)) - { - return MoveTemp(Transforms); - } - - const TArray> HandAngles = HandPose->GetHandAngles(); - for (int32 FingerIndex = 0; FingerIndex < HandAngles.Num(); ++FingerIndex) { const TArray& FingerJointAngles = HandAngles[FingerIndex]; @@ -465,18 +386,16 @@ TMap ASGVirtualHand::GetFingersBonesTransforms() const FTransform& BoneRefTransform{GetFingerBoneRefTransform(FingerIndex, JointIndex)}; FQuat NewBoneRotation{JointRotation * BoneRefTransform.GetRotation()}; - FTransform NewBoneTransform{BoneRefTransform}; - NewBoneTransform.SetRotation(NewBoneRotation); FName BoneName{GetFingerBoneName(FingerIndex, JointIndex)}; - SGLOG(BoneName, JointRotation.Rotator(), BoneRefTransform.Rotator(), NewBoneTransform.Rotator()); + SGLOG(BoneName, JointRotation.Rotator(), BoneRefTransform.Rotator(), NewBoneRotation); - Transforms.Emplace(MoveTemp(BoneName), MoveTemp(NewBoneTransform)); + Rotations.Emplace(MoveTemp(BoneName), MoveTemp(NewBoneRotation)); } } - return MoveTemp(Transforms); + return MoveTemp(Rotations); } ASGVirtualHand::FImpl::FImpl(ASGVirtualHand* InOwner) diff --git a/Source/SenseGlove/Public/SenseGlove/Animation/SGVirtualHandAnimInstanceProxy.h b/Source/SenseGlove/Public/SenseGlove/Animation/SGVirtualHandAnimInstanceProxy.h index 37bb2716..469ae774 100644 --- a/Source/SenseGlove/Public/SenseGlove/Animation/SGVirtualHandAnimInstanceProxy.h +++ b/Source/SenseGlove/Public/SenseGlove/Animation/SGVirtualHandAnimInstanceProxy.h @@ -47,8 +47,7 @@ struct SENSEGLOVE_API FSGVirtualHandAnimInstanceProxy : public FAnimInstanceProx GENERATED_USTRUCT_BODY() public: - //TMap BonesRotations; - TMap BonesTransforms; + TMap BonesRotations; public: FSGVirtualHandAnimInstanceProxy(); diff --git a/Source/SenseGlove/Public/SenseGlove/GameFramework/SGVirtualHand.h b/Source/SenseGlove/Public/SenseGlove/GameFramework/SGVirtualHand.h index faac729f..e445bf6f 100644 --- a/Source/SenseGlove/Public/SenseGlove/GameFramework/SGVirtualHand.h +++ b/Source/SenseGlove/Public/SenseGlove/GameFramework/SGVirtualHand.h @@ -182,6 +182,4 @@ public: FRotator GetFingerBoneRefRotation(int32 Finger, int32 Joint) const; TMap GetFingersBonesRotations(); - - TMap GetFingersBonesTransforms(); }; \ No newline at end of file