Skip to content
Snippets Groups Projects
Select Git revision
  • 9e168acb2fae4675c4068ef5e69063a7e9f36d45
  • 5.3 default protected
  • feature/animation-layering-system
  • feature/MH-audio2face
  • feature/add-new-animations
  • fix/investigate-sync-issues
  • WIP/MA_Dasbach_Bystander
  • thesis/MA_Kuehlem
  • deprecated/4.27
  • thesis/MA_drupp_city-guide
  • thesis/BA_pgriesser_handshake
  • thesis/BA_rschaefer
  • deprecated/4.26
  • thesis/MA_Ye
  • thesis/BA_tsittart
  • thesis/MA_amoedder_natural_gaze_sim
  • thesis/MA_tyroller_backchannels
  • thesis/BA_dvonk_influence-maps
  • thesis/MA_dkuznietsov_emotional-speech
  • fix/random
  • deprecated/4.22
21 results

VHSaccades.cpp

Blame
  • ContinuousMovementComponent.cpp 2.66 KiB
    // Fill out your copyright notice in the Description page of Project Settings.
    
    #include "Pawn/Navigation/ContinuousMovementComponent.h"
    
    #include "EnhancedInputComponent.h"
    #include "EnhancedInputSubsystems.h"
    #include "Engine/LocalPlayer.h"
    #include "GameFramework/PlayerController.h"
    #include "Pawn/VRPawnInputConfig.h"
    #include "Utility/VirtualRealityUtilities.h"
    #include "MotionControllerComponent.h"
    
    void UContinuousMovementComponent::SetupPlayerInput(UInputComponent* PlayerInputComponent)
    {
    	Super::SetupPlayerInput(PlayerInputComponent);
    
    	if (!VRPawn || !VRPawn->HasLocalNetOwner() || !InputSubsystem)
    	{
    		return;
    	}
    
    	// simple way of changing the handedness
    	if (bMoveWithRightHand)
    	{
    		MovementHand = VRPawn->RightHand;
    		RotationHand = VRPawn->LeftHand;
    		IMCMovement = IMCMovementRight;
    	}
    	else
    	{
    		MovementHand = VRPawn->LeftHand;
    		RotationHand = VRPawn->RightHand;
    		IMCMovement = IMCMovementLeft;
    	}
    
    	// add Input Mapping context 
    	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"));
    		return;
    	}
    
    	// continuous steering
    	EI->BindAction(Move, ETriggerEvent::Triggered, this, &UContinuousMovementComponent::OnMove);
    	EI->BindAction(MoveUp, ETriggerEvent::Triggered, this, &UContinuousMovementComponent::OnMoveUp);
    
    	// turning is defined in MovementComponentBase
    }
    
    void UContinuousMovementComponent::OnMove(const FInputActionValue& Value)
    {
    	if (!VRPawn || !VRPawn->Controller)
    		return;
    
    	const bool bGazeDirected = UVirtualRealityUtilities::IsDesktopMode() || SteeringMode ==
    		EVRSteeringModes::STEER_GAZE_DIRECTED;
    
    	const FVector ForwardDir = bGazeDirected
    		                           ? VRPawn->HeadCameraComponent->GetForwardVector()
    		                           : MovementHand->GetForwardVector();
    	const FVector RightDir = bGazeDirected
    		                         ? VRPawn->HeadCameraComponent->GetRightVector()
    		                         : MovementHand->GetRightVector();
    
    	const FVector2D MoveValue = Value.Get<FVector2D>();
    
    	// Forward/Backward direction
    	if (MoveValue.X != 0.f)
    	{
    		VRPawn->AddMovementInput(ForwardDir, MoveValue.X);
    	}
    
    	// Right/Left direction
    	if (MoveValue.Y != 0.f)
    	{
    		VRPawn->AddMovementInput(RightDir, MoveValue.Y);
    	}
    }
    
    void UContinuousMovementComponent::OnMoveUp(const FInputActionValue& Value)
    {
    	if (!VRPawn)
    		return;
    
    	const float MoveValue = Value.Get<FVector2D>().X;
    	//the right hand is rotated on desktop to follow the cursor so it's forward is also changing with cursor position
    	VRPawn->AddMovementInput(FVector::UpVector, MoveValue);
    }