@@ -41,8 +41,26 @@ ARWTHVRPawn::ARWTHVRPawn(const FObjectInitializer& ObjectInitializer) : Super(Ob
4141
4242 LeftHand = CreateDefaultSubobject<UReplicatedMotionControllerComponent>(TEXT (" Left Hand MCC" ));
4343 LeftHand->SetupAttachment (RootComponent);
44+
45+ UniformScale = GetActorScale3D ().X ;
46+ GetRootComponent ()->TransformUpdated .AddLambda (
47+ [this ](USceneComponent*, EUpdateTransformFlags, ETeleportType)
48+ {
49+ FVector CurrentScale = this ->GetActorScale3D ();
50+ if (CurrentScale.X != UniformScale || CurrentScale.Y != UniformScale || CurrentScale.Z != UniformScale)
51+ {
52+ UE_LOGFMT (Toolkit, Warning,
53+ " ARWTHVRPawn: Do not adjust the scale of the pawn directly. This will not work in VR. Use "
54+ " ARWTHVRPawn::SetScale(float) instead." );
55+ }
56+ });
57+ }
58+
59+ void ARWTHVRPawn::BeginPlay ()
60+ {
61+ Super::BeginPlay ();
62+ InitialWorldToMeters = GetWorldSettings ()->WorldToMeters ;
4463}
45- void ARWTHVRPawn::BeginPlay () { Super::BeginPlay (); }
4664
4765void ARWTHVRPawn::Tick (float DeltaSeconds)
4866{
@@ -56,6 +74,22 @@ void ARWTHVRPawn::Tick(float DeltaSeconds)
5674 EvaluateLivelink ();
5775}
5876
77+ /*
78+ * Scales the Pawn while also adjusting the WorldToMeters ratio to adjust for pupillary distance.
79+ * Only supports uniform scaling.
80+ */
81+ void ARWTHVRPawn::SetScale (float NewScale)
82+ {
83+ FVector OldScale = GetActorScale ();
84+ UniformScale = NewScale;
85+ FVector NewScaleVector = FVector (UniformScale, UniformScale, UniformScale);
86+ GetWorldSettings ()->WorldToMeters = InitialWorldToMeters * UniformScale;
87+ SetActorRelativeScale3D (NewScaleVector);
88+ OnScaleChanged.Broadcast (OldScale, NewScale);
89+ }
90+
91+ float ARWTHVRPawn::GetScale () { return UniformScale; }
92+
5993/*
6094 * The alternative would be to do this only on the server on possess and check for player state/type,
6195 * as connections now send their playertype over.
@@ -362,4 +396,4 @@ void ARWTHVRPawn::ApplyLiveLinkTransform(const FTransform& Transform,
362396 HeadCameraComponent->SetRelativeScale3D (Transform.GetScale3D ());
363397 }
364398 }
365- }
399+ }
0 commit comments