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
GitLab 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
1591057c
Commit
1591057c
authored
6 years ago
by
Ali Can Demiralp
Browse files
Options
Downloads
Patches
Plain Diff
Reworked VirtualRealityPawn.
parent
9f0ef47a
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
Source/DisplayClusterExtensions/Private/VirtualRealityPawn.cpp
+74
-51
74 additions, 51 deletions
...e/DisplayClusterExtensions/Private/VirtualRealityPawn.cpp
Source/DisplayClusterExtensions/Public/VirtualRealityPawn.h
+17
-7
17 additions, 7 deletions
Source/DisplayClusterExtensions/Public/VirtualRealityPawn.h
with
91 additions
and
58 deletions
Source/DisplayClusterExtensions/Private/VirtualRealityPawn.cpp
+
74
−
51
View file @
1591057c
...
@@ -12,52 +12,60 @@
...
@@ -12,52 +12,60 @@
AVirtualRealityPawn
::
AVirtualRealityPawn
(
const
FObjectInitializer
&
ObjectInitializer
)
:
Super
(
ObjectInitializer
)
AVirtualRealityPawn
::
AVirtualRealityPawn
(
const
FObjectInitializer
&
ObjectInitializer
)
:
Super
(
ObjectInitializer
)
{
{
MovementComponent
=
CreateDefaultSubobject
<
UFloatingPawnMovement
>
(
TEXT
(
"MovementComponent0"
));
AutoPossessPlayer
=
EAutoReceiveInput
::
Player0
;
// Necessary for receiving motion controller events.
MovementComponent
->
UpdatedComponent
=
RootComponent
;
RotatingComponent
=
CreateDefaultSubobject
<
URotatingMovementComponent
>
(
TEXT
(
"RotatingComponent0"
));
Movement
=
CreateDefaultSubobject
<
UFloatingPawnMovement
>
(
TEXT
(
"Movement"
));
RotatingComponent
->
UpdatedComponent
=
RootComponent
;
Movement
->
UpdatedComponent
=
RootComponent
;
RotatingComponent
->
bRotationInLocalSpace
=
false
;
RotatingComponent
->
PivotTranslation
=
FVector
::
ZeroVector
;
RotatingComponent
->
RotationRate
=
FRotator
::
ZeroRotator
;
TranslationDirection
=
RootComponent
;
RotatingMovement
=
CreateDefaultSubobject
<
URotatingMovementComponent
>
(
TEXT
(
"RotatingMovement"
));
RotatingMovement
->
UpdatedComponent
=
RootComponent
;
RotatingMovement
->
bRotationInLocalSpace
=
false
;
RotatingMovement
->
PivotTranslation
=
FVector
::
ZeroVector
;
RotatingMovement
->
RotationRate
=
FRotator
::
ZeroRotator
;
AutoPossessPlayer
=
EAutoReceiveInput
::
Player0
;
// Necessary for receiving motion controller events.
LeftMotionController
=
CreateDefaultSubobject
<
UMotionControllerComponent
>
(
TEXT
(
"LeftMotionController"
));
LeftMotionController
->
SetupAttachment
(
RootComponent
);
LeftMotionController
->
SetTrackingSource
(
EControllerHand
::
Left
);
LeftMotionController
->
SetShowDeviceModel
(
true
);
LeftMotionController
->
SetVisibility
(
false
);
RightMotionController
=
CreateDefaultSubobject
<
UMotionControllerComponent
>
(
TEXT
(
"RightMotionController"
));
RightMotionController
->
SetupAttachment
(
RootComponent
);
RightMotionController
->
SetTrackingSource
(
EControllerHand
::
Right
);
RightMotionController
->
SetShowDeviceModel
(
true
);
RightMotionController
->
SetVisibility
(
false
);
}
}
void
AVirtualRealityPawn
::
OnForward_Implementation
(
float
Value
)
void
AVirtualRealityPawn
::
OnForward_Implementation
(
float
Value
)
{
{
AddMovementInput
(
TranslationDirection
->
GetForwardVector
(),
Value
);
AddMovementInput
(
Forward
->
GetForwardVector
(),
Value
);
}
}
void
AVirtualRealityPawn
::
OnRight_Implementation
(
float
Value
)
void
AVirtualRealityPawn
::
OnRight_Implementation
(
float
Value
)
{
{
AddMovementInput
(
TranslationDirection
->
GetRightVector
(),
Value
);
AddMovementInput
(
Forward
->
GetRightVector
(),
Value
);
}
}
void
AVirtualRealityPawn
::
OnTurnRate_Implementation
(
float
Rate
)
void
AVirtualRealityPawn
::
OnTurnRate_Implementation
(
float
Rate
)
{
{
if
(
IDisplayCluster
::
Get
().
GetOperationMode
()
==
EDisplayClusterOperationMode
::
Cluster
)
if
(
IDisplayCluster
::
Get
().
GetOperationMode
()
==
EDisplayClusterOperationMode
::
Cluster
)
{
{
if
(
!
RotatingComponent
->
UpdatedComponent
||
!
IDisplayCluster
::
Get
().
GetGameMgr
()
||
!
IDisplayCluster
::
Get
().
GetGameMgr
()
->
GetActiveCamera
())
return
;
const
FVector
CameraLocation
=
IDisplayCluster
::
Get
().
GetGameMgr
()
->
GetActiveCamera
()
->
GetComponentLocation
();
const
FVector
CameraLocation
=
IDisplayCluster
::
Get
().
GetGameMgr
()
->
GetActiveCamera
()
->
GetComponentLocation
();
Rotating
Compon
ent
->
PivotTranslation
=
Rotating
Compon
ent
->
UpdatedComponent
->
GetComponentTransform
().
InverseTransformPositionNoScale
(
CameraLocation
);
Rotating
Movem
ent
->
PivotTranslation
=
Rotating
Movem
ent
->
UpdatedComponent
->
GetComponentTransform
().
InverseTransformPositionNoScale
(
CameraLocation
);
Rotating
Compon
ent
->
RotationRate
=
FRotator
(
Rotating
Compon
ent
->
RotationRate
.
Pitch
,
Rate
*
BaseTurnRate
,
0.0f
);
Rotating
Movem
ent
->
RotationRate
=
FRotator
(
Rotating
Movem
ent
->
RotationRate
.
Pitch
,
Rate
*
BaseTurnRate
,
0.0f
);
}
}
else
else
{
{
AddControllerYawInput
(
BaseTurnRate
*
Rate
*
GetWorld
()
->
GetDeltaSeconds
()
*
CustomTimeDilation
);
AddControllerYawInput
(
Rate
*
BaseTurnRate
*
GetWorld
()
->
GetDeltaSeconds
()
*
CustomTimeDilation
);
}
}
}
}
void
AVirtualRealityPawn
::
OnLookUpRate_Implementation
(
float
Rate
)
void
AVirtualRealityPawn
::
OnLookUpRate_Implementation
(
float
Rate
)
{
{
if
(
IDisplayCluster
::
Get
().
GetOperationMode
()
==
EDisplayClusterOperationMode
::
Cluster
)
if
(
IDisplayCluster
::
Get
().
GetOperationMode
()
==
EDisplayClusterOperationMode
::
Cluster
)
{
{
// User-centered projection causes
mo
tion sickness on look up interaction hence not implemented.
// User-centered projection causes
simula
tion sickness on look up interaction hence not implemented.
}
}
else
else
{
{
AddControllerPitchInput
(
BaseTurnRate
*
Rate
*
GetWorld
()
->
GetDeltaSeconds
()
*
CustomTimeDilation
);
AddControllerPitchInput
(
Rate
*
BaseTurnRate
*
GetWorld
()
->
GetDeltaSeconds
()
*
CustomTimeDilation
);
}
}
}
}
void
AVirtualRealityPawn
::
OnFire_Implementation
(
bool
Pressed
)
void
AVirtualRealityPawn
::
OnFire_Implementation
(
bool
Pressed
)
...
@@ -73,46 +81,61 @@ void AVirtualRealityPawn::BeginPlay ()
...
@@ -73,46 +81,61 @@ void AVirtualRealityPawn::BeginPlay ()
{
{
Super
::
BeginPlay
();
Super
::
BeginPlay
();
if
(
!
IDisplayCluster
::
Get
().
IsModuleInitialized
()
||
!
IDisplayCluster
::
Get
().
IsAvailable
())
return
;
// Display cluster settings apply to all setups (PC, HMD, CAVE/ROLV) despite the unfortunate name due to being an UE4 internal.
auto
IsCluster
=
(
IDisplayCluster
::
Get
().
GetOperationMode
()
==
EDisplayClusterOperationMode
::
Cluster
);
bUseControllerRotationYaw
=
!
IsCluster
;
bUseControllerRotationPitch
=
!
IsCluster
;
bUseControllerRotationRoll
=
!
IsCluster
;
TArray
<
AActor
*>
SettingsActors
;
TArray
<
AActor
*>
SettingsActors
;
UGameplayStatics
::
GetAllActorsOfClass
(
GetWorld
(),
ADisplayClusterSettings
::
StaticClass
(),
SettingsActors
);
UGameplayStatics
::
GetAllActorsOfClass
(
GetWorld
(),
ADisplayClusterSettings
::
StaticClass
(),
SettingsActors
);
if
(
SettingsActors
.
Num
()
==
0
)
return
;
if
(
SettingsActors
.
Num
()
>
0
)
{
ADisplayClusterSettings
*
Settings
=
Cast
<
ADisplayClusterSettings
>
(
SettingsActors
[
0
]);
ADisplayClusterSettings
*
Settings
=
Cast
<
ADisplayClusterSettings
>
(
SettingsActors
[
0
]);
Movement
Component
->
MaxSpeed
=
Settings
->
MovementMaxSpeed
;
Movement
->
MaxSpeed
=
Settings
->
MovementMaxSpeed
;
Movement
Component
->
Acceleration
=
Settings
->
MovementAcceleration
;
Movement
->
Acceleration
=
Settings
->
MovementAcceleration
;
Movement
Component
->
Deceleration
=
Settings
->
MovementDeceleration
;
Movement
->
Deceleration
=
Settings
->
MovementDeceleration
;
Movement
Component
->
TurningBoost
=
Settings
->
MovementTurningBoost
;
Movement
->
TurningBoost
=
Settings
->
MovementTurningBoost
;
BaseTurnRate
=
Settings
->
RotationSpeed
;
BaseTurnRate
=
Settings
->
RotationSpeed
;
}
if
(
UHeadMountedDisplayFunctionLibrary
::
IsHeadMountedDisplayEnabled
())
if
(
IDisplayCluster
::
Get
().
GetOperationMode
()
==
EDisplayClusterOperationMode
::
Cluster
)
{
// Requires a scene node called flystick in the config.
Flystick
=
IDisplayCluster
::
Get
().
GetGameMgr
()
->
GetNodeById
(
TEXT
(
"flystick"
));
Forward
=
Flystick
;
LeftHand
=
Flystick
;
RightHand
=
Flystick
;
}
else
if
(
UHeadMountedDisplayFunctionLibrary
::
IsHeadMountedDisplayEnabled
())
{
{
LeftMotionControllerComponent
=
CreateDefaultSubobject
<
UMotionControllerComponent
>
(
TEXT
(
"LeftMotionControllerComponent"
));
LeftMotionController
->
SetVisibility
(
true
);
LeftMotionControllerComponent
->
SetTrackingSource
(
EControllerHand
::
Left
);
RightMotionController
->
SetVisibility
(
true
);
LeftMotionControllerComponent
->
SetShowDeviceModel
(
true
);
RightMotionControllerComponent
=
CreateDefaultSubobject
<
UMotionControllerComponent
>
(
TEXT
(
"RightMotionControllerComponent"
));
Forward
=
LeftMotionController
;
RightMotionControllerComponent
->
SetTrackingSource
(
EControllerHand
::
Right
);
LeftHand
=
LeftMotionController
;
RightMotionControllerComponent
->
SetShowDeviceModel
(
true
);
RightHand
=
RightMotionController
;
}
else
{
bUseControllerRotationYaw
=
true
;
bUseControllerRotationPitch
=
true
;
bUseControllerRotationRoll
=
true
;
TranslationDirection
=
LeftMotionControllerComponent
;
Forward
=
RootComponent
;
LeftHand
=
RootComponent
;
RightHand
=
RootComponent
;
}
}
}
}
void
AVirtualRealityPawn
::
Tick
(
float
DeltaSeconds
)
void
AVirtualRealityPawn
::
Tick
(
float
DeltaSeconds
)
{
{
Super
::
Tick
(
DeltaSeconds
);
Super
::
Tick
(
DeltaSeconds
);
// Flystick might not be available at start, hence is checked every frame.
if
(
IDisplayCluster
::
Get
().
GetOperationMode
()
==
EDisplayClusterOperationMode
::
Cluster
&&
!
Flystick
)
if
(
IDisplayCluster
::
Get
().
GetOperationMode
()
==
EDisplayClusterOperationMode
::
Cluster
&&
!
Flystick
)
{
{
Flystick
=
IDisplayCluster
::
Get
().
GetGameMgr
()
->
GetNodeById
(
TEXT
(
"flystick"
));
// Note: Requires a scene node called flystick in the config. Make settable.
// Requires a scene node called flystick in the config.
if
(
Flystick
)
Flystick
=
IDisplayCluster
::
Get
().
GetGameMgr
()
->
GetNodeById
(
TEXT
(
"flystick"
));
TranslationDirection
=
Flystick
;
Forward
=
Flystick
;
LeftHand
=
Flystick
;
RightHand
=
Flystick
;
}
}
}
}
void
AVirtualRealityPawn
::
BeginDestroy
()
void
AVirtualRealityPawn
::
BeginDestroy
()
...
@@ -148,5 +171,5 @@ void AVirtualRealityPawn::SetupPlayerInputComponent (UInputC
...
@@ -148,5 +171,5 @@ void AVirtualRealityPawn::SetupPlayerInputComponent (UInputC
}
}
UPawnMovementComponent
*
AVirtualRealityPawn
::
GetMovementComponent
()
const
UPawnMovementComponent
*
AVirtualRealityPawn
::
GetMovementComponent
()
const
{
{
return
Movement
Component
;
return
Movement
;
}
}
This diff is collapsed.
Click to expand it.
Source/DisplayClusterExtensions/Public/VirtualRealityPawn.h
+
17
−
7
View file @
1591057c
...
@@ -23,9 +23,6 @@ public:
...
@@ -23,9 +23,6 @@ public:
UFUNCTION
(
BlueprintNativeEvent
,
BlueprintCallable
,
Category
=
"Pawn"
)
void
OnFire
(
bool
Pressed
);
UFUNCTION
(
BlueprintNativeEvent
,
BlueprintCallable
,
Category
=
"Pawn"
)
void
OnFire
(
bool
Pressed
);
UFUNCTION
(
BlueprintNativeEvent
,
BlueprintCallable
,
Category
=
"Pawn"
)
void
OnAction
(
bool
Pressed
,
int32
Index
);
UFUNCTION
(
BlueprintNativeEvent
,
BlueprintCallable
,
Category
=
"Pawn"
)
void
OnAction
(
bool
Pressed
,
int32
Index
);
UPROPERTY
(
EditAnywhere
,
BlueprintReadWrite
,
Category
=
"Pawn"
)
float
BaseTurnRate
=
45.0f
;
UPROPERTY
(
EditAnywhere
,
BlueprintReadWrite
,
Category
=
"Pawn"
)
UDisplayClusterSceneComponent
*
Flystick
=
nullptr
;
protected:
protected:
DECLARE_DELEGATE_OneParam
(
FFireDelegate
,
bool
);
DECLARE_DELEGATE_OneParam
(
FFireDelegate
,
bool
);
DECLARE_DELEGATE_TwoParams
(
FActionDelegate
,
bool
,
int32
);
DECLARE_DELEGATE_TwoParams
(
FActionDelegate
,
bool
,
int32
);
...
@@ -36,8 +33,21 @@ protected:
...
@@ -36,8 +33,21 @@ protected:
virtual
void
SetupPlayerInputComponent
(
UInputComponent
*
PlayerInputComponent
)
override
;
virtual
void
SetupPlayerInputComponent
(
UInputComponent
*
PlayerInputComponent
)
override
;
virtual
UPawnMovementComponent
*
GetMovementComponent
()
const
override
;
virtual
UPawnMovementComponent
*
GetMovementComponent
()
const
override
;
UPROPERTY
(
VisibleAnywhere
,
BlueprintReadOnly
,
Category
=
"Pawn"
,
meta
=
(
AllowPrivateAccess
=
"true"
))
UFloatingPawnMovement
*
MovementComponent
=
nullptr
;
UPROPERTY
(
EditAnywhere
,
BlueprintReadWrite
,
Category
=
"Pawn"
,
meta
=
(
AllowPrivateAccess
=
"true"
))
float
BaseTurnRate
=
45.0f
;
UPROPERTY
(
VisibleAnywhere
,
BlueprintReadOnly
,
Category
=
"Pawn"
,
meta
=
(
AllowPrivateAccess
=
"true"
))
URotatingMovementComponent
*
RotatingComponent
=
nullptr
;
UPROPERTY
(
VisibleAnywhere
,
BlueprintReadOnly
,
Category
=
"Pawn"
,
meta
=
(
AllowPrivateAccess
=
"true"
))
UFloatingPawnMovement
*
Movement
=
nullptr
;
UPROPERTY
(
VisibleAnywhere
,
BlueprintReadOnly
,
Category
=
"Pawn"
,
meta
=
(
AllowPrivateAccess
=
"true"
))
UMotionControllerComponent
*
LeftMotionControllerComponent
=
nullptr
;
UPROPERTY
(
VisibleAnywhere
,
BlueprintReadOnly
,
Category
=
"Pawn"
,
meta
=
(
AllowPrivateAccess
=
"true"
))
URotatingMovementComponent
*
RotatingMovement
=
nullptr
;
UPROPERTY
(
VisibleAnywhere
,
BlueprintReadOnly
,
Category
=
"Pawn"
,
meta
=
(
AllowPrivateAccess
=
"true"
))
UMotionControllerComponent
*
RightMotionControllerComponent
=
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. HMD left motion controller.
UPROPERTY
(
VisibleAnywhere
,
BlueprintReadOnly
,
Category
=
"Pawn"
,
meta
=
(
AllowPrivateAccess
=
"true"
))
UMotionControllerComponent
*
LeftMotionController
=
nullptr
;
// Use only when handling cross-device (PC, HMD, CAVE/ROLV) compatibility manually. HMD right motion controller.
UPROPERTY
(
VisibleAnywhere
,
BlueprintReadOnly
,
Category
=
"Pawn"
,
meta
=
(
AllowPrivateAccess
=
"true"
))
UMotionControllerComponent
*
RightMotionController
=
nullptr
;
// PC: RootComponent, HMD: LeftMotionController , CAVE/ROLV: Flystick. Movement follows this component.
UPROPERTY
(
VisibleAnywhere
,
BlueprintReadOnly
,
Category
=
"Pawn"
,
meta
=
(
AllowPrivateAccess
=
"true"
))
USceneComponent
*
Forward
=
nullptr
;
// PC: RootComponent, HMD: LeftMotionController , CAVE/ROLV: Flystick. Useful for line trace (e.g. for holding objects).
UPROPERTY
(
VisibleAnywhere
,
BlueprintReadOnly
,
Category
=
"Pawn"
,
meta
=
(
AllowPrivateAccess
=
"true"
))
USceneComponent
*
LeftHand
=
nullptr
;
// PC: RootComponent, HMD: RightMotionController, CAVE/ROLV: Flystick. Useful for line trace (e.g. for holding objects).
UPROPERTY
(
VisibleAnywhere
,
BlueprintReadOnly
,
Category
=
"Pawn"
,
meta
=
(
AllowPrivateAccess
=
"true"
))
USceneComponent
*
RightHand
=
nullptr
;
};
};
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