From 1f5262bb817cc5052830dcdf6dde67a9e08350d6 Mon Sep 17 00:00:00 2001 From: Mamadou Babaei Date: Mon, 13 Mar 2023 14:19:32 +0100 Subject: [PATCH] integrate the virtual hand into the sgpawn --- .../SenseGlove/GameFramework/SGPawn.cpp | 35 +++++++++++++++++-- .../GameFramework/SGPlayerController.cpp | 5 +++ .../Public/SenseGlove/GameFramework/SGPawn.h | 28 ++++++++++----- .../GameFramework/SGPlayerController.h | 5 ++- .../Private/SGKismet/SGPawnKismetLibrary.cpp | 33 ++++++++++++++++- .../Public/SGKismet/SGPawnKismetLibrary.h | 22 +++++++++--- .../SGVirtualHandActorKismetLibrary.h | 3 -- .../SGVirtualHandComponentKismetLibrary.h | 3 -- .../SenseGloveKismet.Build.cs | 1 + 9 files changed, 111 insertions(+), 24 deletions(-) diff --git a/Source/SenseGlove/Private/SenseGlove/GameFramework/SGPawn.cpp b/Source/SenseGlove/Private/SenseGlove/GameFramework/SGPawn.cpp index 04d0a872..846c364a 100644 --- a/Source/SenseGlove/Private/SenseGlove/GameFramework/SGPawn.cpp +++ b/Source/SenseGlove/Private/SenseGlove/GameFramework/SGPawn.cpp @@ -35,9 +35,10 @@ #include "SenseGlove/GameFramework/SGPawn.h" -#include "Components/ActorComponent.h" +#include "Camera/CameraComponent.h" +#include "MotionControllerComponent.h" -#include "SenseGlove/GameFramework/SGPawn.h" +#include "SenseGlove/Components/SGVirtualHandComponent.h" struct ASGPawn::FImpl { @@ -76,8 +77,36 @@ ASGPawn::ASGPawn(const FObjectInitializer& ObjectInitializer) { PrimaryActorTick.bCanEverTick = true; - SceneRoot = CreateDefaultSubobject(TEXT("SceneRoot")); + SceneRoot = ObjectInitializer.CreateDefaultSubobject(this, TEXT("SceneRoot")); SetRootComponent(SceneRoot); + + Camera = ObjectInitializer.CreateDefaultSubobject(this, TEXT("Camera")); + Camera->SetupAttachment(GetRootComponent()); + Camera->SetCanEverAffectNavigation(false); + + MotionControllerLeft = ObjectInitializer.CreateDefaultSubobject( + this, TEXT("MotionControllerLeft")); + MotionControllerLeft->SetupAttachment(GetRootComponent()); + MotionControllerLeft->SetCanEverAffectNavigation(false); + MotionControllerLeft->SetWorldLocation(FVector{30.0f, -20.0f, -10.0f}, + false, nullptr, ETeleportType::None); + + HandLeft = ObjectInitializer.CreateDefaultSubobject(this, TEXT("HandLeft")); + HandLeft->SetupAttachment(MotionControllerLeft); + HandLeft->SetCanEverAffectNavigation(false); + HandLeft->SetRight(false); + + MotionControllerRight = ObjectInitializer.CreateDefaultSubobject( + this, TEXT("MotionControllerRight")); + MotionControllerRight->SetupAttachment(GetRootComponent()); + MotionControllerRight->SetCanEverAffectNavigation(false); + MotionControllerRight->SetWorldLocation(FVector{30.0f, 20.0f, -10.0f}, + false, nullptr, ETeleportType::None); + + HandRight = ObjectInitializer.CreateDefaultSubobject(this, TEXT("HandRight")); + HandRight->SetupAttachment(MotionControllerRight); + HandRight->SetCanEverAffectNavigation(false); + HandRight->SetRight(true); } ASGPawn::FImpl::FImpl(ASGPawn* InOwner) diff --git a/Source/SenseGlove/Private/SenseGlove/GameFramework/SGPlayerController.cpp b/Source/SenseGlove/Private/SenseGlove/GameFramework/SGPlayerController.cpp index 4d1f29d6..727ad2d0 100644 --- a/Source/SenseGlove/Private/SenseGlove/GameFramework/SGPlayerController.cpp +++ b/Source/SenseGlove/Private/SenseGlove/GameFramework/SGPlayerController.cpp @@ -38,4 +38,9 @@ ASGPlayerController::ASGPlayerController(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer) { +} + +void ASGPlayerController::SetupInputComponent() +{ + Super::SetupInputComponent(); } \ No newline at end of file diff --git a/Source/SenseGlove/Public/SenseGlove/GameFramework/SGPawn.h b/Source/SenseGlove/Public/SenseGlove/GameFramework/SGPawn.h index d8076f26..23cbef38 100644 --- a/Source/SenseGlove/Public/SenseGlove/GameFramework/SGPawn.h +++ b/Source/SenseGlove/Public/SenseGlove/GameFramework/SGPawn.h @@ -40,13 +40,15 @@ #include "SGPawn.generated.h" -class UActorComponent; +class UCameraComponent; class UMotionControllerComponent; +class USGVirtualHandComponent; + UCLASS(Config=Game, BlueprintType, Blueprintable) class SENSEGLOVE_API ASGPawn : public APawn { - GENERATED_UCLASS_BODY() + GENERATED_UCLASS_BODY() private: struct FImpl; @@ -63,6 +65,9 @@ private: UPROPERTY(VisibleAnywhere, Category="SenseGlove", meta=(AllowPrivateAccess="false")) USceneComponent* SceneRoot; + UPROPERTY(VisibleAnywhere, Category="SenseGlove", meta=(AllowPrivateAccess="false")) + UCameraComponent* Camera; + UPROPERTY(VisibleAnywhere, Category="SenseGlove", meta=(AllowPrivateAccess="false")) UMotionControllerComponent* MotionControllerLeft; @@ -70,28 +75,33 @@ private: UMotionControllerComponent* MotionControllerRight; UPROPERTY(VisibleAnywhere, Category="SenseGlove", meta=(AllowPrivateAccess="false")) - UActorComponent* HandLeft; + USGVirtualHandComponent* HandLeft; UPROPERTY(VisibleAnywhere, Category="SenseGlove", meta=(AllowPrivateAccess="false")) - UActorComponent* HandRight; + USGVirtualHandComponent* HandRight; -protected: - FORCEINLINE UMotionControllerComponent* GetMotionContollerLeft() const +public: + FORCEINLINE UCameraComponent* GetCamera() const + { + return Camera; + } + + FORCEINLINE UMotionControllerComponent* GetMotionControllerLeft() const { return MotionControllerLeft; } - FORCEINLINE UMotionControllerComponent* GetMotionContollerRight() const + FORCEINLINE UMotionControllerComponent* GetMotionControllerRight() const { return MotionControllerRight; } - FORCEINLINE UActorComponent* GetHandLeft() const + FORCEINLINE USGVirtualHandComponent* GetHandLeft() const { return HandLeft; } - FORCEINLINE UActorComponent* GetHandRight() const + FORCEINLINE USGVirtualHandComponent* GetHandRight() const { return HandRight; } diff --git a/Source/SenseGlove/Public/SenseGlove/GameFramework/SGPlayerController.h b/Source/SenseGlove/Public/SenseGlove/GameFramework/SGPlayerController.h index 7c484c7b..bd24cd2a 100644 --- a/Source/SenseGlove/Public/SenseGlove/GameFramework/SGPlayerController.h +++ b/Source/SenseGlove/Public/SenseGlove/GameFramework/SGPlayerController.h @@ -42,5 +42,8 @@ UCLASS(Config=Game, BlueprintType, Blueprintable) class SENSEGLOVE_API ASGPlayerController : public APlayerController { - GENERATED_UCLASS_BODY() + GENERATED_UCLASS_BODY() + +protected: + virtual void SetupInputComponent() override; }; \ No newline at end of file diff --git a/Source/SenseGloveKismet/Private/SGKismet/SGPawnKismetLibrary.cpp b/Source/SenseGloveKismet/Private/SGKismet/SGPawnKismetLibrary.cpp index 2d735e56..6b2099b4 100644 --- a/Source/SenseGloveKismet/Private/SGKismet/SGPawnKismetLibrary.cpp +++ b/Source/SenseGloveKismet/Private/SGKismet/SGPawnKismetLibrary.cpp @@ -33,4 +33,35 @@ */ -#include "SGKismet/SGPawnKismetLibrary.h" \ No newline at end of file +#include "SGKismet/SGPawnKismetLibrary.h" + +#include "Camera/CameraComponent.h" +#include "MotionControllerComponent.h" + +#include "SenseGlove/Components/SGVirtualHandComponent.h" +#include "SenseGlove/GameFramework/SGPawn.h" + +UCameraComponent* UPawnKismetLibrary::GetCamera(const ASGPawn* Pawn) +{ + return Pawn->GetCamera(); +} + +UMotionControllerComponent* UPawnKismetLibrary::GetMotionControllerLeft(const ASGPawn* Pawn) +{ + return Pawn->GetMotionControllerLeft(); +} + +UMotionControllerComponent* UPawnKismetLibrary::GetMotionControllerRight(const ASGPawn* Pawn) +{ + return Pawn->GetMotionControllerRight(); +} + +USGVirtualHandComponent* UPawnKismetLibrary::GetHandLeft(const ASGPawn* Pawn) +{ + return Pawn->GetHandLeft(); +} + +USGVirtualHandComponent* UPawnKismetLibrary::GetHandRight(const ASGPawn* Pawn) +{ + return Pawn->GetHandRight(); +} \ No newline at end of file diff --git a/Source/SenseGloveKismet/Public/SGKismet/SGPawnKismetLibrary.h b/Source/SenseGloveKismet/Public/SGKismet/SGPawnKismetLibrary.h index b9b8aabc..090e0746 100644 --- a/Source/SenseGloveKismet/Public/SGKismet/SGPawnKismetLibrary.h +++ b/Source/SenseGloveKismet/Public/SGKismet/SGPawnKismetLibrary.h @@ -49,16 +49,30 @@ #include "SGPawnKismetLibrary.generated.h" +class UCameraComponent; +class UMotionControllerComponent; + class ASGPawn; -class ASGVirtualHand; +class USGVirtualHandComponent; -/** - * Represents data of a user's hand required for forward kinematics. - */ UCLASS(meta=(ScriptName = "SesneGlovePawnKismetLibrary")) class SENSEGLOVEKISMET_API UPawnKismetLibrary final : public USGBlueprintFunctionLibrary { GENERATED_BODY() public: + UFUNCTION(BlueprintPure, Category="SenseGlove | Game Framework | Pawn") + static UCameraComponent* GetCamera(const ASGPawn* Pawn); + + UFUNCTION(BlueprintPure, Category="SenseGlove | Game Framework | Pawn") + static UMotionControllerComponent* GetMotionControllerLeft(const ASGPawn* Pawn); + + UFUNCTION(BlueprintPure, Category="SenseGlove | Game Framework | Pawn") + static UMotionControllerComponent* GetMotionControllerRight(const ASGPawn* Pawn); + + UFUNCTION(BlueprintPure, Category="SenseGlove | Game Framework | Pawn") + static USGVirtualHandComponent* GetHandLeft(const ASGPawn* Pawn); + + UFUNCTION(BlueprintPure, Category="SenseGlove | Game Framework | Pawn") + static USGVirtualHandComponent* GetHandRight(const ASGPawn* Pawn); }; \ No newline at end of file diff --git a/Source/SenseGloveKismet/Public/SGKismet/SGVirtualHandActorKismetLibrary.h b/Source/SenseGloveKismet/Public/SGKismet/SGVirtualHandActorKismetLibrary.h index e87184f0..b9515cf6 100644 --- a/Source/SenseGloveKismet/Public/SGKismet/SGVirtualHandActorKismetLibrary.h +++ b/Source/SenseGloveKismet/Public/SGKismet/SGVirtualHandActorKismetLibrary.h @@ -44,9 +44,6 @@ class ASGVirtualHandActor; class USGVirtualHandComponent; -/** - * Represents data of a user's hand required for forward kinematics. - */ UCLASS(meta=(ScriptName = "SesneGloveVirtualHandActorKismetLibrary")) class SENSEGLOVEKISMET_API UVirtualHandActorKismetLibrary final : public USGBlueprintFunctionLibrary { diff --git a/Source/SenseGloveKismet/Public/SGKismet/SGVirtualHandComponentKismetLibrary.h b/Source/SenseGloveKismet/Public/SGKismet/SGVirtualHandComponentKismetLibrary.h index 98f77d0f..8d989f27 100644 --- a/Source/SenseGloveKismet/Public/SGKismet/SGVirtualHandComponentKismetLibrary.h +++ b/Source/SenseGloveKismet/Public/SGKismet/SGVirtualHandComponentKismetLibrary.h @@ -53,9 +53,6 @@ class USkeletalMeshComponent; class USGVirtualHandComponent; class USGHandPose; -/** - * Represents data of a user's hand required for forward kinematics. - */ UCLASS(meta=(ScriptName = "SesneGloveVirtualHandComponentKismetLibrary")) class SENSEGLOVEKISMET_API UVirtualHandComponentKismetLibrary final : public USGBlueprintFunctionLibrary { diff --git a/Source/SenseGloveKismet/SenseGloveKismet.Build.cs b/Source/SenseGloveKismet/SenseGloveKismet.Build.cs index 89d7e64c..e1507235 100644 --- a/Source/SenseGloveKismet/SenseGloveKismet.Build.cs +++ b/Source/SenseGloveKismet/SenseGloveKismet.Build.cs @@ -54,6 +54,7 @@ public class SenseGloveKismet : ModuleRules { "CoreUObject", "Engine", + "HeadMountedDisplay", "SenseGlove", "SenseGloveCore", "SenseGloveLog",