#pragma region CPL License /* Nuclex Unreal Module Copyright (C) 2014-2021 Nuclex Development Labs This library is free software; you can redistribute it and/or modify it under the terms of the IBM Common Public License as published by the IBM Corporation; either version 1.0 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the IBM Common Public License for more details. You should have received a copy of the IBM Common Public License along with this library */ #pragma endregion // CPL License #include "FlyCameraAction.h" // --------------------------------------------------------------------------------------------- // FFlyCameraAction::FFlyCameraAction( const FLatentActionInfo &latentInfo, APawn *pawn, const FTransform &target, float durationSeconds, EEasingFunc::Type easingFunction ) : callbackTarget(latentInfo.CallbackTarget), executionFunction(latentInfo.ExecutionFunction), outputLink(latentInfo.Linkage), pawn(pawn), origin(pawn->GetTransform()), target(target), durationSeconds(durationSeconds), elapsedSeconds(0.0f), easingFunction(easingFunction) {} // --------------------------------------------------------------------------------------------- // void FFlyCameraAction::UpdateOperation(FLatentResponse &response) { const bool fadeAudio = true; const TEnumAsByte interpolationMode( ELerpInterpolationMode::QuatInterp ); this->elapsedSeconds += response.ElapsedTime(); bool isFinished = (this->elapsedSeconds >= this->durationSeconds); if(isFinished) { updatePawnTransform(this->target); } else { float t = this->elapsedSeconds / this->durationSeconds; t = UKismetMathLibrary::Ease(0.0f, 1.0f, t, this->easingFunction); FTransform interpolated = UKismetMathLibrary::TLerp( this->origin, this->target, t, interpolationMode ); updatePawnTransform(interpolated); } response.FinishAndTriggerIf( isFinished, this->executionFunction, this->outputLink, this->callbackTarget ); } // --------------------------------------------------------------------------------------------- // void FFlyCameraAction::updatePawnTransform(const FTransform &newTransform) { bool success; { bool sweep = false; FHitResult *sweepResult = nullptr; success = this->pawn->SetActorTransform( newTransform, sweep, sweepResult, ETeleportType::ResetPhysics ); } if(!success) { UE_LOG( LogTemp, Warning, TEXT("FlyCameraAction::updatePawnTransform() - APawn::SetActorTransform() failed") ); } } // --------------------------------------------------------------------------------------------- //