7#include "IXRTrackingSystem.h"
10#include "DrawDebugHelpers.h"
13 Super(ObjectInitializer)
54 FName CurrentCompName = NAME_None;
57 CurrentCompName = ChildComp->GetFName();
58 if (CurrentCompName == NAME_None)
97 KinPose.SetLocation(KinPose.TransformPosition(
PivotOffset));
109 float DeltaTime, FTransform & WorldTransform,
110 const FTransform &ParentTransform,
113 UPrimitiveComponent * root,
114 bool bRootHasInterface,
115 bool bActorHasInterface,
119 if (!GrippingController)
149 FVector Pivot = relTransform.GetLocation() +
PivotOffset;
150 const FTransform PivotToWorld = FTransform(FQuat::Identity, Pivot);
151 const FTransform WorldToPivot = FTransform(FQuat::Identity, -Pivot);
168 else if (GrippingController->
bHasAuthority && GEngine->XRSystem.IsValid() && GEngine->XRSystem->IsHeadTrackingAllowedForWorld(*
GetWorld()))
170 FQuat curRot = FQuat::Identity;
171 FVector curLoc = FVector::ZeroVector;
173 if (GEngine->XRSystem->GetCurrentPose(IXRTrackingSystem::HMDDeviceId, curRot, curLoc))
187 float DistSquared = FVector::DistSquared(ParentTransform.GetTranslation(),
MountWorldTransform.GetTranslation());
189 if (DistSquared <= StockSnapDistance)
194 if (StockSnapLerpThresh > 0.0f)
213 if (WorldTransVec.Z >= ParentTransform.GetTranslation().Z)
215 WorldTransVec.Z = ParentTransform.GetTranslation().Z;
220#if !(UE_BUILD_SHIPPING || UE_BUILD_TEST)
275 FTransform NewWorldTransform = WorldTransform;
281 if (bRootHasInterface)
282 SecondaryType = IVRGripInterface::Execute_SecondaryGripType(root);
283 else if (bActorHasInterface)
284 SecondaryType = IVRGripInterface::Execute_SecondaryGripType(actor);
290 FVector BasePoint = ParentTransform.GetLocation();
291 FVector Pivot = ParentTransform.GetLocation();
297 Pivot = SecondaryTransform.TransformPositionNoScale(SecondaryTransform.InverseTransformPositionNoScale(Pivot) + (
StoredRootOffset * PhysHandle->RootBoneRotation.GetRotation()).RotateVector(
PivotOffset));
306#if !(UE_BUILD_SHIPPING || UE_BUILD_TEST)
307 static const auto CVarDrawCOMDebugSpheresAccess = IConsoleManager::Get().FindConsoleVariable(TEXT(
"vr.DrawDebugCenterOfMassForGrips"));
308 if (CVarDrawCOMDebugSpheresAccess->GetInt() > 0)
310 DrawDebugSphere(
GetWorld(), Pivot, 5, 32, FColor::Orange,
false);
314 const FTransform PivotToWorld = FTransform(FQuat::Identity, Pivot);
315 const FTransform WorldToPivot = FTransform(FQuat::Identity, -Pivot);
317 FVector frontLocOrig;
342 FVector Scaler = FVector(1.0f);
343 GetAnyScaling(Scaler, Grip, frontLoc, frontLocOrig, SecondaryType, SecondaryTransform);
350 frontLoc = FMath::Lerp(frontLocOrig, frontLoc, rotScaler);
366 FTransform NA = FTransform(rotVal * MountAdditionRotation, FVector::ZeroVector, Scaler);
367 FTransform NB = FTransform(FQuat::FindBetweenVectors(frontLocOrig, frontLoc), FVector::ZeroVector, Scaler);
368 NA.NormalizeRotation();
369 NB.NormalizeRotation();
374 NewWorldTransform = WorldTransform * WorldToPivot * NA * PivotToWorld;
379 NewWorldTransform = WorldTransform * WorldToPivot * MountAdditionRotation * FTransform(rotVal, FVector::ZeroVector, Scaler) * PivotToWorld;
385 FQuat rotVal = FQuat::FindBetweenVectors(frontLocOrig, frontLoc);
388 NewWorldTransform = WorldTransform * WorldToPivot * FTransform(rotVal, FVector::ZeroVector, Scaler) * PivotToWorld;
402 FTransform NA = FTransform(MountAdditionRotation, FVector::ZeroVector, Scaler);
403 FTransform NB = FTransform(FQuat::Identity, FVector::ZeroVector, Scaler);
404 NA.NormalizeRotation();
405 NB.NormalizeRotation();
409 NewWorldTransform = WorldTransform * WorldToPivot * NA * PivotToWorld;
414 NewWorldTransform = WorldTransform * WorldToPivot * MountAdditionRotation * FTransform(FQuat::Identity, FVector::ZeroVector, Scaler) * PivotToWorld;
420 NewWorldTransform = WorldTransform * WorldToPivot * FTransform(FQuat::Identity, FVector::ZeroVector, Scaler) * PivotToWorld;
431 WorldTransform = NewWorldTransform;
436 if (GrippingController->GetAttachParent())
438 FTransform ParentTrans = GrippingController->GetAttachParent()->GetComponentTransform();
439 FTransform ParentRel = WorldTransform * ParentTrans.Inverse();
441 WorldTransform = ParentRel * ParentTrans;
495 if (
AVRBaseCharacter * vrOwner = Cast<AVRBaseCharacter>(GrippingController->GetOwner()))
502 TArray<USceneComponent*> children = GrippingController->GetOwner()->GetRootComponent()->GetAttachChildren();
504 for (
int i = 0; i < children.Num(); i++)
506 if (children[i]->IsA(UCameraComponent::StaticClass()))
555 BodyInst->AddImpulseAtPosition(RecoilAddition.GetLocation(), Optional_Location);
ESecondaryGripType
UENUM(Blueprintable)
@ OverridesWorldTransform
virtual void GetAnyScaling(FVector &Scaler, FBPActorGripInformation &Grip, FVector &frontLoc, FVector &frontLocOrig, ESecondaryGripType SecondaryType, FTransform &SecondaryTransform)
virtual void CalculateSecondaryLocation(FVector &frontLoc, const FVector &BasePoint, FBPActorGripInformation &Grip, UGripMotionControllerComponent *GrippingController)
UCLASS(Blueprintable, meta = (BlueprintSpawnableComponent), ClassGroup = MotionController)
FORCEINLINE FVector GetPivotLocation()
bool IsLocallyControlled() const
FBPActorPhysicsHandleInformation * GetPhysicsGrip(const FBPActorGripInformation &GripInfo)
FORCEINLINE FTransform GetPivotTransform()
static FRotator GetHMDPureYaw_I(FRotator HMDRotation)
UCLASS(config = Engine, defaultconfig)
float OneEuroMinCutoff
UPROPERTY(config, EditAnywhere, Category = "GunSettings|Secondary Grip 1Euro Settings")
float OneEuroDeltaCutoff
UPROPERTY(config, EditAnywhere, Category = "GunSettings|Secondary Grip 1Euro Settings")
static void GetVirtualStockGlobalSettings(FBPVirtualStockSettings &OutVirtualStockSettings)
UFUNCTION(BlueprintCallable, Category = "GunSettings|VirtualStock")
float OneEuroCutoffSlope
UPROPERTY(config, EditAnywhere, Category = "GunSettings|Secondary Grip 1Euro Settings")
FBodyInstance * GetParentBodyInstance(FName OptionalBoneName=NAME_None)
virtual UWorld * GetWorld() const override
bool bInjectPrePhysicsHandle
UPROPERTY(BlueprintReadWrite, EditDefaultsOnly, Category = "GSSettings")
EGSTransformOverrideType WorldTransformOverrideType
UPROPERTY(BlueprintReadWrite, EditDefaultsOnly, Category = "GSSettings")
bool bIsActive
UPROPERTY(BlueprintReadWrite, EditDefaultsOnly, Category = "GSSettings")
AActor * GetOwner()
UFUNCTION(BlueprintPure, Category = "VRGripScript")
float DeltaCutoff
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "FilterSettings")
void ResetSmoothingFilter()
float MinCutoff
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "FilterSettings")
float CutoffSlope
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "FilterSettings")
void ResetSmoothingFilter()
FTransform RunFilterSmoothing(const FTransform &InRawValue, const float &InDeltaTime)
USceneComponent * SecondaryAttachment
UPROPERTY(BlueprintReadOnly, Category = "SecondaryGripInfo")
EGripLerpState GripLerpState
float LerpToRate
UPROPERTY()
float SecondaryGripDistance
UPROPERTY(BlueprintReadOnly, NotReplicated, Category = "SecondaryGripInfo")
FVector LastRelativeLocation
bool bHasSecondaryAttachment
UPROPERTY(BlueprintReadOnly, Category = "SecondaryGripInfo")
FTransform_NetQuantize SecondaryRelativeTransform
UPROPERTY(BlueprintReadOnly, Category = "SecondaryGripInfo")
USTRUCT(BlueprintType, Category = "GunSettings")
bool bSmoothStockHand
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VirtualStock|Smoothing")
void CopyFrom(FBPVirtualStockSettings &B)
FVector_NetQuantize100 StockSnapOffset
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VirtualStock")
float StockSnapLerpThreshold
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VirtualStock", meta = (ClampMin = "0....
float StockSnapDistance
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VirtualStock")
float StockLerpValue
UPROPERTY(BlueprintReadOnly, Category = "VirtualStock")
bool bAdjustZOfStockToPrimaryHand
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VirtualStock")
FBPEuroLowPassFilterTrans StockHandSmoothing
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "GunSettings|VirtualStock|Smoothing")
float SmoothingValueForStock
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VirtualStock|Smoothing", meta = (editconditio...
bool bDebugDrawVirtualStock
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "GunSettings|VirtualStock|Debug")