70 lines
2.2 KiB
C++
70 lines
2.2 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(0, 0, 0));
|
|
RulerPoints.Add(FVector(0, 0, DesiredHeight));
|
|
}
|
|
|
|
void AGestureAction_Ruler::UpdateAction_Implementation()
|
|
{
|
|
if (!HandA || !IsValid(LineIcon)) return;
|
|
const FVector Current = HandA->Points[8];
|
|
|
|
//if (FVector::DistSquared(Current, RulerPoints[RulerPoints.Num() - 1]) < FMath::Square(UEUnitsPerUnit)) return;
|
|
//RulerPoints[RulerPoints.Num() - 1] = Current;
|
|
RulerPoints[RulerPoints.Num() - 1] = Current - StartPoint;
|
|
RulerPoints[RulerPoints.Num() - 1].Z = 0;
|
|
LineIcon->SetPoints(RulerPoints);
|
|
}
|
|
|
|
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];
|
|
//Current.Z = DesiredHeight;
|
|
RulerPoints.Add(Current - StartPoint);
|
|
}
|