166 lines
5.5 KiB
C++
166 lines
5.5 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/SGPawn.h"
|
|
|
|
#include "Camera/CameraComponent.h"
|
|
|
|
#include "SenseGlove/Components/SGVirtualHandComponent.h"
|
|
#include "SenseGlove/Components/SGWristTrackerComponent.h"
|
|
|
|
struct ASGPawn::FImpl
|
|
{
|
|
/************************
|
|
* Static methods
|
|
************************/
|
|
|
|
/************************
|
|
* Owner object
|
|
************************/
|
|
|
|
ASGPawn* Owner;
|
|
|
|
/************************
|
|
* Constructor / Destructor
|
|
************************/
|
|
|
|
explicit FImpl(ASGPawn* InOwner);
|
|
~FImpl();
|
|
|
|
/************************
|
|
* Default copy constructor & copy assignment operator
|
|
************************/
|
|
|
|
FImpl(const FImpl& Rhs) = default;
|
|
FImpl& operator=(const FImpl& Rhs) = default;
|
|
|
|
/************************
|
|
* Methods
|
|
************************/
|
|
};
|
|
|
|
ASGPawn::ASGPawn(const FObjectInitializer& ObjectInitializer)
|
|
: Super(ObjectInitializer),
|
|
Pimpl(TUniquePtr<FImpl, FImplDeleter>(new FImpl{this}, PimplDeleter))
|
|
{
|
|
PrimaryActorTick.bCanEverTick = true;
|
|
|
|
SceneRoot = ObjectInitializer.CreateDefaultSubobject<USceneComponent>(this, TEXT("SceneRoot"));
|
|
SetRootComponent(SceneRoot);
|
|
|
|
Camera = ObjectInitializer.CreateDefaultSubobject<UCameraComponent>(this, TEXT("Camera"));
|
|
Camera->SetupAttachment(GetRootComponent());
|
|
Camera->SetCanEverAffectNavigation(false);
|
|
|
|
WristTrackerLeft = ObjectInitializer.CreateDefaultSubobject<USGWristTrackerComponent>(
|
|
this, TEXT("WristTrackerLeft"));
|
|
WristTrackerLeft->SetupAttachment(GetRootComponent());
|
|
WristTrackerLeft->SetRight(false);
|
|
|
|
HandLeft = ObjectInitializer.CreateDefaultSubobject<USGVirtualHandComponent>(this, TEXT("HandLeft"));
|
|
HandLeft->SetupAttachment(GetRootComponent());
|
|
HandLeft->SetRight(false);
|
|
HandLeft->SetHiddenIfNoGloveDetected(true);
|
|
HandLeft->SetRelativeRotation(FRotator{0.0f, -90.0f, 0.0f},
|
|
false, nullptr, ETeleportType::None);
|
|
HandLeft->SetRelativeLocation(FVector{30.0f, -20.0f, -10.0f},
|
|
false, nullptr, ETeleportType::None);
|
|
|
|
WristTrackerRight = ObjectInitializer.CreateDefaultSubobject<USGWristTrackerComponent>(
|
|
this, TEXT("WristTrackerRight"));
|
|
WristTrackerRight->SetupAttachment(GetRootComponent());
|
|
WristTrackerRight->SetRight(true);
|
|
|
|
HandRight = ObjectInitializer.CreateDefaultSubobject<USGVirtualHandComponent>(this, TEXT("HandRight"));
|
|
HandRight->SetupAttachment(GetRootComponent());
|
|
HandRight->SetRight(true);
|
|
HandRight->SetHiddenIfNoGloveDetected(true);
|
|
HandRight->SetRelativeRotation(FRotator{0.0f, -90.0f, 0.0f},
|
|
false, nullptr, ETeleportType::None);
|
|
HandRight->SetRelativeLocation(FVector{30.0f, 20.0f, -10.0f},
|
|
false, nullptr, ETeleportType::None);
|
|
}
|
|
|
|
void ASGPawn::BeginPlay()
|
|
{
|
|
Super::BeginPlay();
|
|
|
|
ensureAlwaysMsgf(
|
|
WristTrackerLeft->IsLeft() && HandLeft->IsLeft(),
|
|
TEXT("The left hand and the left wrist do not track the left hand!"));
|
|
ensureAlwaysMsgf(
|
|
WristTrackerRight->IsRight() && HandRight->IsRight(),
|
|
TEXT("The right hand and the right wrist do not track the right hand!"));
|
|
|
|
WristTrackerLeft->OnWristLocationChanged().AddWeakLambda(this, [&](const FVector& Location)-> void
|
|
{
|
|
HandLeft->SetRelativeLocation(Location);
|
|
});
|
|
|
|
WristTrackerLeft->OnWristRotationChanged().AddWeakLambda(this, [&](const FRotator& Rotation)-> void
|
|
{
|
|
HandLeft->SetRelativeRotation(Rotation);
|
|
});
|
|
|
|
WristTrackerRight->OnWristLocationChanged().AddWeakLambda(this, [&](const FVector& Location)-> void
|
|
{
|
|
HandRight->SetRelativeLocation(Location);
|
|
});
|
|
|
|
WristTrackerRight->OnWristRotationChanged().AddWeakLambda(this, [&](const FRotator& Rotation)-> void
|
|
{
|
|
HandRight->SetRelativeRotation(Rotation);
|
|
});
|
|
}
|
|
|
|
void ASGPawn::PreInitializeComponents()
|
|
{
|
|
Super::PreInitializeComponents();
|
|
|
|
WristTrackerLeft->SetRight(HandLeft->IsRight());
|
|
WristTrackerRight->SetRight(HandRight->IsRight());
|
|
}
|
|
|
|
ASGPawn::FImpl::FImpl(ASGPawn* InOwner)
|
|
: Owner(InOwner)
|
|
{
|
|
}
|
|
|
|
ASGPawn::FImpl::~FImpl() = default;
|
|
|
|
void ASGPawn::FImplDeleter::operator()(const FImpl* P) const
|
|
{
|
|
delete P;
|
|
} |