4#include "CoreMinimal.h"
7#include "UObject/ObjectMacros.h"
8#include "Engine/EngineTypes.h"
9#include "UObject/ScriptInterface.h"
10#include "Kismet/BlueprintFunctionLibrary.h"
11#include "GameplayTagContainer.h"
13#include "VRInteractibleFunctionLibrary.generated.h"
31USTRUCT(BlueprintType, Category =
"VRExpansionLibrary")
38 UPROPERTY(BlueprintReadOnly, VisibleAnywhere, Category =
"InteractibleData")
39 FTransform InitialRelativeTransform;
42 UPROPERTY(BlueprintReadOnly, VisibleAnywhere, Category = "InteractibleData")
43 FVector InitialInteractorLocation;
46 UPROPERTY(BlueprintReadOnly, VisibleAnywhere, Category = "InteractibleData")
47 FVector InitialGripLoc;
50 UPROPERTY(BlueprintReadOnly, VisibleAnywhere, Category = "InteractibleData")
51 FVector InitialDropLocation;
54 UPROPERTY(BlueprintReadOnly, VisibleAnywhere, Category = "InteractibleData")
55 FTransform ReversedRelativeTransform;
59 InitialInteractorLocation = FVector::ZeroVector;
60 InitialGripLoc = FVector::ZeroVector;
61 InitialDropLocation = FVector::ZeroVector;
71 static float GetAtan2Angle(
EVRInteractibleAxis AxisToCalc, FVector CurInteractorLocation,
float OptionalInitialRotation = 0.0f)
77 return FMath::RadiansToDegrees(FMath::Atan2(CurInteractorLocation.Y, CurInteractorLocation.Z)) - OptionalInitialRotation;
81 return FMath::RadiansToDegrees(FMath::Atan2(CurInteractorLocation.Z, CurInteractorLocation.X)) - OptionalInitialRotation;
85 return FMath::RadiansToDegrees(FMath::Atan2(CurInteractorLocation.Y, CurInteractorLocation.X)) - OptionalInitialRotation;
94 static float GetDeltaAngleFromTransforms(
EVRInteractibleAxis RotAxis, FTransform & InitialRelativeTransform, FTransform &CurrentRelativeTransform)
96 return GetDeltaAngle(RotAxis, (CurrentRelativeTransform.GetRelativeTransform(InitialRelativeTransform).GetRotation()).GetNormalized());
103 DeltaQuat.ToAxisAndAngle(Axis, Angle);
106 return FRotator::NormalizeAxis(FMath::RadiansToDegrees(Angle)) * (FMath::Sign(GetAxisValue(RotAxis, Axis)));
108 return FRotator::NormalizeAxis(FMath::RadiansToDegrees(Angle)) * (-FMath::Sign(GetAxisValue(RotAxis, Axis)));
116 return CheckRotation.Roll;
break;
118 return CheckRotation.Pitch;
break;
120 return CheckRotation.Yaw;
break;
121 default:
return 0.0f;
break;
130 return CheckAxis.X;
break;
132 return CheckAxis.Y;
break;
134 return CheckAxis.Z;
break;
135 default:
return 0.0f;
break;
141 FVector vec = FVector::ZeroVector;
146 vec.X = SetValue;
break;
148 vec.Y = SetValue;
break;
150 vec.Z = SetValue;
break;
159 FRotator vec = FRotator::ZeroRotator;
164 vec.Roll = SetValue;
break;
166 vec.Pitch = SetValue;
break;
168 vec.Yaw = SetValue;
break;
181 vec.Roll = SetValue;
break;
183 vec.Pitch = SetValue;
break;
185 vec.Yaw = SetValue;
break;
193 UFUNCTION(BlueprintPure, Category =
"VRInteractibleFunctions", meta = (bIgnoreSelf =
"true"))
194 static FTransform Interactible_GetCurrentParentTransform(
USceneComponent * SceneComponentToCheck)
196 if (SceneComponentToCheck)
198 if (
USceneComponent * AttachParent = SceneComponentToCheck->GetAttachParent())
200 return AttachParent->GetComponentTransform();
204 return FTransform::Identity;
208 UFUNCTION(BlueprintPure, Category =
"VRInteractibleFunctions", meta = (bIgnoreSelf =
"true"))
211 FTransform ParentTransform = FTransform::Identity;
212 if (SceneComponentToCheck)
214 if (
USceneComponent * AttachParent = SceneComponentToCheck->GetAttachParent())
217 ParentTransform = AttachParent->GetComponentTransform();
221 return BaseData.InitialRelativeTransform * ParentTransform;
225 UFUNCTION(BlueprintCallable, Category =
"VRInteractibleFunctions", meta = (bIgnoreSelf =
"true"))
228 if (!InteractibleComp)
231 BaseDataToInit.InitialRelativeTransform = InteractibleComp->GetRelativeTransform();
235 UFUNCTION(BlueprintCallable, Category =
"VRInteractibleFunctions", meta = (bIgnoreSelf =
"true"))
238 if (!InteractibleComp)
241 BaseDataToInit.ReversedRelativeTransform = FTransform(GripInformation.RelativeTransform.ToInverseMatrixWithScale());
242 BaseDataToInit.InitialDropLocation = BaseDataToInit.ReversedRelativeTransform.GetTranslation();
244 FTransform RelativeToGripTransform = BaseDataToInit.ReversedRelativeTransform * InteractibleComp->GetComponentTransform();
246 BaseDataToInit.InitialInteractorLocation = CurrentRelativeTransform.InverseTransformPosition(RelativeToGripTransform.GetTranslation());
248 BaseDataToInit.InitialGripLoc = BaseDataToInit.InitialRelativeTransform.InverseTransformPosition(InteractibleComp->GetRelativeLocation());
253 UFUNCTION(BlueprintPure, Category =
"VRInteractibleFunctions", meta = (bIgnoreSelf =
"true"))
254 static
float Interactible_GetAngleAroundAxis(
EVRInteractibleAxis AxisToCalc, FVector CurInteractorLocation)
256 float ReturnAxis = 0.0f;
262 ReturnAxis = FMath::RadiansToDegrees(FMath::Atan2(CurInteractorLocation.Y, CurInteractorLocation.Z));
266 ReturnAxis = FMath::RadiansToDegrees(FMath::Atan2(CurInteractorLocation.Z, CurInteractorLocation.X));
270 ReturnAxis = FMath::RadiansToDegrees(FMath::Atan2(CurInteractorLocation.Y, CurInteractorLocation.X));
282 UFUNCTION(BlueprintPure, Category =
"VRInteractibleFunctions", meta = (bIgnoreSelf =
"true"))
283 static
float Interactible_GetAngleAroundAxisDelta(
EVRInteractibleAxis AxisToCalc, FVector CurInteractorLocation,
float InitialAngle)
285 return FRotator::NormalizeAxis(Interactible_GetAngleAroundAxis(AxisToCalc, CurInteractorLocation) - InitialAngle);
290 UFUNCTION(BlueprintPure, Category =
"VRInteractibleFunctions", meta = (bIgnoreSelf =
"true"))
291 static
float Interactible_GetThresholdSnappedValue(
float ValueToSnap,
float SnapIncrement,
float SnapThreshold)
293 if (SnapIncrement > 0.f && FMath::Fmod(ValueToSnap, SnapIncrement) <= FMath::Min(SnapIncrement, SnapThreshold))
295 return FMath::GridSnap(ValueToSnap, SnapIncrement);
DECLARE_LOG_CATEGORY_EXTERN(VRInteractibleFunctionLibraryLog, Log, All)
EVRInteractibleAxis
UENUM(Blueprintable)
static void Interactible_BeginPlayInit(USceneComponent *InteractibleComp, UPARAM(ref) FBPVRInteractibleBaseData &BaseDataToInit)
UFUNCTION(BlueprintCallable, Category = "VRInteractibleFunctions", meta = (bIgnoreSelf = "true"))
static float GetDeltaAngleFromTransforms(EVRInteractibleAxis RotAxis, FTransform &InitialRelativeTransform, FTransform &CurrentRelativeTransform)
static FRotator SetAxisValueRot(EVRInteractibleAxis RotAxis, float SetValue, FRotator Var)
static float GetAxisValue(EVRInteractibleAxis RotAxis, FRotator CheckRotation)
static float GetDeltaAngle(EVRInteractibleAxis RotAxis, FQuat DeltaQuat)
static void Interactible_OnGripInit(USceneComponent *InteractibleComp, UPARAM(ref) FBPActorGripInformation &GripInformation, UPARAM(ref) FBPVRInteractibleBaseData &BaseDataToInit)
UFUNCTION(BlueprintCallable, Category = "VRInteractibleFunctions", meta = (bIgnoreSelf = "true"))
static FRotator SetAxisValueRot(EVRInteractibleAxis RotAxis, float SetValue)
static float Interactible_GetAngleAroundAxis(EVRInteractibleAxis AxisToCalc, FVector CurInteractorLocation)
UFUNCTION(BlueprintPure, Category = "VRInteractibleFunctions", meta = (bIgnoreSelf = "true"))
static float GetAxisValue(EVRInteractibleAxis RotAxis, FVector CheckAxis)
static float GetAtan2Angle(EVRInteractibleAxis AxisToCalc, FVector CurInteractorLocation, float OptionalInitialRotation=0.0f)
static float Interactible_GetAngleAroundAxisDelta(EVRInteractibleAxis AxisToCalc, FVector CurInteractorLocation, float InitialAngle)
UFUNCTION(BlueprintPure, Category = "VRInteractibleFunctions", meta = (bIgnoreSelf = "true"))
static float Interactible_GetThresholdSnappedValue(float ValueToSnap, float SnapIncrement, float SnapThreshold)
UFUNCTION(BlueprintPure, Category = "VRInteractibleFunctions", meta = (bIgnoreSelf = "true"))
static FTransform Interactible_GetCurrentRelativeTransform(USceneComponent *SceneComponentToCheck, UPARAM(ref) FBPVRInteractibleBaseData &BaseData)
UFUNCTION(BlueprintPure, Category = "VRInteractibleFunctions", meta = (bIgnoreSelf = "true"))
static FVector SetAxisValueVec(EVRInteractibleAxis RotAxis, float SetValue)
static FTransform Interactible_GetCurrentParentTransform(USceneComponent *SceneComponentToCheck)
UFUNCTION(BlueprintPure, Category = "VRInteractibleFunctions", meta = (bIgnoreSelf = "true"))
USTRUCT(BlueprintType, Category = "VRExpansionLibrary")
FVector InitialGripLoc
UPROPERTY(BlueprintReadOnly, VisibleAnywhere, Category = "InteractibleData")
FTransform InitialRelativeTransform
UPROPERTY(BlueprintReadOnly, VisibleAnywhere, Category = "InteractibleData")
FVector InitialDropLocation
UPROPERTY(BlueprintReadOnly, VisibleAnywhere, Category = "InteractibleData")
FVector InitialInteractorLocation
UPROPERTY(BlueprintReadOnly, VisibleAnywhere, Category = "InteractibleData")
FBPVRInteractibleBaseData()
FTransform ReversedRelativeTransform
UPROPERTY(BlueprintReadOnly, VisibleAnywhere, Category = "InteractibleData")