diff --git a/Source/DisplayClusterExtensions/Private/VRPawnMovement.cpp b/Source/DisplayClusterExtensions/Private/VRPawnMovement.cpp index 37b75ccf3a9cdd10b80a17a41866d1a20352c0f1..34464addc05d2472d69a3b8befa85e78ce9bf999 100644 --- a/Source/DisplayClusterExtensions/Private/VRPawnMovement.cpp +++ b/Source/DisplayClusterExtensions/Private/VRPawnMovement.cpp @@ -1,4 +1,4 @@ - + #include "VRPawnMovement.h" #include "DrawDebugHelpers.h" @@ -9,6 +9,9 @@ UVRPawnMovement::UVRPawnMovement(const FObjectInitializer& ObjectInitializer) : CapsuleColliderComponent->SetCollisionResponseToAllChannels(ECollisionResponse::ECR_Ignore); CapsuleColliderComponent->SetCollisionResponseToChannel(ECollisionChannel::ECC_WorldStatic, ECollisionResponse::ECR_Block); CapsuleColliderComponent->SetCapsuleSize(40.0f, 96.0f); + + CameraComponent = GetOwner()->FindComponentByClass<UCameraComponent>(); + CapsuleColliderComponent->SetupAttachment(CameraComponent); } void UVRPawnMovement::TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction *ThisTickFunction){ @@ -57,13 +60,6 @@ bool UVRPawnMovement::CheckForVirtualMovCollision(FVector PositionChange, float return false; } -void UVRPawnMovement::SetCameraComponent(UCameraComponent* NewCameraComponent) -{ - CameraComponent = NewCameraComponent; - CapsuleColliderComponent->SetupAttachment(CameraComponent); -} - - void UVRPawnMovement::SetCapsuleColliderToUserSize() { float CharachterSize = abs(UpdatedComponent->GetComponentLocation().Z - CameraComponent->GetComponentLocation().Z); @@ -189,4 +185,4 @@ FHitResult UVRPawnMovement::CreateMultiLineTrace(FVector Direction, const FVecto HitDetailsMultiLineTrace = OutHits[0]; return HitDetailsMultiLineTrace; -} \ No newline at end of file +} diff --git a/Source/DisplayClusterExtensions/Private/VirtualRealityPawn.cpp b/Source/DisplayClusterExtensions/Private/VirtualRealityPawn.cpp index 5a05c6bcb6c51ecc56f6d4e7a60868cc2e936a76..2c6a729d76f78f6e28b098e256e34923a235807c 100644 --- a/Source/DisplayClusterExtensions/Private/VirtualRealityPawn.cpp +++ b/Source/DisplayClusterExtensions/Private/VirtualRealityPawn.cpp @@ -1,116 +1,121 @@ -// Fill out your copyright notice in the Description page of Project Settings. - - -#include "VirtualRealityPawn.h" - - - -#include "GameFramework/InputSettings.h" -#include "GameFramework/PlayerInput.h" -#include "UniversalTrackedComponent.h" -#include "VirtualRealityUtilities.h" -#include "VRPawnMovement.h" - -AVirtualRealityPawn::AVirtualRealityPawn(const FObjectInitializer& ObjectInitializer) - : Super(ObjectInitializer) -{ - bUseControllerRotationYaw = true; - bUseControllerRotationPitch = true; - bUseControllerRotationRoll = true; - BaseEyeHeight = 160.0f; - - AutoPossessPlayer = EAutoReceiveInput::Player0; // Necessary for receiving motion controller events. - - PawnMovement = CreateDefaultSubobject<UVRPawnMovement>(TEXT("Pawn Movement")); - PawnMovement->UpdatedComponent = RootComponent; - - Head = CreateDefaultSubobject<UUniversalTrackedComponent>(TEXT("Head")); - Head->ProxyType = ETrackedComponentType::TCT_HEAD; - Head->SetupAttachment(RootComponent); - - RightHand = CreateDefaultSubobject<UUniversalTrackedComponent>(TEXT("Right Hand")); - RightHand->ProxyType = ETrackedComponentType::TCT_RIGHT_HAND; - RightHand->AttachementType = EAttachementType::AT_FLYSTICK; - RightHand->SetupAttachment(RootComponent); - - LeftHand = CreateDefaultSubobject<UUniversalTrackedComponent>(TEXT("Left Hand")); - LeftHand->ProxyType = ETrackedComponentType::TCT_LEFT_HAND; - LeftHand->AttachementType = EAttachementType::AT_HANDTARGET; - LeftHand->SetupAttachment(RootComponent); - - Tracker1 = CreateDefaultSubobject<UUniversalTrackedComponent>(TEXT("Vive Tracker 1")); - Tracker1->ProxyType = ETrackedComponentType::TCT_TRACKER_1; - Tracker1->SetupAttachment(RootComponent); - - Tracker2 = CreateDefaultSubobject<UUniversalTrackedComponent>(TEXT("Vive Tracker 2")); - Tracker2->ProxyType = ETrackedComponentType::TCT_TRACKER_2; - Tracker2->SetupAttachment(RootComponent); - - BasicVRInteraction = CreateDefaultSubobject<UBasicVRInteractionComponent>(TEXT("Basic VR Interaction")); - BasicVRInteraction->Initialize(RightHand); -} - -void AVirtualRealityPawn::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent) -{ - Super::SetupPlayerInputComponent(PlayerInputComponent); - if (PlayerInputComponent) - { - PlayerInputComponent->BindAxis("MoveForward", this, &AVirtualRealityPawn::OnForward); - PlayerInputComponent->BindAxis("MoveRight", this, &AVirtualRealityPawn::OnRight); - 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); - } -} - -void AVirtualRealityPawn::BeginPlay() -{ - if(!UVirtualRealityUtilities::IsDesktopMode()) /* Disable to not get cyber sick as fast */ - { - UInputSettings::GetInputSettings()->RemoveAxisMapping(FInputAxisKeyMapping("TurnRate", EKeys::MouseX)); - UInputSettings::GetInputSettings()->RemoveAxisMapping(FInputAxisKeyMapping("LookUpRate", EKeys::MouseY)); - } -} - -void AVirtualRealityPawn::OnForward_Implementation(float Value) -{ - if (RightHand) - { - AddMovementInput(RightHand->GetForwardVector(), Value); - } -} - -void AVirtualRealityPawn::OnRight_Implementation(float Value) -{ - if (RightHand) - { - AddMovementInput(RightHand->GetRightVector(), Value); - } -} - -void AVirtualRealityPawn::OnTurnRate_Implementation(float Rate) -{ - AddControllerYawInput(Rate * BaseTurnRate * GetWorld()->GetDeltaSeconds() * CustomTimeDilation); -} - -void AVirtualRealityPawn::OnLookUpRate_Implementation(float Rate) -{ - // User-centered projection causes simulation sickness on look up interaction hence not implemented. - if (!UVirtualRealityUtilities::IsRoomMountedMode()) - { - AddControllerPitchInput(Rate * BaseTurnRate * GetWorld()->GetDeltaSeconds() * CustomTimeDilation); - } -} - -void AVirtualRealityPawn::OnBeginFire_Implementation() -{ - BasicVRInteraction->BeginInteraction(); -} - -void AVirtualRealityPawn::OnEndFire_Implementation() -{ - BasicVRInteraction->EndInteraction(); -} +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "VirtualRealityPawn.h" + + + +#include "GameFramework/InputSettings.h" +#include "GameFramework/PlayerInput.h" +#include "UniversalTrackedComponent.h" +#include "VirtualRealityUtilities.h" +#include "VRPawnMovement.h" + +AVirtualRealityPawn::AVirtualRealityPawn(const FObjectInitializer& ObjectInitializer) + : Super(ObjectInitializer) +{ + bUseControllerRotationYaw = true; + bUseControllerRotationPitch = true; + bUseControllerRotationRoll = true; + BaseEyeHeight = 160.0f; + + AutoPossessPlayer = EAutoReceiveInput::Player0; // Necessary for receiving motion controller events. + + PawnMovement = CreateDefaultSubobject<UVRPawnMovement>(TEXT("Pawn Movement")); + PawnMovement->SetUpdatedComponent(RootComponent); + + Head = CreateDefaultSubobject<UUniversalTrackedComponent>(TEXT("Head")); + Head->ProxyType = ETrackedComponentType::TCT_HEAD; + Head->SetupAttachment(RootComponent); + + RightHand = CreateDefaultSubobject<UUniversalTrackedComponent>(TEXT("Right Hand")); + RightHand->ProxyType = ETrackedComponentType::TCT_RIGHT_HAND; + RightHand->AttachementType = EAttachementType::AT_FLYSTICK; + RightHand->SetupAttachment(RootComponent); + + LeftHand = CreateDefaultSubobject<UUniversalTrackedComponent>(TEXT("Left Hand")); + LeftHand->ProxyType = ETrackedComponentType::TCT_LEFT_HAND; + LeftHand->AttachementType = EAttachementType::AT_HANDTARGET; + LeftHand->SetupAttachment(RootComponent); + + Tracker1 = CreateDefaultSubobject<UUniversalTrackedComponent>(TEXT("Vive Tracker 1")); + Tracker1->ProxyType = ETrackedComponentType::TCT_TRACKER_1; + Tracker1->SetupAttachment(RootComponent); + + Tracker2 = CreateDefaultSubobject<UUniversalTrackedComponent>(TEXT("Vive Tracker 2")); + Tracker2->ProxyType = ETrackedComponentType::TCT_TRACKER_2; + Tracker2->SetupAttachment(RootComponent); + + BasicVRInteraction = CreateDefaultSubobject<UBasicVRInteractionComponent>(TEXT("Basic VR Interaction")); + BasicVRInteraction->Initialize(RightHand); +} + +void AVirtualRealityPawn::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent) +{ + Super::SetupPlayerInputComponent(PlayerInputComponent); + if (PlayerInputComponent) + { + PlayerInputComponent->BindAxis("MoveForward", this, &AVirtualRealityPawn::OnForward); + PlayerInputComponent->BindAxis("MoveRight", this, &AVirtualRealityPawn::OnRight); + 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); + } +} + +void AVirtualRealityPawn::BeginPlay() +{ + if(!UVirtualRealityUtilities::IsDesktopMode()) /* Disable to not get cyber sick as fast */ + { + UInputSettings::GetInputSettings()->RemoveAxisMapping(FInputAxisKeyMapping("TurnRate", EKeys::MouseX)); + UInputSettings::GetInputSettings()->RemoveAxisMapping(FInputAxisKeyMapping("LookUpRate", EKeys::MouseY)); + } +} + +void AVirtualRealityPawn::OnForward_Implementation(float Value) +{ + if (RightHand) + { + AddMovementInput(RightHand->GetForwardVector(), Value); + } +} + +void AVirtualRealityPawn::OnRight_Implementation(float Value) +{ + if (RightHand) + { + AddMovementInput(RightHand->GetRightVector(), Value); + } +} + +void AVirtualRealityPawn::OnTurnRate_Implementation(float Rate) +{ + AddControllerYawInput(Rate * BaseTurnRate * GetWorld()->GetDeltaSeconds() * CustomTimeDilation); +} + +void AVirtualRealityPawn::OnLookUpRate_Implementation(float Rate) +{ + // User-centered projection causes simulation sickness on look up interaction hence not implemented. + if (!UVirtualRealityUtilities::IsRoomMountedMode()) + { + AddControllerPitchInput(Rate * BaseTurnRate * GetWorld()->GetDeltaSeconds() * CustomTimeDilation); + } +} + +void AVirtualRealityPawn::OnBeginFire_Implementation() +{ + BasicVRInteraction->BeginInteraction(); +} + +void AVirtualRealityPawn::OnEndFire_Implementation() +{ + BasicVRInteraction->EndInteraction(); +} + +UPawnMovementComponent* AVirtualRealityPawn::GetMovementComponent() const +{ + return PawnMovement; +} diff --git a/Source/DisplayClusterExtensions/Public/VRPawnMovement.h b/Source/DisplayClusterExtensions/Public/VRPawnMovement.h index 20a6f4b6707cd7a8ec60116f4fb0386d9fc017a4..094b02d303bdbb2946be79f3449d8d0a67feaed0 100644 --- a/Source/DisplayClusterExtensions/Public/VRPawnMovement.h +++ b/Source/DisplayClusterExtensions/Public/VRPawnMovement.h @@ -38,8 +38,6 @@ public: virtual void TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override; - void SetCameraComponent(UCameraComponent* NewCameraComponent); - UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VR Movement") EVRNavigationModes NavigationMode = EVRNavigationModes::Walk; diff --git a/Source/DisplayClusterExtensions/Public/VirtualRealityPawn.h b/Source/DisplayClusterExtensions/Public/VirtualRealityPawn.h index c80414d6f1a3170d169c0da1aaa325029f580ac3..5fc1b5f744ae670e39396d60879f97d0cf8135cd 100644 --- a/Source/DisplayClusterExtensions/Public/VirtualRealityPawn.h +++ b/Source/DisplayClusterExtensions/Public/VirtualRealityPawn.h @@ -1,48 +1,51 @@ -// Fill out your copyright notice in the Description page of Project Settings. - -#pragma once - -#include "BasicVRInteractionComponent.h" -#include "CoreMinimal.h" -#include "GameFramework/DefaultPawn.h" -#include "GameFramework/RotatingMovementComponent.h" -#include "UniversalTrackedComponent.h" -#include "VRPawnMovement.h" -#include "VirtualRealityPawn.generated.h" - -/** - * - */ -UCLASS() -class DISPLAYCLUSTEREXTENSIONS_API AVirtualRealityPawn : public APawn -{ - GENERATED_BODY() -public: - AVirtualRealityPawn(const FObjectInitializer& ObjectInitializer); - - /* Proxy Components */ - UPROPERTY() UUniversalTrackedComponent* Head; - UPROPERTY() UUniversalTrackedComponent* RightHand; - UPROPERTY() UUniversalTrackedComponent* LeftHand; - UPROPERTY() UUniversalTrackedComponent* Tracker1; - UPROPERTY() UUniversalTrackedComponent* Tracker2; - UPROPERTY() UBasicVRInteractionComponent* BasicVRInteraction; - - /* Movement */ - UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Pawn|Movement") UVRPawnMovement* PawnMovement; - UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Pawn|Movement") float BaseTurnRate = 45.0f; - -protected: - virtual void BeginPlay() override; - virtual void SetupPlayerInputComponent(UInputComponent* PlayerInputComponent) override; - - /* 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 OnTurnRate(float Rate); - UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "Pawn|Movement") void OnLookUpRate(float Rate); - - /* Interaction */ - UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "Pawn|Interaction") void OnBeginFire(); - UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "Pawn|Interaction") void OnEndFire(); -}; +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "BasicVRInteractionComponent.h" +#include "CoreMinimal.h" +#include "GameFramework/DefaultPawn.h" +#include "GameFramework/RotatingMovementComponent.h" +#include "UniversalTrackedComponent.h" +#include "VRPawnMovement.h" +#include "VirtualRealityPawn.generated.h" + +/** + * + */ +UCLASS() +class DISPLAYCLUSTEREXTENSIONS_API AVirtualRealityPawn : public APawn +{ + GENERATED_BODY() +public: + AVirtualRealityPawn(const FObjectInitializer& ObjectInitializer); + + /* Proxy Components */ + UPROPERTY() UUniversalTrackedComponent* Head; + UPROPERTY() UUniversalTrackedComponent* RightHand; + UPROPERTY() UUniversalTrackedComponent* LeftHand; + UPROPERTY() UUniversalTrackedComponent* Tracker1; + UPROPERTY() UUniversalTrackedComponent* Tracker2; + UPROPERTY() UBasicVRInteractionComponent* BasicVRInteraction; + + /* Movement */ + UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Pawn|Movement") UVRPawnMovement* PawnMovement; + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Pawn|Movement") float BaseTurnRate = 45.0f; + +protected: + virtual void BeginPlay() override; + virtual void SetupPlayerInputComponent(UInputComponent* PlayerInputComponent) override; + + /* 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 OnTurnRate(float Rate); + UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "Pawn|Movement") void OnLookUpRate(float Rate); + + /* Interaction */ + UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "Pawn|Interaction") void OnBeginFire(); + UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "Pawn|Interaction") void OnEndFire(); + + /* APawn Interface to be able to use AddMovementInput() */ + virtual UPawnMovementComponent* GetMovementComponent() const override; +};