A Demo Project for the UnrealEngineSDK
Loading...
Searching...
No Matches
BaseGrippableStoryActor.cpp
Go to the documentation of this file.
1// Copyright(c) Pixo Group. All Rights Reserved.
2
3
5
7#include "Kismet/GameplayStatics.h"
8
38
44
49
51{
52 GetWorld()->GetTimerManager().ClearTimer(VelocityCheckTimer);
53}
54
56{
58 return;
59
61 StaticMeshComponent->SetSimulatePhysics(false);
62 SetActorTransform(ResetTransform);
63 OnActorPositionResetDelegate.Broadcast(this);
64}
65
67{
68 if (FMath::IsNearlyEqual(GetVelocity().Size(), 0.0f))
69 {
71 OnActorStoppedDelegate.Broadcast(this);
72
74 {
76 }
77 }
78}
79
81{
82 Super::ObjectActivated_Implementation();
84}
85
87{
88 Super::ObjectDeactivated_Implementation();
89 if (IPixoVRStoryObject::Execute_CouldBeGrabbedByOtherHand(this))
91 else
93}
94
96{
97 switch (HandGripLogic)
98 {
101 {
102 ResetTransform = GetTransform();
104 }
106 OnGripped.Broadcast(GrippingController, GripInformation);
107 break;
110 {
111 ResetTransform = GetTransform();
113 }
115 AttachToHandObject(GrippingController, GripInformation);
116 break;
118 OnGripped.Broadcast(GrippingController, GripInformation);
119 break;
120 default:
121 OnGripped.Broadcast(GrippingController, GripInformation);
122 }
123
124 PlayHapticFeedbackEffect(GrippingController);
125}
126
128{
129 switch (HandGripLogic)
130 {
133 break;
137 break;
139 break;
140 default:
141 break;
142 }
143 OnDropped.Broadcast(ReleasingController, GripInformation, bWasSocketed);
144
146 {
147 PlayHapticFeedbackEffect(ReleasingController);
148 }
149}
150
151void ABaseGrippableStoryActor::IsHeld_Implementation(TArray<FBPGripPair>& HoldingControllers, bool& bIsHeld)
152{
153 HoldingControllers = VRGripInterfaceSettings.HoldingControllers;
155}
156
158{
159 if (bIsHeld)
160 {
161 VRGripInterfaceSettings.HoldingControllers.AddUnique(FBPGripPair(HoldingController, GripID));
164 }
165 else
166 {
167 VRGripInterfaceSettings.HoldingControllers.Remove(FBPGripPair(HoldingController, GripID));
169 }
170}
171
176
177
182
187
192
197
202
207
208void ABaseGrippableStoryActor::GetGripStiffnessAndDamping_Implementation(float &GripStiffnessOut, float &GripDampingOut)
209{
212}
213
218
223
224void ABaseGrippableStoryActor::ClosestGripSlotInRange_Implementation(FVector WorldLocation, bool bSecondarySlot, bool & bHadSlotInRange, FTransform & SlotWorldTransform, FName & SlotName, UGripMotionControllerComponent * CallingController, FName OverridePrefix)
225{
226 if (OverridePrefix.IsNone())
227 bSecondarySlot ? OverridePrefix = "VRGripS" : OverridePrefix = "VRGripP";
228
229 UVRExpansionFunctionLibrary::GetGripSlotInRangeByTypeName(OverridePrefix, this, WorldLocation, bSecondarySlot ? VRGripInterfaceSettings.SecondarySlotRange : VRGripInterfaceSettings.PrimarySlotRange, bHadSlotInRange, SlotWorldTransform, SlotName, CallingController);
230}
231
236
259
260void ABaseGrippableStoryActor::OnSecondaryGrip_Implementation(UGripMotionControllerComponent* GripOwningController, USceneComponent* SecondaryGripComponent, const FBPActorGripInformation& GripInformation) { OnSecondaryGripAdded.Broadcast(GripOwningController, GripInformation); }
261void ABaseGrippableStoryActor::OnSecondaryGripRelease_Implementation(UGripMotionControllerComponent* GripOwningController, USceneComponent* ReleasingSecondaryGripComponent, const FBPActorGripInformation& GripInformation) { OnSecondaryGripRemoved.Broadcast(GripOwningController, GripInformation); }
262
264{
265 CurrentHoldingHand = Cast<APixoVRHand>(GrippingController->GetOwner());
267 {
268 DisableComponentsSimulatePhysics();
269 AttachToComponent(CurrentHoldingHand->MotionController, FAttachmentTransformRules::SnapToTargetNotIncludingScale);
270 }
271
272 if (CurrentHoldingHand->HandMotionSource == EControllerHand::Left)
273 {
274 SetActorRelativeTransform(ObjectTransformInLeftHand);
275 }
276 else
277 {
278 SetActorRelativeTransform(ObjectTransformInRightHand);
279 }
280
281 OnGripped.Broadcast(GrippingController, GripInformation);
282}
283
285{
286 FDetachmentTransformRules DetachmentTransformRules(EDetachmentRule::KeepWorld, false);
287 DetachFromActor(DetachmentTransformRules);
288 if (IVRGripInterface::Execute_SimulateOnDrop(this))
289 {
290 for (UActorComponent* Component : GetComponents())
291 {
292 if (UPrimitiveComponent* PrimComp = Cast<UPrimitiveComponent>(Component))
293 {
294 PrimComp->SetSimulatePhysics(true);
295 }
296 }
297 }
298}
299
314
316{
317 if (bFeedbackEnabled && GripMotionControllerComponent)
318 {
319 APlayerController* PlayerController = UGameplayStatics::GetPlayerController(GetWorld(), 0);
320 APixoVRPlayerController* PixoVRPlayerController = Cast<APixoVRPlayerController>(PlayerController);
321 if (PixoVRPlayerController)
322 {
323 EControllerHand Hand;
324 GripMotionControllerComponent->GetHandType(Hand);
325
326 PixoVRPlayerController->PlayHapticFeedback(Hand == EControllerHand::Right, HapticDuration, HapticStrength);
327 }
328 }
329}
EHandGripLogic
Enum representing the different hand grip logic options.
@ OnlyOnGripEvent
@ AttachToHandWithCustomTransform
@ AttachToHand
EGripMovementReplicationSettings
UENUM(Blueprintable)
ESecondaryGripType
UENUM(Blueprintable)
EGripCollisionType
UENUM(Blueprintable)
EGripLateUpdateSettings
UENUM(Blueprintable)
EGripInterfaceTeleportBehavior
UENUM(Blueprintable)
void StopVelocityCheckTimer()
Stopping the current velocity check timer.
FTimerHandle VelocityCheckTimer
Internal timer for checking object's velocity in a given time.
virtual void OnGripRelease_Implementation(UGripMotionControllerComponent *ReleasingController, const FBPActorGripInformation &GripInformation, bool bWasSocketed) override
Implementation of the OnGripRelease function from the IVRGripInterface interface. Event triggered on ...
void PlayHapticFeedbackEffect(UGripMotionControllerComponent *GripMotionControllerComponent) const
Plays haptic feedback on specific controller.
virtual EGripMovementReplicationSettings GripMovementReplicationType_Implementation() override
Implementation of the GripMovementReplicationType function from the IVRGripInterface interface....
virtual void GetGripStiffnessAndDamping_Implementation(float &GripStiffnessOut, float &GripDampingOut) override
Implementation of the GetGripStiffnessAndDamping function from the IVRGripInterface interface....
float HapticStrength
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "Feedback Effect", meta=(EditCondition = "bFee...
void UpdateHandGripLogic(EHandGripLogic NewHandGripLogic)
Updates the hand grip logic.
FVROnGripSignature OnSecondaryGripAdded
UPROPERTY(BlueprintAssignable, Category = "Grip Events")
virtual void ClosestGripSlotInRange_Implementation(FVector WorldLocation, bool bSecondarySlot, bool &bHadSlotInRange, FTransform &SlotWorldTransform, FName &SlotName, UGripMotionControllerComponent *CallingController=nullptr, FName OverridePrefix=NAME_None) override
Implementation of the ClosestGripSlotInRange function from the IVRGripInterface interface....
void AttachToHandObject(UGripMotionControllerComponent *GrippingController, const FBPActorGripInformation &GripInformation)
Attaches the object to a hand.
FTransform ResetTransform
UPROPERTY(BlueprintReadOnly, Category = "GrippableObject")
virtual ESecondaryGripType SecondaryGripType_Implementation() override
Implementation of the SecondaryGripType function from the IVRGripInterface interface....
bool bSaveResetTransformOnGrip
Flag for preventing this objet from saving ResetTransform.
virtual void OnSecondaryGripRelease_Implementation(UGripMotionControllerComponent *GripOwningController, USceneComponent *ReleasingSecondaryGripComponent, const FBPActorGripInformation &GripInformation) override
Implementation of the OnSecondaryGripRelease function from the IVRGripInterface interface....
EHandGripLogic HandGripLogic
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "GrippableObject")
void DetachObjectFromHand()
Detaches the object from the hand.
FTransform ObjectTransformInRightHand
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "GrippableObject")
FVROnGripSignature OnSecondaryGripRemoved
UPROPERTY(BlueprintAssignable, Category = "Grip Events")
float HapticDuration
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "Feedback Effect", meta=(EditCondition = "bFee...
FVROnDropSignature OnDropped
UPROPERTY(BlueprintAssignable, Category = "Grip Events")
virtual void SetHeld_Implementation(UGripMotionControllerComponent *HoldingController, uint8 GripID, bool bIsHeld) override
Implementation of the SetHeld function from the IVRGripInterface interface. Sets is held,...
virtual EGripInterfaceTeleportBehavior TeleportBehavior_Implementation() override
Implementation of the TeleportBehavior function from the IVRGripInterface interface....
virtual float GripBreakDistance_Implementation() override
Implementation of the GripBreakDistance function from the IVRGripInterface interface....
virtual void IsHeld_Implementation(TArray< FBPGripPair > &HoldingControllers, bool &bIsHeld) override
Implementation of the IsHeld function from the IVRGripInterface interface. Returns if the object is h...
UStaticMeshComponent * StaticMeshComponent
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Components")
FVROnGripSignature OnGripped
UPROPERTY(BlueprintAssignable, Category = "Grip Events")
virtual EGripLateUpdateSettings GripLateUpdateSetting_Implementation() override
Implementation of the GripLateUpdateSetting function from the IVRGripInterface interface....
bool bDisablePhysicsOnCustomTransformAttach
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "GrippableObject", meta=(EditCondition = "...
void OnGrippedEvent(UGripMotionControllerComponent *GrippingController, const FBPActorGripInformation &GripInformation)
Event triggered when the object is gripped.
bool bActivateLocationResetAfterDrop
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "GrippableObject")
virtual void OnSecondaryGrip_Implementation(UGripMotionControllerComponent *GripOwningController, USceneComponent *SecondaryGripComponent, const FBPActorGripInformation &GripInformation) override
Implementation of the OnSecondaryGrip function from the IVRGripInterface interface....
float VelocityCheckRate
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "GrippableObject")
virtual bool DenyGripping_Implementation(UGripMotionControllerComponent *GripInitiator=nullptr) override
Implementation of the DenyGripping function from the IVRGripInterface interface. Set up as deny inste...
APixoVRHand * CurrentHoldingHand
UPROPERTY(VisibleInstanceOnly, BlueprintReadWrite, Category = "GrippableObject")
ABaseGrippableStoryActor()
virtual void UpdateObjectHighlight_Implementation(bool Activate) override
Implementation of the UpdateObjectHighlight function from the IPixoVRStoryObject interface.
void ResetPosition()
Resetting object to the position it has ben grabbed off.
bool bCanResetPosition
UPROPERTY(BlueprintReadWrite, Category = "GrippableObject")
virtual bool SimulateOnDrop_Implementation() override
Implementation of the SimulateOnDrop function from the IVRGripInterface interface....
virtual void ObjectActivated_Implementation() override
Implementation of the ObjectActivated function from the IPixoVRStoryObject interface.
void CheckVelocity()
Checking if this object has stopped.
FBPInterfaceProperties VRGripInterfaceSettings
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VRGripInterface")
void StartVelocityCheckTimer()
Stopping new velocity check timer.
FOnActorStopped OnActorStoppedDelegate
UPROPERTY(BlueprintReadWrite, BlueprintCallable, BlueprintAssignable)
FOnActorStopped OnActorPositionResetDelegate
UPROPERTY(BlueprintReadWrite, BlueprintCallable, BlueprintAssignable)
FTransform ObjectTransformInLeftHand
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "GrippableObject")
virtual void OnGrip_Implementation(UGripMotionControllerComponent *GrippingController, const FBPActorGripInformation &GripInformation) override
Implementation of the OnGrip function from the IVRGripInterface interface. Event triggered on the int...
bool bFeedbackEnabled
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "Feedback Effect")
virtual FBPAdvGripSettings AdvancedGripSettings_Implementation() override
Implementation of the AdvancedGripSettings function from the IVRGripInterface interface....
void OnReleasedEvent(UGripMotionControllerComponent *ReleasingController, const FBPActorGripInformation &GripInformation, bool bWasSocketed)
Event triggered when the object is released from the grip.
virtual void BeginPlay() override
virtual EGripCollisionType GetPrimaryGripType_Implementation(bool bIsSlot) override
Implementation of the GetPrimaryGripType function from the IVRGripInterface interface....
virtual bool AllowsMultipleGrips_Implementation() override
Implementation of the AllowsMultipleGrips function from the IVRGripInterface interface....
virtual void ObjectDeactivated_Implementation() override
Implementation of the ObjectDeactivated function from the IPixoVRStoryObject interface.
UHighlightComponent * HighlightComponent
UPROPERTY(EditAnywhere, BlueprintReadWrite)
UGripMotionControllerComponent * MotionController
UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = "Components")
Definition PixoVRHand.h:118
EControllerHand HandMotionSource
UPROPERTY(BlueprintReadWrite, Category = "Init", meta = (ExposeOnSpawn = "true"))
Definition PixoVRHand.h:352
A custom player controller class for PixoVR.
void PlayHapticFeedback(bool RightHand, float Duration, float Strength)
UFUNCTION(BlueprintCallable, Category = "Haptic")
UCLASS(Blueprintable, meta = (BlueprintSpawnableComponent), ClassGroup = MotionController)
void GetHandType(EControllerHand &Hand)
UFUNCTION(BlueprintPure, Category = "VRExpansionFunctions", meta = (bIgnoreSelf = "true",...
FTimerHandle PulseHighlightTimerHandle
UPROPERTY(BlueprintReadWrite)
void UpdateHighlightValue(EHighlightColor HighlightColor)
Updates the highlight color of the object.
static void GetGripSlotInRangeByTypeName(FName SlotType, AActor *Actor, FVector WorldLocation, float MaxRange, bool &bHadSlotInRange, FTransform &SlotWorldTransform, FName &SlotName, UGripMotionControllerComponent *QueryController=nullptr)
UFUNCTION(BlueprintPure, Category = "VRGrip", meta = (bIgnoreSelf = "true", DisplayName = "GetGripSlo...
USTRUCT(BlueprintType, Category = "VRExpansionLibrary")
USTRUCT(BlueprintType, Category = "VRExpansionLibrary")
USTRUCT(BlueprintType, Category = "VRExpansionLibrary")
ESecondaryGripType SecondaryGripType
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VRGripInterface")
bool bDenyGripping
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VRGripInterface")
EGripCollisionType FreeDefaultGripType
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VRGripInterface")
float ConstraintBreakDistance
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VRGripInterface")
bool bAllowMultipleGrips
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VRGripInterface")
float SecondarySlotRange
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VRGripInterface")
EGripLateUpdateSettings LateUpdateSetting
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VRGripInterface")
EGripCollisionType SlotDefaultGripType
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VRGripInterface")
EGripInterfaceTeleportBehavior OnTeleportBehavior
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VRGripInterface")
float ConstraintStiffness
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VRGripInterface")
float PrimarySlotRange
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VRGripInterface")
bool bIsHeld
UPROPERTY(BlueprintReadWrite, NotReplicated, Category = "VRGripInterface")
TArray< FBPGripPair > HoldingControllers
UPROPERTY(BlueprintReadWrite, NotReplicated, Category = "VRGripInterface")
float ConstraintDamping
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VRGripInterface")
FBPAdvGripSettings AdvancedGripSettings
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VRGripInterface|AdvancedGripSettings")
EGripMovementReplicationSettings MovementReplicationType
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VRGripInterface")
bool bSimulateOnDrop
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VRGripInterface")