Skip to content
Snippets Groups Projects
Commit 8c5ae66f authored by Timon Römer's avatar Timon Römer
Browse files

Integrates Enhaced Input into IntenSelect

parent 4082bf9c
No related branches found
No related tags found
2 merge requests!81Inten Select 5.3,!80UE5.3-2023.1-rc2
No preview for this file type
#include "Pawn/IntenSelectComponent.h" #include "Pawn/IntenSelectComponent.h"
#include "EnhancedInputSubsystems.h"
#include "Components/WidgetComponent.h" #include "Components/WidgetComponent.h"
#include "Interaction/Targetable.h" #include "Interaction/Targetable.h"
#include "Haptics/HapticFeedbackEffect_Curve.h" #include "Haptics/HapticFeedbackEffect_Curve.h"
...@@ -70,6 +71,15 @@ void UIntenSelectComponent::BeginPlay() ...@@ -70,6 +71,15 @@ void UIntenSelectComponent::BeginPlay()
} }
void UIntenSelectComponent::InitInputBindings(){ void UIntenSelectComponent::InitInputBindings(){
const APlayerController* PC = UGameplayStatics::GetPlayerController(GetWorld(), 0);
UEnhancedInputLocalPlayerSubsystem* Subsystem = ULocalPlayer::GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(PC->GetLocalPlayer());
// Clear out existing mapping, and add our mapping
Subsystem->ClearAllMappings();
Subsystem->AddMappingContext(InputMapping, 0);
// const auto InputComponent = GetOwner()->FindComponentByClass<UInputComponent>(); // const auto InputComponent = GetOwner()->FindComponentByClass<UInputComponent>();
// if(!InputComponent) // if(!InputComponent)
// { // {
...@@ -104,7 +114,7 @@ void UIntenSelectComponent::InitSplineComponent() ...@@ -104,7 +114,7 @@ void UIntenSelectComponent::InitSplineComponent()
const FString Message = "Error while spawning SplineComponent!"; const FString Message = "Error while spawning SplineComponent!";
#if WITH_EDITOR #if WITH_EDITOR
const FText Title = FText::FromString(FString("ERROR")); const FText Title = FText::FromString(FString("ERROR"));
FMessageDialog::Open(EAppMsgType::Ok, FText::FromString(Message), &Title); FMessageDialog::Open(EAppMsgType::Ok, FText::FromString(Message), Title);
#endif #endif
UE_LOG(LogTemp, Error, TEXT("%s"), *Message) UE_LOG(LogTemp, Error, TEXT("%s"), *Message)
......
// Fill out your copyright notice in the Description page of Project Settings. // Fill out your copyright notice in the Description page of Project Settings.
#pragma once #pragma once
#pragma region /** Includes */
#include "Kismet/KismetSystemLibrary.h" #include "Kismet/KismetSystemLibrary.h"
#include "Components/SplineComponent.h" #include "Components/SplineComponent.h"
#include "Components/SplineMeshComponent.h" #include "Components/SplineMeshComponent.h"
#include "CoreMinimal.h" #include "CoreMinimal.h"
#include "Kismet/GameplayStatics.h" #include "Kismet/GameplayStatics.h"
//#include "SteamVRInputDeviceFunctionLibrary.h"
#include "Components/WidgetInteractionComponent.h" #include "Components/WidgetInteractionComponent.h"
#include "Interaction/GrabbingBehaviorComponent.h" #include "Interaction/GrabbingBehaviorComponent.h"
#include "Interaction/IntenSelectable.h" #include "Interaction/IntenSelectable.h"
#include "IntenSelectComponent.generated.h" #include "IntenSelectComponent.generated.h"
#pragma endregion
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FOnNewComponent); DECLARE_DYNAMIC_MULTICAST_DELEGATE(FOnNewComponent);
...@@ -21,13 +22,14 @@ class RWTHVRTOOLKIT_API UIntenSelectComponent : public UWidgetInteractionCompone ...@@ -21,13 +22,14 @@ class RWTHVRTOOLKIT_API UIntenSelectComponent : public UWidgetInteractionCompone
GENERATED_BODY() GENERATED_BODY()
// VARIABLES
#pragma region /** INTERNAL VARIABLES */
private: private:
float SphereCastRadius; float SphereCastRadius;
float FeedbackCooldown; float FeedbackCooldown;
bool IsGrabbing; bool IsGrabbing;
bool IsWidgetInFocus; bool IsWidgetInFocus;
FVector WidgetFocusPoint; FVector WidgetFocusPoint;
UPROPERTY() UPROPERTY()
...@@ -60,11 +62,10 @@ private: ...@@ -60,11 +62,10 @@ private:
UMaterialInterface* DebugConeMaterial; UMaterialInterface* DebugConeMaterial;
UPROPERTY() UPROPERTY()
UStaticMesh* ForwardRayMesh; UStaticMesh* ForwardRayMesh;
#pragma endregion
#pragma region /** SETTINGS */
public: public:
// SETTINGS
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "IntenSelect|Settings") UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "IntenSelect|Settings")
bool SetActiveOnStart = true; bool SetActiveOnStart = true;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "IntenSelect|Settings") UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "IntenSelect|Settings")
...@@ -79,9 +80,10 @@ public: ...@@ -79,9 +80,10 @@ public:
float MaxClickStickAngle = 10; float MaxClickStickAngle = 10;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "IntenSelect|Settings") UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "IntenSelect|Settings")
float ForwardRayWidth = 0.01; float ForwardRayWidth = 0.01;
#pragma endregion
// REFERENCES #pragma region /** REFERENCES */
public:
UPROPERTY(EditAnywhere, Category= "IntenSelect|References") UPROPERTY(EditAnywhere, Category= "IntenSelect|References")
UStaticMesh* SplineMesh; UStaticMesh* SplineMesh;
UPROPERTY(EditAnywhere, Category = "IntenSelect|References") UPROPERTY(EditAnywhere, Category = "IntenSelect|References")
...@@ -96,73 +98,96 @@ public: ...@@ -96,73 +98,96 @@ public:
UMaterialParameterCollection* MaterialParamCollection; UMaterialParameterCollection* MaterialParamCollection;
UPROPERTY(EditAnywhere, Category = "IntenSelect|References") UPROPERTY(EditAnywhere, Category = "IntenSelect|References")
UCurveFloat* ForwardRayTransparencyCurve; UCurveFloat* ForwardRayTransparencyCurve;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "IntenSelect|References") #pragma endregion
TArray<AActor*> ActorsToIgnore;
// DEBUG VARIABLES
#pragma region /** DEBUG */
public:
UPROPERTY(EditAnywhere, Category = "IntenSelect|Debug")
bool bDrawDebugCone = false;
UPROPERTY(EditAnywhere, Category = "IntenSelect|Debug")
bool bDrawForwardRay = true;
UPROPERTY(EditAnywhere, Category = "IntenSelect|Debug") UPROPERTY(EditAnywhere, Category = "IntenSelect|Debug")
FRotator DebugConeRotation = FRotator(90, 0, 0); FRotator DebugConeRotation = FRotator(90, 0, 0);
UPROPERTY(EditAnywhere, Category = "IntenSelect|Debug") UPROPERTY(EditAnywhere, Category = "IntenSelect|Debug")
FVector DebugConeScale = FVector(1,1,1); FVector DebugConeScale = FVector(1,1,1);
UPROPERTY(EditAnywhere, Category = "IntenSelect|Debug") UPROPERTY(EditAnywhere, Category = "IntenSelect|Debug")
FVector DebugConePosition = FVector(-90, 0, 0); FVector DebugConePosition = FVector(-90, 0, 0);
UPROPERTY(EditAnywhere, Category = "IntenSelect|Debug")
bool bDrawDebugCone = false;
UPROPERTY(EditAnywhere, Category = "IntenSelect|Debug")
bool bDrawForwardRay = true;
UPROPERTY(EditAnywhere, Category = "IntenSelect|Debug") UPROPERTY(EditAnywhere, Category = "IntenSelect|Debug")
float DebugRayTransparency = 1; float DebugRayTransparency = 1;
#pragma endregion
// OTHER #pragma region /** Input */
protected:
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Enhanced Input")
class UInputMappingContext* InputMapping;
#pragma endregion
#pragma region /** EVENTS */
public:
UPROPERTY(BlueprintAssignable) UPROPERTY(BlueprintAssignable)
FOnNewComponent OnNewSelectedEvent; FOnNewComponent OnNewSelectedEvent;
#pragma endregion
private:
// INITIALIZATION // FUNCTIONS
#pragma region /** INITIALIZATION */
private:
void InitInputBindings(); void InitInputBindings();
void InitDebugConeMeshComponent(); void InitDebugConeMeshComponent();
void InitSplineMeshComponent(); void InitSplineMeshComponent();
void InitSplineComponent(); void InitSplineComponent();
void InitForwardRayMeshComponent(); void InitForwardRayMeshComponent();
void InitMaterialParamCollection(); void InitMaterialParamCollection();
#pragma endregion
// SCORING #pragma region /** SCORING */
private:
float CalculateSphereCastRadius() const; float CalculateSphereCastRadius() const;
bool GetActorsFromSphereCast(const FVector& SphereCastStart, TArray<FHitResult>& OutHits) const; bool GetActorsFromSphereCast(const FVector& SphereCastStart, TArray<FHitResult>& OutHits) const;
bool CheckPointInCone(const FVector ConeStartPoint, const FVector ConeForward, const FVector PointToTest, const float Angle) const; bool CheckPointInCone(const FVector ConeStartPoint, const FVector ConeForward, const FVector PointToTest, const float Angle) const;
UIntenSelectable* GetMaxScoreActor(const float DeltaTime); UIntenSelectable* GetMaxScoreActor(const float DeltaTime);
#pragma endregion
// VISUALS #pragma region /** VISUALS */
private:
void DrawSelectionCurve(const FVector& EndPoint) const; void DrawSelectionCurve(const FVector& EndPoint) const;
void AddSplinePointsDefault(const FVector& StartPoint, const FVector& Forward, const FVector& EndPoint) const; void AddSplinePointsDefault(const FVector& StartPoint, const FVector& Forward, const FVector& EndPoint) const;
void UpdateForwardRay(const FVector& ReferencePoint) const; void UpdateForwardRay(const FVector& ReferencePoint) const;
#pragma endregion
// RAYCASTING #pragma region /** RAYCASTING */
private:
void HandleWidgetInteraction(); void HandleWidgetInteraction();
TOptional<FHitResult> RaytraceForFirstHit(const FVector& Start, const FVector& End) const; TOptional<FHitResult> RaytraceForFirstHit(const FVector& Start, const FVector& End) const;
#pragma endregion
// INPUT-HANDLING #pragma region /** INPUT-HANDLING */
private:
UFUNCTION(BlueprintCallable) UFUNCTION(BlueprintCallable)
void OnFireDown(); void OnFireDown();
UFUNCTION(BlueprintCallable) UFUNCTION(BlueprintCallable)
void OnFireUp(); void OnFireUp();
#pragma endregion
// OTHER #pragma region /** OTHER */
private:
void HandleCooldown(const float DeltaTime); void HandleCooldown(const float DeltaTime);
void HandleGrabbing(const float DeltaTime) const; void HandleGrabbing(const float DeltaTime) const;
void HandleNoActorSelected(); void HandleNoActorSelected();
void HandleActorSelected(UIntenSelectable* NewSelection); void HandleActorSelected(UIntenSelectable* NewSelection);
FVector ConvertNetVector(FVector_NetQuantize v); FVector ConvertNetVector(FVector_NetQuantize v);
#pragma endregion
public: public:
UIntenSelectComponent(const FObjectInitializer& ObjectInitializer); UIntenSelectComponent(const FObjectInitializer& ObjectInitializer);
// SELECTION #pragma region /** SELECTION */
void SelectObject(UGrabbingBehaviorComponent* GrabbingBehaviourComponent, UIntenSelectable* SelectableComponent, AActor* SelectedBy); void SelectObject(UGrabbingBehaviorComponent* GrabbingBehaviourComponent, UIntenSelectable* SelectableComponent, AActor* SelectedBy);
void Unselect(); void Unselect();
#pragma endregion
virtual void SetActive(bool bNewActive, bool bReset) override; virtual void SetActive(bool bNewActive, bool bReset) override;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment