1536 lines
65 KiB
C++
1536 lines
65 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 "Components/PrimitiveComponent.h"
|
|
#include "Components/SphereComponent.h"
|
|
#include "Kismet/KismetMathLibrary.h"
|
|
|
|
#include "SenseGlove/Components/SGGrabComponent.h"
|
|
#include "SenseGlove/Components/SGTouchComponent.h"
|
|
#include "SenseGlove/Components/SGVirtualHandComponent.h"
|
|
#include "SenseGlove/Components/SGWristTrackerComponent.h"
|
|
#include "SGLog/SGLog.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
|
|
************************/
|
|
|
|
void BindFingerGrabOverlapEvents();
|
|
void UnbindFingerGrabOverlapEvents();
|
|
|
|
void BindFingerTouchOverlapEvents();
|
|
void UnbindFingerTouchOverlapEvents();
|
|
|
|
void DisableActorPhysics(const AActor* Actor) const;
|
|
void EnableActorPhysics(const AActor* Actor) const;
|
|
|
|
void ApplyHandVelocityToGrabbedActor(const FSGGrabState& GrabState) const;
|
|
|
|
void SetGrabbedActor(FSGGrabState& GrabState, AActor* Actor) const;
|
|
void SetLeftHandGrabbedActor(AActor* Actor) const;
|
|
void SetRightHandGrabbedActor(AActor* Actor) const;
|
|
|
|
void RecordHandVelocity(FSGGrabState& GrabState, const float DeltaSeconds) const;
|
|
|
|
void Release(FSGGrabState& GrabState) const;
|
|
};
|
|
|
|
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);
|
|
HandLeft->SetWristTracker(WristTrackerLeft);
|
|
|
|
LeftThumbFingertipGrabCollider = ObjectInitializer.CreateDefaultSubobject<USphereComponent>(
|
|
this, TEXT("LeftThumbFingertipGrabCollider"));
|
|
LeftThumbFingertipGrabCollider->SetRelativeScale3D(HandLeft->GetDefaultFingertipsGrabColliderSize());
|
|
LeftThumbFingertipGrabCollider->SetupAttachment(HandLeft, HandLeft->GetThumbFingertipGrabSocketName());
|
|
LeftThumbFingertipGrabCollider->SetCastShadow(false);
|
|
LeftThumbFingertipGrabCollider->bCastDynamicShadow = false;
|
|
LeftThumbFingertipGrabCollider->SetReceivesDecals(true);
|
|
LeftThumbFingertipGrabCollider->SetCanEverAffectNavigation(false);
|
|
LeftThumbFingertipGrabCollider->SetCollisionObjectType(ECC_WorldDynamic);
|
|
LeftThumbFingertipGrabCollider->SetCollisionEnabled(ECollisionEnabled::QueryOnly);
|
|
LeftThumbFingertipGrabCollider->SetCollisionResponseToAllChannels(ECR_Overlap);
|
|
LeftThumbFingertipGrabCollider->SetCollisionResponseToChannel(ECC_WorldStatic, ECR_Overlap);
|
|
LeftThumbFingertipGrabCollider->SetCollisionResponseToChannel(ECC_WorldDynamic, ECR_Overlap);
|
|
LeftThumbFingertipGrabCollider->SetCollisionResponseToChannel(ECC_Pawn, ECR_Overlap);
|
|
LeftThumbFingertipGrabCollider->SetCollisionResponseToChannel(ECC_Visibility, ECR_Overlap);
|
|
LeftThumbFingertipGrabCollider->SetCollisionResponseToChannel(ECC_PhysicsBody, ECR_Overlap);
|
|
LeftThumbFingertipGrabCollider->SetCollisionResponseToChannel(ECC_Vehicle, ECR_Overlap);
|
|
LeftThumbFingertipGrabCollider->SetCollisionResponseToChannel(ECC_Destructible, ECR_Overlap);
|
|
|
|
LeftIndexFingertipGrabCollider = ObjectInitializer.CreateDefaultSubobject<USphereComponent>(
|
|
this, TEXT("LeftIndexFingertipGrabCollider"));
|
|
LeftIndexFingertipGrabCollider->SetRelativeScale3D(HandLeft->GetDefaultFingertipsGrabColliderSize());
|
|
LeftIndexFingertipGrabCollider->SetupAttachment(HandLeft, HandLeft->GetIndexFingertipGrabSocketName());
|
|
LeftIndexFingertipGrabCollider->SetCastShadow(false);
|
|
LeftIndexFingertipGrabCollider->bCastDynamicShadow = false;
|
|
LeftIndexFingertipGrabCollider->SetReceivesDecals(true);
|
|
LeftIndexFingertipGrabCollider->SetCanEverAffectNavigation(false);
|
|
LeftIndexFingertipGrabCollider->SetCollisionObjectType(ECC_WorldDynamic);
|
|
LeftIndexFingertipGrabCollider->SetCollisionEnabled(ECollisionEnabled::QueryOnly);
|
|
LeftIndexFingertipGrabCollider->SetCollisionResponseToAllChannels(ECR_Overlap);
|
|
LeftIndexFingertipGrabCollider->SetCollisionResponseToChannel(ECC_WorldStatic, ECR_Overlap);
|
|
LeftIndexFingertipGrabCollider->SetCollisionResponseToChannel(ECC_WorldDynamic, ECR_Overlap);
|
|
LeftIndexFingertipGrabCollider->SetCollisionResponseToChannel(ECC_Pawn, ECR_Overlap);
|
|
LeftIndexFingertipGrabCollider->SetCollisionResponseToChannel(ECC_Visibility, ECR_Overlap);
|
|
LeftIndexFingertipGrabCollider->SetCollisionResponseToChannel(ECC_PhysicsBody, ECR_Overlap);
|
|
LeftIndexFingertipGrabCollider->SetCollisionResponseToChannel(ECC_Vehicle, ECR_Overlap);
|
|
LeftIndexFingertipGrabCollider->SetCollisionResponseToChannel(ECC_Destructible, ECR_Overlap);
|
|
|
|
LeftMiddleFingertipGrabCollider = ObjectInitializer.CreateDefaultSubobject<USphereComponent>(
|
|
this, TEXT("LeftMiddleFingertipGrabCollider"));
|
|
LeftMiddleFingertipGrabCollider->SetRelativeScale3D(HandLeft->GetDefaultFingertipsGrabColliderSize());
|
|
LeftMiddleFingertipGrabCollider->SetupAttachment(HandLeft, HandLeft->GetMiddleFingertipGrabSocketName());
|
|
LeftMiddleFingertipGrabCollider->SetCastShadow(false);
|
|
LeftMiddleFingertipGrabCollider->bCastDynamicShadow = false;
|
|
LeftMiddleFingertipGrabCollider->SetReceivesDecals(true);
|
|
LeftMiddleFingertipGrabCollider->SetCanEverAffectNavigation(false);
|
|
LeftMiddleFingertipGrabCollider->SetCollisionObjectType(ECC_WorldDynamic);
|
|
LeftMiddleFingertipGrabCollider->SetCollisionEnabled(ECollisionEnabled::QueryOnly);
|
|
LeftMiddleFingertipGrabCollider->SetCollisionResponseToAllChannels(ECR_Overlap);
|
|
LeftMiddleFingertipGrabCollider->SetCollisionResponseToChannel(ECC_WorldStatic, ECR_Overlap);
|
|
LeftMiddleFingertipGrabCollider->SetCollisionResponseToChannel(ECC_WorldDynamic, ECR_Overlap);
|
|
LeftMiddleFingertipGrabCollider->SetCollisionResponseToChannel(ECC_Pawn, ECR_Overlap);
|
|
LeftMiddleFingertipGrabCollider->SetCollisionResponseToChannel(ECC_Visibility, ECR_Overlap);
|
|
LeftMiddleFingertipGrabCollider->SetCollisionResponseToChannel(ECC_PhysicsBody, ECR_Overlap);
|
|
LeftMiddleFingertipGrabCollider->SetCollisionResponseToChannel(ECC_Vehicle, ECR_Overlap);
|
|
LeftMiddleFingertipGrabCollider->SetCollisionResponseToChannel(ECC_Destructible, ECR_Overlap);
|
|
|
|
LeftThumbFingertipTouchCollider = ObjectInitializer.CreateDefaultSubobject<USphereComponent>(
|
|
this, TEXT("LeftThumbFingertipTouchCollider"));
|
|
LeftThumbFingertipTouchCollider->SetRelativeScale3D(HandLeft->GetDefaultFingertipsTouchColliderSize());
|
|
LeftThumbFingertipTouchCollider->SetupAttachment(HandLeft, HandLeft->GetThumbFingertipTouchSocketName());
|
|
LeftThumbFingertipTouchCollider->SetCastShadow(false);
|
|
LeftThumbFingertipTouchCollider->bCastDynamicShadow = false;
|
|
LeftThumbFingertipTouchCollider->SetReceivesDecals(true);
|
|
LeftThumbFingertipTouchCollider->SetCanEverAffectNavigation(false);
|
|
LeftThumbFingertipTouchCollider->SetCollisionObjectType(ECC_WorldDynamic);
|
|
LeftThumbFingertipTouchCollider->SetCollisionEnabled(ECollisionEnabled::QueryOnly);
|
|
LeftThumbFingertipTouchCollider->SetCollisionResponseToAllChannels(ECR_Overlap);
|
|
LeftThumbFingertipTouchCollider->SetCollisionResponseToChannel(ECC_WorldStatic, ECR_Overlap);
|
|
LeftThumbFingertipTouchCollider->SetCollisionResponseToChannel(ECC_WorldDynamic, ECR_Overlap);
|
|
LeftThumbFingertipTouchCollider->SetCollisionResponseToChannel(ECC_Pawn, ECR_Overlap);
|
|
LeftThumbFingertipTouchCollider->SetCollisionResponseToChannel(ECC_Visibility, ECR_Overlap);
|
|
LeftThumbFingertipTouchCollider->SetCollisionResponseToChannel(ECC_PhysicsBody, ECR_Overlap);
|
|
LeftThumbFingertipTouchCollider->SetCollisionResponseToChannel(ECC_Vehicle, ECR_Overlap);
|
|
LeftThumbFingertipTouchCollider->SetCollisionResponseToChannel(ECC_Destructible, ECR_Overlap);
|
|
|
|
LeftIndexFingertipTouchCollider = ObjectInitializer.CreateDefaultSubobject<USphereComponent>(
|
|
this, TEXT("LeftIndexFingertipTouchCollider"));
|
|
LeftIndexFingertipTouchCollider->SetRelativeScale3D(HandLeft->GetDefaultFingertipsTouchColliderSize());
|
|
LeftIndexFingertipTouchCollider->SetupAttachment(HandLeft, HandLeft->GetIndexFingertipTouchSocketName());
|
|
LeftIndexFingertipTouchCollider->SetCastShadow(false);
|
|
LeftIndexFingertipTouchCollider->bCastDynamicShadow = false;
|
|
LeftIndexFingertipTouchCollider->SetReceivesDecals(true);
|
|
LeftIndexFingertipTouchCollider->SetCanEverAffectNavigation(false);
|
|
LeftIndexFingertipTouchCollider->SetCollisionObjectType(ECC_WorldDynamic);
|
|
LeftIndexFingertipTouchCollider->SetCollisionEnabled(ECollisionEnabled::QueryOnly);
|
|
LeftIndexFingertipTouchCollider->SetCollisionResponseToAllChannels(ECR_Overlap);
|
|
LeftIndexFingertipTouchCollider->SetCollisionResponseToChannel(ECC_WorldStatic, ECR_Overlap);
|
|
LeftIndexFingertipTouchCollider->SetCollisionResponseToChannel(ECC_WorldDynamic, ECR_Overlap);
|
|
LeftIndexFingertipTouchCollider->SetCollisionResponseToChannel(ECC_Pawn, ECR_Overlap);
|
|
LeftIndexFingertipTouchCollider->SetCollisionResponseToChannel(ECC_Visibility, ECR_Overlap);
|
|
LeftIndexFingertipTouchCollider->SetCollisionResponseToChannel(ECC_PhysicsBody, ECR_Overlap);
|
|
LeftIndexFingertipTouchCollider->SetCollisionResponseToChannel(ECC_Vehicle, ECR_Overlap);
|
|
LeftIndexFingertipTouchCollider->SetCollisionResponseToChannel(ECC_Destructible, ECR_Overlap);
|
|
|
|
LeftMiddleFingertipTouchCollider = ObjectInitializer.CreateDefaultSubobject<USphereComponent>(
|
|
this, TEXT("LeftMiddleFingertipTouchCollider"));
|
|
LeftMiddleFingertipTouchCollider->SetRelativeScale3D(HandLeft->GetDefaultFingertipsTouchColliderSize());
|
|
LeftMiddleFingertipTouchCollider->SetupAttachment(HandLeft, HandLeft->GetMiddleFingertipTouchSocketName());
|
|
LeftMiddleFingertipTouchCollider->SetCastShadow(false);
|
|
LeftMiddleFingertipTouchCollider->bCastDynamicShadow = false;
|
|
LeftMiddleFingertipTouchCollider->SetReceivesDecals(true);
|
|
LeftMiddleFingertipTouchCollider->SetCanEverAffectNavigation(false);
|
|
LeftMiddleFingertipTouchCollider->SetCollisionObjectType(ECC_WorldDynamic);
|
|
LeftMiddleFingertipTouchCollider->SetCollisionEnabled(ECollisionEnabled::QueryOnly);
|
|
LeftMiddleFingertipTouchCollider->SetCollisionResponseToAllChannels(ECR_Overlap);
|
|
LeftMiddleFingertipTouchCollider->SetCollisionResponseToChannel(ECC_WorldStatic, ECR_Overlap);
|
|
LeftMiddleFingertipTouchCollider->SetCollisionResponseToChannel(ECC_WorldDynamic, ECR_Overlap);
|
|
LeftMiddleFingertipTouchCollider->SetCollisionResponseToChannel(ECC_Pawn, ECR_Overlap);
|
|
LeftMiddleFingertipTouchCollider->SetCollisionResponseToChannel(ECC_Visibility, ECR_Overlap);
|
|
LeftMiddleFingertipTouchCollider->SetCollisionResponseToChannel(ECC_PhysicsBody, ECR_Overlap);
|
|
LeftMiddleFingertipTouchCollider->SetCollisionResponseToChannel(ECC_Vehicle, ECR_Overlap);
|
|
LeftMiddleFingertipTouchCollider->SetCollisionResponseToChannel(ECC_Destructible, ECR_Overlap);
|
|
|
|
LeftRingFingertipTouchCollider = ObjectInitializer.CreateDefaultSubobject<USphereComponent>(
|
|
this, TEXT("LeftRingFingertipTouchCollider"));
|
|
LeftRingFingertipTouchCollider->SetRelativeScale3D(HandLeft->GetDefaultFingertipsTouchColliderSize());
|
|
LeftRingFingertipTouchCollider->SetupAttachment(HandLeft, HandLeft->GetRingFingertipTouchSocketName());
|
|
LeftRingFingertipTouchCollider->SetCastShadow(false);
|
|
LeftRingFingertipTouchCollider->bCastDynamicShadow = false;
|
|
LeftRingFingertipTouchCollider->SetReceivesDecals(true);
|
|
LeftRingFingertipTouchCollider->SetCanEverAffectNavigation(false);
|
|
LeftRingFingertipTouchCollider->SetCollisionObjectType(ECC_WorldDynamic);
|
|
LeftRingFingertipTouchCollider->SetCollisionEnabled(ECollisionEnabled::QueryOnly);
|
|
LeftRingFingertipTouchCollider->SetCollisionResponseToAllChannels(ECR_Overlap);
|
|
LeftRingFingertipTouchCollider->SetCollisionResponseToChannel(ECC_WorldStatic, ECR_Overlap);
|
|
LeftRingFingertipTouchCollider->SetCollisionResponseToChannel(ECC_WorldDynamic, ECR_Overlap);
|
|
LeftRingFingertipTouchCollider->SetCollisionResponseToChannel(ECC_Pawn, ECR_Overlap);
|
|
LeftRingFingertipTouchCollider->SetCollisionResponseToChannel(ECC_Visibility, ECR_Overlap);
|
|
LeftRingFingertipTouchCollider->SetCollisionResponseToChannel(ECC_PhysicsBody, ECR_Overlap);
|
|
LeftRingFingertipTouchCollider->SetCollisionResponseToChannel(ECC_Vehicle, ECR_Overlap);
|
|
LeftRingFingertipTouchCollider->SetCollisionResponseToChannel(ECC_Destructible, ECR_Overlap);
|
|
|
|
LeftPinkyFingertipTouchCollider = ObjectInitializer.CreateDefaultSubobject<USphereComponent>(
|
|
this, TEXT("LeftPinkyFingertipTouchCollider"));
|
|
LeftPinkyFingertipTouchCollider->SetRelativeScale3D(HandLeft->GetDefaultFingertipsTouchColliderSize());
|
|
LeftPinkyFingertipTouchCollider->SetupAttachment(HandLeft, HandLeft->GetPinkyFingertipTouchSocketName());
|
|
LeftPinkyFingertipTouchCollider->SetCastShadow(false);
|
|
LeftPinkyFingertipTouchCollider->bCastDynamicShadow = false;
|
|
LeftPinkyFingertipTouchCollider->SetReceivesDecals(true);
|
|
LeftPinkyFingertipTouchCollider->SetCanEverAffectNavigation(false);
|
|
LeftPinkyFingertipTouchCollider->SetCollisionObjectType(ECC_WorldDynamic);
|
|
LeftPinkyFingertipTouchCollider->SetCollisionEnabled(ECollisionEnabled::QueryOnly);
|
|
LeftPinkyFingertipTouchCollider->SetCollisionResponseToAllChannels(ECR_Overlap);
|
|
LeftPinkyFingertipTouchCollider->SetCollisionResponseToChannel(ECC_WorldStatic, ECR_Overlap);
|
|
LeftPinkyFingertipTouchCollider->SetCollisionResponseToChannel(ECC_WorldDynamic, ECR_Overlap);
|
|
LeftPinkyFingertipTouchCollider->SetCollisionResponseToChannel(ECC_Pawn, ECR_Overlap);
|
|
LeftPinkyFingertipTouchCollider->SetCollisionResponseToChannel(ECC_Visibility, ECR_Overlap);
|
|
LeftPinkyFingertipTouchCollider->SetCollisionResponseToChannel(ECC_PhysicsBody, ECR_Overlap);
|
|
LeftPinkyFingertipTouchCollider->SetCollisionResponseToChannel(ECC_Vehicle, ECR_Overlap);
|
|
LeftPinkyFingertipTouchCollider->SetCollisionResponseToChannel(ECC_Destructible, ECR_Overlap);
|
|
|
|
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);
|
|
HandRight->SetWristTracker(WristTrackerRight);
|
|
|
|
RightThumbFingertipGrabCollider = ObjectInitializer.CreateDefaultSubobject<USphereComponent>(
|
|
this, TEXT("RightThumbFingertipGrabCollider"));
|
|
RightThumbFingertipGrabCollider->SetRelativeScale3D(HandLeft->GetDefaultFingertipsGrabColliderSize());
|
|
RightThumbFingertipGrabCollider->SetupAttachment(HandRight, HandRight->GetThumbFingertipGrabSocketName());
|
|
RightThumbFingertipGrabCollider->SetCastShadow(false);
|
|
RightThumbFingertipGrabCollider->bCastDynamicShadow = false;
|
|
RightThumbFingertipGrabCollider->SetReceivesDecals(true);
|
|
RightThumbFingertipGrabCollider->SetCanEverAffectNavigation(false);
|
|
RightThumbFingertipGrabCollider->SetCollisionObjectType(ECC_WorldDynamic);
|
|
RightThumbFingertipGrabCollider->SetCollisionEnabled(ECollisionEnabled::QueryOnly);
|
|
RightThumbFingertipGrabCollider->SetCollisionResponseToAllChannels(ECR_Overlap);
|
|
RightThumbFingertipGrabCollider->SetCollisionResponseToChannel(ECC_WorldStatic, ECR_Overlap);
|
|
RightThumbFingertipGrabCollider->SetCollisionResponseToChannel(ECC_WorldDynamic, ECR_Overlap);
|
|
RightThumbFingertipGrabCollider->SetCollisionResponseToChannel(ECC_Pawn, ECR_Overlap);
|
|
RightThumbFingertipGrabCollider->SetCollisionResponseToChannel(ECC_Visibility, ECR_Overlap);
|
|
RightThumbFingertipGrabCollider->SetCollisionResponseToChannel(ECC_PhysicsBody, ECR_Overlap);
|
|
RightThumbFingertipGrabCollider->SetCollisionResponseToChannel(ECC_Vehicle, ECR_Overlap);
|
|
RightThumbFingertipGrabCollider->SetCollisionResponseToChannel(ECC_Destructible, ECR_Overlap);
|
|
|
|
RightIndexFingertipGrabCollider = ObjectInitializer.CreateDefaultSubobject<USphereComponent>(
|
|
this, TEXT("RightIndexFingertipGrabCollider"));
|
|
RightIndexFingertipGrabCollider->SetRelativeScale3D(HandLeft->GetDefaultFingertipsGrabColliderSize());
|
|
RightIndexFingertipGrabCollider->SetupAttachment(HandRight, HandRight->GetIndexFingertipGrabSocketName());
|
|
RightIndexFingertipGrabCollider->SetCastShadow(false);
|
|
RightIndexFingertipGrabCollider->bCastDynamicShadow = false;
|
|
RightIndexFingertipGrabCollider->SetReceivesDecals(true);
|
|
RightIndexFingertipGrabCollider->SetCanEverAffectNavigation(false);
|
|
RightIndexFingertipGrabCollider->SetCollisionObjectType(ECC_WorldDynamic);
|
|
RightIndexFingertipGrabCollider->SetCollisionEnabled(ECollisionEnabled::QueryOnly);
|
|
RightIndexFingertipGrabCollider->SetCollisionResponseToAllChannels(ECR_Overlap);
|
|
RightIndexFingertipGrabCollider->SetCollisionResponseToChannel(ECC_WorldStatic, ECR_Overlap);
|
|
RightIndexFingertipGrabCollider->SetCollisionResponseToChannel(ECC_WorldDynamic, ECR_Overlap);
|
|
RightIndexFingertipGrabCollider->SetCollisionResponseToChannel(ECC_Pawn, ECR_Overlap);
|
|
RightIndexFingertipGrabCollider->SetCollisionResponseToChannel(ECC_Visibility, ECR_Overlap);
|
|
RightIndexFingertipGrabCollider->SetCollisionResponseToChannel(ECC_PhysicsBody, ECR_Overlap);
|
|
RightIndexFingertipGrabCollider->SetCollisionResponseToChannel(ECC_Vehicle, ECR_Overlap);
|
|
RightIndexFingertipGrabCollider->SetCollisionResponseToChannel(ECC_Destructible, ECR_Overlap);
|
|
|
|
RightMiddleFingertipGrabCollider = ObjectInitializer.CreateDefaultSubobject<USphereComponent>(
|
|
this, TEXT("RightMiddleFingertipGrabCollider"));
|
|
RightMiddleFingertipGrabCollider->SetRelativeScale3D(HandLeft->GetDefaultFingertipsGrabColliderSize());
|
|
RightMiddleFingertipGrabCollider->SetupAttachment(HandRight, HandRight->GetMiddleFingertipGrabSocketName());
|
|
RightMiddleFingertipGrabCollider->SetCastShadow(false);
|
|
RightMiddleFingertipGrabCollider->bCastDynamicShadow = false;
|
|
RightMiddleFingertipGrabCollider->SetReceivesDecals(true);
|
|
RightMiddleFingertipGrabCollider->SetCanEverAffectNavigation(false);
|
|
RightMiddleFingertipGrabCollider->SetCollisionObjectType(ECC_WorldDynamic);
|
|
RightMiddleFingertipGrabCollider->SetCollisionEnabled(ECollisionEnabled::QueryOnly);
|
|
RightMiddleFingertipGrabCollider->SetCollisionResponseToAllChannels(ECR_Overlap);
|
|
RightMiddleFingertipGrabCollider->SetCollisionResponseToChannel(ECC_WorldStatic, ECR_Overlap);
|
|
RightMiddleFingertipGrabCollider->SetCollisionResponseToChannel(ECC_WorldDynamic, ECR_Overlap);
|
|
RightMiddleFingertipGrabCollider->SetCollisionResponseToChannel(ECC_Pawn, ECR_Overlap);
|
|
RightMiddleFingertipGrabCollider->SetCollisionResponseToChannel(ECC_Visibility, ECR_Overlap);
|
|
RightMiddleFingertipGrabCollider->SetCollisionResponseToChannel(ECC_PhysicsBody, ECR_Overlap);
|
|
RightMiddleFingertipGrabCollider->SetCollisionResponseToChannel(ECC_Vehicle, ECR_Overlap);
|
|
RightMiddleFingertipGrabCollider->SetCollisionResponseToChannel(ECC_Destructible, ECR_Overlap);
|
|
|
|
RightThumbFingertipTouchCollider = ObjectInitializer.CreateDefaultSubobject<USphereComponent>(
|
|
this, TEXT("RightThumbFingertipTouchCollider"));
|
|
RightThumbFingertipTouchCollider->SetRelativeScale3D(HandRight->GetDefaultFingertipsTouchColliderSize());
|
|
RightThumbFingertipTouchCollider->SetupAttachment(HandRight, HandRight->GetThumbFingertipTouchSocketName());
|
|
RightThumbFingertipTouchCollider->SetCastShadow(false);
|
|
RightThumbFingertipTouchCollider->bCastDynamicShadow = false;
|
|
RightThumbFingertipTouchCollider->SetReceivesDecals(true);
|
|
RightThumbFingertipTouchCollider->SetCanEverAffectNavigation(false);
|
|
RightThumbFingertipTouchCollider->SetCollisionObjectType(ECC_WorldDynamic);
|
|
RightThumbFingertipTouchCollider->SetCollisionEnabled(ECollisionEnabled::QueryOnly);
|
|
RightThumbFingertipTouchCollider->SetCollisionResponseToAllChannels(ECR_Overlap);
|
|
RightThumbFingertipTouchCollider->SetCollisionResponseToChannel(ECC_WorldStatic, ECR_Overlap);
|
|
RightThumbFingertipTouchCollider->SetCollisionResponseToChannel(ECC_WorldDynamic, ECR_Overlap);
|
|
RightThumbFingertipTouchCollider->SetCollisionResponseToChannel(ECC_Pawn, ECR_Overlap);
|
|
RightThumbFingertipTouchCollider->SetCollisionResponseToChannel(ECC_Visibility, ECR_Overlap);
|
|
RightThumbFingertipTouchCollider->SetCollisionResponseToChannel(ECC_PhysicsBody, ECR_Overlap);
|
|
RightThumbFingertipTouchCollider->SetCollisionResponseToChannel(ECC_Vehicle, ECR_Overlap);
|
|
RightThumbFingertipTouchCollider->SetCollisionResponseToChannel(ECC_Destructible, ECR_Overlap);
|
|
|
|
RightIndexFingertipTouchCollider = ObjectInitializer.CreateDefaultSubobject<USphereComponent>(
|
|
this, TEXT("RightIndexFingertipTouchCollider"));
|
|
RightIndexFingertipTouchCollider->SetRelativeScale3D(HandRight->GetDefaultFingertipsTouchColliderSize());
|
|
RightIndexFingertipTouchCollider->SetupAttachment(HandRight, HandRight->GetIndexFingertipTouchSocketName());
|
|
RightIndexFingertipTouchCollider->SetCastShadow(false);
|
|
RightIndexFingertipTouchCollider->bCastDynamicShadow = false;
|
|
RightIndexFingertipTouchCollider->SetReceivesDecals(true);
|
|
RightIndexFingertipTouchCollider->SetCanEverAffectNavigation(false);
|
|
RightIndexFingertipTouchCollider->SetCollisionObjectType(ECC_WorldDynamic);
|
|
RightIndexFingertipTouchCollider->SetCollisionEnabled(ECollisionEnabled::QueryOnly);
|
|
RightIndexFingertipTouchCollider->SetCollisionResponseToAllChannels(ECR_Overlap);
|
|
RightIndexFingertipTouchCollider->SetCollisionResponseToChannel(ECC_WorldStatic, ECR_Overlap);
|
|
RightIndexFingertipTouchCollider->SetCollisionResponseToChannel(ECC_WorldDynamic, ECR_Overlap);
|
|
RightIndexFingertipTouchCollider->SetCollisionResponseToChannel(ECC_Pawn, ECR_Overlap);
|
|
RightIndexFingertipTouchCollider->SetCollisionResponseToChannel(ECC_Visibility, ECR_Overlap);
|
|
RightIndexFingertipTouchCollider->SetCollisionResponseToChannel(ECC_PhysicsBody, ECR_Overlap);
|
|
RightIndexFingertipTouchCollider->SetCollisionResponseToChannel(ECC_Vehicle, ECR_Overlap);
|
|
RightIndexFingertipTouchCollider->SetCollisionResponseToChannel(ECC_Destructible, ECR_Overlap);
|
|
|
|
RightMiddleFingertipTouchCollider = ObjectInitializer.CreateDefaultSubobject<USphereComponent>(
|
|
this, TEXT("RightMiddleFingertipTouchCollider"));
|
|
RightMiddleFingertipTouchCollider->SetRelativeScale3D(HandRight->GetDefaultFingertipsTouchColliderSize());
|
|
RightMiddleFingertipTouchCollider->SetupAttachment(HandRight, HandRight->GetMiddleFingertipTouchSocketName());
|
|
RightMiddleFingertipTouchCollider->SetCastShadow(false);
|
|
RightMiddleFingertipTouchCollider->bCastDynamicShadow = false;
|
|
RightMiddleFingertipTouchCollider->SetReceivesDecals(true);
|
|
RightMiddleFingertipTouchCollider->SetCanEverAffectNavigation(false);
|
|
RightMiddleFingertipTouchCollider->SetCollisionObjectType(ECC_WorldDynamic);
|
|
RightMiddleFingertipTouchCollider->SetCollisionEnabled(ECollisionEnabled::QueryOnly);
|
|
RightMiddleFingertipTouchCollider->SetCollisionResponseToAllChannels(ECR_Overlap);
|
|
RightMiddleFingertipTouchCollider->SetCollisionResponseToChannel(ECC_WorldStatic, ECR_Overlap);
|
|
RightMiddleFingertipTouchCollider->SetCollisionResponseToChannel(ECC_WorldDynamic, ECR_Overlap);
|
|
RightMiddleFingertipTouchCollider->SetCollisionResponseToChannel(ECC_Pawn, ECR_Overlap);
|
|
RightMiddleFingertipTouchCollider->SetCollisionResponseToChannel(ECC_Visibility, ECR_Overlap);
|
|
RightMiddleFingertipTouchCollider->SetCollisionResponseToChannel(ECC_PhysicsBody, ECR_Overlap);
|
|
RightMiddleFingertipTouchCollider->SetCollisionResponseToChannel(ECC_Vehicle, ECR_Overlap);
|
|
RightMiddleFingertipTouchCollider->SetCollisionResponseToChannel(ECC_Destructible, ECR_Overlap);
|
|
|
|
RightRingFingertipTouchCollider = ObjectInitializer.CreateDefaultSubobject<USphereComponent>(
|
|
this, TEXT("RightRingFingertipTouchCollider"));
|
|
RightRingFingertipTouchCollider->SetRelativeScale3D(HandRight->GetDefaultFingertipsTouchColliderSize());
|
|
RightRingFingertipTouchCollider->SetupAttachment(HandRight, HandRight->GetRingFingertipTouchSocketName());
|
|
RightRingFingertipTouchCollider->SetCastShadow(false);
|
|
RightRingFingertipTouchCollider->bCastDynamicShadow = false;
|
|
RightRingFingertipTouchCollider->SetReceivesDecals(true);
|
|
RightRingFingertipTouchCollider->SetCanEverAffectNavigation(false);
|
|
RightRingFingertipTouchCollider->SetCollisionObjectType(ECC_WorldDynamic);
|
|
RightRingFingertipTouchCollider->SetCollisionEnabled(ECollisionEnabled::QueryOnly);
|
|
RightRingFingertipTouchCollider->SetCollisionResponseToAllChannels(ECR_Overlap);
|
|
RightRingFingertipTouchCollider->SetCollisionResponseToChannel(ECC_WorldStatic, ECR_Overlap);
|
|
RightRingFingertipTouchCollider->SetCollisionResponseToChannel(ECC_WorldDynamic, ECR_Overlap);
|
|
RightRingFingertipTouchCollider->SetCollisionResponseToChannel(ECC_Pawn, ECR_Overlap);
|
|
RightRingFingertipTouchCollider->SetCollisionResponseToChannel(ECC_Visibility, ECR_Overlap);
|
|
RightRingFingertipTouchCollider->SetCollisionResponseToChannel(ECC_PhysicsBody, ECR_Overlap);
|
|
RightRingFingertipTouchCollider->SetCollisionResponseToChannel(ECC_Vehicle, ECR_Overlap);
|
|
RightRingFingertipTouchCollider->SetCollisionResponseToChannel(ECC_Destructible, ECR_Overlap);
|
|
|
|
RightPinkyFingertipTouchCollider = ObjectInitializer.CreateDefaultSubobject<USphereComponent>(
|
|
this, TEXT("RightPinkyFingertipTouchCollider"));
|
|
RightPinkyFingertipTouchCollider->SetRelativeScale3D(HandRight->GetDefaultFingertipsTouchColliderSize());
|
|
RightPinkyFingertipTouchCollider->SetupAttachment(HandRight, HandRight->GetPinkyFingertipTouchSocketName());
|
|
RightPinkyFingertipTouchCollider->SetCastShadow(false);
|
|
RightPinkyFingertipTouchCollider->bCastDynamicShadow = false;
|
|
RightPinkyFingertipTouchCollider->SetReceivesDecals(true);
|
|
RightPinkyFingertipTouchCollider->SetCanEverAffectNavigation(false);
|
|
RightPinkyFingertipTouchCollider->SetCollisionObjectType(ECC_WorldDynamic);
|
|
RightPinkyFingertipTouchCollider->SetCollisionEnabled(ECollisionEnabled::QueryOnly);
|
|
RightPinkyFingertipTouchCollider->SetCollisionResponseToAllChannels(ECR_Overlap);
|
|
RightPinkyFingertipTouchCollider->SetCollisionResponseToChannel(ECC_WorldStatic, ECR_Overlap);
|
|
RightPinkyFingertipTouchCollider->SetCollisionResponseToChannel(ECC_WorldDynamic, ECR_Overlap);
|
|
RightPinkyFingertipTouchCollider->SetCollisionResponseToChannel(ECC_Pawn, ECR_Overlap);
|
|
RightPinkyFingertipTouchCollider->SetCollisionResponseToChannel(ECC_Visibility, ECR_Overlap);
|
|
RightPinkyFingertipTouchCollider->SetCollisionResponseToChannel(ECC_PhysicsBody, ECR_Overlap);
|
|
RightPinkyFingertipTouchCollider->SetCollisionResponseToChannel(ECC_Vehicle, ECR_Overlap);
|
|
RightPinkyFingertipTouchCollider->SetCollisionResponseToChannel(ECC_Destructible, ECR_Overlap);
|
|
|
|
MaxNumberOfHandVelocitySamples = 10;
|
|
|
|
LeftHandGrabState = FSGGrabState(HandLeft, FVector::Zero(), {}, nullptr, nullptr, nullptr, nullptr);
|
|
LeftHandTouchState = FSGTouchState(HandLeft, nullptr, nullptr, nullptr, nullptr, nullptr);
|
|
|
|
RightHandGrabState = FSGGrabState(HandRight, FVector::Zero(), {}, nullptr, nullptr, nullptr, nullptr);
|
|
RightHandTouchState = FSGTouchState(HandRight, nullptr, nullptr, nullptr, nullptr, nullptr);
|
|
}
|
|
|
|
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->SetWorldLocation(Location);
|
|
});
|
|
|
|
WristTrackerLeft->OnWristRotationChanged().AddWeakLambda(this, [&](const FRotator& Rotation)-> void
|
|
{
|
|
HandLeft->SetWorldRotation(Rotation);
|
|
});
|
|
|
|
WristTrackerRight->OnWristLocationChanged().AddWeakLambda(this, [&](const FVector& Location)-> void
|
|
{
|
|
HandRight->SetWorldLocation(Location);
|
|
});
|
|
|
|
WristTrackerRight->OnWristRotationChanged().AddWeakLambda(this, [&](const FRotator& Rotation)-> void
|
|
{
|
|
HandRight->SetWorldRotation(Rotation);
|
|
});
|
|
|
|
Pimpl->BindFingerGrabOverlapEvents();
|
|
Pimpl->BindFingerTouchOverlapEvents();
|
|
}
|
|
|
|
void ASGPawn::EndPlay(const EEndPlayReason::Type EndPlayReason)
|
|
{
|
|
Super::EndPlay(EndPlayReason);
|
|
|
|
Pimpl->UnbindFingerGrabOverlapEvents();
|
|
Pimpl->UnbindFingerTouchOverlapEvents();
|
|
}
|
|
|
|
void ASGPawn::Tick(const float DeltaSeconds)
|
|
{
|
|
Super::Tick(DeltaSeconds);
|
|
|
|
Pimpl->RecordHandVelocity(LeftHandGrabState, DeltaSeconds);
|
|
Pimpl->RecordHandVelocity(RightHandGrabState, DeltaSeconds);
|
|
}
|
|
|
|
void ASGPawn::PreInitializeComponents()
|
|
{
|
|
Super::PreInitializeComponents();
|
|
|
|
WristTrackerLeft->SetRight(HandLeft->IsRight());
|
|
WristTrackerRight->SetRight(HandRight->IsRight());
|
|
}
|
|
|
|
void ASGPawn::OnLeftThumbFingertipGrabColliderOverlapBegins(
|
|
UPrimitiveComponent* OverlappedComponent,
|
|
AActor* OtherActor,
|
|
UPrimitiveComponent* OtherComp,
|
|
const int32 OtherBodyIndex,
|
|
const bool bFromSweep,
|
|
const FHitResult& SweepResult)
|
|
{
|
|
(void) OverlappedComponent;
|
|
(void) OtherBodyIndex;
|
|
(void) bFromSweep;
|
|
(void) SweepResult;
|
|
|
|
if (USGGrabComponent::IsGrabbable(OtherActor))
|
|
{
|
|
LeftHandGrabState.ActorThumbCanGrab = OtherActor;
|
|
GrabStateUpdatedEvent.Broadcast(LeftHandGrabState);
|
|
}
|
|
}
|
|
|
|
void ASGPawn::OnLeftThumbFingertipGrabColliderOverlapEnds(
|
|
UPrimitiveComponent* OverlappedComponent,
|
|
AActor* OtherActor,
|
|
UPrimitiveComponent* OtherComp,
|
|
const int32 OtherBodyIndex)
|
|
{
|
|
(void) OverlappedComponent;
|
|
(void) OtherBodyIndex;
|
|
|
|
if (LeftHandGrabState.ActorThumbCanGrab == OtherActor)
|
|
{
|
|
LeftHandGrabState.ActorThumbCanGrab = nullptr;
|
|
GrabStateUpdatedEvent.Broadcast(LeftHandGrabState);
|
|
}
|
|
}
|
|
|
|
void ASGPawn::OnLeftIndexFingertipGrabColliderOverlapBegins(
|
|
UPrimitiveComponent* OverlappedComponent,
|
|
AActor* OtherActor,
|
|
UPrimitiveComponent* OtherComp,
|
|
const int32 OtherBodyIndex,
|
|
const bool bFromSweep,
|
|
const FHitResult& SweepResult)
|
|
{
|
|
(void) OverlappedComponent;
|
|
(void) OtherBodyIndex;
|
|
(void) bFromSweep;
|
|
(void) SweepResult;
|
|
|
|
if (USGGrabComponent::IsGrabbable(OtherActor))
|
|
{
|
|
LeftHandGrabState.ActorIndexCanGrab = OtherActor;
|
|
GrabStateUpdatedEvent.Broadcast(LeftHandGrabState);
|
|
}
|
|
}
|
|
|
|
void ASGPawn::OnLeftIndexFingertipGrabColliderOverlapEnds(
|
|
UPrimitiveComponent* OverlappedComponent,
|
|
AActor* OtherActor,
|
|
UPrimitiveComponent* OtherComp,
|
|
const int32 OtherBodyIndex)
|
|
{
|
|
(void) OverlappedComponent;
|
|
(void) OtherBodyIndex;
|
|
|
|
if (LeftHandGrabState.ActorIndexCanGrab == OtherActor)
|
|
{
|
|
LeftHandGrabState.ActorIndexCanGrab = nullptr;
|
|
GrabStateUpdatedEvent.Broadcast(LeftHandGrabState);
|
|
}
|
|
}
|
|
|
|
void ASGPawn::OnLeftMiddleFingertipGrabColliderOverlapBegins(
|
|
UPrimitiveComponent* OverlappedComponent,
|
|
AActor* OtherActor,
|
|
UPrimitiveComponent* OtherComp,
|
|
const int32 OtherBodyIndex,
|
|
const bool bFromSweep,
|
|
const FHitResult& SweepResult)
|
|
{
|
|
(void) OverlappedComponent;
|
|
(void) OtherBodyIndex;
|
|
(void) bFromSweep;
|
|
(void) SweepResult;
|
|
|
|
if (USGGrabComponent::IsGrabbable(OtherActor))
|
|
{
|
|
LeftHandGrabState.ActorMiddleCanGrab = OtherActor;
|
|
GrabStateUpdatedEvent.Broadcast(LeftHandGrabState);
|
|
}
|
|
}
|
|
|
|
void ASGPawn::OnLeftMiddleFingertipGrabColliderOverlapEnds(
|
|
UPrimitiveComponent* OverlappedComponent,
|
|
AActor* OtherActor,
|
|
UPrimitiveComponent* OtherComp,
|
|
const int32 OtherBodyIndex)
|
|
{
|
|
(void) OverlappedComponent;
|
|
(void) OtherBodyIndex;
|
|
|
|
if (LeftHandGrabState.ActorMiddleCanGrab == OtherActor)
|
|
{
|
|
LeftHandGrabState.ActorMiddleCanGrab = nullptr;
|
|
GrabStateUpdatedEvent.Broadcast(LeftHandGrabState);
|
|
}
|
|
}
|
|
|
|
void ASGPawn::OnLeftThumbFingertipTouchColliderOverlapBegins(
|
|
UPrimitiveComponent* OverlappedComponent,
|
|
AActor* OtherActor,
|
|
UPrimitiveComponent* OtherComp,
|
|
const int32 OtherBodyIndex,
|
|
const bool bFromSweep,
|
|
const FHitResult& SweepResult)
|
|
{
|
|
(void) OverlappedComponent;
|
|
(void) OtherComp;
|
|
(void) OtherBodyIndex;
|
|
(void) bFromSweep;
|
|
(void) SweepResult;
|
|
|
|
if (USGTouchComponent::IsTouchable(OtherActor))
|
|
{
|
|
LeftHandTouchState.ActorThumbTouching = OtherActor;
|
|
TouchStateUpdatedEvent.Broadcast(LeftHandTouchState);
|
|
}
|
|
}
|
|
|
|
void ASGPawn::OnLeftThumbFingertipTouchColliderOverlapEnds(
|
|
UPrimitiveComponent* OverlappedComponent,
|
|
AActor* OtherActor,
|
|
UPrimitiveComponent* OtherComp,
|
|
const int32 OtherBodyIndex)
|
|
{
|
|
(void) OverlappedComponent;
|
|
(void) OtherComp;
|
|
(void) OtherBodyIndex;
|
|
|
|
if (LeftHandTouchState.ActorThumbTouching == OtherActor)
|
|
{
|
|
LeftHandTouchState.ActorThumbTouching = nullptr;
|
|
TouchStateUpdatedEvent.Broadcast(LeftHandTouchState);
|
|
}
|
|
}
|
|
|
|
void ASGPawn::OnLeftIndexFingertipTouchColliderOverlapBegins(
|
|
UPrimitiveComponent* OverlappedComponent,
|
|
AActor* OtherActor,
|
|
UPrimitiveComponent* OtherComp,
|
|
const int32 OtherBodyIndex,
|
|
const bool bFromSweep,
|
|
const FHitResult& SweepResult)
|
|
{
|
|
(void) OverlappedComponent;
|
|
(void) OtherComp;
|
|
(void) OtherBodyIndex;
|
|
(void) bFromSweep;
|
|
(void) SweepResult;
|
|
|
|
if (USGTouchComponent::IsTouchable(OtherActor))
|
|
{
|
|
LeftHandTouchState.ActorIndexTouching = OtherActor;
|
|
TouchStateUpdatedEvent.Broadcast(LeftHandTouchState);
|
|
}
|
|
}
|
|
|
|
void ASGPawn::OnLeftIndexFingertipTouchColliderOverlapEnds(
|
|
UPrimitiveComponent* OverlappedComponent,
|
|
AActor* OtherActor,
|
|
UPrimitiveComponent* OtherComp,
|
|
const int32 OtherBodyIndex)
|
|
{
|
|
(void) OverlappedComponent;
|
|
(void) OtherComp;
|
|
(void) OtherBodyIndex;
|
|
|
|
if (LeftHandTouchState.ActorIndexTouching == OtherActor)
|
|
{
|
|
LeftHandTouchState.ActorIndexTouching = nullptr;
|
|
TouchStateUpdatedEvent.Broadcast(LeftHandTouchState);
|
|
}
|
|
}
|
|
|
|
void ASGPawn::OnLeftMiddleFingertipTouchColliderOverlapBegins(
|
|
UPrimitiveComponent* OverlappedComponent,
|
|
AActor* OtherActor,
|
|
UPrimitiveComponent* OtherComp,
|
|
const int32 OtherBodyIndex,
|
|
const bool bFromSweep,
|
|
const FHitResult& SweepResult)
|
|
{
|
|
(void) OverlappedComponent;
|
|
(void) OtherComp;
|
|
(void) OtherBodyIndex;
|
|
(void) bFromSweep;
|
|
(void) SweepResult;
|
|
|
|
if (USGTouchComponent::IsTouchable(OtherActor))
|
|
{
|
|
LeftHandTouchState.ActorMiddleTouching = OtherActor;
|
|
TouchStateUpdatedEvent.Broadcast(LeftHandTouchState);
|
|
}
|
|
}
|
|
|
|
void ASGPawn::OnLeftMiddleFingertipTouchColliderOverlapEnds(
|
|
UPrimitiveComponent* OverlappedComponent,
|
|
AActor* OtherActor,
|
|
UPrimitiveComponent* OtherComp,
|
|
const int32 OtherBodyIndex)
|
|
{
|
|
(void) OverlappedComponent;
|
|
(void) OtherComp;
|
|
(void) OtherBodyIndex;
|
|
|
|
if (LeftHandTouchState.ActorMiddleTouching == OtherActor)
|
|
{
|
|
LeftHandTouchState.ActorMiddleTouching = nullptr;
|
|
TouchStateUpdatedEvent.Broadcast(LeftHandTouchState);
|
|
}
|
|
}
|
|
|
|
void ASGPawn::OnLeftRingFingertipTouchColliderOverlapBegins(
|
|
UPrimitiveComponent* OverlappedComponent,
|
|
AActor* OtherActor,
|
|
UPrimitiveComponent* OtherComp,
|
|
const int32 OtherBodyIndex,
|
|
const bool bFromSweep,
|
|
const FHitResult& SweepResult)
|
|
{
|
|
(void) OverlappedComponent;
|
|
(void) OtherComp;
|
|
(void) OtherBodyIndex;
|
|
(void) bFromSweep;
|
|
(void) SweepResult;
|
|
|
|
if (USGTouchComponent::IsTouchable(OtherActor))
|
|
{
|
|
LeftHandTouchState.ActorRingTouching = OtherActor;
|
|
TouchStateUpdatedEvent.Broadcast(LeftHandTouchState);
|
|
}
|
|
}
|
|
|
|
void ASGPawn::OnLeftRingFingertipTouchColliderOverlapEnds(
|
|
UPrimitiveComponent* OverlappedComponent,
|
|
AActor* OtherActor,
|
|
UPrimitiveComponent* OtherComp,
|
|
const int32 OtherBodyIndex)
|
|
{
|
|
(void) OverlappedComponent;
|
|
(void) OtherComp;
|
|
(void) OtherBodyIndex;
|
|
|
|
if (LeftHandTouchState.ActorRingTouching == OtherActor)
|
|
{
|
|
LeftHandTouchState.ActorRingTouching = nullptr;
|
|
TouchStateUpdatedEvent.Broadcast(LeftHandTouchState);
|
|
}
|
|
}
|
|
|
|
void ASGPawn::OnLeftPinkyFingertipTouchColliderOverlapBegins(
|
|
UPrimitiveComponent* OverlappedComponent,
|
|
AActor* OtherActor,
|
|
UPrimitiveComponent* OtherComp,
|
|
const int32 OtherBodyIndex,
|
|
const bool bFromSweep,
|
|
const FHitResult& SweepResult)
|
|
{
|
|
(void) OverlappedComponent;
|
|
(void) OtherComp;
|
|
(void) OtherBodyIndex;
|
|
(void) bFromSweep;
|
|
(void) SweepResult;
|
|
|
|
if (USGTouchComponent::IsTouchable(OtherActor))
|
|
{
|
|
LeftHandTouchState.ActorPinkyTouching = OtherActor;
|
|
TouchStateUpdatedEvent.Broadcast(LeftHandTouchState);
|
|
}
|
|
}
|
|
|
|
void ASGPawn::OnLeftPinkyFingertipTouchColliderOverlapEnds(
|
|
UPrimitiveComponent* OverlappedComponent,
|
|
AActor* OtherActor,
|
|
UPrimitiveComponent* OtherComp,
|
|
const int32 OtherBodyIndex)
|
|
{
|
|
(void) OverlappedComponent;
|
|
(void) OtherComp;
|
|
(void) OtherBodyIndex;
|
|
|
|
if (LeftHandTouchState.ActorPinkyTouching == OtherActor)
|
|
{
|
|
LeftHandTouchState.ActorPinkyTouching = nullptr;
|
|
TouchStateUpdatedEvent.Broadcast(LeftHandTouchState);
|
|
}
|
|
}
|
|
|
|
void ASGPawn::OnRightThumbFingertipGrabColliderOverlapBegins(
|
|
UPrimitiveComponent* OverlappedComponent,
|
|
AActor* OtherActor,
|
|
UPrimitiveComponent* OtherComp,
|
|
const int32 OtherBodyIndex,
|
|
const bool bFromSweep,
|
|
const FHitResult& SweepResult)
|
|
{
|
|
(void) OverlappedComponent;
|
|
(void) OtherBodyIndex;
|
|
(void) bFromSweep;
|
|
(void) SweepResult;
|
|
|
|
if (USGGrabComponent::IsGrabbable(OtherActor))
|
|
{
|
|
RightHandGrabState.ActorThumbCanGrab = OtherActor;
|
|
TouchStateUpdatedEvent.Broadcast(LeftHandTouchState);
|
|
}
|
|
}
|
|
|
|
void ASGPawn::OnRightThumbFingertipGrabColliderOverlapEnds(
|
|
UPrimitiveComponent* OverlappedComponent,
|
|
AActor* OtherActor,
|
|
UPrimitiveComponent* OtherComp,
|
|
const int32 OtherBodyIndex)
|
|
{
|
|
(void) OverlappedComponent;
|
|
(void) OtherBodyIndex;
|
|
|
|
if (RightHandGrabState.ActorThumbCanGrab == OtherActor)
|
|
{
|
|
RightHandGrabState.ActorThumbCanGrab = nullptr;
|
|
GrabStateUpdatedEvent.Broadcast(RightHandGrabState);
|
|
}
|
|
}
|
|
|
|
void ASGPawn::OnRightIndexFingertipGrabColliderOverlapBegins(
|
|
UPrimitiveComponent* OverlappedComponent,
|
|
AActor* OtherActor,
|
|
UPrimitiveComponent* OtherComp,
|
|
const int32 OtherBodyIndex,
|
|
const bool bFromSweep,
|
|
const FHitResult& SweepResult)
|
|
{
|
|
(void) OverlappedComponent;
|
|
(void) OtherBodyIndex;
|
|
(void) bFromSweep;
|
|
(void) SweepResult;
|
|
|
|
if (USGGrabComponent::IsGrabbable(OtherActor))
|
|
{
|
|
RightHandGrabState.ActorIndexCanGrab = OtherActor;
|
|
GrabStateUpdatedEvent.Broadcast(RightHandGrabState);
|
|
}
|
|
}
|
|
|
|
void ASGPawn::OnRightIndexFingertipGrabColliderOverlapEnds(
|
|
UPrimitiveComponent* OverlappedComponent,
|
|
AActor* OtherActor,
|
|
UPrimitiveComponent* OtherComp,
|
|
const int32 OtherBodyIndex)
|
|
{
|
|
(void) OverlappedComponent;
|
|
(void) OtherBodyIndex;
|
|
|
|
if (RightHandGrabState.ActorThumbCanGrab == OtherActor)
|
|
{
|
|
RightHandGrabState.ActorIndexCanGrab = nullptr;
|
|
GrabStateUpdatedEvent.Broadcast(RightHandGrabState);
|
|
}
|
|
}
|
|
|
|
void ASGPawn::OnRightMiddleFingertipGrabColliderOverlapBegins(
|
|
UPrimitiveComponent* OverlappedComponent,
|
|
AActor* OtherActor,
|
|
UPrimitiveComponent* OtherComp,
|
|
const int32 OtherBodyIndex,
|
|
const bool bFromSweep,
|
|
const FHitResult& SweepResult)
|
|
{
|
|
(void) OverlappedComponent;
|
|
(void) OtherBodyIndex;
|
|
(void) bFromSweep;
|
|
(void) SweepResult;
|
|
|
|
if (USGGrabComponent::IsGrabbable(OtherActor))
|
|
{
|
|
RightHandGrabState.ActorMiddleCanGrab = OtherActor;
|
|
GrabStateUpdatedEvent.Broadcast(RightHandGrabState);
|
|
}
|
|
}
|
|
|
|
void ASGPawn::OnRightMiddleFingertipGrabColliderOverlapEnds(
|
|
UPrimitiveComponent* OverlappedComponent,
|
|
AActor* OtherActor,
|
|
UPrimitiveComponent* OtherComp,
|
|
const int32 OtherBodyIndex)
|
|
{
|
|
(void) OverlappedComponent;
|
|
(void) OtherBodyIndex;
|
|
|
|
if (RightHandGrabState.ActorMiddleCanGrab == OtherActor)
|
|
{
|
|
RightHandGrabState.ActorMiddleCanGrab = nullptr;
|
|
GrabStateUpdatedEvent.Broadcast(RightHandGrabState);
|
|
}
|
|
}
|
|
|
|
void ASGPawn::OnRightThumbFingertipTouchColliderOverlapBegins(
|
|
UPrimitiveComponent* OverlappedComponent,
|
|
AActor* OtherActor,
|
|
UPrimitiveComponent* OtherComp,
|
|
const int32 OtherBodyIndex,
|
|
const bool bFromSweep,
|
|
const FHitResult& SweepResult)
|
|
{
|
|
(void) OverlappedComponent;
|
|
(void) OtherComp;
|
|
(void) OtherBodyIndex;
|
|
(void) bFromSweep;
|
|
(void) SweepResult;
|
|
|
|
if (USGTouchComponent::IsTouchable(OtherActor))
|
|
{
|
|
RightHandTouchState.ActorThumbTouching = OtherActor;
|
|
TouchStateUpdatedEvent.Broadcast(RightHandTouchState);
|
|
}
|
|
}
|
|
|
|
void ASGPawn::OnRightThumbFingertipTouchColliderOverlapEnds(
|
|
UPrimitiveComponent* OverlappedComponent,
|
|
AActor* OtherActor,
|
|
UPrimitiveComponent* OtherComp,
|
|
const int32 OtherBodyIndex)
|
|
{
|
|
(void) OverlappedComponent;
|
|
(void) OtherComp;
|
|
(void) OtherBodyIndex;
|
|
|
|
if (RightHandTouchState.ActorThumbTouching == OtherActor)
|
|
{
|
|
RightHandTouchState.ActorThumbTouching = nullptr;
|
|
TouchStateUpdatedEvent.Broadcast(RightHandTouchState);
|
|
}
|
|
}
|
|
|
|
void ASGPawn::OnRightIndexFingertipTouchColliderOverlapBegins(
|
|
UPrimitiveComponent* OverlappedComponent,
|
|
AActor* OtherActor,
|
|
UPrimitiveComponent* OtherComp,
|
|
const int32 OtherBodyIndex,
|
|
const bool bFromSweep,
|
|
const FHitResult& SweepResult)
|
|
{
|
|
(void) OverlappedComponent;
|
|
(void) OtherComp;
|
|
(void) OtherBodyIndex;
|
|
(void) bFromSweep;
|
|
(void) SweepResult;
|
|
|
|
if (USGTouchComponent::IsTouchable(OtherActor))
|
|
{
|
|
RightHandTouchState.ActorIndexTouching = OtherActor;
|
|
TouchStateUpdatedEvent.Broadcast(RightHandTouchState);
|
|
}
|
|
}
|
|
|
|
void ASGPawn::OnRightIndexFingertipTouchColliderOverlapEnds(
|
|
UPrimitiveComponent* OverlappedComponent,
|
|
AActor* OtherActor,
|
|
UPrimitiveComponent* OtherComp,
|
|
const int32 OtherBodyIndex)
|
|
{
|
|
(void) OverlappedComponent;
|
|
(void) OtherComp;
|
|
(void) OtherBodyIndex;
|
|
|
|
if (RightHandTouchState.ActorIndexTouching == OtherActor)
|
|
{
|
|
RightHandTouchState.ActorIndexTouching = nullptr;
|
|
TouchStateUpdatedEvent.Broadcast(RightHandTouchState);
|
|
}
|
|
}
|
|
|
|
void ASGPawn::OnRightMiddleFingertipTouchColliderOverlapBegins(
|
|
UPrimitiveComponent* OverlappedComponent,
|
|
AActor* OtherActor,
|
|
UPrimitiveComponent* OtherComp,
|
|
const int32 OtherBodyIndex,
|
|
const bool bFromSweep,
|
|
const FHitResult& SweepResult)
|
|
{
|
|
(void) OverlappedComponent;
|
|
(void) OtherComp;
|
|
(void) OtherBodyIndex;
|
|
(void) bFromSweep;
|
|
(void) SweepResult;
|
|
|
|
if (USGTouchComponent::IsTouchable(OtherActor))
|
|
{
|
|
RightHandTouchState.ActorMiddleTouching = OtherActor;
|
|
TouchStateUpdatedEvent.Broadcast(RightHandTouchState);
|
|
}
|
|
}
|
|
|
|
void ASGPawn::OnRightMiddleFingertipTouchColliderOverlapEnds(
|
|
UPrimitiveComponent* OverlappedComponent,
|
|
AActor* OtherActor,
|
|
UPrimitiveComponent* OtherComp,
|
|
const int32 OtherBodyIndex)
|
|
{
|
|
(void) OverlappedComponent;
|
|
(void) OtherComp;
|
|
(void) OtherBodyIndex;
|
|
|
|
if (RightHandTouchState.ActorMiddleTouching == OtherActor)
|
|
{
|
|
RightHandTouchState.ActorMiddleTouching = nullptr;
|
|
TouchStateUpdatedEvent.Broadcast(RightHandTouchState);
|
|
}
|
|
}
|
|
|
|
void ASGPawn::OnRightRingFingertipTouchColliderOverlapBegins(
|
|
UPrimitiveComponent* OverlappedComponent,
|
|
AActor* OtherActor,
|
|
UPrimitiveComponent* OtherComp,
|
|
const int32 OtherBodyIndex,
|
|
const bool bFromSweep,
|
|
const FHitResult& SweepResult)
|
|
{
|
|
(void) OverlappedComponent;
|
|
(void) OtherComp;
|
|
(void) OtherBodyIndex;
|
|
(void) bFromSweep;
|
|
(void) SweepResult;
|
|
|
|
if (USGTouchComponent::IsTouchable(OtherActor))
|
|
{
|
|
RightHandTouchState.ActorRingTouching = OtherActor;
|
|
TouchStateUpdatedEvent.Broadcast(RightHandTouchState);
|
|
}
|
|
}
|
|
|
|
void ASGPawn::OnRightRingFingertipTouchColliderOverlapEnds(
|
|
UPrimitiveComponent* OverlappedComponent,
|
|
AActor* OtherActor,
|
|
UPrimitiveComponent* OtherComp,
|
|
const int32 OtherBodyIndex)
|
|
{
|
|
(void) OverlappedComponent;
|
|
(void) OtherComp;
|
|
(void) OtherBodyIndex;
|
|
|
|
if (RightHandTouchState.ActorRingTouching == OtherActor)
|
|
{
|
|
RightHandTouchState.ActorRingTouching = nullptr;
|
|
TouchStateUpdatedEvent.Broadcast(RightHandTouchState);
|
|
}
|
|
}
|
|
|
|
void ASGPawn::OnRightPinkyFingertipTouchColliderOverlapBegins(
|
|
UPrimitiveComponent* OverlappedComponent,
|
|
AActor* OtherActor,
|
|
UPrimitiveComponent* OtherComp,
|
|
const int32 OtherBodyIndex,
|
|
const bool bFromSweep,
|
|
const FHitResult& SweepResult)
|
|
{
|
|
(void) OverlappedComponent;
|
|
(void) OtherComp;
|
|
(void) OtherBodyIndex;
|
|
(void) bFromSweep;
|
|
(void) SweepResult;
|
|
|
|
if (USGTouchComponent::IsTouchable(OtherActor))
|
|
{
|
|
RightHandTouchState.ActorPinkyTouching = OtherActor;
|
|
TouchStateUpdatedEvent.Broadcast(RightHandTouchState);
|
|
}
|
|
}
|
|
|
|
void ASGPawn::OnRightPinkyFingertipTouchColliderOverlapEnds(
|
|
UPrimitiveComponent* OverlappedComponent,
|
|
AActor* OtherActor,
|
|
UPrimitiveComponent* OtherComp,
|
|
const int32 OtherBodyIndex)
|
|
{
|
|
(void) OverlappedComponent;
|
|
(void) OtherComp;
|
|
(void) OtherBodyIndex;
|
|
|
|
if (RightHandTouchState.ActorPinkyTouching == OtherActor)
|
|
{
|
|
RightHandTouchState.ActorPinkyTouching = nullptr;
|
|
TouchStateUpdatedEvent.Broadcast(RightHandTouchState);
|
|
}
|
|
}
|
|
|
|
bool ASGPawn::IsLeftHandGrabbing(AActor*& OutActor) const
|
|
{
|
|
if (IsValid(LeftHandGrabState.GrabbedActor))
|
|
{
|
|
OutActor = LeftHandGrabState.GrabbedActor;
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
bool ASGPawn::IsRightHandGrabbing(AActor*& OutActor) const
|
|
{
|
|
if (IsValid(RightHandGrabState.GrabbedActor))
|
|
{
|
|
OutActor = RightHandGrabState.GrabbedActor;
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
bool ASGPawn::IsGrabbing(const USGVirtualHandComponent* Hand, AActor*& OutActor) const
|
|
{
|
|
return Hand == HandLeft ? IsLeftHandGrabbing(OutActor) : IsRightHandGrabbing(OutActor);
|
|
}
|
|
|
|
void ASGPawn::Grab(USGVirtualHandComponent* Hand, AActor* Actor)
|
|
{
|
|
if (!ensureAlwaysMsgf(IsValid(Actor), TEXT("%s"), TEXT("ERROR: invalid actor!")))
|
|
{
|
|
return;
|
|
}
|
|
|
|
const USGGrabComponent* GrabComponent{USGGrabComponent::GetGrabComponent(Actor)};
|
|
if (!GrabComponent)
|
|
{
|
|
return;
|
|
}
|
|
|
|
FAttachmentTransformRules AttachmentRules{
|
|
FAttachmentTransformRules(GrabComponent->GetAttachmentLocationRule(),
|
|
GrabComponent->GetAttachmentRotationRule(),
|
|
GrabComponent->GetAttachmentScaleRule(),
|
|
GrabComponent->GetAttachmentWeldSimulatedBodies())
|
|
};
|
|
|
|
const FName SocketName{GrabComponent->GetAttachmentSocketName()};
|
|
ensureAlwaysMsgf(SocketName != NAME_None, TEXT("invalid attachment socket name!"));
|
|
|
|
if (GrabComponent->GetAffectPhysicsState())
|
|
{
|
|
Pimpl->DisableActorPhysics(Actor);
|
|
}
|
|
|
|
#if ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 2
|
|
const bool bAttached = Actor->AttachToComponent(Hand, MoveTemp(AttachmentRules), SocketName);
|
|
if (bAttached)
|
|
{
|
|
if (Hand->IsRight())
|
|
{
|
|
Pimpl->SetRightHandGrabbedActor(Actor);
|
|
}
|
|
else
|
|
{
|
|
Pimpl->SetLeftHandGrabbedActor(Actor);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (Hand->IsRight())
|
|
{
|
|
SGLOG_ERROR("Failed to grab the actor with the right hand!", Actor, SocketName);
|
|
}
|
|
else
|
|
{
|
|
SGLOG_ERROR("Failed to grab the actor with the left hand!", Actor, SocketName);
|
|
}
|
|
}
|
|
#else
|
|
Actor->AttachToComponent(Hand, MoveTemp(AttachmentRules), SocketName);
|
|
if (Hand->IsRight())
|
|
{
|
|
Pimpl->SetRightHandGrabbedActor(Actor);
|
|
}
|
|
else
|
|
{
|
|
Pimpl->SetLeftHandGrabbedActor(Actor);
|
|
}
|
|
#endif /* ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 2 */
|
|
}
|
|
|
|
void ASGPawn::ReleaseLeft()
|
|
{
|
|
Pimpl->Release(LeftHandGrabState);
|
|
}
|
|
|
|
void ASGPawn::ReleaseRight()
|
|
{
|
|
Pimpl->Release(RightHandGrabState);
|
|
}
|
|
|
|
ASGPawn::FImpl::FImpl(ASGPawn* InOwner)
|
|
: Owner(InOwner)
|
|
{
|
|
}
|
|
|
|
void ASGPawn::FImpl::BindFingerGrabOverlapEvents()
|
|
{
|
|
Owner->LeftThumbFingertipGrabCollider->OnComponentBeginOverlap.AddDynamic(
|
|
Owner, &ASGPawn::OnLeftThumbFingertipGrabColliderOverlapBegins);
|
|
Owner->LeftThumbFingertipGrabCollider->OnComponentEndOverlap.AddDynamic(
|
|
Owner, &ASGPawn::OnLeftThumbFingertipGrabColliderOverlapEnds);
|
|
|
|
Owner->LeftIndexFingertipGrabCollider->OnComponentBeginOverlap.AddDynamic(
|
|
Owner, &ASGPawn::OnLeftIndexFingertipGrabColliderOverlapBegins);
|
|
Owner->LeftIndexFingertipGrabCollider->OnComponentEndOverlap.AddDynamic(
|
|
Owner, &ASGPawn::OnLeftIndexFingertipGrabColliderOverlapEnds);
|
|
|
|
Owner->LeftMiddleFingertipGrabCollider->OnComponentBeginOverlap.AddDynamic(
|
|
Owner, &ASGPawn::OnLeftMiddleFingertipGrabColliderOverlapBegins);
|
|
Owner->LeftMiddleFingertipGrabCollider->OnComponentEndOverlap.AddDynamic(
|
|
Owner, &ASGPawn::OnLeftMiddleFingertipGrabColliderOverlapEnds);
|
|
|
|
Owner->RightThumbFingertipGrabCollider->OnComponentBeginOverlap.AddDynamic(
|
|
Owner, &ASGPawn::OnRightThumbFingertipGrabColliderOverlapBegins);
|
|
Owner->RightThumbFingertipGrabCollider->OnComponentEndOverlap.AddDynamic(
|
|
Owner, &ASGPawn::OnRightThumbFingertipGrabColliderOverlapEnds);
|
|
|
|
Owner->RightIndexFingertipGrabCollider->OnComponentBeginOverlap.AddDynamic(
|
|
Owner, &ASGPawn::OnRightIndexFingertipGrabColliderOverlapBegins);
|
|
Owner->RightIndexFingertipGrabCollider->OnComponentEndOverlap.AddDynamic(
|
|
Owner, &ASGPawn::OnRightIndexFingertipGrabColliderOverlapEnds);
|
|
|
|
Owner->RightMiddleFingertipGrabCollider->OnComponentBeginOverlap.AddDynamic(
|
|
Owner, &ASGPawn::OnRightMiddleFingertipGrabColliderOverlapBegins);
|
|
Owner->RightMiddleFingertipGrabCollider->OnComponentEndOverlap.AddDynamic(
|
|
Owner, &ASGPawn::OnRightMiddleFingertipGrabColliderOverlapEnds);
|
|
}
|
|
|
|
void ASGPawn::FImpl::UnbindFingerGrabOverlapEvents()
|
|
{
|
|
Owner->LeftThumbFingertipGrabCollider->OnComponentBeginOverlap.RemoveDynamic(
|
|
Owner, &ASGPawn::OnLeftThumbFingertipGrabColliderOverlapBegins);
|
|
Owner->LeftThumbFingertipGrabCollider->OnComponentEndOverlap.RemoveDynamic(
|
|
Owner, &ASGPawn::OnLeftThumbFingertipGrabColliderOverlapEnds);
|
|
|
|
Owner->LeftIndexFingertipGrabCollider->OnComponentBeginOverlap.RemoveDynamic(
|
|
Owner, &ASGPawn::OnLeftIndexFingertipGrabColliderOverlapBegins);
|
|
Owner->LeftIndexFingertipGrabCollider->OnComponentEndOverlap.RemoveDynamic(
|
|
Owner, &ASGPawn::OnLeftIndexFingertipGrabColliderOverlapEnds);
|
|
|
|
Owner->LeftMiddleFingertipGrabCollider->OnComponentBeginOverlap.RemoveDynamic(
|
|
Owner, &ASGPawn::OnLeftMiddleFingertipGrabColliderOverlapBegins);
|
|
Owner->LeftMiddleFingertipGrabCollider->OnComponentEndOverlap.RemoveDynamic(
|
|
Owner, &ASGPawn::OnLeftMiddleFingertipGrabColliderOverlapEnds);
|
|
|
|
Owner->RightThumbFingertipGrabCollider->OnComponentBeginOverlap.RemoveDynamic(
|
|
Owner, &ASGPawn::OnRightThumbFingertipGrabColliderOverlapBegins);
|
|
Owner->RightThumbFingertipGrabCollider->OnComponentEndOverlap.RemoveDynamic(
|
|
Owner, &ASGPawn::OnRightThumbFingertipGrabColliderOverlapEnds);
|
|
|
|
Owner->RightIndexFingertipGrabCollider->OnComponentBeginOverlap.RemoveDynamic(
|
|
Owner, &ASGPawn::OnRightIndexFingertipGrabColliderOverlapBegins);
|
|
Owner->RightIndexFingertipGrabCollider->OnComponentEndOverlap.RemoveDynamic(
|
|
Owner, &ASGPawn::OnRightIndexFingertipGrabColliderOverlapEnds);
|
|
|
|
Owner->RightMiddleFingertipGrabCollider->OnComponentBeginOverlap.RemoveDynamic(
|
|
Owner, &ASGPawn::OnRightMiddleFingertipGrabColliderOverlapBegins);
|
|
Owner->RightMiddleFingertipGrabCollider->OnComponentEndOverlap.RemoveDynamic(
|
|
Owner, &ASGPawn::OnRightMiddleFingertipGrabColliderOverlapEnds);
|
|
}
|
|
|
|
void ASGPawn::FImpl::BindFingerTouchOverlapEvents()
|
|
{
|
|
Owner->LeftThumbFingertipTouchCollider->OnComponentBeginOverlap.AddDynamic(
|
|
Owner, &ASGPawn::OnLeftThumbFingertipTouchColliderOverlapBegins);
|
|
Owner->LeftThumbFingertipTouchCollider->OnComponentEndOverlap.AddDynamic(
|
|
Owner, &ASGPawn::OnLeftThumbFingertipTouchColliderOverlapEnds);
|
|
|
|
Owner->LeftIndexFingertipTouchCollider->OnComponentBeginOverlap.AddDynamic(
|
|
Owner, &ASGPawn::OnLeftIndexFingertipTouchColliderOverlapBegins);
|
|
Owner->LeftIndexFingertipTouchCollider->OnComponentEndOverlap.AddDynamic(
|
|
Owner, &ASGPawn::OnLeftIndexFingertipTouchColliderOverlapEnds);
|
|
|
|
Owner->LeftMiddleFingertipTouchCollider->OnComponentBeginOverlap.AddDynamic(
|
|
Owner, &ASGPawn::OnLeftMiddleFingertipTouchColliderOverlapBegins);
|
|
Owner->LeftMiddleFingertipTouchCollider->OnComponentEndOverlap.AddDynamic(
|
|
Owner, &ASGPawn::OnLeftMiddleFingertipTouchColliderOverlapEnds);
|
|
|
|
Owner->LeftRingFingertipTouchCollider->OnComponentBeginOverlap.AddDynamic(
|
|
Owner, &ASGPawn::OnLeftRingFingertipTouchColliderOverlapBegins);
|
|
Owner->LeftRingFingertipTouchCollider->OnComponentEndOverlap.AddDynamic(
|
|
Owner, &ASGPawn::OnLeftRingFingertipTouchColliderOverlapEnds);
|
|
|
|
Owner->LeftPinkyFingertipTouchCollider->OnComponentBeginOverlap.AddDynamic(
|
|
Owner, &ASGPawn::OnLeftPinkyFingertipTouchColliderOverlapBegins);
|
|
Owner->LeftPinkyFingertipTouchCollider->OnComponentEndOverlap.AddDynamic(
|
|
Owner, &ASGPawn::OnLeftPinkyFingertipTouchColliderOverlapEnds);
|
|
|
|
Owner->RightThumbFingertipTouchCollider->OnComponentBeginOverlap.AddDynamic(
|
|
Owner, &ASGPawn::OnRightThumbFingertipTouchColliderOverlapBegins);
|
|
Owner->RightThumbFingertipTouchCollider->OnComponentEndOverlap.AddDynamic(
|
|
Owner, &ASGPawn::OnRightThumbFingertipTouchColliderOverlapEnds);
|
|
|
|
Owner->RightIndexFingertipTouchCollider->OnComponentBeginOverlap.AddDynamic(
|
|
Owner, &ASGPawn::OnRightIndexFingertipTouchColliderOverlapBegins);
|
|
Owner->RightIndexFingertipTouchCollider->OnComponentEndOverlap.AddDynamic(
|
|
Owner, &ASGPawn::OnRightIndexFingertipTouchColliderOverlapEnds);
|
|
|
|
Owner->RightMiddleFingertipTouchCollider->OnComponentBeginOverlap.AddDynamic(
|
|
Owner, &ASGPawn::OnRightMiddleFingertipTouchColliderOverlapBegins);
|
|
Owner->RightMiddleFingertipTouchCollider->OnComponentEndOverlap.AddDynamic(
|
|
Owner, &ASGPawn::OnRightMiddleFingertipTouchColliderOverlapEnds);
|
|
|
|
Owner->RightRingFingertipTouchCollider->OnComponentBeginOverlap.AddDynamic(
|
|
Owner, &ASGPawn::OnRightRingFingertipTouchColliderOverlapBegins);
|
|
Owner->RightRingFingertipTouchCollider->OnComponentEndOverlap.AddDynamic(
|
|
Owner, &ASGPawn::OnRightRingFingertipTouchColliderOverlapEnds);
|
|
|
|
Owner->RightPinkyFingertipTouchCollider->OnComponentBeginOverlap.AddDynamic(
|
|
Owner, &ASGPawn::OnRightPinkyFingertipTouchColliderOverlapBegins);
|
|
Owner->RightPinkyFingertipTouchCollider->OnComponentEndOverlap.AddDynamic(
|
|
Owner, &ASGPawn::OnRightPinkyFingertipTouchColliderOverlapEnds);
|
|
}
|
|
|
|
void ASGPawn::FImpl::UnbindFingerTouchOverlapEvents()
|
|
{
|
|
Owner->LeftThumbFingertipTouchCollider->OnComponentBeginOverlap.RemoveDynamic(
|
|
Owner, &ASGPawn::OnLeftThumbFingertipTouchColliderOverlapBegins);
|
|
Owner->LeftThumbFingertipTouchCollider->OnComponentEndOverlap.RemoveDynamic(
|
|
Owner, &ASGPawn::OnLeftThumbFingertipTouchColliderOverlapEnds);
|
|
|
|
Owner->LeftIndexFingertipTouchCollider->OnComponentBeginOverlap.RemoveDynamic(
|
|
Owner, &ASGPawn::OnLeftIndexFingertipTouchColliderOverlapBegins);
|
|
Owner->LeftIndexFingertipTouchCollider->OnComponentEndOverlap.RemoveDynamic(
|
|
Owner, &ASGPawn::OnLeftIndexFingertipTouchColliderOverlapEnds);
|
|
|
|
Owner->LeftMiddleFingertipTouchCollider->OnComponentBeginOverlap.RemoveDynamic(
|
|
Owner, &ASGPawn::OnLeftMiddleFingertipTouchColliderOverlapBegins);
|
|
Owner->LeftMiddleFingertipTouchCollider->OnComponentEndOverlap.RemoveDynamic(
|
|
Owner, &ASGPawn::OnLeftMiddleFingertipTouchColliderOverlapEnds);
|
|
|
|
Owner->LeftRingFingertipTouchCollider->OnComponentBeginOverlap.RemoveDynamic(
|
|
Owner, &ASGPawn::OnLeftRingFingertipTouchColliderOverlapBegins);
|
|
Owner->LeftRingFingertipTouchCollider->OnComponentEndOverlap.RemoveDynamic(
|
|
Owner, &ASGPawn::OnLeftRingFingertipTouchColliderOverlapEnds);
|
|
|
|
Owner->LeftPinkyFingertipTouchCollider->OnComponentBeginOverlap.RemoveDynamic(
|
|
Owner, &ASGPawn::OnLeftPinkyFingertipTouchColliderOverlapBegins);
|
|
Owner->LeftPinkyFingertipTouchCollider->OnComponentEndOverlap.RemoveDynamic(
|
|
Owner, &ASGPawn::OnLeftPinkyFingertipTouchColliderOverlapEnds);
|
|
|
|
Owner->RightThumbFingertipGrabCollider->OnComponentBeginOverlap.RemoveDynamic(
|
|
Owner, &ASGPawn::OnRightThumbFingertipGrabColliderOverlapBegins);
|
|
Owner->RightThumbFingertipGrabCollider->OnComponentEndOverlap.RemoveDynamic(
|
|
Owner, &ASGPawn::OnRightThumbFingertipGrabColliderOverlapEnds);
|
|
|
|
Owner->RightIndexFingertipGrabCollider->OnComponentBeginOverlap.RemoveDynamic(
|
|
Owner, &ASGPawn::OnRightIndexFingertipGrabColliderOverlapBegins);
|
|
Owner->RightIndexFingertipGrabCollider->OnComponentEndOverlap.RemoveDynamic(
|
|
Owner, &ASGPawn::OnRightIndexFingertipGrabColliderOverlapEnds);
|
|
|
|
Owner->RightMiddleFingertipGrabCollider->OnComponentBeginOverlap.RemoveDynamic(
|
|
Owner, &ASGPawn::OnRightMiddleFingertipGrabColliderOverlapBegins);
|
|
Owner->RightMiddleFingertipGrabCollider->OnComponentEndOverlap.RemoveDynamic(
|
|
Owner, &ASGPawn::OnRightMiddleFingertipGrabColliderOverlapEnds);
|
|
|
|
Owner->RightThumbFingertipTouchCollider->OnComponentBeginOverlap.RemoveDynamic(
|
|
Owner, &ASGPawn::OnRightThumbFingertipTouchColliderOverlapBegins);
|
|
Owner->RightThumbFingertipTouchCollider->OnComponentEndOverlap.RemoveDynamic(
|
|
Owner, &ASGPawn::OnRightThumbFingertipTouchColliderOverlapEnds);
|
|
|
|
Owner->RightIndexFingertipTouchCollider->OnComponentBeginOverlap.RemoveDynamic(
|
|
Owner, &ASGPawn::OnRightIndexFingertipTouchColliderOverlapBegins);
|
|
Owner->RightIndexFingertipTouchCollider->OnComponentEndOverlap.RemoveDynamic(
|
|
Owner, &ASGPawn::OnRightIndexFingertipTouchColliderOverlapEnds);
|
|
|
|
Owner->RightMiddleFingertipTouchCollider->OnComponentBeginOverlap.RemoveDynamic(
|
|
Owner, &ASGPawn::OnRightMiddleFingertipTouchColliderOverlapBegins);
|
|
Owner->RightMiddleFingertipTouchCollider->OnComponentEndOverlap.RemoveDynamic(
|
|
Owner, &ASGPawn::OnRightMiddleFingertipTouchColliderOverlapEnds);
|
|
|
|
Owner->RightRingFingertipTouchCollider->OnComponentBeginOverlap.RemoveDynamic(
|
|
Owner, &ASGPawn::OnRightRingFingertipTouchColliderOverlapBegins);
|
|
Owner->RightRingFingertipTouchCollider->OnComponentEndOverlap.RemoveDynamic(
|
|
Owner, &ASGPawn::OnRightRingFingertipTouchColliderOverlapEnds);
|
|
|
|
Owner->RightPinkyFingertipTouchCollider->OnComponentBeginOverlap.RemoveDynamic(
|
|
Owner, &ASGPawn::OnRightPinkyFingertipTouchColliderOverlapBegins);
|
|
Owner->RightPinkyFingertipTouchCollider->OnComponentEndOverlap.RemoveDynamic(
|
|
Owner, &ASGPawn::OnRightPinkyFingertipTouchColliderOverlapEnds);
|
|
}
|
|
|
|
void ASGPawn::FImpl::DisableActorPhysics(const AActor* Actor) const
|
|
{
|
|
UPrimitiveComponent* ActorRootComponent{Cast<UPrimitiveComponent>(Actor->GetRootComponent())};
|
|
if (!ensureAlwaysMsgf(IsValid(ActorRootComponent), TEXT("RootComponent is not a valid UPrimativeComponent!")))
|
|
{
|
|
return;
|
|
}
|
|
|
|
ActorRootComponent->SetEnableGravity(false);
|
|
ActorRootComponent->SetSimulatePhysics(false);
|
|
ActorRootComponent->PutRigidBodyToSleep();
|
|
}
|
|
|
|
void ASGPawn::FImpl::EnableActorPhysics(const AActor* Actor) const
|
|
{
|
|
if (!IsValid(Actor))
|
|
{
|
|
return;
|
|
}
|
|
|
|
UPrimitiveComponent* ActorRootComponent{Cast<UPrimitiveComponent>(Actor->GetRootComponent())};
|
|
if (!ensureAlwaysMsgf(IsValid(ActorRootComponent), TEXT("RootComponent is not a valid UPrimativeComponent!")))
|
|
{
|
|
return;
|
|
}
|
|
|
|
ActorRootComponent->SetEnableGravity(true);
|
|
ActorRootComponent->SetSimulatePhysics(true);
|
|
ActorRootComponent->WakeRigidBody();
|
|
}
|
|
|
|
void ASGPawn::FImpl::ApplyHandVelocityToGrabbedActor(const FSGGrabState& GrabState) const
|
|
{
|
|
if (!IsValid(GrabState.Hand))
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (!IsValid(GrabState.GrabbedActor))
|
|
{
|
|
return;
|
|
}
|
|
|
|
UPrimitiveComponent* ActorRootComponent{Cast<UPrimitiveComponent>(GrabState.GrabbedActor->GetRootComponent())};
|
|
if (!ensureAlwaysMsgf(IsValid(ActorRootComponent), TEXT("RootComponent is not a valid UPrimativeComponent!")))
|
|
{
|
|
return;
|
|
}
|
|
|
|
FVector HandVelocity{UKismetMathLibrary::GetVectorArrayAverage(GrabState.HandVelocityHistory)};
|
|
|
|
ActorRootComponent->SetPhysicsLinearVelocity(HandVelocity);
|
|
ActorRootComponent->AddImpulse(MoveTemp(HandVelocity), NAME_None, true);
|
|
}
|
|
|
|
void ASGPawn::FImpl::SetGrabbedActor(FSGGrabState& GrabState, AActor* Actor) const
|
|
{
|
|
GrabState.GrabbedActor = Actor;
|
|
}
|
|
|
|
void ASGPawn::FImpl::SetLeftHandGrabbedActor(AActor* Actor) const
|
|
{
|
|
SetGrabbedActor(Owner->LeftHandGrabState, Actor);
|
|
}
|
|
|
|
void ASGPawn::FImpl::SetRightHandGrabbedActor(AActor* Actor) const
|
|
{
|
|
SetGrabbedActor(Owner->RightHandGrabState, Actor);
|
|
}
|
|
|
|
void ASGPawn::FImpl::RecordHandVelocity(FSGGrabState& GrabState, const float DeltaSeconds) const
|
|
{
|
|
if (!IsValid(GrabState.Hand))
|
|
{
|
|
return;
|
|
}
|
|
|
|
FVector HandVelocity{
|
|
(GrabState.Hand->GetComponentLocation() - GrabState.PreviousHandLocation) / DeltaSeconds
|
|
};
|
|
|
|
if (GrabState.HandVelocityHistory.Num() >= Owner->MaxNumberOfHandVelocitySamples)
|
|
{
|
|
if (GrabState.HandVelocityHistory.IsValidIndex(0))
|
|
{
|
|
GrabState.HandVelocityHistory.RemoveAt(0, 1, false);
|
|
GrabState.HandVelocityHistory.Emplace(MoveTemp(HandVelocity));
|
|
}
|
|
}
|
|
else
|
|
{
|
|
GrabState.HandVelocityHistory.Emplace(MoveTemp(HandVelocity));
|
|
}
|
|
|
|
GrabState.PreviousHandLocation = GrabState.Hand->GetComponentLocation();
|
|
}
|
|
|
|
void ASGPawn::FImpl::Release(FSGGrabState& GrabState) const
|
|
{
|
|
if (!IsValid(GrabState.GrabbedActor))
|
|
{
|
|
return;
|
|
}
|
|
|
|
const USGGrabComponent* GrabComponent{USGGrabComponent::GetGrabComponent(GrabState.GrabbedActor)};
|
|
if (!IsValid(GrabComponent))
|
|
{
|
|
return;
|
|
}
|
|
|
|
GrabState.GrabbedActor->DetachFromActor(
|
|
FDetachmentTransformRules(GrabComponent->GetDetachmentLocationRule(),
|
|
GrabComponent->GetDetachmentRotationRule(),
|
|
GrabComponent->GetDetachmentScaleRule(),
|
|
GrabComponent->GetDetachmentInCallModify())
|
|
);
|
|
|
|
if (GrabComponent->GetAffectPhysicsState())
|
|
{
|
|
EnableActorPhysics(GrabState.GrabbedActor);
|
|
}
|
|
|
|
ApplyHandVelocityToGrabbedActor(GrabState);
|
|
|
|
SetGrabbedActor(GrabState, nullptr);
|
|
}
|
|
|
|
ASGPawn::FImpl::~FImpl() = default;
|
|
|
|
void ASGPawn::FImplDeleter::operator()(const FImpl* P) const
|
|
{
|
|
delete P;
|
|
} |