Skip to content
Snippets Groups Projects
Commit 5a3ef6a1 authored by Timon Römer's avatar Timon Römer
Browse files

Cleanup and Format

parent 536a4bdf
Branches
Tags
2 merge requests!81Inten Select 5.3,!80UE5.3-2023.1-rc2
Pipeline #371698 failed
Showing
with 629 additions and 503 deletions
......@@ -8,17 +8,16 @@
#include "Misc/MessageDialog.h"
#include "Pawn/IntenSelectComponent.h"
UIntenSelectable::UIntenSelectable()
{
PrimaryComponentTick.bCanEverTick = true;
}
UIntenSelectable::UIntenSelectable() { PrimaryComponentTick.bCanEverTick = true; }
TPair<FHitResult, float> UIntenSelectable::GetBestPointScorePair(const FVector& ConeOrigin,
const FVector& ConeForwardDirection, const float ConeBackwardShiftDistance, const float ConeAngle,
const float LastValue, const float DeltaTime) const
const FVector& ConeForwardDirection,
const float ConeBackwardShiftDistance,
const float ConeAngle, const float LastValue,
const float DeltaTime) const
{
checkf(ScoringBehaviour,TEXT("%s"),*GetOwner()->GetName())
return ScoringBehaviour->GetBestPointScorePair(ConeOrigin, ConeForwardDirection, ConeBackwardShiftDistance, ConeAngle, LastValue, DeltaTime);
checkf(ScoringBehaviour, TEXT("%s"), *GetOwner()->GetName()) return ScoringBehaviour->GetBestPointScorePair(
ConeOrigin, ConeForwardDirection, ConeBackwardShiftDistance, ConeAngle, LastValue, DeltaTime);
}
void UIntenSelectable::HandleOnSelectStartEvents(const UIntenSelectComponent* IntenSelect, const FHitResult& HitResult)
......@@ -59,14 +58,18 @@ void UIntenSelectable::HandleOnClickEndEvents(UIntenSelectComponent* IntenSelect
void UIntenSelectable::InitDefaultBehaviourReferences()
{
// Scoring
if(UIntenSelectableScoring* AttachedScoring = Cast<UIntenSelectableScoring>(GetOwner()->GetComponentByClass(UIntenSelectableScoring::StaticClass())))
if (UIntenSelectableScoring* AttachedScoring =
Cast<UIntenSelectableScoring>(GetOwner()->GetComponentByClass(UIntenSelectableScoring::StaticClass())))
{
ScoringBehaviour = AttachedScoring;
}else
}
else
{
ScoringBehaviour = NewObject<UIntenSelectableSinglePointScoring>(this, UIntenSelectableSinglePointScoring::StaticClass(), "Default Scoring");
ScoringBehaviour = NewObject<UIntenSelectableSinglePointScoring>(
this, UIntenSelectableSinglePointScoring::StaticClass(), "Default Scoring");
ScoringBehaviour->SetWorldLocation(GetOwner()->GetActorLocation());
ScoringBehaviour->AttachToComponent(GetOwner()->GetRootComponent(), FAttachmentTransformRules::SnapToTargetNotIncludingScale);
ScoringBehaviour->AttachToComponent(GetOwner()->GetRootComponent(),
FAttachmentTransformRules::SnapToTargetNotIncludingScale);
}
// Selecting
......@@ -102,9 +105,11 @@ void UIntenSelectable::BeginPlay()
{
if (!ScoringBehaviour)
{
ShowErrorAndQuit("Please assign the Scoring Behaviour manually when using more than one IntenSelectable Component!");
ShowErrorAndQuit(
"Please assign the Scoring Behaviour manually when using more than one IntenSelectable Component!");
}
}
}else
else
{
InitDefaultBehaviourReferences();
}
......
......@@ -6,17 +6,16 @@
#include "Kismet/KismetMathLibrary.h"
// Sets default values for this component's properties
UIntenSelectableCircleScoring::UIntenSelectableCircleScoring()
{
PrimaryComponentTick.bCanEverTick = true;
}
UIntenSelectableCircleScoring::UIntenSelectableCircleScoring() { PrimaryComponentTick.bCanEverTick = true; }
TPair<FHitResult, float> UIntenSelectableCircleScoring::GetBestPointScorePair(const FVector& ConeOrigin,
const FVector& ConeForwardDirection, const float ConeBackwardShiftDistance, const float ConeAngle,
TPair<FHitResult, float>
UIntenSelectableCircleScoring::GetBestPointScorePair(const FVector& ConeOrigin, const FVector& ConeForwardDirection,
const float ConeBackwardShiftDistance, const float ConeAngle,
const float LastValue, const float DeltaTime)
{
const FVector Point = GetClosestSelectionPointTo(ConeOrigin, ConeForwardDirection);
float Score = GetScore(ConeOrigin, ConeForwardDirection, ConeBackwardShiftDistance, ConeAngle, Point, LastValue, DeltaTime);
float Score =
GetScore(ConeOrigin, ConeForwardDirection, ConeBackwardShiftDistance, ConeAngle, Point, LastValue, DeltaTime);
FHitResult Result = FHitResult{GetOwner(), nullptr, Point, FVector::ForwardVector};
return TPair<FHitResult, float>{Result, Score};
}
......@@ -24,11 +23,13 @@ TPair<FHitResult, float> UIntenSelectableCircleScoring::GetBestPointScorePair(co
FVector UIntenSelectableCircleScoring::GetClosestSelectionPointTo(const FVector& Point, const FVector& Direction) const
{
const FVector CenterWorld = this->GetComponentLocation();
const FVector CircleNormalWorld = this->GetComponentTransform().TransformPositionNoScale(FVector::ForwardVector) - CenterWorld;
const FVector CircleNormalWorld =
this->GetComponentTransform().TransformPositionNoScale(FVector::ForwardVector) - CenterWorld;
float t;
FVector Intersect;
if(!UKismetMathLibrary::LinePlaneIntersection_OriginNormal(Point, Point + Direction * 100000, CenterWorld, CircleNormalWorld, t, Intersect))
if (!UKismetMathLibrary::LinePlaneIntersection_OriginNormal(Point, Point + Direction * 100000, CenterWorld,
CircleNormalWorld, t, Intersect))
{
return CenterWorld;
}
......@@ -39,14 +40,16 @@ FVector UIntenSelectableCircleScoring::GetClosestSelectionPointTo(const FVector&
if (OnlyOutline)
{
Result = (CenterToPoint.GetSafeNormal() * Radius) + CenterWorld;
}else
}
else
{
const float DistanceToCenter = CenterToPoint.Size();
if (DistanceToCenter >= Radius)
{
Result = (CenterToPoint.GetSafeNormal() * Radius) + CenterWorld;
}else
}
else
{
Result = Intersect;
}
......
......@@ -13,17 +13,21 @@ UIntenSelectableCubeScoring::UIntenSelectableCubeScoring()
SetRelativeScale3D(FVector::One() * 100);
}
TPair<FHitResult, float> UIntenSelectableCubeScoring::GetBestPointScorePair(const FVector& ConeOrigin,
const FVector& ConeForwardDirection, const float ConeBackwardShiftDistance, const float ConeAngle,
TPair<FHitResult, float>
UIntenSelectableCubeScoring::GetBestPointScorePair(const FVector& ConeOrigin, const FVector& ConeForwardDirection,
const float ConeBackwardShiftDistance, const float ConeAngle,
const float LastValue, const float DeltaTime)
{
FVector Point = GetClosestSelectionPointTo(ConeOrigin, ConeForwardDirection);
float Score = Super::GetScore(ConeOrigin, ConeForwardDirection, ConeBackwardShiftDistance, ConeAngle, Point, LastValue, DeltaTime);
float Score = Super::GetScore(ConeOrigin, ConeForwardDirection, ConeBackwardShiftDistance, ConeAngle, Point,
LastValue, DeltaTime);
FHitResult Result = FHitResult{GetOwner(), nullptr, Point, FVector::ForwardVector};
return TPair<FHitResult, float>{Result, Score};
}
FVector UIntenSelectableCubeScoring::GetClosestPointToRectangle(const FVector& StartPoint, const FVector& Direction, const FVector& Corner00, const FVector& Corner01, const FVector& Corner10, const FVector& Corner11) const
FVector UIntenSelectableCubeScoring::GetClosestPointToRectangle(const FVector& StartPoint, const FVector& Direction,
const FVector& Corner00, const FVector& Corner01,
const FVector& Corner10, const FVector& Corner11) const
{
const float X = FVector::Distance(Corner00, Corner10);
const float Y = FVector::Distance(Corner00, Corner01);
......@@ -31,14 +35,16 @@ FVector UIntenSelectableCubeScoring::GetClosestPointToRectangle(const FVector& S
FVector Intersection;
float T;
UKismetMathLibrary::LinePlaneIntersection_OriginNormal(StartPoint, StartPoint + Direction * 10000, Corner00, PlaneNormal, T, Intersection);
UKismetMathLibrary::LinePlaneIntersection_OriginNormal(StartPoint, StartPoint + Direction * 10000, Corner00,
PlaneNormal, T, Intersection);
FVector LocalIntersection = this->GetComponentTransform().InverseTransformPosition(Intersection);
if (LocalIntersection.Y > X / 2)
{
LocalIntersection.Y = X / 2;
}else if(LocalIntersection.Y < -X / 2)
}
else if (LocalIntersection.Y < -X / 2)
{
LocalIntersection.Y = -X / 2;
}
......@@ -46,7 +52,8 @@ FVector UIntenSelectableCubeScoring::GetClosestPointToRectangle(const FVector& S
if (LocalIntersection.Z > Y / 2)
{
LocalIntersection.Z = Y / 2;
}else if(LocalIntersection.Z < -Y / 2)
}
else if (LocalIntersection.Z < -Y / 2)
{
LocalIntersection.Z = -Y / 2;
}
......@@ -118,7 +125,8 @@ FVector UIntenSelectableCubeScoring::GetClosestPointToRectangle(const FVector& S
return this->GetComponentTransform().TransformPosition(LocalIntersection);
}
bool UIntenSelectableCubeScoring::LineToLineIntersection(const FVector& FromA, const FVector& FromB, const FVector& ToA, const FVector& ToB, FVector& OutIntersection)
bool UIntenSelectableCubeScoring::LineToLineIntersection(const FVector& FromA, const FVector& FromB, const FVector& ToA,
const FVector& ToB, FVector& OutIntersection)
{
const FVector Da = ToA - FromA;
const FVector DB = ToB - FromB;
......@@ -128,7 +136,8 @@ bool UIntenSelectableCubeScoring::LineToLineIntersection(const FVector& FromA, c
const float Prod = CrossDaDb.X * CrossDaDb.X + CrossDaDb.Y * CrossDaDb.Y + CrossDaDb.Z * CrossDaDb.Z;
const float Res = FVector::DotProduct(FVector::CrossProduct(DC, DB), FVector::CrossProduct(Da, DB) / Prod);
if (Res >= -0.02f && Res <= 1.02f) {
if (Res >= -0.02f && Res <= 1.02f)
{
OutIntersection = FromA + Da * FVector(Res, Res, Res);
return true;
}
......@@ -188,19 +197,21 @@ FVector UIntenSelectableCubeScoring::GetClosestSelectionPointTo(const FVector& R
{
if (DrawDebug)
{
DrawDebugSolidPlane(GetWorld(), Plane, GetComponentLocation(), 20, FColor::Red.WithAlpha(9), false, -1, 0);
DrawDebugSolidPlane(GetWorld(), Plane, GetComponentLocation(), 20, FColor::Red.WithAlpha(9), false, -1,
0);
}
continue;
}else
}
else
{
if (DrawDebug)
{
DrawDebugSolidPlane(GetWorld(), Plane, GetComponentLocation(), 20, FColor::Green.WithAlpha(9), false, -1, 0);
DrawDebugSolidPlane(GetWorld(), Plane, GetComponentLocation(), 20, FColor::Green.WithAlpha(9), false,
-1, 0);
}
}
FVector CurrentPoint = FMath::RayPlaneIntersection(RayOrigin, RayDirection, Plane);
FVector CurrentPointLocal = GetComponentTransform().InverseTransformPositionNoScale(CurrentPoint);
......@@ -224,39 +235,43 @@ FVector UIntenSelectableCubeScoring::GetClosestSelectionPointTo(const FVector& R
if (XSnapDist < ZSnapDist)
{
SnapZ = false;
}else
}
else
{
SnapX = false;
}
}else if(FVector::Parallel(Plane.GetNormal(), GetUpVector()))
}
else if (FVector::Parallel(Plane.GetNormal(), GetUpVector()))
{
if (XSnapDist < YSnapDist)
{
SnapY = false;
}else
}
else
{
SnapX = false;
}
}else if(FVector::Parallel(Plane.GetNormal(), GetForwardVector()))
}
else if (FVector::Parallel(Plane.GetNormal(), GetForwardVector()))
{
if (YSnapDist < ZSnapDist)
{
SnapZ = false;
}else
}
else
{
SnapY = false;
}
}
if (SnapX)
{
if (CurrentPointLocal.X > 0)
{
CurrentPointLocal.X = Scale.X / 2;
}else
}
else
{
CurrentPointLocal.X = -Scale.X / 2;
}
......@@ -266,7 +281,8 @@ FVector UIntenSelectableCubeScoring::GetClosestSelectionPointTo(const FVector& R
if (CurrentPointLocal.Y > 0)
{
CurrentPointLocal.Y = Scale.Y / 2;
}else
}
else
{
CurrentPointLocal.Y = -Scale.Y / 2;
}
......@@ -276,7 +292,8 @@ FVector UIntenSelectableCubeScoring::GetClosestSelectionPointTo(const FVector& R
if (CurrentPointLocal.Z > 0)
{
CurrentPointLocal.Z = Scale.Z / 2;
}else
}
else
{
CurrentPointLocal.Z = -Scale.Z / 2;
}
......@@ -294,7 +311,8 @@ FVector UIntenSelectableCubeScoring::GetClosestSelectionPointTo(const FVector& R
{
if (MinDistance < 0.001)
{
const float DistToPlayerOld = IsSet ? FVector::Distance(RayOrigin, ClosestPoint) : TNumericLimits<float>::Max();
const float DistToPlayerOld =
IsSet ? FVector::Distance(RayOrigin, ClosestPoint) : TNumericLimits<float>::Max();
const float DistToPlayerNew = FVector::Distance(RayOrigin, CurrentPoint);
if (DistToPlayerNew < DistToPlayerOld)
......@@ -303,13 +321,15 @@ FVector UIntenSelectableCubeScoring::GetClosestSelectionPointTo(const FVector& R
ClosestPoint = CurrentPoint;
IsSet = true;
}
}else
}
else
{
MinDistance = Distance;
ClosestPoint = CurrentPoint;
IsSet = true;
}
}else
}
else
{
if (Distance < MinDistance)
{
......@@ -320,7 +340,9 @@ FVector UIntenSelectableCubeScoring::GetClosestSelectionPointTo(const FVector& R
}
}
if(DrawDebug) DrawDebugBox(GetWorld(), GetComponentLocation(), FVector(Scale.X, Scale.Y, Scale.Z) /2, GetComponentRotation().Quaternion(), FColor::Green, false, -1, 0, 2);
if (DrawDebug)
DrawDebugBox(GetWorld(), GetComponentLocation(), FVector(Scale.X, Scale.Y, Scale.Z) / 2,
GetComponentRotation().Quaternion(), FColor::Green, false, -1, 0, 2);
return ClosestPoint;
}
......
......@@ -7,22 +7,23 @@
#include "Kismet/KismetMathLibrary.h"
// Sets default values for this component's properties
UIntenSelectableCylinderScoring::UIntenSelectableCylinderScoring()
{
PrimaryComponentTick.bCanEverTick = true;
}
UIntenSelectableCylinderScoring::UIntenSelectableCylinderScoring() { PrimaryComponentTick.bCanEverTick = true; }
TPair<FHitResult, float> UIntenSelectableCylinderScoring::GetBestPointScorePair(const FVector& ConeOrigin,
const FVector& ConeForwardDirection, const float ConeBackwardShiftDistance, const float ConeAngle,
TPair<FHitResult, float>
UIntenSelectableCylinderScoring::GetBestPointScorePair(const FVector& ConeOrigin, const FVector& ConeForwardDirection,
const float ConeBackwardShiftDistance, const float ConeAngle,
const float LastValue, const float DeltaTime)
{
FVector Point = GetClosestSelectionPointTo(ConeOrigin, ConeForwardDirection);
float Score = GetScore(ConeOrigin, ConeForwardDirection, ConeBackwardShiftDistance, ConeAngle, Point, LastValue, DeltaTime);
float Score =
GetScore(ConeOrigin, ConeForwardDirection, ConeBackwardShiftDistance, ConeAngle, Point, LastValue, DeltaTime);
FHitResult Result = FHitResult{GetOwner(), nullptr, Point, FVector::ForwardVector};
return TPair<FHitResult, float>{Result, Score};
}
bool UIntenSelectableCylinderScoring::LineToLineIntersection(const FVector& FromA, const FVector& FromB, const FVector& ToA, const FVector& ToB, FVector& OutIntersection)
bool UIntenSelectableCylinderScoring::LineToLineIntersection(const FVector& FromA, const FVector& FromB,
const FVector& ToA, const FVector& ToB,
FVector& OutIntersection)
{
const FVector Da = ToA - FromA;
const FVector DB = ToB - FromB;
......@@ -32,7 +33,8 @@ bool UIntenSelectableCylinderScoring::LineToLineIntersection(const FVector& From
const float Prod = CrossDaDb.X * CrossDaDb.X + CrossDaDb.Y * CrossDaDb.Y + CrossDaDb.Z * CrossDaDb.Z;
const float Res = FVector::DotProduct(FVector::CrossProduct(DC, DB), FVector::CrossProduct(Da, DB) / Prod);
if (Res >= -0.02f && Res <= 1.02f) {
if (Res >= -0.02f && Res <= 1.02f)
{
OutIntersection = FromA + Da * FVector(Res, Res, Res);
return true;
}
......@@ -40,7 +42,8 @@ bool UIntenSelectableCylinderScoring::LineToLineIntersection(const FVector& From
return false;
}
FVector UIntenSelectableCylinderScoring::GetClosestSelectionPointTo(const FVector& Point, const FVector& Direction) const
FVector UIntenSelectableCylinderScoring::GetClosestSelectionPointTo(const FVector& Point,
const FVector& Direction) const
{
const FVector CylinderStartWorld = this->GetComponentTransform().TransformPosition(LinePoints[0]);
const FVector CylinderEndWorld = this->GetComponentTransform().TransformPosition(LinePoints[1]);
......@@ -83,7 +86,8 @@ FVector UIntenSelectableCylinderScoring::GetClosestSelectionPointTo(const FVecto
FVector ShiftResult = ProjectionToSphere.GetSafeNormal() * Radius;
ShiftResult -= ShiftResult.ProjectOnTo(CylinderDir);
return Result - ShiftResult;
}else
}
else
{
FVector ShiftResult = ProjectionToSphere.GetSafeNormal() * ProjLength;
ShiftResult -= ShiftResult.ProjectOnTo(CylinderDir);
......
......@@ -19,17 +19,20 @@ UIntenSelectableLineScoring::UIntenSelectableLineScoring()
}
}
TPair<FHitResult, float> UIntenSelectableLineScoring::GetBestPointScorePair(const FVector& ConeOrigin,
const FVector& ConeForwardDirection, const float ConeBackwardShiftDistance, const float ConeAngle,
TPair<FHitResult, float>
UIntenSelectableLineScoring::GetBestPointScorePair(const FVector& ConeOrigin, const FVector& ConeForwardDirection,
const float ConeBackwardShiftDistance, const float ConeAngle,
const float LastValue, const float DeltaTime)
{
FVector Point = GetClosestSelectionPointTo(ConeOrigin, ConeForwardDirection);
float Score = GetScore(ConeOrigin, ConeForwardDirection, ConeBackwardShiftDistance, ConeAngle, Point, LastValue, DeltaTime);
float Score =
GetScore(ConeOrigin, ConeForwardDirection, ConeBackwardShiftDistance, ConeAngle, Point, LastValue, DeltaTime);
FHitResult Result = FHitResult{GetOwner(), nullptr, Point, FVector::ForwardVector};
return TPair<FHitResult, float>{Result, Score};
}
bool UIntenSelectableLineScoring::LineToLineIntersection(const FVector& FromA, const FVector& FromB, const FVector& ToA, const FVector& ToB, FVector& OutIntersection)
bool UIntenSelectableLineScoring::LineToLineIntersection(const FVector& FromA, const FVector& FromB, const FVector& ToA,
const FVector& ToB, FVector& OutIntersection)
{
const FVector Da = ToA - FromA;
const FVector DB = ToB - FromB;
......@@ -39,7 +42,8 @@ bool UIntenSelectableLineScoring::LineToLineIntersection(const FVector& FromA, c
const float Prod = CrossDaDb.X * CrossDaDb.X + CrossDaDb.Y * CrossDaDb.Y + CrossDaDb.Z * CrossDaDb.Z;
const float Res = FVector::DotProduct(FVector::CrossProduct(DC, DB), FVector::CrossProduct(Da, DB) / Prod);
if (Res >= -0.02f && Res <= 1.02f) {
if (Res >= -0.02f && Res <= 1.02f)
{
OutIntersection = FromA + Da * FVector(Res, Res, Res);
return true;
}
......
......@@ -9,25 +9,26 @@
UIntenSelectableMultiPointScoring::UIntenSelectableMultiPointScoring()
{
PrimaryComponentTick.bCanEverTick = true;
PointsToSelect = TArray<FVector>{FVector::UpVector * 100, FVector::DownVector * 100, FVector::RightVector * 100, FVector::LeftVector * 100};
PointsToSelect = TArray<FVector>{FVector::UpVector * 100, FVector::DownVector * 100, FVector::RightVector * 100,
FVector::LeftVector * 100};
}
TPair<FHitResult, float> UIntenSelectableMultiPointScoring::GetBestPointScorePair(const FVector& ConeOrigin,
const FVector& ConeForwardDirection, const float ConeBackwardShiftDistance, const float ConeAngle,
TPair<FHitResult, float>
UIntenSelectableMultiPointScoring::GetBestPointScorePair(const FVector& ConeOrigin, const FVector& ConeForwardDirection,
const float ConeBackwardShiftDistance, const float ConeAngle,
const float LastValue, const float DeltaTime)
{
FVector Point = GetClosestSelectionPointTo(ConeOrigin, ConeForwardDirection);
float Score = Super::GetScore(ConeOrigin, ConeForwardDirection, ConeBackwardShiftDistance, ConeAngle, Point, LastValue, DeltaTime);
float Score = Super::GetScore(ConeOrigin, ConeForwardDirection, ConeBackwardShiftDistance, ConeAngle, Point,
LastValue, DeltaTime);
FHitResult Result = FHitResult{GetOwner(), nullptr, Point, FVector::ForwardVector};
return TPair<FHitResult, float>{Result, Score};
}
void UIntenSelectableMultiPointScoring::UpdatePoints()
{
}
void UIntenSelectableMultiPointScoring::UpdatePoints() {}
FVector UIntenSelectableMultiPointScoring::GetClosestSelectionPointTo(const FVector& Point, const FVector& Direction) const
FVector UIntenSelectableMultiPointScoring::GetClosestSelectionPointTo(const FVector& Point,
const FVector& Direction) const
{
if (PointsToSelect.Num() == 0)
{
......
......@@ -6,22 +6,23 @@
#include "Kismet/KismetMathLibrary.h"
// Sets default values for this component's properties
UIntenSelectableRectangleScoring::UIntenSelectableRectangleScoring()
{
PrimaryComponentTick.bCanEverTick = true;
}
UIntenSelectableRectangleScoring::UIntenSelectableRectangleScoring() { PrimaryComponentTick.bCanEverTick = true; }
TPair<FHitResult, float> UIntenSelectableRectangleScoring::GetBestPointScorePair(const FVector& ConeOrigin,
const FVector& ConeForwardDirection, const float ConeBackwardShiftDistance, const float ConeAngle,
TPair<FHitResult, float>
UIntenSelectableRectangleScoring::GetBestPointScorePair(const FVector& ConeOrigin, const FVector& ConeForwardDirection,
const float ConeBackwardShiftDistance, const float ConeAngle,
const float LastValue, const float DeltaTime)
{
FVector Point = GetClosestSelectionPointTo(ConeOrigin, ConeForwardDirection);
float Score = Super::GetScore(ConeOrigin, ConeForwardDirection, ConeBackwardShiftDistance, ConeAngle, Point, LastValue, DeltaTime);
float Score = Super::GetScore(ConeOrigin, ConeForwardDirection, ConeBackwardShiftDistance, ConeAngle, Point,
LastValue, DeltaTime);
FHitResult Result = FHitResult{GetOwner(), nullptr, Point, FVector::ForwardVector};
return TPair<FHitResult, float>{Result, Score};
}
bool UIntenSelectableRectangleScoring::LineToLineIntersection(const FVector& FromA, const FVector& FromB, const FVector& ToA, const FVector& ToB, FVector& OutIntersection)
bool UIntenSelectableRectangleScoring::LineToLineIntersection(const FVector& FromA, const FVector& FromB,
const FVector& ToA, const FVector& ToB,
FVector& OutIntersection)
{
const FVector Da = ToA - FromA;
const FVector DB = ToB - FromB;
......@@ -31,7 +32,8 @@ bool UIntenSelectableRectangleScoring::LineToLineIntersection(const FVector& Fro
const float Prod = CrossDaDb.X * CrossDaDb.X + CrossDaDb.Y * CrossDaDb.Y + CrossDaDb.Z * CrossDaDb.Z;
const float Res = FVector::DotProduct(FVector::CrossProduct(DC, DB), FVector::CrossProduct(Da, DB) / Prod);
if (Res >= -0.02f && Res <= 1.02f) {
if (Res >= -0.02f && Res <= 1.02f)
{
OutIntersection = FromA + Da * FVector(Res, Res, Res);
return true;
}
......@@ -39,28 +41,33 @@ bool UIntenSelectableRectangleScoring::LineToLineIntersection(const FVector& Fro
return false;
}
FVector UIntenSelectableRectangleScoring::GetClosestSelectionPointTo(const FVector& Point, const FVector& Direction) const
FVector UIntenSelectableRectangleScoring::GetClosestSelectionPointTo(const FVector& Point,
const FVector& Direction) const
{
const FVector X = this->GetRightVector() * XLength;
const FVector Y = this->GetUpVector() * YLength;
const FVector CornerWorld00 = this->GetComponentTransform().TransformPosition(FVector::ZeroVector) - (X / 2) - (Y / 2);
const FVector CornerWorld00 =
this->GetComponentTransform().TransformPosition(FVector::ZeroVector) - (X / 2) - (Y / 2);
const FVector CornerWorld10 = CornerWorld00 + X;
const FVector CornerWorld01 = CornerWorld00 + Y;
const FVector CornerWorld11 = CornerWorld00 + X + Y;
const FVector PlaneNormal = FVector::CrossProduct(CornerWorld10 - CornerWorld00, CornerWorld01 - CornerWorld00).GetSafeNormal();
const FVector PlaneNormal =
FVector::CrossProduct(CornerWorld10 - CornerWorld00, CornerWorld01 - CornerWorld00).GetSafeNormal();
FVector Intersection;
float T;
UKismetMathLibrary::LinePlaneIntersection_OriginNormal(Point, Point + Direction * 10000, CornerWorld00, PlaneNormal, T, Intersection);
UKismetMathLibrary::LinePlaneIntersection_OriginNormal(Point, Point + Direction * 10000, CornerWorld00, PlaneNormal,
T, Intersection);
FVector LocalIntersection = this->GetComponentTransform().InverseTransformPosition(Intersection);
if (LocalIntersection.Y > XLength / 2)
{
LocalIntersection.Y = XLength / 2;
}else if(LocalIntersection.Y < -XLength / 2)
}
else if (LocalIntersection.Y < -XLength / 2)
{
LocalIntersection.Y = -XLength / 2;
}
......@@ -68,7 +75,8 @@ FVector UIntenSelectableRectangleScoring::GetClosestSelectionPointTo(const FVect
if (LocalIntersection.Z > YLength / 2)
{
LocalIntersection.Z = YLength / 2;
}else if(LocalIntersection.Z < -YLength / 2)
}
else if (LocalIntersection.Z < -YLength / 2)
{
LocalIntersection.Z = -YLength / 2;
}
......@@ -87,25 +95,29 @@ FVector UIntenSelectableRectangleScoring::GetClosestSelectionPointTo(const FVect
{
// snap left
LocalIntersection.Y = -(XLength / 2);
}else
}
else
{
// snap bottom
LocalIntersection.Z = -(YLength / 2);
}
}else
}
else
{
// bottom and right
if (XLength - DistToLeft < DistToBottom)
{
// snap right
LocalIntersection.Y = XLength / 2;
}else
}
else
{
// snap bottom
LocalIntersection.Z = -(YLength / 2);
}
}
}else
}
else
{
if (LocalIntersection.Y < 0)
{
......@@ -114,19 +126,22 @@ FVector UIntenSelectableRectangleScoring::GetClosestSelectionPointTo(const FVect
{
// snap left
LocalIntersection.Y = -(XLength / 2);
}else
}
else
{
// snap top
LocalIntersection.Z = (YLength / 2);
}
}else
}
else
{
// top and right
if (XLength - DistToLeft < YLength - DistToBottom)
{
// snap right
LocalIntersection.Y = XLength / 2;
}else
}
else
{
// snap top
LocalIntersection.Z = (YLength / 2);
......@@ -148,7 +163,8 @@ void UIntenSelectableRectangleScoring::TickComponent(float DeltaTime, ELevelTick
const FVector X = this->GetRightVector() * XLength;
const FVector Y = this->GetUpVector() * YLength;
const FVector CornerWorld00 = this->GetComponentTransform().TransformPosition(FVector::ZeroVector) - (X / 2) - (Y / 2);
const FVector CornerWorld00 =
this->GetComponentTransform().TransformPosition(FVector::ZeroVector) - (X / 2) - (Y / 2);
const FVector CornerWorld10 = CornerWorld00 + X;
const FVector CornerWorld01 = CornerWorld00 + Y;
const FVector CornerWorld11 = CornerWorld00 + X + Y;
......
......@@ -4,31 +4,38 @@
#include "Interaction/Interactables/IntenSelect/IntenSelectableScoring.h"
float UIntenSelectableScoring::GetScore(const FVector& ConeOrigin, const FVector& ConeForwardDirection,
const float ConeBackwardShiftDistance, const float ConeAngle, const FVector& TestPoint, const float LastValue,
const float DeltaTime)
const float ConeBackwardShiftDistance, const float ConeAngle,
const FVector& TestPoint, const float LastValue, const float DeltaTime)
{
const FVector ShiftedConeOrigin = ConeOrigin - (ConeForwardDirection * ConeBackwardShiftDistance);
const float D_Perspective = FMath::PointDistToLine(TestPoint, ConeForwardDirection, ShiftedConeOrigin);
const float D_Projection = (TestPoint - ShiftedConeOrigin).ProjectOnTo(ConeForwardDirection).Size();
const float Angle = FMath::RadiansToDegrees(FMath::Atan(D_Perspective / (FMath::Pow(D_Projection / 100, CompensationConstant) * 100)));
const float Angle = FMath::RadiansToDegrees(
FMath::Atan(D_Perspective / (FMath::Pow(D_Projection / 100, CompensationConstant) * 100)));
float S_Contrib = 1 - (Angle / ConeAngle);
if(S_Contrib < 0) S_Contrib = 0;
if (S_Contrib < 0)
S_Contrib = 0;
//GEngine->AddOnScreenDebugMessage(INDEX_NONE, 0, FColor::Red, GetOwner()->GetName() + " - Contrib: " + FString::FromInt(S_Contrib));
// GEngine->AddOnScreenDebugMessage(INDEX_NONE, 0, FColor::Red, GetOwner()->GetName() + " - Contrib: " +
// FString::FromInt(S_Contrib));
if (LastValue != 0)
{
constexpr float Interpolate = 0.5;
if (S_Contrib > LastValue)
{
CurrentScore = LastValue + (((LastValue * Interpolate) + (S_Contrib * (1-Interpolate))) - LastValue) * DeltaTime * Snappiness;
}else
CurrentScore = LastValue +
(((LastValue * Interpolate) + (S_Contrib * (1 - Interpolate))) - LastValue) * DeltaTime * Snappiness;
}
else
{
CurrentScore = LastValue + (((LastValue * Interpolate) + (S_Contrib * (1-Interpolate))) - LastValue) * DeltaTime * Stickiness;
CurrentScore = LastValue +
(((LastValue * Interpolate) + (S_Contrib * (1 - Interpolate))) - LastValue) * DeltaTime * Stickiness;
}
}
}else
else
{
CurrentScore = S_Contrib * Snappiness * DeltaTime;
}
......@@ -36,20 +43,15 @@ float UIntenSelectableScoring::GetScore(const FVector& ConeOrigin, const FVector
}
// Sets default values for this component's properties
UIntenSelectableScoring::UIntenSelectableScoring()
{
PrimaryComponentTick.bCanEverTick = true;
}
UIntenSelectableScoring::UIntenSelectableScoring() { PrimaryComponentTick.bCanEverTick = true; }
TPair<FHitResult, float> UIntenSelectableScoring::GetBestPointScorePair(const FVector& ConeOrigin,
const FVector& ConeForwardDirection, const float ConeBackwardShiftDistance, const float ConeAngle,
const float LastValue, const float DeltaTime)
const FVector& ConeForwardDirection,
const float ConeBackwardShiftDistance,
const float ConeAngle, const float LastValue,
const float DeltaTime)
{
return {};
}
void UIntenSelectableScoring::BeginPlay()
{
Super::BeginPlay();
}
void UIntenSelectableScoring::BeginPlay() { Super::BeginPlay(); }
#include "Interaction/Interactables/IntenSelect/IntenSelectableSinglePointScoring.h"
UIntenSelectableSinglePointScoring::UIntenSelectableSinglePointScoring()
{
PrimaryComponentTick.bCanEverTick = true;
}
UIntenSelectableSinglePointScoring::UIntenSelectableSinglePointScoring() { PrimaryComponentTick.bCanEverTick = true; }
TPair<FHitResult, float> UIntenSelectableSinglePointScoring::GetBestPointScorePair(const FVector& ConeOrigin, const FVector& ConeForwardDirection, const float ConeBackwardShiftDistance,
TPair<FHitResult, float> UIntenSelectableSinglePointScoring::GetBestPointScorePair(
const FVector& ConeOrigin, const FVector& ConeForwardDirection, const float ConeBackwardShiftDistance,
const float ConeAngle, const float LastValue, const float DeltaTime)
{
const FVector Point = this->GetComponentLocation();
float Score = GetScore(ConeOrigin, ConeForwardDirection, ConeBackwardShiftDistance, ConeAngle, Point, LastValue, DeltaTime);
float Score =
GetScore(ConeOrigin, ConeForwardDirection, ConeBackwardShiftDistance, ConeAngle, Point, LastValue, DeltaTime);
FHitResult Result = FHitResult{GetOwner(), nullptr, Point, FVector::ForwardVector};
return TPair<FHitResult, float>{Result, Score};
}
void UIntenSelectableSinglePointScoring::BeginPlay()
{
Super::BeginPlay();
}
void UIntenSelectableSinglePointScoring::BeginPlay() { Super::BeginPlay(); }
......@@ -8,17 +8,16 @@
#include "Kismet/KismetMathLibrary.h"
// Sets default values for this component's properties
UIntenSelectableSphereScoring::UIntenSelectableSphereScoring()
{
PrimaryComponentTick.bCanEverTick = true;
}
UIntenSelectableSphereScoring::UIntenSelectableSphereScoring() { PrimaryComponentTick.bCanEverTick = true; }
TPair<FHitResult, float> UIntenSelectableSphereScoring::GetBestPointScorePair(const FVector& ConeOrigin,
const FVector& ConeForwardDirection, const float ConeBackwardShiftDistance, const float ConeAngle,
TPair<FHitResult, float>
UIntenSelectableSphereScoring::GetBestPointScorePair(const FVector& ConeOrigin, const FVector& ConeForwardDirection,
const float ConeBackwardShiftDistance, const float ConeAngle,
const float LastValue, const float DeltaTime)
{
FVector Point = GetClosestSelectionPointTo(ConeOrigin, ConeForwardDirection);
float Score = GetScore(ConeOrigin, ConeForwardDirection, ConeBackwardShiftDistance, ConeAngle, Point, LastValue, DeltaTime);
float Score =
GetScore(ConeOrigin, ConeForwardDirection, ConeBackwardShiftDistance, ConeAngle, Point, LastValue, DeltaTime);
FHitResult Result = FHitResult{GetOwner(), nullptr, Point, FVector::ForwardVector};
return TPair<FHitResult, float>{Result, Score};
}
......@@ -50,7 +49,8 @@ FVector UIntenSelectableSphereScoring::GetClosestSelectionPointTo(const FVector&
if (FVector::Distance(Point, Result1) < FVector::Distance(Point, Result2))
{
Result = Result1;
}else
}
else
{
Result = Result2;
}
......@@ -59,7 +59,8 @@ FVector UIntenSelectableSphereScoring::GetClosestSelectionPointTo(const FVector&
/*
TArray<FHitResult> Out;
const float Dist = FVector::Distance(Point, GetComponentLocation());
if(GetWorld()->LineTraceMultiByChannel(Out, Point, Point + (Direction.GetSafeNormal() * Dist), ECollisionChannel::ECC_Visibility))
if(GetWorld()->LineTraceMultiByChannel(Out, Point, Point + (Direction.GetSafeNormal() * Dist),
ECollisionChannel::ECC_Visibility))
{
for(auto Hit : Out)
{
......
......@@ -112,8 +112,7 @@ void UDirectInteractionComponent::OnBeginInteraction(const FInputActionValue& Va
if (bOnlyInteractWithClosestActor)
{
auto MinElement = *Algo::MinElementBy(
CurrentInteractableComponentsInRange,
[&](auto Element)
CurrentInteractableComponentsInRange, [&](auto Element)
{ return FVector(Element->GetOwner()->GetActorLocation() - InteractionLocation).Size(); });
MinElement->HandleOnActionStartEvents(this, InteractionInputAction, Value, EInteractorType::Direct);
CurrentlyInteractedComponents = {MinElement};
......
This diff is collapsed.
......@@ -35,7 +35,9 @@ public:
public:
UIntenSelectable();
TPair<FHitResult, float> GetBestPointScorePair(const FVector& ConeOrigin, const FVector& ConeForwardDirection, const float ConeBackwardShiftDistance, const float ConeAngle, const float LastValue, const float DeltaTime) const;
TPair<FHitResult, float> GetBestPointScorePair(const FVector& ConeOrigin, const FVector& ConeForwardDirection,
const float ConeBackwardShiftDistance, const float ConeAngle,
const float LastValue, const float DeltaTime) const;
void HandleOnSelectStartEvents(const UIntenSelectComponent* IntenSelect, const FHitResult& HitResult);
void HandleOnSelectEndEvents(const UIntenSelectComponent* IntenSelect);
......
......@@ -23,6 +23,8 @@ public:
UPROPERTY(EditAnywhere)
float Radius = 50;
virtual TPair<FHitResult, float> GetBestPointScorePair(const FVector& ConeOrigin, const FVector& ConeForwardDirection, const float ConeBackwardShiftDistance, const float ConeAngle, const float LastValue, const float DeltaTime) override;
virtual TPair<FHitResult, float> GetBestPointScorePair(const FVector& ConeOrigin,
const FVector& ConeForwardDirection,
const float ConeBackwardShiftDistance, const float ConeAngle,
const float LastValue, const float DeltaTime) override;
};
......@@ -10,11 +10,13 @@ class RWTHVRTOOLKIT_API UIntenSelectableCubeScoring : public UIntenSelectableSco
GENERATED_BODY()
protected:
static bool LineToLineIntersection(const FVector& FromA, const FVector& FromB, const FVector& ToA, const FVector& ToB, FVector& OutIntersection);
static bool LineToLineIntersection(const FVector& FromA, const FVector& FromB, const FVector& ToA,
const FVector& ToB, FVector& OutIntersection);
FVector GetClosestSelectionPointTo(const FVector& RayOrigin, const FVector& RayDirection);
virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
virtual void TickComponent(float DeltaTime, ELevelTick TickType,
FActorComponentTickFunction* ThisTickFunction) override;
public:
UIntenSelectableCubeScoring();
......@@ -37,7 +39,11 @@ public:
// UPROPERTY(EditAnywhere)
// float ZLength = 100;
virtual TPair<FHitResult, float> GetBestPointScorePair(const FVector& ConeOrigin, const FVector& ConeForwardDirection, const float ConeBackwardShiftDistance, const float ConeAngle, const float LastValue, const float DeltaTime) override;
virtual TPair<FHitResult, float> GetBestPointScorePair(const FVector& ConeOrigin,
const FVector& ConeForwardDirection,
const float ConeBackwardShiftDistance, const float ConeAngle,
const float LastValue, const float DeltaTime) override;
FVector GetClosestPointToRectangle(const FVector& StartPoint, const FVector& Direction, const FVector& Corner00, const FVector& Corner01, const FVector& Corner10, const FVector& Corner11) const;
FVector GetClosestPointToRectangle(const FVector& StartPoint, const FVector& Direction, const FVector& Corner00,
const FVector& Corner01, const FVector& Corner10, const FVector& Corner11) const;
};
......@@ -10,11 +10,13 @@ class RWTHVRTOOLKIT_API UIntenSelectableCylinderScoring : public UIntenSelectabl
GENERATED_BODY()
protected:
static bool LineToLineIntersection(const FVector& FromA, const FVector& FromB, const FVector& ToA, const FVector& ToB, FVector& OutIntersection);
static bool LineToLineIntersection(const FVector& FromA, const FVector& FromB, const FVector& ToA,
const FVector& ToB, FVector& OutIntersection);
FVector GetClosestSelectionPointTo(const FVector& Point, const FVector& Direction) const;
virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
virtual void TickComponent(float DeltaTime, ELevelTick TickType,
FActorComponentTickFunction* ThisTickFunction) override;
public:
UIntenSelectableCylinderScoring();
......@@ -26,14 +28,16 @@ public:
// Check if the property changed is MyMonitoredProperty
if (PropertyChangedEvent.Property && PropertyChangedEvent.Property->GetName() == TEXT("LinePoints"))
{
}
}
UPROPERTY(EditAnywhere)
bool DrawDebug = true;
virtual TPair<FHitResult, float> GetBestPointScorePair(const FVector& ConeOrigin, const FVector& ConeForwardDirection, const float ConeBackwardShiftDistance, const float ConeAngle, const float LastValue, const float DeltaTime) override;
virtual TPair<FHitResult, float> GetBestPointScorePair(const FVector& ConeOrigin,
const FVector& ConeForwardDirection,
const float ConeBackwardShiftDistance, const float ConeAngle,
const float LastValue, const float DeltaTime) override;
UPROPERTY(EditAnywhere)
TArray<FVector> LinePoints{FVector::UpVector * 50, FVector::DownVector * 50};
......
......@@ -10,11 +10,13 @@ class RWTHVRTOOLKIT_API UIntenSelectableLineScoring : public UIntenSelectableSco
GENERATED_BODY()
protected:
static bool LineToLineIntersection(const FVector& FromA, const FVector& FromB, const FVector& ToA, const FVector& ToB, FVector& OutIntersection);
static bool LineToLineIntersection(const FVector& FromA, const FVector& FromB, const FVector& ToA,
const FVector& ToB, FVector& OutIntersection);
FVector GetClosestSelectionPointTo(const FVector& Point, const FVector& Direction) const;
virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
virtual void TickComponent(float DeltaTime, ELevelTick TickType,
FActorComponentTickFunction* ThisTickFunction) override;
public:
UIntenSelectableLineScoring();
......@@ -22,7 +24,10 @@ public:
UPROPERTY(EditAnywhere)
bool DrawDebug = true;
virtual TPair<FHitResult, float> GetBestPointScorePair(const FVector& ConeOrigin, const FVector& ConeForwardDirection, const float ConeBackwardShiftDistance, const float ConeAngle, const float LastValue, const float DeltaTime) override;
virtual TPair<FHitResult, float> GetBestPointScorePair(const FVector& ConeOrigin,
const FVector& ConeForwardDirection,
const float ConeBackwardShiftDistance, const float ConeAngle,
const float LastValue, const float DeltaTime) override;
UPROPERTY(EditAnywhere, meta = (EditFixedSize))
TArray<FVector> LinePoints{FVector::RightVector * 50, FVector::LeftVector * 50};
......
......@@ -17,11 +17,13 @@ protected:
public:
UIntenSelectableMultiPointScoring();
virtual TPair<FHitResult, float> GetBestPointScorePair(const FVector& ConeOrigin, const FVector& ConeForwardDirection, const float ConeBackwardShiftDistance, const float ConeAngle, const float LastValue, const float DeltaTime) override;
virtual TPair<FHitResult, float> GetBestPointScorePair(const FVector& ConeOrigin,
const FVector& ConeForwardDirection,
const float ConeBackwardShiftDistance, const float ConeAngle,
const float LastValue, const float DeltaTime) override;
void UpdatePoints();
UPROPERTY(EditAnywhere, BlueprintReadWrite)
TArray<FVector> PointsToSelect;
};
......@@ -10,11 +10,13 @@ class RWTHVRTOOLKIT_API UIntenSelectableRectangleScoring : public UIntenSelectab
GENERATED_BODY()
protected:
static bool LineToLineIntersection(const FVector& FromA, const FVector& FromB, const FVector& ToA, const FVector& ToB, FVector& OutIntersection);
static bool LineToLineIntersection(const FVector& FromA, const FVector& FromB, const FVector& ToA,
const FVector& ToB, FVector& OutIntersection);
FVector GetClosestSelectionPointTo(const FVector& Point, const FVector& Direction) const;
virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
virtual void TickComponent(float DeltaTime, ELevelTick TickType,
FActorComponentTickFunction* ThisTickFunction) override;
public:
UIntenSelectableRectangleScoring();
......@@ -31,5 +33,8 @@ public:
UPROPERTY(EditAnywhere)
float YLength = 100;
virtual TPair<FHitResult, float> GetBestPointScorePair(const FVector& ConeOrigin, const FVector& ConeForwardDirection, const float ConeBackwardShiftDistance, const float ConeAngle, const float LastValue, const float DeltaTime) override;
virtual TPair<FHitResult, float> GetBestPointScorePair(const FVector& ConeOrigin,
const FVector& ConeForwardDirection,
const float ConeBackwardShiftDistance, const float ConeAngle,
const float LastValue, const float DeltaTime) override;
};
......@@ -10,7 +10,9 @@ class RWTHVRTOOLKIT_API UIntenSelectableScoring : public USceneComponent
GENERATED_BODY()
protected:
float GetScore(const FVector& ConeOrigin, const FVector& ConeForwardDirection, const float ConeBackwardShiftDistance, const float ConeAngle, const FVector& TestPoint, const float LastValue, const float DeltaTime);
float GetScore(const FVector& ConeOrigin, const FVector& ConeForwardDirection,
const float ConeBackwardShiftDistance, const float ConeAngle, const FVector& TestPoint,
const float LastValue, const float DeltaTime);
public:
UIntenSelectableScoring();
......@@ -29,7 +31,10 @@ public:
bool bOverwritingContrib = false;
float Contrib = 0;
virtual TPair<FHitResult, float> GetBestPointScorePair(const FVector& ConeOrigin, const FVector& ConeForwardDirection, const float ConeBackwardShiftDistance, const float ConeAngle, const float LastValue, const float DeltaTime);
virtual TPair<FHitResult, float> GetBestPointScorePair(const FVector& ConeOrigin,
const FVector& ConeForwardDirection,
const float ConeBackwardShiftDistance, const float ConeAngle,
const float LastValue, const float DeltaTime);
virtual void BeginPlay() override;
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment