A Demo Project for the UnrealEngineSDK
Loading...
Searching...
No Matches
ReplicatedVRCameraComponent.h
Go to the documentation of this file.
1// Fill out your copyright notice in the Description page of Project Settings.
2
3#pragma once
4#include "CoreMinimal.h"
5#include "VRBPDatatypes.h"
6#include "Net/UnrealNetwork.h"
7#include "Camera/CameraComponent.h"
8#include "ReplicatedVRCameraComponent.generated.h"
9
11
15UCLASS(Blueprintable, meta = (BlueprintSpawnableComponent), ClassGroup = VRExpansionLibrary)
16class VREXPANSIONPLUGIN_API UReplicatedVRCameraComponent : public UCameraComponent
17{
18 GENERATED_BODY()
20public:
21 UReplicatedVRCameraComponent(const FObjectInitializer& ObjectInitializer);
22
23
24 // If true, this component will not perform logic in its tick, it will instead allow the character movement component to move it (unless the CMC is inactive, then it will go back to self managing)
25 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VRExpansionLibrary")
26 bool bUpdateInCharacterMovement;
27
28 UPROPERTY()
29 TWeakObjectPtr<AVRBaseCharacter> AttachChar;
30 void UpdateTracking(float DeltaTime);
31
32 virtual void OnAttachmentChanged() override;
34 virtual void TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction *ThisTickFunction) override;
35 //virtual void PreReplication(IRepChangedPropertyTracker & ChangedPropertyTracker) override;
36
38 bool bHasAuthority;
39
41 bool bIsServer;
42
43 FTransform LastRelativePosition;
44 bool bHadValidFirstVelocity;
45
46 // If we should sample the velocity in world or local space
47 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "ReplicatedCamera|ComponentVelocity")
48 bool bSampleVelocityInWorldSpace;
49
50 // For non view target positional updates
51 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "ReplicatedCamera")
52 bool bSetPositionDuringTick;
54 // If true will subtract the HMD's location from the position, useful for if the actors base is set to the HMD location always (simple character).
55 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "ReplicatedCamera")
56 bool bOffsetByHMD;
57
58 // If true will scale the tracking of the camera by TrackingScaler
59 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "ReplicatedCamera|Advanced|Tracking")
60 bool bScaleTracking;
62 // A scale to be applied to the tracking of the camera
63 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "ReplicatedCamera|Advanced|Tracking", meta = (ClampMin = "0.1", UIMin = "0.1", EditCondition = "bScaleTracking"))
64 FVector TrackingScaler;
65
66 // If true we will use the minimum height value to clamp the Z too
67 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "ReplicatedCamera|Advanced|Tracking")
68 bool bLimitMinHeight;
70 // The minimum height to allow for this camera
71 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "ReplicatedCamera|Advanced|Tracking", meta = (ClampMin = "0.0", UIMin = "0.0", EditCondition = "bLimitMinHeight"))
72 float MinimumHeightAllowed;
73
74 // If true will limit the max Z height that the camera is capable of reaching
75 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "ReplicatedCamera|Advanced|Tracking")
76 bool bLimitMaxHeight;
78 // If we are limiting the max height, this is the maximum allowed value
79 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "ReplicatedCamera|Advanced|Tracking", meta = (ClampMin = "0.1", UIMin = "0.1", EditCondition = "bLimitMaxHeight"))
80 float MaxHeightAllowed;
81
82 // If true will limit the maximum offset from center of the players tracked space
83 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "ReplicatedCamera|Advanced|Tracking")
84 bool bLimitBounds;
86 // If we are limiting the maximum bounds, this is the maximum length of the vector from the center of the tracked space
87 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "ReplicatedCamera|Advanced|Tracking", meta = (ClampMin = "0.1", UIMin = "0.1", EditCondition = "bLimitMaxHeight"))
88 float MaximumTrackedBounds;
89
91 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "ReplicatedCamera|Advanced|Tracking")
92 uint32 bAutoSetLockToHmd : 1;
94 void ApplyTrackingParameters(FVector& OriginalPosition);
95 bool HasTrackingParameters();
96
97 //UFUNCTION(BlueprintCallable, Category = Camera)
98 virtual void GetCameraView(float DeltaTime, FMinimalViewInfo& DesiredView) override;
99
100 UPROPERTY(EditDefaultsOnly, ReplicatedUsing = OnRep_ReplicatedCameraTransform, Category = "ReplicatedCamera|Networking")
101 FBPVRComponentPosRep ReplicatedCameraTransform;
102
103 FBPVRComponentPosRep MotionSampleUpdateBuffer[2];
104
105 FVector LastUpdatesRelativePosition;
106 FRotator LastUpdatesRelativeRotation;
107
108 bool bLerpingPosition;
109 bool bReppedOnce;
110
111 // Run the smoothing step
112 void RunNetworkedSmoothing(float DeltaTime);
113
114 // Whether to smooth (lerp) between ticks for the replicated motion, DOES NOTHING if update rate is larger than FPS!
115 UPROPERTY(EditAnywhere, BlueprintReadWrite, Replicated, Category = "ReplicatedCamera|Networking")
116 bool bSmoothReplicatedMotion;
118 // If true then we will use exponential smoothing with buffered correction
119 UPROPERTY(EditAnywhere, Category = "GripMotionController|Networking|Smoothing", meta = (editcondition = "bSmoothReplicatedMotion"))
120 bool bUseExponentialSmoothing = true;
121
122 // Timestep of smoothing translation
123 UPROPERTY(EditAnywhere, Category = "GripMotionController|Networking|Smoothing", meta = (editcondition = "bUseExponentialSmoothing"))
124 float InterpolationSpeed = 50.0f;
126 // Max distance to allow smoothing before snapping the remainder
127 UPROPERTY(EditAnywhere, Category = "GripMotionController|Networking|Smoothing", meta = (editcondition = "bUseExponentialSmoothing"))
128 float NetworkMaxSmoothUpdateDistance = 50.f;
129
130 // Max distance to allow smoothing before snapping entirely to the new position
131 UPROPERTY(EditAnywhere, Category = "GripMotionController|Networking|Smoothing", meta = (editcondition = "bUseExponentialSmoothing"))
132 float NetworkNoSmoothUpdateDistance = 100.f;
134 UFUNCTION()
135 virtual void OnRep_ReplicatedCameraTransform();
136
137 // Rate to update the position to the server, 100htz is default (same as replication rate, should also hit every tick).
138 UPROPERTY(EditAnywhere, BlueprintReadWrite, Replicated, Category = "ReplicatedCamera|Networking")
139 float NetUpdateRate;
140
141 // Used in Tick() to accumulate before sending updates, didn't want to use a timer in this case.
142 float NetUpdateCount;
143
144 // I'm sending it unreliable because it is being resent pretty often
145 UFUNCTION(Unreliable, Server, WithValidation)
146 void Server_SendCameraTransform(FBPVRComponentPosRep NewTransform);
147
148 // Pointer to an override to call from the owning character - this saves 7 bits a rep avoiding component IDs on the RPC
149 typedef void (AVRBaseCharacter::*VRBaseCharTransformRPC_Pointer)(FBPVRComponentPosRep NewTransform);
150 VRBaseCharTransformRPC_Pointer OverrideSendTransform;
151
152 // Need this as I can't think of another way for an actor component to make sure it isn't on the server
153 inline bool IsLocallyControlled() const
154 {
155 // I like epics new authority check more than my own
156 const AActor* MyOwner = GetOwner();
157 return MyOwner->HasLocalNetOwner();
158 //const APawn* MyPawn = Cast<APawn>(MyOwner);
159 //return MyPawn ? MyPawn->IsLocallyControlled() : false;// (MyOwner->Role == ENetRole::ROLE_Authority);
160 }
162 //bool IsServer();
UCLASS(Blueprintable, meta = (BlueprintSpawnableComponent), ClassGroup = VRExpansionLibrary)
bool bSampleVelocityInWorldSpace
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "ReplicatedCamera|ComponentVelocity")
bool bScaleTracking
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "ReplicatedCamera|Advanced|Tracking")
bool bOffsetByHMD
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "ReplicatedCamera")
bool bLimitMaxHeight
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "ReplicatedCamera|Advanced|Tracking")
uint32 bAutoSetLockToHmd
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "ReplicatedCamera|Advanced|Tracking")
TWeakObjectPtr< AVRBaseCharacter > AttachChar
UPROPERTY()
FVector TrackingScaler
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "ReplicatedCamera|Advanced|Tracking",...
float NetUpdateRate
UPROPERTY(EditAnywhere, BlueprintReadWrite, Replicated, Category = "ReplicatedCamera|Networking")
FBPVRComponentPosRep ReplicatedCameraTransform
UPROPERTY(EditDefaultsOnly, ReplicatedUsing = OnRep_ReplicatedCameraTransform, Category = "Replicated...
bool bSetPositionDuringTick
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "ReplicatedCamera")
VRBaseCharTransformRPC_Pointer OverrideSendTransform
float MaximumTrackedBounds
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "ReplicatedCamera|Advanced|Tracking",...
float MinimumHeightAllowed
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "ReplicatedCamera|Advanced|Tracking",...
bool bUpdateInCharacterMovement
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VRExpansionLibrary")
float MaxHeightAllowed
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "ReplicatedCamera|Advanced|Tracking",...
void Server_SendCameraTransform(FBPVRComponentPosRep NewTransform)
UFUNCTION(Unreliable, Server, WithValidation)
bool bSmoothReplicatedMotion
UPROPERTY(EditAnywhere, BlueprintReadWrite, Replicated, Category = "ReplicatedCamera|Networking")
bool bLimitMinHeight
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "ReplicatedCamera|Advanced|Tracking")
bool bLimitBounds
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "ReplicatedCamera|Advanced|Tracking")