Skip to content
Snippets Groups Projects
Commit 7d7a9da8 authored by Sebastian Pape's avatar Sebastian Pape
Browse files

Merge branch 'feature/restructure_VRpawn' into 'develop'

Restructure VRPawn

See merge request VR-Group/unreal-development/ndisplayextensions!11
parents e4014704 e085472b
No related branches found
No related tags found
1 merge request!11Restructure VRPawn
......@@ -31,6 +31,10 @@ AVirtualRealityPawn::AVirtualRealityPawn(const FObjectInitializer& ObjectInitial
RotatingMovement->PivotTranslation = FVector::ZeroVector;
RotatingMovement->RotationRate = FRotator::ZeroRotator;
Head = CreateDefaultSubobject<USceneComponent>(TEXT("Head"));
RightHand = CreateDefaultSubobject<USceneComponent>(TEXT("RightHand"));
LeftHand = CreateDefaultSubobject<USceneComponent>(TEXT("LeftHand"));
HmdLeftMotionController = CreateDefaultSubobject<UMotionControllerComponent>(TEXT("HmdLeftMotionController"));
HmdLeftMotionController->SetupAttachment(RootComponent);
HmdLeftMotionController->SetTrackingSource(EControllerHand::Left);
......@@ -149,6 +153,16 @@ UDisplayClusterSceneComponent* AVirtualRealityPawn::GetFlystickComponent()
return Flystick;
}
UDisplayClusterSceneComponent* AVirtualRealityPawn::GetRightHandtargetComponent()
{
return RightHandTarget;
}
UDisplayClusterSceneComponent* AVirtualRealityPawn::GetLeftHandtargetComponent()
{
return LeftHandTarget;
}
UMotionControllerComponent* AVirtualRealityPawn::GetHmdLeftMotionControllerComponent()
{
return HmdLeftMotionController;
......@@ -174,9 +188,9 @@ USceneComponent* AVirtualRealityPawn::GetRightHandComponent()
return RightHand;
}
USceneComponent* AVirtualRealityPawn::GetCaveOriginComponent()
USceneComponent* AVirtualRealityPawn::GetTrackingOriginComponent()
{
return CaveOrigin;
return TrackingOrigin;
}
USceneComponent* AVirtualRealityPawn::GetCaveCenterComponent()
......@@ -234,27 +248,31 @@ void AVirtualRealityPawn::BeginPlay()
UInputSettings::GetInputSettings()->RemoveAxisMapping(FInputAxisKeyMapping("TurnRate", EKeys::MouseX));
UInputSettings::GetInputSettings()->RemoveAxisMapping(FInputAxisKeyMapping("LookUpRate", EKeys::MouseY));
InitComponentReferences();
RootComponent->SetWorldLocation(FVector(0, 2, 0), false, nullptr, ETeleportType::None);
InitRoomMountedComponentReferences();
}
else if (IsHeadMountedMode())
{
UInputSettings::GetInputSettings()->RemoveAxisMapping(FInputAxisKeyMapping("TurnRate", EKeys::MouseX));
UInputSettings::GetInputSettings()->RemoveAxisMapping(FInputAxisKeyMapping("LookUpRate", EKeys::MouseY));
HmdLeftMotionController->SetVisibility(true);
HmdRightMotionController->SetVisibility(true);
HmdLeftMotionController->SetVisibility(ShowHMDControllers);
HmdRightMotionController->SetVisibility(ShowHMDControllers);
LeftHand = HmdLeftMotionController;
RightHand = HmdRightMotionController;
Head = GetCameraComponent();
LeftHand->AttachToComponent(HmdLeftMotionController, FAttachmentTransformRules::KeepRelativeTransform);
RightHand->AttachToComponent(HmdRightMotionController, FAttachmentTransformRules::KeepRelativeTransform);
Head->AttachToComponent(GetCameraComponent(), FAttachmentTransformRules::KeepRelativeTransform);
}
else //Desktop
{
LeftHand = RootComponent;
RightHand = RootComponent;
Head = GetCameraComponent();
Head->AttachToComponent(GetCameraComponent(), FAttachmentTransformRules::KeepRelativeTransform);
//also attach the hands to the camera component so we can use them for interaction
LeftHand->AttachToComponent(GetCameraComponent(), FAttachmentTransformRules::KeepRelativeTransform);
RightHand->AttachToComponent(GetCameraComponent(), FAttachmentTransformRules::KeepRelativeTransform);
//move to eyelevel
GetCameraComponent()->SetRelativeLocation(FVector(0, 0, 160));
}
//In ADisplayClusterPawn::BeginPlay() input is disabled on all slaves, so we cannot react to button presses, e.g. on the flystick correctly.
......@@ -294,7 +312,7 @@ void AVirtualRealityPawn::Tick(float DeltaSeconds)
Super::Tick(DeltaSeconds);
//Flystick might not be available at start, hence is checked every frame.
InitComponentReferences();
InitRoomMountedComponentReferences();
}
void AVirtualRealityPawn::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
......@@ -314,24 +332,41 @@ UPawnMovementComponent* AVirtualRealityPawn::GetMovementComponent() const
return Movement;
}
void AVirtualRealityPawn::InitComponentReferences()
void AVirtualRealityPawn::InitRoomMountedComponentReferences()
{
if (!IsRoomMountedMode()) return;
if (!CaveOrigin) CaveOrigin = GetClusterComponent("cave_origin");
//check whether the nodes already exist (otherwise GetClusterComponent() returns nullptr and prints a warning) and assign them
if (!TrackingOrigin) TrackingOrigin = GetClusterComponent("cave_origin");
if (!TrackingOrigin) TrackingOrigin = GetClusterComponent("rolv_origin");
if (!CaveCenter) CaveCenter = GetClusterComponent("cave_center");
if (!ShutterGlasses)
{
ShutterGlasses = GetClusterComponent("shutter_glasses");
Head = ShutterGlasses;
Head->AttachToComponent(ShutterGlasses, FAttachmentTransformRules::KeepRelativeTransform);
}
if (!Flystick)
{
Flystick = GetClusterComponent("flystick");
LeftHand = Flystick;
RightHand = Flystick;
if (AttachRightHandInCAVE == EAttachementType::AT_FLYSTICK)
RightHand->AttachToComponent(Flystick, FAttachmentTransformRules::KeepRelativeTransform);
if (AttachLeftHandInCAVE == EAttachementType::AT_FLYSTICK)
LeftHand->AttachToComponent(Flystick, FAttachmentTransformRules::KeepRelativeTransform);
}
if (!LeftHandTarget)
{
LeftHandTarget = GetClusterComponent("left_hand_target");
if (AttachLeftHandInCAVE == EAttachementType::AT_HANDTARGET)
LeftHand->AttachToComponent(LeftHandTarget, FAttachmentTransformRules::KeepRelativeTransform);
}
if (!RightHandTarget)
{
RightHandTarget = GetClusterComponent("right_hand_target");
if (AttachRightHandInCAVE == EAttachementType::AT_HANDTARGET)
RightHand->AttachToComponent(RightHandTarget, FAttachmentTransformRules::KeepRelativeTransform);
}
}
EEyeType AVirtualRealityPawn::GetNodeEyeType()
{
......
......@@ -26,6 +26,14 @@ enum class EEyeType : uint8
ET_STEREO_LEFT UMETA(DisplayName = "stereo_left")
};
UENUM(BlueprintType)
enum class EAttachementType : uint8
{
AT_NONE UMETA(DisplayName = "not attached"),
AT_HANDTARGET UMETA(DisplayName = "to the right/left hand target"),
AT_FLYSTICK UMETA(DisplayName = "to the Flystick")
};
UCLASS()
class DISPLAYCLUSTEREXTENSIONS_API AVirtualRealityPawn : public ADisplayClusterPawn
{
......@@ -43,6 +51,7 @@ public:
UFUNCTION(BlueprintPure, Category = "Pawn") static bool IsRoomMountedMode();
UFUNCTION(BlueprintPure, Category = "Pawn") static bool IsHeadMountedMode();
UFUNCTION(BlueprintPure, Category = "Pawn") static FString GetNodeName();
UFUNCTION(BlueprintPure, Category = "Pawn") static float GetEyeDistance();
......@@ -54,8 +63,9 @@ public:
UFUNCTION(Category = "Pawn") URotatingMovementComponent* GetRotatingMovementComponent();
//Bunch of Getter Functions for components to avoid users having to know the names
UFUNCTION(Category = "Pawn") UDisplayClusterSceneComponent* GetFlystickComponent();
UFUNCTION(Category = "Pawn") UDisplayClusterSceneComponent* GetRightHandtargetComponent();
UFUNCTION(Category = "Pawn") UDisplayClusterSceneComponent* GetLeftHandtargetComponent();
UFUNCTION(Category = "Pawn") UMotionControllerComponent* GetHmdLeftMotionControllerComponent();
UFUNCTION(Category = "Pawn") UMotionControllerComponent* GetHmdRightMotionControllerComponent();
......@@ -63,10 +73,13 @@ public:
UFUNCTION(Category = "Pawn") USceneComponent* GetLeftHandComponent();
UFUNCTION(Category = "Pawn") USceneComponent* GetRightHandComponent();
UFUNCTION(Category = "Pawn") USceneComponent* GetCaveOriginComponent();
UFUNCTION(Category = "Pawn") USceneComponent* GetTrackingOriginComponent();
private:
UFUNCTION(Category = "Pawn") USceneComponent* GetCaveCenterComponent();
UFUNCTION(Category = "Pawn") USceneComponent* GetShutterGlassesComponent();
public:
//Get Compenent of Display Cluster by it's name, which is specified in the nDisplay config
UFUNCTION(BlueprintPure, BlueprintCallable, Category = "Pawn") static UDisplayClusterSceneComponent* GetClusterComponent(const FString& Name);
......@@ -95,25 +108,35 @@ protected:
// Use only when handling cross-device (PC, HMD, CAVE/ROLV) compatibility manually. CAVE/ROLV flystick.
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Pawn", meta = (AllowPrivateAccess = "true")) UDisplayClusterSceneComponent* Flystick = nullptr;
// Use only when handling cross-device (PC, HMD, CAVE/ROLV) compatibility manually. CAVE/ROLV flystick.
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Pawn", meta = (AllowPrivateAccess = "true")) UDisplayClusterSceneComponent* RightHandTarget = nullptr;
// Use only when handling cross-device (PC, HMD, CAVE/ROLV) compatibility manually. CAVE/ROLV flystick.
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Pawn", meta = (AllowPrivateAccess = "true")) UDisplayClusterSceneComponent* LeftHandTarget = nullptr;
// Use only when handling cross-device (PC, HMD, CAVE/ROLV) compatibility manually. HMD left motion controller.
UPROPERTY(VisibleAnywhere, BlueprintReadOnly , Category = "Pawn", meta = (AllowPrivateAccess = "true")) UMotionControllerComponent* HmdLeftMotionController = nullptr;
UMotionControllerComponent* HmdLeftMotionController = nullptr;
// Use only when handling cross-device (PC, HMD, CAVE/ROLV) compatibility manually. HMD right motion controller.
UPROPERTY(VisibleAnywhere, BlueprintReadOnly , Category = "Pawn", meta = (AllowPrivateAccess = "true")) UMotionControllerComponent* HmdRightMotionController = nullptr;
UMotionControllerComponent* HmdRightMotionController = nullptr;
// PC: Camera, HMD: Camera, CAVE/ROLV: Shutter glasses.
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Pawn", meta = (AllowPrivateAccess = "true")) USceneComponent* Head = nullptr;
// PC: RootComponent, HMD: HmdLeftMotionController , CAVE/ROLV: Flystick. Useful for line trace (e.g. for holding objects).
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Pawn", meta = (AllowPrivateAccess = "true")) USceneComponent* LeftHand = nullptr;
// PC: RootComponent, HMD: HmdRightMotionController, CAVE/ROLV: Flystick. Useful for line trace (e.g. for holding objects).
// PC: RootComponent, HMD: HmdLeftMotionController , CAVE/ROLV: regarding to AttachRightHandInCAVE. Useful for line trace (e.g. for holding objects).
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Pawn", meta = (AllowPrivateAccess = "true")) USceneComponent* RightHand = nullptr;
// PC: RootComponent, HMD: HmdRightMotionController, CAVE/ROLV: regarding to AttachLeftHandInCAVE. Useful for line trace (e.g. for holding objects).
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Pawn", meta = (AllowPrivateAccess = "true")) USceneComponent* LeftHand = nullptr;
// Holding the Cave Origin Component that is attached to this Pawn
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Pawn", meta = (AllowPrivateAccess = "true")) USceneComponent* CaveOrigin = nullptr;
// Holding the Cave Center Component that is attached to this Pawn
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Pawn", meta = (AllowPrivateAccess = "true")) USceneComponent* CaveCenter = nullptr;
// Holding the Cave/rolv Origin Component that is attached to this Pawn
UPROPERTY() USceneComponent* TrackingOrigin = nullptr;
// Holding the Cave Center Component that is attached to this Pawn, it is needed for the internal transform of nDisplay
UPROPERTY() USceneComponent* CaveCenter = nullptr;
// Holding the Shutter Glasses Component that is attached to this Pawn
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Pawn", meta = (AllowPrivateAccess = "true")) USceneComponent* ShutterGlasses = nullptr;
UPROPERTY() USceneComponent* ShutterGlasses = nullptr;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Pawn") bool ShowHMDControllers = true;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Pawn") EAttachementType AttachRightHandInCAVE = EAttachementType::AT_FLYSTICK;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Pawn") EAttachementType AttachLeftHandInCAVE = EAttachementType::AT_NONE;
private:
void InitComponentReferences();
void InitRoomMountedComponentReferences();
};
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment