From 62366312fc2ea3746bc8d17b4b8f922d4fc48dda Mon Sep 17 00:00:00 2001 From: David Gilbert <gilbert@vr.rwth-aachen.de> Date: Fri, 27 Oct 2023 15:47:34 +0200 Subject: [PATCH 1/3] Huge reformatting / cosmetic fixes commit. --- .../Private/CAVEOverlay/CAVEOverlay.cpp | 5 +- .../CAVEOverlay/CAVEOverlayController.cpp | 69 ++++++---- .../RWTHVRCluster/Private/ClusterConsole.cpp | 50 +++---- .../RWTHVRCluster/Private/RWTHVRCluster.cpp | 3 +- .../CAVEOverlay/CAVEOverlayController.h | 4 +- Source/RWTHVRCluster/Public/ClusterConsole.h | 2 +- .../Fixes/ActivateConsoleInShipping.cpp | 12 +- .../Private/Interaction/ClickBehaviour.cpp | 8 +- .../Private/Interaction/Clickable.cpp | 8 -- .../Private/Interaction/GrabComponent.cpp | 68 ++++------ .../Private/Interaction/Grabable.cpp | 10 -- .../Interaction/GrabbingBehaviorComponent.cpp | 36 ++--- .../GrabbingBehaviorOnLineComponent.cpp | 56 +++----- .../GrabbingBehaviorOnPlaneComponent.cpp | 43 +----- .../Private/Interaction/HoverBehaviour.cpp | 21 --- .../Private/Interaction/InteractableBase.cpp | 24 +--- .../Interaction/OnClickGrabBehavior.cpp | 71 +++------- .../Interaction/RaycastSelectionComponent.cpp | 89 ++++++------ .../Private/Interaction/Targetable.cpp | 8 -- .../Pawn/BasicVRInteractionComponent.cpp | 1 - .../Pawn/ContinuousMovementComponent.cpp | 4 +- .../Private/Pawn/InputExtensionInterface.cpp | 2 +- .../Private/Pawn/MovementComponentBase.cpp | 6 +- .../Private/Pawn/MovementComponentBase.h | 18 +-- .../Pawn/ReplicatedCameraComponent.cpp | 16 +-- .../ReplicatedMotionControllerComponent.cpp | 19 +-- .../Private/Pawn/TeleportationComponent.cpp | 43 +++--- .../Private/Pawn/VRPawnMovement.cpp | 80 ++++++----- .../RWTHVRToolkit/Private/RWTHVRToolkit.cpp | 11 +- .../Private/UI/ExternalImage.cpp | 128 +++++++++--------- .../Utility/VirtualRealityUtilities.cpp | 65 +++++---- .../Public/Core/ClientTransformReplication.h | 10 +- .../Public/Core/RWTHVRGameModeBase.h | 2 +- .../Public/Core/RWTHVRPlayerState.h | 5 +- .../Public/Fixes/ActivateConsoleInShipping.h | 2 +- .../Fixes/LiveLinkMotionControllerFix.h | 67 ++++++--- .../Public/Interaction/ClickBehaviour.h | 27 ++-- .../Public/Interaction/Clickable.h | 5 +- .../Public/Interaction/GrabComponent.h | 27 ++-- .../Public/Interaction/Grabable.h | 6 +- .../Public/Interaction/GrabbableComponent.h | 3 +- .../Interaction/GrabbingBehaviorComponent.h | 14 +- .../GrabbingBehaviorOnLineComponent.h | 32 +++-- .../GrabbingBehaviorOnPlaneComponent.h | 11 -- .../Public/Interaction/HoverBehaviour.h | 3 - .../Public/Interaction/InteractableBase.h | 26 ++-- .../Public/Interaction/OnClickGrabBehavior.h | 20 +-- .../Public/Interaction/RaycastSelectable.h | 3 +- .../Interaction/RaycastSelectionComponent.h | 29 ++-- .../Public/Interaction/Targetable.h | 8 +- .../Public/Pawn/BasicVRInteractionComponent.h | 47 ++++--- .../Public/Pawn/ContinuousMovementComponent.h | 19 ++- .../Public/Pawn/InputExtensionInterface.h | 2 +- .../Public/Pawn/ReplicatedCameraComponent.h | 13 +- .../ReplicatedMotionControllerComponent.h | 11 +- .../Public/Pawn/TeleportationComponent.h | 3 +- .../Public/Pawn/VRPawnInputConfig.h | 10 +- .../Public/Pawn/VRPawnMovement.h | 14 +- Source/RWTHVRToolkit/Public/RWTHVRToolkit.h | 4 +- .../RWTHVRToolkit/Public/UI/ExternalImage.h | 21 +-- .../RWTHVRToolkit/Public/Utility/DemoConfig.h | 29 ++-- .../Public/Utility/VirtualRealityUtilities.h | 65 +++++---- .../GrabbingBehaviorOnLineVisualizer.cpp | 8 +- .../GrabbingBehaviorPlaneVisualizer.cpp | 11 +- .../Private/RWTHVRToolkitEditor.cpp | 29 ++-- .../GrabbingBehaviorOnLineVisualizer.h | 7 +- .../GrabbingBehaviorPlaneVisualizer.h | 3 +- .../Public/RWTHVRToolkitEditor.h | 3 +- 68 files changed, 720 insertions(+), 859 deletions(-) delete mode 100644 Source/RWTHVRToolkit/Private/Interaction/Clickable.cpp delete mode 100644 Source/RWTHVRToolkit/Private/Interaction/Grabable.cpp delete mode 100644 Source/RWTHVRToolkit/Private/Interaction/Targetable.cpp diff --git a/Source/RWTHVRCluster/Private/CAVEOverlay/CAVEOverlay.cpp b/Source/RWTHVRCluster/Private/CAVEOverlay/CAVEOverlay.cpp index 75db39b1..926603b6 100644 --- a/Source/RWTHVRCluster/Private/CAVEOverlay/CAVEOverlay.cpp +++ b/Source/RWTHVRCluster/Private/CAVEOverlay/CAVEOverlay.cpp @@ -25,12 +25,11 @@ void FCAVEOverlay::OnSessionStart(UWorld* World, const UWorld::InitializationVal TArray<AActor*> Actors; UGameplayStatics::GetAllActorsOfClass(World, ACAVEOverlayController::StaticClass(), Actors); - if((Settings->DefaultActivationType == DefaultActivationType_ON + if ((Settings->DefaultActivationType == DefaultActivationType_ON != Settings->excludedMaps.ContainsByPredicate( - [World](const FSoftObjectPath& Map) {return Map.GetAssetName() == World->GetName();} + [World](const FSoftObjectPath& Map) { return Map.GetAssetName() == World->GetName(); } )) && Actors.Num() == 0) { World->SpawnActor(ACAVEOverlayController::StaticClass()); } } - diff --git a/Source/RWTHVRCluster/Private/CAVEOverlay/CAVEOverlayController.cpp b/Source/RWTHVRCluster/Private/CAVEOverlay/CAVEOverlayController.cpp index f1ec0008..08415c9b 100644 --- a/Source/RWTHVRCluster/Private/CAVEOverlay/CAVEOverlayController.cpp +++ b/Source/RWTHVRCluster/Private/CAVEOverlay/CAVEOverlayController.cpp @@ -1,14 +1,12 @@ #include "CAVEOverlay/CAVEOverlayController.h" #include "CoreMinimal.h" -#include "CAVEOverlay/DoorOverlayData.h" #include "IDisplayCluster.h" -#include "IXRTrackingSystem.h" +#include "CAVEOverlay/DoorOverlayData.h" #include "Cluster/IDisplayClusterClusterManager.h" -#include "Game/IDisplayClusterGameManager.h" -#include "UObject/ConstructorHelpers.h" #include "Components/StaticMeshComponent.h" -#include "Materials/MaterialInstanceDynamic.h" #include "Engine/CollisionProfile.h" +#include "Materials/MaterialInstanceDynamic.h" +#include "UObject/ConstructorHelpers.h" #include "Utility/VirtualRealityUtilities.h" DEFINE_LOG_CATEGORY(LogCAVEOverlay); @@ -22,7 +20,8 @@ bool ContainsFString(const TArray<FString>& Array, const FString& Entry) return false; } -UStaticMeshComponent* ACAVEOverlayController::CreateMeshComponent(const FName& Name, UStaticMesh* Mesh, USceneComponent* Parent) +UStaticMeshComponent* ACAVEOverlayController::CreateMeshComponent(const FName& Name, UStaticMesh* Mesh, + USceneComponent* Parent) { UStaticMeshComponent* Result = CreateDefaultSubobject<UStaticMeshComponent>(Name); Result->SetStaticMesh(Mesh); @@ -40,7 +39,8 @@ ACAVEOverlayController::ACAVEOverlayController() bAllowTickBeforeBeginPlay = false; AutoReceiveInput = EAutoReceiveInput::Player0; - ConstructorHelpers::FClassFinder<UDoorOverlayData> WidgetClassFinder(TEXT("Blueprint'/RWTHVRToolkit/CAVEOverlay/DoorOverlay'")); + ConstructorHelpers::FClassFinder<UDoorOverlayData> WidgetClassFinder( + TEXT("Blueprint'/RWTHVRToolkit/CAVEOverlay/DoorOverlay'")); if (WidgetClassFinder.Succeeded()) { OverlayClass = WidgetClassFinder.Class; @@ -133,7 +133,8 @@ void ACAVEOverlayController::CycleDoorType() void ACAVEOverlayController::HandleClusterEvent(const FDisplayClusterClusterEventJson& Event) { - if (Event.Category.Equals("CAVEOverlay") && Event.Type.Equals("DoorChange") && Event.Parameters.Contains("NewDoorState")) + if (Event.Category.Equals("CAVEOverlay") && Event.Type.Equals("DoorChange") && Event.Parameters.Contains( + "NewDoorState")) { SetDoorMode(static_cast<EDoorMode>(FCString::Atoi(*Event.Parameters["NewDoorState"]))); } @@ -148,7 +149,8 @@ void ACAVEOverlayController::SetDoorMode(EDoorMode NewMode) case EDoorMode::DOOR_PARTIALLY_OPEN: DoorCurrentOpeningWidthAbsolute = DoorOpeningWidthAbsolute; if (ScreenType == SCREEN_DOOR) Overlay->BlackBox->SetRenderScale(FVector2D(0, 1)); - if (ScreenType == SCREEN_DOOR_PARTIAL) Overlay->BlackBox->SetRenderScale(FVector2D(DoorOpeningWidthRelative, 1)); + if (ScreenType == SCREEN_DOOR_PARTIAL) Overlay->BlackBox-> + SetRenderScale(FVector2D(DoorOpeningWidthRelative, 1)); if (ScreenType == SCREEN_MASTER) Overlay->BlackBox->SetRenderScale(FVector2D(0, 1)); Overlay->BlackBox->SetVisibility(ESlateVisibility::Visible); break; @@ -170,7 +172,8 @@ void ACAVEOverlayController::SetDoorMode(EDoorMode NewMode) } if (ScreenType == SCREEN_NORMAL) Overlay->BlackBox->SetRenderScale(FVector2D(0, 1)); //no overlay - UE_LOG(LogCAVEOverlay, Log, TEXT("Switched door state to '%s'. New opening width is %f."), *DoorModeNames[DoorCurrentMode], DoorCurrentOpeningWidthAbsolute); + UE_LOG(LogCAVEOverlay, Log, TEXT("Switched door state to '%s'. New opening width is %f."), + *DoorModeNames[DoorCurrentMode], DoorCurrentOpeningWidthAbsolute); if (ScreenType == SCREEN_MASTER) { @@ -192,7 +195,8 @@ void ACAVEOverlayController::BeginPlay() IDisplayClusterClusterManager* ClusterManager = IDisplayCluster::Get().GetClusterMgr(); if (ClusterManager && !ClusterEventListenerDelegate.IsBound()) { - ClusterEventListenerDelegate = FOnClusterEventJsonListener::CreateUObject(this, &ACAVEOverlayController::HandleClusterEvent); + ClusterEventListenerDelegate = FOnClusterEventJsonListener::CreateUObject( + this, &ACAVEOverlayController::HandleClusterEvent); ClusterManager->AddClusterEventJsonListener(ClusterEventListenerDelegate); } @@ -217,7 +221,8 @@ void ACAVEOverlayController::BeginPlay() Overlay = CreateWidget<UDoorOverlayData>(GetWorld()->GetFirstPlayerController(), OverlayClass); Overlay->AddToViewport(0); SetDoorMode(DoorCurrentMode); - Overlay->CornerText->SetText(FText::FromString("")); //Set Text to "" until someone presses the key for the first time + Overlay->CornerText->SetText(FText::FromString("")); + //Set Text to "" until someone presses the key for the first time if (!bAttachedToCAVEOrigin && CaveOrigin) { @@ -237,7 +242,7 @@ void ACAVEOverlayController::EndPlay(const EEndPlayReason::Type EndPlayReason) Super::EndPlay(EndPlayReason); } -float ACAVEOverlayController::CalculateOpacityFromPosition(FVector Position) const +float ACAVEOverlayController::CalculateOpacityFromPosition(const FVector& Position) const { return FMath::Max( FMath::Clamp((FMath::Abs(Position.X) - (WallDistance - WallCloseDistance)) / WallFadeDistance, 0.0f, 1.0f), @@ -245,10 +250,12 @@ float ACAVEOverlayController::CalculateOpacityFromPosition(FVector Position) con ); } -bool ACAVEOverlayController::PositionInDoorOpening(FVector Position) const +bool ACAVEOverlayController::PositionInDoorOpening(const FVector& Position) const { - return FMath::IsWithinInclusive(-Position.X, WallDistance + 10 - 20 - WallCloseDistance, WallDistance + 10) //Overlap both sides 10cm - && FMath::IsWithinInclusive(-Position.Y, WallDistance + 10 - DoorCurrentOpeningWidthAbsolute, WallDistance + 10); //Overlap one side 10cm + return FMath::IsWithinInclusive(-Position.X, WallDistance + 10 - 20 - WallCloseDistance, WallDistance + 10) + //Overlap both sides 10cm + && FMath::IsWithinInclusive(-Position.Y, WallDistance + 10 - DoorCurrentOpeningWidthAbsolute, + WallDistance + 10); //Overlap one side 10cm } // Called every frame @@ -272,7 +279,8 @@ void ACAVEOverlayController::Tick(float DeltaTime) //FPS Counter if (Overlay) { - if (DoorCurrentMode == EDoorMode::DOOR_DEBUG && ContainsFString(ScreensFPS, IDisplayCluster::Get().GetClusterMgr()->GetNodeId())) + if (DoorCurrentMode == EDoorMode::DOOR_DEBUG && ContainsFString( + ScreensFPS, IDisplayCluster::Get().GetClusterMgr()->GetNodeId())) { Overlay->FPS->SetText(FText::FromString(FString::Printf(TEXT("FPS: %.1f"), 1.0f / DeltaTime))); } @@ -284,14 +292,15 @@ void ACAVEOverlayController::Tick(float DeltaTime) if (!Head) { - Head = UVirtualRealityUtilities::GetNamedClusterComponent(ENamedClusterComponent::NCC_SHUTTERGLASSES); + Head = UVirtualRealityUtilities::GetNamedClusterComponent(ENamedClusterComponent::NCC_SHUTTERGLASSES); } if (!Head || !CaveOrigin) return; //Display Cluster not fully initialized //Head/Tape Logic - const FVector ShutterPosition = Head->GetComponentLocation() - CaveOrigin->GetComponentLocation(); - const bool bHeadIsCloseToWall = FMath::IsWithinInclusive(ShutterPosition.GetAbsMax(), WallDistance - WallCloseDistance, WallDistance); + const FVector ShutterPosition = Head->GetComponentLocation() - CaveOrigin->GetComponentLocation(); + const bool bHeadIsCloseToWall = FMath::IsWithinInclusive(ShutterPosition.GetAbsMax(), + WallDistance - WallCloseDistance, WallDistance); if (bHeadIsCloseToWall && !PositionInDoorOpening(ShutterPosition)) { @@ -316,24 +325,28 @@ void ACAVEOverlayController::Tick(float DeltaTime) } // Flystick/Sign Logic - if(!Flystick) + if (!Flystick) { - Flystick = UVirtualRealityUtilities::GetNamedClusterComponent(ENamedClusterComponent::NCC_FLYSTICK); + Flystick = UVirtualRealityUtilities::GetNamedClusterComponent(ENamedClusterComponent::NCC_FLYSTICK); } if (Flystick) { - const FVector FlystickPosition = Flystick->GetRelativeTransform().GetLocation(); - const bool bFlystickInDoor = PositionInDoorOpening(FlystickPosition); + const FVector FlystickPosition = Flystick->GetRelativeTransform().GetLocation(); + const bool bFlystickInDoor = PositionInDoorOpening(FlystickPosition); SignNegativeX->SetRelativeLocation(FVector(-WallDistance, FlystickPosition.Y, FlystickPosition.Z)); SignNegativeY->SetRelativeLocation(FVector(FlystickPosition.X, -WallDistance, FlystickPosition.Z)); SignPositiveX->SetRelativeLocation(FVector(+WallDistance, FlystickPosition.Y, FlystickPosition.Z)); SignPositiveY->SetRelativeLocation(FVector(FlystickPosition.X, +WallDistance, FlystickPosition.Z)); - SignNegativeX->SetVisibility(FMath::IsWithin(-FlystickPosition.X, WallDistance - WallCloseDistance, WallDistance) && !bFlystickInDoor); - SignNegativeY->SetVisibility(FMath::IsWithin(-FlystickPosition.Y, WallDistance - WallCloseDistance, WallDistance) && !bFlystickInDoor); - SignPositiveX->SetVisibility(FMath::IsWithin(+FlystickPosition.X, WallDistance - WallCloseDistance, WallDistance) && !bFlystickInDoor); - SignPositiveY->SetVisibility(FMath::IsWithin(+FlystickPosition.Y, WallDistance - WallCloseDistance, WallDistance) && !bFlystickInDoor); + SignNegativeX->SetVisibility( + FMath::IsWithin(-FlystickPosition.X, WallDistance - WallCloseDistance, WallDistance) && !bFlystickInDoor); + SignNegativeY->SetVisibility( + FMath::IsWithin(-FlystickPosition.Y, WallDistance - WallCloseDistance, WallDistance) && !bFlystickInDoor); + SignPositiveX->SetVisibility( + FMath::IsWithin(+FlystickPosition.X, WallDistance - WallCloseDistance, WallDistance) && !bFlystickInDoor); + SignPositiveY->SetVisibility( + FMath::IsWithin(+FlystickPosition.Y, WallDistance - WallCloseDistance, WallDistance) && !bFlystickInDoor); SignMaterialDynamic->SetScalarParameterValue("SignOpacity", CalculateOpacityFromPosition(FlystickPosition)); } diff --git a/Source/RWTHVRCluster/Private/ClusterConsole.cpp b/Source/RWTHVRCluster/Private/ClusterConsole.cpp index 7fe177c8..548e2a0c 100644 --- a/Source/RWTHVRCluster/Private/ClusterConsole.cpp +++ b/Source/RWTHVRCluster/Private/ClusterConsole.cpp @@ -5,40 +5,42 @@ void FClusterConsole::Register() { /* Registering console command */ - ClusterConsoleCommand = IConsoleManager::Get().RegisterConsoleCommand(TEXT("ClusterExecute"), TEXT("<Your Command> - Execute commands on every node of the nDisplay cluster by prepending ClusterExecute"), - FConsoleCommandWithArgsDelegate::CreateLambda([](const TArray< FString >& Args) - { - if(IDisplayCluster::Get().GetClusterMgr() == nullptr || Args.Num() == 0) return; - - /* Emitting cluster event */ - FDisplayClusterClusterEventJson ClusterEvent; - ClusterEvent.Name = "ClusterExecute " + Args[0]; - ClusterEvent.Type = Args[0]; - ClusterEvent.Category = "NDisplayClusterExecute"; - ClusterEvent.Parameters.Add("Command", FString::Join(Args, TEXT(" "))); - - IDisplayCluster::Get().GetClusterMgr()->EmitClusterEventJson(ClusterEvent, false); - })); + ClusterConsoleCommand = IConsoleManager::Get().RegisterConsoleCommand( + TEXT("ClusterExecute"), + TEXT("<Your Command> - Execute commands on every node of the nDisplay cluster by prepending ClusterExecute"), + FConsoleCommandWithArgsDelegate::CreateLambda([](const TArray<FString>& Args) + { + if (IDisplayCluster::Get().GetClusterMgr() == nullptr || Args.Num() == 0) return; + + /* Emitting cluster event */ + FDisplayClusterClusterEventJson ClusterEvent; + ClusterEvent.Name = "ClusterExecute " + Args[0]; + ClusterEvent.Type = Args[0]; + ClusterEvent.Category = "NDisplayClusterExecute"; + ClusterEvent.Parameters.Add("Command", FString::Join(Args, TEXT(" "))); + + IDisplayCluster::Get().GetClusterMgr()->EmitClusterEventJson(ClusterEvent, false); + })); /* Register cluster event handling */ - IDisplayCluster* DisplayCluster = FModuleManager::LoadModulePtr<IDisplayCluster>(IDisplayCluster::ModuleName); + const IDisplayCluster* DisplayCluster = FModuleManager::LoadModulePtr<IDisplayCluster>(IDisplayCluster::ModuleName); if (DisplayCluster && !ClusterEventListenerDelegate.IsBound()) { - ClusterEventListenerDelegate = FOnClusterEventJsonListener::CreateLambda([](const FDisplayClusterClusterEventJson& Event) - { - /* Actual handling */ - if (Event.Category.Equals("NDisplayClusterExecute") && Event.Parameters.Contains("Command") && GEngine) + ClusterEventListenerDelegate = FOnClusterEventJsonListener::CreateLambda( + [](const FDisplayClusterClusterEventJson& Event) { - GEngine->Exec(GEngine->GetCurrentPlayWorld(), *Event.Parameters["Command"]); - } - }); + /* Actual handling */ + if (Event.Category.Equals("NDisplayClusterExecute") && Event.Parameters.Contains("Command") && GEngine) + { + GEngine->Exec(GEngine->GetCurrentPlayWorld(), *Event.Parameters["Command"]); + } + }); DisplayCluster->GetClusterMgr()->AddClusterEventJsonListener(ClusterEventListenerDelegate); } } -void FClusterConsole::Unregister() +void FClusterConsole::Unregister() const { IConsoleManager::Get().UnregisterConsoleObject(ClusterConsoleCommand); IDisplayCluster::Get().GetClusterMgr()->RemoveClusterEventJsonListener(ClusterEventListenerDelegate); } - diff --git a/Source/RWTHVRCluster/Private/RWTHVRCluster.cpp b/Source/RWTHVRCluster/Private/RWTHVRCluster.cpp index 6aa76eeb..9796e294 100644 --- a/Source/RWTHVRCluster/Private/RWTHVRCluster.cpp +++ b/Source/RWTHVRCluster/Private/RWTHVRCluster.cpp @@ -7,6 +7,7 @@ void FRWTHVRClusterModule::StartupModule () ClusterConsole.Register(); CAVEOverlay.Register(); } + void FRWTHVRClusterModule::ShutdownModule() { ClusterConsole.Unregister(); @@ -15,4 +16,4 @@ void FRWTHVRClusterModule::ShutdownModule() #undef LOCTEXT_NAMESPACE -IMPLEMENT_MODULE(FRWTHVRClusterModule, RWTHVRCluster) \ No newline at end of file +IMPLEMENT_MODULE(FRWTHVRClusterModule, RWTHVRCluster) diff --git a/Source/RWTHVRCluster/Public/CAVEOverlay/CAVEOverlayController.h b/Source/RWTHVRCluster/Public/CAVEOverlay/CAVEOverlayController.h index 1ac575b6..8f16a699 100644 --- a/Source/RWTHVRCluster/Public/CAVEOverlay/CAVEOverlayController.h +++ b/Source/RWTHVRCluster/Public/CAVEOverlay/CAVEOverlayController.h @@ -56,8 +56,8 @@ private: UStaticMeshComponent* CreateMeshComponent(const FName& Name, UStaticMesh* Mesh, USceneComponent* Parent); UPROPERTY() UMaterial* TapeMaterial = nullptr; UPROPERTY() UMaterial* SignMaterial = nullptr; - float CalculateOpacityFromPosition(FVector Position) const; - bool PositionInDoorOpening(FVector Position) const; + float CalculateOpacityFromPosition(const FVector& Position) const; + bool PositionInDoorOpening(const FVector& Position) const; //Pawn Components bool bAttachedToCAVEOrigin = false; diff --git a/Source/RWTHVRCluster/Public/ClusterConsole.h b/Source/RWTHVRCluster/Public/ClusterConsole.h index 81faf82f..79a3ff22 100644 --- a/Source/RWTHVRCluster/Public/ClusterConsole.h +++ b/Source/RWTHVRCluster/Public/ClusterConsole.h @@ -22,5 +22,5 @@ private: public: void Register(); - void Unregister(); + void Unregister() const; }; diff --git a/Source/RWTHVRToolkit/Private/Fixes/ActivateConsoleInShipping.cpp b/Source/RWTHVRToolkit/Private/Fixes/ActivateConsoleInShipping.cpp index 9164ffbc..e81ddaa0 100644 --- a/Source/RWTHVRToolkit/Private/Fixes/ActivateConsoleInShipping.cpp +++ b/Source/RWTHVRToolkit/Private/Fixes/ActivateConsoleInShipping.cpp @@ -3,7 +3,8 @@ void FActivateConsoleInShipping::Register() { - if(FApp::GetBuildConfiguration() != EBuildConfiguration::Shipping) return; /* Should only enable console in shipping */ + if (FApp::GetBuildConfiguration() != EBuildConfiguration::Shipping) return; + /* Should only enable console in shipping */ On_Post_World_Initialization_Delegate.BindRaw(this, &FActivateConsoleInShipping::OnSessionStart); StartHandle = FWorldDelegates::OnPostWorldInitialization.Add(On_Post_World_Initialization_Delegate); @@ -11,14 +12,15 @@ void FActivateConsoleInShipping::Register() void FActivateConsoleInShipping::Unregister() const { - if(FApp::GetBuildConfiguration() != EBuildConfiguration::Shipping) return; + if (FApp::GetBuildConfiguration() != EBuildConfiguration::Shipping) return; - FWorldDelegates::OnPostWorldInitialization.Remove(StartHandle); + FWorldDelegates::OnPostWorldInitialization.Remove(StartHandle); } void FActivateConsoleInShipping::OnSessionStart(UWorld* World, const UWorld::InitializationValues Values) const { - if(!World->IsGameWorld() || !World->GetGameViewport() || World->GetGameViewport()->ViewportConsole != nullptr) return; + if (!World->IsGameWorld() || !World->GetGameViewport() || World->GetGameViewport()->ViewportConsole != nullptr) + return; - World->GetGameViewport()->ViewportConsole = NewObject<UConsole>(World->GetGameViewport()); + World->GetGameViewport()->ViewportConsole = NewObject<UConsole>(World->GetGameViewport()); } diff --git a/Source/RWTHVRToolkit/Private/Interaction/ClickBehaviour.cpp b/Source/RWTHVRToolkit/Private/Interaction/ClickBehaviour.cpp index 87a9e769..d5073c9b 100644 --- a/Source/RWTHVRToolkit/Private/Interaction/ClickBehaviour.cpp +++ b/Source/RWTHVRToolkit/Private/Interaction/ClickBehaviour.cpp @@ -9,14 +9,12 @@ UClickBehaviour::UClickBehaviour() PrimaryComponentTick.bCanEverTick = true; } -void UClickBehaviour::OnClickStart(USceneComponent* TriggeredComponent,const FInputActionValue& Value) +void UClickBehaviour::OnClickStart(USceneComponent* TriggeredComponent, const FInputActionValue& Value) { - } -void UClickBehaviour::OnClickEnd(USceneComponent* TriggeredComponent,const FInputActionValue& Value) +void UClickBehaviour::OnClickEnd(USceneComponent* TriggeredComponent, const FInputActionValue& Value) { - } void UClickBehaviour::BeginPlay() @@ -27,10 +25,8 @@ void UClickBehaviour::BeginPlay() OnClickEndEvent.AddDynamic(this, &UClickBehaviour::OnClickEnd); } - // Called every frame void UClickBehaviour::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) { Super::TickComponent(DeltaTime, TickType, ThisTickFunction); } - diff --git a/Source/RWTHVRToolkit/Private/Interaction/Clickable.cpp b/Source/RWTHVRToolkit/Private/Interaction/Clickable.cpp deleted file mode 100644 index 16de826a..00000000 --- a/Source/RWTHVRToolkit/Private/Interaction/Clickable.cpp +++ /dev/null @@ -1,8 +0,0 @@ -// Fill out your copyright notice in the Description page of Project Settings. - - -#include "Interaction/Clickable.h" - -UClickable::UClickable(const FObjectInitializer& ObjectInitializer) - :Super(ObjectInitializer) -{} diff --git a/Source/RWTHVRToolkit/Private/Interaction/GrabComponent.cpp b/Source/RWTHVRToolkit/Private/Interaction/GrabComponent.cpp index db49c8cb..acdd11d9 100644 --- a/Source/RWTHVRToolkit/Private/Interaction/GrabComponent.cpp +++ b/Source/RWTHVRToolkit/Private/Interaction/GrabComponent.cpp @@ -8,7 +8,6 @@ #include "Interaction/GrabbableComponent.h" #include "Kismet/GameplayStatics.h" -#include "Utility/VirtualRealityUtilities.h" // Sets default values for this component's properties UGrabComponent::UGrabComponent() @@ -26,24 +25,25 @@ void UGrabComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorC TArray<UGrabbableComponent*> CurrentGrabCompsInRange; - + TArray<AActor*> ActorsToIgnore; TArray<FHitResult> OutHits; const ETraceTypeQuery TraceType = UEngineTypes::ConvertToTraceType(ECollisionChannel::ECC_PhysicsBody); - + auto DebugTrace = bShowDebugTrace ? EDrawDebugTrace::ForOneFrame : EDrawDebugTrace::None; - - UKismetSystemLibrary::SphereTraceMulti(GetWorld(),GetAttachParent()->GetComponentLocation(), - GetAttachParent()->GetComponentLocation(),GrabSphereRadius,TraceType,true,ActorsToIgnore,DebugTrace, - OutHits,true,FColor::Green); - for(FHitResult Hit : OutHits) + UKismetSystemLibrary::SphereTraceMulti(GetWorld(), GetAttachParent()->GetComponentLocation(), + GetAttachParent()->GetComponentLocation(), GrabSphereRadius, TraceType, true, + ActorsToIgnore, DebugTrace, + OutHits, true, FColor::Green); + + for (FHitResult Hit : OutHits) { AActor* HitActor = Hit.GetActor(); - if(HitActor) + if (HitActor) { UGrabbableComponent* Grabbable = HitActor->FindComponentByClass<UGrabbableComponent>(); - if(Grabbable && Grabbable->IsInteractable) + if (Grabbable && Grabbable->IsInteractable) { Grabbable->HitResult = Hit; CurrentGrabCompsInRange.Add(Grabbable); @@ -54,67 +54,59 @@ void UGrabComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorC CurrentGrabbableInRange = CurrentGrabCompsInRange; // Call hover start events on all components that were not in range before - for(UGrabbableComponent* CurrentGrabbale : CurrentGrabCompsInRange) + for (UGrabbableComponent* CurrentGrabbale : CurrentGrabCompsInRange) { - if(!PreviousGrabbablesInRange.Contains(CurrentGrabbale)) + if (!PreviousGrabbablesInRange.Contains(CurrentGrabbale)) { PreviousGrabbablesInRange.Add(CurrentGrabbale); CurrentGrabbale->HandleOnHoverStartEvents(this); } - } TArray<UGrabbableComponent*> ComponentsToRemove; - + // Call hover end events on all components that were previously in range, but not anymore - for(UGrabbableComponent* PrevGrabbale : PreviousGrabbablesInRange) + for (UGrabbableComponent* PrevGrabbale : PreviousGrabbablesInRange) { - if(!CurrentGrabCompsInRange.Contains(PrevGrabbale)) + if (!CurrentGrabCompsInRange.Contains(PrevGrabbale)) { ComponentsToRemove.Add(PrevGrabbale); PrevGrabbale->HandleOnHoverEndEvents(this); } } - for(UGrabbableComponent* CompToRemove : ComponentsToRemove) + for (UGrabbableComponent* CompToRemove : ComponentsToRemove) { PreviousGrabbablesInRange.Remove(CompToRemove); } } -// Called when the game starts -void UGrabComponent::BeginPlay() +void UGrabComponent::SetupPlayerInput(UInputComponent* PlayerInputComponent) { - Super::BeginPlay(); - SetupInputActions(); - // ... - -} + IInputExtensionInterface::SetupPlayerInput(PlayerInputComponent); -void UGrabComponent::SetupInputActions() -{ const APawn* Pawn = Cast<APawn>(GetOwner()); - const APlayerController* PlayerController = Cast<APlayerController>(Pawn->GetController()); - const ULocalPlayer* LP = PlayerController ? PlayerController->GetLocalPlayer() : nullptr; - if (LP == nullptr) + if (!Pawn) + return; + + auto* InputSubsystem = GetEnhancedInputLocalPlayerSubsystem(Pawn); + if (!InputSubsystem) return; - UEnhancedInputLocalPlayerSubsystem* InputSubsystem = LP->GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(); // add Input Mapping context - InputSubsystem->AddMappingContext(IMCGrab,0); - + InputSubsystem->AddMappingContext(IMCGrab, 0); + UEnhancedInputComponent* EI = Cast<UEnhancedInputComponent>(Pawn->InputComponent); if (EI == nullptr) return; - + EI->BindAction(GrabInputAction, ETriggerEvent::Started, this, &UGrabComponent::OnBeginGrab); - EI->BindAction(GrabInputAction, ETriggerEvent::Completed, this, &UGrabComponent::OnEndGrab); - + EI->BindAction(GrabInputAction, ETriggerEvent::Completed, this, &UGrabComponent::OnEndGrab); } void UGrabComponent::OnBeginGrab(const FInputActionValue& Value) { - for(UGrabbableComponent* Grabbale : CurrentGrabbableInRange) + for (UGrabbableComponent* Grabbale : CurrentGrabbableInRange) { Grabbale->HandleOnClickStartEvents(this, Value); } @@ -122,10 +114,8 @@ void UGrabComponent::OnBeginGrab(const FInputActionValue& Value) void UGrabComponent::OnEndGrab(const FInputActionValue& Value) { - for(UGrabbableComponent* Grabbale : CurrentGrabbableInRange) + for (UGrabbableComponent* Grabbale : CurrentGrabbableInRange) { Grabbale->HandleOnClickEndEvents(this, Value); } } - - diff --git a/Source/RWTHVRToolkit/Private/Interaction/Grabable.cpp b/Source/RWTHVRToolkit/Private/Interaction/Grabable.cpp deleted file mode 100644 index ab420ac4..00000000 --- a/Source/RWTHVRToolkit/Private/Interaction/Grabable.cpp +++ /dev/null @@ -1,10 +0,0 @@ -// Fill out your copyright notice in the Description page of Project Settings. - - -#include "Interaction/Grabable.h" - -// to avoid some bugs -UGrabable::UGrabable(const FObjectInitializer& ObjectInitializer) - :Super(ObjectInitializer) -{} - diff --git a/Source/RWTHVRToolkit/Private/Interaction/GrabbingBehaviorComponent.cpp b/Source/RWTHVRToolkit/Private/Interaction/GrabbingBehaviorComponent.cpp index 155a7539..8d5630f1 100644 --- a/Source/RWTHVRToolkit/Private/Interaction/GrabbingBehaviorComponent.cpp +++ b/Source/RWTHVRToolkit/Private/Interaction/GrabbingBehaviorComponent.cpp @@ -19,8 +19,10 @@ UPrimitiveComponent* UGrabbingBehaviorComponent::GetFirstComponentSimulatingPhys TargetActor->GetComponents<UPrimitiveComponent>(PrimitiveComponents); // find any component that simulates physics, then traverse the hierarchy - for (UPrimitiveComponent* const& Component : PrimitiveComponents) { - if (Component->IsSimulatingPhysics()) { + for (UPrimitiveComponent* const& Component : PrimitiveComponents) + { + if (Component->IsSimulatingPhysics()) + { return GetHighestParentSimulatingPhysics(Component); } } @@ -30,50 +32,54 @@ UPrimitiveComponent* UGrabbingBehaviorComponent::GetFirstComponentSimulatingPhys // recursively goes up the hierarchy and returns the highest parent simulating physics UPrimitiveComponent* UGrabbingBehaviorComponent::GetHighestParentSimulatingPhysics(UPrimitiveComponent* Comp) { - if (Cast<UPrimitiveComponent>(Comp->GetAttachParent()) && Comp->GetAttachParent()->IsSimulatingPhysics()) { + if (Cast<UPrimitiveComponent>(Comp->GetAttachParent()) && Comp->GetAttachParent()->IsSimulatingPhysics()) + { return GetHighestParentSimulatingPhysics(Cast<UPrimitiveComponent>(Comp->GetAttachParent())); } - else { + else + { return Comp; } } void UGrabbingBehaviorComponent::HandleGrabHold(FVector Position, FQuat Orientation) { - } void UGrabbingBehaviorComponent::HandleGrabStart(AActor* GrabbedBy) { USceneComponent* RightHand = Cast<USceneComponent>(GrabbedBy->GetDefaultSubobjectByName("Right Hand")); - + const FAttachmentTransformRules Rules = FAttachmentTransformRules(EAttachmentRule::KeepWorld, false); MyPhysicsComponent = GetFirstComponentSimulatingPhysics(GetOwner()); - if (MyPhysicsComponent) { + if (MyPhysicsComponent) + { MyPhysicsComponent->SetSimulatePhysics(false); MyPhysicsComponent->AttachToComponent(RightHand, Rules); } - else { + else + { GetOwner()->GetRootComponent()->AttachToComponent(RightHand, Rules); } - + OnBeginGrab.Broadcast(GrabbedBy); } void UGrabbingBehaviorComponent::HandleGrabEnd() { - if(MyPhysicsComponent) + if (MyPhysicsComponent) { MyPhysicsComponent->DetachFromComponent(FDetachmentTransformRules::KeepWorldTransform); MyPhysicsComponent->SetSimulatePhysics(true); - }else + } + else { GetOwner()->GetRootComponent()->DetachFromComponent(FDetachmentTransformRules::KeepWorldTransform); } - + OnEndGrab.Broadcast(); } @@ -82,10 +88,8 @@ void UGrabbingBehaviorComponent::BeginPlay() Super::BeginPlay(); } -void UGrabbingBehaviorComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) +void UGrabbingBehaviorComponent::TickComponent(float DeltaTime, ELevelTick TickType, + FActorComponentTickFunction* ThisTickFunction) { Super::TickComponent(DeltaTime, TickType, ThisTickFunction); } - - - diff --git a/Source/RWTHVRToolkit/Private/Interaction/GrabbingBehaviorOnLineComponent.cpp b/Source/RWTHVRToolkit/Private/Interaction/GrabbingBehaviorOnLineComponent.cpp index 43827e34..b98a7463 100644 --- a/Source/RWTHVRToolkit/Private/Interaction/GrabbingBehaviorOnLineComponent.cpp +++ b/Source/RWTHVRToolkit/Private/Interaction/GrabbingBehaviorOnLineComponent.cpp @@ -9,48 +9,44 @@ UGrabbingBehaviorOnLineComponent::UGrabbingBehaviorOnLineComponent() // Set this component to be initialized when the game starts, and to be ticked every frame. You can turn these features // off to improve performance if you don't need them. PrimaryComponentTick.bCanEverTick = true; - - this->Distance = 0; -} + Distance = 0; +} void UGrabbingBehaviorOnLineComponent::SetDistance(float Dist) { - check(Dist > 0 && "max distance has to be greater than 0"); - this->Distance = Dist; + Distance = Dist; } - -float UGrabbingBehaviorOnLineComponent::GetDistance() const +float UGrabbingBehaviorOnLineComponent::GetDistance() const { - return this->Distance; + return Distance; } - void UGrabbingBehaviorOnLineComponent::SetDiscreteNumberOfPoints(int Num) { NumPoints = Num; bIsDiscrete = true; } - void UGrabbingBehaviorOnLineComponent::HandleGrabHold(FVector Position, FQuat Orientation) { - FVector AttachmentPoint = this->GetRelativeLocation(); - FVector ConstraintAxis = this->GetComponentQuat().GetUpVector(); - FVector Direction = Orientation.GetForwardVector(); - FVector FromHandToMe = -Position + AttachmentPoint; + const FVector AttachmentPoint = this->GetRelativeLocation(); + const FVector ConstraintAxis = this->GetComponentQuat().GetUpVector(); + const FVector Direction = Orientation.GetForwardVector(); + const FVector FromHandToMe = -Position + AttachmentPoint; // Vector perpendicular to both points FVector Temp = FVector::CrossProduct(FromHandToMe, ConstraintAxis); Temp.Normalize(); - FVector PlaneNormal = FVector::CrossProduct(ConstraintAxis, Temp); + const FVector PlaneNormal = FVector::CrossProduct(ConstraintAxis, Temp); // get intersection point defined by plane - FVector Intersection = FMath::LinePlaneIntersection(Position, Position + Direction, AttachmentPoint, PlaneNormal); - FVector FromOriginToIntersection = Intersection - AttachmentPoint; + const FVector Intersection = FMath::LinePlaneIntersection(Position, Position + Direction, AttachmentPoint, + PlaneNormal); + const FVector FromOriginToIntersection = Intersection - AttachmentPoint; // point along the constraint axis with length of the projection from intersection point onto the axis FVector NewPosition = FVector::DotProduct(FromOriginToIntersection, ConstraintAxis) * ConstraintAxis; @@ -59,9 +55,10 @@ void UGrabbingBehaviorOnLineComponent::HandleGrabHold(FVector Position, FQuat Or if (bIsDiscrete) { - float lengthOfSegment = 1.f / static_cast<float>(NumPoints + 1.f); - FVector LineBeginning = -ConstraintAxis * Distance; - float LengthOnLine = (FVector::DotProduct(FromOriginToIntersection, ConstraintAxis) / Distance + 1.f) / 2.f; // is between 0 and 1 + const float lengthOfSegment = 1.f / static_cast<float>(NumPoints + 1.f); + const FVector LineBeginning = -ConstraintAxis * Distance; + const float LengthOnLine = (FVector::DotProduct(FromOriginToIntersection, ConstraintAxis) / Distance + 1.f) / 2.f; + // is between 0 and 1 float VectorSize = FMath::CeilToFloat(LengthOnLine / lengthOfSegment); if (VectorSize <= 0) VectorSize = 1; @@ -75,22 +72,3 @@ void UGrabbingBehaviorOnLineComponent::HandleGrabHold(FVector Position, FQuat Or // here rotation is not changed GetOwner()->SetActorLocation(NewPosition); } - - -// Called when the game starts -void UGrabbingBehaviorOnLineComponent::BeginPlay() -{ - Super::BeginPlay(); - - // ... - -} - - -// Called every frame -void UGrabbingBehaviorOnLineComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) -{ - Super::TickComponent(DeltaTime, TickType, ThisTickFunction); - -} - diff --git a/Source/RWTHVRToolkit/Private/Interaction/GrabbingBehaviorOnPlaneComponent.cpp b/Source/RWTHVRToolkit/Private/Interaction/GrabbingBehaviorOnPlaneComponent.cpp index 10a5e554..0e8be980 100644 --- a/Source/RWTHVRToolkit/Private/Interaction/GrabbingBehaviorOnPlaneComponent.cpp +++ b/Source/RWTHVRToolkit/Private/Interaction/GrabbingBehaviorOnPlaneComponent.cpp @@ -3,65 +3,34 @@ #include "Interaction/GrabbingBehaviorOnPlaneComponent.h" -// Sets default values for this component's properties -UGrabbingBehaviorOnPlaneComponent::UGrabbingBehaviorOnPlaneComponent() -{ - // Set this component to be initialized when the game starts, and to be ticked every frame. You can turn these features - // off to improve performance if you don't need them. - PrimaryComponentTick.bCanEverTick = true; -} - - void UGrabbingBehaviorOnPlaneComponent::SetDistance(float Dist) { check(Dist > 0 && "max distance has to be greater than 0"); this->Distance = Dist; } -float UGrabbingBehaviorOnPlaneComponent::GetDistance() const +float UGrabbingBehaviorOnPlaneComponent::GetDistance() const { return this->Distance; } - void UGrabbingBehaviorOnPlaneComponent::HandleGrabHold(FVector Position, FQuat Orientation) { FVector AttachmentPoint = this->GetRelativeLocation(); - FVector PlaneNormal = this->GetComponentQuat().GetUpVector(); + FVector PlaneNormal = this->GetComponentQuat().GetUpVector(); FVector Direction = Orientation.GetForwardVector(); - + // calculate point on plane which is pointed to by hand ray FVector Intersection = FMath::LinePlaneIntersection(Position, Position + Direction, AttachmentPoint, PlaneNormal); FVector NewPosition = -AttachmentPoint + Intersection; - + // clamp size by maxDistance NewPosition = NewPosition.GetClampedToMaxSize(Distance); - + // after this NewPoint is in world position NewPosition += AttachmentPoint; // set new position and orientation using calculated quaternion and position // here rotation is not changed GetOwner()->SetActorLocation(NewPosition); -} - - -// Called when the game starts -void UGrabbingBehaviorOnPlaneComponent::BeginPlay() -{ - Super::BeginPlay(); - - // ... - -} - - -// Called every frame -void UGrabbingBehaviorOnPlaneComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) -{ - Super::TickComponent(DeltaTime, TickType, ThisTickFunction); - - // ... - -} - +} \ No newline at end of file diff --git a/Source/RWTHVRToolkit/Private/Interaction/HoverBehaviour.cpp b/Source/RWTHVRToolkit/Private/Interaction/HoverBehaviour.cpp index f3da461b..e3a86ee1 100644 --- a/Source/RWTHVRToolkit/Private/Interaction/HoverBehaviour.cpp +++ b/Source/RWTHVRToolkit/Private/Interaction/HoverBehaviour.cpp @@ -3,16 +3,6 @@ #include "Interaction/HoverBehaviour.h" -// Sets default values for this component's properties -UHoverBehaviour::UHoverBehaviour() -{ - // Set this component to be initialized when the game starts, and to be ticked every frame. You can turn these features - // off to improve performance if you don't need them. - PrimaryComponentTick.bCanEverTick = true; - - // ... -} - void UHoverBehaviour::OnHoverStart(const USceneComponent* TriggeredComponent, FHitResult Hit) { } @@ -21,21 +11,10 @@ void UHoverBehaviour::OnHoverEnd(const USceneComponent* TriggeredComponent) { } - void UHoverBehaviour::BeginPlay() { Super::BeginPlay(); OnHoverStartEvent.AddDynamic(this, &UHoverBehaviour::OnHoverStart); OnHoverEndEvent.AddDynamic(this, &UHoverBehaviour::OnHoverEnd); - } - - -void UHoverBehaviour::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) -{ - Super::TickComponent(DeltaTime, TickType, ThisTickFunction); - - -} - diff --git a/Source/RWTHVRToolkit/Private/Interaction/InteractableBase.cpp b/Source/RWTHVRToolkit/Private/Interaction/InteractableBase.cpp index d9522129..f15c48f3 100644 --- a/Source/RWTHVRToolkit/Private/Interaction/InteractableBase.cpp +++ b/Source/RWTHVRToolkit/Private/Interaction/InteractableBase.cpp @@ -5,20 +5,8 @@ #include "Interaction/ClickBehaviour.h" #include "Interaction/HoverBehaviour.h" -#include "Utility/VirtualRealityUtilities.h" -// Sets default values for this component's properties -UInteractableBase::UInteractableBase() -{ - // Set this component to be initialized when the game starts, and to be ticked every frame. You can turn these features - // off to improve performance if you don't need them. - PrimaryComponentTick.bCanEverTick = true; - - // ... -} - - -void UInteractableBase::RestrictInteractionToComponents(TArray<USceneComponent*> Components) +void UInteractableBase::RestrictInteractionToComponents(const TArray<USceneComponent*>& Components) { if(Components.IsEmpty()) { @@ -49,16 +37,6 @@ void UInteractableBase::BeginPlay() { Super::BeginPlay(); InitDefaultBehaviourReferences(); - // ... - -} - -// Called every frame -void UInteractableBase::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) -{ - Super::TickComponent(DeltaTime, TickType, ThisTickFunction); - - // ... } void UInteractableBase::HandleOnHoverStartEvents(USceneComponent* TriggerComponent) diff --git a/Source/RWTHVRToolkit/Private/Interaction/OnClickGrabBehavior.cpp b/Source/RWTHVRToolkit/Private/Interaction/OnClickGrabBehavior.cpp index c264da00..6154e96c 100644 --- a/Source/RWTHVRToolkit/Private/Interaction/OnClickGrabBehavior.cpp +++ b/Source/RWTHVRToolkit/Private/Interaction/OnClickGrabBehavior.cpp @@ -3,40 +3,9 @@ #include "Interaction/OnClickGrabBehavior.h" -#include "Interaction/GrabbableComponent.h" #include "Interaction/InteractableBase.h" #include "Kismet/GameplayStatics.h" #include "Serialization/JsonTypes.h" -#include "Utility/VirtualRealityUtilities.h" - -// Sets default values for this component's properties -UOnClickGrabBehavior::UOnClickGrabBehavior() -{ - // Set this component to be initialized when the game starts, and to be ticked every frame. You can turn these features - // off to improve performance if you don't need them. - PrimaryComponentTick.bCanEverTick = true; - - // ... -} - - -// Called when the game starts -void UOnClickGrabBehavior::BeginPlay() -{ - Super::BeginPlay(); - - // ... - -} - - -// Called every frame -void UOnClickGrabBehavior::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) -{ - Super::TickComponent(DeltaTime, TickType, ThisTickFunction); - - // ... -} UPrimitiveComponent* UOnClickGrabBehavior::GetFirstComponentSimulatingPhysics(const AActor* TargetActor) { @@ -44,8 +13,10 @@ UPrimitiveComponent* UOnClickGrabBehavior::GetFirstComponentSimulatingPhysics(co TargetActor->GetComponents<UPrimitiveComponent>(PrimitiveComponents); // find any component that simulates physics, then traverse the hierarchy - for (UPrimitiveComponent* const& Component : PrimitiveComponents) { - if (Component->IsSimulatingPhysics()) { + for (UPrimitiveComponent* const& Component : PrimitiveComponents) + { + if (Component->IsSimulatingPhysics()) + { return GetHighestParentSimulatingPhysics(Component); } } @@ -55,10 +26,12 @@ UPrimitiveComponent* UOnClickGrabBehavior::GetFirstComponentSimulatingPhysics(co // recursively goes up the hierarchy and returns the highest parent simulating physics UPrimitiveComponent* UOnClickGrabBehavior::GetHighestParentSimulatingPhysics(UPrimitiveComponent* Comp) { - if (Cast<UPrimitiveComponent>(Comp->GetAttachParent()) && Comp->GetAttachParent()->IsSimulatingPhysics()) { + if (Cast<UPrimitiveComponent>(Comp->GetAttachParent()) && Comp->GetAttachParent()->IsSimulatingPhysics()) + { return GetHighestParentSimulatingPhysics(Cast<UPrimitiveComponent>(Comp->GetAttachParent())); } - else { + else + { return Comp; } } @@ -66,14 +39,15 @@ UPrimitiveComponent* UOnClickGrabBehavior::GetHighestParentSimulatingPhysics(UPr void UOnClickGrabBehavior::OnClickStart(USceneComponent* TriggeredComponent, const FInputActionValue& Value) { const APawn* Player = UGameplayStatics::GetPlayerPawn(GetWorld(), 0); - + USceneComponent* Hand = Cast<USceneComponent>(TriggeredComponent->GetAttachParent()); - + const FAttachmentTransformRules Rules = FAttachmentTransformRules(EAttachmentRule::KeepWorld, false); MyPhysicsComponent = GetFirstComponentSimulatingPhysics(GetOwner()); - if (MyPhysicsComponent) { + if (MyPhysicsComponent) + { MyPhysicsComponent->SetSimulatePhysics(false); MyPhysicsComponent->AttachToComponent(Hand, Rules); } @@ -82,11 +56,11 @@ void UOnClickGrabBehavior::OnClickStart(USceneComponent* TriggeredComponent, con GetOwner()->GetRootComponent()->AttachToComponent(Hand, Rules); } - - if(bBlockOtherInteractionsWhileGrabbed) + + if (bBlockOtherInteractionsWhileGrabbed) { - TArray<UInteractableBase*> Interactables; - GetOwner()->GetComponents<UInteractableBase>(Interactables,false); + TArray<UInteractableBase*> Interactables; + GetOwner()->GetComponents<UInteractableBase>(Interactables, false); for (UInteractableBase* Interactable : Interactables) { Interactable->RestrictInteractionToComponent(TriggeredComponent); @@ -96,24 +70,23 @@ void UOnClickGrabBehavior::OnClickStart(USceneComponent* TriggeredComponent, con void UOnClickGrabBehavior::OnClickEnd(USceneComponent* TriggeredComponent, const FInputActionValue& Value) { - if(MyPhysicsComponent) + if (MyPhysicsComponent) { MyPhysicsComponent->DetachFromComponent(FDetachmentTransformRules::KeepWorldTransform); MyPhysicsComponent->SetSimulatePhysics(true); - }else + } + else { GetOwner()->GetRootComponent()->DetachFromComponent(FDetachmentTransformRules::KeepWorldTransform); } - if(bBlockOtherInteractionsWhileGrabbed) + if (bBlockOtherInteractionsWhileGrabbed) { - TArray<UInteractableBase*> Interactables; - GetOwner()->GetComponents<UInteractableBase>(Interactables,false); + TArray<UInteractableBase*> Interactables; + GetOwner()->GetComponents<UInteractableBase>(Interactables, false); for (UInteractableBase* Interactable : Interactables) { Interactable->ResetRestrictInteraction(); } } } - - diff --git a/Source/RWTHVRToolkit/Private/Interaction/RaycastSelectionComponent.cpp b/Source/RWTHVRToolkit/Private/Interaction/RaycastSelectionComponent.cpp index 0ac53f6a..240c9c70 100644 --- a/Source/RWTHVRToolkit/Private/Interaction/RaycastSelectionComponent.cpp +++ b/Source/RWTHVRToolkit/Private/Interaction/RaycastSelectionComponent.cpp @@ -6,7 +6,6 @@ #include "EnhancedInputComponent.h" #include "EnhancedInputSubsystems.h" #include "Kismet/KismetSystemLibrary.h" -#include "Utility/VirtualRealityUtilities.h" // Sets default values for this component's properties URaycastSelectionComponent::URaycastSelectionComponent() @@ -18,57 +17,47 @@ URaycastSelectionComponent::URaycastSelectionComponent() // ... } - -// Called when the game starts -void URaycastSelectionComponent::BeginPlay() -{ - Super::BeginPlay(); - SetupInputActions(); - // ... - -} - // Called every frame -void URaycastSelectionComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) +void URaycastSelectionComponent::TickComponent(float DeltaTime, ELevelTick TickType, + FActorComponentTickFunction* ThisTickFunction) { Super::TickComponent(DeltaTime, TickType, ThisTickFunction); URaycastSelectable* CurrentSelectable = nullptr; - - + + TArray<AActor*> ActorsToIgnore; FHitResult Hit; const ETraceTypeQuery TraceType = UEngineTypes::ConvertToTraceType(ECollisionChannel::ECC_PhysicsBody); FVector TraceStart = GetAttachParent()->GetComponentLocation(); FVector TraceEnd = GetAttachParent()->GetComponentLocation() + TraceLength * GetAttachParent()->GetForwardVector(); - + auto DebugTrace = bShowDebugTrace ? EDrawDebugTrace::ForOneFrame : EDrawDebugTrace::None; - - UKismetSystemLibrary::LineTraceSingle(GetWorld(),TraceStart,TraceEnd - ,TraceType,true,ActorsToIgnore,DebugTrace, - Hit,true,FColor::Green); - + + UKismetSystemLibrary::LineTraceSingle(GetWorld(), TraceStart, TraceEnd + , TraceType, true, ActorsToIgnore, DebugTrace, + Hit, true, FColor::Green); + AActor* HitActor = Hit.GetActor(); - if(HitActor) + if (HitActor) { URaycastSelectable* Selectable = HitActor->FindComponentByClass<URaycastSelectable>(); - if(Selectable && Selectable->IsInteractable) + if (Selectable && Selectable->IsInteractable) { CurrentSelectable = Selectable; Selectable->HitResult = Hit; } } - CurrentRaycastSelectable = CurrentSelectable; - - if(CurrentRaycastSelectable != PreviousRaycastSelectable) + + if (CurrentRaycastSelectable != PreviousRaycastSelectable) { - if(CurrentRaycastSelectable) + if (CurrentRaycastSelectable) { CurrentRaycastSelectable->HandleOnHoverStartEvents(this); } - if(PreviousRaycastSelectable) + if (PreviousRaycastSelectable) { PreviousRaycastSelectable->HandleOnHoverEndEvents(this); } @@ -77,29 +66,9 @@ void URaycastSelectionComponent::TickComponent(float DeltaTime, ELevelTick TickT PreviousRaycastSelectable = CurrentRaycastSelectable; } -void URaycastSelectionComponent::SetupInputActions() -{ - const APawn* Pawn = Cast<APawn>(GetOwner()); - const APlayerController* PlayerController = Cast<APlayerController>(Pawn->GetController()); - const ULocalPlayer* LP = PlayerController ? PlayerController->GetLocalPlayer() : nullptr; - if (LP == nullptr) - return; - UEnhancedInputLocalPlayerSubsystem* InputSubsystem = LP->GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(); - - // add Input Mapping context - InputSubsystem->AddMappingContext(IMCRaycastSelection,0); - - UEnhancedInputComponent* EI = Cast<UEnhancedInputComponent>(Pawn->InputComponent); - if (EI == nullptr) - return; - - EI->BindAction(RayCastSelectInputAction, ETriggerEvent::Started, this, &URaycastSelectionComponent::OnBeginSelect); - EI->BindAction(RayCastSelectInputAction, ETriggerEvent::Completed, this, &URaycastSelectionComponent::OnEndSelect); -} - void URaycastSelectionComponent::OnBeginSelect(const FInputActionValue& Value) { - if(CurrentRaycastSelectable) + if (CurrentRaycastSelectable) { CurrentRaycastSelectable->HandleOnClickStartEvents(this, Value); } @@ -107,7 +76,29 @@ void URaycastSelectionComponent::OnBeginSelect(const FInputActionValue& Value) void URaycastSelectionComponent::OnEndSelect(const FInputActionValue& Value) { - if(CurrentRaycastSelectable) + if (CurrentRaycastSelectable) CurrentRaycastSelectable->HandleOnClickEndEvents(this, Value); } +void URaycastSelectionComponent::SetupPlayerInput(UInputComponent* PlayerInputComponent) +{ + IInputExtensionInterface::SetupPlayerInput(PlayerInputComponent); + + const APawn* Pawn = Cast<APawn>(GetOwner()); + if (!Pawn) + return; + + auto* InputSubsystem = GetEnhancedInputLocalPlayerSubsystem(Pawn); + if (!InputSubsystem) + return; + + // add Input Mapping context + InputSubsystem->AddMappingContext(IMCRaycastSelection, 0); + + UEnhancedInputComponent* EI = Cast<UEnhancedInputComponent>(Pawn->InputComponent); + if (!EI) + return; + + EI->BindAction(RayCastSelectInputAction, ETriggerEvent::Started, this, &URaycastSelectionComponent::OnBeginSelect); + EI->BindAction(RayCastSelectInputAction, ETriggerEvent::Completed, this, &URaycastSelectionComponent::OnEndSelect); +} diff --git a/Source/RWTHVRToolkit/Private/Interaction/Targetable.cpp b/Source/RWTHVRToolkit/Private/Interaction/Targetable.cpp deleted file mode 100644 index fae43d04..00000000 --- a/Source/RWTHVRToolkit/Private/Interaction/Targetable.cpp +++ /dev/null @@ -1,8 +0,0 @@ -// Fill out your copyright notice in the Description page of Project Settings. - - -#include "Interaction/Targetable.h" - -UTargetable::UTargetable(const FObjectInitializer& ObjectInitializer) - :Super(ObjectInitializer) -{} diff --git a/Source/RWTHVRToolkit/Private/Pawn/BasicVRInteractionComponent.cpp b/Source/RWTHVRToolkit/Private/Pawn/BasicVRInteractionComponent.cpp index f3e931cc..0509af6a 100644 --- a/Source/RWTHVRToolkit/Private/Pawn/BasicVRInteractionComponent.cpp +++ b/Source/RWTHVRToolkit/Private/Pawn/BasicVRInteractionComponent.cpp @@ -8,7 +8,6 @@ #include "Interaction/Targetable.h" #include "Interaction/GrabbingBehaviorComponent.h" #include "Misc/Optional.h" -#include "DrawDebugHelpers.h" DEFINE_LOG_CATEGORY(LogVRInteractionComponent); diff --git a/Source/RWTHVRToolkit/Private/Pawn/ContinuousMovementComponent.cpp b/Source/RWTHVRToolkit/Private/Pawn/ContinuousMovementComponent.cpp index ff3d0e11..787b9c1a 100644 --- a/Source/RWTHVRToolkit/Private/Pawn/ContinuousMovementComponent.cpp +++ b/Source/RWTHVRToolkit/Private/Pawn/ContinuousMovementComponent.cpp @@ -13,7 +13,7 @@ void UContinuousMovementComponent::SetupPlayerInput(UInputComponent* PlayerInputComponent) { Super::SetupPlayerInput(PlayerInputComponent); - + if (!VRPawn || !VRPawn->HasLocalNetOwner() || !InputSubsystem) { return; @@ -32,7 +32,7 @@ void UContinuousMovementComponent::SetupPlayerInput(UInputComponent* PlayerInput RotationHand = VRPawn->RightHand; IMCMovement = IMCMovementLeft; } - + // add Input Mapping context InputSubsystem->AddMappingContext(IMCMovement, 0); diff --git a/Source/RWTHVRToolkit/Private/Pawn/InputExtensionInterface.cpp b/Source/RWTHVRToolkit/Private/Pawn/InputExtensionInterface.cpp index 8c429dc9..9d0fc069 100644 --- a/Source/RWTHVRToolkit/Private/Pawn/InputExtensionInterface.cpp +++ b/Source/RWTHVRToolkit/Private/Pawn/InputExtensionInterface.cpp @@ -3,7 +3,7 @@ #include "Pawn/InputExtensionInterface.h" -UEnhancedInputLocalPlayerSubsystem* IInputExtensionInterface::GetEnhancedInputLocalPlayerSubsystem(APawn* Pawn) const +UEnhancedInputLocalPlayerSubsystem* IInputExtensionInterface::GetEnhancedInputLocalPlayerSubsystem(const APawn* Pawn) const { const APlayerController* PlayerController = Pawn ? Cast<APlayerController>(Pawn->GetController()) : nullptr; const ULocalPlayer* LP = PlayerController ? PlayerController->GetLocalPlayer() : nullptr; diff --git a/Source/RWTHVRToolkit/Private/Pawn/MovementComponentBase.cpp b/Source/RWTHVRToolkit/Private/Pawn/MovementComponentBase.cpp index b4f680c8..715cd955 100644 --- a/Source/RWTHVRToolkit/Private/Pawn/MovementComponentBase.cpp +++ b/Source/RWTHVRToolkit/Private/Pawn/MovementComponentBase.cpp @@ -28,7 +28,7 @@ void UMovementComponentBase::SetupPlayerInput(UInputComponent* PlayerInputCompon UE_LOG(Toolkit, Error, TEXT("InputSubsystem IS NOT VALID")); return; } - + // add Input Mapping context InputSubsystem->AddMappingContext(IMCRotation, 0); @@ -78,7 +78,7 @@ void UMovementComponentBase::OnBeginTurn(const FInputActionValue& Value) if (!VRPawn || !VRPawn->Controller) return; - + const FVector2D TurnValue = Value.Get<FVector2D>(); if (TurnValue.X != 0.f) @@ -99,7 +99,7 @@ void UMovementComponentBase::OnBeginSnapTurn(const FInputActionValue& Value) { if (!VRPawn || !VRPawn->Controller) return; - + const FVector2D TurnValue = Value.Get<FVector2D>(); if (TurnValue.X > 0.f) { diff --git a/Source/RWTHVRToolkit/Private/Pawn/MovementComponentBase.h b/Source/RWTHVRToolkit/Private/Pawn/MovementComponentBase.h index 0a9d869e..388e4ce8 100644 --- a/Source/RWTHVRToolkit/Private/Pawn/MovementComponentBase.h +++ b/Source/RWTHVRToolkit/Private/Pawn/MovementComponentBase.h @@ -7,6 +7,7 @@ #include "Pawn/InputExtensionInterface.h" #include "MovementComponentBase.generated.h" +class AVirtualRealityPawn; /** * */ @@ -16,19 +17,21 @@ class RWTHVRTOOLKIT_API UMovementComponentBase : public UActorComponent, public GENERATED_BODY() public: - virtual void SetupPlayerInput(UInputComponent* PlayerInputComponent) override; UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VR Movement") bool bAllowTurning = true; - UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VR Movement|Turning", meta = (EditCondition = "bAllowTurning")) + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VR Movement|Turning", + meta = (EditCondition = "bAllowTurning")) bool bSnapTurn = false; - UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VR Movement|Turning", meta = (EditCondition = "!bSnapTurn && bAllowTurning")) + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VR Movement|Turning", + meta = (EditCondition = "!bSnapTurn && bAllowTurning")) float TurnRateFactor = 1.0f; - UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VR Movement|Turning", meta = (EditCondition = "bSnapTurn && bAllowTurning", ClampMin = 0, ClampMax = 360)) + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VR Movement|Turning", + meta = (EditCondition = "bSnapTurn && bAllowTurning", ClampMin = 0, ClampMax = 360)) float SnapTurnAngle = 22.5; UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "VR Movement|Input|Actions") @@ -37,24 +40,23 @@ public: UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "VR Movement|Input|Actions") class UInputAction* DesktopRotation; - + /*Movement Input*/ UFUNCTION(BlueprintCallable) void OnBeginTurn(const FInputActionValue& Value); UFUNCTION(BlueprintCallable) void OnBeginSnapTurn(const FInputActionValue& Value); - + /*Desktop Testing*/ // the idea is that you have to hold the right mouse button to do rotations UFUNCTION() void StartDesktopRotation(); - + UFUNCTION() void EndDesktopRotation(); protected: - UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "VR Movement|Input") class UInputMappingContext* IMCRotation; diff --git a/Source/RWTHVRToolkit/Private/Pawn/ReplicatedCameraComponent.cpp b/Source/RWTHVRToolkit/Private/Pawn/ReplicatedCameraComponent.cpp index 1c8a8563..be9d5221 100644 --- a/Source/RWTHVRToolkit/Private/Pawn/ReplicatedCameraComponent.cpp +++ b/Source/RWTHVRToolkit/Private/Pawn/ReplicatedCameraComponent.cpp @@ -31,35 +31,35 @@ void UReplicatedCameraComponent::UpdateState(float DeltaTime) { ControllerNetUpdateCount += DeltaTime; if (ControllerNetUpdateCount >= (1.0f / ControllerNetUpdateRate)) // todo save inverse? - { + { ControllerNetUpdateCount = 0.0f; ReplicatedTransform.Position = Loc; ReplicatedTransform.Rotation = Rot; if (GetNetMode() == NM_Client) // why do we differentiate here between netmode and authority? - { - ServerSendControllerTransformRpc(ReplicatedTransform); - } + { + ServerSendControllerTransformRpc(ReplicatedTransform); } + } } } } } void UReplicatedCameraComponent::TickComponent(float DeltaTime, ELevelTick TickType, - FActorComponentTickFunction* ThisTickFunction) + FActorComponentTickFunction* ThisTickFunction) { Super::TickComponent(DeltaTime, TickType, ThisTickFunction); UpdateState(DeltaTime); } -void UReplicatedCameraComponent::GetLifetimeReplicatedProps(TArray< class FLifetimeProperty >& OutLifetimeProps) const +void UReplicatedCameraComponent::GetLifetimeReplicatedProps(TArray<class FLifetimeProperty>& OutLifetimeProps) const { Super::GetLifetimeReplicatedProps(OutLifetimeProps); DISABLE_REPLICATED_PRIVATE_PROPERTY(USceneComponent, RelativeLocation); DISABLE_REPLICATED_PRIVATE_PROPERTY(USceneComponent, RelativeRotation); - DISABLE_REPLICATED_PRIVATE_PROPERTY(USceneComponent, RelativeScale3D); + DISABLE_REPLICATED_PRIVATE_PROPERTY(USceneComponent, RelativeScale3D); // Skipping the owner with this as the owner will use the controllers location directly DOREPLIFETIME_CONDITION(UReplicatedCameraComponent, ReplicatedTransform, COND_SkipOwner); @@ -79,4 +79,4 @@ bool UReplicatedCameraComponent::ServerSendControllerTransformRpc_Validate(FVRTr { return true; // Optionally check to make sure that player is inside of their bounds and deny it if they aren't? -} \ No newline at end of file +} diff --git a/Source/RWTHVRToolkit/Private/Pawn/ReplicatedMotionControllerComponent.cpp b/Source/RWTHVRToolkit/Private/Pawn/ReplicatedMotionControllerComponent.cpp index 4c8c0681..bc7eace3 100644 --- a/Source/RWTHVRToolkit/Private/Pawn/ReplicatedMotionControllerComponent.cpp +++ b/Source/RWTHVRToolkit/Private/Pawn/ReplicatedMotionControllerComponent.cpp @@ -3,7 +3,6 @@ #include "Pawn/ReplicatedMotionControllerComponent.h" - #include "Net/UnrealNetwork.h" UReplicatedMotionControllerComponent::UReplicatedMotionControllerComponent() @@ -32,42 +31,44 @@ void UReplicatedMotionControllerComponent::UpdateState(float DeltaTime) { ControllerNetUpdateCount += DeltaTime; if (ControllerNetUpdateCount >= (1.0f / ControllerNetUpdateRate)) // todo save inverse? - { + { ControllerNetUpdateCount = 0.0f; ReplicatedTransform.Position = Loc; ReplicatedTransform.Rotation = Rot; if (GetNetMode() == NM_Client) // why do we differentiate here between netmode and authority? - { + { SendControllerTransform_ServerRpc(ReplicatedTransform); - } } + } } } } } void UReplicatedMotionControllerComponent::TickComponent(float DeltaTime, ELevelTick TickType, - FActorComponentTickFunction* ThisTickFunction) + FActorComponentTickFunction* ThisTickFunction) { Super::TickComponent(DeltaTime, TickType, ThisTickFunction); UpdateState(DeltaTime); } -void UReplicatedMotionControllerComponent::GetLifetimeReplicatedProps(TArray< class FLifetimeProperty >& OutLifetimeProps) const +void UReplicatedMotionControllerComponent::GetLifetimeReplicatedProps( + TArray<class FLifetimeProperty>& OutLifetimeProps) const { Super::GetLifetimeReplicatedProps(OutLifetimeProps); DISABLE_REPLICATED_PRIVATE_PROPERTY(USceneComponent, RelativeLocation); DISABLE_REPLICATED_PRIVATE_PROPERTY(USceneComponent, RelativeRotation); - DISABLE_REPLICATED_PRIVATE_PROPERTY(USceneComponent, RelativeScale3D); + DISABLE_REPLICATED_PRIVATE_PROPERTY(USceneComponent, RelativeScale3D); // Skipping the owner with this as the owner will use the controllers location directly DOREPLIFETIME_CONDITION(UReplicatedMotionControllerComponent, ReplicatedTransform, COND_SkipOwner); DOREPLIFETIME(UReplicatedMotionControllerComponent, ControllerNetUpdateRate); } -void UReplicatedMotionControllerComponent::SendControllerTransform_ServerRpc_Implementation(FVRTransformRep NewTransform) +void UReplicatedMotionControllerComponent::SendControllerTransform_ServerRpc_Implementation( + FVRTransformRep NewTransform) { // Store new transform and trigger OnRep_Function ReplicatedTransform = NewTransform; @@ -80,4 +81,4 @@ bool UReplicatedMotionControllerComponent::SendControllerTransform_ServerRpc_Val { return true; // Optionally check to make sure that player is inside of their bounds and deny it if they aren't? -} \ No newline at end of file +} diff --git a/Source/RWTHVRToolkit/Private/Pawn/TeleportationComponent.cpp b/Source/RWTHVRToolkit/Private/Pawn/TeleportationComponent.cpp index 00864280..c760b50c 100644 --- a/Source/RWTHVRToolkit/Private/Pawn/TeleportationComponent.cpp +++ b/Source/RWTHVRToolkit/Private/Pawn/TeleportationComponent.cpp @@ -19,12 +19,12 @@ void UTeleportationComponent::SetupPlayerInput(UInputComponent* PlayerInputComponent) { Super::SetupPlayerInput(PlayerInputComponent); - + if (!VRPawn || !VRPawn->HasLocalNetOwner() || !InputSubsystem) { return; } - + TeleportTraceComponent = UNiagaraFunctionLibrary::SpawnSystemAtLocation ( GetWorld(), @@ -40,15 +40,15 @@ void UTeleportationComponent::SetupPlayerInput(UInputComponent* PlayerInputCompo FActorSpawnParameters SpawnParameters = FActorSpawnParameters(); SpawnParameters.Name = "TeleportVisualizer"; - + if (BPTeleportVisualizer) { TeleportVisualizer = GetWorld()->SpawnActor<AActor>(BPTeleportVisualizer, VRPawn->GetActorLocation(), - VRPawn->GetActorRotation(), SpawnParameters); + VRPawn->GetActorRotation(), SpawnParameters); } TeleportTraceComponent->SetVisibility(false); TeleportVisualizer->SetActorHiddenInGame(true); - + // simple way of changing the handedness if (bMoveWithRightHand) { @@ -62,17 +62,17 @@ void UTeleportationComponent::SetupPlayerInput(UInputComponent* PlayerInputCompo RotationHand = VRPawn->RightHand; IMCMovement = IMCTeleportLeft; } - + // add Input Mapping context - InputSubsystem->AddMappingContext(IMCMovement,0); - + InputSubsystem->AddMappingContext(IMCMovement, 0); + UEnhancedInputComponent* EI = Cast<UEnhancedInputComponent>(PlayerInputComponent); if (!EI) { - UE_LOG(Toolkit,Error,TEXT("Cannot cast Input Component to Enhanced Inpu Component in VRPawnMovement")); + UE_LOG(Toolkit, Error, TEXT("Cannot cast Input Component to Enhanced Inpu Component in VRPawnMovement")); return; } - + // teleporting EI->BindAction(Move, ETriggerEvent::Started, this, &UTeleportationComponent::OnStartTeleportTrace); EI->BindAction(Move, ETriggerEvent::Triggered, this, &UTeleportationComponent::UpdateTeleportTrace); @@ -99,7 +99,7 @@ void UTeleportationComponent::UpdateTeleportTrace(const FInputActionValue& Value const FVector ForwardVector = TeleportationHand->GetForwardVector(); TArray<AActor> ActorsToIgnore; - + FPredictProjectilePathParams PredictParams = FPredictProjectilePathParams ( TeleportProjectileRadius, @@ -111,16 +111,16 @@ void UTeleportationComponent::UpdateTeleportTrace(const FInputActionValue& Value PredictParams.ActorsToIgnore.Add(VRPawn); PredictParams.ActorsToIgnore.Add(TeleportVisualizer); - - UGameplayStatics::PredictProjectilePath(GetWorld(),PredictParams,PredictResult); + + UGameplayStatics::PredictProjectilePath(GetWorld(), PredictParams, PredictResult); const FVector HitLocation = PredictResult.HitResult.Location; const bool bValidHit = PredictResult.HitResult.IsValidBlockingHit(); // check if this is a valid location to move to - - FVector OutLocation; + + FVector OutLocation; const bool bValidProjection = IsValidTeleportLocation(PredictResult.HitResult, OutLocation); - + if (bUseNavMesh) { FinalTeleportLocation = OutLocation; @@ -138,7 +138,7 @@ void UTeleportationComponent::UpdateTeleportTrace(const FInputActionValue& Value TeleportVisualizer->SetActorHiddenInGame(false); // update location TeleportVisualizer->SetActorLocation(FinalTeleportLocation); - } + } } TArray<FVector> PathPoints; @@ -147,7 +147,8 @@ void UTeleportationComponent::UpdateTeleportTrace(const FInputActionValue& Value { PathPoints.Add(PData.Location); } - UNiagaraDataInterfaceArrayFunctionLibrary::SetNiagaraArrayVector(TeleportTraceComponent,FName("User.PointArray"),PathPoints); + UNiagaraDataInterfaceArrayFunctionLibrary::SetNiagaraArrayVector(TeleportTraceComponent, FName("User.PointArray"), + PathPoints); } bool UTeleportationComponent::IsValidTeleportLocation(const FHitResult& Hit, FVector& ProjectedLocation) const @@ -155,7 +156,8 @@ bool UTeleportationComponent::IsValidTeleportLocation(const FHitResult& Hit, FVe UNavigationSystemV1* NavSys = FNavigationSystem::GetCurrent<UNavigationSystemV1>(GetWorld()); const FNavAgentProperties& AgentProps = FNavAgentProperties(15, 160); FNavLocation ProjectedNavLocation; - const bool bProjectPoint = (NavSys && NavSys->ProjectPointToNavigation(Hit.Location, ProjectedNavLocation, INVALID_NAVEXTENT, &AgentProps)); + const bool bProjectPoint = (NavSys && NavSys->ProjectPointToNavigation( + Hit.Location, ProjectedNavLocation, INVALID_NAVEXTENT, &AgentProps)); ProjectedLocation = ProjectedNavLocation.Location; return bProjectPoint /*&& Hit.IsValidBlockingHit()*/; } @@ -169,8 +171,7 @@ void UTeleportationComponent::OnEndTeleportTrace(const FInputActionValue& Value) bTeleportTraceActive = false; TeleportTraceComponent->SetVisibility(false); TeleportVisualizer->SetActorHiddenInGame(true); - + bValidTeleportLocation = false; VRPawn->TeleportTo(FinalTeleportLocation, VRPawn->GetActorRotation()); } - diff --git a/Source/RWTHVRToolkit/Private/Pawn/VRPawnMovement.cpp b/Source/RWTHVRToolkit/Private/Pawn/VRPawnMovement.cpp index c844af96..4b4b8190 100644 --- a/Source/RWTHVRToolkit/Private/Pawn/VRPawnMovement.cpp +++ b/Source/RWTHVRToolkit/Private/Pawn/VRPawnMovement.cpp @@ -1,5 +1,4 @@ - -#include "Pawn/VRPawnMovement.h" +#include "Pawn/VRPawnMovement.h" #include "DrawDebugHelpers.h" #include "Kismet/KismetSystemLibrary.h" @@ -10,7 +9,8 @@ UVRPawnMovement::UVRPawnMovement(const FObjectInitializer& ObjectInitializer) : CapsuleColliderComponent = CreateDefaultSubobject<UCapsuleComponent>(TEXT("CapsuleCollider")); CapsuleColliderComponent->SetCollisionEnabled(ECollisionEnabled::QueryAndPhysics); CapsuleColliderComponent->SetCollisionResponseToAllChannels(ECollisionResponse::ECR_Overlap); - CapsuleColliderComponent->SetCollisionResponseToChannel(ECollisionChannel::ECC_WorldStatic, ECollisionResponse::ECR_Block); + CapsuleColliderComponent->SetCollisionResponseToChannel(ECollisionChannel::ECC_WorldStatic, + ECollisionResponse::ECR_Block); CapsuleColliderComponent->SetCapsuleSize(CapsuleRadius, 80.0f); //set some defaults for the UFloatingPawnMovement component, which are more reasonable for usage in VR @@ -23,14 +23,15 @@ void UVRPawnMovement::BeginPlay() { Super::BeginPlay(); LastCollisionFreeCapsulePosition = CapsuleColliderComponent->GetComponentLocation(); - LastSteeringCollisionVector = FVector(0,0,0); + LastSteeringCollisionVector = FVector(0, 0, 0); - ActorsToIgnore = { GetOwner() }; + ActorsToIgnore = {GetOwner()}; } -void UVRPawnMovement::TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction *ThisTickFunction){ - +void UVRPawnMovement::TickComponent(float DeltaTime, enum ELevelTick TickType, + FActorComponentTickFunction* ThisTickFunction) +{ SetCapsuleColliderToUserSize(); FVector InputVector = GetPendingInputVector(); @@ -49,12 +50,13 @@ void UVRPawnMovement::TickComponent(float DeltaTime, enum ELevelTick TickType, F CheckAndRevertCollisionSinceLastTick(); //check whether we are still in collision e.g. if an object has moved and got us into collision MoveOutOfNewDynamicCollisions(); - - if(NavigationMode == EVRNavigationModes::NAV_FLY || NavigationMode == EVRNavigationModes::NAV_WALK) + + if (NavigationMode == EVRNavigationModes::NAV_FLY || NavigationMode == EVRNavigationModes::NAV_WALK) { - if(InputVector.Size() > 0.001){ + if (InputVector.Size() > 0.001) + { const FVector SafeSteeringInput = GetCollisionSafeVirtualSteeringVec(InputVector, DeltaTime); - if(SafeSteeringInput != InputVector) + if (SafeSteeringInput != InputVector) { // if we would move into something if we apply this input (estimating distance by max speed) // we only apply its perpendicular part (unless it is facing away from the collision) @@ -71,7 +73,7 @@ void UVRPawnMovement::TickComponent(float DeltaTime, enum ELevelTick TickType, F CheckForPhysWalkingCollision(); } - if(NavigationMode == EVRNavigationModes::NAV_NONE) + if (NavigationMode == EVRNavigationModes::NAV_NONE) { //just remove whatever input is there ConsumeInputVector(); @@ -86,12 +88,11 @@ void UVRPawnMovement::SetHeadComponent(USceneComponent* NewHeadComponent) CapsuleColliderComponent->SetupAttachment(HeadComponent); const float HalfHeight = 80.0f; //this is just an initial value to look good in editor CapsuleColliderComponent->SetCapsuleSize(CapsuleRadius, HalfHeight); - CapsuleColliderComponent->SetWorldLocation(FVector(0.0f, 0.0f,-HalfHeight)); + CapsuleColliderComponent->SetWorldLocation(FVector(0.0f, 0.0f, -HalfHeight)); } -void UVRPawnMovement::SetCapsuleColliderToUserSize() +void UVRPawnMovement::SetCapsuleColliderToUserSize() const { - // the collider should be placed // between head and floor + MaxStepHeight // head @@ -125,7 +126,8 @@ void UVRPawnMovement::SetCapsuleColliderToUserSize() CapsuleColliderComponent->SetCapsuleSize(CapsuleRadius, ColliderHalfHeight); } - CapsuleColliderComponent->SetWorldLocation(HeadComponent->GetComponentLocation() - FVector(0, 0, ColliderHalfHeight)); + CapsuleColliderComponent->SetWorldLocation( + HeadComponent->GetComponentLocation() - FVector(0, 0, ColliderHalfHeight)); } else { @@ -165,15 +167,14 @@ void UVRPawnMovement::CheckForPhysWalkingCollision() //if this was not possible move the entire pawn away to avoid the head collision if (HitResult.bBlockingHit) { - const FVector MoveOutVector = HitResult.Location-CapsuleLocation; + const FVector MoveOutVector = HitResult.Location - CapsuleLocation; //move it out twice as far, to avoid getting stuck situations - UpdatedComponent->AddWorldOffset(2*MoveOutVector); + UpdatedComponent->AddWorldOffset(2 * MoveOutVector); } } FVector UVRPawnMovement::GetCollisionSafeVirtualSteeringVec(FVector InputVector, float DeltaTime) { - const float SafetyFactor = 3.0f; //so we detect collision a bit earlier const FVector CapsuleLocation = CapsuleColliderComponent->GetComponentLocation(); FVector ProbePosition = SafetyFactor * InputVector.GetSafeNormal() * GetMaxSpeed() * DeltaTime + CapsuleLocation; @@ -188,7 +189,7 @@ FVector UVRPawnMovement::GetCollisionSafeVirtualSteeringVec(FVector InputVector, FVector CollisionVector = TraceResult.Location - CapsuleLocation; //sometimes (if by chance we already moved into collision entirely CollisionVector is 0 - if(!CollisionVector.Normalize()) + if (!CollisionVector.Normalize()) { //then we probably start already in collision, so we use the last one CollisionVector = LastSteeringCollisionVector; @@ -199,8 +200,8 @@ FVector UVRPawnMovement::GetCollisionSafeVirtualSteeringVec(FVector InputVector, } FVector SafeInput = InputVector; - const float DotProduct = FVector::DotProduct(InputVector, CollisionVector); - if(DotProduct>0.0f) + const float DotProduct = FVector::DotProduct(InputVector, CollisionVector); + if (DotProduct > 0.0f) { // only keep perpendicular part of the input vector (remove anything towards hit) SafeInput -= DotProduct * CollisionVector; @@ -212,36 +213,36 @@ void UVRPawnMovement::MoveByGravityOrStepUp(float DeltaSeconds) { const FVector DownTraceStart = CapsuleColliderComponent->GetComponentLocation(); const float DownTraceDist = MaxFallingDepth < 0.0f ? 1000.0f : MaxFallingDepth; - const FVector DownTraceDir = FVector(0,0,-1); + const FVector DownTraceDir = FVector(0, 0, -1); const FVector DownTraceEnd = DownTraceStart + DownTraceDist * DownTraceDir; const FHitResult DownTraceHitResult = CreateCapsuleTrace(DownTraceStart, DownTraceEnd); float HeightDifference = 0.0f; - if(DownTraceHitResult.bBlockingHit) + if (DownTraceHitResult.bBlockingHit) { HeightDifference = DownTraceHitResult.ImpactPoint.Z - UpdatedComponent->GetComponentLocation().Z; //so for HeightDifference>0, we have to move the pawn up; for HeightDifference<0 we have to move it down } //Going up (in Fly and Walk Mode) - if (HeightDifference>0.0f && HeightDifference<=MaxStepHeight) + if (HeightDifference > 0.0f && HeightDifference <= MaxStepHeight) { ShiftVertically(HeightDifference, UpSteppingAcceleration, DeltaSeconds); } - if(NavigationMode!=EVRNavigationModes::NAV_WALK) + if (NavigationMode != EVRNavigationModes::NAV_WALK) { return; } - if(!DownTraceHitResult.bBlockingHit && MaxFallingDepth<0.0f) + if (!DownTraceHitResult.bBlockingHit && MaxFallingDepth < 0.0f) { HeightDifference = -1000.0f; //just fall } //Gravity (only in Walk Mode) - if (HeightDifference<0.0f) + if (HeightDifference < 0.0f) { ShiftVertically(HeightDifference, GravityAcceleration, DeltaSeconds); } @@ -250,25 +251,28 @@ void UVRPawnMovement::MoveByGravityOrStepUp(float DeltaSeconds) void UVRPawnMovement::ShiftVertically(float Distance, float VerticalAcceleration, float DeltaSeconds) { VerticalSpeed += VerticalAcceleration * DeltaSeconds; - if (abs(VerticalSpeed*DeltaSeconds) < abs(Distance)) + if (abs(VerticalSpeed * DeltaSeconds) < abs(Distance)) { - UpdatedComponent->AddWorldOffset(FVector(0.f, 0.f, VerticalSpeed * DeltaSeconds)); + UpdatedComponent->AddWorldOffset(FVector(0.f, 0.f, VerticalSpeed * DeltaSeconds)); } else { - UpdatedComponent->AddWorldOffset(FVector(0.f, 0.f, Distance)); + UpdatedComponent->AddWorldOffset(FVector(0.f, 0.f, Distance)); VerticalSpeed = 0; } } -FHitResult UVRPawnMovement::CreateCapsuleTrace(const FVector Start, FVector End, bool DrawDebug) +FHitResult UVRPawnMovement::CreateCapsuleTrace(const FVector& Start, const FVector& End, const bool DrawDebug) const { const EDrawDebugTrace::Type DrawType = DrawDebug ? EDrawDebugTrace::Type::ForDuration : EDrawDebugTrace::Type::None; //UE_LOG(LogTemp, Warning, TEXT("Capsule from %s to %s"), *Start.ToString(), *End.ToString()) FHitResult Hit; - UKismetSystemLibrary::CapsuleTraceSingle(GetWorld(), Start, End, CapsuleColliderComponent->GetScaledCapsuleRadius(), CapsuleColliderComponent->GetScaledCapsuleHalfHeight(), UEngineTypes::ConvertToTraceType(ECollisionChannel::ECC_Visibility), true, ActorsToIgnore, DrawType, Hit, true); + UKismetSystemLibrary::CapsuleTraceSingle(GetWorld(), Start, End, CapsuleColliderComponent->GetScaledCapsuleRadius(), + CapsuleColliderComponent->GetScaledCapsuleHalfHeight(), + UEngineTypes::ConvertToTraceType(ECollisionChannel::ECC_Visibility), true, + ActorsToIgnore, DrawType, Hit, true); return Hit; } @@ -277,15 +281,19 @@ FVector UVRPawnMovement::GetOverlapResolveDirection() TArray<UPrimitiveComponent*> OverlappingComponents; TArray<TEnumAsByte<EObjectTypeQuery>> traceObjectTypes; traceObjectTypes.Add(UEngineTypes::ConvertToObjectType(ECollisionChannel::ECC_Visibility)); - UKismetSystemLibrary::CapsuleOverlapComponents(GetWorld(), CapsuleColliderComponent->GetComponentLocation(), CapsuleColliderComponent->GetScaledCapsuleRadius(), CapsuleColliderComponent->GetScaledCapsuleHalfHeight(), traceObjectTypes, nullptr, ActorsToIgnore, OverlappingComponents); + UKismetSystemLibrary::CapsuleOverlapComponents(GetWorld(), CapsuleColliderComponent->GetComponentLocation(), + CapsuleColliderComponent->GetScaledCapsuleRadius(), + CapsuleColliderComponent->GetScaledCapsuleHalfHeight(), + traceObjectTypes, nullptr, ActorsToIgnore, OverlappingComponents); FVector ResolveVector = FVector::ZeroVector; //check what to do to move out of these collisions (or nothing if non is there) //we just add the penetrations so in very unfortunate conditions this can become problematic/blocking but for now and our regular use cases this works - for(const UPrimitiveComponent* OverlappingComp : OverlappingComponents) + for (const UPrimitiveComponent* OverlappingComp : OverlappingComponents) { - FHitResult Hit = CreateCapsuleTrace(CapsuleColliderComponent->GetComponentLocation(), OverlappingComp->GetComponentLocation(), false); + FHitResult Hit = CreateCapsuleTrace(CapsuleColliderComponent->GetComponentLocation(), + OverlappingComp->GetComponentLocation(), false); ResolveVector += Hit.ImpactNormal * Hit.PenetrationDepth; } return ResolveVector; diff --git a/Source/RWTHVRToolkit/Private/RWTHVRToolkit.cpp b/Source/RWTHVRToolkit/Private/RWTHVRToolkit.cpp index c335e156..6e2fa82b 100644 --- a/Source/RWTHVRToolkit/Private/RWTHVRToolkit.cpp +++ b/Source/RWTHVRToolkit/Private/RWTHVRToolkit.cpp @@ -2,18 +2,18 @@ #define LOCTEXT_NAMESPACE "FRWTHVRToolkitModule" -void FRWTHVRToolkitModule::StartupModule () +void FRWTHVRToolkitModule::StartupModule() { - IModularFeatures& ModularFeatures = IModularFeatures::Get(); if (ModularFeatures.IsModularFeatureAvailable(ILiveLinkClient::ModularFeatureName)) { - FLiveLinkClient* LiveLinkClient = static_cast<FLiveLinkClient*>(&IModularFeatures::Get().GetModularFeature<ILiveLinkClient>( + FLiveLinkClient* LiveLinkClient = static_cast<FLiveLinkClient*>(&IModularFeatures::Get().GetModularFeature< + ILiveLinkClient>( ILiveLinkClient::ModularFeatureName)); LiveLinkMotionController = MakeUnique<FLiveLinkMotionControllerFix>(*LiveLinkClient); LiveLinkMotionController->RegisterController(); } - + ConsoleActivation.Register(); } @@ -24,7 +24,6 @@ void FRWTHVRToolkitModule::ShutdownModule() LiveLinkMotionController->UnregisterController(); } - #undef LOCTEXT_NAMESPACE -IMPLEMENT_MODULE(FRWTHVRToolkitModule, RWTHVRToolkit) \ No newline at end of file +IMPLEMENT_MODULE(FRWTHVRToolkitModule, RWTHVRToolkit) diff --git a/Source/RWTHVRToolkit/Private/UI/ExternalImage.cpp b/Source/RWTHVRToolkit/Private/UI/ExternalImage.cpp index 07a57faa..378aa325 100644 --- a/Source/RWTHVRToolkit/Private/UI/ExternalImage.cpp +++ b/Source/RWTHVRToolkit/Private/UI/ExternalImage.cpp @@ -1,43 +1,45 @@ #include "UI/ExternalImage.h" -#include "Interfaces/IHttpResponse.h" #include "HttpModule.h" +#include "Interfaces/IHttpResponse.h" #include "Misc/FileHelper.h" #include "Runtime/ImageWrapper/Public/IImageWrapperModule.h" -UExternalImage::UExternalImage(){} +UExternalImage::UExternalImage() +{ +} void UExternalImage::LoadImageFromURL(const FString& ImageURL) { - const TFunction<void()> LoadingCallback = [this]() - { - if (LoadCompressedDataIntoTexture2D(CompressedData, NewTexture)) - { - UImage::SetBrushFromTexture(NewTexture, true); - } + const TFunction<void()> LoadingCallback = [this]() + { + if (LoadCompressedDataIntoTexture2D(CompressedData, NewTexture)) + { + UImage::SetBrushFromTexture(NewTexture, true); + } - CompressedData.Empty(); - }; + CompressedData.Empty(); + }; - if (FPaths::FileExists(ImageURL)) - { - LoadDataFromFile(ImageURL, CompressedData, LoadingCallback); - } - else - { - LoadDataFromURL(ImageURL, CompressedData, LoadingCallback); - } + if (FPaths::FileExists(ImageURL)) + { + LoadDataFromFile(ImageURL, CompressedData, LoadingCallback); + } + else + { + LoadDataFromURL(ImageURL, CompressedData, LoadingCallback); + } } bool UExternalImage::LoadCompressedDataIntoTexture2D(const TArray<uint8>& InCompressedData, UTexture2D*& OutTexture) { - TSharedPtr<IImageWrapper> ImageWrapper; - TArray<uint8> UncompressedRGBA; + TSharedPtr<IImageWrapper> ImageWrapper; + TArray<uint8> UncompressedRGBA; - /* Detect Format */ - IImageWrapperModule& Module = FModuleManager::LoadModuleChecked<IImageWrapperModule>(FName("ImageWrapper")); + /* Detect Format */ + IImageWrapperModule& Module = FModuleManager::LoadModuleChecked<IImageWrapperModule>(FName("ImageWrapper")); const EImageFormat DetectedFormat = Module.DetectImageFormat(InCompressedData.GetData(), InCompressedData.Num()); - if (DetectedFormat != EImageFormat::Invalid) + if (DetectedFormat != EImageFormat::Invalid) { ImageWrapper = Module.CreateImageWrapper(DetectedFormat); } @@ -47,56 +49,60 @@ bool UExternalImage::LoadCompressedDataIntoTexture2D(const TArray<uint8>& InComp return false; } - /* Decompress Data */ - if (!ImageWrapper.IsValid() || !ImageWrapper->SetCompressed(InCompressedData.GetData(), InCompressedData.Num())) - { - UE_LOG(LogTemp, Warning, TEXT("UExternalyLoadedImage is not able to decompress the image.")); - return false; - } + /* Decompress Data */ + if (!ImageWrapper.IsValid() || !ImageWrapper->SetCompressed(InCompressedData.GetData(), InCompressedData.Num())) + { + UE_LOG(LogTemp, Warning, TEXT("UExternalyLoadedImage is not able to decompress the image.")); + return false; + } - /* Write out data into decompressed array - * Must be in BGRA channel format, otherwise the jpg format file cannot be loaded correctly */ - if (!ImageWrapper->GetRaw(ERGBFormat::BGRA, 8, UncompressedRGBA)) - { - UE_LOG(LogTemp, Warning, TEXT("UExternalyLoadedImage is not able to write out the decompressed image.")); - return false; - } + /* Write out data into decompressed array + * Must be in BGRA channel format, otherwise the jpg format file cannot be loaded correctly */ + if (!ImageWrapper->GetRaw(ERGBFormat::BGRA, 8, UncompressedRGBA)) + { + UE_LOG(LogTemp, Warning, TEXT("UExternalyLoadedImage is not able to write out the decompressed image.")); + return false; + } - OutTexture = UTexture2D::CreateTransient(ImageWrapper->GetWidth(), ImageWrapper->GetHeight(), PF_B8G8R8A8); - if (OutTexture) - { - void* TextureData = OutTexture->GetPlatformData()->Mips[0].BulkData.Lock(LOCK_READ_WRITE); - FMemory::Memcpy(TextureData, UncompressedRGBA.GetData(), UncompressedRGBA.Num()); - OutTexture->GetPlatformData()->Mips[0].BulkData.Unlock(); - OutTexture->UpdateResource(); - } - return true; + OutTexture = UTexture2D::CreateTransient(ImageWrapper->GetWidth(), ImageWrapper->GetHeight(), PF_B8G8R8A8); + if (OutTexture) + { + void* TextureData = OutTexture->GetPlatformData()->Mips[0].BulkData.Lock(LOCK_READ_WRITE); + FMemory::Memcpy(TextureData, UncompressedRGBA.GetData(), UncompressedRGBA.Num()); + OutTexture->GetPlatformData()->Mips[0].BulkData.Unlock(); + OutTexture->UpdateResource(); + } + return true; } -void UExternalImage::LoadDataFromURL(const FString& ImageURL, TArray<uint8>& OutCompressedData, TFunction<void()> OnSuccessCallback) +void UExternalImage::LoadDataFromURL(const FString& ImageURL, TArray<uint8>& OutCompressedData, + TFunction<void()> OnSuccessCallback) { - TSharedRef<IHttpRequest, ESPMode::ThreadSafe> Request = FHttpModule::Get().CreateRequest(); + TSharedRef<IHttpRequest, ESPMode::ThreadSafe> Request = FHttpModule::Get().CreateRequest(); - Request->OnProcessRequestComplete().BindLambda([OnSuccessCallback, &OutCompressedData](FHttpRequestPtr Request, FHttpResponsePtr Response, bool) - { - if (Response.IsValid() && EHttpResponseCodes::IsOk(Response->GetResponseCode())) + Request->OnProcessRequestComplete().BindLambda( + [OnSuccessCallback, &OutCompressedData](FHttpRequestPtr Request, FHttpResponsePtr Response, bool) { - OutCompressedData.Empty(); - OutCompressedData.Append(Response->GetContent()); - OnSuccessCallback(); - } - else - { - UE_LOG(LogTemp, Log, TEXT("UExternalyLoadedImage Request unsucessful (%d): %s"), Response->GetResponseCode(), *Request->GetURL()); - } - }); + if (Response.IsValid() && EHttpResponseCodes::IsOk(Response->GetResponseCode())) + { + OutCompressedData.Empty(); + OutCompressedData.Append(Response->GetContent()); + OnSuccessCallback(); + } + else + { + UE_LOG(LogTemp, Log, TEXT("UExternalyLoadedImage Request unsucessful (%d): %s"), + Response->GetResponseCode(), *Request->GetURL()); + } + }); Request->SetVerb("GET"); Request->SetURL(ImageURL); Request->ProcessRequest(); } -void UExternalImage::LoadDataFromFile(const FString& ImagePath, TArray<uint8>& OutCompressedData, TFunction<void()> OnSuccessCallback) +void UExternalImage::LoadDataFromFile(const FString& ImagePath, TArray<uint8>& OutCompressedData, + TFunction<void()> OnSuccessCallback) { - if(FFileHelper::LoadFileToArray(OutCompressedData, *ImagePath)) OnSuccessCallback(); + if (FFileHelper::LoadFileToArray(OutCompressedData, *ImagePath)) OnSuccessCallback(); } diff --git a/Source/RWTHVRToolkit/Private/Utility/VirtualRealityUtilities.cpp b/Source/RWTHVRToolkit/Private/Utility/VirtualRealityUtilities.cpp index 2445caca..5653faff 100644 --- a/Source/RWTHVRToolkit/Private/Utility/VirtualRealityUtilities.cpp +++ b/Source/RWTHVRToolkit/Private/Utility/VirtualRealityUtilities.cpp @@ -1,24 +1,21 @@ #include "Utility/VirtualRealityUtilities.h" #if PLATFORM_SUPPORTS_NDISPLAY - #include "Cluster/IDisplayClusterClusterManager.h" - #include "Components/DisplayClusterCameraComponent.h" - #include "Config/IDisplayClusterConfigManager.h" - #include "DisplayClusterRootActor.h" - #include "DisplayClusterConfigurationTypes.h" - #include "Game/IDisplayClusterGameManager.h" - #include "IDisplayCluster.h" +#include "DisplayClusterConfigurationTypes.h" +#include "DisplayClusterRootActor.h" +#include "IDisplayCluster.h" +#include "Cluster/IDisplayClusterClusterManager.h" +#include "Components/DisplayClusterCameraComponent.h" +#include "Config/IDisplayClusterConfigManager.h" +#include "Game/IDisplayClusterGameManager.h" #endif -#include "Engine/Engine.h" -#include "IXRTrackingSystem.h" -#include "IHeadMountedDisplay.h" #include "AudioDevice.h" -#include "EnhancedInputComponent.h" -#include "EnhancedInputSubsystems.h" +#include "IHeadMountedDisplay.h" +#include "IXRTrackingSystem.h" +#include "Engine/Engine.h" #include "Engine/LocalPlayer.h" #include "Kismet/GameplayStatics.h" -#include "Pawn/VirtualRealityPawn.h" DEFINE_LOG_CATEGORY(Toolkit); @@ -47,8 +44,8 @@ bool UVirtualRealityUtilities::IsHeadMountedMode() bool UVirtualRealityUtilities::IsCave() { #if PLATFORM_SUPPORTS_NDISPLAY - if(!IsRoomMountedMode()) return false; - + if (!IsRoomMountedMode()) return false; + const UDisplayClusterConfigurationData* ClusterConfig = IDisplayCluster::Get().GetConfigMgr()->GetConfig(); return ClusterConfig->CustomParameters.Contains("Hardware_Platform") && ClusterConfig->CustomParameters.Find("Hardware_Platform")->Equals("aixcave", ESearchCase::IgnoreCase); @@ -60,11 +57,12 @@ bool UVirtualRealityUtilities::IsCave() bool UVirtualRealityUtilities::IsTdw() { #if PLATFORM_SUPPORTS_NDISPLAY - if(!IsRoomMountedMode()) return false; - + if (!IsRoomMountedMode()) return false; + const UDisplayClusterConfigurationData* ClusterConfig = IDisplayCluster::Get().GetConfigMgr()->GetConfig(); return ClusterConfig->CustomParameters.Contains("Hardware_Platform") - && ClusterConfig->CustomParameters.Find("Hardware_Platform")->Equals("TiledDisplayWall", ESearchCase::IgnoreCase); + && ClusterConfig->CustomParameters.Find("Hardware_Platform")->Equals( + "TiledDisplayWall", ESearchCase::IgnoreCase); #else return false; #endif @@ -73,8 +71,8 @@ bool UVirtualRealityUtilities::IsTdw() bool UVirtualRealityUtilities::IsRolv() { #if PLATFORM_SUPPORTS_NDISPLAY - if(!IsRoomMountedMode()) return false; - + if (!IsRoomMountedMode()) return false; + const UDisplayClusterConfigurationData* ClusterConfig = IDisplayCluster::Get().GetConfigMgr()->GetConfig(); return ClusterConfig->CustomParameters.Contains("Hardware_Platform") && ClusterConfig->CustomParameters.Find("Hardware_Platform")->Equals("ROLV", ESearchCase::IgnoreCase); @@ -87,7 +85,7 @@ bool UVirtualRealityUtilities::IsRolv() bool UVirtualRealityUtilities::IsMaster() { #if PLATFORM_SUPPORTS_NDISPLAY - if (!IDisplayCluster::IsAvailable()) + if (!IDisplayCluster::IsAvailable()) { return true; } @@ -118,15 +116,15 @@ FString UVirtualRealityUtilities::GetNodeName() float UVirtualRealityUtilities::GetEyeDistance() { - if(IsHeadMountedMode()) + if (IsHeadMountedMode()) { - return GEngine->XRSystem->GetHMDDevice()->GetInterpupillaryDistance(); + return GEngine->XRSystem->GetHMDDevice()->GetInterpupillaryDistance(); } - else + else { #if PLATFORM_SUPPORTS_NDISPLAY - ADisplayClusterRootActor* RootActor = IDisplayCluster::Get().GetGameMgr()->GetRootActor(); - return (RootActor) ? RootActor->GetDefaultCamera()->GetInterpupillaryDistance() : 0.0f; + ADisplayClusterRootActor* RootActor = IDisplayCluster::Get().GetGameMgr()->GetRootActor(); + return (RootActor) ? RootActor->GetDefaultCamera()->GetInterpupillaryDistance() : 0.0f; #else return 0.0f; #endif @@ -137,7 +135,9 @@ EEyeStereoOffset UVirtualRealityUtilities::GetNodeEyeType() { #if PLATFORM_SUPPORTS_NDISPLAY ADisplayClusterRootActor* RootActor = IDisplayCluster::Get().GetGameMgr()->GetRootActor(); - return static_cast<EEyeStereoOffset>((RootActor) ? RootActor->GetDefaultCamera()->GetStereoOffset() : EDisplayClusterEyeStereoOffset::None); + return static_cast<EEyeStereoOffset>((RootActor) + ? RootActor->GetDefaultCamera()->GetStereoOffset() + : EDisplayClusterEyeStereoOffset::None); #else return EDisplayClusterEyeStereoOffset::None; #endif @@ -146,7 +146,7 @@ EEyeStereoOffset UVirtualRealityUtilities::GetNodeEyeType() USceneComponent* UVirtualRealityUtilities::GetClusterComponent(const FString& Name) { #if PLATFORM_SUPPORTS_NDISPLAY - ADisplayClusterRootActor* RootActor = IDisplayCluster::Get().GetGameMgr()->GetRootActor(); + const ADisplayClusterRootActor* RootActor = IDisplayCluster::Get().GetGameMgr()->GetRootActor(); return (RootActor) ? RootActor->GetComponentByName<USceneComponent>(Name) : nullptr; #else return nullptr; @@ -155,7 +155,7 @@ USceneComponent* UVirtualRealityUtilities::GetClusterComponent(const FString& Na USceneComponent* UVirtualRealityUtilities::GetNamedClusterComponent(const ENamedClusterComponent& Component) { - switch(Component) + switch (Component) { case ENamedClusterComponent::NCC_CAVE_ORIGIN: return GetClusterComponent("cave_origin"); case ENamedClusterComponent::NCC_CAVE_CENTER: return GetClusterComponent("cave_center"); @@ -169,9 +169,9 @@ USceneComponent* UVirtualRealityUtilities::GetNamedClusterComponent(const ENamed case ENamedClusterComponent::NCC_CALIBRATIO: return GetClusterComponent("calibratio"); case ENamedClusterComponent::NCC_TRACKING_ORIGIN: USceneComponent* Result; - if((Result = GetClusterComponent("cave_origin"))) return Result; - if((Result = GetClusterComponent("rolv_origin"))) return Result; - if((Result = GetClusterComponent("tdw_origin_floor"))) return Result; + if ((Result = GetClusterComponent("cave_origin"))) return Result; + if ((Result = GetClusterComponent("rolv_origin"))) return Result; + if ((Result = GetClusterComponent("tdw_origin_floor"))) return Result; return nullptr; default: return nullptr; } @@ -185,5 +185,4 @@ void UVirtualRealityUtilities::ShowErrorAndQuit(UWorld* WorldContext, const FStr FMessageDialog::Open(EAppMsgType::Ok, FText::FromString(Message), Title); #endif UKismetSystemLibrary::QuitGame(WorldContext, nullptr, EQuitPreference::Quit, false); - } diff --git a/Source/RWTHVRToolkit/Public/Core/ClientTransformReplication.h b/Source/RWTHVRToolkit/Public/Core/ClientTransformReplication.h index 347a8335..472a4f45 100644 --- a/Source/RWTHVRToolkit/Public/Core/ClientTransformReplication.h +++ b/Source/RWTHVRToolkit/Public/Core/ClientTransformReplication.h @@ -11,7 +11,7 @@ /* * Simple Client Transform Replication Component. Replicates the owning actor's root transform from owning client to server, * from there to all other clients. -*/ +*/ UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent)) class RWTHVRTOOLKIT_API UClientTransformReplication : public UActorComponent { @@ -21,7 +21,6 @@ public: UClientTransformReplication(); protected: - /* * For now, replicate in a naive sending every x ms if the transform has changed. * This is way overkill, as we should only be sending input. However, I am not yet fully sure how @@ -29,14 +28,15 @@ protected: * As this modifies only the tracking origin, latency should not be that much of an issue, so theoretically * Server-Authority should work here too, in which case we'd just send the x and y input. * Try both ways. - */ - + */ + ///////////////////////////////////////////////////////////////////////////////////////////////////// // Full transform update replication ///////////////////////////////////////////////////////////////////////////////////////////////////// // Rate to update the position to the server, 100htz is default (same as replication rate, should also hit every tick). - UPROPERTY(EditAnywhere, BlueprintReadWrite, Replicated, Category = "Networking", meta = (ClampMin = "0", UIMin = "0")) + UPROPERTY(EditAnywhere, BlueprintReadWrite, Replicated, Category = "Networking", + meta = (ClampMin = "0", UIMin = "0")) float ControllerNetUpdateRate; // Accumulates time until next send diff --git a/Source/RWTHVRToolkit/Public/Core/RWTHVRGameModeBase.h b/Source/RWTHVRToolkit/Public/Core/RWTHVRGameModeBase.h index ba4db020..9e84c8aa 100644 --- a/Source/RWTHVRToolkit/Public/Core/RWTHVRGameModeBase.h +++ b/Source/RWTHVRToolkit/Public/Core/RWTHVRGameModeBase.h @@ -18,5 +18,5 @@ class RWTHVRTOOLKIT_API ARWTHVRGameModeBase : public AGameModeBase protected: virtual FString InitNewPlayer(APlayerController* NewPlayerController, const FUniqueNetIdRepl& UniqueId, - const FString& Options, const FString& Portal) override; + const FString& Options, const FString& Portal) override; }; diff --git a/Source/RWTHVRToolkit/Public/Core/RWTHVRPlayerState.h b/Source/RWTHVRToolkit/Public/Core/RWTHVRPlayerState.h index 4f9cc9d5..cc453e4c 100644 --- a/Source/RWTHVRToolkit/Public/Core/RWTHVRPlayerState.h +++ b/Source/RWTHVRToolkit/Public/Core/RWTHVRPlayerState.h @@ -28,12 +28,11 @@ private: void SetPlayerType(EPlayerType NewPlayerType); public: - UFUNCTION(BlueprintGetter) EPlayerType GetPlayerType() const { return PlayerType; - } + } UFUNCTION(BlueprintCallable) void RequestSetPlayerType(EPlayerType NewPlayerType); @@ -41,5 +40,5 @@ public: virtual void CopyProperties(APlayerState* PlayerState) override; virtual void OverrideWith(APlayerState* PlayerState) override; - virtual void GetLifetimeReplicatedProps(TArray< FLifetimeProperty > & OutLifetimeProps) const override; + virtual void GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const override; }; diff --git a/Source/RWTHVRToolkit/Public/Fixes/ActivateConsoleInShipping.h b/Source/RWTHVRToolkit/Public/Fixes/ActivateConsoleInShipping.h index ae673625..140b0544 100644 --- a/Source/RWTHVRToolkit/Public/Fixes/ActivateConsoleInShipping.h +++ b/Source/RWTHVRToolkit/Public/Fixes/ActivateConsoleInShipping.h @@ -14,7 +14,7 @@ struct RWTHVRTOOLKIT_API FActivateConsoleInShipping void Register(); void Unregister() const; - + private: void OnSessionStart(UWorld*, const UWorld::InitializationValues) const; diff --git a/Source/RWTHVRToolkit/Public/Fixes/LiveLinkMotionControllerFix.h b/Source/RWTHVRToolkit/Public/Fixes/LiveLinkMotionControllerFix.h index 208a0ad0..ad6e78c1 100644 --- a/Source/RWTHVRToolkit/Public/Fixes/LiveLinkMotionControllerFix.h +++ b/Source/RWTHVRToolkit/Public/Fixes/LiveLinkMotionControllerFix.h @@ -33,7 +33,10 @@ class FLiveLinkMotionControllerFix : public IMotionController // MotionSource name for interacting with Motion Controller system FName MotionSource; - FLiveLinkMotionControllerEnumeratedSource(const FLiveLinkSubjectKey& Key, FName MotionSourceName) : SubjectKey(Key), MotionSource(MotionSourceName) {} + FLiveLinkMotionControllerEnumeratedSource(const FLiveLinkSubjectKey& Key, FName MotionSourceName) : + SubjectKey(Key), MotionSource(MotionSourceName) + { + } }; // Built array of Live Link Sources to give to Motion Controller system @@ -41,9 +44,10 @@ class FLiveLinkMotionControllerFix : public IMotionController public: FLiveLinkMotionControllerFix(FLiveLinkClient& InClient) : Client(InClient) - { + { BuildSourceData(); - OnSubjectsChangedHandle = Client.OnLiveLinkSubjectsChanged().AddRaw(this, &FLiveLinkMotionControllerFix::OnSubjectsChangedHandler); + OnSubjectsChangedHandle = Client.OnLiveLinkSubjectsChanged().AddRaw( + this, &FLiveLinkMotionControllerFix::OnSubjectsChangedHandler); WildcardSource = FGuid::NewGuid(); } @@ -63,14 +67,17 @@ public: IModularFeatures::Get().UnregisterModularFeature(GetModularFeatureName(), this); } - virtual bool GetControllerOrientationAndPosition(const int32 ControllerIndex, const FName MotionSource, FRotator& OutOrientation, FVector& OutPosition, float) const override + virtual bool GetControllerOrientationAndPosition(const int32 ControllerIndex, const FName MotionSource, + FRotator& OutOrientation, FVector& OutPosition, + float) const override { FLiveLinkSubjectKey SubjectKey = GetSubjectKeyFromMotionSource(MotionSource); FLiveLinkSubjectFrameData FrameData; if (Client.EvaluateFrame_AnyThread(SubjectKey.SubjectName, ULiveLinkTransformRole::StaticClass(), FrameData)) { - if (FLiveLinkTransformFrameData* TransformFrameData = FrameData.FrameData.Cast<FLiveLinkTransformFrameData>()) + if (FLiveLinkTransformFrameData* TransformFrameData = FrameData.FrameData.Cast< + FLiveLinkTransformFrameData>()) { OutPosition = TransformFrameData->Transform.GetLocation(); OutOrientation = TransformFrameData->Transform.GetRotation().Rotator(); @@ -80,21 +87,39 @@ public: return false; } - virtual bool GetControllerOrientationAndPosition(const int32 ControllerIndex, const FName MotionSource, FRotator& OutOrientation, FVector& OutPosition, bool& OutbProvidedLinearVelocity, FVector& OutLinearVelocity, bool& OutbProvidedAngularVelocity, FVector& OutAngularVelocityAsAxisAndLength, bool& OutbProvidedLinearAcceleration, FVector& OutLinearAcceleration, float WorldToMetersScale) const override + virtual bool GetControllerOrientationAndPosition(const int32 ControllerIndex, const FName MotionSource, + FRotator& OutOrientation, FVector& OutPosition, + bool& OutbProvidedLinearVelocity, FVector& OutLinearVelocity, + bool& OutbProvidedAngularVelocity, + FVector& OutAngularVelocityAsAxisAndLength, + bool& OutbProvidedLinearAcceleration, + FVector& OutLinearAcceleration, + float WorldToMetersScale) const override { OutbProvidedLinearVelocity = false; OutbProvidedAngularVelocity = false; OutbProvidedLinearAcceleration = false; - return GetControllerOrientationAndPosition(ControllerIndex, MotionSource, OutOrientation, OutPosition, WorldToMetersScale); + return GetControllerOrientationAndPosition(ControllerIndex, MotionSource, OutOrientation, OutPosition, + WorldToMetersScale); } - - virtual bool GetControllerOrientationAndPositionForTime(const int32 ControllerIndex, const FName MotionSource, FTimespan Time, bool& OutTimeWasUsed, FRotator& OutOrientation, FVector& OutPosition, bool& OutbProvidedLinearVelocity, FVector& OutLinearVelocity, bool& OutbProvidedAngularVelocity, FVector& OutAngularVelocityAsAxisAndLength, bool& OutbProvidedLinearAcceleration, FVector& OutLinearAcceleration, float WorldToMetersScale) const override + + virtual bool GetControllerOrientationAndPositionForTime(const int32 ControllerIndex, const FName MotionSource, + FTimespan Time, bool& OutTimeWasUsed, + FRotator& OutOrientation, FVector& OutPosition, + bool& OutbProvidedLinearVelocity, + FVector& OutLinearVelocity, + bool& OutbProvidedAngularVelocity, + FVector& OutAngularVelocityAsAxisAndLength, + bool& OutbProvidedLinearAcceleration, + FVector& OutLinearAcceleration, + float WorldToMetersScale) const override { OutTimeWasUsed = false; OutbProvidedLinearVelocity = false; OutbProvidedAngularVelocity = false; OutbProvidedLinearAcceleration = false; - return GetControllerOrientationAndPosition(ControllerIndex, MotionSource, OutOrientation, OutPosition, WorldToMetersScale); + return GetControllerOrientationAndPosition(ControllerIndex, MotionSource, OutOrientation, OutPosition, + WorldToMetersScale); } float GetCustomParameterValue(const FName MotionSource, FName ParameterName, bool& bValueFound) const override @@ -121,7 +146,8 @@ public: return 0.f; } - virtual ETrackingStatus GetControllerTrackingStatus(const int32 ControllerIndex, const FName MotionSource) const override + virtual ETrackingStatus + GetControllerTrackingStatus(const int32 ControllerIndex, const FName MotionSource) const override { FLiveLinkSubjectKey SubjectKey = GetSubjectKeyFromMotionSource(MotionSource); @@ -163,13 +189,18 @@ public: for (const FGuid& Source : SourceGuids) { - FText SourceName = (Source == WildcardSource) ? LOCTEXT("LiveLinkAnySource", "Any") : Client.GetSourceType(Source); + FText SourceName = (Source == WildcardSource) + ? LOCTEXT("LiveLinkAnySource", "Any") + : Client.GetSourceType(Source); Headers.Emplace(Source, SourceName); } { FGuid& CaptureWildcardSource = WildcardSource; - Headers.Sort([CaptureWildcardSource](const FHeaderEntry& A, const FHeaderEntry& B) { return A.Key == CaptureWildcardSource || A.Value.CompareToCaseIgnored(B.Value) <= 0; }); + Headers.Sort([CaptureWildcardSource](const FHeaderEntry& A, const FHeaderEntry& B) + { + return A.Key == CaptureWildcardSource || A.Value.CompareToCaseIgnored(B.Value) <= 0; + }); } //Build EnumeratedSources data @@ -182,7 +213,7 @@ public: Subjects.Sort(FNameLexicalLess()); for (FName Subject : Subjects) { - FName FullName = *FString::Format(TEXT("{0} ({1})"), { Subject.ToString(), Header.Value.ToString() }); + FName FullName = *FString::Format(TEXT("{0} ({1})"), {Subject.ToString(), Header.Value.ToString()}); EnumeratedSources.Emplace(FLiveLinkSubjectKey(Header.Key, Subject), FullName); } } @@ -201,12 +232,16 @@ public: } } - virtual bool GetHandJointPosition(const FName MotionSource, int jointIndex, FVector& OutPosition) const override { return false; } + virtual bool GetHandJointPosition(const FName MotionSource, int jointIndex, FVector& OutPosition) const override + { + return false; + } private: FLiveLinkSubjectKey GetSubjectKeyFromMotionSource(FName MotionSource) const { - const FLiveLinkMotionControllerEnumeratedSource* EnumeratedSource = EnumeratedSources.FindByPredicate([&](const FLiveLinkMotionControllerEnumeratedSource& Item) { return Item.MotionSource == MotionSource; }); + const FLiveLinkMotionControllerEnumeratedSource* EnumeratedSource = EnumeratedSources.FindByPredicate( + [&](const FLiveLinkMotionControllerEnumeratedSource& Item) { return Item.MotionSource == MotionSource; }); if (EnumeratedSource) { return EnumeratedSource->SubjectKey; diff --git a/Source/RWTHVRToolkit/Public/Interaction/ClickBehaviour.h b/Source/RWTHVRToolkit/Public/Interaction/ClickBehaviour.h index 435d852a..c2116085 100644 --- a/Source/RWTHVRToolkit/Public/Interaction/ClickBehaviour.h +++ b/Source/RWTHVRToolkit/Public/Interaction/ClickBehaviour.h @@ -8,33 +8,36 @@ #include "ClickBehaviour.generated.h" +DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FOnClickStart, USceneComponent*, TriggeredComponent, + const FInputActionValue&, Value); -DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FOnClickStart, USceneComponent*, TriggeredComponent, const FInputActionValue&, Value); -DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FOnClicktEnd, USceneComponent*, TriggeredComponent, const FInputActionValue&, Value); +DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FOnClicktEnd, USceneComponent*, TriggeredComponent, + const FInputActionValue&, Value); -UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) ) +UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent)) class RWTHVRTOOLKIT_API UClickBehaviour : public USceneComponent { GENERATED_BODY() -public: +public: // Sets default values for this component's properties UClickBehaviour(); UPROPERTY(BlueprintAssignable) - FOnClickStart OnClickStartEvent; + FOnClickStart OnClickStartEvent; + UPROPERTY(BlueprintAssignable) - FOnClicktEnd OnClickEndEvent; + FOnClicktEnd OnClickEndEvent; protected: UFUNCTION() - virtual void OnClickStart(USceneComponent* TriggeredComponent,const FInputActionValue& Value); - UFUNCTION() - virtual void OnClickEnd(USceneComponent* TriggeredComponent,const FInputActionValue& Value); + virtual void OnClickStart(USceneComponent* TriggeredComponent, const FInputActionValue& Value); + UFUNCTION() + virtual void OnClickEnd(USceneComponent* TriggeredComponent, const FInputActionValue& Value); + virtual void BeginPlay() override; - - virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override; - + virtual void TickComponent(float DeltaTime, ELevelTick TickType, + FActorComponentTickFunction* ThisTickFunction) override; }; diff --git a/Source/RWTHVRToolkit/Public/Interaction/Clickable.h b/Source/RWTHVRToolkit/Public/Interaction/Clickable.h index 1382df77..f7ec15ba 100644 --- a/Source/RWTHVRToolkit/Public/Interaction/Clickable.h +++ b/Source/RWTHVRToolkit/Public/Interaction/Clickable.h @@ -11,16 +11,15 @@ UINTERFACE(BlueprintType) class RWTHVRTOOLKIT_API UClickable : public UInterface { // has to be empty, this is Unreals syntax to make it visible in blueprints - GENERATED_UINTERFACE_BODY() + GENERATED_BODY() }; class RWTHVRTOOLKIT_API IClickable { - GENERATED_IINTERFACE_BODY() + GENERATED_BODY() public: // function that will be called when clickable actor got clicked, and passed the world pos of the click UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = Gameplay) void OnClick(FVector WorldPositionOfClick); }; - diff --git a/Source/RWTHVRToolkit/Public/Interaction/GrabComponent.h b/Source/RWTHVRToolkit/Public/Interaction/GrabComponent.h index 3165dc1b..dd0676c1 100644 --- a/Source/RWTHVRToolkit/Public/Interaction/GrabComponent.h +++ b/Source/RWTHVRToolkit/Public/Interaction/GrabComponent.h @@ -4,41 +4,38 @@ #include "CoreMinimal.h" #include "Components/SceneComponent.h" +#include "Pawn/InputExtensionInterface.h" #include "GrabComponent.generated.h" class UGrabbableComponent; -UCLASS(Abstract,Blueprintable) -class RWTHVRTOOLKIT_API UGrabComponent : public USceneComponent +UCLASS(Abstract, Blueprintable) +class RWTHVRTOOLKIT_API UGrabComponent : public USceneComponent, public IInputExtensionInterface { GENERATED_BODY() -public: +public: // Sets default values for this component's properties UGrabComponent(); - virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override; - + virtual void TickComponent(float DeltaTime, ELevelTick TickType, + FActorComponentTickFunction* ThisTickFunction) override; + UPROPERTY(EditDefaultsOnly, Category = "Input") class UInputMappingContext* IMCGrab; - + UPROPERTY(EditAnywhere, Category = "Input") class UInputAction* GrabInputAction; - UPROPERTY(EditAnywhere,BlueprintReadWrite,Category = "Grabbing") + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Grabbing") float GrabSphereRadius = 15.0; - UPROPERTY(EditAnywhere,BlueprintReadWrite,Category = "Grabbing") + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Grabbing") bool bShowDebugTrace = false; - -protected: - // Called when the game starts - virtual void BeginPlay() override; + virtual void SetupPlayerInput(UInputComponent* PlayerInputComponent) override; private: - void SetupInputActions(); - UFUNCTION() void OnBeginGrab(const FInputActionValue& Value); @@ -50,6 +47,4 @@ private: UPROPERTY() TArray<UGrabbableComponent*> CurrentGrabbableInRange; - - }; diff --git a/Source/RWTHVRToolkit/Public/Interaction/Grabable.h b/Source/RWTHVRToolkit/Public/Interaction/Grabable.h index fa3bc99d..bcef67ff 100644 --- a/Source/RWTHVRToolkit/Public/Interaction/Grabable.h +++ b/Source/RWTHVRToolkit/Public/Interaction/Grabable.h @@ -11,18 +11,18 @@ UINTERFACE(BlueprintType) class RWTHVRTOOLKIT_API UGrabable : public UInterface { // has to be empty, this is Unreals syntax to make it visible in blueprints - GENERATED_UINTERFACE_BODY() + GENERATED_BODY() }; class RWTHVRTOOLKIT_API IGrabable { - GENERATED_IINTERFACE_BODY() + GENERATED_BODY() public: // function that will be called when grabbed by a pawn UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = Gameplay) void OnBeginGrab(); - + // called when pawn released the object UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = Gameplay) void OnEndGrab(); diff --git a/Source/RWTHVRToolkit/Public/Interaction/GrabbableComponent.h b/Source/RWTHVRToolkit/Public/Interaction/GrabbableComponent.h index cb32db53..5b628ecf 100644 --- a/Source/RWTHVRToolkit/Public/Interaction/GrabbableComponent.h +++ b/Source/RWTHVRToolkit/Public/Interaction/GrabbableComponent.h @@ -9,9 +9,8 @@ /** * */ -UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) ) +UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent)) class RWTHVRTOOLKIT_API UGrabbableComponent : public UInteractableBase { GENERATED_BODY() - }; diff --git a/Source/RWTHVRToolkit/Public/Interaction/GrabbingBehaviorComponent.h b/Source/RWTHVRToolkit/Public/Interaction/GrabbingBehaviorComponent.h index 91f6ec0a..4f334e36 100644 --- a/Source/RWTHVRToolkit/Public/Interaction/GrabbingBehaviorComponent.h +++ b/Source/RWTHVRToolkit/Public/Interaction/GrabbingBehaviorComponent.h @@ -8,6 +8,7 @@ DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnBeginGrabSignature, AActor*, GrabbedBy); + DECLARE_DYNAMIC_MULTICAST_DELEGATE(FOnEndGrabSignature); UCLASS(ClassGroup = (Custom), meta = (BlueprintSpawnableComponent)) @@ -18,13 +19,13 @@ class RWTHVRTOOLKIT_API UGrabbingBehaviorComponent : public USceneComponent protected: bool WasSimulatingPhysicsOnGrab; UPROPERTY() - UPrimitiveComponent* MyPhysicsComponent; - + UPrimitiveComponent* MyPhysicsComponent; + public: UPROPERTY(BlueprintAssignable) - FOnBeginGrabSignature OnBeginGrab; + FOnBeginGrabSignature OnBeginGrab; UPROPERTY(BlueprintAssignable) - FOnEndGrabSignature OnEndGrab; + FOnEndGrabSignature OnEndGrab; // Sets default values for this component's properties UGrabbingBehaviorComponent(); @@ -32,13 +33,14 @@ public: public: // takes the hand ray and moves the parent actor to a new possible position, also might change rotation virtual void HandleGrabHold(FVector Position, FQuat Orientation); - + virtual void HandleGrabStart(AActor* GrabbedBy); virtual void HandleGrabEnd(); // Called every frame - virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override; + virtual void TickComponent(float DeltaTime, ELevelTick TickType, + FActorComponentTickFunction* ThisTickFunction) override; protected: // Called when the game starts diff --git a/Source/RWTHVRToolkit/Public/Interaction/GrabbingBehaviorOnLineComponent.h b/Source/RWTHVRToolkit/Public/Interaction/GrabbingBehaviorOnLineComponent.h index 9488b25f..7e257d5c 100644 --- a/Source/RWTHVRToolkit/Public/Interaction/GrabbingBehaviorOnLineComponent.h +++ b/Source/RWTHVRToolkit/Public/Interaction/GrabbingBehaviorOnLineComponent.h @@ -7,32 +7,34 @@ #include "GrabbingBehaviorOnLineComponent.generated.h" -UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) ) +UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent)) class RWTHVRTOOLKIT_API UGrabbingBehaviorOnLineComponent : public UGrabbingBehaviorComponent { GENERATED_BODY() -public: +public: // Sets default values for this component's properties UGrabbingBehaviorOnLineComponent(); // defining a constraint line with these 3 parameters - UFUNCTION(BlueprintCallable) void SetDistance(float Dist); - UFUNCTION(BlueprintCallable) float GetDistance() const; - UFUNCTION(BlueprintCallable) void SetDiscreteNumberOfPoints(int Num); + UFUNCTION(BlueprintCallable) + void SetDistance(float Dist); - virtual void HandleGrabHold(FVector position, FQuat orientation) override; + UFUNCTION(BlueprintCallable) + float GetDistance() const; -protected: - // Called when the game starts - virtual void BeginPlay() override; + UFUNCTION(BlueprintCallable) + void SetDiscreteNumberOfPoints(int Num); -public: - // Called every frame - virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override; + virtual void HandleGrabHold(FVector position, FQuat orientation) override; private: - UPROPERTY(EditAnywhere) float Distance = 100; // distance the object can be moved from the center - UPROPERTY(EditAnywhere) bool bIsDiscrete = false; - UPROPERTY(EditAnywhere) int NumPoints = 1; + UPROPERTY(EditAnywhere) + float Distance = 100; // distance the object can be moved from the center + + UPROPERTY(EditAnywhere) + bool bIsDiscrete = false; + + UPROPERTY(EditAnywhere) + int NumPoints = 1; }; diff --git a/Source/RWTHVRToolkit/Public/Interaction/GrabbingBehaviorOnPlaneComponent.h b/Source/RWTHVRToolkit/Public/Interaction/GrabbingBehaviorOnPlaneComponent.h index 6f74eb4f..fece01f1 100644 --- a/Source/RWTHVRToolkit/Public/Interaction/GrabbingBehaviorOnPlaneComponent.h +++ b/Source/RWTHVRToolkit/Public/Interaction/GrabbingBehaviorOnPlaneComponent.h @@ -13,23 +13,12 @@ class RWTHVRTOOLKIT_API UGrabbingBehaviorOnPlaneComponent : public UGrabbingBeha GENERATED_BODY() public: - // Sets default values for this component's properties - UGrabbingBehaviorOnPlaneComponent(); // defining the constraint plane with these 3 parameters UFUNCTION(BlueprintCallable) void SetDistance(float Dist); UFUNCTION(BlueprintCallable) float GetDistance() const; virtual void HandleGrabHold(FVector position, FQuat orientation) override; - -protected: - // Called when the game starts - virtual void BeginPlay() override; - -public: - // Called every frame - virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override; - private: UPROPERTY(EditAnywhere) float Distance; // distance the object can be moved from the center diff --git a/Source/RWTHVRToolkit/Public/Interaction/HoverBehaviour.h b/Source/RWTHVRToolkit/Public/Interaction/HoverBehaviour.h index e9d132e4..3bdcde4f 100644 --- a/Source/RWTHVRToolkit/Public/Interaction/HoverBehaviour.h +++ b/Source/RWTHVRToolkit/Public/Interaction/HoverBehaviour.h @@ -16,7 +16,6 @@ class RWTHVRTOOLKIT_API UHoverBehaviour : public USceneComponent GENERATED_BODY() public: - UHoverBehaviour(); /** * TriggeredComponent: Component that triggered this event (e.g. GrabComponent, RayCastComponent attached at the VRPawn) * Hit: Hit Result of the trace to get access to e.g. contact point/normals etc. @@ -34,6 +33,4 @@ protected: virtual void OnHoverEnd(const USceneComponent* TriggeredComponent); virtual void BeginPlay() override; - virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override; - }; diff --git a/Source/RWTHVRToolkit/Public/Interaction/InteractableBase.h b/Source/RWTHVRToolkit/Public/Interaction/InteractableBase.h index 1f4d92b2..c291ff27 100644 --- a/Source/RWTHVRToolkit/Public/Interaction/InteractableBase.h +++ b/Source/RWTHVRToolkit/Public/Interaction/InteractableBase.h @@ -11,47 +11,39 @@ struct FInputActionValue; class UClickBehaviour; class UHoverBehaviour; -UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) ) +UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent)) class RWTHVRTOOLKIT_API UInteractableBase : public UActorComponent { GENERATED_BODY() -public: - // Sets default values for this component's properties - UInteractableBase(); - +public: UPROPERTY(EditAnywhere, BlueprintReadWrite) bool IsInteractable = true; - + UPROPERTY(EditAnywhere, BlueprintReadWrite) TArray<UHoverBehaviour*> OnHoverBehaviours; - + UPROPERTY(EditAnywhere, BlueprintReadWrite) TArray<UClickBehaviour*> OnClickBehaviours; - + /** * @brief Restrict interactability to given components (e.g. if an object is grabbed, block interactions from other components) * @param Components */ UFUNCTION() - void RestrictInteractionToComponents(TArray<USceneComponent*> Components); - + void RestrictInteractionToComponents(const TArray<USceneComponent*>& Components); + UFUNCTION() void RestrictInteractionToComponent(USceneComponent* Component); UFUNCTION() void ResetRestrictInteraction(); - protected: // Called when the game starts virtual void BeginPlay() override; - -public: - // Called every frame - virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override; - +public: void HandleOnHoverStartEvents(USceneComponent* TriggerComponent); void HandleOnHoverEndEvents(USceneComponent* TriggerComponent); void HandleOnClickStartEvents(USceneComponent* TriggerComponent, const FInputActionValue& Value); @@ -75,7 +67,5 @@ public: bool IsComponentAllowed(USceneComponent* Component) const; private: - bool bInitOnce = true; - }; diff --git a/Source/RWTHVRToolkit/Public/Interaction/OnClickGrabBehavior.h b/Source/RWTHVRToolkit/Public/Interaction/OnClickGrabBehavior.h index cb702f1e..45022934 100644 --- a/Source/RWTHVRToolkit/Public/Interaction/OnClickGrabBehavior.h +++ b/Source/RWTHVRToolkit/Public/Interaction/OnClickGrabBehavior.h @@ -8,29 +8,18 @@ #include "OnClickGrabBehavior.generated.h" -UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) ) +UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent)) class RWTHVRTOOLKIT_API UOnClickGrabBehavior : public UClickBehaviour { GENERATED_BODY() -public: - // Sets default values for this component's properties - UOnClickGrabBehavior(); - +public: UPROPERTY(EditAnywhere, Category="Grabbing") bool bBlockOtherInteractionsWhileGrabbed = true; -protected: - // Called when the game starts - virtual void BeginPlay() override; - -public: - // Called every frame - virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override; - virtual void OnClickStart(USceneComponent* TriggeredComponent, const FInputActionValue& Value) override; virtual void OnClickEnd(USceneComponent* TriggeredComponent, const FInputActionValue& Value) override; - + UPrimitiveComponent* GetFirstComponentSimulatingPhysics(const AActor* TargetActor); // recursively goes up the hierarchy and returns the highest parent simulating physics @@ -38,7 +27,4 @@ public: UPROPERTY() UPrimitiveComponent* MyPhysicsComponent; - - - }; diff --git a/Source/RWTHVRToolkit/Public/Interaction/RaycastSelectable.h b/Source/RWTHVRToolkit/Public/Interaction/RaycastSelectable.h index 14a90f73..30ad490d 100644 --- a/Source/RWTHVRToolkit/Public/Interaction/RaycastSelectable.h +++ b/Source/RWTHVRToolkit/Public/Interaction/RaycastSelectable.h @@ -9,9 +9,8 @@ /** * */ -UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent)) +UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent)) class RWTHVRTOOLKIT_API URaycastSelectable : public UInteractableBase { GENERATED_BODY() - }; diff --git a/Source/RWTHVRToolkit/Public/Interaction/RaycastSelectionComponent.h b/Source/RWTHVRToolkit/Public/Interaction/RaycastSelectionComponent.h index 718c54f2..8033c8c4 100644 --- a/Source/RWTHVRToolkit/Public/Interaction/RaycastSelectionComponent.h +++ b/Source/RWTHVRToolkit/Public/Interaction/RaycastSelectionComponent.h @@ -2,54 +2,53 @@ #pragma once +#include <Pawn/InputExtensionInterface.h> + #include "CoreMinimal.h" #include "RaycastSelectable.h" #include "Components/SceneComponent.h" #include "RaycastSelectionComponent.generated.h" -UCLASS(Abstract,Blueprintable) -class RWTHVRTOOLKIT_API URaycastSelectionComponent : public USceneComponent +UCLASS(Abstract, Blueprintable) +class RWTHVRTOOLKIT_API URaycastSelectionComponent : public USceneComponent, public IInputExtensionInterface { GENERATED_BODY() -public: +public: // Sets default values for this component's properties URaycastSelectionComponent(); -protected: - // Called when the game starts - virtual void BeginPlay() override; - -public: // Called every frame - virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override; + virtual void TickComponent(float DeltaTime, ELevelTick TickType, + FActorComponentTickFunction* ThisTickFunction) override; UPROPERTY(EditDefaultsOnly, Category = "Input") class UInputMappingContext* IMCRaycastSelection; - + UPROPERTY(EditAnywhere, Category = "Input") class UInputAction* RayCastSelectInputAction; - UPROPERTY(EditAnywhere,BlueprintReadWrite,Category = "Raycast") + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Raycast") float TraceLength = 3000.0; - UPROPERTY(EditAnywhere,BlueprintReadWrite,Category = "Raycast") + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Raycast") bool bShowDebugTrace = false; private: - void SetupInputActions(); - UFUNCTION() void OnBeginSelect(const FInputActionValue& Value); UFUNCTION() void OnEndSelect(const FInputActionValue& Value); +public: + virtual void SetupPlayerInput(UInputComponent* PlayerInputComponent) override; + +private: UPROPERTY() URaycastSelectable* PreviousRaycastSelectable; UPROPERTY() URaycastSelectable* CurrentRaycastSelectable; - }; diff --git a/Source/RWTHVRToolkit/Public/Interaction/Targetable.h b/Source/RWTHVRToolkit/Public/Interaction/Targetable.h index 40cabccd..0b501d30 100644 --- a/Source/RWTHVRToolkit/Public/Interaction/Targetable.h +++ b/Source/RWTHVRToolkit/Public/Interaction/Targetable.h @@ -8,21 +8,21 @@ #include "Targetable.generated.h" UINTERFACE(BlueprintType) -class RWTHVRTOOLKIT_API UTargetable: public UInterface +class RWTHVRTOOLKIT_API UTargetable : public UInterface { // has to be empty, this is Unreals syntax to make it visible in blueprints - GENERATED_UINTERFACE_BODY() + GENERATED_BODY() }; class RWTHVRTOOLKIT_API ITargetable { - GENERATED_IINTERFACE_BODY() + GENERATED_BODY() public: // function that will be called when targetable actor is targeted, the world pos of the target is returned UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = Gameplay) void OnTargeted(FVector WorldPositionOfTarget); - + //function that will be called when a targetable actor gets focused UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = Gameplay) void OnTargetedEnter(); diff --git a/Source/RWTHVRToolkit/Public/Pawn/BasicVRInteractionComponent.h b/Source/RWTHVRToolkit/Public/Pawn/BasicVRInteractionComponent.h index bf62656e..7732d693 100644 --- a/Source/RWTHVRToolkit/Public/Pawn/BasicVRInteractionComponent.h +++ b/Source/RWTHVRToolkit/Public/Pawn/BasicVRInteractionComponent.h @@ -14,77 +14,80 @@ UENUM() enum EInteractionRayVisibility { Visible UMETA(DisplayName = "Interaction ray visible"), - VisibleOnHoverOnly UMETA(DisplayName = "Interaction ray only visible when hovering over Clickable or Targetable objects, or interactable widgets"), + VisibleOnHoverOnly UMETA( + DisplayName = + "Interaction ray only visible when hovering over Clickable or Targetable objects, or interactable widgets"), Invisible UMETA(DisplayName = "Interaction ray invisible") }; -UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent)) +UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent)) class RWTHVRTOOLKIT_API UBasicVRInteractionComponent : public UWidgetInteractionComponent { GENERATED_BODY() -public: +public: // Sets default values for this component's properties UBasicVRInteractionComponent(); virtual void BeginPlay() override; - virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override; + virtual void TickComponent(float DeltaTime, ELevelTick TickType, + FActorComponentTickFunction* ThisTickFunction) override; UFUNCTION(BlueprintCallable) void BeginInteraction(); - + UFUNCTION(BlueprintCallable) - void EndInteraction(); + void EndInteraction(); UFUNCTION(BlueprintCallable) void Initialize(USceneComponent* RayEmitter); - + UFUNCTION(BlueprintCallable, BlueprintPure) - AActor* GetGrabbedActor() const { return GrabbedActor;} - + AActor* GetGrabbedActor() const { return GrabbedActor; } + UFUNCTION(BlueprintCallable, BlueprintPure) - USceneComponent* GetInteractionRayEmitter() const { return InteractionRayEmitter; } + USceneComponent* GetInteractionRayEmitter() const { return InteractionRayEmitter; } UFUNCTION(BlueprintCallable) void SetInteractionRayVisibility(EInteractionRayVisibility NewVisibility); UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Pawn|Interaction") UStaticMeshComponent* InteractionRay; - - UPROPERTY(EditAnywhere,BlueprintReadWrite) + + UPROPERTY(EditAnywhere, BlueprintReadWrite) float MaxGrabDistance = 50; - - UPROPERTY(EditAnywhere,BlueprintReadWrite) + + UPROPERTY(EditAnywhere, BlueprintReadWrite) float MaxClickDistance = 500; - + // Enable this if you want to interact with Targetable classes or use EInteractionRayVisibility::VisibleOnHoverOnly UPROPERTY(EditAnywhere) bool bCanRaytraceEveryTick = false; - + UPROPERTY(EditAnywhere) TEnumAsByte<EInteractionRayVisibility> InteractionRayVisibility = EInteractionRayVisibility::Invisible; - + private: /* Holding a reference to the actor that is currently being grabbed */ UPROPERTY() AActor* GrabbedActor; - + /* Holds a reference to the grabbed actors physics simulating component if there was one*/ UPROPERTY() UPrimitiveComponent* ComponentSimulatingPhysics = nullptr; - + UPROPERTY() UGrabbingBehaviorComponent* Behavior = nullptr; - + UPROPERTY() USceneComponent* InteractionRayEmitter = nullptr; - + /* Stores the reference of the Actor that was hit in the last frame*/ UPROPERTY() AActor* LastActorHit = nullptr; - + void HandlePhysicsAndAttachActor(const AActor* HitActor); FTwoVectors GetHandRay(float Length) const; TOptional<FHitResult> RaytraceForFirstHit(const FTwoVectors& Ray) const; diff --git a/Source/RWTHVRToolkit/Public/Pawn/ContinuousMovementComponent.h b/Source/RWTHVRToolkit/Public/Pawn/ContinuousMovementComponent.h index e4ea442d..0c1daf2f 100644 --- a/Source/RWTHVRToolkit/Public/Pawn/ContinuousMovementComponent.h +++ b/Source/RWTHVRToolkit/Public/Pawn/ContinuousMovementComponent.h @@ -3,7 +3,6 @@ #pragma once #include "CoreMinimal.h" -#include "InputExtensionInterface.h" #include "Pawn/VirtualRealityPawn.h" #include "Pawn/MovementComponentBase.h" #include "Components/ActorComponent.h" @@ -26,42 +25,40 @@ class RWTHVRTOOLKIT_API UContinuousMovementComponent : public UMovementComponent GENERATED_BODY() public: - UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VR Movement") EVRSteeringModes SteeringMode = EVRSteeringModes::STEER_HAND_DIRECTED; - + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VR Movement") bool bMoveWithRightHand = true; - + UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "VR Movement|Input") UInputMappingContext* IMCMovementLeft; UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "VR Movement|Input") UInputMappingContext* IMCMovementRight; - + UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "VR Movement|Input|Actions") UInputAction* Move; UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "VR Movement|Input|Actions") UInputAction* MoveUp; - + /*Movement Input*/ UFUNCTION(BlueprintCallable) void OnMove(const FInputActionValue& Value); UFUNCTION(BlueprintCallable) void OnMoveUp(const FInputActionValue& Value); - + virtual void SetupPlayerInput(UInputComponent* PlayerInputComponent) override; private: - UPROPERTY() class UInputMappingContext* IMCMovement; - + UPROPERTY() UMotionControllerComponent* MovementHand; - + UPROPERTY() - UMotionControllerComponent* RotationHand; + UMotionControllerComponent* RotationHand; }; diff --git a/Source/RWTHVRToolkit/Public/Pawn/InputExtensionInterface.h b/Source/RWTHVRToolkit/Public/Pawn/InputExtensionInterface.h index 543fe244..323049f5 100644 --- a/Source/RWTHVRToolkit/Public/Pawn/InputExtensionInterface.h +++ b/Source/RWTHVRToolkit/Public/Pawn/InputExtensionInterface.h @@ -27,6 +27,6 @@ public: virtual void SetupPlayerInput(UInputComponent* PlayerInputComponent) {} // Helper function to get the local player subsystem - virtual UEnhancedInputLocalPlayerSubsystem* GetEnhancedInputLocalPlayerSubsystem(APawn* Pawn) const; + virtual UEnhancedInputLocalPlayerSubsystem* GetEnhancedInputLocalPlayerSubsystem(const APawn* Pawn) const; }; diff --git a/Source/RWTHVRToolkit/Public/Pawn/ReplicatedCameraComponent.h b/Source/RWTHVRToolkit/Public/Pawn/ReplicatedCameraComponent.h index b211d827..8807531c 100644 --- a/Source/RWTHVRToolkit/Public/Pawn/ReplicatedCameraComponent.h +++ b/Source/RWTHVRToolkit/Public/Pawn/ReplicatedCameraComponent.h @@ -14,26 +14,27 @@ UCLASS() class RWTHVRTOOLKIT_API UReplicatedCameraComponent : public UCameraComponent { GENERATED_BODY() + public: // Sets default values for this component's properties UReplicatedCameraComponent(); - -protected: +protected: ///////////////////////////////////////////////////////////////////////////////////////////////////// // Full transform update replication ///////////////////////////////////////////////////////////////////////////////////////////////////// // Rate to update the position to the server, 100htz is default (same as replication rate, should also hit every tick). - UPROPERTY(EditAnywhere, BlueprintReadWrite, Replicated, Category = "Networking", meta = (ClampMin = "0", UIMin = "0")) + UPROPERTY(EditAnywhere, BlueprintReadWrite, Replicated, Category = "Networking", + meta = (ClampMin = "0", UIMin = "0")) float ControllerNetUpdateRate; // Accumulates time until next send float ControllerNetUpdateCount; - + UPROPERTY(EditDefaultsOnly, ReplicatedUsing = OnRep_ReplicatedTransform, Category = "Networking") FVRTransformRep ReplicatedTransform; - + void UpdateState(float DeltaTime); UFUNCTION() @@ -50,5 +51,5 @@ protected: public: // Called every frame virtual void TickComponent(float DeltaTime, ELevelTick TickType, - FActorComponentTickFunction* ThisTickFunction) override; + FActorComponentTickFunction* ThisTickFunction) override; }; diff --git a/Source/RWTHVRToolkit/Public/Pawn/ReplicatedMotionControllerComponent.h b/Source/RWTHVRToolkit/Public/Pawn/ReplicatedMotionControllerComponent.h index 1d77aa63..cd666939 100644 --- a/Source/RWTHVRToolkit/Public/Pawn/ReplicatedMotionControllerComponent.h +++ b/Source/RWTHVRToolkit/Public/Pawn/ReplicatedMotionControllerComponent.h @@ -18,23 +18,23 @@ class RWTHVRTOOLKIT_API UReplicatedMotionControllerComponent : public UMotionCon public: // Sets default values for this component's properties UReplicatedMotionControllerComponent(); - -protected: +protected: ///////////////////////////////////////////////////////////////////////////////////////////////////// // Full transform update replication ///////////////////////////////////////////////////////////////////////////////////////////////////// // Rate to update the position to the server, 100htz is default (same as replication rate, should also hit every tick). - UPROPERTY(EditAnywhere, BlueprintReadWrite, Replicated, Category = "Networking", meta = (ClampMin = "0", UIMin = "0")) + UPROPERTY(EditAnywhere, BlueprintReadWrite, Replicated, Category = "Networking", + meta = (ClampMin = "0", UIMin = "0")) float ControllerNetUpdateRate; // Accumulates time until next send float ControllerNetUpdateCount; - + UPROPERTY(EditDefaultsOnly, ReplicatedUsing = OnRep_ReplicatedTransform, Category = "Networking") FVRTransformRep ReplicatedTransform; - + void UpdateState(float DeltaTime); UFUNCTION() @@ -51,5 +51,4 @@ public: // Called every frame virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override; - }; diff --git a/Source/RWTHVRToolkit/Public/Pawn/TeleportationComponent.h b/Source/RWTHVRToolkit/Public/Pawn/TeleportationComponent.h index 867c122f..9946ed94 100644 --- a/Source/RWTHVRToolkit/Public/Pawn/TeleportationComponent.h +++ b/Source/RWTHVRToolkit/Public/Pawn/TeleportationComponent.h @@ -3,7 +3,6 @@ #pragma once #include "CoreMinimal.h" -#include "InputExtensionInterface.h" #include "Components/ActorComponent.h" #include "Pawn/VirtualRealityPawn.h" #include "NiagaraComponent.h" @@ -76,7 +75,7 @@ private: UPROPERTY() UInputMappingContext* IMCMovement; - + bool bTeleportTraceActive; float TeleportProjectileRadius = 3.6; float RotationArrowRadius = 10.0; diff --git a/Source/RWTHVRToolkit/Public/Pawn/VRPawnInputConfig.h b/Source/RWTHVRToolkit/Public/Pawn/VRPawnInputConfig.h index c7dc0183..c4f26cfb 100644 --- a/Source/RWTHVRToolkit/Public/Pawn/VRPawnInputConfig.h +++ b/Source/RWTHVRToolkit/Public/Pawn/VRPawnInputConfig.h @@ -16,16 +16,15 @@ class RWTHVRTOOLKIT_API UVRPawnInputConfig : public UDataAsset GENERATED_BODY() public: - UPROPERTY(EditDefaultsOnly, BlueprintReadOnly) UInputAction* MoveUp; - + UPROPERTY(EditDefaultsOnly, BlueprintReadOnly) UInputAction* DesktopRotation; UPROPERTY(EditDefaultsOnly, BlueprintReadOnly) UInputAction* Fire; - + UPROPERTY(EditDefaultsOnly, BlueprintReadOnly) UInputAction* Grab; @@ -40,10 +39,7 @@ public: UPROPERTY(EditDefaultsOnly, BlueprintReadOnly) UInputAction* GrabLeft; - + UPROPERTY(EditDefaultsOnly, BlueprintReadOnly) UInputAction* GrabRight; - - - }; diff --git a/Source/RWTHVRToolkit/Public/Pawn/VRPawnMovement.h b/Source/RWTHVRToolkit/Public/Pawn/VRPawnMovement.h index 8e789de1..31ae483a 100644 --- a/Source/RWTHVRToolkit/Public/Pawn/VRPawnMovement.h +++ b/Source/RWTHVRToolkit/Public/Pawn/VRPawnMovement.h @@ -3,7 +3,6 @@ #include "CoreMinimal.h" #include "GameFramework/FloatingPawnMovement.h" #include "Components/CapsuleComponent.h" -#include "Camera/CameraComponent.h" #include "VRPawnMovement.generated.h" @@ -34,7 +33,6 @@ class RWTHVRTOOLKIT_API UVRPawnMovement : public UFloatingPawnMovement GENERATED_UCLASS_BODY() public: - virtual void BeginPlay() override; void CheckAndRevertCollisionSinceLastTick(); @@ -57,7 +55,7 @@ public: UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VR Movement", meta = (ClampMax="0.0")) float GravityAcceleration = -981.0f; - + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VR Movement", meta = (ClampMin="0.0")) float UpSteppingAcceleration = 981.0f; @@ -66,16 +64,18 @@ public: private: //check for - FHitResult CreateCapsuleTrace(const FVector Start, FVector End, bool DrawDebug=false); + FHitResult CreateCapsuleTrace(const FVector& Start, const FVector& End, bool DrawDebug = false) const; FVector GetOverlapResolveDirection(); - void SetCapsuleColliderToUserSize(); + void SetCapsuleColliderToUserSize() const; void CheckForPhysWalkingCollision(); FVector GetCollisionSafeVirtualSteeringVec(FVector InputVector, float DeltaTime); void MoveByGravityOrStepUp(float DeltaSeconds); void ShiftVertically(float Distance, float VerticalAcceleration, float DeltaSeconds); - UPROPERTY(VisibleAnywhere) UCapsuleComponent* CapsuleColliderComponent = nullptr; - UPROPERTY() USceneComponent* HeadComponent = nullptr; + UPROPERTY(VisibleAnywhere) + UCapsuleComponent* CapsuleColliderComponent = nullptr; + UPROPERTY() + USceneComponent* HeadComponent = nullptr; float VerticalSpeed = 0.0f; FVector LastCollisionFreeCapsulePosition; diff --git a/Source/RWTHVRToolkit/Public/RWTHVRToolkit.h b/Source/RWTHVRToolkit/Public/RWTHVRToolkit.h index c1d682b4..70a9cc7e 100644 --- a/Source/RWTHVRToolkit/Public/RWTHVRToolkit.h +++ b/Source/RWTHVRToolkit/Public/RWTHVRToolkit.h @@ -8,9 +8,9 @@ class FRWTHVRToolkitModule : public IModuleInterface { public: - virtual void StartupModule () override; + virtual void StartupModule() override; virtual void ShutdownModule() override; - + private: FActivateConsoleInShipping ConsoleActivation; TUniquePtr<FLiveLinkMotionControllerFix> LiveLinkMotionController; diff --git a/Source/RWTHVRToolkit/Public/UI/ExternalImage.h b/Source/RWTHVRToolkit/Public/UI/ExternalImage.h index ddad2a83..d566a678 100644 --- a/Source/RWTHVRToolkit/Public/UI/ExternalImage.h +++ b/Source/RWTHVRToolkit/Public/UI/ExternalImage.h @@ -2,7 +2,6 @@ #include "CoreMinimal.h" #include "Components/Image.h" -#include "Runtime/ImageWrapper/Public/IImageWrapper.h" #include "ExternalImage.generated.h" /** @@ -13,17 +12,21 @@ class RWTHVRTOOLKIT_API UExternalImage : public UImage { GENERATED_BODY() - UExternalImage(); + UExternalImage(); public: - /* Loads an Image from either a file or an URL */ - UFUNCTION(BlueprintCallable) void LoadImageFromURL(const FString& ImageURL); + /* Loads an Image from either a file or an URL */ + UFUNCTION(BlueprintCallable) + void LoadImageFromURL(const FString& ImageURL); private: - TArray<uint8> CompressedData; - UPROPERTY() UTexture2D* NewTexture; + TArray<uint8> CompressedData; + UPROPERTY() + UTexture2D* NewTexture; - bool LoadCompressedDataIntoTexture2D(const TArray<uint8>& InCompressedData, UTexture2D*& OutTexture); - static void LoadDataFromURL(const FString& ImageURL, TArray<uint8>& OutCompressedData, TFunction<void()> OnSuccessCallback); - static void LoadDataFromFile(const FString& ImagePath, TArray<uint8>& OutCompressedData, TFunction<void()> OnSuccessCallback); + bool LoadCompressedDataIntoTexture2D(const TArray<uint8>& InCompressedData, UTexture2D*& OutTexture); + static void LoadDataFromURL(const FString& ImageURL, TArray<uint8>& OutCompressedData, + TFunction<void()> OnSuccessCallback); + static void LoadDataFromFile(const FString& ImagePath, TArray<uint8>& OutCompressedData, + TFunction<void()> OnSuccessCallback); }; diff --git a/Source/RWTHVRToolkit/Public/Utility/DemoConfig.h b/Source/RWTHVRToolkit/Public/Utility/DemoConfig.h index 105f9fb4..51c20241 100644 --- a/Source/RWTHVRToolkit/Public/Utility/DemoConfig.h +++ b/Source/RWTHVRToolkit/Public/Utility/DemoConfig.h @@ -17,33 +17,34 @@ class RWTHVRTOOLKIT_API UDemoConfig : public UDeveloperSettings { GENERATED_BODY() - virtual FName GetCategoryName() const override {return "Game";}; + virtual FName GetCategoryName() const override { return "Game"; }; - #if WITH_EDITOR - virtual FText GetSectionText() const override {return FText::FromString("Demo");}; - #endif +#if WITH_EDITOR + virtual FText GetSectionText() const override { return FText::FromString("Demo"); }; +#endif virtual void PostInitProperties() override { Super::PostInitProperties(); // Do not create/load this config file in the editor. We have the DefaultDemo.ini already - if(FApp::GetBuildTargetType() == EBuildTargetType::Editor) return; + if (FApp::GetBuildTargetType() == EBuildTargetType::Editor) return; // Load config file (does nothing if not exist) - const FString ConfigFile = FPaths::Combine(FPaths::ProjectConfigDir(), FPaths::GetCleanFilename(GetClass()->GetConfigName())); - FConfigCacheIni Config(EConfigCacheType::DiskBacked); + const FString ConfigFile = FPaths::Combine(FPaths::ProjectConfigDir(), + FPaths::GetCleanFilename(GetClass()->GetConfigName())); + FConfigCacheIni Config(EConfigCacheType::DiskBacked); Config.LoadFile(ConfigFile); // Check existence of correct section (fails if file does not exist) - if(Config.DoesSectionExist(*GetClass()->GetPathName(), ConfigFile)) + if (Config.DoesSectionExist(*GetClass()->GetPathName(), ConfigFile)) { - LoadConfig(GetClass(), *ConfigFile); - } - else - { - SaveConfig(CPF_Config, *ConfigFile, &Config); + LoadConfig(GetClass(), *ConfigFile); + } + else + { + SaveConfig(CPF_Config, *ConfigFile, &Config); Config.Flush(false); - } + } }; }; diff --git a/Source/RWTHVRToolkit/Public/Utility/VirtualRealityUtilities.h b/Source/RWTHVRToolkit/Public/Utility/VirtualRealityUtilities.h index 67169f99..cc23a497 100644 --- a/Source/RWTHVRToolkit/Public/Utility/VirtualRealityUtilities.h +++ b/Source/RWTHVRToolkit/Public/Utility/VirtualRealityUtilities.h @@ -7,7 +7,6 @@ #include "VirtualRealityUtilities.generated.h" - /** * Custom log category for all RWTHVRToolkit related components */ @@ -50,39 +49,51 @@ class RWTHVRTOOLKIT_API UVirtualRealityUtilities : public UBlueprintFunctionLibr GENERATED_BODY() public: - UFUNCTION(BlueprintPure, Category = "DisplayCluster|Platform") static bool IsDesktopMode(); - UFUNCTION(BlueprintPure, Category = "DisplayCluster|Platform") static bool IsRoomMountedMode(); - UFUNCTION(BlueprintPure, Category = "DisplayCluster|Platform") static bool IsHeadMountedMode(); - UFUNCTION(BlueprintPure, Category = "DisplayCluster|Platform") static bool IsCave(); - UFUNCTION(BlueprintPure, Category = "DisplayCluster|Platform") static bool IsTdw(); - UFUNCTION(BlueprintPure, Category = "DisplayCluster|Platform") static bool IsRolv(); - - UFUNCTION(BlueprintPure, Category = "DisplayCluster") static bool IsMaster(); - UFUNCTION(BlueprintPure, Category = "DisplayCluster") static bool IsSlave(); - - UFUNCTION(BlueprintPure, Category = "DisplayCluster") static FString GetNodeName(); + UFUNCTION(BlueprintPure, Category = "DisplayCluster|Platform") + static bool IsDesktopMode(); + UFUNCTION(BlueprintPure, Category = "DisplayCluster|Platform") + static bool IsRoomMountedMode(); + UFUNCTION(BlueprintPure, Category = "DisplayCluster|Platform") + static bool IsHeadMountedMode(); + UFUNCTION(BlueprintPure, Category = "DisplayCluster|Platform") + static bool IsCave(); + UFUNCTION(BlueprintPure, Category = "DisplayCluster|Platform") + static bool IsTdw(); + UFUNCTION(BlueprintPure, Category = "DisplayCluster|Platform") + static bool IsRolv(); + + UFUNCTION(BlueprintPure, Category = "DisplayCluster") + static bool IsMaster(); + UFUNCTION(BlueprintPure, Category = "DisplayCluster") + static bool IsSlave(); + + UFUNCTION(BlueprintPure, Category = "DisplayCluster") + static FString GetNodeName(); /* Distance in meters */ - UFUNCTION(BlueprintPure, Category = "DisplayCluster") static float GetEyeDistance(); + UFUNCTION(BlueprintPure, Category = "DisplayCluster") + static float GetEyeDistance(); - UFUNCTION(BlueprintPure, Category = "DisplayCluster") static EEyeStereoOffset GetNodeEyeType(); + UFUNCTION(BlueprintPure, Category = "DisplayCluster") + static EEyeStereoOffset GetNodeEyeType(); //Get Component of Display Cluster by it's name, which is specified in the nDisplay config - UFUNCTION(BlueprintPure, BlueprintCallable, Category = "DisplayCluster") static USceneComponent* GetClusterComponent(const FString& Name); - UFUNCTION(BlueprintPure, BlueprintCallable, Category = "DisplayCluster") static USceneComponent* GetNamedClusterComponent(const ENamedClusterComponent& Component); - + UFUNCTION(BlueprintPure, BlueprintCallable, Category = "DisplayCluster") + static USceneComponent* GetClusterComponent(const FString& Name); + UFUNCTION(BlueprintPure, BlueprintCallable, Category = "DisplayCluster") + static USceneComponent* GetNamedClusterComponent(const ENamedClusterComponent& Component); + /* Load and create an Object from an asset path. This only works in the constructor */ - template <class T> + template <class T> [[deprecated]] - static bool LoadAsset(const FString& Path, T*& Result); - - /* Finds and returns a class of an asset. This only works in the constructor */ - template <class T> + static bool LoadAsset(const FString& Path, T*& Result); + + /* Finds and returns a class of an asset. This only works in the constructor */ + template <class T> [[deprecated]] - static bool LoadClass(const FString& Path, TSubclassOf<T>& Result); + static bool LoadClass(const FString& Path, TSubclassOf<T>& Result); UFUNCTION(BlueprintCallable) - static void ShowErrorAndQuit(UWorld* WorldContext,const FString& Message); - + static void ShowErrorAndQuit(UWorld* WorldContext, const FString& Message); }; template <typename T> @@ -95,9 +106,9 @@ bool UVirtualRealityUtilities::LoadAsset(const FString& Path, T* & Result) } template <typename T> -bool UVirtualRealityUtilities::LoadClass(const FString& Path, TSubclassOf<T> & Result) +bool UVirtualRealityUtilities::LoadClass(const FString& Path, TSubclassOf<T>& Result) { - ConstructorHelpers::FClassFinder<T> Loader(*Path); + ConstructorHelpers::FClassFinder<T> Loader(*Path); Result = Loader.Class; if (!Loader.Succeeded()) UE_LOG(LogTemp, Error, TEXT("Could not find %s. Have you renamed it?"), *Path); return Loader.Succeeded(); diff --git a/Source/RWTHVRToolkitEditor/Private/Interaction/GrabbingBehaviorOnLineVisualizer.cpp b/Source/RWTHVRToolkitEditor/Private/Interaction/GrabbingBehaviorOnLineVisualizer.cpp index 3cc4699e..2370043a 100644 --- a/Source/RWTHVRToolkitEditor/Private/Interaction/GrabbingBehaviorOnLineVisualizer.cpp +++ b/Source/RWTHVRToolkitEditor/Private/Interaction/GrabbingBehaviorOnLineVisualizer.cpp @@ -17,9 +17,9 @@ FGrabbingBehaviorOnLineVisualizer::~FGrabbingBehaviorOnLineVisualizer() // Fill out your copyright notice in the Description page of Project Settings. -void FGrabbingBehaviorOnLineVisualizer::DrawVisualization(const UActorComponent* Component, const FSceneView* View, FPrimitiveDrawInterface* PDI) { - - +void FGrabbingBehaviorOnLineVisualizer::DrawVisualization(const UActorComponent* Component, const FSceneView* View, + FPrimitiveDrawInterface* PDI) +{ const UGrabbingBehaviorOnLineComponent* LineBehavior = Cast<const UGrabbingBehaviorOnLineComponent>(Component); if (LineBehavior != nullptr) @@ -31,5 +31,3 @@ void FGrabbingBehaviorOnLineVisualizer::DrawVisualization(const UActorComponent* PDI->DrawLine(Attachment + Forward * Distance, Attachment - Forward * Distance, FColor::Blue, SDPG_World); } } - - diff --git a/Source/RWTHVRToolkitEditor/Private/Interaction/GrabbingBehaviorPlaneVisualizer.cpp b/Source/RWTHVRToolkitEditor/Private/Interaction/GrabbingBehaviorPlaneVisualizer.cpp index d2c940b6..4af4d772 100644 --- a/Source/RWTHVRToolkitEditor/Private/Interaction/GrabbingBehaviorPlaneVisualizer.cpp +++ b/Source/RWTHVRToolkitEditor/Private/Interaction/GrabbingBehaviorPlaneVisualizer.cpp @@ -13,9 +13,9 @@ FGrabbingBehaviorPlaneVisualizer::~FGrabbingBehaviorPlaneVisualizer() { } -void FGrabbingBehaviorPlaneVisualizer::DrawVisualization(const UActorComponent* Component, const FSceneView* View, FPrimitiveDrawInterface* PDI) { - - +void FGrabbingBehaviorPlaneVisualizer::DrawVisualization(const UActorComponent* Component, const FSceneView* View, + FPrimitiveDrawInterface* PDI) +{ const UGrabbingBehaviorOnPlaneComponent* PlaneBehavior = Cast<const UGrabbingBehaviorOnPlaneComponent>(Component); if (PlaneBehavior != nullptr) @@ -33,11 +33,10 @@ void FGrabbingBehaviorPlaneVisualizer::DrawVisualization(const UActorComponent* for (int i = 1; i < Segments + 1; i++) // draw circle using lines { - Next = Right.RotateAngleAxis(360/Segments, Forward); + Next = Right.RotateAngleAxis(360 / Segments, Forward); - PDI->DrawLine(Attachment + Right*Distance,Attachment + Next*Distance, FColor::Blue, SDPG_World); + PDI->DrawLine(Attachment + Right * Distance, Attachment + Next * Distance, FColor::Blue, SDPG_World); Right = Next; } } } - diff --git a/Source/RWTHVRToolkitEditor/Private/RWTHVRToolkitEditor.cpp b/Source/RWTHVRToolkitEditor/Private/RWTHVRToolkitEditor.cpp index ca8f91aa..2f9907ec 100644 --- a/Source/RWTHVRToolkitEditor/Private/RWTHVRToolkitEditor.cpp +++ b/Source/RWTHVRToolkitEditor/Private/RWTHVRToolkitEditor.cpp @@ -1,14 +1,11 @@ #include "RWTHVRToolkitEditor.h" -#include "ComponentVisualizers.h" -#include "Interaction/GrabbingBehaviorOnLineVisualizer.h" -#include "Interaction/GrabbingBehaviorPlaneVisualizer.h" - -#include "Interaction/GrabbingBehaviorOnPlaneComponent.h" -#include "Interaction/GrabbingBehaviorOnLineComponent.h" - #include "UnrealEdGlobals.h" #include "Editor/UnrealEdEngine.h" +#include "Interaction/GrabbingBehaviorOnLineComponent.h" +#include "Interaction/GrabbingBehaviorOnLineVisualizer.h" +#include "Interaction/GrabbingBehaviorOnPlaneComponent.h" +#include "Interaction/GrabbingBehaviorPlaneVisualizer.h" IMPLEMENT_GAME_MODULE(FRWTHVRToolkitEditorModule, RWTHVRToolkitEditor); @@ -16,21 +13,23 @@ IMPLEMENT_GAME_MODULE(FRWTHVRToolkitEditorModule, RWTHVRToolkitEditor); void FRWTHVRToolkitEditorModule::StartupModule() { - if (GUnrealEd != NULL) + if (GUnrealEd != nullptr) { - TSharedPtr<FComponentVisualizer> LineVisualizer = MakeShareable(new FGrabbingBehaviorOnLineVisualizer()); + const TSharedPtr<FComponentVisualizer> LineVisualizer = MakeShareable(new FGrabbingBehaviorOnLineVisualizer()); if (LineVisualizer.IsValid()) { - GUnrealEd->RegisterComponentVisualizer(UGrabbingBehaviorOnLineComponent::StaticClass()->GetFName(), LineVisualizer); + GUnrealEd->RegisterComponentVisualizer(UGrabbingBehaviorOnLineComponent::StaticClass()->GetFName(), + LineVisualizer); LineVisualizer->OnRegister(); } - TSharedPtr<FComponentVisualizer> PlaneVisualizer = MakeShareable(new FGrabbingBehaviorPlaneVisualizer()); - + const TSharedPtr<FComponentVisualizer> PlaneVisualizer = MakeShareable(new FGrabbingBehaviorPlaneVisualizer()); + if (PlaneVisualizer.IsValid()) { - GUnrealEd->RegisterComponentVisualizer(UGrabbingBehaviorOnPlaneComponent::StaticClass()->GetFName(), PlaneVisualizer); + GUnrealEd->RegisterComponentVisualizer(UGrabbingBehaviorOnPlaneComponent::StaticClass()->GetFName(), + PlaneVisualizer); PlaneVisualizer->OnRegister(); } } @@ -38,11 +37,11 @@ void FRWTHVRToolkitEditorModule::StartupModule() void FRWTHVRToolkitEditorModule::ShutdownModule() { - if (GUnrealEd != NULL) + if (GUnrealEd != nullptr) { GUnrealEd->UnregisterComponentVisualizer(UGrabbingBehaviorOnLineComponent::StaticClass()->GetFName()); GUnrealEd->UnregisterComponentVisualizer(UGrabbingBehaviorOnPlaneComponent::StaticClass()->GetFName()); } } -#undef LOCTEXT_NAMESPACE \ No newline at end of file +#undef LOCTEXT_NAMESPACE diff --git a/Source/RWTHVRToolkitEditor/Public/Interaction/GrabbingBehaviorOnLineVisualizer.h b/Source/RWTHVRToolkitEditor/Public/Interaction/GrabbingBehaviorOnLineVisualizer.h index 7cb7de8c..cc220cde 100644 --- a/Source/RWTHVRToolkitEditor/Public/Interaction/GrabbingBehaviorOnLineVisualizer.h +++ b/Source/RWTHVRToolkitEditor/Public/Interaction/GrabbingBehaviorOnLineVisualizer.h @@ -16,9 +16,6 @@ public: FGrabbingBehaviorOnLineVisualizer(); ~FGrabbingBehaviorOnLineVisualizer(); - virtual void DrawVisualization(const UActorComponent* Component, const FSceneView* View, FPrimitiveDrawInterface* PDI) override; + virtual void DrawVisualization(const UActorComponent* Component, const FSceneView* View, + FPrimitiveDrawInterface* PDI) override; }; - - - - diff --git a/Source/RWTHVRToolkitEditor/Public/Interaction/GrabbingBehaviorPlaneVisualizer.h b/Source/RWTHVRToolkitEditor/Public/Interaction/GrabbingBehaviorPlaneVisualizer.h index db020e56..43428d8a 100644 --- a/Source/RWTHVRToolkitEditor/Public/Interaction/GrabbingBehaviorPlaneVisualizer.h +++ b/Source/RWTHVRToolkitEditor/Public/Interaction/GrabbingBehaviorPlaneVisualizer.h @@ -16,5 +16,6 @@ public: FGrabbingBehaviorPlaneVisualizer(); ~FGrabbingBehaviorPlaneVisualizer(); - virtual void DrawVisualization(const UActorComponent* Component, const FSceneView* View, FPrimitiveDrawInterface* PDI) override; + virtual void DrawVisualization(const UActorComponent* Component, const FSceneView* View, + FPrimitiveDrawInterface* PDI) override; }; diff --git a/Source/RWTHVRToolkitEditor/Public/RWTHVRToolkitEditor.h b/Source/RWTHVRToolkitEditor/Public/RWTHVRToolkitEditor.h index 0effe932..ae6b3851 100644 --- a/Source/RWTHVRToolkitEditor/Public/RWTHVRToolkitEditor.h +++ b/Source/RWTHVRToolkitEditor/Public/RWTHVRToolkitEditor.h @@ -11,5 +11,4 @@ public: virtual void StartupModule() override; virtual void ShutdownModule() override; // End IModuleInterface implementation - -}; \ No newline at end of file +}; -- GitLab From f36b1dd73b7ae79fe5803b0531c68089166f5ccc Mon Sep 17 00:00:00 2001 From: David Gilbert <gilbert@vr.rwth-aachen.de> Date: Mon, 30 Oct 2023 09:04:04 +0100 Subject: [PATCH 2/3] remove unnecessary nullptr check --- Source/RWTHVRToolkit/Private/Pawn/VirtualRealityPawn.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/RWTHVRToolkit/Private/Pawn/VirtualRealityPawn.cpp b/Source/RWTHVRToolkit/Private/Pawn/VirtualRealityPawn.cpp index 4ac07d8e..e597c920 100644 --- a/Source/RWTHVRToolkit/Private/Pawn/VirtualRealityPawn.cpp +++ b/Source/RWTHVRToolkit/Private/Pawn/VirtualRealityPawn.cpp @@ -207,7 +207,7 @@ void AVirtualRealityPawn::UpdateRightHandForDesktopInteraction() const // Todo rewrite this in some other way or attach it differently, this is horrible void AVirtualRealityPawn::AttachDCRAtoPawn() { - if (!CaveSetupActorClass || !CaveSetupActorClass->IsValidLowLevelFast()) + if (!CaveSetupActorClass->IsValidLowLevelFast()) { UE_LOGFMT(Toolkit, Warning, "No CaveSetup Actor class set in pawn!"); return; -- GitLab From 73c75e1c07bf04b9f0dc2474319177b1aa7d211e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20Kr=C3=BCger?= <marcel.krueger@rwth-aachen.de> Date: Mon, 30 Oct 2023 10:08:55 +0100 Subject: [PATCH 3/3] Applied comment line number changes --- .../CAVEOverlay/CAVEOverlayController.cpp | 7 +-- .../Fixes/ActivateConsoleInShipping.cpp | 52 +++++++++---------- .../Private/Pawn/VirtualRealityPawn.cpp | 2 +- 3 files changed, 31 insertions(+), 30 deletions(-) diff --git a/Source/RWTHVRCluster/Private/CAVEOverlay/CAVEOverlayController.cpp b/Source/RWTHVRCluster/Private/CAVEOverlay/CAVEOverlayController.cpp index 08415c9b..0a64cbb3 100644 --- a/Source/RWTHVRCluster/Private/CAVEOverlay/CAVEOverlayController.cpp +++ b/Source/RWTHVRCluster/Private/CAVEOverlay/CAVEOverlayController.cpp @@ -221,8 +221,8 @@ void ACAVEOverlayController::BeginPlay() Overlay = CreateWidget<UDoorOverlayData>(GetWorld()->GetFirstPlayerController(), OverlayClass); Overlay->AddToViewport(0); SetDoorMode(DoorCurrentMode); - Overlay->CornerText->SetText(FText::FromString("")); //Set Text to "" until someone presses the key for the first time + Overlay->CornerText->SetText(FText::FromString("")); if (!bAttachedToCAVEOrigin && CaveOrigin) { @@ -252,10 +252,11 @@ float ACAVEOverlayController::CalculateOpacityFromPosition(const FVector& Positi bool ACAVEOverlayController::PositionInDoorOpening(const FVector& Position) const { + //Overlap both sides 10cm return FMath::IsWithinInclusive(-Position.X, WallDistance + 10 - 20 - WallCloseDistance, WallDistance + 10) - //Overlap both sides 10cm + //Overlap one side 10cm && FMath::IsWithinInclusive(-Position.Y, WallDistance + 10 - DoorCurrentOpeningWidthAbsolute, - WallDistance + 10); //Overlap one side 10cm + WallDistance + 10); } // Called every frame diff --git a/Source/RWTHVRToolkit/Private/Fixes/ActivateConsoleInShipping.cpp b/Source/RWTHVRToolkit/Private/Fixes/ActivateConsoleInShipping.cpp index e81ddaa0..e24d994d 100644 --- a/Source/RWTHVRToolkit/Private/Fixes/ActivateConsoleInShipping.cpp +++ b/Source/RWTHVRToolkit/Private/Fixes/ActivateConsoleInShipping.cpp @@ -1,26 +1,26 @@ -#include "Fixes/ActivateConsoleInShipping.h" -#include "Engine/Console.h" - -void FActivateConsoleInShipping::Register() -{ - if (FApp::GetBuildConfiguration() != EBuildConfiguration::Shipping) return; - /* Should only enable console in shipping */ - - On_Post_World_Initialization_Delegate.BindRaw(this, &FActivateConsoleInShipping::OnSessionStart); - StartHandle = FWorldDelegates::OnPostWorldInitialization.Add(On_Post_World_Initialization_Delegate); -} - -void FActivateConsoleInShipping::Unregister() const -{ - if (FApp::GetBuildConfiguration() != EBuildConfiguration::Shipping) return; - - FWorldDelegates::OnPostWorldInitialization.Remove(StartHandle); -} - -void FActivateConsoleInShipping::OnSessionStart(UWorld* World, const UWorld::InitializationValues Values) const -{ - if (!World->IsGameWorld() || !World->GetGameViewport() || World->GetGameViewport()->ViewportConsole != nullptr) - return; - - World->GetGameViewport()->ViewportConsole = NewObject<UConsole>(World->GetGameViewport()); -} +#include "Fixes/ActivateConsoleInShipping.h" +#include "Engine/Console.h" + +void FActivateConsoleInShipping::Register() +{ + /* Should only enable console in shipping */ + if (FApp::GetBuildConfiguration() != EBuildConfiguration::Shipping) return; + + On_Post_World_Initialization_Delegate.BindRaw(this, &FActivateConsoleInShipping::OnSessionStart); + StartHandle = FWorldDelegates::OnPostWorldInitialization.Add(On_Post_World_Initialization_Delegate); +} + +void FActivateConsoleInShipping::Unregister() const +{ + if (FApp::GetBuildConfiguration() != EBuildConfiguration::Shipping) return; + + FWorldDelegates::OnPostWorldInitialization.Remove(StartHandle); +} + +void FActivateConsoleInShipping::OnSessionStart(UWorld* World, const UWorld::InitializationValues Values) const +{ + if (!World->IsGameWorld() || !World->GetGameViewport() || World->GetGameViewport()->ViewportConsole != nullptr) + return; + + World->GetGameViewport()->ViewportConsole = NewObject<UConsole>(World->GetGameViewport()); +} diff --git a/Source/RWTHVRToolkit/Private/Pawn/VirtualRealityPawn.cpp b/Source/RWTHVRToolkit/Private/Pawn/VirtualRealityPawn.cpp index e597c920..4ac07d8e 100644 --- a/Source/RWTHVRToolkit/Private/Pawn/VirtualRealityPawn.cpp +++ b/Source/RWTHVRToolkit/Private/Pawn/VirtualRealityPawn.cpp @@ -207,7 +207,7 @@ void AVirtualRealityPawn::UpdateRightHandForDesktopInteraction() const // Todo rewrite this in some other way or attach it differently, this is horrible void AVirtualRealityPawn::AttachDCRAtoPawn() { - if (!CaveSetupActorClass->IsValidLowLevelFast()) + if (!CaveSetupActorClass || !CaveSetupActorClass->IsValidLowLevelFast()) { UE_LOGFMT(Toolkit, Warning, "No CaveSetup Actor class set in pawn!"); return; -- GitLab