Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
RWTH VR Toolkit
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
LuFG VR VIS
VR-Group
Unreal-Development
Plugins
RWTH VR Toolkit
Commits
fc4eda4e
Commit
fc4eda4e
authored
2 months ago
by
Kris Tabea Helwig
Browse files
Options
Downloads
Patches
Plain Diff
feat(pawn): Adds VR scaling functionality
parent
1536d61c
No related branches found
No related tags found
2 merge requests
!118
fix: Converted all static meshes to nanite
,
!114
Feature/scaling
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Source/RWTHVRToolkit/Private/Pawn/RWTHVRPawn.cpp
+46
-13
46 additions, 13 deletions
Source/RWTHVRToolkit/Private/Pawn/RWTHVRPawn.cpp
Source/RWTHVRToolkit/Public/Pawn/RWTHVRPawn.h
+4
-0
4 additions, 0 deletions
Source/RWTHVRToolkit/Public/Pawn/RWTHVRPawn.h
with
50 additions
and
13 deletions
Source/RWTHVRToolkit/Private/Pawn/RWTHVRPawn.cpp
+
46
−
13
View file @
fc4eda4e
...
...
@@ -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.
...
...
@@ -71,7 +104,7 @@ void ARWTHVRPawn::NotifyControllerChanged()
if
(
HasAuthority
())
{
UE_LOG
(
Toolkit
,
Display
,
TEXT
(
"ARWTHVRPawn: Player Controller has changed, trying to change Cluster attachment if possible..."
));
TEXT
(
"ARWTHVRPawn: Player Controller has changed, trying to change Cluster attachment if possible..."
));
if
(
const
ARWTHVRPlayerState
*
State
=
GetPlayerState
<
ARWTHVRPlayerState
>
())
{
const
EPlayerType
Type
=
State
->
GetPlayerType
();
...
...
@@ -101,7 +134,7 @@ void ARWTHVRPawn::SetupPlayerInputComponent(UInputComponent* PlayerInputComponen
}
UE_LOGFMT
(
Toolkit
,
Display
,
"SetupPlayerInputComponent: Player Controller is valid, setting up input for {Pawn}"
,
GetName
());
GetName
());
// Set the control rotation of the PC to zero again. There is a small period of 2 frames where, when the pawn gets
...
...
@@ -173,7 +206,7 @@ void ARWTHVRPawn::AddInputMappingContext(const APlayerController* PC, const UInp
else
{
UE_LOGFMT
(
Toolkit
,
Warning
,
"ARWTHVRPawn::AddInputMappingContext: UEnhancedInputLocalPlayerSubsystem is nullptr!"
);
"ARWTHVRPawn::AddInputMappingContext: UEnhancedInputLocalPlayerSubsystem is nullptr!"
);
}
}
else
...
...
@@ -201,7 +234,7 @@ void ARWTHVRPawn::EvaluateLivelink() const
IModularFeatures
::
Get
().
GetModularFeature
<
ILiveLinkClient
>
(
ILiveLinkClient
::
ModularFeatureName
);
FLiveLinkSubjectFrameData
SubjectData
;
const
bool
bHasValidData
=
LiveLinkClient
.
EvaluateFrame_AnyThread
(
HeadSubjectRepresentation
.
Subject
,
HeadSubjectRepresentation
.
Role
,
SubjectData
);
HeadSubjectRepresentation
.
Role
,
SubjectData
);
if
(
!
bHasValidData
)
{
...
...
@@ -278,12 +311,12 @@ void ARWTHVRPawn::AttachClustertoPawn()
bool
bAttached
=
ClusterActor
->
AttachToComponent
(
GetRootComponent
(),
AttachmentRules
);
// State->GetCorrespondingClusterActor()->OnAttached();
UE_LOGFMT
(
Toolkit
,
Display
,
"ARWTHVRPawn: Attaching corresponding cluster actor to our pawn returned: {Attached}"
,
bAttached
);
"ARWTHVRPawn: Attaching corresponding cluster actor to our pawn returned: {Attached}"
,
bAttached
);
}
else
{
UE_LOGFMT
(
Toolkit
,
Error
,
"ARWTHVRPawn::AttachClustertoPawn: No ARWTHVRPlayerState set! This won't work on the Cave."
);
"ARWTHVRPawn::AttachClustertoPawn: No ARWTHVRPlayerState set! This won't work on the Cave."
);
}
if
(
HasAuthority
())
// Should always be the case here, but double check
...
...
@@ -321,19 +354,19 @@ void ARWTHVRPawn::SetCameraOffset() const
}
void
ARWTHVRPawn
::
ApplyLiveLinkTransform
(
const
FTransform
&
Transform
,
const
FLiveLinkTransformStaticData
&
StaticData
)
const
const
FLiveLinkTransformStaticData
&
StaticData
)
const
{
if
(
StaticData
.
bIsLocationSupported
)
{
if
(
bWorldTransform
)
{
HeadCameraComponent
->
SetWorldLocation
(
Transform
.
GetLocation
(),
false
,
nullptr
,
ETeleportType
::
TeleportPhysics
);
ETeleportType
::
TeleportPhysics
);
}
else
{
HeadCameraComponent
->
SetRelativeLocation
(
Transform
.
GetLocation
(),
false
,
nullptr
,
ETeleportType
::
TeleportPhysics
);
ETeleportType
::
TeleportPhysics
);
}
}
...
...
@@ -342,12 +375,12 @@ void ARWTHVRPawn::ApplyLiveLinkTransform(const FTransform& Transform,
if
(
bWorldTransform
)
{
HeadCameraComponent
->
SetWorldRotation
(
Transform
.
GetRotation
(),
false
,
nullptr
,
ETeleportType
::
TeleportPhysics
);
ETeleportType
::
TeleportPhysics
);
}
else
{
HeadCameraComponent
->
SetRelativeRotation
(
Transform
.
GetRotation
(),
false
,
nullptr
,
ETeleportType
::
TeleportPhysics
);
ETeleportType
::
TeleportPhysics
);
}
}
...
...
@@ -362,4 +395,4 @@ void ARWTHVRPawn::ApplyLiveLinkTransform(const FTransform& Transform,
HeadCameraComponent
->
SetRelativeScale3D
(
Transform
.
GetScale3D
());
}
}
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Source/RWTHVRToolkit/Public/Pawn/RWTHVRPawn.h
+
4
−
0
View file @
fc4eda4e
...
...
@@ -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
;
};
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment