Skip to content

Commit

Permalink
Remove the camera lag substepping as it is useless
Browse files Browse the repository at this point in the history
  • Loading branch information
Sixze committed Nov 23, 2024
1 parent 43b5caf commit f1cb9c2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 91 deletions.
81 changes: 6 additions & 75 deletions Source/ALSCamera/Private/AlsCameraComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,34 +341,7 @@ FRotator UAlsCameraComponent::CalculateCameraRotation(const FRotator& CameraTarg

const auto RotationLag{GetAnimInstance()->GetCurveValue(UAlsCameraConstants::RotationLagCurveName())};

if (!Settings->bEnableCameraLagSubstepping ||
DeltaTime <= Settings->CameraLagSubstepping.LagSubstepDeltaTime ||
RotationLag <= 0.0f)
{
return UAlsRotation::ExponentialDecayRotation(CameraRotation, CameraTargetRotation, DeltaTime, RotationLag);
}

const auto CameraInitialRotation{CameraRotation};
const auto SubstepRotationSpeed{(CameraTargetRotation - CameraInitialRotation).GetNormalized() * (1.0f / DeltaTime)};

auto NewCameraRotation{CameraRotation};
auto PreviousSubstepTime{0.0f};

for (auto SubstepNumber{1};; SubstepNumber++)
{
const auto SubstepTime{SubstepNumber * Settings->CameraLagSubstepping.LagSubstepDeltaTime};
if (SubstepTime < DeltaTime - UE_SMALL_NUMBER)
{
NewCameraRotation = FMath::RInterpTo(NewCameraRotation, CameraInitialRotation + SubstepRotationSpeed * SubstepTime,
SubstepTime - PreviousSubstepTime, RotationLag);

PreviousSubstepTime = SubstepTime;
}
else
{
return FMath::RInterpTo(NewCameraRotation, CameraTargetRotation, DeltaTime - PreviousSubstepTime, RotationLag);
}
}
return UAlsRotation::ExponentialDecayRotation(CameraRotation, CameraTargetRotation, DeltaTime, RotationLag);
}

FVector UAlsCameraComponent::CalculatePivotLagLocation(const FQuat& CameraYawRotation, const float DeltaTime, const bool bAllowLag) const
Expand All @@ -385,53 +358,11 @@ FVector UAlsCameraComponent::CalculatePivotLagLocation(const FQuat& CameraYawRot
const auto LocationLagY{GetAnimInstance()->GetCurveValue(UAlsCameraConstants::LocationLagYCurveName())};
const auto LocationLagZ{GetAnimInstance()->GetCurveValue(UAlsCameraConstants::LocationLagZCurveName())};

if (!Settings->bEnableCameraLagSubstepping ||
DeltaTime <= Settings->CameraLagSubstepping.LagSubstepDeltaTime ||
(LocationLagX <= 0.0f && LocationLagY <= 0.0f && LocationLagZ <= 0.0f))
{
return CameraYawRotation.RotateVector({
UAlsMath::ExponentialDecay(RelativePivotInitialLagLocation.X, RelativePivotTargetLocation.X, DeltaTime, LocationLagX),
UAlsMath::ExponentialDecay(RelativePivotInitialLagLocation.Y, RelativePivotTargetLocation.Y, DeltaTime, LocationLagY),
UAlsMath::ExponentialDecay(RelativePivotInitialLagLocation.Z, RelativePivotTargetLocation.Z, DeltaTime, LocationLagZ)
});
}

const auto SubstepMovementSpeed{(RelativePivotTargetLocation - RelativePivotInitialLagLocation) / DeltaTime};

auto RelativePivotLagLocation{RelativePivotInitialLagLocation};
auto PreviousSubstepTime{0.0f};

for (auto SubstepNumber{1};; SubstepNumber++)
{
const auto SubstepTime{SubstepNumber * Settings->CameraLagSubstepping.LagSubstepDeltaTime};
if (SubstepTime < DeltaTime - UE_SMALL_NUMBER)
{
const auto SubstepRelativePivotTargetLocation{RelativePivotInitialLagLocation + SubstepMovementSpeed * SubstepTime};
const auto SubstepDeltaTime{SubstepTime - PreviousSubstepTime};

RelativePivotLagLocation.X = FMath::FInterpTo(RelativePivotLagLocation.X, SubstepRelativePivotTargetLocation.X,
SubstepDeltaTime, LocationLagX);
RelativePivotLagLocation.Y = FMath::FInterpTo(RelativePivotLagLocation.Y, SubstepRelativePivotTargetLocation.Y,
SubstepDeltaTime, LocationLagY);
RelativePivotLagLocation.Z = FMath::FInterpTo(RelativePivotLagLocation.Z, SubstepRelativePivotTargetLocation.Z,
SubstepDeltaTime, LocationLagZ);

PreviousSubstepTime = SubstepTime;
}
else
{
const auto RemainingDeltaTime{DeltaTime - PreviousSubstepTime};

RelativePivotLagLocation.X = FMath::FInterpTo(RelativePivotLagLocation.X, RelativePivotTargetLocation.X,
RemainingDeltaTime, LocationLagX);
RelativePivotLagLocation.Y = FMath::FInterpTo(RelativePivotLagLocation.Y, RelativePivotTargetLocation.Y,
RemainingDeltaTime, LocationLagY);
RelativePivotLagLocation.Z = FMath::FInterpTo(RelativePivotLagLocation.Z, RelativePivotTargetLocation.Z,
RemainingDeltaTime, LocationLagZ);

return CameraYawRotation.RotateVector(RelativePivotLagLocation);
}
}
return CameraYawRotation.RotateVector({
UAlsMath::ExponentialDecay(RelativePivotInitialLagLocation.X, RelativePivotTargetLocation.X, DeltaTime, LocationLagX),
UAlsMath::ExponentialDecay(RelativePivotInitialLagLocation.Y, RelativePivotTargetLocation.Y, DeltaTime, LocationLagY),
UAlsMath::ExponentialDecay(RelativePivotInitialLagLocation.Z, RelativePivotTargetLocation.Z, DeltaTime, LocationLagZ)
});
}

FVector UAlsCameraComponent::CalculatePivotOffset() const
Expand Down
16 changes: 0 additions & 16 deletions Source/ALSCamera/Public/AlsCameraSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,6 @@ struct ALSCAMERA_API FAlsThirdPersonCameraSettings
FAlsTraceDistanceSmoothingSettings TraceDistanceSmoothing;
};

USTRUCT(BlueprintType)
struct ALSCAMERA_API FAlsCameraLagSubsteppingSettings
{
GENERATED_BODY()

UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "ALS", Meta = (ClampMin = 0.005, ClampMax = 0.5, ForceUnits = "s"))
float LagSubstepDeltaTime{1.0f / 60.0f};
};

UCLASS(Blueprintable, BlueprintType)
class ALSCAMERA_API UAlsCameraSettings : public UDataAsset
{
Expand All @@ -92,13 +83,6 @@ class ALSCAMERA_API UAlsCameraSettings : public UDataAsset
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Settings")
FAlsThirdPersonCameraSettings ThirdPerson;

UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Settings", Meta = (InlineEditConditionToggle))
uint8 bEnableCameraLagSubstepping : 1 {false};

UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Settings",
DisplayName = "Enable Camera Lag Substepping", Meta = (EditCondition = "bEnableCameraLagSubstepping"))
FAlsCameraLagSubsteppingSettings CameraLagSubstepping;

UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Settings")
FPostProcessSettings PostProcess;

Expand Down

0 comments on commit f1cb9c2

Please sign in to comment.