Skip to content
Snippets Groups Projects
Commit 2c2b8243 authored by Jonathan Ehret's avatar Jonathan Ehret
Browse files

moved debug desktop hand movement stuff to pawn and fixed it

parent 0c95a467
No related branches found
No related tags found
1 merge request!30Replace LiveLink UniversalTrackedComponent implementation by MotionControllers
...@@ -71,16 +71,6 @@ void UContinuousMovementComponent::SetupInputActions() ...@@ -71,16 +71,6 @@ void UContinuousMovementComponent::SetupInputActions()
// bind additional functions for desktop rotations // bind additional functions for desktop rotations
if (UVirtualRealityUtilities::IsDesktopMode()) 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, &UContinuousMovementComponent::StartDesktopRotation); EI->BindAction(DesktopRotation, ETriggerEvent::Started, this, &UContinuousMovementComponent::StartDesktopRotation);
EI->BindAction(DesktopRotation, ETriggerEvent::Completed, this, &UContinuousMovementComponent::EndDesktopRotation); EI->BindAction(DesktopRotation, ETriggerEvent::Completed, this, &UContinuousMovementComponent::EndDesktopRotation);
EI->BindAction(MoveUp, ETriggerEvent::Triggered,this,&UContinuousMovementComponent::OnBeginUp); EI->BindAction(MoveUp, ETriggerEvent::Triggered,this,&UContinuousMovementComponent::OnBeginUp);
...@@ -133,10 +123,6 @@ void UContinuousMovementComponent::OnBeginTurn(const FInputActionValue& Value) ...@@ -133,10 +123,6 @@ void UContinuousMovementComponent::OnBeginTurn(const FInputActionValue& Value)
if (TurnValue.X != 0.f) if (TurnValue.X != 0.f)
{ {
VRPawn->AddControllerYawInput(TurnRateFactor * TurnValue.X); VRPawn->AddControllerYawInput(TurnRateFactor * TurnValue.X);
if (UVirtualRealityUtilities::IsDesktopMode())
{
UpdateRightHandForDesktopInteraction();
}
} }
if (TurnValue.Y != 0.f) if (TurnValue.Y != 0.f)
...@@ -144,7 +130,6 @@ void UContinuousMovementComponent::OnBeginTurn(const FInputActionValue& Value) ...@@ -144,7 +130,6 @@ void UContinuousMovementComponent::OnBeginTurn(const FInputActionValue& Value)
if (UVirtualRealityUtilities::IsDesktopMode() && bApplyDesktopRotation) if (UVirtualRealityUtilities::IsDesktopMode() && bApplyDesktopRotation)
{ {
VRPawn->AddControllerPitchInput(TurnRateFactor * -TurnValue.Y); VRPawn->AddControllerPitchInput(TurnRateFactor * -TurnValue.Y);
SetCameraOffset();
} }
} }
} }
...@@ -162,28 +147,6 @@ void UContinuousMovementComponent::OnBeginSnapTurn(const FInputActionValue& Valu ...@@ -162,28 +147,6 @@ void UContinuousMovementComponent::OnBeginSnapTurn(const FInputActionValue& Valu
} }
} }
void UContinuousMovementComponent::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->HeadCameraComponent->SetWorldLocationAndRotation(Location, Rotation);
}
void UContinuousMovementComponent::UpdateRightHandForDesktopInteraction()
{
APlayerController* PC = Cast<APlayerController>(VRPawn->GetController());
if (PC)
{
FVector MouseLocation, MouseDirection;
PC->DeprojectMousePositionToWorld(MouseLocation, MouseDirection);
FRotator HandOrientation = MouseDirection.ToOrientationRotator();
VRPawn->RightHand->SetWorldRotation(HandOrientation);
}
}
void UContinuousMovementComponent::OnBeginUp(const FInputActionValue& Value) void UContinuousMovementComponent::OnBeginUp(const FInputActionValue& Value)
{ {
const float MoveValue = Value.Get<FVector2D>().X; const float MoveValue = Value.Get<FVector2D>().X;
......
...@@ -34,13 +34,6 @@ AVirtualRealityPawn::AVirtualRealityPawn(const FObjectInitializer& ObjectInitial ...@@ -34,13 +34,6 @@ AVirtualRealityPawn::AVirtualRealityPawn(const FObjectInitializer& ObjectInitial
RightHand = CreateDefaultSubobject<UMotionControllerComponent>(TEXT("Right Hand MCC")); RightHand = CreateDefaultSubobject<UMotionControllerComponent>(TEXT("Right Hand MCC"));
RightHand->SetupAttachment(RootComponent); RightHand->SetupAttachment(RootComponent);
if(UVirtualRealityUtilities::IsDesktopMode())
{
RightHand->SetEnableGravity(false);
RightHand->SetRelativeLocation(FVector(30,15,BaseEyeHeight-20));
}
LeftHand = CreateDefaultSubobject<UMotionControllerComponent>(TEXT("Left Hand MCC")); LeftHand = CreateDefaultSubobject<UMotionControllerComponent>(TEXT("Left Hand MCC"));
LeftHand->SetupAttachment(RootComponent); LeftHand->SetupAttachment(RootComponent);
...@@ -48,15 +41,37 @@ AVirtualRealityPawn::AVirtualRealityPawn(const FObjectInitializer& ObjectInitial ...@@ -48,15 +41,37 @@ AVirtualRealityPawn::AVirtualRealityPawn(const FObjectInitializer& ObjectInitial
BasicVRInteraction->Initialize(RightHand); BasicVRInteraction->Initialize(RightHand);
} }
void AVirtualRealityPawn::Tick(float DeltaSeconds)
{
Super::Tick(DeltaSeconds);
if (UVirtualRealityUtilities::IsDesktopMode())
{
SetCameraOffset();
UpdateRightHandForDesktopInteraction();
}
}
void AVirtualRealityPawn::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent) void AVirtualRealityPawn::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{ {
const APlayerController* PlayerController = Cast<APlayerController>(GetController()); APlayerController* PlayerController = Cast<APlayerController>(GetController());
if (!PlayerController) {
UE_LOG(LogTemp, Error, TEXT("PC Player Controller is invalid"));
return;
}
UEnhancedInputLocalPlayerSubsystem* InputSubsystem = ULocalPlayer::GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(PlayerController->GetLocalPlayer()); UEnhancedInputLocalPlayerSubsystem* InputSubsystem = ULocalPlayer::GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(PlayerController->GetLocalPlayer());
if(!InputSubsystem) if(!InputSubsystem)
{ {
UE_LOG(Toolkit,Error,TEXT("[VirtualRealiytPawn.cpp] InputSubsystem IS NOT VALID")); UE_LOG(Toolkit,Error,TEXT("[VirtualRealiytPawn.cpp] InputSubsystem IS NOT VALID"));
} }
if(UVirtualRealityUtilities::IsDesktopMode())
{
PlayerController->bShowMouseCursor = true;
PlayerController->bEnableClickEvents = true;
PlayerController->bEnableMouseOverEvents = true;
}
InputSubsystem->ClearAllMappings(); InputSubsystem->ClearAllMappings();
// add Input Mapping context // add Input Mapping context
...@@ -71,6 +86,29 @@ void AVirtualRealityPawn::SetupPlayerInputComponent(UInputComponent* PlayerInput ...@@ -71,6 +86,29 @@ void AVirtualRealityPawn::SetupPlayerInputComponent(UInputComponent* PlayerInput
EI->BindAction(ToggleNavigationMode,ETriggerEvent::Started,this,&AVirtualRealityPawn::OnToggleNavigationMode); EI->BindAction(ToggleNavigationMode,ETriggerEvent::Started,this,&AVirtualRealityPawn::OnToggleNavigationMode);
} }
void AVirtualRealityPawn::UpdateRightHandForDesktopInteraction()
{
APlayerController* PC = Cast<APlayerController>(GetController());
if (PC)
{
FVector MouseLocation, MouseDirection;
PC->DeprojectMousePositionToWorld(MouseLocation, MouseDirection);
FRotator HandOrientation = MouseDirection.ToOrientationRotator();
RightHand->SetWorldRotation(HandOrientation);
RightHand->SetRelativeLocation(HeadCameraComponent->GetRelativeLocation());
}
}
void AVirtualRealityPawn::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;
GetActorEyesViewPoint(Location, Rotation);
HeadCameraComponent->SetWorldLocationAndRotation(Location, Rotation);
}
// legacy grabbing // legacy grabbing
void AVirtualRealityPawn::OnBeginFire(const FInputActionValue& Value) void AVirtualRealityPawn::OnBeginFire(const FInputActionValue& Value)
{ {
......
...@@ -102,10 +102,4 @@ private: ...@@ -102,10 +102,4 @@ private:
UPROPERTY() UPROPERTY()
AVirtualRealityPawn* VRPawn; AVirtualRealityPawn* VRPawn;
/**
* Fixes camera rotation in desktop mode.
*/
void SetCameraOffset() const;
void UpdateRightHandForDesktopInteraction();
}; };
...@@ -21,6 +21,8 @@ class RWTHVRTOOLKIT_API AVirtualRealityPawn : public APawn ...@@ -21,6 +21,8 @@ class RWTHVRTOOLKIT_API AVirtualRealityPawn : public APawn
public: public:
AVirtualRealityPawn(const FObjectInitializer& ObjectInitializer); AVirtualRealityPawn(const FObjectInitializer& ObjectInitializer);
virtual void Tick(float DeltaSeconds) override;
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Pawn|MotionControllers") UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Pawn|MotionControllers")
UMotionControllerComponent* RightHand; UMotionControllerComponent* RightHand;
...@@ -63,4 +65,10 @@ protected: ...@@ -63,4 +65,10 @@ protected:
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Pawn|Input") UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Pawn|Input")
class UInputAction* ToggleNavigationMode; class UInputAction* ToggleNavigationMode;
/**
* Fixes camera rotation in desktop mode.
*/
void SetCameraOffset() const;
void UpdateRightHandForDesktopInteraction();
}; };
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment