-
Notifications
You must be signed in to change notification settings - Fork 86
/
UxtPointerFocus.h
181 lines (126 loc) · 6.66 KB
/
UxtPointerFocus.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
#pragma once
#include "CoreMinimal.h"
#include "Engine/EngineTypes.h"
#include "UObject/WeakObjectPtrTemplates.h"
class UActorComponent;
class UPrimitiveComponent;
class UUxtNearPointerComponent;
/** Result of closest point search functions. */
struct FUxtPointerFocusSearchResult
{
bool IsValid() const;
/** Closest object that implements the requires pointer target interface. */
UObject* Target;
/** Primitive that contains the closes point. */
UPrimitiveComponent* Primitive;
/** Closest point on the primitive to the pointer position. */
FVector ClosestPointOnTarget;
/** Distance of the closest point to the pointer position. */
float MinDistance;
};
/** Utility class that is used by components to manage different pointers and their focus targets. */
struct FUxtPointerFocus
{
public:
virtual ~FUxtPointerFocus() {}
/** Get the closest point on the surface of the focused target */
const FVector& GetClosestTargetPoint() const;
/** Get the currently focused target object. */
UObject* GetFocusedTarget() const;
/** Get the currently focused primitive component */
UPrimitiveComponent* GetFocusedPrimitive() const;
/** Get the currently focused target object.
* Returns null if the target does not implement the expected interface.
*/
UObject* GetFocusedTargetChecked() const;
// TODO get hand joints from WMR => no need to pass PointerTransform
/** Select and set the focused target among the list of overlaps. */
void SelectClosestTarget(UUxtNearPointerComponent* Pointer, const FTransform& PointerTransform, const TArray<FOverlapResult>& Overlaps);
/** Update the ClosestTargetPoint while focus is locked */
void UpdateClosestTarget(const FTransform& PointerTransform);
/** Select the closest primitive from the owner of the given target component.
* The target component will be the new focus, unless no usable primitive can be found.
*/
void SelectClosestPointOnTarget(UUxtNearPointerComponent* Pointer, const FTransform& PointerTransform, UActorComponent* NewTarget);
/** Clear the focused target. */
void ClearFocus(UUxtNearPointerComponent* Pointer);
/** Notify the focused target of a pointer update. */
void UpdateFocus(UUxtNearPointerComponent* Pointer) const;
/** Find a component of the actor that implements the required interface. */
UActorComponent* FindInterfaceComponent(AActor* Owner) const;
protected:
/** Set the focus to the given target object, primitive, and point on the target. */
void SetFocus(
UUxtNearPointerComponent* Pointer,
const FTransform& PointerTransform,
UObject* NewTarget,
UPrimitiveComponent* NewPrimitive,
const FVector& NewClosestPointOnTarget);
/** Find the closest target object, primitive, and point among the overlaps. */
FUxtPointerFocusSearchResult FindClosestTarget(const TArray<FOverlapResult>& Overlaps, const FVector& Point) const;
/** Find the closest primitive and point on the owner of the given component. */
FUxtPointerFocusSearchResult FindClosestPointOnComponent(UActorComponent* Target, const FVector& Point) const;
/** Get the interface class that targets for the pointer must implement. */
virtual UClass* GetInterfaceClass() const = 0;
/** Returns true if the given object implements the required target interface. */
virtual bool ImplementsTargetInterface(UObject* Target) const = 0;
/** Find the closest point on the given primitive using the distance function of the target interface. */
virtual bool GetClosestPointOnTarget(const UActorComponent* Target, const UPrimitiveComponent* Primitive, const FVector& Point, FVector& OutClosestPoint) const = 0;
/** Notify the target object that it has entered focus. */
virtual void RaiseEnterFocusEvent(UObject* Target, UUxtNearPointerComponent* Pointer) const = 0;
/** Notify the focused target object that the pointer has been updated. */
virtual void RaiseUpdateFocusEvent(UObject* Target, UUxtNearPointerComponent* Pointer) const = 0;
/** Notify the target object that it has exited focus. */
virtual void RaiseExitFocusEvent(UObject* Target, UUxtNearPointerComponent* Pointer) const = 0;
private:
/** Weak reference to the currently focused target. */
TWeakObjectPtr<UObject> FocusedTargetWeak;
/** Weak reference to the focused grab target primitive. */
TWeakObjectPtr<UPrimitiveComponent> FocusedPrimitiveWeak;
/** Closest point on the surface of the focused target. */
FVector ClosestTargetPoint = FVector::ZeroVector;
};
/** Focus implementation for the grab pointers. */
struct FUxtGrabPointerFocus : public FUxtPointerFocus
{
public:
/** Notify the target object that grab has started. */
void BeginGrab(UUxtNearPointerComponent* Pointer);
/** Notify the grabbed target object that the pointer has been updated. */
void UpdateGrab(UUxtNearPointerComponent* Pointer);
/** Notify the target object that grab has ended. */
void EndGrab(UUxtNearPointerComponent* Pointer);
bool IsGrabbing() const;
protected:
virtual UClass* GetInterfaceClass() const override;
virtual bool ImplementsTargetInterface(UObject* Target) const override;
virtual bool GetClosestPointOnTarget(const UActorComponent* Target, const UPrimitiveComponent* Primitive, const FVector& Point, FVector& OutClosestPoint) const override;
virtual void RaiseEnterFocusEvent(UObject* Target, UUxtNearPointerComponent* Pointer) const override;
virtual void RaiseUpdateFocusEvent(UObject* Target, UUxtNearPointerComponent* Pointer) const override;
virtual void RaiseExitFocusEvent(UObject* Target, UUxtNearPointerComponent* Pointer) const override;
private:
bool bIsGrabbing = false;
};
/** Focus implementation for the poke pointers. */
struct FUxtPokePointerFocus : public FUxtPointerFocus
{
public:
/** Notify the target object that poke has started. */
void BeginPoke(UUxtNearPointerComponent* Pointer);
/** Notify the poked target object that the pointer has been updated. */
void UpdatePoke(UUxtNearPointerComponent* Pointer);
/** Notify the target object that poke has ended. */
void EndPoke(UUxtNearPointerComponent* Pointer);
bool IsPoking() const;
protected:
virtual UClass* GetInterfaceClass() const override;
virtual bool ImplementsTargetInterface(UObject* Target) const override;
virtual bool GetClosestPointOnTarget(const UActorComponent* Target, const UPrimitiveComponent* Primitive, const FVector& Point, FVector& OutClosestPoint) const override;
virtual void RaiseEnterFocusEvent(UObject* Target, UUxtNearPointerComponent* Pointer) const override;
virtual void RaiseUpdateFocusEvent(UObject* Target, UUxtNearPointerComponent* Pointer) const override;
virtual void RaiseExitFocusEvent(UObject* Target, UUxtNearPointerComponent* Pointer) const override;
private:
bool bIsPoking = false;
};