diff --git a/Content/BP_VirtualRealityPawn.uasset b/Content/BP_VirtualRealityPawn.uasset index 1045271d9f6e3ffbf9fd49e9910224b230d8d035..2e762125581ad5e940d88c07031d92e41809aa92 100644 Binary files a/Content/BP_VirtualRealityPawn.uasset and b/Content/BP_VirtualRealityPawn.uasset differ diff --git a/Content/Components/Grabbing/BP_GrabbableObjectTest.uasset b/Content/Components/Grabbing/BP_GrabbableObjectTest.uasset index 254a0a2b2bf23d5dcd13f759e20ff9391fadec2f..48a53f0bba3dd43a99b4379394b1a467885588a3 100644 Binary files a/Content/Components/Grabbing/BP_GrabbableObjectTest.uasset and b/Content/Components/Grabbing/BP_GrabbableObjectTest.uasset differ diff --git a/Content/Components/Grabbing/IA_GrabLeft.uasset b/Content/Components/Grabbing/IA_GrabLeft.uasset index 6468d8b66cf74845b1fd90a1502392e78bc01400..bcc873bcdbf823add969db4e7528603617badb84 100644 Binary files a/Content/Components/Grabbing/IA_GrabLeft.uasset and b/Content/Components/Grabbing/IA_GrabLeft.uasset differ diff --git a/Content/Components/Grabbing/IMCGrab.uasset b/Content/Components/Grabbing/IMCGrab.uasset index 26ac2bacfbfa78b98ad362f75b421f3adb272d53..92f4e610116080694e4be9b23e4510414faff0b7 100644 Binary files a/Content/Components/Grabbing/IMCGrab.uasset and b/Content/Components/Grabbing/IMCGrab.uasset differ diff --git a/Content/Components/Movement/ContinuousMovement/ContinuousMovementComponent.uasset b/Content/Components/Movement/ContinuousMovement/ContinuousMovementComponent.uasset new file mode 100644 index 0000000000000000000000000000000000000000..bb2383319803fa6b37bf252852c15be726005fa2 Binary files /dev/null and b/Content/Components/Movement/ContinuousMovement/ContinuousMovementComponent.uasset differ diff --git a/Content/Components/Movement/ContinuousMovementComponent.uasset b/Content/Components/Movement/ContinuousMovementComponent.uasset index ae283beeff5102560cae3777480a3aa87c77ac0d..7744ec0839f73c6f9e196944a521d2929c7c7f63 100644 Binary files a/Content/Components/Movement/ContinuousMovementComponent.uasset and b/Content/Components/Movement/ContinuousMovementComponent.uasset differ diff --git a/Content/Components/Movement/IA_DesktopRotation.uasset b/Content/Components/Movement/IA_DesktopRotation.uasset index 9be621bc6d606638594c1a49abc72e9cb8992351..715a68136d45aaf362e011ff88be23d2287bbe69 100644 Binary files a/Content/Components/Movement/IA_DesktopRotation.uasset and b/Content/Components/Movement/IA_DesktopRotation.uasset differ diff --git a/Content/Components/Movement/IA_Move.uasset b/Content/Components/Movement/IA_Move.uasset index 30f4d9b9229ee3d6b908b89853371f08570b5284..3ed093a673b85e12d24ec5b3e8899478d8dddecf 100644 Binary files a/Content/Components/Movement/IA_Move.uasset and b/Content/Components/Movement/IA_Move.uasset differ diff --git a/Content/Components/Movement/IA_MoveUp.uasset b/Content/Components/Movement/IA_MoveUp.uasset index c8552464fd1ab0f87e4bb178f54f7a52053f646d..99fa5ec30e16ae367180e862e408e913549f1d99 100644 Binary files a/Content/Components/Movement/IA_MoveUp.uasset and b/Content/Components/Movement/IA_MoveUp.uasset differ diff --git a/Content/Components/Movement/IA_Turn.uasset b/Content/Components/Movement/IA_Turn.uasset index 32f606e3caf67014426eeaf9668bfba50d52ba23..e3571167c6e95853fae3b9314e883041468032dc 100644 Binary files a/Content/Components/Movement/IA_Turn.uasset and b/Content/Components/Movement/IA_Turn.uasset differ diff --git a/Content/Components/Movement/IMC_MovementLeftHand.uasset b/Content/Components/Movement/IMC_MovementLeftHand.uasset index a47951fbbd1e0a6673d789b6f4ff000e9833b35b..6433b73e1cced50e4461445fb61ee59c67141454 100644 Binary files a/Content/Components/Movement/IMC_MovementLeftHand.uasset and b/Content/Components/Movement/IMC_MovementLeftHand.uasset differ diff --git a/Content/Components/Movement/IMC_MovementRightHand.uasset b/Content/Components/Movement/IMC_MovementRightHand.uasset index f3595814ec6a7ada864dfadaa9a3a4d1e5af4949..96445a0942239961dbbee23eeb8210065e00aed3 100644 Binary files a/Content/Components/Movement/IMC_MovementRightHand.uasset and b/Content/Components/Movement/IMC_MovementRightHand.uasset differ diff --git a/Content/Components/Movement/Teleportation/Arrow.uasset b/Content/Components/Movement/Teleportation/Arrow.uasset new file mode 100644 index 0000000000000000000000000000000000000000..7b64317bd560683e5a80444e0f62325d778623ee Binary files /dev/null and b/Content/Components/Movement/Teleportation/Arrow.uasset differ diff --git a/Content/Components/Movement/Teleportation/Materials/DefaultRibbonMaterial_NoGradient.uasset b/Content/Components/Movement/Teleportation/Materials/DefaultRibbonMaterial_NoGradient.uasset new file mode 100644 index 0000000000000000000000000000000000000000..ac47615c9f9da139a24aaf772d1303e7dc1b09bc Binary files /dev/null and b/Content/Components/Movement/Teleportation/Materials/DefaultRibbonMaterial_NoGradient.uasset differ diff --git a/Content/Components/Movement/Teleportation/Materials/M_TeleportCylinder.uasset b/Content/Components/Movement/Teleportation/Materials/M_TeleportCylinder.uasset new file mode 100644 index 0000000000000000000000000000000000000000..6420372e4f5fa79afd155cba71ef0fd95887b8ee Binary files /dev/null and b/Content/Components/Movement/Teleportation/Materials/M_TeleportCylinder.uasset differ diff --git a/Content/Components/Movement/Teleportation/Materials/M_TeleportNoise.uasset b/Content/Components/Movement/Teleportation/Materials/M_TeleportNoise.uasset new file mode 100644 index 0000000000000000000000000000000000000000..762a6253fca191c58bac445b8771f3b80f31b7da Binary files /dev/null and b/Content/Components/Movement/Teleportation/Materials/M_TeleportNoise.uasset differ diff --git a/Content/Components/Movement/Teleportation/TeleportationComponent.uasset b/Content/Components/Movement/Teleportation/TeleportationComponent.uasset new file mode 100644 index 0000000000000000000000000000000000000000..06f428ca1ec69ad72ad4a4256b5853296a39a60d Binary files /dev/null and b/Content/Components/Movement/Teleportation/TeleportationComponent.uasset differ diff --git a/Content/Components/Movement/Teleportation/VFX/NPC_VRTemplate.uasset b/Content/Components/Movement/Teleportation/VFX/NPC_VRTemplate.uasset new file mode 100644 index 0000000000000000000000000000000000000000..2c68021f8a71ca02827854330b973ab782545882 Binary files /dev/null and b/Content/Components/Movement/Teleportation/VFX/NPC_VRTemplate.uasset differ diff --git a/Content/Components/Movement/Teleportation/VFX/NS_PlayAreaBounds.uasset b/Content/Components/Movement/Teleportation/VFX/NS_PlayAreaBounds.uasset new file mode 100644 index 0000000000000000000000000000000000000000..53f9a269714e49d46357efc74a9a8befe88fb66e Binary files /dev/null and b/Content/Components/Movement/Teleportation/VFX/NS_PlayAreaBounds.uasset differ diff --git a/Content/Components/Movement/Teleportation/VFX/NS_TeleportRing.uasset b/Content/Components/Movement/Teleportation/VFX/NS_TeleportRing.uasset new file mode 100644 index 0000000000000000000000000000000000000000..47225be89cfb4da9f70afa8fc36003977d2be1d6 Binary files /dev/null and b/Content/Components/Movement/Teleportation/VFX/NS_TeleportRing.uasset differ diff --git a/Content/Components/Movement/Teleportation/VFX/NS_TeleportTrace.uasset b/Content/Components/Movement/Teleportation/VFX/NS_TeleportTrace.uasset new file mode 100644 index 0000000000000000000000000000000000000000..02560d4b5203637d587ce51a3679318ba6ca740a Binary files /dev/null and b/Content/Components/Movement/Teleportation/VFX/NS_TeleportTrace.uasset differ diff --git a/Content/Components/Movement/Teleportation/VRTeleportVisualizer.uasset b/Content/Components/Movement/Teleportation/VRTeleportVisualizer.uasset new file mode 100644 index 0000000000000000000000000000000000000000..8391f7295fbb35e9cb7d8172853ebd0393e5714f Binary files /dev/null and b/Content/Components/Movement/Teleportation/VRTeleportVisualizer.uasset differ diff --git a/Content/Components/Movement/Teleportation/mat5.uasset b/Content/Components/Movement/Teleportation/mat5.uasset new file mode 100644 index 0000000000000000000000000000000000000000..d49a23804eeb6f40a5e49e209b2b221001be8ca5 Binary files /dev/null and b/Content/Components/Movement/Teleportation/mat5.uasset differ diff --git a/Content/Input/InputActions/IA_DesktopRotation.uasset b/Content/Input/InputActions/IA_DesktopRotation.uasset index eaf33f335199a6d8d8bd0be40ea7718a65c125a7..026d276385e99ac5ce563ee53127d8e2a025a4d5 100644 Binary files a/Content/Input/InputActions/IA_DesktopRotation.uasset and b/Content/Input/InputActions/IA_DesktopRotation.uasset differ diff --git a/Content/Input/InputActions/IA_Move.uasset b/Content/Input/InputActions/IA_Move.uasset index e62ed997a18b8fc4f2d467992313c7c5a8db3727..a345daa29c27dd76083051f1da4eddaefb409156 100644 Binary files a/Content/Input/InputActions/IA_Move.uasset and b/Content/Input/InputActions/IA_Move.uasset differ diff --git a/Content/Input/InputActions/IA_MoveUp.uasset b/Content/Input/InputActions/IA_MoveUp.uasset index cbfa31b796158fded3da35daf2712b8ac65cc216..09d3041aa08fd5fd0a7248fa54bd2fae5a878f4e 100644 Binary files a/Content/Input/InputActions/IA_MoveUp.uasset and b/Content/Input/InputActions/IA_MoveUp.uasset differ diff --git a/Content/Input/InputActions/IA_Turn.uasset b/Content/Input/InputActions/IA_Turn.uasset index 722e5c0061beda4af697ff039ab7495fe9f6de4f..c670f8762cf093181d26cf992a4e22909bf8b07c 100644 Binary files a/Content/Input/InputActions/IA_Turn.uasset and b/Content/Input/InputActions/IA_Turn.uasset differ diff --git a/Content/RWTHVRGameMode.uasset b/Content/RWTHVRGameMode.uasset index e7a13dbbd502806e10afe7d6de403ff3db8cd164..6e3b11f843990e7dd4f9418596c8987874829aa1 100644 Binary files a/Content/RWTHVRGameMode.uasset and b/Content/RWTHVRGameMode.uasset differ diff --git a/Content/TestMap.umap b/Content/TestMap.umap index 22257960e7d80f036ceeea2c052570f30f6a7aaa..7011da4b6ba3919d325f4cce30ec9330e77770df 100644 Binary files a/Content/TestMap.umap and b/Content/TestMap.umap differ diff --git a/RWTHVRToolkit.uplugin b/RWTHVRToolkit.uplugin index 105867ccdbf98f09afcc08121d9a7849e244f78a..1c0bcb4332ebb58f2526e4bdb53e08b2ea89461e 100644 --- a/RWTHVRToolkit.uplugin +++ b/RWTHVRToolkit.uplugin @@ -64,6 +64,10 @@ { "Name": "EnhancedInput", "Enabled": true + }, + { + "Name": "Niagara", + "Enabled": true } ] } \ No newline at end of file diff --git a/Source/RWTHVRToolkit/Private/Interaction/InteractableBase.cpp b/Source/RWTHVRToolkit/Private/Interaction/InteractableBase.cpp index 856fd73a136577edbffbae5e01c1ae5fdebd82d5..d9522129fd474f5830014c12eb891b3a9467e4a4 100644 --- a/Source/RWTHVRToolkit/Private/Interaction/InteractableBase.cpp +++ b/Source/RWTHVRToolkit/Private/Interaction/InteractableBase.cpp @@ -5,6 +5,7 @@ #include "Interaction/ClickBehaviour.h" #include "Interaction/HoverBehaviour.h" +#include "Utility/VirtualRealityUtilities.h" // Sets default values for this component's properties UInteractableBase::UInteractableBase() @@ -103,18 +104,25 @@ void UInteractableBase::HandleOnClickEndEvents(USceneComponent* TriggerComponent void UInteractableBase::InitDefaultBehaviourReferences() { - //Selecting - TInlineComponentArray<UHoverBehaviour*> AttachedHoverBehaviours; - GetOwner()->GetComponents(AttachedHoverBehaviours, true); - - OnHoverBehaviours = AttachedHoverBehaviours; - - //Clicking - TInlineComponentArray<UClickBehaviour*> AttachedClickBehaviours; - GetOwner()->GetComponents(AttachedClickBehaviours, true); + // only do this if empty, otherwise the user has explicitly stated, which behaviors to include + if(OnHoverBehaviours.IsEmpty()) + { + //Selecting + TInlineComponentArray<UHoverBehaviour*> AttachedHoverBehaviours; + GetOwner()->GetComponents(AttachedHoverBehaviours, true); - OnClickBehaviours = AttachedClickBehaviours; + OnHoverBehaviours = AttachedHoverBehaviours; + } + + // only do this if empty, otherwise the user has explicitly stated, which behaviors to include + if(OnClickBehaviours.IsEmpty()) + { + //Clicking + TInlineComponentArray<UClickBehaviour*> AttachedClickBehaviours; + GetOwner()->GetComponents(AttachedClickBehaviours, true); + OnClickBehaviours = AttachedClickBehaviours; + } } bool UInteractableBase::IsComponentAllowed(USceneComponent* Component) const diff --git a/Source/RWTHVRToolkit/Private/Interaction/OnClickGrabBehavior.cpp b/Source/RWTHVRToolkit/Private/Interaction/OnClickGrabBehavior.cpp index 0a3e29aca8b8cb4dd880c7a318deaefaa4b71240..e258d69399cc8c7adf666c769c319fefe96902f2 100644 --- a/Source/RWTHVRToolkit/Private/Interaction/OnClickGrabBehavior.cpp +++ b/Source/RWTHVRToolkit/Private/Interaction/OnClickGrabBehavior.cpp @@ -7,6 +7,7 @@ #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() @@ -64,6 +65,7 @@ UPrimitiveComponent* UOnClickGrabBehavior::GetHighestParentSimulatingPhysics(UPr void UOnClickGrabBehavior::OnClickStart(USceneComponent* TriggeredComponent, const FInputActionValue& Value) { + UE_LOG(Toolkit, Error, TEXT("Click Start in On Click Grab")) const APawn* Player = UGameplayStatics::GetPlayerPawn(GetWorld(), 0); USceneComponent* Hand = Cast<USceneComponent>(TriggeredComponent->GetAttachParent()); @@ -73,10 +75,13 @@ void UOnClickGrabBehavior::OnClickStart(USceneComponent* TriggeredComponent, con MyPhysicsComponent = GetFirstComponentSimulatingPhysics(GetOwner()); if (MyPhysicsComponent) { + UE_LOG(Toolkit, Error, TEXT("Attach to Component phisics comp")) MyPhysicsComponent->SetSimulatePhysics(false); MyPhysicsComponent->AttachToComponent(Hand, Rules); } - else { + else + { + UE_LOG(Toolkit, Error, TEXT("Attach to Component else")) GetOwner()->GetRootComponent()->AttachToComponent(Hand, Rules); } diff --git a/Source/RWTHVRToolkit/Private/Interaction/RaycastSelectionComponent.cpp b/Source/RWTHVRToolkit/Private/Interaction/RaycastSelectionComponent.cpp index 76365b59dc362640a28cac67d820907799b753b5..808c5249412591889bc172e5fe1e708e958e26ee 100644 --- a/Source/RWTHVRToolkit/Private/Interaction/RaycastSelectionComponent.cpp +++ b/Source/RWTHVRToolkit/Private/Interaction/RaycastSelectionComponent.cpp @@ -91,8 +91,12 @@ void URaycastSelectionComponent::SetupInputActions() void URaycastSelectionComponent::OnBeginSelect(const FInputActionValue& Value) { + UE_LOG(Toolkit, Error, TEXT("Begin Select")) if(CurrentRaycastSelectable) + { + UE_LOG(Toolkit, Error, TEXT("Selectable is valid")) CurrentRaycastSelectable->HandleOnClickStartEvents(this, Value); + } } void URaycastSelectionComponent::OnEndSelect(const FInputActionValue& Value) diff --git a/Source/RWTHVRToolkit/Private/Pawn/ContinuousMovementComponent.cpp b/Source/RWTHVRToolkit/Private/Pawn/ContinuousMovementComponent.cpp index 78e58fc7b9774038b3f476de359dbf6dbaeb7ef5..af46f80934f02d316a5680f35a1a0a684c809cd3 100644 --- a/Source/RWTHVRToolkit/Private/Pawn/ContinuousMovementComponent.cpp +++ b/Source/RWTHVRToolkit/Private/Pawn/ContinuousMovementComponent.cpp @@ -55,15 +55,20 @@ void UContinuousMovementComponent::SetupInputActions() EI->BindAction(Move, ETriggerEvent::Triggered, this, &UContinuousMovementComponent::OnBeginMove); // turning - if(bSnapTurn && !UVirtualRealityUtilities::IsDesktopMode()) - { - EI->BindAction(Turn, ETriggerEvent::Started, this, &UContinuousMovementComponent::OnBeginSnapTurn); - } else + + if(bAllowTurning) { - EI->BindAction(Turn, ETriggerEvent::Triggered, this, &UContinuousMovementComponent::OnBeginTurn); + // no snap turning for desktop mode + if(bSnapTurn && !UVirtualRealityUtilities::IsDesktopMode()) + { + EI->BindAction(Turn, ETriggerEvent::Started, this, &UContinuousMovementComponent::OnBeginSnapTurn); + } else + { + EI->BindAction(Turn, ETriggerEvent::Triggered, this, &UContinuousMovementComponent::OnBeginTurn); + } } - // bind functions for desktop rotations only on holding down right mouse + // bind additional functions for desktop rotations if (UVirtualRealityUtilities::IsDesktopMode()) { APlayerController* PC = Cast<APlayerController>(VRPawn->GetController()); diff --git a/Source/RWTHVRToolkit/Private/Pawn/TeleportationComponent.cpp b/Source/RWTHVRToolkit/Private/Pawn/TeleportationComponent.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b775efcac63506828c7112e3675cad196a652ce5 --- /dev/null +++ b/Source/RWTHVRToolkit/Private/Pawn/TeleportationComponent.cpp @@ -0,0 +1,290 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "Pawn/TeleportationComponent.h" + +#include "EnhancedInputComponent.h" +#include "EnhancedInputSubsystems.h" +#include "NavigationSystem.h" +#include "Engine/LocalPlayer.h" +#include "GameFramework/PlayerController.h" +#include "Pawn/VRPawnInputConfig.h" +#include "NiagaraFunctionLibrary.h" +#include "Kismet/GameplayStatics.h" +#include "NiagaraDataInterfaceArrayFunctionLibrary.h" +#include "Utility/VirtualRealityUtilities.h" + +// Sets default values for this component's properties +UTeleportationComponent::UTeleportationComponent() +{ + // 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 UTeleportationComponent::BeginPlay() +{ + Super::BeginPlay(); + + VRPawn = Cast<AVirtualRealityPawn>(GetOwner()); + SetupInputActions(); + + TeleportTraceComponent = UNiagaraFunctionLibrary::SpawnSystemAtLocation + ( + GetWorld(), + TeleportTraceSystem, + GetOwner()->GetActorLocation(), + FRotator(0), + FVector(1), + true, + true, + ENCPoolMethod::AutoRelease, + true + ); + + FActorSpawnParameters SpawnParameters = FActorSpawnParameters(); + SpawnParameters.Name = "TeleportVisualizer"; + if(BPTeleportVisualizer) + { + TeleportVisualizer = GetWorld()->SpawnActor<AActor>(BPTeleportVisualizer,GetOwner()->GetActorLocation(),GetOwner()->GetActorRotation(),SpawnParameters); + } + TeleportTraceComponent->SetVisibility(false); + TeleportVisualizer->SetActorHiddenInGame(true); + + + // ... +} + +// Called every frame +void UTeleportationComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) +{ + Super::TickComponent(DeltaTime, TickType, ThisTickFunction); + + // ... +} + +void UTeleportationComponent::SetupInputActions() +{ + // simple way of changing the handedness + if(bMoveWithRightHand) + { + TeleportationHand = VRPawn->RightHand; + RotationHand = VRPawn->LeftHand; + IMCMovement = IMCTeleportRight; + } else + { + TeleportationHand = VRPawn->LeftHand; + RotationHand = VRPawn->RightHand; + IMCMovement = IMCTeleportLeft; + } + + const APlayerController* PlayerController = Cast<APlayerController>(VRPawn->GetController()); + UEnhancedInputLocalPlayerSubsystem* InputSubsystem = ULocalPlayer::GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(PlayerController->GetLocalPlayer()); + if(!InputSubsystem) + { + UE_LOG(Toolkit,Error,TEXT("InputSubsystem IS NOT VALID")); + return; + } + // add Input Mapping context + InputSubsystem->AddMappingContext(IMCMovement,0); + + UEnhancedInputComponent* EI = Cast<UEnhancedInputComponent>(VRPawn->InputComponent); + if(!EI) + { + UE_LOG(Toolkit,Error,TEXT("Cannot cast Input Component to Enhanced Inpu Component in VRPawnMovement")); + return; + } + + // walking + EI->BindAction(Move, ETriggerEvent::Started, this, &UTeleportationComponent::OnStartTeleportTrace); + EI->BindAction(Move, ETriggerEvent::Triggered, this, &UTeleportationComponent::UpdateTeleportTrace); + EI->BindAction(Move, ETriggerEvent::Completed, this, &UTeleportationComponent::OnEndTeleportTrace); + EI->BindAction(Move, ETriggerEvent::Canceled, this, &UTeleportationComponent::OnEndTeleportTrace); + + // turning + if(bSnapTurn && !UVirtualRealityUtilities::IsDesktopMode()) + { + EI->BindAction(Turn, ETriggerEvent::Started, this, &UTeleportationComponent::OnBeginSnapTurn); + } else + { + EI->BindAction(Turn, ETriggerEvent::Triggered, this, &UTeleportationComponent::OnBeginTurn); + } + + // bind functions for desktop rotations only on holding down right mouse + if (UVirtualRealityUtilities::IsDesktopMode()) + { + APlayerController* PC = Cast<APlayerController>(VRPawn->GetController()); + if (PC) + { + PC->bShowMouseCursor = true; + PC->bEnableClickEvents = true; + PC->bEnableMouseOverEvents = true; + } else + { + UE_LOG(LogTemp,Error,TEXT("PC Player Controller is invalid")); + } + EI->BindAction(DesktopRotation, ETriggerEvent::Started, this, &UTeleportationComponent::StartDesktopRotation); + EI->BindAction(DesktopRotation, ETriggerEvent::Completed, this, &UTeleportationComponent::EndDesktopRotation); + } +} + +void UTeleportationComponent::StartDesktopRotation() +{ + bApplyDesktopRotation = true; +} + +void UTeleportationComponent::EndDesktopRotation() +{ + bApplyDesktopRotation = false; +} + +// On button press -> show teleport trace +void UTeleportationComponent::OnStartTeleportTrace(const FInputActionValue& Value) +{ + // Start Trace + bTeleportTraceActive = true; + TeleportTraceComponent->SetVisibility(true); + TeleportVisualizer->SetActorHiddenInGame(false); +} + +// called while button is pressed (Triggered) +void UTeleportationComponent::UpdateTeleportTrace(const FInputActionValue& Value) +{ + // Update the teleport trace + FVector StartPosition = TeleportationHand->GetComponentLocation(); + FVector ForwardVector = TeleportationHand->GetForwardVector(); + + TArray<AActor> ActorsToIgnore; + + FPredictProjectilePathParams PredictParams = FPredictProjectilePathParams + ( + TeleportProjectileRadius, + StartPosition, + TeleportLaunchSpeed * ForwardVector, + 5.0, + ECC_WorldStatic + ); + + PredictParams.ActorsToIgnore.Add(GetOwner()); + PredictParams.ActorsToIgnore.Add(TeleportVisualizer); + + UGameplayStatics::PredictProjectilePath(GetWorld(),PredictParams,PredictResult); + + FVector HitLocation = PredictResult.HitResult.Location; + bool bValidHit = PredictResult.HitResult.IsValidBlockingHit(); + // check if this is a valid location to move to + FNavLocation OutLocation; + + FNavAgentProperties AgentProperties = FNavAgentProperties(15, 160); + + UNavigationSystemV1* NavSystem = UNavigationSystemV1::GetCurrent(GetWorld()); + // TODO: does not give valid location + const bool bValidProjection = NavSystem->ProjectPointToNavigation(HitLocation,OutLocation,FVector(1,1,1), &AgentProperties); + + if(bUseNavMesh) + { + FinalTeleportLocation = OutLocation.Location; + if(bValidTeleportLocation != bValidProjection) + { + bValidTeleportLocation = bValidProjection; + TeleportVisualizer->SetActorHiddenInGame(!bValidTeleportLocation); + } + } else + { + if(bValidHit) + { + FinalTeleportLocation = HitLocation; + TeleportVisualizer->SetActorHiddenInGame(false); + // update location + TeleportVisualizer->SetActorLocation(FinalTeleportLocation); + } + } + + + TArray<FVector> PathPoints; + PathPoints.Add(StartPosition); + for(FPredictProjectilePathPointData PData : PredictResult.PathData) + { + PathPoints.Add(PData.Location); + } + UNiagaraDataInterfaceArrayFunctionLibrary::SetNiagaraArrayVector(TeleportTraceComponent,FName("User.PointArray"),PathPoints); + +} + +// On button release -> remove trace and teleport user to location +void UTeleportationComponent::OnEndTeleportTrace(const FInputActionValue& Value) +{ + + // End Teleport Trace + bTeleportTraceActive = false; + TeleportTraceComponent->SetVisibility(false); + TeleportVisualizer->SetActorHiddenInGame(true); + + bValidTeleportLocation = false; + GetOwner()->TeleportTo(FinalTeleportLocation,GetOwner()->GetActorRotation()); + +} + +void UTeleportationComponent::OnBeginTurn(const FInputActionValue& Value) +{ + if(UVirtualRealityUtilities::IsDesktopMode() && !bApplyDesktopRotation) return; + if (VRPawn->Controller != nullptr) + { + const FVector2D TurnValue = Value.Get<FVector2D>(); + + if (TurnValue.X != 0.f) + { + VRPawn->AddControllerYawInput(TurnRateFactor * TurnValue.X); + if (UVirtualRealityUtilities::IsDesktopMode()) + { + UpdateRightHandForDesktopInteraction(); + } + } + + if (TurnValue.Y != 0.f) + { + if (UVirtualRealityUtilities::IsDesktopMode() && bApplyDesktopRotation) + { + VRPawn->AddControllerPitchInput(TurnRateFactor * -TurnValue.Y); + SetCameraOffset(); + } + } + } +} + +void UTeleportationComponent::OnBeginSnapTurn(const FInputActionValue& Value) +{ + const FVector2D TurnValue = Value.Get<FVector2D>(); + if (TurnValue.X > 0.f) + { + VRPawn->AddControllerYawInput(SnapTurnAngle); + } else if (TurnValue.X < 0.f) + { + VRPawn->AddControllerYawInput(-SnapTurnAngle); + } +} + +void UTeleportationComponent::SetCameraOffset() const +{ + // this also incorporates the BaseEyeHeight, if set as static offset, + // rotations are still around the center of the pawn (on the floor), so pitch rotations look weird + FVector Location; + FRotator Rotation; + VRPawn->GetActorEyesViewPoint(Location, Rotation); + VRPawn->CameraComponent->SetWorldLocationAndRotation(Location, Rotation); +} + +void UTeleportationComponent::UpdateRightHandForDesktopInteraction() +{ + APlayerController* PC = Cast<APlayerController>(VRPawn->GetController()); + if (PC) + { + FVector MouseLocation, MouseDirection; + PC->DeprojectMousePositionToWorld(MouseLocation, MouseDirection); + FRotator HandOrientation = MouseDirection.ToOrientationRotator(); + VRPawn->RightHand->SetWorldRotation(HandOrientation); + } +} + diff --git a/Source/RWTHVRToolkit/Public/Interaction/GrabComponent.h b/Source/RWTHVRToolkit/Public/Interaction/GrabComponent.h index 0ab857c28defeef3c9884f63bd519e717f7009fe..3165dc1b3ad32ad87cdd0f539c720b5360eff625 100644 --- a/Source/RWTHVRToolkit/Public/Interaction/GrabComponent.h +++ b/Source/RWTHVRToolkit/Public/Interaction/GrabComponent.h @@ -29,7 +29,7 @@ public: float GrabSphereRadius = 15.0; UPROPERTY(EditAnywhere,BlueprintReadWrite,Category = "Grabbing") - bool bShowDebugTrace = true; + bool bShowDebugTrace = false; protected: diff --git a/Source/RWTHVRToolkit/Public/Interaction/InteractableBase.h b/Source/RWTHVRToolkit/Public/Interaction/InteractableBase.h index f13704b4e53cf7a31d890f3dfb33466df535347c..1f4d92b20e16d3c0b754f82f5860c49a8ddbc56c 100644 --- a/Source/RWTHVRToolkit/Public/Interaction/InteractableBase.h +++ b/Source/RWTHVRToolkit/Public/Interaction/InteractableBase.h @@ -28,7 +28,7 @@ public: 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 @@ -47,15 +47,19 @@ protected: // Called when the game starts virtual void BeginPlay() override; + public: // Called every frame virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override; - + void HandleOnHoverStartEvents(USceneComponent* TriggerComponent); void HandleOnHoverEndEvents(USceneComponent* TriggerComponent); void HandleOnClickStartEvents(USceneComponent* TriggerComponent, const FInputActionValue& Value); void HandleOnClickEndEvents(USceneComponent* TriggerComponent, const FInputActionValue& Value); + /** + * @brief If click and grab behaviors are not explicitly specified, load all existing ones + */ void InitDefaultBehaviourReferences(); // Hit event of component that triggered this interactable @@ -70,5 +74,8 @@ public: bool IsComponentAllowed(USceneComponent* Component) const; +private: + + bool bInitOnce = true; }; diff --git a/Source/RWTHVRToolkit/Public/Interaction/RaycastSelectionComponent.h b/Source/RWTHVRToolkit/Public/Interaction/RaycastSelectionComponent.h index 074c863d19b7699e4085f8bb113ca834a6739e1c..718c54f24cc525415e6b242ed2e56c436739d5aa 100644 --- a/Source/RWTHVRToolkit/Public/Interaction/RaycastSelectionComponent.h +++ b/Source/RWTHVRToolkit/Public/Interaction/RaycastSelectionComponent.h @@ -35,7 +35,7 @@ public: UPROPERTY(EditAnywhere,BlueprintReadWrite,Category = "Raycast") float TraceLength = 3000.0; UPROPERTY(EditAnywhere,BlueprintReadWrite,Category = "Raycast") - bool bShowDebugTrace = true; + bool bShowDebugTrace = false; private: void SetupInputActions(); diff --git a/Source/RWTHVRToolkit/Public/Pawn/ContinuousMovementComponent.h b/Source/RWTHVRToolkit/Public/Pawn/ContinuousMovementComponent.h index 36af1239b68d143348816b899d836c6be789c36d..38bada0c11d392d7e011b4d9d2830c3399197bf2 100644 --- a/Source/RWTHVRToolkit/Public/Pawn/ContinuousMovementComponent.h +++ b/Source/RWTHVRToolkit/Public/Pawn/ContinuousMovementComponent.h @@ -31,15 +31,18 @@ public: EVRSteeringModes SteeringMode = EVRSteeringModes::STEER_HAND_DIRECTED; UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VR Movement") - bool bMoveWithRightHand = false; + bool bMoveWithRightHand = true; - UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VR Movement") + UPROPERTY(EditAnywhere,BlueprintReadWrite, Category = "VR Movement") + bool bAllowTurning = true; + + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VR Movement|Turning", meta=(EditCondition="bAllowTurning")) bool bSnapTurn = false; - UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VR Movement", meta=(EditCondition="!bSnapTurn")) + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VR Movement|Turning", meta=(EditCondition="!bSnapTurn && bAllowTurning")) float TurnRateFactor = 1.0f; - UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VR Movement", meta=(EditCondition="bSnapTurn",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") diff --git a/Source/RWTHVRToolkit/Public/Pawn/TeleportationComponent.h b/Source/RWTHVRToolkit/Public/Pawn/TeleportationComponent.h new file mode 100644 index 0000000000000000000000000000000000000000..4521fdd7322e5880f533d674b73ee992ffbf926e --- /dev/null +++ b/Source/RWTHVRToolkit/Public/Pawn/TeleportationComponent.h @@ -0,0 +1,149 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "Components/ActorComponent.h" +#include "Pawn/VirtualRealityPawn.h" +#include "NiagaraComponent.h" +#include "Kismet/GameplayStaticsTypes.h" + + +#include "TeleportationComponent.generated.h" + + +UCLASS(Blueprintable) +class RWTHVRTOOLKIT_API UTeleportationComponent : public UActorComponent +{ + GENERATED_BODY() + +public: + // Sets default values for this component's properties + UTeleportationComponent(); + +protected: + // Called when the game starts + virtual void BeginPlay() override; + +public: + // Called every frame + virtual void TickComponent(float DeltaTime, ELevelTick TickType, + FActorComponentTickFunction* ThisTickFunction) override; + + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VR Movement") + bool bMoveWithRightHand = true; + + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VR Movement") + bool bAllowTurning = true; + + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VR Movement|Turning", meta=(EditCondition="bAllowTurning")) + bool bSnapTurn = false; + + 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)) + float SnapTurnAngle = 22.5; + + /** + * Whether the hit location of the teleport trace should be projected onto the navigation mesh + * TODO: does currently not work, so leave it at false + */ + UPROPERTY(VisibleAnywhere, Category = "VR Movement|Teleport") + bool bUseNavMesh = false; + + + /** + * Speed at which the projectile shoots out from the controller to get the teleport location + * Higher values = larger teleportation range + */ + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VR Movement|Teleport") + float TeleportLaunchSpeed = 800; + + UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "VR Movement|Input") + class UInputMappingContext* IMCTeleportLeft; + + UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "VR Movement|Input") + class UInputMappingContext* IMCTeleportRight; + + UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "VR Movement|Input|Actions") + class UInputAction* Move; + + UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "VR Movement|Input|Actions") + class UInputAction* Turn; + + UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "VR Movement|Input|Actions") + class UInputAction* DesktopRotation; + + /*Movement Input*/ + UFUNCTION(BlueprintCallable) + void OnStartTeleportTrace(const FInputActionValue& Value); + + UFUNCTION(BlueprintCallable) + void UpdateTeleportTrace(const FInputActionValue& Value); + + UFUNCTION(BlueprintCallable) + void OnEndTeleportTrace(const FInputActionValue& Value); + + + 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(); + + bool bApplyDesktopRotation = false; + + + // Trace Visualization + UPROPERTY(EditAnywhere) + TSubclassOf<AActor> BPTeleportVisualizer; + + UPROPERTY(EditDefaultsOnly) + UNiagaraSystem* TeleportTraceSystem; + + UPROPERTY() + UNiagaraComponent* TeleportTraceComponent; + +private: + UPROPERTY() + UUniversalTrackedComponent* TeleportationHand; + + UPROPERTY() + UUniversalTrackedComponent* RotationHand; + + UPROPERTY() + class UInputMappingContext* IMCMovement; + + void SetupInputActions(); + + UPROPERTY() + AVirtualRealityPawn* VRPawn; + + /** + * Fixes camera rotation in desktop mode. + */ + void SetCameraOffset() const; + void UpdateRightHandForDesktopInteraction(); + + bool bTeleportTraceActive; + float TeleportProjectileRadius = 3.6; + float RotationArrowRadius = 10.0; + FPredictProjectilePathResult PredictResult; + bool bValidTeleportLocation = false; + FVector FinalTeleportLocation; + + UPROPERTY() + AActor* TeleportVisualizer; + +}; diff --git a/Source/RWTHVRToolkit/Public/Pawn/VRPawnMovement.h b/Source/RWTHVRToolkit/Public/Pawn/VRPawnMovement.h index 4781254861821137c1c309078983adcdb60acd4b..11e3854f9a1e422ccda91d721281e75441c10466 100644 --- a/Source/RWTHVRToolkit/Public/Pawn/VRPawnMovement.h +++ b/Source/RWTHVRToolkit/Public/Pawn/VRPawnMovement.h @@ -4,7 +4,6 @@ #include "GameFramework/FloatingPawnMovement.h" #include "Components/CapsuleComponent.h" #include "Camera/CameraComponent.h" -#include "Actor.h" #include "VRPawnMovement.generated.h" diff --git a/Source/RWTHVRToolkit/Public/Pawn/VirtualRealityPawn.h b/Source/RWTHVRToolkit/Public/Pawn/VirtualRealityPawn.h index 86803a7ccdd3669df948220321f5a7df0ad4e401..af7c8f2d146080ea0ef8a437ec6f2c98a9a6b214 100644 --- a/Source/RWTHVRToolkit/Public/Pawn/VirtualRealityPawn.h +++ b/Source/RWTHVRToolkit/Public/Pawn/VirtualRealityPawn.h @@ -36,26 +36,15 @@ public: UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Pawn|Interaction") UBasicVRInteractionComponent* BasicVRInteraction; - -<<<<<<< Source/RWTHVRToolkit/Public/Pawn/VirtualRealityPawn.h /* Movement */ - UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Pawn|Movement") UVRPawnMovement* PawnMovement; - UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Pawn|Movement") float BaseTurnRate = 45.0f; -======= - /** Workaround dummy component to prevent the Capsule from rotating in the editor, if LiveLink tracking is being used. - * This happens due to the rotation of the Capsule being set only while in Play Mode (instead of using e.g. absolute rotation). - * Additionally, there is an implicit race condition in Tick, due to LiveLink adjusting the parent's rotation, while the capsule - * then gets rotated back in Tick to be vertical. Depending on the order, LiveLink overrides the VRPawnMovement's rotation settings. - * The dummy seems to fix this, because its absolute rotation just catches all parent rotations and prevents them from - * overriding any of the capsules'. - */ - UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Pawn|Movement") - USceneComponent* CapsuleRotationFix; - UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Pawn|Movement") UVRPawnMovement* PawnMovement; ->>>>>>> Source/RWTHVRToolkit/Public/Pawn/VirtualRealityPawn.h + + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Pawn|Movement") + USceneComponent* CapsuleRotationFix; + + /* CameraComponent */ UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Pawn|Camera") UCameraComponent* CameraComponent; diff --git a/Source/RWTHVRToolkit/RWTHVRToolkit.Build.cs b/Source/RWTHVRToolkit/RWTHVRToolkit.Build.cs index 8345d954abb2ade18d2974e89a1ca9ace8c42c12..d68c4ffc1ab3c60308bc525b24edc6d4c7bb92a6 100644 --- a/Source/RWTHVRToolkit/RWTHVRToolkit.Build.cs +++ b/Source/RWTHVRToolkit/RWTHVRToolkit.Build.cs @@ -29,7 +29,9 @@ public class RWTHVRToolkit : ModuleRules "HTTP", "LiveLink", "LiveLinkInterface", - "EnhancedInput" + "EnhancedInput", + "Niagara", + "NavigationSystem" } );