Documentation for the Unreal C++ Plugin
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#include "Kismet/KismetMathLibrary.h"
10
12 : Super()
13{
14 StaticMeshComponent = CreateDefaultSubobject<UStaticMeshComponent>("StaticMeshComponent");
15 SetRootComponent(StaticMeshComponent);
16
17 VRGripInterfaceSettings.bDenyGripping = false;
18 VRGripInterfaceSettings.OnTeleportBehavior = EGripInterfaceTeleportBehavior::TeleportAllComponents;
19 VRGripInterfaceSettings.bSimulateOnDrop = true;
20 VRGripInterfaceSettings.SecondaryGripType = ESecondaryGripType::SG_None;
21 VRGripInterfaceSettings.MovementReplicationType = EGripMovementReplicationSettings::ForceClientSideMovement;
22 VRGripInterfaceSettings.LateUpdateSetting = EGripLateUpdateSettings::NotWhenCollidingOrDoubleGripping;
23 VRGripInterfaceSettings.ConstraintStiffness = 1500.0f;
24 VRGripInterfaceSettings.ConstraintDamping = 200.0f;
25 VRGripInterfaceSettings.ConstraintBreakDistance = 100.0f;
26 VRGripInterfaceSettings.SecondarySlotRange = 20.0f;
27 VRGripInterfaceSettings.PrimarySlotRange = 20.0f;
28 VRGripInterfaceSettings.bIsHeld = false;
29
31
32 bFeedbackEnabled = false;
33 HapticDuration = 0.5f;
34 HapticStrength = 0.5f;
35
36 bGripSoundsEnabled = false;
38
39 //Bind gripping events for using in the blueprints
42}
43
49
55
57{
58 GetWorld()->GetTimerManager().ClearTimer(PositionResetTimer);
59}
60
62{
64 return;
65
67 {
68 OnDroppedActorDeleted.Broadcast(GetClass());
69
70 Destroy();
71 }
72 else
73 {
75 StaticMeshComponent->SetSimulatePhysics(false);
76
77 SetActorTransform(ResetTransform);
78 OnActorPositionResetDelegate.Broadcast(this);
79 }
80}
81
97
102
110
112{
114 {
115 FTransform RelativeToHandWorldTransform = GrabbedHand->MotionController->GetComponentTransform();
116 const FTransform InHandOffsetTransform = GrabbedHand->HandMotionSource == EControllerHand::Left ? ObjectTransformInLeftHand : ObjectTransformInRightHand;
117 RelativeToHandWorldTransform.SetTranslation(RelativeToHandWorldTransform.TransformPosition(InHandOffsetTransform.GetTranslation()));
118 RelativeToHandWorldTransform.SetRotation(RelativeToHandWorldTransform.GetRotation() * InHandOffsetTransform.GetRotation());
119 RelativeToHandWorldTransform.SetScale3D(InHandOffsetTransform.GetScale3D());
120
121 return RelativeToHandWorldTransform;
122 }
123
124 return GetTransform();
125}
126
128{
129 Super::ObjectActivated_Implementation();
130
132 {
133 VRGripInterfaceSettings.bDenyGripping = false;
134 }
135}
136
138{
139 Super::ObjectDeactivated_Implementation();
140
142 return;
143
144 if (Execute_CouldBeGrabbedByOtherHand(this) || (Story->GameManager && Story->GameManager->bWrongInteractableActorGrabEnabled))
145 VRGripInterfaceSettings.bDenyGripping = false;
146 else
147 VRGripInterfaceSettings.bDenyGripping = true;
148}
149
150void ABaseGrippableStoryActor::OnGrip_Implementation(UGripMotionControllerComponent* GrippingController, const FBPActorGripInformation& GripInformation)
151{
152 switch (HandGripLogic)
153 {
158 {
159 ResetTransform = GetTransform();
161 }
163 OnGripped.Broadcast(GrippingController, GripInformation);
164 break;
167 {
168 ResetTransform = GetTransform();
170 }
172 AttachToHandObject(GrippingController, GripInformation);
173 break;
175 OnGripped.Broadcast(GrippingController, GripInformation);
176 break;
177 default:
178 OnGripped.Broadcast(GrippingController, GripInformation);
179 }
181 PlayHapticFeedbackEffect(GrippingController);
182}
183
184void ABaseGrippableStoryActor::OnGripRelease_Implementation(UGripMotionControllerComponent* ReleasingController, const FBPActorGripInformation& GripInformation, bool bWasSocketed)
185{
186 switch (HandGripLogic)
187 {
192 break;
196 break;
198 break;
199 default:
200 break;
201 }
202 OnDropped.Broadcast(ReleasingController, GripInformation, bWasSocketed);
203
205 {
207 PlayHapticFeedbackEffect(ReleasingController);
208 }
209}
210
211void ABaseGrippableStoryActor::IsHeld_Implementation(TArray<FBPGripPair>& HoldingControllers, bool& bIsHeld)
212{
213 HoldingControllers = VRGripInterfaceSettings.HoldingControllers;
214 bIsHeld = VRGripInterfaceSettings.bIsHeld;
215}
216
217void ABaseGrippableStoryActor::SetHeld_Implementation(UGripMotionControllerComponent* HoldingController, uint8 GripID, bool bIsHeld)
218{
219 if (bIsHeld)
220 {
221 VRGripInterfaceSettings.HoldingControllers.AddUnique(FBPGripPair(HoldingController, GripID));
222 VRGripInterfaceSettings.bWasHeld = true;
223 VRGripInterfaceSettings.bIsHeld = VRGripInterfaceSettings.HoldingControllers.Num() > 0;
224 }
225 else
226 {
227 VRGripInterfaceSettings.HoldingControllers.Remove(FBPGripPair(HoldingController, GripID));
228 VRGripInterfaceSettings.bIsHeld = VRGripInterfaceSettings.HoldingControllers.Num() > 0;
229 }
230}
231
232bool ABaseGrippableStoryActor::DenyGripping_Implementation(UGripMotionControllerComponent * GripInitiator)
233{
234 return VRGripInterfaceSettings.bDenyGripping;
235}
236
237
239{
240 return VRGripInterfaceSettings.OnTeleportBehavior;
241}
242
247
249{
250 return bIsSlot ? VRGripInterfaceSettings.SlotDefaultGripType : VRGripInterfaceSettings.FreeDefaultGripType;
251}
252
254{
255 return VRGripInterfaceSettings.SecondaryGripType;
256}
257
259{
260 return VRGripInterfaceSettings.MovementReplicationType;
261}
262
264{
265 return VRGripInterfaceSettings.LateUpdateSetting;
266}
267
268void ABaseGrippableStoryActor::GetGripStiffnessAndDamping_Implementation(float &GripStiffnessOut, float &GripDampingOut)
269{
270 GripStiffnessOut = VRGripInterfaceSettings.ConstraintStiffness;
271 GripDampingOut = VRGripInterfaceSettings.ConstraintDamping;
272}
273
275{
276 return VRGripInterfaceSettings.AdvancedGripSettings;
277}
278
283
284void ABaseGrippableStoryActor::ClosestGripSlotInRange_Implementation(FVector WorldLocation, bool bSecondarySlot, bool & bHadSlotInRange, FTransform & SlotWorldTransform, FName & SlotName, UGripMotionControllerComponent * CallingController, FName OverridePrefix)
285{
286 if (OverridePrefix.IsNone())
287 bSecondarySlot ? OverridePrefix = "VRGripS" : OverridePrefix = "VRGripP";
288
289 UVRExpansionFunctionLibrary::GetGripSlotInRangeByTypeName(OverridePrefix, this, WorldLocation, bSecondarySlot ? VRGripInterfaceSettings.SecondarySlotRange : VRGripInterfaceSettings.PrimarySlotRange, bHadSlotInRange, SlotWorldTransform, SlotName, CallingController);
290}
291
296
298{
299 HandGripLogic = NewHandGripLogic;
300 switch (HandGripLogic)
301 {
303 VRGripInterfaceSettings.SlotDefaultGripType = EGripCollisionType::InteractiveCollisionWithPhysics;
304 VRGripInterfaceSettings.FreeDefaultGripType = EGripCollisionType::InteractiveCollisionWithPhysics;
305 break;
307 VRGripInterfaceSettings.SlotDefaultGripType = EGripCollisionType::EventsOnly;
308 VRGripInterfaceSettings.FreeDefaultGripType = EGripCollisionType::EventsOnly;
309 break;
311 VRGripInterfaceSettings.SlotDefaultGripType = EGripCollisionType::EventsOnly;
312 VRGripInterfaceSettings.FreeDefaultGripType = EGripCollisionType::EventsOnly;
313 break;
315 VRGripInterfaceSettings.SlotDefaultGripType = EGripCollisionType::InteractiveHybridCollisionWithSweep;
316 VRGripInterfaceSettings.FreeDefaultGripType = EGripCollisionType::InteractiveHybridCollisionWithSweep;
317 break;
319 break;
320 default:
321 VRGripInterfaceSettings.SlotDefaultGripType = EGripCollisionType::InteractiveCollisionWithPhysics;
322 VRGripInterfaceSettings.FreeDefaultGripType = EGripCollisionType::InteractiveCollisionWithPhysics;
323 }
324}
325
326void ABaseGrippableStoryActor::OnSecondaryGrip_Implementation(UGripMotionControllerComponent* GripOwningController, USceneComponent* SecondaryGripComponent, const FBPActorGripInformation& GripInformation) { OnSecondaryGripAdded.Broadcast(GripOwningController, GripInformation); }
327void ABaseGrippableStoryActor::OnSecondaryGripRelease_Implementation(UGripMotionControllerComponent* GripOwningController, USceneComponent* ReleasingSecondaryGripComponent, const FBPActorGripInformation& GripInformation) { OnSecondaryGripRemoved.Broadcast(GripOwningController, GripInformation); }
328
329void ABaseGrippableStoryActor::AttachToHandObject(UGripMotionControllerComponent* GrippingController, const FBPActorGripInformation& GripInformation)
330{
331 CurrentHoldingHand = Cast<APixoVRHand>(GrippingController->GetOwner());
332
333 DisableComponentsSimulatePhysics();
334 AttachToComponent(CurrentHoldingHand->MotionController, FAttachmentTransformRules::SnapToTargetNotIncludingScale);
335
336 if (CurrentHoldingHand->HandMotionSource == EControllerHand::Left)
337 {
338 SetActorRelativeTransform(ObjectTransformInLeftHand);
339 }
340 else
341 {
342 SetActorRelativeTransform(ObjectTransformInRightHand);
343 }
344
345 OnGripped.Broadcast(GrippingController, GripInformation);
346}
347
349{
350 FDetachmentTransformRules DetachmentTransformRules(EDetachmentRule::KeepWorld, false);
351 DetachFromActor(DetachmentTransformRules);
352 if (IVRGripInterface::Execute_SimulateOnDrop(this))
353 {
354 for (UActorComponent* Component : GetComponents())
355 {
356 if (UPrimitiveComponent* PrimComp = Cast<UPrimitiveComponent>(Component))
357 {
358 PrimComp->SetSimulatePhysics(true);
359 }
360 }
361 }
362}
363
364void ABaseGrippableStoryActor::GrabWithTwoHands_Implementation(UMotionControllerComponent* GrabbingController)
365{
366 Super::GrabWithTwoHands_Implementation(GrabbingController);
367
368 FOverlappingInfo OverlappingInfo;
369 APixoVRCharacter* PlayerRef = Cast<APixoVRCharacter>(UGameplayStatics::GetPlayerPawn(GetWorld(), 0));
370 PixoVRHandLeft = PlayerRef->VRHandLeft;
371 PixoVRHandRight = PlayerRef->VRHandRight;
372 TWeakObjectPtr<APixoVRHand> GrabbingHand = GrabbingController->MotionSource.IsEqual("Right") ? PixoVRHandRight : PixoVRHandLeft;
373
374 GrabbingHand.Get()->GetOverlappingActor(OverlappingInfo);
375 if (!OverlappingInfo.OverlapActor || !(OverlappingInfo.OverlapActor == this))
376 return;
377
378 if( PlayerRef->bActivateLeftLaser || PlayerRef->bActivateRightLaser)
379 {
380 PlayerRef->bLaserBeamActive = false;
381 PlayerRef->ActivateLaserBeam(EControllerHand::Right, false);
382 PlayerRef->ActivateLaserBeam(EControllerHand::Left, false);
383 }
384
385 DetachFromActor(FDetachmentTransformRules::KeepWorldTransform);
387 PixoVRHandLeft->HandHoldingObject = this;
388 PixoVRHandRight->HandHoldingObject = this;
389 Cast<APixoVRCharacter>(UGameplayStatics::GetPlayerPawn(GetWorld(), 0))->HoldToolRight = true;
390 Cast<APixoVRCharacter>(UGameplayStatics::GetPlayerPawn(GetWorld(), 0))->HoldToolLeft = true;
391 TwoHandMainGrabController = GrabbingController->MotionSource.IsEqual("Right") ? PixoVRHandLeft->MotionController : PixoVRHandRight->MotionController;
392
393 for (const auto FakeHand : IPixoVRStoryObject::Execute_GetTwoHandProperties(this).FakeHands)
394 {
395 FakeHand->SetVisibility(true);
396 }
397 if (PixoVRHandLeft.IsValid() && PixoVRHandRight.IsValid() && !IPixoVRStoryObject::Execute_GetTwoHandProperties(this).EnableDebug)
398 {
399 PixoVRHandLeft->SetActorHiddenInGame(true);
400 PixoVRHandRight->SetActorHiddenInGame(true);
401 }
402 TwoHandGrab();
403}
404
405void ABaseGrippableStoryActor::ReleaseTwoHands_Implementation(UMotionControllerComponent* ReleasingController)
406{
407 Super::ReleaseTwoHands_Implementation(ReleasingController);
409 {
410 if (GetWorldTimerManager().IsTimerActive(TwoHandTimer))
411 GetWorldTimerManager().ClearTimer(TwoHandTimer);
412 PixoVRHandLeft->SetActorHiddenInGame(false);
413 PixoVRHandRight->SetActorHiddenInGame(false);
415 for (const auto FakeHand : IPixoVRStoryObject::Execute_GetTwoHandProperties(this).FakeHands)
416 {
417 FakeHand->SetVisibility(false);
418 }
419 Cast<APixoVRCharacter>(UGameplayStatics::GetPlayerPawn(GetWorld(), 0))->ResetHand(true);
420 Cast<APixoVRCharacter>(UGameplayStatics::GetPlayerPawn(GetWorld(), 0))->ResetHand(false);
421 IPixoVRStoryObject::Execute_ResetTwoHandsHoldingFunctionality(this);
422 }
423 if (TwoHandMainGrabController.IsValid() && (TwoHandMainGrabController == ReleasingController) && true)
424 {
425 return;
426 }
427 if (GetWorldTimerManager().IsTimerActive(TwoHandTimer))
428 {
429 GetWorldTimerManager().ClearTimer(TwoHandTimer);
430 PixoVRHandLeft->SetActorHiddenInGame(false);
431 PixoVRHandRight->SetActorHiddenInGame(false);
433
434 for (const auto FakeHand : IPixoVRStoryObject::Execute_GetTwoHandProperties(this).FakeHands)
435 {
436 FakeHand->SetVisibility(false);
437 }
438
439 APixoVRHand* ActiveHandAfterRelease = ReleasingController->MotionSource.IsEqual("Right") ? PixoVRHandLeft.Get() : PixoVRHandRight.Get();
440 if (ReleasingController->MotionSource.IsEqual("Right"))
441 {
442 Cast<APixoVRCharacter>(UGameplayStatics::GetPlayerPawn(GetWorld(), 0))->ResetHand(true);
443 // Cast<APixoVRCharacter>(UGameplayStatics::GetPlayerPawn(GetWorld(), 0))->HoldToolRight = false;
444 // PixoVRHandRight->HandHoldingObject = nullptr;
445 }
446 else
447 {
448 Cast<APixoVRCharacter>(UGameplayStatics::GetPlayerPawn(GetWorld(), 0))->ResetHand(false);
449 // Cast<APixoVRCharacter>(UGameplayStatics::GetPlayerPawn(GetWorld(), 0))->HoldToolLeft = false;
450 // PixoVRHandLeft->HandHoldingObject = nullptr;
451 }
452
453 if (TwoHandMainGrabController.IsValid() && TwoHandMainGrabController == ReleasingController)
454 {
455 TwoHandMainGrabController = ActiveHandAfterRelease->MotionController;
456 ActiveHandAfterRelease->MotionController->GripObjectByInterface(this, IPixoVRStoryObject::Execute_GetObjectGrabTransform(this, ActiveHandAfterRelease));
457 }
458 else
459 {
460 this->AttachToComponent(ActiveHandAfterRelease->MotionController, FAttachmentTransformRules::SnapToTargetNotIncludingScale);
461 ReleasingController->MotionSource.IsEqual("Right") ? SetActorRelativeTransform(ObjectTransformInLeftHand) : SetActorRelativeTransform(ObjectTransformInRightHand);
462 }
463 }
464}
465
470
472{
473 Super::ResetTwoHandsHoldingFunctionality_Implementation();
474
475 if (GetWorldTimerManager().IsTimerActive(TwoHandTimer))
476 {
477 GetWorldTimerManager().ClearTimer(TwoHandTimer);
478 PixoVRHandLeft->SetActorHiddenInGame(false);
479 PixoVRHandRight->SetActorHiddenInGame(false);
481
482 for (const auto FakeHand : IPixoVRStoryObject::Execute_GetTwoHandProperties(this).FakeHands)
483 {
484 FakeHand->SetVisibility(false);
485 }
486 }
487}
488
493
508
509void ABaseGrippableStoryActor::PlayHapticFeedbackEffect(UGripMotionControllerComponent* GripMotionControllerComponent) const
510{
511 if (bFeedbackEnabled && GripMotionControllerComponent)
512 {
513 APlayerController* PlayerController = UGameplayStatics::GetPlayerController(GetWorld(), 0);
514 APixoVRPlayerController* PixoVRPlayerController = Cast<APixoVRPlayerController>(PlayerController);
515 if (PixoVRPlayerController)
516 {
517 EControllerHand Hand;
518 GripMotionControllerComponent->GetHandType(Hand);
519
520 PixoVRPlayerController->PlayHapticFeedback(Hand == EControllerHand::Right, HapticDuration, HapticStrength);
521 }
522 }
523}
524
526{
528 {
529 UGameplayStatics::PlaySoundAtLocation(this, GripSoundCue, GetActorLocation());
530 }
531}
532
534{
536 {
537 UGameplayStatics::PlaySoundAtLocation(this, ReleaseSoundCue, GetActorLocation());
538 }
539}
540
542{
543 if (!PixoVRHandLeft.IsValid() || !PixoVRHandRight.IsValid())
544 return;
545
546 const FRotator HandDirectionRotator = UKismetMathLibrary::ComposeRotators(UKismetMathLibrary::FindLookAtRotation(PixoVRHandRight->GrabSphere->GetComponentLocation(), PixoVRHandLeft->GrabSphere->GetComponentLocation()), FRotator(0.0, -90.0, 0.0));
547 if (CrossDetected && IPixoVRStoryObject::Execute_GetTwoHandProperties(this).EnableFlip)
548 {
549 if (HandDirectionRotator.Pitch <= 0.0)
550 {
551 ResultedPitch = FMath::Abs(PitchBeforeCross) + (FMath::Abs(PitchBeforeCross) - FMath::Abs(HandDirectionRotator.Pitch));
552 }
553 else
554 {
555 ResultedPitch = (FMath::Abs(PitchBeforeCross) + (FMath::Abs(PitchBeforeCross) - FMath::Abs(HandDirectionRotator.Pitch))) * -1.0;
556 }
557 SetActorRotation(FRotator(0.0, TwoHandZAxisValue, ResultedPitch));
558 }
559 else if (CrossDetected && !IPixoVRStoryObject::Execute_GetTwoHandProperties(this).EnableFlip)
560 {
561 SetActorRotation(FRotator(0.0, TwoHandZAxisValue, ResultedPitch));
562 }
563 else
564 {
565 if (HandDirectionRotator.Pitch <= 0.0)
566 {
567 ResultedPitch = (HandDirectionRotator.Pitch - MoveBackPitchDelta) * -1.0;
568 }
569 else
570 {
571 ResultedPitch = (HandDirectionRotator.Pitch + MoveBackPitchDelta) * -1.0;
572 }
573
574 if (MoveBackPitchDelta > 0.0)
575 {
577 }
578 else
579 {
580 MoveBackPitchDelta = 0.0;
581 }
582
583 if (!((ResultedPitch >= 60.0) || ResultedPitch <= -60.0))
584 TwoHandZAxisValue = HandDirectionRotator.Yaw;
585 SetActorRotation(FRotator(0.0, TwoHandZAxisValue, ResultedPitch));
586 }
587
588 FVector ObjectRelatedHandLocation = (PixoVRHandRight->GrabSphere->GetComponentLocation() - (PixoVRHandRight->GrabSphere->GetComponentLocation()-PixoVRHandLeft->GrabSphere->GetComponentLocation())/2);
589 ObjectRelatedHandLocation.Z -= IPixoVRStoryObject::Execute_GetTwoHandProperties(this).ZAxisOffsetInHands;
590 SetActorLocation(ObjectRelatedHandLocation);
591 HandCrossDetection(ResultedPitch, HandDirectionRotator.Pitch);
592
593 if (IPixoVRStoryObject::Execute_GetTwoHandProperties(this).EnableDebug)
594 {
595 GEngine->AddOnScreenDebugMessage(-1, 0.01, FColor::Red, FString::Printf(TEXT("Right hand distance to object - %f"), (PixoVRHandRight->GrabSphere->GetComponentLocation() - GetActorLocation()).Size()));
596 GEngine->AddOnScreenDebugMessage(-1, 0.01, FColor::Blue, FString::Printf(TEXT("Left hand distance to object - %f"), (PixoVRHandLeft->GrabSphere->GetComponentLocation() - GetActorLocation()).Size()));
597 GEngine->AddOnScreenDebugMessage(-1, 0.01, FColor::Black, FString::Printf(TEXT("Detach distance - %f"), (IPixoVRStoryObject::Execute_GetTwoHandProperties(this).ControllerDetachDistance)));
598 GEngine->AddOnScreenDebugMessage(-1, 0.01, FColor::Black, FString::Printf(TEXT("Cross detected - %s"), CrossDetected ? TEXT("true") : TEXT("false")));
599 DrawDebugSphere(GetWorld(), (PixoVRHandRight->GrabSphere->GetComponentLocation() - (PixoVRHandRight->GrabSphere->GetComponentLocation()-PixoVRHandLeft->GrabSphere->GetComponentLocation())/2), 3.0, 10, FColor::Yellow, false, 0.1);
600 }
601 if ((PixoVRHandRight->GrabSphere->GetComponentLocation() - GetActorLocation()).Size() > (IPixoVRStoryObject::Execute_GetTwoHandProperties(this).ControllerDetachDistance))
602 IPixoVRStoryObject::Execute_ReleaseTwoHands(this, PixoVRHandRight->MotionController);
603 if ((PixoVRHandLeft->GrabSphere->GetComponentLocation() - GetActorLocation()).Size() > (IPixoVRStoryObject::Execute_GetTwoHandProperties(this).ControllerDetachDistance))
604 IPixoVRStoryObject::Execute_ReleaseTwoHands(this, PixoVRHandLeft->MotionController);
605
606 GetWorldTimerManager().SetTimer(TwoHandTimer, this, &ABaseGrippableStoryActor::TwoHandGrab, IPixoVRStoryObject::Execute_GetTwoHandProperties(this).TwoHandUpdateFrequency, false);
607}
608
609void ABaseGrippableStoryActor::HandCrossDetection(float CurrentPitch, float RightLeftHandVPitch)
610{
611 const APixoVRCharacter* PlayerRef =Cast<APixoVRCharacter>(UGameplayStatics::GetPlayerPawn(GetWorld(),0));
612 FVector CameraRightHandV = PlayerRef->VRHandRight->GrabSphere->GetComponentLocation() - PlayerRef->VRReplicatedCamera->GetComponentLocation();
613 FVector CameraLeftHandV = PlayerRef->VRHandLeft->GrabSphere->GetComponentLocation() - PlayerRef->VRReplicatedCamera->GetComponentLocation();
614 if (!CameraRightHandV.Normalize())
615 GEngine->AddOnScreenDebugMessage(-1, 10.0, FColor::Orange, FString::Printf(TEXT("Bad normalization CameraRightHandV")));
616 if (!CameraLeftHandV.Normalize())
617 GEngine->AddOnScreenDebugMessage(-1, 10.0, FColor::Orange, FString::Printf(TEXT("Bad normalization CameraLeftHandV")));
618
619 FVector RightLeftHandV = CameraRightHandV + CameraLeftHandV;
620 if (!RightLeftHandV.Normalize())
621 GEngine->AddOnScreenDebugMessage(-1, 10.0, FColor::Orange, FString::Printf(TEXT("Bad normalization CameraLeftHandV")));
622
623 const FVector Cross = FVector::CrossProduct(CameraRightHandV, RightLeftHandV);
624 CrossDetected = Cross.Z > 0.f;
625 if (IPixoVRStoryObject::Execute_GetTwoHandProperties(this).EnableDebug)
626 {
627 GEngine->AddOnScreenDebugMessage(-1, 0.01, FColor::Orange, FString::Printf(TEXT("RightLeftHandV x - %f, y - %f, z - %f"), RightLeftHandV.X, RightLeftHandV.Y, RightLeftHandV.Z));
628 GEngine->AddOnScreenDebugMessage(-1, 0.01, FColor::Orange, FString::Printf(TEXT("VRHandRight x - %f, y - %f, z - %f"), PlayerRef->VRHandRight->GetActorLocation().X, PlayerRef->VRHandRight->GetActorLocation().Y, PlayerRef->VRHandRight->GetActorLocation().Z));
629 GEngine->AddOnScreenDebugMessage(-1, 0.01, FColor::Orange, FString::Printf(TEXT("CameraRightHandV x - %f, y - %f, z - %f"), CameraRightHandV.X, CameraRightHandV.Y, CameraRightHandV.Z));
630 GEngine->AddOnScreenDebugMessage(-1, 0.01, FColor::Orange, FString::Printf(TEXT("Z cross - %f"), Cross.Z));
631 }
633 {
634 PitchBeforeCross = CurrentPitch;
635 if (CrossDetected)
636 {
638 }
639 else
640 {
641 MoveBackPitchDelta = FMath::Abs(FMath::Abs(CurrentPitch) - FMath::Abs(RightLeftHandVPitch));
643 }
644 }
645}
EHandGripLogic
Enum representing the different hand grip logic options.
@ OnlyOnGripEvent
@ AttachToHandWithCustomTransform
@ NativeVRGripInterfaceSettings
@ AttachToHand
@ CustomTransformAttachWithPhysics
virtual void ReleaseTwoHands_Implementation(UMotionControllerComponent *ReleasingController) override
virtual void SendWrongGrabbingNotification_Implementation() override
Implementation of the SendErrorGrabbingNotification function from the IPixoVRStoryObject interface....
bool EnableOnePressDetach
TWeakObjectPtr< UMotionControllerComponent > TwoHandMainGrabController
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 PlayGripSound() const
float MoveBackPitchDelta
TWeakObjectPtr< APixoVRHand > PixoVRHandLeft
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....
FOnDroppedActorDeleted OnDroppedActorDeleted
UPROPERTY(BlueprintReadWrite, BlueprintCallable, BlueprintAssignable)
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...
float PitchBeforeCross
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....
bool StoryActivationAffectsDenyGripping
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "GrippableObject")
void AttachToHandObject(UGripMotionControllerComponent *GrippingController, const FBPActorGripInformation &GripInformation)
Attaches the object to a hand.
FTransform ResetTransform
UPROPERTY(BlueprintReadOnly, Category = "GrippableObject")
bool CrossChanged
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....
float TimeSinceResetTimerStarted
Time that accumulates after PositionResetTimer has started.
void StopPositionResetTimer()
Stopping the current position reset check timer.
void StartPositionResetTimer()
Stopping new position reset check timer.
EHandGripLogic HandGripLogic
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "GrippableObject")
void DetachObjectFromHand()
Detaches the object from the hand.
virtual void GrabWithTwoHands_Implementation(UMotionControllerComponent *GrabbingController) override
Two hand grabbing logic implementation.
void HandCrossDetection(float CurrentPitch, float RightLeftHandVPitch)
void CheckPositionResetConditions()
Checking if this object's position can be reset.
virtual FTransform GetObjectGrabTransform_Implementation(APixoVRHand *GrabbedHand) override
Implementation of the GetObjectGrabTransform function from the IPixoVRStoryObject interface....
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...
bool bGripSoundsEnabled
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "Feedback Effect")
USoundCue * ReleaseSoundCue
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "Feedback Effect", meta = (EditCondition = "bR...
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...
virtual void EnableOnePressDetach_Implementation(bool Enable) override
UStaticMeshComponent * StaticMeshComponent
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Components")
bool bDestroyActorAfterFailedDrop
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "GrippableObject")
virtual bool IsGrabbingWrongActorActive_Implementation() override
Implementation of the IsGrabbingWrongActorActive function from the IPixoVRStoryObject interface....
FVROnGripSignature OnGripped
UPROPERTY(BlueprintAssignable, Category = "Grip Events")
virtual EGripLateUpdateSettings GripLateUpdateSetting_Implementation() override
Implementation of the GripLateUpdateSetting function from the IVRGripInterface interface....
float TwoHandZAxisValue
void TwoHandGrab()
float PositionResetCheckRate
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "GrippableObject")
bool CrossDetected
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....
TWeakObjectPtr< APixoVRHand > PixoVRHandRight
virtual bool DenyGripping_Implementation(UGripMotionControllerComponent *GripInitiator=nullptr) override
Implementation of the DenyGripping function from the IVRGripInterface interface. Set up as deny inste...
USoundCue * GripSoundCue
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "Feedback Effect", meta = (EditCondition = "bG...
virtual bool IsObjectHeldWithTwoHands_Implementation() override
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")
float ResultedPitch
float PositionResetMaximumDelay
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "GrippableObject")
FTimerHandle PositionResetTimer
Internal timer for checking object's conditions for position reset.
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.
FBPInterfaceProperties VRGripInterfaceSettings
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VRGripInterface")
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....
bool bReleaseSoundsEnabled
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "Feedback Effect")
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 void ResetTwoHandsHoldingFunctionality_Implementation() override
void PlayReleaseSound() const
bool ObjectHeldWithTwoHands
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Two Hands Grip")
virtual bool AllowsMultipleGrips_Implementation() override
Implementation of the AllowsMultipleGrips function from the IVRGripInterface interface....
FTimerHandle TwoHandTimer
virtual void ObjectDeactivated_Implementation() override
Implementation of the ObjectDeactivated function from the IPixoVRStoryObject interface.
UStoryComponent * Story
UPROPERTY(BlueprintReadWrite, EditAnywhere)
UHighlightComponent * HighlightComponent
UPROPERTY(EditAnywhere, BlueprintReadWrite)
Pixo VR Character This class represents the main character in the Pixo VR game. It extends the AVRCha...
bool bActivateRightLaser
UPROPERTY(BlueprintReadOnly, Replicated)
bool bActivateLeftLaser
UPROPERTY(BlueprintReadOnly, Replicated)
APixoVRHand * VRHandLeft
UPROPERTY(BlueprintReadOnly, Category = "Hands")
APixoVRHand * VRHandRight
UPROPERTY(BlueprintReadOnly, Category = "Hands")
void ActivateLaserBeam(EControllerHand Hand, bool InActivate)
Activate/Deactivate the Laser-beam.
bool bLaserBeamActive
UPROPERTY(BlueprintReadWrite, Category = "PixoVR")
APixoVRHand is an actor class that represents a hand in the VR environment.
Definition PixoVRHand.h:99
UGripMotionControllerComponent * MotionController
UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = "Components")
Definition PixoVRHand.h:118
USphereComponent * GrabSphere
UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = "Components")
Definition PixoVRHand.h:124
EControllerHand HandMotionSource
UPROPERTY(BlueprintReadWrite, Category = "Init", meta = (ExposeOnSpawn = "true"))
Definition PixoVRHand.h:383
A custom player controller class for PixoVR.
void PlayHapticFeedback(bool RightHand, float Duration, float Strength)
UFUNCTION(BlueprintCallable, Category = "Haptic")
FOnWrongInteractableActorGrabbed OnWrongInteractableActorGrabbed
UPROPERTY(BlueprintReadWrite, BlueprintCallable, BlueprintAssignable)
bool bWrongInteractableActorGrabEnabled
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "GameManager|WrongActionFeedback")
FTimerHandle PulseHighlightTimerHandle
UPROPERTY(BlueprintReadWrite)
void UpdateHighlightValue(EHighlightColor HighlightColor)
Updates the highlight color of the object.
UGameManager * GameManager
UPROPERTY(BlueprintReadOnly, Category = "Story|Setup")
FOverlappingInfo is a structure that holds information about overlapping actors and components.
Definition PixoVRHand.h:22
AActor * OverlapActor
Definition PixoVRHand.h:29