From d38ea78795f5da4d9b2ed038d87c9ef65c8af492 Mon Sep 17 00:00:00 2001 From: Ehret <jw210150@WIN.RZ.RWTH-AACHEN.DE> Date: Wed, 24 Feb 2021 09:45:50 +0100 Subject: [PATCH] Use head instead of camera to get the head's position in VRPawnMovement --- .../Private/Pawn/VRPawnMovement.cpp | 18 +++++++++--------- .../Private/Pawn/VirtualRealityPawn.cpp | 8 ++++---- .../Public/Pawn/VRPawnMovement.h | 6 +++--- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/Source/DisplayClusterExtensions/Private/Pawn/VRPawnMovement.cpp b/Source/DisplayClusterExtensions/Private/Pawn/VRPawnMovement.cpp index 5cceb96c..182c2b5e 100644 --- a/Source/DisplayClusterExtensions/Private/Pawn/VRPawnMovement.cpp +++ b/Source/DisplayClusterExtensions/Private/Pawn/VRPawnMovement.cpp @@ -42,7 +42,7 @@ void UVRPawnMovement::TickComponent(float DeltaTime, enum ELevelTick TickType, F Super::TickComponent(DeltaTime, TickType, ThisTickFunction); - LastCameraPosition = CameraComponent->GetComponentLocation(); + LastHeadPosition = HeadComponent->GetComponentLocation(); } bool UVRPawnMovement::CheckForVirtualMovCollision(FVector PositionChange, float DeltaTime) @@ -57,15 +57,15 @@ bool UVRPawnMovement::CheckForVirtualMovCollision(FVector PositionChange, float return false; } -void UVRPawnMovement::SetCameraComponent(UCameraComponent* NewCameraComponent) +void UVRPawnMovement::SetHeadComponent(USceneComponent* NewHeadComponent) { - CameraComponent = NewCameraComponent; - CapsuleColliderComponent->SetupAttachment(CameraComponent); + HeadComponent = NewHeadComponent; + CapsuleColliderComponent->SetupAttachment(HeadComponent); } void UVRPawnMovement::SetCapsuleColliderToUserSize() { - float CharachterSize = abs(UpdatedComponent->GetComponentLocation().Z - CameraComponent->GetComponentLocation().Z); + float CharachterSize = abs(UpdatedComponent->GetComponentLocation().Z - HeadComponent->GetComponentLocation().Z); if (CharachterSize > MaxStepHeight) { @@ -81,21 +81,21 @@ void UVRPawnMovement::SetCapsuleColliderToUserSize() CapsuleColliderComponent->SetCapsuleSize(ColliderRadius, ColliderHalfHeight); } - CapsuleColliderComponent->SetWorldLocation(CameraComponent->GetComponentLocation()); + CapsuleColliderComponent->SetWorldLocation(HeadComponent->GetComponentLocation()); CapsuleColliderComponent->AddWorldOffset(FVector(0, 0, -ColliderHalfHeight)); CapsuleColliderComponent->SetWorldRotation(FRotator(0, 0, 1)); } else { - CapsuleColliderComponent->SetWorldLocation(CameraComponent->GetComponentLocation()); + CapsuleColliderComponent->SetWorldLocation(HeadComponent->GetComponentLocation()); CapsuleColliderComponent->SetWorldRotation(FRotator(0, 0, 1)); } } void UVRPawnMovement::CheckForPhysWalkingCollision() { - FVector CurrentCameraPosition = CameraComponent->GetComponentLocation(); - FVector Direction = CurrentCameraPosition - LastCameraPosition; + FVector CurrentHeadPosition = HeadComponent->GetComponentLocation(); + FVector Direction = CurrentHeadPosition - LastHeadPosition; FHitResult FHitResultPhys; CapsuleColliderComponent->AddWorldOffset(Direction, true, &FHitResultPhys); diff --git a/Source/DisplayClusterExtensions/Private/Pawn/VirtualRealityPawn.cpp b/Source/DisplayClusterExtensions/Private/Pawn/VirtualRealityPawn.cpp index 3a078bd5..de5947b1 100644 --- a/Source/DisplayClusterExtensions/Private/Pawn/VirtualRealityPawn.cpp +++ b/Source/DisplayClusterExtensions/Private/Pawn/VirtualRealityPawn.cpp @@ -26,14 +26,14 @@ AVirtualRealityPawn::AVirtualRealityPawn(const FObjectInitializer& ObjectInitial CameraComponent = CreateDefaultSubobject<UCameraComponent>(TEXT("Camera")); CameraComponent->SetupAttachment(RootComponent); CameraComponent->SetAbsolute(); - - PawnMovement = CreateDefaultSubobject<UVRPawnMovement>(TEXT("Pawn Movement")); - PawnMovement->SetUpdatedComponent(RootComponent); - PawnMovement->SetCameraComponent(CameraComponent); Head = CreateDefaultSubobject<UUniversalTrackedComponent>(TEXT("Head")); Head->ProxyType = ETrackedComponentType::TCT_HEAD; Head->SetupAttachment(RootComponent); + + PawnMovement = CreateDefaultSubobject<UVRPawnMovement>(TEXT("Pawn Movement")); + PawnMovement->SetUpdatedComponent(RootComponent); + PawnMovement->SetHeadComponent(Head); RightHand = CreateDefaultSubobject<UUniversalTrackedComponent>(TEXT("Right Hand")); RightHand->ProxyType = ETrackedComponentType::TCT_RIGHT_HAND; diff --git a/Source/DisplayClusterExtensions/Public/Pawn/VRPawnMovement.h b/Source/DisplayClusterExtensions/Public/Pawn/VRPawnMovement.h index 0eeee2e3..31bb8611 100644 --- a/Source/DisplayClusterExtensions/Public/Pawn/VRPawnMovement.h +++ b/Source/DisplayClusterExtensions/Public/Pawn/VRPawnMovement.h @@ -38,7 +38,7 @@ public: virtual void TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override; - void SetCameraComponent(UCameraComponent* NewCameraComponent); + void SetHeadComponent(USceneComponent* NewHeadComponent); UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VR Movement") EVRNavigationModes NavigationMode = EVRNavigationModes::NAV_WALK; @@ -63,8 +63,8 @@ private: //(direction = Down = -1), (direction = Up = 1) UPROPERTY() UCapsuleComponent* CapsuleColliderComponent = nullptr; - UPROPERTY() UCameraComponent* CameraComponent = nullptr; + UPROPERTY() USceneComponent* HeadComponent = nullptr; float VerticalSpeed = 0.0f; - FVector LastCameraPosition; + FVector LastHeadPosition; }; -- GitLab