Skip to content
Snippets Groups Projects
Commit fc4eda4e authored by Kris Tabea Helwig's avatar Kris Tabea Helwig
Browse files

feat(pawn): Adds VR scaling functionality

parent 1536d61c
Branches
Tags
3 merge requests!118fix: Converted all static meshes to nanite,!115Feature/scaling,!114Feature/scaling
......@@ -41,8 +41,30 @@ ARWTHVRPawn::ARWTHVRPawn(const FObjectInitializer& ObjectInitializer) : Super(Ob
LeftHand = CreateDefaultSubobject<UReplicatedMotionControllerComponent>(TEXT("Left Hand MCC"));
LeftHand->SetupAttachment(RootComponent);
GetRootComponent()->TransformUpdated.AddLambda([this](USceneComponent*, EUpdateTransformFlags, ETeleportType)
{
FVector CurrentScale = this->GetActorScale3D();
if (CurrentScale.X == CurrentScale.Y && CurrentScale.Y == CurrentScale.Z)
{
float expectedScale = GetWorldSettings()->WorldToMeters / InitialWorldToMeters;
float ErrorPrecision = 1E-05;
if (FMath::IsNearlyEqual(CurrentScale.X, expectedScale, ErrorPrecision))
{
return;
}
}
UE_LOGFMT(Toolkit, Warning,
"ARWTHVRPawn: Do not adjust the scale of the pawn directly. This will not work in VR. Use ARWTHVRPawn::SetScale(float) instead.")
;
});
}
void ARWTHVRPawn::BeginPlay()
{
Super::BeginPlay();
InitialWorldToMeters = GetWorldSettings()->WorldToMeters;
}
void ARWTHVRPawn::BeginPlay() { Super::BeginPlay(); }
void ARWTHVRPawn::Tick(float DeltaSeconds)
{
......@@ -56,6 +78,17 @@ void ARWTHVRPawn::Tick(float DeltaSeconds)
EvaluateLivelink();
}
/*
* Scales the Pawn while also adjusting the WorldToMeters ratio to adjust for pupillary distance.
* Only supports uniform scaling.
*/
void ARWTHVRPawn::SetScale(float NewScale)
{
FVector NewScaleVector = FVector(NewScale, NewScale, NewScale);
GetWorldSettings()->WorldToMeters = InitialWorldToMeters * NewScale;
SetActorScale3D(NewScaleVector);
}
/*
* 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.
......
......@@ -31,6 +31,9 @@ public:
virtual void NotifyControllerChanged() override;
UFUNCTION(BlueprintCallable)
void SetScale(float NewScale);
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Pawn|Input")
TArray<UInputMappingContext*> InputMappingContexts;
......@@ -111,4 +114,5 @@ protected:
private:
UInputComponent* ActivePlayerInputComponent;
float InitialWorldToMeters;
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment