Files
UnrealEngineUWP/Engine/Source/Runtime/AnimGraphRuntime/Private/AnimNodes/AnimNode_RotateRootBone.cpp
ryan durand 0f0464a30e Updating copyright for Engine Runtime.
#rnx
#rb none


#ROBOMERGE-OWNER: ryan.durand
#ROBOMERGE-AUTHOR: ryan.durand
#ROBOMERGE-SOURCE: CL 10869210 via CL 10869511 via CL 10869900
#ROBOMERGE-BOT: (v613-10869866)

[CL 10870549 by ryan durand in Main branch]
2019-12-26 14:45:42 -05:00

85 lines
2.7 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#include "AnimNodes/AnimNode_RotateRootBone.h"
#include "Animation/AnimTrace.h"
/////////////////////////////////////////////////////
// FAnimNode_RotateRootBone
void FAnimNode_RotateRootBone::Initialize_AnyThread(const FAnimationInitializeContext& Context)
{
DECLARE_SCOPE_HIERARCHICAL_COUNTER_ANIMNODE(Initialize_AnyThread)
FAnimNode_Base::Initialize_AnyThread(Context);
BasePose.Initialize(Context);
PitchScaleBiasClamp.Reinitialize();
YawScaleBiasClamp.Reinitialize();
}
void FAnimNode_RotateRootBone::CacheBones_AnyThread(const FAnimationCacheBonesContext& Context)
{
DECLARE_SCOPE_HIERARCHICAL_COUNTER_ANIMNODE(CacheBones_AnyThread)
BasePose.CacheBones(Context);
}
void FAnimNode_RotateRootBone::Update_AnyThread(const FAnimationUpdateContext& Context)
{
DECLARE_SCOPE_HIERARCHICAL_COUNTER_ANIMNODE(Update_AnyThread)
GetEvaluateGraphExposedInputs().Execute(Context);
BasePose.Update(Context);
ActualPitch = PitchScaleBiasClamp.ApplyTo(Pitch, Context.GetDeltaTime());
ActualYaw = YawScaleBiasClamp.ApplyTo(Yaw, Context.GetDeltaTime());
TRACE_ANIM_NODE_VALUE(Context, TEXT("Pitch"), ActualPitch);
TRACE_ANIM_NODE_VALUE(Context, TEXT("Yaw"), ActualYaw);
}
void FAnimNode_RotateRootBone::Evaluate_AnyThread(FPoseContext& Output)
{
DECLARE_SCOPE_HIERARCHICAL_COUNTER_ANIMNODE(Evaluate_AnyThread)
// Evaluate the input
BasePose.Evaluate(Output);
checkSlow(!FMath::IsNaN(ActualYaw) && FMath::IsFinite(ActualYaw));
checkSlow(!FMath::IsNaN(ActualPitch) && FMath::IsFinite(ActualPitch));
if (!FMath::IsNearlyZero(ActualPitch, KINDA_SMALL_NUMBER) || !FMath::IsNearlyZero(ActualYaw, KINDA_SMALL_NUMBER))
{
// Build our desired rotation
const FRotator DeltaRotation(ActualPitch, ActualYaw, 0.f);
const FQuat DeltaQuat(DeltaRotation);
const FQuat MeshToComponentQuat(MeshToComponent);
// Convert our rotation from Component Space to Mesh Space.
const FQuat MeshSpaceDeltaQuat = MeshToComponentQuat.Inverse() * DeltaQuat * MeshToComponentQuat;
// Apply rotation to root bone.
FCompactPoseBoneIndex RootBoneIndex(0);
Output.Pose[RootBoneIndex].SetRotation(Output.Pose[RootBoneIndex].GetRotation() * MeshSpaceDeltaQuat);
Output.Pose[RootBoneIndex].NormalizeRotation();
}
}
void FAnimNode_RotateRootBone::GatherDebugData(FNodeDebugData& DebugData)
{
DECLARE_SCOPE_HIERARCHICAL_COUNTER_ANIMNODE(GatherDebugData)
FString DebugLine = DebugData.GetNodeName(this);
DebugLine += FString::Printf(TEXT("Pitch(%.2f) Yaw(%.2f)"), ActualPitch, ActualYaw);
DebugData.AddDebugItem(DebugLine);
BasePose.GatherDebugData(DebugData);
}
FAnimNode_RotateRootBone::FAnimNode_RotateRootBone()
: Pitch(0.0f)
, Yaw(0.0f)
, MeshToComponent(FRotator::ZeroRotator)
, ActualPitch(0.f)
, ActualYaw(0.f)
{
}