2016-12-08 08:52:44 -05:00
|
|
|
// Copyright 1998-2017 Epic Games, Inc. All Rights Reserved.
|
2014-03-14 14:13:41 -04:00
|
|
|
|
2015-07-22 14:37:24 -04:00
|
|
|
#include "AnimNodes/AnimNode_RotateRootBone.h"
|
2014-03-14 14:13:41 -04:00
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////
|
|
|
|
|
// FAnimNode_RotateRootBone
|
|
|
|
|
|
|
|
|
|
void FAnimNode_RotateRootBone::Initialize(const FAnimationInitializeContext& Context)
|
|
|
|
|
{
|
2015-09-03 09:55:41 -04:00
|
|
|
FAnimNode_Base::Initialize(Context);
|
|
|
|
|
|
2014-03-14 14:13:41 -04:00
|
|
|
BasePose.Initialize(Context);
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-01 14:45:04 -04:00
|
|
|
void FAnimNode_RotateRootBone::CacheBones(const FAnimationCacheBonesContext& Context)
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
|
|
|
|
BasePose.CacheBones(Context);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FAnimNode_RotateRootBone::Update(const FAnimationUpdateContext& Context)
|
|
|
|
|
{
|
|
|
|
|
EvaluateGraphExposedInputs.Execute(Context);
|
|
|
|
|
BasePose.Update(Context);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FAnimNode_RotateRootBone::Evaluate(FPoseContext& Output)
|
|
|
|
|
{
|
|
|
|
|
// Evaluate the input
|
|
|
|
|
BasePose.Evaluate(Output);
|
|
|
|
|
|
|
|
|
|
checkSlow(!FMath::IsNaN(Yaw) && FMath::IsFinite(Yaw));
|
|
|
|
|
checkSlow(!FMath::IsNaN(Pitch) && FMath::IsFinite(Pitch));
|
|
|
|
|
|
2015-10-28 19:18:20 -04:00
|
|
|
if (!FMath::IsNearlyZero(Pitch, KINDA_SMALL_NUMBER) || !FMath::IsNearlyZero(Yaw, KINDA_SMALL_NUMBER))
|
2015-05-29 16:09:13 -04:00
|
|
|
{
|
|
|
|
|
// Build our desired rotation
|
|
|
|
|
const FRotator DeltaRotation(Pitch, Yaw, 0.f);
|
|
|
|
|
const FQuat DeltaQuat(DeltaRotation);
|
|
|
|
|
const FQuat MeshToComponentQuat(MeshToComponent);
|
2014-03-14 14:13:41 -04:00
|
|
|
|
2015-05-29 16:09:13 -04:00
|
|
|
// Convert our rotation from Component Space to Mesh Space.
|
|
|
|
|
const FQuat MeshSpaceDeltaQuat = MeshToComponentQuat.Inverse() * DeltaQuat * MeshToComponentQuat;
|
2014-03-14 14:13:41 -04:00
|
|
|
|
2015-05-29 16:09:13 -04:00
|
|
|
// Apply rotation to root bone.
|
2015-10-28 19:18:20 -04:00
|
|
|
FCompactPoseBoneIndex RootBoneIndex(0);
|
|
|
|
|
Output.Pose[RootBoneIndex].SetRotation(Output.Pose[RootBoneIndex].GetRotation() * MeshSpaceDeltaQuat);
|
|
|
|
|
Output.Pose[RootBoneIndex].NormalizeRotation();
|
2015-05-29 16:09:13 -04:00
|
|
|
}
|
2014-03-14 14:13:41 -04:00
|
|
|
}
|
|
|
|
|
|
2014-04-23 18:35:21 -04:00
|
|
|
|
|
|
|
|
void FAnimNode_RotateRootBone::GatherDebugData(FNodeDebugData& DebugData)
|
|
|
|
|
{
|
|
|
|
|
FString DebugLine = DebugData.GetNodeName(this);
|
|
|
|
|
|
|
|
|
|
DebugLine += FString::Printf(TEXT("(Pitch: %.2f Yaw: %.2f)"), Pitch, Yaw);
|
|
|
|
|
DebugData.AddDebugItem(DebugLine);
|
|
|
|
|
|
|
|
|
|
BasePose.GatherDebugData(DebugData);
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-14 14:13:41 -04:00
|
|
|
FAnimNode_RotateRootBone::FAnimNode_RotateRootBone()
|
|
|
|
|
: Pitch(0.0f)
|
|
|
|
|
, Yaw(0.0f)
|
|
|
|
|
, MeshToComponent(FRotator::ZeroRotator)
|
|
|
|
|
{
|
|
|
|
|
}
|