From 6b0d87cad596fa6cefa3a32334a01dccb2eb8fd8 Mon Sep 17 00:00:00 2001 From: Mamadou Babaei Date: Wed, 14 Aug 2024 15:26:42 +0200 Subject: [PATCH] replace SGPawn::FImpl::EnableActorPhysics() and SGPawn::FImpl::DisableActorPhysics() with USGGrabComponent::SimulatePhysics() --- Handbook/src/appendix/changelog.md | 1 + .../SenseGlove/Components/SGGrabComponent.cpp | 45 ++++++++++++------- .../SenseGlove/GameFramework/SGPawn.cpp | 38 +--------------- .../SenseGlove/Components/SGGrabComponent.h | 3 ++ 4 files changed, 35 insertions(+), 52 deletions(-) diff --git a/Handbook/src/appendix/changelog.md b/Handbook/src/appendix/changelog.md index 3d3aea87..d88ddef0 100644 --- a/Handbook/src/appendix/changelog.md +++ b/Handbook/src/appendix/changelog.md @@ -40,6 +40,7 @@ This is a minor release focusing mainly on bringing OpenXR-compatible hand track - GetMotionControllerData() has been introduced to the USGVitualHandComponent in order to retrieve the OpenXR-compatible glove data in Unreal's FXRMotionControllerData format. - Added FSGVirtualHandAnimInstanceProxy::GetMotionControllerData and many more accessor methods usable only by child classes to allow consumption of the data required for manipulating the virtual hand mesh animations. - GetMotionControllerData() has been introduced to the USGWristTrackerComponent in order to retrieve the OpenXR-compatible glove data in Unreal's FXRMotionControllerData format. +- Added USGGrabComponent::SimulatePhysics() method. - Added FSGDebugCube. - Added FSGDebugCubeSettings. - Added the SenseGloveDebugKismet module in order to allow drawing of debugging, cubes, gizmos, and virtual hands from Blueprint. diff --git a/Source/SenseGlove/Private/SenseGlove/Components/SGGrabComponent.cpp b/Source/SenseGlove/Private/SenseGlove/Components/SGGrabComponent.cpp index b94bf03c..b265da5a 100644 --- a/Source/SenseGlove/Private/SenseGlove/Components/SGGrabComponent.cpp +++ b/Source/SenseGlove/Private/SenseGlove/Components/SGGrabComponent.cpp @@ -137,27 +137,40 @@ void USGGrabComponent::FImplDeleter::operator()(const FImpl* P) const delete P; } +void USGGrabComponent::SimulatePhysics(const bool bSimulatePhysics) const +{ + const AActor* OwnerActor{GetOwner()}; + if (!ensureAlwaysMsgf(IsValid(OwnerActor), TEXT("Invalid OwnerActor!"))) + { + return; + } + + UPrimitiveComponent* ActorRootComponent{Cast(OwnerActor->GetRootComponent())}; + if (!ensureAlwaysMsgf(IsValid(ActorRootComponent), + TEXT("RootComponent is not a valid UPrimativeComponent!"))) + { + return; + } + + ActorRootComponent->SetEnableGravity(bSimulatePhysics); + ActorRootComponent->SetSimulatePhysics(bSimulatePhysics); + + if (bSimulatePhysics) + { + ActorRootComponent->WakeRigidBody(); + } + else + { + ActorRootComponent->PutRigidBodyToSleep(); + } +} + void USGGrabComponent::BeginPlay() { Super::BeginPlay(); if (bAffectPhysicsState) { - const AActor* OwnerActor{GetOwner()}; - if (!ensureAlwaysMsgf(IsValid(OwnerActor), TEXT("Invalid OwnerActor!"))) - { - return; - } - - UPrimitiveComponent* ActorRootComponent{Cast(OwnerActor->GetRootComponent())}; - if (!ensureAlwaysMsgf(IsValid(ActorRootComponent), - TEXT("RootComponent is not a valid UPrimativeComponent!"))) - { - return; - } - - ActorRootComponent->SetEnableGravity(true); - ActorRootComponent->SetSimulatePhysics(true); - ActorRootComponent->WakeRigidBody(); + SimulatePhysics(true); } } \ No newline at end of file diff --git a/Source/SenseGlove/Private/SenseGlove/GameFramework/SGPawn.cpp b/Source/SenseGlove/Private/SenseGlove/GameFramework/SGPawn.cpp index 75a85403..f5ce1c99 100644 --- a/Source/SenseGlove/Private/SenseGlove/GameFramework/SGPawn.cpp +++ b/Source/SenseGlove/Private/SenseGlove/GameFramework/SGPawn.cpp @@ -138,9 +138,6 @@ struct ASGPawn::FImpl return Owner->RightHandOverlappedActors.Num() > 0; } - void DisableActorPhysics(const AActor* Actor) const; - void EnableActorPhysics(const AActor* Actor) const; - void ApplyHandVelocityToGrabbedActor(const FSGGrabState& GrabState) const; void SetGrabbedActor(FSGGrabState& GrabState, AActor* Actor) const; @@ -1723,7 +1720,7 @@ void ASGPawn::Grab(USGVirtualHandComponent* Hand, AActor* Actor) if (GrabComponent->GetAffectPhysicsState()) { - Pimpl->DisableActorPhysics(Actor); + GrabComponent->SimulatePhysics(false); } if (Hand->IsRight()) @@ -2152,37 +2149,6 @@ void ASGPawn::FImpl::SetAllFingersColliderCollisionEnabled(const bool bRight, co } } -void ASGPawn::FImpl::DisableActorPhysics(const AActor* Actor) const -{ - UPrimitiveComponent* ActorRootComponent{Cast(Actor->GetRootComponent())}; - if (!ensureAlwaysMsgf(IsValid(ActorRootComponent), TEXT("RootComponent is not a valid UPrimativeComponent!"))) - { - return; - } - - ActorRootComponent->SetEnableGravity(false); - ActorRootComponent->SetSimulatePhysics(false); - ActorRootComponent->PutRigidBodyToSleep(); -} - -void ASGPawn::FImpl::EnableActorPhysics(const AActor* Actor) const -{ - if (!IsValid(Actor)) - { - return; - } - - UPrimitiveComponent* ActorRootComponent{Cast(Actor->GetRootComponent())}; - if (!ensureAlwaysMsgf(IsValid(ActorRootComponent), TEXT("RootComponent is not a valid UPrimativeComponent!"))) - { - return; - } - - ActorRootComponent->SetEnableGravity(true); - ActorRootComponent->SetSimulatePhysics(true); - ActorRootComponent->WakeRigidBody(); -} - void ASGPawn::FImpl::ApplyHandVelocityToGrabbedActor(const FSGGrabState& GrabState) const { if (!IsValid(GrabState.Hand)) @@ -2271,7 +2237,7 @@ void ASGPawn::FImpl::Release(FSGGrabState& GrabState) const if (GrabComponent->GetAffectPhysicsState()) { - EnableActorPhysics(GrabState.GrabbedActor); + GrabComponent->SimulatePhysics(true); } ApplyHandVelocityToGrabbedActor(GrabState); diff --git a/Source/SenseGlove/Public/SenseGlove/Components/SGGrabComponent.h b/Source/SenseGlove/Public/SenseGlove/Components/SGGrabComponent.h index 3cfe8ca2..e9bb06f1 100644 --- a/Source/SenseGlove/Public/SenseGlove/Components/SGGrabComponent.h +++ b/Source/SenseGlove/Public/SenseGlove/Components/SGGrabComponent.h @@ -197,6 +197,9 @@ public: bAffectPhysicsState = bInAffectPhysicsState; } +public: + virtual void SimulatePhysics(bool bSimulatePhysics) const; + public: virtual void BeginPlay() override; }; \ No newline at end of file