6#include "DrawDebugHelpers.h"
7#include "GameFramework/Actor.h"
10UParabolaComponent::UParabolaComponent()
12 PrimaryComponentTick.bCanEverTick =
true;
16void UParabolaComponent::BeginPlay()
20 for (
auto& P : BallisticTracks)
22 for (
auto& P : GeometricTracks)
27void UParabolaComponent::TickComponent(
float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
29 Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
30 UpdateTracks(DeltaTime);
34void UParabolaComponent::UpdateTracks(
float DeltaTime)
36 for (
auto& P : BallisticTracks)
37 P.Value.Advance(DeltaTime);
38 for (
auto& P : GeometricTracks)
39 P.Value.Advance(DeltaTime);
45FRotator UParabolaComponent::GetParabolaFacing(FName TrackName,
bool bYawOnly,
EForwardAxis ForwardAxis)
const
49 const float CurAlpha = FMath::Clamp(Ballistic->GetAlpha(), 0.f, 1.f);
50 const float NextAlpha = FMath::Clamp(CurAlpha + 0.08f, 0.f, 1.f);
52 if (FMath::IsNearlyEqual(CurAlpha, NextAlpha))
53 return GetOwner()->GetActorRotation();
55 const FVector CurLocation = Ballistic->EvaluateAtAlpha(GetOwner(), CurAlpha);
56 const FVector NextLocation = Ballistic->EvaluateAtAlpha(GetOwner(), NextAlpha);
58 return MakeFacingFromDir(NextLocation - CurLocation, bYawOnly, ForwardAxis);
62 const float CurAlpha = FMath::Clamp(Geometric->GetAlpha(), 0.f, 1.f);
63 const float NextAlpha = FMath::Clamp(CurAlpha + 0.08f, 0.f, 1.f);
65 if (FMath::IsNearlyEqual(CurAlpha, NextAlpha))
66 return GetOwner()->GetActorRotation();
68 const FVector CurLocation = Geometric->EvaluateAtAlpha(GetOwner(), CurAlpha);
69 const FVector NextLocation = Geometric->EvaluateAtAlpha(GetOwner(), NextAlpha);
71 return MakeFacingFromDir(NextLocation - CurLocation, bYawOnly, ForwardAxis);
74 return GetOwner()->GetActorRotation();
78FRotator UParabolaComponent::MakeFacingFromDir(
const FVector& Direction,
const bool bYawOnly,
const EForwardAxis ForwardAxis)
const
80 FVector Dir = Direction;
86 return GetOwner() ? GetOwner()->GetActorRotation() : FRotator::ZeroRotator;
92 Rot = FRotationMatrix::MakeFromX(Dir).Rotator();
95 Rot = FRotationMatrix::MakeFromY(Dir).Rotator();
98 Rot = FRotationMatrix::MakeFromZ(Dir).Rotator();
101 Rot = FRotationMatrix::MakeFromX(Dir).Rotator();
124 BallisticTracks.FindOrAdd(TrackName) = Copy;
128FVector UParabolaComponent::GetBallisticParabolaVectorTrack(FName TrackName)
const
134 return FVector::ZeroVector;
138FVector UParabolaComponent::GetBallisticVectorAtAlphaFromTrack(FName TrackName,
float Alpha)
const
142 return T->EvaluateAtAlpha(GetOwner(), Alpha);
144 return FVector::ZeroVector;
148void UParabolaComponent::DrawBallisticPath(FName TrackName, int32 NumSegments, FColor
Color,
float LifeTime)
const
152 const float StepTime = T->Duration / NumSegments;
153 FVector PrevPos = T->EvaluateAtTime(GetOwner(), 0.f);
155 for (int32 i = 1; i <= NumSegments; ++i)
157 float t = StepTime * i;
158 FVector CurrPos = T->EvaluateAtTime(GetOwner(), t);
184 GeometricTracks.FindOrAdd(TrackName) = Copy;
188FVector UParabolaComponent::GetGeometricParabolaVectorTrack(FName TrackName)
const
194 return FVector::ZeroVector;
198FVector UParabolaComponent::GetGeometricVectorAtAlphaFromTrack(FName TrackName,
float Alpha)
const
202 return T->EvaluateAtAlpha(GetOwner(), Alpha);
204 return FVector::ZeroVector;
208void UParabolaComponent::DrawGeometricPath(FName TrackName, int32 NumSegments, FColor
Color,
float LifeTime)
const
212 const float StepAlpha = 1.f / NumSegments;
213 FVector PrevPos = T->EvaluateAtAlpha(GetOwner(), 0.f);
215 for (int32 i = 1; i <= NumSegments; ++i)
217 float a = StepAlpha * i;
218 FVector CurrPos = T->EvaluateAtAlpha(GetOwner(), a);
EParabolaType 클래스를 선언합니다.
EForwardAxis
정면 방향 축을 지정한다.
물리 기반(초기 속도/중력) 포물선을 계산하는 트랙.
FORCEINLINE FVector EvaluateAtCurrent(const AActor *Owner) const
현재 시간 기준 위치를 계산한다.
정점 높이를 지정해 기하학적 포물선을 계산하는 트랙.
FORCEINLINE FVector EvaluateAtCurrent(const AActor *Owner) const
현재 시간 기준 위치를 계산한다.