use rotators instead of quats
This commit is contained in:
@@ -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<FName, FTransform>& Bone: BonesTransforms)
|
||||
for (const TTuple<FName, FRotator>& 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;
|
||||
|
||||
@@ -374,85 +374,6 @@ TMap<FName, FRotator> ASGVirtualHand::GetFingersBonesRotations()
|
||||
|
||||
const TArray<TArray<FVector>> HandAngles = HandPose->GetHandAngles();
|
||||
|
||||
for (int32 FingerIndex = 0; FingerIndex < HandAngles.Num(); ++FingerIndex)
|
||||
{
|
||||
const TArray<FVector>& 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<FName, FTransform> ASGVirtualHand::GetFingersBonesTransforms()
|
||||
{
|
||||
TMap<FName, FTransform> Transforms;
|
||||
|
||||
const USGHandPose* HandPose = GetHandPose();
|
||||
if (!IsValid(HandPose))
|
||||
{
|
||||
return MoveTemp(Transforms);
|
||||
}
|
||||
|
||||
const TArray<TArray<FVector>> HandAngles = HandPose->GetHandAngles();
|
||||
|
||||
for (int32 FingerIndex = 0; FingerIndex < HandAngles.Num(); ++FingerIndex)
|
||||
{
|
||||
const TArray<FVector>& FingerJointAngles = HandAngles[FingerIndex];
|
||||
@@ -465,18 +386,16 @@ TMap<FName, FTransform> 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)
|
||||
|
||||
@@ -47,8 +47,7 @@ struct SENSEGLOVE_API FSGVirtualHandAnimInstanceProxy : public FAnimInstanceProx
|
||||
GENERATED_USTRUCT_BODY()
|
||||
|
||||
public:
|
||||
//TMap<FName, FRotator> BonesRotations;
|
||||
TMap<FName, FTransform> BonesTransforms;
|
||||
TMap<FName, FRotator> BonesRotations;
|
||||
|
||||
public:
|
||||
FSGVirtualHandAnimInstanceProxy();
|
||||
|
||||
@@ -182,6 +182,4 @@ public:
|
||||
|
||||
FRotator GetFingerBoneRefRotation(int32 Finger, int32 Joint) const;
|
||||
TMap<FName, FRotator> GetFingersBonesRotations();
|
||||
|
||||
TMap<FName, FTransform> GetFingersBonesTransforms();
|
||||
};
|
||||
Reference in New Issue
Block a user