86 lines
2.7 KiB
C++
86 lines
2.7 KiB
C++
// Fill out your copyright notice in the Description page of Project Settings.
|
|
|
|
|
|
#include "MyGestureActions.h"
|
|
#include "HandActor.h"
|
|
#include "TableIconActor.h"
|
|
#include "MyTableIconActors.h"
|
|
|
|
|
|
void AGestureAction_Ruler::InitAction_Implementation(AHandActor* Hand, const FGestureBinding& NewBinding, float NewUEUnitsPerUnit, float TableHeight)
|
|
{
|
|
Super::InitAction_Implementation(Hand, NewBinding, NewUEUnitsPerUnit, TableHeight);
|
|
DesiredHeight = -500;
|
|
StartPoint = HandA->Points[8];
|
|
StartPoint.Z = DesiredHeight;
|
|
|
|
FActorSpawnParameters SpawnParams;
|
|
SpawnParams.Owner = this;
|
|
SpawnParams.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
|
|
|
|
if (LineIconClass)
|
|
{
|
|
|
|
LineIcon = GetWorld()->SpawnActor<ATableIconLineActor>(LineIconClass, StartPoint, FRotator::ZeroRotator, SpawnParams);
|
|
|
|
if (LineIcon)
|
|
{
|
|
LineIcon->OwningAction = this;
|
|
LineIcon->bPersistOnActionEnd = true;
|
|
LineIcon->LineThickness = 50;
|
|
Icons.Add(LineIcon);
|
|
}
|
|
}
|
|
RulerPoints.Add(FVector::ZeroVector);
|
|
RulerPoints.Add(FVector::ZeroVector);
|
|
|
|
if (LabelIconClass)
|
|
{
|
|
LabelIcon = GetWorld()->SpawnActor<ATableIconLabelActor>(LabelIconClass, StartPoint, FRotator::ZeroRotator, SpawnParams);
|
|
|
|
if (LabelIcon)
|
|
{
|
|
LabelIcon->OwningAction = this;
|
|
LabelIcon->bPersistOnActionEnd = true;
|
|
LabelIcon->UpdateLabel(StartPoint, 0.f);
|
|
Icons.Add(LabelIcon);
|
|
}
|
|
}
|
|
}
|
|
|
|
void AGestureAction_Ruler::UpdateAction_Implementation()
|
|
{
|
|
if (!HandA || !IsValid(LineIcon) || !IsValid(LabelIcon)) return;
|
|
const FVector Current = HandA->Points[8];
|
|
|
|
//if (FVector::DistSquared(Current, RulerPoints[RulerPoints.Num() - 1]) < FMath::Square(UEUnitsPerUnit)) return;
|
|
RulerPoints.Last() = Current - StartPoint;
|
|
RulerPoints.Last().Z = 0;
|
|
LineIcon->SetPoints(RulerPoints);
|
|
|
|
// RulerPoints are local to the line actor, so convert back to world
|
|
FVector LabelPosition = StartPoint + (RulerPoints.Last() * 0.5f);
|
|
LabelPosition.Z = 10;
|
|
LabelIcon->UpdateLabel(LabelPosition, GetSnappedUnits(GetTotalLength()));
|
|
}
|
|
|
|
float AGestureAction_Ruler::GetSnappedUnits(float RawDistance) const
|
|
{
|
|
if (UEUnitsPerUnit <= 0.f) return 0.f;
|
|
return FMath::RoundToFloat(RawDistance / UEUnitsPerUnit);
|
|
}
|
|
|
|
float AGestureAction_Ruler::GetTotalLength() const
|
|
{
|
|
float Total = 0.f;
|
|
for (int32 i = 0; i < RulerPoints.Num() - 1; i++)
|
|
Total += FVector::Dist(RulerPoints[i], RulerPoints[i + 1]);
|
|
return Total;
|
|
}
|
|
|
|
void AGestureAction_Ruler::AddRulerPoint()
|
|
{
|
|
FVector Current = HandA->Points[8];
|
|
RulerPoints.Add(Current - StartPoint);
|
|
}
|