44 virtual void InitializeComponent()
override;
51 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category =
"VRExpansionLibrary", meta = (ClampMin =
"0", UIMin =
"0"))
54 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VRExpansionLibrary", meta = (ClampMin = "0", UIMin = "0"))
57 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VRExpansionLibrary")
64 FTransform LeftControllerTrans;
65 FTransform RightControllerTrans;
68 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VRExpansionLibrary")
69 bool bUseFeetLocation;
73 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VRExpansionLibrary")
77 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VRExpansionLibrary")
81 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VRExpansionLibrary")
82 bool bIgnoreRotationFromParent;
85 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VRExpansionLibrary")
86 bool bUpdateInCharacterMovement;
89 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VRTrackedParentInterface")
92 virtual
void SetTrackedParent(UPrimitiveComponent * NewParentComponent,
float WaistRadius,
EBPVRWaistTrackingMode WaistTrackingMode)
override
102 void TickComponent(
float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction *ThisTickFunction) override;
104 virtual
void OnAttachmentChanged() override;
105 void UpdateTracking(
float DeltaTime);
107 bool IsLocallyControlled()
const
110 const AActor* MyOwner = GetOwner();
111 return MyOwner->HasLocalNetOwner();
117 inline void SetRelativeRotAndLoc(FVector NewRelativeLocation, FRotator NewRelativeRotation,
float DeltaTime)
120 RunSampling(NewRelativeRotation, NewRelativeLocation);
122 if (bUseFeetLocation)
124 if (!bIgnoreRotationFromParent)
126 SetRelativeLocationAndRotation(
127 FVector(NewRelativeLocation.X, NewRelativeLocation.Y, 0.0f) + CustomOffset,
128 GetCalculatedRotation(NewRelativeRotation, DeltaTime)
133 SetRelativeLocation(FVector(NewRelativeLocation.X, NewRelativeLocation.Y, 0.0f) + CustomOffset);
138 if (!bIgnoreRotationFromParent)
140 SetRelativeLocationAndRotation(
141 NewRelativeLocation + CustomOffset,
142 GetCalculatedRotation(NewRelativeRotation, DeltaTime)
147 SetRelativeLocation(NewRelativeLocation + CustomOffset);
152 FQuat GetCalculatedRotation(FRotator InverseRot,
float DeltaTime)
154 FRotator FinalRot = FRotator::ZeroRotator;
156 if (FPlatformMath::Abs(FRotator::ClampAxis(InverseRot.Yaw) - LastRot) < YawTolerance)
160 LastRot = FRotator::ClampAxis(InverseRot.Yaw);
161 LastLerpVal = LastRot;
162 LerpTarget = LastRot;
166 if (bLerpTransition && !FMath::IsNearlyEqual(LastLerpVal, LerpTarget))
168 LastLerpVal = FMath::FixedTurn(LastLerpVal, LerpTarget, LerpSpeed * DeltaTime);
169 FinalRot = FRotator(0, LastLerpVal, 0);
173 FinalRot = FRotator(0, LastRot, 0);
174 LastLerpVal = LastRot;
180 if (!FMath::IsNearlyZero(YawTolerance))
182 LerpTarget = FRotator::ClampAxis(InverseRot.Yaw);
183 LastLerpVal = FMath::FixedTurn(LastLerpVal, LerpTarget, LerpSpeed * DeltaTime);
184 FinalRot = FRotator(0, LastLerpVal, 0);
188 FinalRot = FRotator(0, FRotator::ClampAxis(InverseRot.Yaw), 0);
191 LastRot = FRotator::ClampAxis(InverseRot.Yaw);
194 return FinalRot.Quaternion();
199 void RunSampling(FRotator &HMDRotation, FVector &HMDLocation)
223 void GetEstShoulderRotation(FRotator &InputHMDRotation, FVector &InputHMDLocation)
225 float WorldToMeters = GetWorld() ? GetWorld()->GetWorldSettings()->WorldToMeters : 100.0f;
228 FTransform shoulder = FTransform::Identity;
229 FVector headNeckDirectionVector = FVector(-.05f, 0.f, -1.f);
230 FVector neckShoulderDistance = FVector(-0.02f, 0.f, -.15f) * WorldToMeters;
231 float headNeckDistance = 0.03f * WorldToMeters;
233 FVector headNeckOffset = InputHMDRotation.RotateVector(headNeckDirectionVector);
234 FVector targetPosition = InputHMDLocation + headNeckOffset * headNeckDistance;
235 shoulder.SetLocation(targetPosition + InputHMDRotation.RotateVector(neckShoulderDistance));
303 void DetectHandsBehindHead(
float& TargetRot, FRotator HMDRotation)
339 void ClampHeadRotationDelta(
float& TargetRotation, FRotator HMDRotation)