本文整理汇总了C++中FTransform::CopyRotationPart方法的典型用法代码示例。如果您正苦于以下问题:C++ FTransform::CopyRotationPart方法的具体用法?C++ FTransform::CopyRotationPart怎么用?C++ FTransform::CopyRotationPart使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FTransform
的用法示例。
在下文中一共展示了FTransform::CopyRotationPart方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: EvaluateBoneTransforms
//.........这里部分代码省略.........
FMatrix OldToNewTM = OldLocalToWorld * SkelComp->GetTransformMatrix().InverseFast();
// Add fake velocity if present to all but root bone
if(!FakeVelocity.IsZero())
{
FVector FakeMovement = -FakeVelocity * ThisTimstep;
if (bActorSpaceFakeVel && SkelComp->GetOwner())
{
const FTransform BoneToWorld(SkelComp->GetOwner()->GetActorRotation(), SkelComp->GetOwner()->GetActorLocation());
FakeMovement = BoneToWorld.TransformVector(FakeMovement);
}
FakeMovement = SkelComp->GetTransformMatrix().InverseTransformVector(FakeMovement);
// Then add to each bone
for(int32 i=1; i<TrailBoneLocations.Num(); i++)
{
TrailBoneLocations[i] += FakeMovement;
}
}
// Root bone of trail is not modified.
int32 RootIndex = ChainBoneIndices[0];
FTransform ChainTransform = MeshBases.GetComponentSpaceTransform(RootIndex);
OutBoneTransforms[0] = FBoneTransform(RootIndex, ChainTransform);
TrailBoneLocations[0] = ChainTransform.GetTranslation();
// Starting one below head of chain, move bones.
for(int32 i=1; i<ChainBoneIndices.Num(); i++)
{
// Parent bone position in component space.
int32 ParentIndex = ChainBoneIndices[i-1];
FVector ParentPos = TrailBoneLocations[i-1];
FVector ParentAnimPos = MeshBases.GetComponentSpaceTransform(ParentIndex).GetTranslation();
// Child bone position in component space.
int32 ChildIndex = ChainBoneIndices[i];
FVector ChildPos = OldToNewTM.TransformPosition(TrailBoneLocations[i]); // move from 'last frames component' frame to 'this frames component' frame
FVector ChildAnimPos = MeshBases.GetComponentSpaceTransform(ChildIndex).GetTranslation();
// Desired parent->child offset.
FVector TargetDelta = (ChildAnimPos - ParentAnimPos);
// Desired child position.
FVector ChildTarget = ParentPos + TargetDelta;
// Find vector from child to target
FVector Error = ChildTarget - ChildPos;
// Calculate how much to push the child towards its target
float Correction = FMath::Clamp<float>(ThisTimstep * TrailRelaxation, 0.f, 1.f);
// Scale correction vector and apply to get new world-space child position.
TrailBoneLocations[i] = ChildPos + (Error * Correction);
// If desired, prevent bones stretching too far.
if(bLimitStretch)
{
float RefPoseLength = TargetDelta.Size();
FVector CurrentDelta = TrailBoneLocations[i] - TrailBoneLocations[i-1];
float CurrentLength = CurrentDelta.Size();
// If we are too far - cut it back (just project towards parent particle).
if( (CurrentLength - RefPoseLength > StretchLimit) && CurrentLength > SMALL_NUMBER )
{
FVector CurrentDir = CurrentDelta / CurrentLength;
TrailBoneLocations[i] = TrailBoneLocations[i-1] + (CurrentDir * (RefPoseLength + StretchLimit));
}
}
// Modify child matrix
OutBoneTransforms[i] = FBoneTransform(ChildIndex, MeshBases.GetComponentSpaceTransform(ChildIndex));
OutBoneTransforms[i].Transform.SetTranslation(TrailBoneLocations[i]);
// Modify rotation of parent matrix to point at this one.
// Calculate the direction that parent bone is currently pointing.
FVector CurrentBoneDir = OutBoneTransforms[i-1].Transform.TransformVector( GetAlignVector(ChainBoneAxis, bInvertChainBoneAxis) );
CurrentBoneDir = CurrentBoneDir.SafeNormal(SMALL_NUMBER);
// Calculate vector from parent to child.
FVector NewBoneDir = FVector(OutBoneTransforms[i].Transform.GetTranslation() - OutBoneTransforms[i - 1].Transform.GetTranslation()).SafeNormal(SMALL_NUMBER);
// Calculate a quaternion that gets us from our current rotation to the desired one.
FQuat DeltaLookQuat = FQuat::FindBetween(CurrentBoneDir, NewBoneDir);
FTransform DeltaTM( DeltaLookQuat, FVector(0.f) );
// Apply to the current parent bone transform.
FTransform TmpMatrix = FTransform::Identity;
TmpMatrix.CopyRotationPart(OutBoneTransforms[i - 1].Transform);
TmpMatrix = TmpMatrix * DeltaTM;
OutBoneTransforms[i - 1].Transform.CopyRotationPart(TmpMatrix);
}
// For the last bone in the chain, use the rotation from the bone above it.
OutBoneTransforms[ChainLength - 1].Transform.CopyRotationPart(OutBoneTransforms[ChainLength - 2].Transform);
// Update OldLocalToWorld
OldLocalToWorld = SkelComp->GetTransformMatrix();
}