205 lines
8.4 KiB
C++
205 lines
8.4 KiB
C++
/**
|
|
* @file
|
|
*
|
|
* @author Mamadou Babaei <mamadou@senseglove.com>
|
|
*
|
|
* @section LICENSE
|
|
*
|
|
* (The MIT License)
|
|
*
|
|
* Copyright (c) 2020 - 2023 SenseGlove
|
|
*
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
* in the Software without restriction, including without limitation the rights
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
* furnished to do so, subject to the following conditions:
|
|
*
|
|
* The above copyright notice and this permission notice shall be included in all
|
|
* copies or substantial portions of the Software.
|
|
*
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
* SOFTWARE.
|
|
*
|
|
* @section DESCRIPTION
|
|
*
|
|
*
|
|
*/
|
|
|
|
|
|
#include "SenseGlove/GameFramework/SGVirtualHandActor.h"
|
|
|
|
#include "Components/SphereComponent.h"
|
|
|
|
#include "SenseGlove/Components/SGVirtualHandComponent.h"
|
|
#include "SenseGlove/Components/SGWristTrackerComponent.h"
|
|
|
|
struct ASGVirtualHandActor::FImpl
|
|
{
|
|
/************************
|
|
* Owner object
|
|
************************/
|
|
|
|
ASGVirtualHandActor* Owner;
|
|
|
|
/************************
|
|
* Constructor / Destructor
|
|
************************/
|
|
|
|
explicit FImpl(ASGVirtualHandActor* InOwner);
|
|
~FImpl();
|
|
|
|
/************************
|
|
* Default copy constructor & copy assignment operator
|
|
************************/
|
|
|
|
FImpl(const FImpl& Rhs) = default;
|
|
FImpl& operator=(const FImpl& Rhs) = default;
|
|
|
|
/************************
|
|
* Methods
|
|
************************/
|
|
};
|
|
|
|
ASGVirtualHandActor::ASGVirtualHandActor(const FObjectInitializer& ObjectInitializer)
|
|
: Super(ObjectInitializer),
|
|
Pimpl(TUniquePtr<FImpl, FImplDeleter>(new FImpl{this}, PimplDeleter))
|
|
{
|
|
PrimaryActorTick.bCanEverTick = true;
|
|
|
|
SceneRoot = CreateDefaultSubobject<USceneComponent>(TEXT("SceneRoot"));
|
|
SetRootComponent(SceneRoot);
|
|
|
|
VirtualHand = CreateDefaultSubobject<USGVirtualHandComponent>(TEXT("VirtualHand"));
|
|
VirtualHand->SetupAttachment(RootComponent);
|
|
VirtualHand->SetRelativeRotation(FRotator{0.0f, -90.0f, 0.0f},
|
|
false, nullptr, ETeleportType::None);
|
|
|
|
ThumbFingertipCollider = ObjectInitializer.CreateDefaultSubobject<USphereComponent>(
|
|
this, TEXT("ThumbFingertipCollider"));
|
|
ThumbFingertipCollider->SetupAttachment(VirtualHand, VirtualHand->GetThumbFingertipSocketName());
|
|
ThumbFingertipCollider->SetRelativeScale3D(VirtualHand->GetDefaultFingertipsColliderSize());
|
|
ThumbFingertipCollider->SetCastShadow(false);
|
|
ThumbFingertipCollider->bCastDynamicShadow = false;
|
|
ThumbFingertipCollider->SetReceivesDecals(true);
|
|
ThumbFingertipCollider->SetCanEverAffectNavigation(false);
|
|
ThumbFingertipCollider->SetCollisionObjectType(ECC_WorldDynamic);
|
|
ThumbFingertipCollider->SetCollisionEnabled(ECollisionEnabled::QueryOnly);
|
|
ThumbFingertipCollider->SetCollisionResponseToAllChannels(ECR_Overlap);
|
|
ThumbFingertipCollider->SetCollisionResponseToChannel(ECC_WorldStatic, ECR_Overlap);
|
|
ThumbFingertipCollider->SetCollisionResponseToChannel(ECC_WorldDynamic, ECR_Overlap);
|
|
ThumbFingertipCollider->SetCollisionResponseToChannel(ECC_Pawn, ECR_Overlap);
|
|
ThumbFingertipCollider->SetCollisionResponseToChannel(ECC_Visibility, ECR_Overlap);
|
|
ThumbFingertipCollider->SetCollisionResponseToChannel(ECC_PhysicsBody, ECR_Overlap);
|
|
ThumbFingertipCollider->SetCollisionResponseToChannel(ECC_Vehicle, ECR_Overlap);
|
|
ThumbFingertipCollider->SetCollisionResponseToChannel(ECC_Destructible, ECR_Overlap);
|
|
|
|
IndexFingertipCollider = ObjectInitializer.CreateDefaultSubobject<USphereComponent>(
|
|
this, TEXT("IndexFingertipCollider"));
|
|
IndexFingertipCollider->SetRelativeScale3D(VirtualHand->GetDefaultFingertipsColliderSize());
|
|
IndexFingertipCollider->SetupAttachment(VirtualHand, VirtualHand->GetIndexFingertipSocketName());
|
|
IndexFingertipCollider->SetCastShadow(false);
|
|
IndexFingertipCollider->bCastDynamicShadow = false;
|
|
IndexFingertipCollider->SetReceivesDecals(true);
|
|
IndexFingertipCollider->SetCanEverAffectNavigation(false);
|
|
IndexFingertipCollider->SetCollisionObjectType(ECC_WorldDynamic);
|
|
IndexFingertipCollider->SetCollisionEnabled(ECollisionEnabled::QueryOnly);
|
|
IndexFingertipCollider->SetCollisionResponseToAllChannels(ECR_Overlap);
|
|
IndexFingertipCollider->SetCollisionResponseToChannel(ECC_WorldStatic, ECR_Overlap);
|
|
IndexFingertipCollider->SetCollisionResponseToChannel(ECC_WorldDynamic, ECR_Overlap);
|
|
IndexFingertipCollider->SetCollisionResponseToChannel(ECC_Pawn, ECR_Overlap);
|
|
IndexFingertipCollider->SetCollisionResponseToChannel(ECC_Visibility, ECR_Overlap);
|
|
IndexFingertipCollider->SetCollisionResponseToChannel(ECC_PhysicsBody, ECR_Overlap);
|
|
IndexFingertipCollider->SetCollisionResponseToChannel(ECC_Vehicle, ECR_Overlap);
|
|
IndexFingertipCollider->SetCollisionResponseToChannel(ECC_Destructible, ECR_Overlap);
|
|
|
|
MiddleFingertipCollider = ObjectInitializer.CreateDefaultSubobject<USphereComponent>(
|
|
this, TEXT("MiddleFingertipCollider"));
|
|
MiddleFingertipCollider->SetRelativeScale3D(VirtualHand->GetDefaultFingertipsColliderSize());
|
|
MiddleFingertipCollider->SetupAttachment(VirtualHand, VirtualHand->GetMiddleFingertipSocketName());
|
|
MiddleFingertipCollider->SetCastShadow(false);
|
|
MiddleFingertipCollider->bCastDynamicShadow = false;
|
|
MiddleFingertipCollider->SetReceivesDecals(true);
|
|
MiddleFingertipCollider->SetCanEverAffectNavigation(false);
|
|
MiddleFingertipCollider->SetCollisionObjectType(ECC_WorldDynamic);
|
|
MiddleFingertipCollider->SetCollisionEnabled(ECollisionEnabled::QueryOnly);
|
|
MiddleFingertipCollider->SetCollisionResponseToAllChannels(ECR_Overlap);
|
|
MiddleFingertipCollider->SetCollisionResponseToChannel(ECC_WorldStatic, ECR_Overlap);
|
|
MiddleFingertipCollider->SetCollisionResponseToChannel(ECC_WorldDynamic, ECR_Overlap);
|
|
MiddleFingertipCollider->SetCollisionResponseToChannel(ECC_Pawn, ECR_Overlap);
|
|
MiddleFingertipCollider->SetCollisionResponseToChannel(ECC_Visibility, ECR_Overlap);
|
|
MiddleFingertipCollider->SetCollisionResponseToChannel(ECC_PhysicsBody, ECR_Overlap);
|
|
MiddleFingertipCollider->SetCollisionResponseToChannel(ECC_Vehicle, ECR_Overlap);
|
|
MiddleFingertipCollider->SetCollisionResponseToChannel(ECC_Destructible, ECR_Overlap);
|
|
|
|
WristTracker = CreateDefaultSubobject<USGWristTrackerComponent>(TEXT("WristTracker"));
|
|
WristTracker->SetupAttachment(RootComponent);
|
|
|
|
WristTracker->SetRight(VirtualHand->IsRight());
|
|
}
|
|
|
|
void ASGVirtualHandActor::BeginPlay()
|
|
{
|
|
Super::BeginPlay();
|
|
|
|
ensureAlwaysMsgf(
|
|
(WristTracker->IsLeft() && VirtualHand->IsLeft())
|
|
|| (WristTracker->IsRight() && VirtualHand->IsRight()),
|
|
TEXT("The virtual hand component and the wrist tracker component do not track the same hand!"));
|
|
|
|
WristTracker->OnWristLocationChanged().AddWeakLambda(this, [&](const FVector& Location)-> void
|
|
{
|
|
VirtualHand->SetWorldLocation(Location);
|
|
});
|
|
|
|
WristTracker->OnWristRotationChanged().AddWeakLambda(this, [&](const FRotator& Rotation)-> void
|
|
{
|
|
VirtualHand->SetWorldRotation(Rotation);
|
|
});
|
|
}
|
|
|
|
void ASGVirtualHandActor::PreInitializeComponents()
|
|
{
|
|
Super::PreInitializeComponents();
|
|
|
|
WristTracker->SetRight(VirtualHand->IsRight());
|
|
}
|
|
|
|
bool ASGVirtualHandActor::IsLeft() const
|
|
{
|
|
return WristTracker->IsLeft() && VirtualHand->IsLeft();
|
|
}
|
|
|
|
bool ASGVirtualHandActor::IsRight() const
|
|
{
|
|
return WristTracker->IsRight() && VirtualHand->IsRight();
|
|
}
|
|
|
|
void ASGVirtualHandActor::SetRight(const bool bRight)
|
|
{
|
|
WristTracker->SetRight(bRight);
|
|
VirtualHand->SetRight(bRight);
|
|
}
|
|
|
|
bool ASGVirtualHandActor::IsGloveConnected() const
|
|
{
|
|
return VirtualHand->IsGloveConnected();
|
|
}
|
|
|
|
ASGVirtualHandActor::FImpl::FImpl(ASGVirtualHandActor* InOwner)
|
|
: Owner(InOwner)
|
|
{
|
|
}
|
|
|
|
ASGVirtualHandActor::FImpl::~FImpl() = default;
|
|
|
|
void ASGVirtualHandActor::FImplDeleter::operator()(const FImpl* P) const
|
|
{
|
|
delete P;
|
|
} |