cache all overlapped actors with the real/virtual hands

This commit is contained in:
Mamadou Babaei
2023-08-14 17:28:07 +02:00
parent 12365ff9b4
commit 2e4a8b7904
2 changed files with 55 additions and 54 deletions
@@ -53,13 +53,6 @@ struct ASGPawn::FImpl
* Static methods
************************/
/************************
* Member variables
************************/
bool bUpdateLeftHandLocationAndRotation;
bool bUpdateRightHandLocationAndRotation;
/************************
* Owner object
************************/
@@ -110,6 +103,15 @@ struct ASGPawn::FImpl
void UpdateRightHandLocationAndRotation(
const FVector& Location, const FRotator& Rotation, const bool bUpdateVirtualHand);
void RegisterLeftHandOverlappedActor(const AActor* Actor) const;
void UnregisterLeftHandOverlappedActor(const AActor* Actor) const;
void RegisterRightHandOverlappedActor(const AActor* Actor) const;
void UnregisterRightHandOverlappedActor(const AActor* Actor) const;
bool IsLeftHandOverlappingWithAnyActor() const;
bool IsRightHandOverlappingWithAnyActor() const;
void DisableActorPhysics(const AActor* Actor) const;
void EnableActorPhysics(const AActor* Actor) const;
@@ -596,22 +598,22 @@ void ASGPawn::BeginPlay()
WristTrackerLeft->OnWristLocationChanged().AddWeakLambda(this, [&](const FVector& Location)-> void
{
Pimpl->UpdateLeftHandLocation(Location, Pimpl->bUpdateLeftHandLocationAndRotation);
Pimpl->UpdateLeftHandLocation(Location, !Pimpl->IsLeftHandOverlappingWithAnyActor());
});
WristTrackerLeft->OnWristRotationChanged().AddWeakLambda(this, [&](const FRotator& Rotation)-> void
{
Pimpl->UpdateLeftHandRotation(Rotation, Pimpl->bUpdateLeftHandLocationAndRotation);
Pimpl->UpdateLeftHandRotation(Rotation, !Pimpl->IsLeftHandOverlappingWithAnyActor());
});
WristTrackerRight->OnWristLocationChanged().AddWeakLambda(this, [&](const FVector& Location)-> void
{
Pimpl->UpdateRightHandLocation(Location, Pimpl->bUpdateRightHandLocationAndRotation);
Pimpl->UpdateRightHandLocation(Location, !Pimpl->IsRightHandOverlappingWithAnyActor());
});
WristTrackerRight->OnWristRotationChanged().AddWeakLambda(this, [&](const FRotator& Rotation)-> void
{
Pimpl->UpdateRightHandRotation(Rotation, Pimpl->bUpdateRightHandLocationAndRotation);
Pimpl->UpdateRightHandRotation(Rotation, !Pimpl->IsRightHandOverlappingWithAnyActor());
});
Pimpl->BindRealHandsOverlapEvents();
@@ -670,16 +672,7 @@ void ASGPawn::OnRealLeftHandOverlapBegins(
return;
}
if (!Pimpl->bUpdateLeftHandLocationAndRotation)
{
return;
}
Pimpl->bUpdateLeftHandLocationAndRotation = false;
/*FVector WristLocation{WristTrackerLeft->GetWristLocation()};
FRotator WristRotation{WristTrackerLeft->GetWristRotation()};
Pimpl->UpdateLeftHandLocationAndRotation(MoveTemp(WristLocation), MoveTemp(WristRotation), true);*/
Pimpl->RegisterLeftHandOverlappedActor(OtherActor);
}
void ASGPawn::OnRealLeftHandOverlapEnds(
@@ -697,16 +690,7 @@ void ASGPawn::OnRealLeftHandOverlapEnds(
return;
}
if (Pimpl->bUpdateLeftHandLocationAndRotation)
{
return;
}
Pimpl->bUpdateLeftHandLocationAndRotation = true;
/*FVector WristLocation{WristTrackerLeft->GetWristLocation()};
FRotator WristRotation{WristTrackerLeft->GetWristRotation()};
Pimpl->UpdateLeftHandLocationAndRotation(MoveTemp(WristLocation), MoveTemp(WristRotation), true);*/
Pimpl->UnregisterLeftHandOverlappedActor(OtherActor);
}
void ASGPawn::OnRealRightHandOverlapBegins(
@@ -728,16 +712,7 @@ void ASGPawn::OnRealRightHandOverlapBegins(
return;
}
if (!Pimpl->bUpdateRightHandLocationAndRotation)
{
return;
}
Pimpl->bUpdateRightHandLocationAndRotation = false;
/*FVector WristLocation{WristTrackerRight->GetWristLocation()};
FRotator WristRotation{WristTrackerRight->GetWristRotation()};
Pimpl->UpdateRightHandLocationAndRotation(MoveTemp(WristLocation), MoveTemp(WristRotation), true);*/
Pimpl->RegisterRightHandOverlappedActor(OtherActor);
}
void ASGPawn::OnRealRightHandOverlapEnds(
@@ -755,16 +730,7 @@ void ASGPawn::OnRealRightHandOverlapEnds(
return;
}
if (Pimpl->bUpdateRightHandLocationAndRotation)
{
return;
}
Pimpl->bUpdateRightHandLocationAndRotation = true;
/*FVector WristLocation{WristTrackerRight->GetWristLocation()};
FRotator WristRotation{WristTrackerRight->GetWristRotation()};
Pimpl->UpdateRightHandLocationAndRotation(MoveTemp(WristLocation), MoveTemp(WristRotation), true);*/
Pimpl->UnregisterRightHandOverlappedActor(OtherActor);
}
void ASGPawn::OnLeftThumbFingertipGrabColliderOverlapBegins(
@@ -1478,9 +1444,7 @@ void ASGPawn::ReleaseRight()
}
ASGPawn::FImpl::FImpl(ASGPawn* InOwner)
: bUpdateLeftHandLocationAndRotation(true),
bUpdateRightHandLocationAndRotation(true),
Owner(InOwner)
: Owner(InOwner)
{
}
@@ -1795,6 +1759,36 @@ void ASGPawn::FImpl::UpdateRightHandLocationAndRotation(
UpdateRightHandRotation(Rotation, bUpdateVirtualHand);
}
void ASGPawn::FImpl::RegisterLeftHandOverlappedActor(const AActor* Actor) const
{
Owner->LeftHandOverlappedActors.AddUnique(Actor);
}
void ASGPawn::FImpl::UnregisterLeftHandOverlappedActor(const AActor* Actor) const
{
Owner->LeftHandOverlappedActors.Remove(Actor);
}
void ASGPawn::FImpl::RegisterRightHandOverlappedActor(const AActor* Actor) const
{
Owner->RightHandOverlappedActors.AddUnique(Actor);
}
void ASGPawn::FImpl::UnregisterRightHandOverlappedActor(const AActor* Actor) const
{
Owner->RightHandOverlappedActors.Remove(Actor);
}
bool ASGPawn::FImpl::IsLeftHandOverlappingWithAnyActor() const
{
return Owner->LeftHandOverlappedActors.Num() > 0;
}
bool ASGPawn::FImpl::IsRightHandOverlappingWithAnyActor() const
{
return Owner->RightHandOverlappedActors.Num() > 0;
}
void ASGPawn::FImpl::DisableActorPhysics(const AActor* Actor) const
{
UPrimitiveComponent* ActorRootComponent{Cast<UPrimitiveComponent>(Actor->GetRootComponent())};
@@ -35,6 +35,7 @@
#pragma once
#include "Containers/Array.h"
#include "GameFramework/Pawn.h"
#include "SenseGlove/Components/SGVirtualHandComponent.h"
#include "Templates/UniquePtr.h"
@@ -175,6 +176,12 @@ private:
UPROPERTY(Transient)
FSGTouchState RightHandTouchState;
UPROPERTY(Transient)
TArray<const AActor*> LeftHandOverlappedActors;
UPROPERTY(Transient)
TArray<const AActor*> RightHandOverlappedActors;
public:
FORCEINLINE UCameraComponent* GetCamera() const
{