From 3a08aadda9f4af10867dc46adcfac8a7adf375e0 Mon Sep 17 00:00:00 2001 From: Ehret <jw210150@WIN.RZ.RWTH-AACHEN.DE> Date: Fri, 8 Apr 2022 12:26:57 +0200 Subject: [PATCH] allow rotations only when right mouse button is held --- .../Private/Pawn/VirtualRealityPawn.cpp | 28 +++++++++++++++++-- .../Public/Pawn/VirtualRealityPawn.h | 6 ++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/Source/RWTHVRToolkit/Private/Pawn/VirtualRealityPawn.cpp b/Source/RWTHVRToolkit/Private/Pawn/VirtualRealityPawn.cpp index df743136..eaccfb7c 100644 --- a/Source/RWTHVRToolkit/Private/Pawn/VirtualRealityPawn.cpp +++ b/Source/RWTHVRToolkit/Private/Pawn/VirtualRealityPawn.cpp @@ -63,6 +63,30 @@ void AVirtualRealityPawn::SetupPlayerInputComponent(UInputComponent* PlayerInput // function bindings for grabbing and releasing PlayerInputComponent->BindAction("Fire", IE_Pressed, this, &AVirtualRealityPawn::OnBeginFire); PlayerInputComponent->BindAction("Fire", IE_Released, this, &AVirtualRealityPawn::OnEndFire); + + // bind functions for desktop rotations only on holding down right mouse + if (UVirtualRealityUtilities::IsDesktopMode()) + { + APlayerController* PC = Cast<APlayerController>(GetController()); + if (PC) + { + PC->bShowMouseCursor = true; + PC->bEnableClickEvents = true; + PC->bEnableMouseOverEvents = true; + } + PlayerInputComponent->BindAction("EnableDesktopRotation", IE_Pressed, this, &AVirtualRealityPawn::StartDesktopRotation); + PlayerInputComponent->BindAction("EnableDesktopRotation", IE_Released, this, &AVirtualRealityPawn::EndDesktopRotation); + } +} + +void AVirtualRealityPawn::StartDesktopRotation() +{ + bApplyDesktopRotation = true; +} + +void AVirtualRealityPawn::EndDesktopRotation() +{ + bApplyDesktopRotation = false; } void AVirtualRealityPawn::SetCameraOffset() const @@ -102,7 +126,7 @@ void AVirtualRealityPawn::OnUp_Implementation(float Value) void AVirtualRealityPawn::OnTurnRate_Implementation(float Rate) { /* Turning the user externally will make them sick */ - if (UVirtualRealityUtilities::IsDesktopMode()) + if (UVirtualRealityUtilities::IsDesktopMode() && bApplyDesktopRotation) { AddControllerYawInput(Rate * BaseTurnRate * GetWorld()->GetDeltaSeconds() * CustomTimeDilation); } @@ -111,7 +135,7 @@ void AVirtualRealityPawn::OnTurnRate_Implementation(float Rate) void AVirtualRealityPawn::OnLookUpRate_Implementation(float Rate) { /* Turning the user externally will make them sick */ - if (UVirtualRealityUtilities::IsDesktopMode()) + if (UVirtualRealityUtilities::IsDesktopMode() && bApplyDesktopRotation) { AddControllerPitchInput(Rate * BaseTurnRate * GetWorld()->GetDeltaSeconds() * CustomTimeDilation); SetCameraOffset(); diff --git a/Source/RWTHVRToolkit/Public/Pawn/VirtualRealityPawn.h b/Source/RWTHVRToolkit/Public/Pawn/VirtualRealityPawn.h index 0e32e7a6..4153d539 100644 --- a/Source/RWTHVRToolkit/Public/Pawn/VirtualRealityPawn.h +++ b/Source/RWTHVRToolkit/Public/Pawn/VirtualRealityPawn.h @@ -48,5 +48,11 @@ protected: UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "Pawn|Interaction") void OnBeginFire(); UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "Pawn|Interaction") void OnEndFire(); + /*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; + void SetCameraOffset() const; }; -- GitLab