187 - Interp Between Frames

This commit is contained in:
Kingsmedia 2022-05-27 17:05:07 +02:00
parent bd20b76da7
commit 650b206797
2 changed files with 26 additions and 0 deletions

View File

@ -34,6 +34,31 @@ void ULagCompensationComponent::SaveFramePackage(FFramePackage& Package)
}
}
FFramePackage ULagCompensationComponent::InterpBetweenFrames(const FFramePackage& OlderFrame, const FFramePackage& YoungerFrame, float HitTime)
{
const float Distance = YoungerFrame.Time - OlderFrame.Time;
const float InterpFraction = FMath::Clamp((HitTime - OlderFrame.Time) / Distance, 0.f, 1.f);
FFramePackage InterpFramePackage;
InterpFramePackage.Time = HitTime;
for (auto& YoungerPair : YoungerFrame.HitBoxInfo)
{
const FName& BoxInfoName = YoungerPair.Key;
const FBoxInformation& OlderBox = OlderFrame.HitBoxInfo[BoxInfoName];
const FBoxInformation& YoungerBox = YoungerFrame.HitBoxInfo[BoxInfoName];
FBoxInformation InterpBoxInfo;
InterpBoxInfo.Location = FMath::VInterpTo(OlderBox.Location, YoungerBox.Location, 1.f, InterpFraction);
InterpBoxInfo.Rotation = FMath::RInterpTo(OlderBox.Rotation, YoungerBox.Rotation, 1.f, InterpFraction);
InterpBoxInfo.BoxExtend = OlderBox.BoxExtend;
InterpFramePackage.HitBoxInfo.Add(BoxInfoName, InterpBoxInfo);
}
return InterpFramePackage;
}
void ULagCompensationComponent::ShowFramePackage(const FFramePackage& Package, const FColor Color)
{
for (auto& BoxInfo : Package.HitBoxInfo)

View File

@ -48,6 +48,7 @@ public:
protected:
virtual void BeginPlay() override;
void SaveFramePackage(FFramePackage& Package);
FFramePackage InterpBetweenFrames(const FFramePackage& OlderFrame, const FFramePackage& YoungerFrame, float HitTime);
private: