Hi, I was trying to implement Linear Interpolation into one of my Component’s and It seems to be acting wierd. I noticed that the Data i have to read (since its a 2D component mind you) has a angle, in this case pitch, that is only 0-360, which resets when you go past 360 or 0 in the program.
The data also stores a spin variable, that tells you if you going clockwise/counter-clockwise for that interpolation, but i cant seem to figure out how to use this spin correctly with my data to make it always turn correctly.
C1 = (CurrentTimeMS - Keys[0].Pin()->TimeInMS);
C2 = (Keys[1].Pin()->TimeInMS - Keys[0].Pin()->TimeInMS);
if (C1 == 0)
{
Alpha = 0;
}
else
{
Alpha = C2 / C1;
}
FTransform First Transform = Keys[0].Pin()->Info->ConvertToTransform();
FTransform SecondTransform = Keys[1].Pin()->Info->ConvertToTransform();
float SpinCorrection = 0;
///////////////////////////////////////////////////////////
// Spin > 0 : Clockwise | Spin < 0 : Counter-Clockwise/////
///////////////////////////////////////////////////////////
if (Keys[0].Pin()->Spin > 0 && (FirstTransform.Rotator().Pitch > SecondTransform.Rotator().Pitch))
{
SpinCorrection = 360;
}
else if (Keys[0].Pin()->Spin < 0 && (SecondTransform.Rotator().Pitch > FirstTransform.Rotator().Pitch))
{
SpinCorrection = -360;
}
RelativeTransform.SetLocation(FMath::Lerp(FirstTransform.GetLocation(), SecondTransform.GetLocation(), Alpha));
RelativeTransform.SetRotation(FMath::Lerp(FirstTransform.GetRotation(), (SecondTransform.Rotator() + FRotator(SpinCorrection, 0, 0)).Quaternion(), Alpha));
RelativeTransform.SetScale3D(FMath::Lerp(FirstTransform.GetScale3D(), SecondTransform.GetScale3D(), Alpha));
Theres the code for what i explained, its still resulting in flipping angles and such.