From 8313c578250954afa7a062557a45bafa7d5f5a39 Mon Sep 17 00:00:00 2001 From: MostExcellent Date: Sun, 20 Oct 2024 17:07:50 -0700 Subject: [PATCH] VRInputConfig and start of VRUtils done --- .gitignore | 38 +++++++++---- Config/DefaultGame.ini | 2 +- .../VRGAS/Private/Input/VRInputComponent.cpp | 5 ++ .../VRGAS/Private/Input/VRInputConfig.cpp | 45 +++++++++++++++ .../VRGAS/Public/Input/VRInputComponent.h | 15 +++++ .../Source/VRGAS/Public/Input/VRInputConfig.h | 49 ++++++++++++++++ .../VRUtils/Private/VRUtilsBPLibrary.cpp | 49 ++++++++++++++-- .../Source/VRUtils/Public/VRUtilsBPLibrary.h | 57 ++++++++++++------- VRPlugins.uproject | 4 ++ 9 files changed, 229 insertions(+), 35 deletions(-) create mode 100644 Plugins/VRGAS/Source/VRGAS/Private/Input/VRInputComponent.cpp create mode 100644 Plugins/VRGAS/Source/VRGAS/Private/Input/VRInputConfig.cpp create mode 100644 Plugins/VRGAS/Source/VRGAS/Public/Input/VRInputComponent.h create mode 100644 Plugins/VRGAS/Source/VRGAS/Public/Input/VRInputConfig.h diff --git a/.gitignore b/.gitignore index c351b53..67b5989 100644 --- a/.gitignore +++ b/.gitignore @@ -2,17 +2,6 @@ # Visual Studio 2015 user specific files .vs/ -#Jetbrains IDE files -.idea/ -.fleet/ -*.DotSettings - -# VS Code files -.vscode/ -*.code-workspace - -# Linux Makefile -Makefile # Compiled Object files *.slo @@ -86,3 +75,30 @@ Plugins/*/Intermediate/* # Cache files for the editor to use DerivedDataCache/* +# Visual Studio 2015+ user-specific files +.vs/ +.vsconfig +*.user +*.userosscache +*.VC.opendb + +# Don't ignore whitelist PakBlacklist-.txt files +!Build/*/ +Build/*/** +!Build/*/PakBlacklist*.txt + +# Don't ignore icon files in Build +!Build/**/*.ico + + +#Files Ignored +Makefile.bin +Makefile +*.directory +.idea/* +.vscode/* +*.code-workspace +*.opendb +*.DotSettings +.fleet/ +Cooked/* \ No newline at end of file diff --git a/Config/DefaultGame.ini b/Config/DefaultGame.ini index c3e48be..9c5b8dc 100644 --- a/Config/DefaultGame.ini +++ b/Config/DefaultGame.ini @@ -1,5 +1,5 @@ [/Script/EngineSettings.GeneralProjectSettings] ProjectID=B0DD2F214F0AC320FA72EB9C9432375E -CopyrightNotice=Copyright Vagabond Rose Interactive, all rights reserved +CopyrightNotice=Copyright diff --git a/Plugins/VRGAS/Source/VRGAS/Private/Input/VRInputComponent.cpp b/Plugins/VRGAS/Source/VRGAS/Private/Input/VRInputComponent.cpp new file mode 100644 index 0000000..2b885fb --- /dev/null +++ b/Plugins/VRGAS/Source/VRGAS/Private/Input/VRInputComponent.cpp @@ -0,0 +1,5 @@ +// Copyright + + +#include "Input/VRInputComponent.h" + diff --git a/Plugins/VRGAS/Source/VRGAS/Private/Input/VRInputConfig.cpp b/Plugins/VRGAS/Source/VRGAS/Private/Input/VRInputConfig.cpp new file mode 100644 index 0000000..e56ec5f --- /dev/null +++ b/Plugins/VRGAS/Source/VRGAS/Private/Input/VRInputConfig.cpp @@ -0,0 +1,45 @@ +// Copyright + + +#include "Input/VRInputConfig.h" + +UInputAction* UVRInputConfig::FindNativeInputActionForTag(const FGameplayTag& InTag, bool bLogNotFound) const +{ + if (!InTag.IsValid()) return nullptr; + + for (const FVRTagInputAction& Action : NativeInputActions) + { + if (!Action.IsValid()) continue; + + if (Action.InputAction && Action.InputTag.IsValid()) + { + return Action.InputAction.Get(); + } + } + + if (bLogNotFound) + { + // TODO: Add logging for VRGAS + } + + return nullptr; +} +UInputAction* UVRInputConfig::FindAbilityInputActionForTag(const FGameplayTag& InTag, bool bLogNotFound) const +{ + if (!InTag.IsValid()) return nullptr; + + for (const FVRTagInputAction& Action : AbilityInputActions) + { + if (!Action.IsValid() && Action.InputTag.IsValid()) + { + return Action.InputAction.Get(); + } + } + + if (bLogNotFound) + { + // TODO: Add logging for VRGAS + } + + return nullptr; +} diff --git a/Plugins/VRGAS/Source/VRGAS/Public/Input/VRInputComponent.h b/Plugins/VRGAS/Source/VRGAS/Public/Input/VRInputComponent.h new file mode 100644 index 0000000..6ebffc0 --- /dev/null +++ b/Plugins/VRGAS/Source/VRGAS/Public/Input/VRInputComponent.h @@ -0,0 +1,15 @@ +// Copyright + +#pragma once + +#include "CoreMinimal.h" +#include "EnhancedInputComponent.h" +#include "VRInputComponent.generated.h" + + +UCLASS() +class VRGAS_API UVRInputComponent : public UEnhancedInputComponent +{ + GENERATED_BODY() + +}; diff --git a/Plugins/VRGAS/Source/VRGAS/Public/Input/VRInputConfig.h b/Plugins/VRGAS/Source/VRGAS/Public/Input/VRInputConfig.h new file mode 100644 index 0000000..691ca53 --- /dev/null +++ b/Plugins/VRGAS/Source/VRGAS/Public/Input/VRInputConfig.h @@ -0,0 +1,49 @@ +// Copyright + +#pragma once + +#include "CoreMinimal.h" +#include "GameplayTagContainer.h" +#include "Engine/DataAsset.h" +#include "VRInputConfig.generated.h" + + +class UInputAction; + +USTRUCT(BlueprintType) +struct FVRTagInputAction +{ + GENERATED_BODY() + + UPROPERTY(EditDefaultsOnly, BlueprintReadOnly) + TObjectPtr InputAction = nullptr; + + UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Meta = (Categories = "InputTag")) + FGameplayTag InputTag; + + bool IsValid() const + { + return InputTag.IsValid() && InputAction != nullptr; + } +}; +/** + * + */ +UCLASS(BlueprintType, Const) // Const for now, since we aren't doing anything beyond what lyra does here +class VRGAS_API UVRInputConfig : public UDataAsset +{ + GENERATED_BODY() + +public: + UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Meta = (TitleProperty = "InputAction")) + TArray NativeInputActions; + + UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Meta = (TitleProperty = "InputAction")) + TArray AbilityInputActions; + + UFUNCTION(BlueprintCallable, Category = "Input") + UInputAction* FindNativeInputActionForTag(const FGameplayTag& InTag, bool bLogNotFound = true) const; + + UFUNCTION(BlueprintCallable, Category = "Input") + UInputAction* FindAbilityInputActionForTag(const FGameplayTag& InTag, bool bLogNotFound = true) const; +}; diff --git a/Plugins/VRUtils/Source/VRUtils/Private/VRUtilsBPLibrary.cpp b/Plugins/VRUtils/Source/VRUtils/Private/VRUtilsBPLibrary.cpp index c3dca67..93f8a94 100644 --- a/Plugins/VRUtils/Source/VRUtils/Private/VRUtilsBPLibrary.cpp +++ b/Plugins/VRUtils/Source/VRUtils/Private/VRUtilsBPLibrary.cpp @@ -1,10 +1,51 @@ -// Copyright Epic Games, Inc. All Rights Reserved. +// Copyright #include "VRUtilsBPLibrary.h" #include "VRUtils.h" -UVRUtilsBPLibrary::UVRUtilsBPLibrary(const FObjectInitializer& ObjectInitializer) -: Super(ObjectInitializer) +float UVRUtilsBPLibrary::GetPawnSpeedAlongVector(const APawn* InPawn, const FVector& InVector) { + if (!InPawn) return 0.0f; -} \ No newline at end of file + const FVector Velocity = InPawn->GetVelocity(); + const FVector InVectorNormalized = InVector.GetSafeNormal(); + + return FVector::DotProduct(Velocity, InVectorNormalized); +} + +// The following speed functions do not use GetPawnSpeedAlongVector to avoid one extra copy +float UVRUtilsBPLibrary::GetPawnForwardVectorSpeed(const APawn* InPawn) +{ + if (!InPawn) return 0.0f; + + const FVector Velocity = InPawn->GetVelocity(); + const FVector ForwardVector = InPawn->GetActorForwardVector(); + + return FVector::DotProduct(Velocity, ForwardVector); +} + +float UVRUtilsBPLibrary::GetPawnRightVectorSpeed(const APawn* InPawn) +{ + if (!InPawn) return 0.0f; + + const FVector Velocity = InPawn->GetVelocity(); + const FVector RightVector = InPawn->GetActorRightVector(); + + return FVector::DotProduct(Velocity, RightVector); +} + +float UVRUtilsBPLibrary::GetPawnUpVectorSpeed(const APawn* InPawn) +{ + if (!InPawn) return 0.0f; + + const FVector Velocity = InPawn->GetVelocity(); + const FVector UpVector = InPawn->GetActorUpVector(); + + return FVector::DotProduct(Velocity, UpVector); +} + +float UVRUtilsBPLibrary::GetDegreeDiff(const FVector& A, const FVector& B) +{ + const float DotResult = FVector::DotProduct(A, B); + return FMath::RadiansToDegrees(FMath::Acos(DotResult)); +} diff --git a/Plugins/VRUtils/Source/VRUtils/Public/VRUtilsBPLibrary.h b/Plugins/VRUtils/Source/VRUtils/Public/VRUtilsBPLibrary.h index 2860b5f..fe400b5 100644 --- a/Plugins/VRUtils/Source/VRUtils/Public/VRUtilsBPLibrary.h +++ b/Plugins/VRUtils/Source/VRUtils/Public/VRUtilsBPLibrary.h @@ -1,30 +1,49 @@ -// Copyright Epic Games, Inc. All Rights Reserved. +// Copyright #pragma once #include "Kismet/BlueprintFunctionLibrary.h" #include "VRUtilsBPLibrary.generated.h" -/* -* Function library class. -* Each function in it is expected to be static and represents blueprint node that can be called in any blueprint. -* -* When declaring function you can define metadata for the node. Key function specifiers will be BlueprintPure and BlueprintCallable. -* BlueprintPure - means the function does not affect the owning object in any way and thus creates a node without Exec pins. -* BlueprintCallable - makes a function which can be executed in Blueprints - Thus it has Exec pins. -* DisplayName - full name of the node, shown when you mouse over the node and in the blueprint drop down menu. -* Its lets you name the node using characters not allowed in C++ function names. -* CompactNodeTitle - the word(s) that appear on the node. -* Keywords - the list of keywords that helps you to find node when you search for it using Blueprint drop-down menu. -* Good example is "Print String" node which you can find also by using keyword "log". -* Category - the category your node will be under in the Blueprint drop-down menu. -* -* For more info on custom blueprint nodes visit documentation: -* https://wiki.unrealengine.com/Custom_Blueprint_Node_Creation -*/ +/** + * Vagabond Rose core utility functions, exposed to blueprints. + */ UCLASS() class UVRUtilsBPLibrary : public UBlueprintFunctionLibrary { - GENERATED_UCLASS_BODY() + GENERATED_BODY() +public: + #pragma region MovementSpeeds + /** + * Computes the pawn's speed along a given vector. + * + * @param InPawn The pawn whose speed is being measured. If null, the function returns 0. + * @param InVector The vector along which the speed is to be measured. + * @return The speed of the pawn along the provided vector. + */ + UFUNCTION(BlueprintPure, Category = "VRUtils|Movement|Speed") + static float GetPawnSpeedAlongVector(const APawn* InPawn, UPARAM(ref) const FVector& InVector); + + UFUNCTION(BlueprintPure, Category = "VRUtils|Movement|Speed") + static float GetPawnForwardVectorSpeed(const APawn* InPawn); + + UFUNCTION(BlueprintPure, Category = "VRUtils|Movement|Speed") + static float GetPawnRightVectorSpeed(const APawn* InPawn); + + UFUNCTION(BlueprintPure, Category = "VRUtils|Movement|Speed") + static float GetPawnUpVectorSpeed(const APawn* InPawn); + #pragma endregion + + #pragma region Math + /** + * Calculates the angular difference in degrees between two vectors. + * + * @param A The first vector. + * @param B The second vector. + * @return The angular difference between the two vectors in degrees. + */ + UFUNCTION(BlueprintPure, Category = "VRUtils|Math") + static float GetDegreeDiff(const FVector& A, const FVector& B); + #pragma endregion }; diff --git a/VRPlugins.uproject b/VRPlugins.uproject index 51dcede..5bf7812 100644 --- a/VRPlugins.uproject +++ b/VRPlugins.uproject @@ -18,6 +18,10 @@ "Editor" ] }, + { + "Name": "GameplayAbilities", + "Enabled": true + }, { "Name": "VRGAS", "Enabled": true