Skip to content
Snippets Groups Projects
Commit 0988cd1a authored by David Gilbert's avatar David Gilbert :bug:
Browse files

Started on moving DCRA Attachment and LiveLink to C++, some issues persist.

parent 94f9fde1
Branches
Tags
1 merge request!31Initial Pawn Replication
File added
File deleted
File added
No preview for this file type
......@@ -38,7 +38,7 @@ void UReplicatedCameraComponent::UpdateState(float DeltaTime)
ReplicatedTransform.Rotation = Rot;
if (GetNetMode() == NM_Client) // why do we differentiate here between netmode and authority?
{
SendControllerTransform_ServerRpc(ReplicatedTransform);
ServerSendControllerTransformRpc(ReplicatedTransform);
}
}
}
......@@ -66,7 +66,7 @@ void UReplicatedCameraComponent::GetLifetimeReplicatedProps(TArray< class FLifet
DOREPLIFETIME(UReplicatedCameraComponent, ControllerNetUpdateRate);
}
void UReplicatedCameraComponent::SendControllerTransform_ServerRpc_Implementation(FVRTransformRep NewTransform)
void UReplicatedCameraComponent::ServerSendControllerTransformRpc_Implementation(FVRTransformRep NewTransform)
{
// Store new transform and trigger OnRep_Function
ReplicatedTransform = NewTransform;
......@@ -75,7 +75,7 @@ void UReplicatedCameraComponent::SendControllerTransform_ServerRpc_Implementatio
OnRep_ReplicatedTransform();
}
bool UReplicatedCameraComponent::SendControllerTransform_ServerRpc_Validate(FVRTransformRep NewTransform)
bool UReplicatedCameraComponent::ServerSendControllerTransformRpc_Validate(FVRTransformRep NewTransform)
{
return true;
// Optionally check to make sure that player is inside of their bounds and deny it if they aren't?
......
......@@ -8,6 +8,8 @@
#include "EnhancedInputSubsystems.h"
#include "ILiveLinkClient.h"
#include "Core/RWTHVRPlayerState.h"
#include "Kismet/GameplayStatics.h"
#include "Logging/StructuredLog.h"
#include "Pawn/ContinuousMovementComponent.h"
#include "Pawn/ReplicatedCameraComponent.h"
#include "Pawn/ReplicatedMotionControllerComponent.h"
......@@ -50,19 +52,42 @@ void AVirtualRealityPawn::Tick(float DeltaSeconds)
SetCameraOffset();
UpdateRightHandForDesktopInteraction();
}
EvaluateLivelink();
}
/*
* The alternative would be to do this only on the server on possess and check for player state/type,
* as connections now send their playertype over.
*/
void AVirtualRealityPawn::NotifyControllerChanged()
{
Super::NotifyControllerChanged();
// Only do this for all local controlled pawns
if (IsLocallyControlled())
{
// Only do this for the master
if(UVirtualRealityUtilities::IsRoomMountedMode() && UVirtualRealityUtilities::IsMaster())
{
if (HasAuthority())
AttachDCRAtoPawn();
else
ServerAttachDCRAtoPawnRpc();
}
}
}
void AVirtualRealityPawn::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
Super::SetupPlayerInputComponent(PlayerInputComponent);
APlayerController* PlayerController = Cast<APlayerController>(GetController());
if (!PlayerController)
{
UE_LOG(Toolkit, Warning, TEXT("SetupPlayerInputComponent: Player Controller is invalid"));
return;
}
// Set the control rotation of the PC to zero again. There is a small period of 2 frames where, when the pawn gets possessed,
// the PC takes on the rotation of the VR Headset ONLY WHEN SPAWNING ON A CLIENT. Reset the rotation here such that
// bUseControllerRotationYaw=true does not pass the wrong yaw value to the pawn initially.
......@@ -70,13 +95,15 @@ void AVirtualRealityPawn::SetupPlayerInputComponent(UInputComponent* PlayerInput
PlayerController->SetControlRotation(FRotator::ZeroRotator);
const ULocalPlayer* LP = PlayerController->GetLocalPlayer();
UEnhancedInputLocalPlayerSubsystem* InputSubsystem = LP->GetSubsystem<UEnhancedInputLocalPlayerSubsystem>();
UEnhancedInputLocalPlayerSubsystem* InputSubsystem = LP ? LP->GetSubsystem<UEnhancedInputLocalPlayerSubsystem>() : nullptr;
if(!InputSubsystem)
{
UE_LOG(Toolkit, Error, TEXT("[VirtualRealiytPawn.cpp] InputSubsystem IS NOT VALID"));
return;
}
SetupMotionControllerSources();
ARWTHVRPlayerState* State = GetPlayerState<ARWTHVRPlayerState>();
// Should not do this here but on connection or on possess I think.
......@@ -128,7 +155,7 @@ void AVirtualRealityPawn::EvaluateLivelink()
if (UVirtualRealityUtilities::IsRoomMountedMode() && IsLocallyControlled())
{
if(bDisableLiveLink || SubjectRepresentation.Subject.IsNone() || SubjectRepresentation.Role == nullptr)
if(bDisableLiveLink || HeadSubjectRepresentation.Subject.IsNone() || HeadSubjectRepresentation.Role == nullptr)
{
return;
}
......@@ -137,7 +164,7 @@ void AVirtualRealityPawn::EvaluateLivelink()
// Get the LiveLink interface and evaluate the current existing frame data for the given Subject and Role.
ILiveLinkClient& LiveLinkClient = IModularFeatures::Get().GetModularFeature<ILiveLinkClient>(ILiveLinkClient::ModularFeatureName);
FLiveLinkSubjectFrameData SubjectData;
const bool bHasValidData = LiveLinkClient.EvaluateFrame_AnyThread(SubjectRepresentation.Subject, SubjectRepresentation.Role, SubjectData);
const bool bHasValidData = LiveLinkClient.EvaluateFrame_AnyThread(HeadSubjectRepresentation.Subject, HeadSubjectRepresentation.Role, SubjectData);
if(!bHasValidData)
return;
......@@ -168,6 +195,55 @@ void AVirtualRealityPawn::UpdateRightHandForDesktopInteraction()
}
}
// Todo rewrite this in some other way or attach it differently, this is horrible
void AVirtualRealityPawn::AttachDCRAtoPawn()
{
if (!CaveSetupActorClass || !CaveSetupActorClass->IsValidLowLevelFast())
{
UE_LOGFMT(Toolkit, Warning, "No CaveSetup Actor class set in pawn!");
return;
}
TArray<AActor*> FoundActors;
UGameplayStatics::GetAllActorsOfClass(GetWorld(), CaveSetupActorClass, FoundActors);
if (!FoundActors.IsEmpty())
{
const auto CaveSetupActor = FoundActors[0];
FAttachmentTransformRules AttachmentRules = FAttachmentTransformRules::SnapToTargetNotIncludingScale;
AttachmentRules.RotationRule = EAttachmentRule::KeepWorld;
CaveSetupActor->AttachToActor(this, AttachmentRules);
}
else
{
UE_LOGFMT(Toolkit, Warning, "No CaveSetup Actor found which can be attached to the Pawn! This won't work on the Cave.");
}
}
void AVirtualRealityPawn::SetupMotionControllerSources()
{
// Setup Motion Controllers
FName MotionControllerSourceLeft = EName::None;
FName MotionControllerSourceRight = EName::None;
if (UVirtualRealityUtilities::IsHeadMountedMode())
{
MotionControllerSourceLeft = FName("Left");
MotionControllerSourceRight = FName("Right");
}
if (UVirtualRealityUtilities::IsRoomMountedMode() && UVirtualRealityUtilities::IsMaster())
{
MotionControllerSourceLeft = LeftSubjectRepresentation.Subject;
MotionControllerSourceRight = RightSubjectRepresentation.Subject;
}
LeftHand->SetTrackingMotionSource(MotionControllerSourceLeft);
RightHand->SetTrackingMotionSource(MotionControllerSourceRight);
}
void AVirtualRealityPawn::ServerAttachDCRAtoPawnRpc_Implementation()
{
AttachDCRAtoPawn();
}
void AVirtualRealityPawn::SetCameraOffset() const
{
// this also incorporates the BaseEyeHeight, if set as static offset,
......
......@@ -45,7 +45,7 @@ protected:
}
UFUNCTION(Unreliable, Server, WithValidation)
void SendControllerTransform_ServerRpc(FVRTransformRep NewTransform);
void ServerSendControllerTransformRpc(FVRTransformRep NewTransform);
public:
// Called every frame
......
......@@ -25,6 +25,8 @@ public:
virtual void Tick(float DeltaSeconds) override;
virtual void NotifyControllerChanged() override;
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Pawn|MotionControllers")
UMotionControllerComponent* RightHand;
......@@ -49,12 +51,24 @@ public:
/** Set the LiveLink Subject Representation to be used by this pawn. */
UPROPERTY(BlueprintReadOnly, EditAnywhere, Category="Pawn|LiveLink")
FLiveLinkSubjectRepresentation SubjectRepresentation;
FLiveLinkSubjectRepresentation HeadSubjectRepresentation;
/** Set the LiveLink Subject Representation to be used by this pawn. */
UPROPERTY(BlueprintReadOnly, EditAnywhere, Category="Pawn|LiveLink")
FLiveLinkSubjectRepresentation LeftSubjectRepresentation;
/** Set the LiveLink Subject Representation to be used by this pawn. */
UPROPERTY(BlueprintReadOnly, EditAnywhere, Category="Pawn|LiveLink")
FLiveLinkSubjectRepresentation RightSubjectRepresentation;
/** Set the transform of the component in world space of in its local reference frame. */
UPROPERTY(BlueprintReadOnly, EditAnywhere, Category="Pawn|LiveLink")
bool bWorldTransform = false;
/** The class which to search for DCRA attachment. TODO: Make this better it's ugly */
//UPROPERTY(BlueprintReadOnly, EditAnywhere, Category="Pawn|LiveLink")
TSubclassOf<AActor> CaveSetupActorClass;
protected:
virtual void SetupPlayerInputComponent(UInputComponent* PlayerInputComponent) override;
......@@ -93,4 +107,18 @@ protected:
void SetCameraOffset() const;
void UpdateRightHandForDesktopInteraction();
/**
* Ask the server to attach the DCRA to the correct pawn
* @return void
*/
UFUNCTION(Reliable, Server)
void ServerAttachDCRAtoPawnRpc();
/**
* Attaches the DCRA to the pawn
* @return void
*/
void AttachDCRAtoPawn();
void SetupMotionControllerSources();
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment