diff --git a/Source/RWTHVRToolkit/Private/Pawn/VirtualRealityPawn.cpp b/Source/RWTHVRToolkit/Private/Pawn/VirtualRealityPawn.cpp index 583154554c37cea3b6d0b2acdccb905cf506eeec..06e03060955c7230298531463b4cf02deff8e098 100644 --- a/Source/RWTHVRToolkit/Private/Pawn/VirtualRealityPawn.cpp +++ b/Source/RWTHVRToolkit/Private/Pawn/VirtualRealityPawn.cpp @@ -56,12 +56,37 @@ void AVirtualRealityPawn::SetupPlayerInputComponent(UInputComponent* PlayerInput PlayerInputComponent->BindAxis("MoveForward", this, &AVirtualRealityPawn::OnForward); PlayerInputComponent->BindAxis("MoveRight", this, &AVirtualRealityPawn::OnRight); + PlayerInputComponent->BindAxis("MoveUp", this, &AVirtualRealityPawn::OnUp); PlayerInputComponent->BindAxis("TurnRate", this, &AVirtualRealityPawn::OnTurnRate); PlayerInputComponent->BindAxis("LookUpRate", this, &AVirtualRealityPawn::OnLookUpRate); // 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 @@ -74,6 +99,18 @@ void AVirtualRealityPawn::SetCameraOffset() const CameraComponent->SetWorldLocationAndRotation(Location, Rotation); } +void AVirtualRealityPawn::UpdateRightHandForDesktopInteraction() +{ + APlayerController* PC = Cast<APlayerController>(GetController()); + if (PC) + { + FVector MouseLocation, MouseDirection; + PC->DeprojectMousePositionToWorld(MouseLocation, MouseDirection); + FRotator HandOrientation = MouseDirection.ToOrientationRotator(); + RightHand->SetWorldRotation(HandOrientation); + } +} + void AVirtualRealityPawn::OnForward_Implementation(float Value) { if (RightHand) @@ -90,19 +127,31 @@ void AVirtualRealityPawn::OnRight_Implementation(float Value) } } +void AVirtualRealityPawn::OnUp_Implementation(float Value) +{ + if (RightHand) + { + AddMovementInput(RightHand->GetUpVector(), 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); } + if (UVirtualRealityUtilities::IsDesktopMode()) + { + UpdateRightHandForDesktopInteraction(); + } } 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 9f027a03fe0cd0406687d7ac97adc0f7aaa58c7b..0d46c37621e5b519e2e463b8287579530cbccb73 100644 --- a/Source/RWTHVRToolkit/Public/Pawn/VirtualRealityPawn.h +++ b/Source/RWTHVRToolkit/Public/Pawn/VirtualRealityPawn.h @@ -40,6 +40,7 @@ protected: /* Movement */ UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "Pawn|Movement") void OnForward(float Value); UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "Pawn|Movement") void OnRight(float Value); + UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "Pawn|Movement") void OnUp(float Value); UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "Pawn|Movement") void OnTurnRate(float Rate); UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "Pawn|Movement") void OnLookUpRate(float Rate); @@ -47,5 +48,12 @@ 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; + void UpdateRightHandForDesktopInteraction(); };