A Demo Project for the UnrealEngineSDK
Loading...
Searching...
No Matches
GS_Default.cpp
Go to the documentation of this file.
1// Fill out your copyright notice in the Description page of Project Settings.
2
4#include "VRGripInterface.h"
6
7UGS_Default::UGS_Default(const FObjectInitializer& ObjectInitializer) :
8 Super(ObjectInitializer)
9{
10 bIsActive = true;
12}
13
14void UGS_Default::GetAnyScaling(FVector& Scaler, FBPActorGripInformation& Grip, FVector& frontLoc, FVector& frontLocOrig, ESecondaryGripType SecondaryType, FTransform& SecondaryTransform)
15{
17 {
18 //float Scaler = 1.0f;
20 {
21 /*Grip.SecondaryScaler*/ Scaler = FVector(frontLoc.Size() / frontLocOrig.Size());
22 //bRescalePhysicsGrips = true; // This is for the physics grips
23 }
24 }
25}
26
27void UGS_Default::ApplySmoothingAndLerp(FBPActorGripInformation& Grip, FVector& frontLoc, FVector& frontLocOrig, float DeltaTime)
28{
29 if (Grip.SecondaryGripInfo.GripLerpState == EGripLerpState::StartLerp) // Lerp into the new grip to smooth the transition
30 {
31 /*if (Grip.AdvancedGripSettings.SecondaryGripSettings.SecondaryGripScaler_DEPRECATED < 1.0f)
32 {
33 FVector SmoothedValue = Grip.AdvancedGripSettings.SecondaryGripSettings.SecondarySmoothing.RunFilterSmoothing(frontLoc, DeltaTime);
34
35 frontLoc = FMath::Lerp(SmoothedValue, frontLoc, Grip.AdvancedGripSettings.SecondaryGripSettings.SecondaryGripScaler_DEPRECATED);
36 }*/
37
38 frontLocOrig = FMath::Lerp(frontLocOrig, frontLoc, FMath::Clamp(Grip.SecondaryGripInfo.curLerp / Grip.SecondaryGripInfo.LerpToRate, 0.0f, 1.0f));
39 }
40 /*else if (Grip.SecondaryGripInfo.GripLerpState == EGripLerpState::ConstantLerp_DEPRECATED) // If there is a frame by frame lerp
41 {
42 FVector SmoothedValue = Grip.AdvancedGripSettings.SecondaryGripSettings.SecondarySmoothing.RunFilterSmoothing(frontLoc, DeltaTime);
43
44 frontLoc = FMath::Lerp(SmoothedValue, frontLoc, Grip.AdvancedGripSettings.SecondaryGripSettings.SecondaryGripScaler_DEPRECATED);
45 }*/
46}
47
49(
50 UGripMotionControllerComponent* GrippingController,
51 float DeltaTime, FTransform& WorldTransform,
52 const FTransform& ParentTransform,
54 AActor* actor,
55 UPrimitiveComponent* root,
56 bool bRootHasInterface,
57 bool bActorHasInterface,
58 bool bIsForTeleport
59)
60{
61 if (!GrippingController)
62 return false;
63
64 // Just simple transform setting
65 WorldTransform = Grip.RelativeTransform * Grip.AdditionTransform * ParentTransform;
66
67 // Check the grip lerp state, this it ouside of the secondary attach check below because it can change the result of it
69 {
71 {
74 {
75 if (Grip.SecondaryGripInfo.curLerp > 0.01f)
76 Grip.SecondaryGripInfo.curLerp -= DeltaTime;
77 else
78 {
79 /*if (Grip.SecondaryGripInfo.bHasSecondaryAttachment &&
80 Grip.AdvancedGripSettings.SecondaryGripSettings.bUseSecondaryGripSettings &&
81 Grip.AdvancedGripSettings.SecondaryGripSettings.SecondaryGripScaler_DEPRECATED < 1.0f)
82 {
83 Grip.SecondaryGripInfo.GripLerpState = EGripLerpState::ConstantLerp_DEPRECATED;
84 }
85 else*/
87 }
88
89 }break;
90 //case EGripLerpState::ConstantLerp_DEPRECATED:
92 default:break;
93 }
94 }
95
96 // Handle the interp and multi grip situations, re-checking the grip situation here as it may have changed in the switch above.
98 {
99 FTransform SecondaryTransform = Grip.RelativeTransform * ParentTransform;
100
101 // Checking secondary grip type for the scaling setting
103
104 if (bRootHasInterface)
105 SecondaryType = IVRGripInterface::Execute_SecondaryGripType(root);
106 else if (bActorHasInterface)
107 SecondaryType = IVRGripInterface::Execute_SecondaryGripType(actor);
108
109 // If the grip is a custom one, skip all of this logic we won't be changing anything
110 if (SecondaryType != ESecondaryGripType::SG_Custom)
111 {
112 // Variables needed for multi grip transform
113 FVector BasePoint = ParentTransform.GetLocation(); // Get our pivot point
114 const FTransform PivotToWorld = FTransform(FQuat::Identity, BasePoint);
115 const FTransform WorldToPivot = FTransform(FQuat::Identity, -BasePoint);
116
117 FVector frontLocOrig;
118 FVector frontLoc;
119
120 // Ending lerp out of a multi grip
122 {
123 frontLocOrig = (/*WorldTransform*/SecondaryTransform.TransformPosition(Grip.SecondaryGripInfo.SecondaryRelativeTransform.GetLocation())) - BasePoint;
125
126 frontLocOrig = FMath::Lerp(frontLoc, frontLocOrig, FMath::Clamp(Grip.SecondaryGripInfo.curLerp / Grip.SecondaryGripInfo.LerpToRate, 0.0f, 1.0f));
127 }
128 else // Is in a multi grip, might be lerping into it as well.
129 {
130 //FVector curLocation; // Current location of the secondary grip
131
132 // Calculates the correct secondary attachment location and sets frontLoc to it
133 CalculateSecondaryLocation(frontLoc, BasePoint, Grip, GrippingController);
134
135 frontLocOrig = (/*WorldTransform*/SecondaryTransform.TransformPosition(Grip.SecondaryGripInfo.SecondaryRelativeTransform.GetLocation())) - BasePoint;
136
137 // Apply any smoothing settings and lerping in / constant lerping
138 ApplySmoothingAndLerp(Grip, frontLoc, frontLocOrig, DeltaTime);
139
141 }
142
143 // Get any scaling addition from a scaling secondary grip type
144 FVector Scaler = FVector(1.0f);
146 {
147 GetAnyScaling(Scaler, Grip, frontLoc, frontLocOrig, SecondaryType, SecondaryTransform);
148 }
149
150 Grip.SecondaryGripInfo.SecondaryGripDistance = FVector::Dist(frontLocOrig, frontLoc);
151
152 /*if (Grip.AdvancedGripSettings.SecondaryGripSettings.bUseSecondaryGripSettings && Grip.AdvancedGripSettings.SecondaryGripSettings.bUseSecondaryGripDistanceInfluence_DEPRECATED)
153 {
154 float rotScaler = 1.0f - FMath::Clamp((Grip.SecondaryGripInfo.SecondaryGripDistance - Grip.AdvancedGripSettings.SecondaryGripSettings.GripInfluenceDeadZone_DEPRECATED) / FMath::Max(Grip.AdvancedGripSettings.SecondaryGripSettings.GripInfluenceDistanceToZero_DEPRECATED, 1.0f), 0.0f, 1.0f);
155 frontLoc = FMath::Lerp(frontLocOrig, frontLoc, rotScaler);
156 }*/
157
158 // Skip rot val for scaling only
159 if (SecondaryType != ESecondaryGripType::SG_ScalingOnly)
160 {
161 // Get the rotation difference from the initial second grip
162 FQuat rotVal = FQuat::FindBetweenVectors(frontLocOrig, frontLoc);
163
164 // Rebase the world transform to the pivot point, add the rotation, remove the pivot point rebase
165 WorldTransform = WorldTransform * WorldToPivot * FTransform(rotVal, FVector::ZeroVector, Scaler) * PivotToWorld;
166 }
167 else
168 {
169 // Rebase the world transform to the pivot point, add the scaler, remove the pivot point rebase
170 WorldTransform = WorldTransform * WorldToPivot * FTransform(FQuat::Identity, FVector::ZeroVector, Scaler) * PivotToWorld;
171 }
172 }
173 }
174 return true;
175}
176
177void UGS_Default::CalculateSecondaryLocation(FVector& frontLoc, const FVector& BasePoint, FBPActorGripInformation& Grip, UGripMotionControllerComponent* GrippingController)
178{
179 bool bPulledControllerLoc = false;
180 if (UGripMotionControllerComponent* OtherController = Cast<UGripMotionControllerComponent>(Grip.SecondaryGripInfo.SecondaryAttachment))
181 {
182 bool bPulledCurrentTransform = false;
183
184 if (OtherController->CustomPivotComponent.IsValid())
185 {
186 FTransform SecondaryTrans = FTransform::Identity;
187 SecondaryTrans = OtherController->GetPivotTransform();
188 bPulledControllerLoc = true;
189 frontLoc = SecondaryTrans.GetLocation() - BasePoint;
190 }
191 }
192
193 if (!bPulledControllerLoc)
194 {
195 frontLoc = Grip.SecondaryGripInfo.SecondaryAttachment->GetComponentLocation() - BasePoint;
196 }
197}
198
199void UGS_ExtendedDefault::GetAnyScaling(FVector& Scaler, FBPActorGripInformation& Grip, FVector& frontLoc, FVector& frontLocOrig, ESecondaryGripType SecondaryType, FTransform& SecondaryTransform)
200{
202 {
203
204 //float Scaler = 1.0f;
206 {
207 /*Grip.SecondaryScaler*/ Scaler = FVector(frontLoc.Size() / frontLocOrig.Size());
208 //bRescalePhysicsGrips = true; // This is for the physics grips
209
211 {
212 // Get the total scale after modification
213 // #TODO: convert back to singular float version? Can get Min() & Max() to convert the float to a range...think about it
214 FVector WorldScale = /*WorldTransform*/SecondaryTransform.GetScale3D();
215 FVector CombinedScale = WorldScale * Scaler;
216
217 // Clamp to the minimum and maximum values
218 CombinedScale.X = FMath::Clamp(CombinedScale.X, MinimumGripScaling.X, MaximumGripScaling.X);
219 CombinedScale.Y = FMath::Clamp(CombinedScale.Y, MinimumGripScaling.Y, MaximumGripScaling.Y);
220 CombinedScale.Z = FMath::Clamp(CombinedScale.Z, MinimumGripScaling.Z, MaximumGripScaling.Z);
221
222 // Recreate in scaler form so that the transform chain below works as normal
223 Scaler = CombinedScale / WorldScale;
224 }
225 //Scaler = Grip.SecondaryScaler;
226 }
227 }
228}
ESecondaryGripType
UENUM(Blueprintable)
UGS_Default(const FObjectInitializer &ObjectInitializer)
Definition GS_Default.cpp:7
virtual void GetAnyScaling(FVector &Scaler, FBPActorGripInformation &Grip, FVector &frontLoc, FVector &frontLocOrig, ESecondaryGripType SecondaryType, FTransform &SecondaryTransform)
virtual void ApplySmoothingAndLerp(FBPActorGripInformation &Grip, FVector &frontLoc, FVector &frontLocOrig, float DeltaTime)
virtual void CalculateSecondaryLocation(FVector &frontLoc, const FVector &BasePoint, FBPActorGripInformation &Grip, UGripMotionControllerComponent *GrippingController)
virtual bool GetWorldTransform_Implementation(UGripMotionControllerComponent *GrippingController, float DeltaTime, FTransform &WorldTransform, const FTransform &ParentTransform, FBPActorGripInformation &Grip, AActor *actor, UPrimitiveComponent *root, bool bRootHasInterface, bool bActorHasInterface, bool bIsForTeleport) override
FVector_NetQuantize100 MaximumGripScaling
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "SecondaryGripSettings", meta = (editcondition...
Definition GS_Default.h:64
bool bLimitGripScaling
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "SecondaryGripSettings")
Definition GS_Default.h:48
virtual void GetAnyScaling(FVector &Scaler, FBPActorGripInformation &Grip, FVector &frontLoc, FVector &frontLocOrig, ESecondaryGripType SecondaryType, FTransform &SecondaryTransform) override
FVector_NetQuantize100 MinimumGripScaling
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "SecondaryGripSettings", meta = (editcondition...
Definition GS_Default.h:56
UCLASS(Blueprintable, meta = (BlueprintSpawnableComponent), ClassGroup = MotionController)
EGSTransformOverrideType WorldTransformOverrideType
UPROPERTY(BlueprintReadWrite, EditDefaultsOnly, Category = "GSSettings")
bool bIsActive
UPROPERTY(BlueprintReadWrite, EditDefaultsOnly, Category = "GSSettings")
USTRUCT(BlueprintType, Category = "VRExpansionLibrary")
FTransform AdditionTransform
UPROPERTY(BlueprintReadWrite, NotReplicated, Category = "Settings")
FTransform_NetQuantize RelativeTransform
UPROPERTY(BlueprintReadWrite, Category = "Settings")
FBPSecondaryGripInfo SecondaryGripInfo
UPROPERTY(BlueprintReadOnly, Category = "Settings")
USceneComponent * SecondaryAttachment
UPROPERTY(BlueprintReadOnly, Category = "SecondaryGripInfo")
EGripLerpState GripLerpState
float LerpToRate
UPROPERTY()
float SecondaryGripDistance
UPROPERTY(BlueprintReadOnly, NotReplicated, Category = "SecondaryGripInfo")
bool bHasSecondaryAttachment
UPROPERTY(BlueprintReadOnly, Category = "SecondaryGripInfo")
FTransform_NetQuantize SecondaryRelativeTransform
UPROPERTY(BlueprintReadOnly, Category = "SecondaryGripInfo")