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

Adding new and shiny VRPawn implementation (untested so far)

parent d811e7a5
Branches
Tags
No related merge requests found
...@@ -13,10 +13,48 @@ UUniversalTrackedComponent::UUniversalTrackedComponent() ...@@ -13,10 +13,48 @@ UUniversalTrackedComponent::UUniversalTrackedComponent()
// Set this component to be initialized when the game starts, and to be ticked every frame. You can turn these features // Set this component to be initialized when the game starts, and to be ticked every frame. You can turn these features
// off to improve performance if you don't need them. // off to improve performance if you don't need them.
PrimaryComponentTick.bCanEverTick = true; PrimaryComponentTick.bCanEverTick = true;
}
void UUniversalTrackedComponent::SetShowDeviceModel(const bool bShowControllerModel)
{
if (!UVirtualRealityUtilities::IsHeadMountedMode() || TrackedComponent == nullptr) return;
ShowDeviceModelInHMD = bShowControllerModel;
Cast<UMotionControllerComponent>(TrackedComponent)->SetShowDeviceModel(ShowDeviceModelInHMD);
}
// ... void UUniversalTrackedComponent::BeginPlay()
{
Super::BeginPlay();
/* Spawn Motion Controller Components in HMD Mode */
if (UVirtualRealityUtilities::IsHeadMountedMode())
{
UMotionControllerComponent* MotionController = Cast<UMotionControllerComponent>(GetOwner()->AddComponentByClass(UMotionControllerComponent::StaticClass(), false, FTransform::Identity, false));
switch(ProxyType)
{
case ETrackedComponentType::TCT_TRACKER_1:
MotionController->SetTrackingMotionSource(FName("Special_1"));
break;
case ETrackedComponentType::TCT_TRACKER_2:
MotionController->SetTrackingMotionSource(FName("Special_2"));
break;
case ETrackedComponentType::TCT_RIGHT_HAND:
MotionController->SetTrackingMotionSource(FName("Right"));
break;
case ETrackedComponentType::TCT_LEFT_HAND:
MotionController->SetTrackingMotionSource(FName("Left"));
break;
default: break;
} }
MotionController->SetShowDeviceModel(ShowDeviceModelInHMD);
TrackedComponent = MotionController;
AttachToComponent(TrackedComponent, FAttachmentTransformRules::SnapToTargetIncludingScale);
}
}
void UUniversalTrackedComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) void UUniversalTrackedComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{ {
......
...@@ -3,3 +3,114 @@ ...@@ -3,3 +3,114 @@
#include "VirtualRealityPawn.h" #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();
}
This diff is collapsed.
...@@ -41,9 +41,13 @@ public: ...@@ -41,9 +41,13 @@ public:
UUniversalTrackedComponent(); UUniversalTrackedComponent();
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Tracking") ETrackedComponentType ProxyType = ETrackedComponentType::TCT_HEAD; UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Tracking") ETrackedComponentType ProxyType = ETrackedComponentType::TCT_HEAD;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Tracking") EAttachementType AttachementType = EAttachementType::AT_FLYSTICK; UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Tracking|nDisplay") EAttachementType AttachementType = EAttachementType::AT_NONE;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Tracking|HMD", BlueprintSetter=SetShowDeviceModel) bool ShowDeviceModelInHMD = true;
// Called every frame UFUNCTION(BlueprintSetter)
void SetShowDeviceModel(const bool bShowControllerModel);
virtual void BeginPlay() override;
virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override; virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
private: private:
......
...@@ -2,16 +2,47 @@ ...@@ -2,16 +2,47 @@
#pragma once #pragma once
#include "BasicVRInteractionComponent.h"
#include "CoreMinimal.h" #include "CoreMinimal.h"
#include "GameFramework/DefaultPawn.h" #include "GameFramework/DefaultPawn.h"
#include "GameFramework/RotatingMovementComponent.h"
#include "UniversalTrackedComponent.h"
#include "VRPawnMovement.h"
#include "VirtualRealityPawn.generated.h" #include "VirtualRealityPawn.generated.h"
/** /**
* *
*/ */
UCLASS() UCLASS()
class DISPLAYCLUSTEREXTENSIONS_API AVirtualRealityPawn : public ADefaultPawn class DISPLAYCLUSTEREXTENSIONS_API AVirtualRealityPawn : public APawn
{ {
GENERATED_BODY() 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();
}; };
#pragma once
#include "CoreMinimal.h"
#include "Cluster/DisplayClusterClusterEvent.h"
#include "Cluster/IDisplayClusterClusterManager.h"
#include "Components/DisplayClusterSceneComponent.h"
#include "Components/CapsuleComponent.h"
#include "GameFramework/FloatingPawnMovement.h"
#include "GameFramework/PawnMovementComponent.h"
#include "GameFramework/RotatingMovementComponent.h"
#include "UniversalTrackedComponent.h"
#include "MotionControllerComponent.h"
#include "VirtualRealityPawnOld.generated.h"
UENUM(BlueprintType)
enum class EVRNavigationModes : uint8
{
nav_mode_none UMETA(DisplayName = "Navigation Mode None"),
nav_mode_walk UMETA(DisplayName = "Navigation Mode Walk"),
nav_mode_fly UMETA(DisplayName = "Navigation Mode Fly")
};
UCLASS()
class DISPLAYCLUSTEREXTENSIONS_API AVirtualRealityPawnOld : public APawn
{
GENERATED_UCLASS_BODY()
public:
UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "Pawn") void OnForward(float Value);
UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "Pawn") void OnRight(float Value);
UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "Pawn") void OnTurnRate(float Rate);
UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "Pawn") void OnLookUpRate(float Rate);
UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "Pawn") void OnBeginFire();
UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "Pawn") void OnEndFire();
UFUNCTION(Category = "Pawn") float GetBaseTurnRate() const;
UFUNCTION(Category = "Pawn") void SetBaseTurnRate(float Value);
UFUNCTION(Category = "Pawn") UFloatingPawnMovement* GetFloatingPawnMovement();
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();
UFUNCTION(Category = "Pawn") UMotionControllerComponent* GetHmdTracker1MotionControllerComponent();
UFUNCTION(Category = "Pawn") UMotionControllerComponent* GetHmdTracker2MotionControllerComponent();
UFUNCTION(Category = "Pawn") USceneComponent* GetHeadComponent();
UFUNCTION(Category = "Pawn") USceneComponent* GetLeftHandComponent();
UFUNCTION(Category = "Pawn") USceneComponent* GetRightHandComponent();
UFUNCTION(Category = "Pawn") USceneComponent* GetTrackingOriginComponent();
private:
UFUNCTION(Category = "Pawn") USceneComponent* GetCaveCenterComponent();
UFUNCTION(Category = "Pawn") USceneComponent* GetShutterGlassesComponent();
UFUNCTION(Category = "Pawn") FTwoVectors GetHandRay(float Distance);
UFUNCTION(Category = "Pawn") void HandlePhysicsAndAttachActor(AActor* HitActor);
public:
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Pawn") EVRNavigationModes NavigationMode = EVRNavigationModes::nav_mode_fly;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Pawn") float MaxStepHeight = 40.0f;
protected:
virtual void BeginPlay() override;
virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override;
virtual void Tick(float DeltaSeconds) override;
virtual void SetupPlayerInputComponent(UInputComponent* PlayerInputComponent) override;
virtual UPawnMovementComponent* GetMovementComponent() const override;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Pawn", meta = (AllowPrivateAccess = "true")) float BaseTurnRate = 45.0f;
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Pawn", meta = (AllowPrivateAccess = "true")) UFloatingPawnMovement* Movement = nullptr;
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Pawn", meta = (AllowPrivateAccess = "true")) URotatingMovementComponent* RotatingMovement = 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* 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() UMotionControllerComponent* HmdLeftMotionController = nullptr;
// Use only when handling cross-device (PC, HMD, CAVE/ROLV) compatibility manually. HMD right motion controller.
UPROPERTY() UMotionControllerComponent* HmdRightMotionController = nullptr;
// used only for HMDs, tested with the additional Vive Trackers
UPROPERTY() UMotionControllerComponent* HmdTracker1 = nullptr;
UPROPERTY() UMotionControllerComponent* HmdTracker2 = 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: 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/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() USceneComponent* ShutterGlasses = nullptr;
// Holding a reference to the actor that is currently being grabbed
UPROPERTY() AActor* GrabbedActor;
// indicates if the grabbed actor was simulating physics before we grabbed it
UPROPERTY() bool bDidSimulatePhysics;
UPROPERTY(EditAnywhere) float MaxGrabDistance = 50;
UPROPERTY(EditAnywhere) float MaxClickDistance = 500;
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;
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Pawn", meta = (AllowPrivateAccess = "true")) UCapsuleComponent* CapsuleColliderComponent = nullptr;
private:
float DeltaTime = 0.0f;
float VerticalSpeed = 0.0f;
UPROPERTY() float GravityAcceleration = 981.0f;
UPROPERTY() float UpSteppingAcceleration = 500.0f;
FVector LastCameraPosition;
FHitResult CreateLineTrace(FVector Direction, const FVector Start, bool Visibility);
FHitResult CreateMultiLineTrace(FVector Direction, const FVector Start, float Radius, bool Visibility);
void SetCapsuleColliderCharacterSizeVR();
void CheckForPhysWalkingCollision();
void HandleMovementInput(float Value, FVector Direction);
void VRWalkingMode(float Value, FVector Direction);
void VRFlyingMode(float Value, FVector Direction);
void MoveByGravityOrStepUp(float DeltaSeconds);
void ShiftVertically(float DiffernceDistance, float Acceleration, float DeltaSeconds, int Direction);//(direction = Down = -1), (direction = Up = 1)
void InitRoomMountedComponentReferences();
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment