A Demo Project for the UnrealEngineSDK
Loading...
Searching...
No Matches
VRTrackedParentInterface.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 "UObject/ObjectMacros.h"
7#include "UObject/ScriptMacros.h"
8#include "UObject/Interface.h"
9
10#include "VRTrackedParentInterface.generated.h"
11
12
13UINTERFACE(MinimalAPI, meta = (CannotImplementInterfaceInBlueprint))
15{
17};
18
20class VREXPANSIONPLUGIN_API IVRTrackedParentInterface
21{
22 GENERATED_IINTERFACE_BODY()
24public:
26 // Set a tracked parent
27 UFUNCTION(BlueprintCallable, Category = "VRTrackedParentInterface")
28 virtual void SetTrackedParent(UPrimitiveComponent * NewParentComponent, float WaistRadius, EBPVRWaistTrackingMode WaistTrackingMode)
29 {}
30
31 static void Default_SetTrackedParent_Impl(UPrimitiveComponent * NewParentComponent, float WaistRadius, EBPVRWaistTrackingMode WaistTrackingMode, FBPVRWaistTracking_Info & OptionalWaistTrackingParent, USceneComponent * Self)
32 {
33 // If had a different original tracked parent
34 // Moved this to first thing so the pre-res is removed prior to erroring out and clearing this
35 if (OptionalWaistTrackingParent.IsValid())
36 {
37 // Remove the tick Prerequisite
38 Self->RemoveTickPrerequisiteComponent(OptionalWaistTrackingParent.TrackedDevice);
39 }
40
41 if (!NewParentComponent || !Self)
42 {
43 OptionalWaistTrackingParent.Clear();
44 return;
45 }
46
47 // Make other component tick first if possible, waste of time if in wrong tick group
48 if (NewParentComponent->PrimaryComponentTick.TickGroup == Self->PrimaryComponentTick.TickGroup)
49 {
50 // Make sure the other component isn't depending on this one
51 NewParentComponent->RemoveTickPrerequisiteComponent(Self);
52
53 // Add a tick pre-res for ourselves so that we tick after our tracked parent.
54 Self->AddTickPrerequisiteComponent(NewParentComponent);
55 }
56
57 OptionalWaistTrackingParent.TrackedDevice = NewParentComponent;
58 OptionalWaistTrackingParent.RestingRotation = NewParentComponent->GetRelativeRotation();
59 OptionalWaistTrackingParent.RestingRotation.Yaw = 0.0f;
60
61 OptionalWaistTrackingParent.TrackingMode = WaistTrackingMode;
62 OptionalWaistTrackingParent.WaistRadius = WaistRadius;
63 }
64
65 // Returns local transform of the parent relative attachment
66 static FTransform Default_GetWaistOrientationAndPosition(FBPVRWaistTracking_Info & WaistTrackingInfo)
67 {
68 if (!WaistTrackingInfo.IsValid())
69 return FTransform::Identity;
70
71 FTransform DeviceTransform = WaistTrackingInfo.TrackedDevice->GetRelativeTransform();
73 // Rewind by the initial rotation when the new parent was set, this should be where the tracker rests on the person
74 DeviceTransform.ConcatenateRotation(WaistTrackingInfo.RestingRotation.Quaternion().Inverse());
75 DeviceTransform.SetScale3D(FVector(1, 1, 1));
76
77 // Don't bother if not set
78 if (WaistTrackingInfo.WaistRadius > 0.0f)
79 {
80 DeviceTransform.AddToTranslation(DeviceTransform.GetRotation().RotateVector(FVector(-WaistTrackingInfo.WaistRadius, 0, 0)));
81 }
82
83
84 // This changes the forward vector to be correct
85 // I could pre do it by changed the yaw in resting mode to these values, but that had its own problems
86 // If given an initial forward vector that it should align to I wouldn't have to do this and could auto calculate it.
87 // But without that I am limited to this.
88
89 // #TODO: add optional ForwardVector to initial setup function that auto calculates offset so that the user can pass in HMD forward or something for calibration X+
90 // Also would be better overall because slightly offset from right angles in yaw wouldn't matter anymore, it would adjust for it.
91 switch (WaistTrackingInfo.TrackingMode)
92 {
93 case EBPVRWaistTrackingMode::VRWaist_Tracked_Front: DeviceTransform.ConcatenateRotation(FRotator(0, 0, 0).Quaternion()); break;
94 case EBPVRWaistTrackingMode::VRWaist_Tracked_Rear: DeviceTransform.ConcatenateRotation(FRotator(0, -180, 0).Quaternion()); break;
95 case EBPVRWaistTrackingMode::VRWaist_Tracked_Left: DeviceTransform.ConcatenateRotation(FRotator(0, 90, 0).Quaternion()); break;
96 case EBPVRWaistTrackingMode::VRWaist_Tracked_Right: DeviceTransform.ConcatenateRotation(FRotator(0, -90, 0).Quaternion()); break;
97 }
98
99 return DeviceTransform;
100 }
101};
EBPVRWaistTrackingMode
UENUM(Blueprintable)
static void Default_SetTrackedParent_Impl(UPrimitiveComponent *NewParentComponent, float WaistRadius, EBPVRWaistTrackingMode WaistTrackingMode, FBPVRWaistTracking_Info &OptionalWaistTrackingParent, USceneComponent *Self)
virtual void SetTrackedParent(UPrimitiveComponent *NewParentComponent, float WaistRadius, EBPVRWaistTrackingMode WaistTrackingMode)
UFUNCTION(BlueprintCallable, Category = "VRTrackedParentInterface")
static FTransform Default_GetWaistOrientationAndPosition(FBPVRWaistTracking_Info &WaistTrackingInfo)
UINTERFACE(MinimalAPI, meta = (CannotImplementInterfaceInBlueprint))
USTRUCT(BlueprintType, Category = "VRExpansionLibrary")
float WaistRadius
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "Settings")
FRotator RestingRotation
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "Settings")
EBPVRWaistTrackingMode TrackingMode
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "Settings")
UPrimitiveComponent * TrackedDevice
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "Settings")