From 2819d1ee1ccc4aa020bfad10ca72f75dc2e165d6 Mon Sep 17 00:00:00 2001 From: Mamadou Babaei Date: Mon, 24 Apr 2023 08:45:35 +0200 Subject: [PATCH] add the base implementation for the senseglove grab component --- .../SenseGlove/Components/SGGrabComponent.cpp | 102 ++++++++++++++++++ .../SenseGlove/Components/SGGrabComponent.h | 65 +++++++++++ .../SGKismet/SGGrabComponentKismetLibrary.cpp | 46 ++++++++ .../SGKismet/SGGrabComponentKismetLibrary.h | 55 ++++++++++ 4 files changed, 268 insertions(+) create mode 100644 Source/SenseGlove/Private/SenseGlove/Components/SGGrabComponent.cpp create mode 100644 Source/SenseGlove/Public/SenseGlove/Components/SGGrabComponent.h create mode 100644 Source/SenseGloveKismet/Private/SGKismet/SGGrabComponentKismetLibrary.cpp create mode 100644 Source/SenseGloveKismet/Public/SGKismet/SGGrabComponentKismetLibrary.h diff --git a/Source/SenseGlove/Private/SenseGlove/Components/SGGrabComponent.cpp b/Source/SenseGlove/Private/SenseGlove/Components/SGGrabComponent.cpp new file mode 100644 index 00000000..dea60f6c --- /dev/null +++ b/Source/SenseGlove/Private/SenseGlove/Components/SGGrabComponent.cpp @@ -0,0 +1,102 @@ +/** + * @file + * + * @author Mamadou Babaei + * + * @section LICENSE + * + * (The MIT License) + * + * Copyright (c) 2020 - 2023 SenseGlove + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * @section DESCRIPTION + * + * + */ + + +#include "SenseGlove/Components/SGGrabComponent.h" + +struct USGGrabComponent::FImpl +{ + /************************ + * Static methods + ************************/ + + /************************ + * Owner object + ************************/ + + USGGrabComponent* Owner; + + /************************ + * Constructor / Destructor + ************************/ + + explicit FImpl(USGGrabComponent* InOwner); + ~FImpl(); + + /************************ + * Default copy constructor & copy assignment operator + ************************/ + + FImpl(const FImpl& Rhs) = default; + FImpl& operator=(const FImpl& Rhs) = default; + + /************************ + * Methods + ************************/ +}; + +bool USGGrabComponent::IsGrabbable(const AActor* Actor) +{ + if (ensureAlwaysMsgf(IsValid(Actor), TEXT("%s"), TEXT("ERROR: invalid actor!"))) + { + return false; + } + + const USGGrabComponent* GrabComponent = Cast( + Actor->GetComponentByClass(USGGrabComponent::StaticClass())); + if (!IsValid(GrabComponent)) + { + return false; + } + + return true; +} + +USGGrabComponent::USGGrabComponent(const FObjectInitializer& ObjectInitializer) + : Super(ObjectInitializer), + Pimpl(TUniquePtr(new FImpl{this}, PimplDeleter)) +{ +} + +USGGrabComponent::FImpl::FImpl(USGGrabComponent* InOwner) + : Owner(InOwner) +{ +} + +USGGrabComponent::FImpl::~FImpl() = default; + +void USGGrabComponent::FImplDeleter::operator()(const FImpl* P) const +{ + delete P; +} \ No newline at end of file diff --git a/Source/SenseGlove/Public/SenseGlove/Components/SGGrabComponent.h b/Source/SenseGlove/Public/SenseGlove/Components/SGGrabComponent.h new file mode 100644 index 00000000..58f8d9bc --- /dev/null +++ b/Source/SenseGlove/Public/SenseGlove/Components/SGGrabComponent.h @@ -0,0 +1,65 @@ +/** + * @file + * + * @author Mamadou Babaei + * + * @section LICENSE + * + * (The MIT License) + * + * Copyright (c) 2020 - 2023 SenseGlove + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * @section DESCRIPTION + * + * + */ + + +#pragma once + +#include "Components/SceneComponent.h" +#include "Templates/UniquePtr.h" + +#include "SGGrabComponent.generated.h" + +class AActor; + +UCLASS(Blueprintable, BlueprintType, meta=(BlueprintSpawnableComponent)) +class SENSEGLOVE_API USGGrabComponent : public USceneComponent +{ + GENERATED_UCLASS_BODY() + +public: + static bool IsGrabbable(const AActor* Actor); + +private: + struct FImpl; + + struct FImplDeleter + { + void operator()(const FImpl* P) const; + }; + + TUniquePtr Pimpl; + FImplDeleter PimplDeleter; + +public: +}; \ No newline at end of file diff --git a/Source/SenseGloveKismet/Private/SGKismet/SGGrabComponentKismetLibrary.cpp b/Source/SenseGloveKismet/Private/SGKismet/SGGrabComponentKismetLibrary.cpp new file mode 100644 index 00000000..6969783b --- /dev/null +++ b/Source/SenseGloveKismet/Private/SGKismet/SGGrabComponentKismetLibrary.cpp @@ -0,0 +1,46 @@ + +/** + * @file + * + * @author Mamadou Babaei + * + * @section LICENSE + * + * (The MIT License) + * + * Copyright (c) 2020 - 2023 SenseGlove + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * @section DESCRIPTION + * + * A data class containing the minimum required data for a hand's forward + * kinematics. + * Used in both kinematics and calibration. + */ + + +#include "SGKismet/SGGrabComponentKismetLibrary.h" + +#include "SenseGlove/Components/SGGrabComponent.h" + +bool UGrabComponentKismetLibrary::IsGrabbable(const AActor* Actor) +{ + return USGGrabComponent::IsGrabbable(Actor); +} \ No newline at end of file diff --git a/Source/SenseGloveKismet/Public/SGKismet/SGGrabComponentKismetLibrary.h b/Source/SenseGloveKismet/Public/SGKismet/SGGrabComponentKismetLibrary.h new file mode 100644 index 00000000..286ff74d --- /dev/null +++ b/Source/SenseGloveKismet/Public/SGKismet/SGGrabComponentKismetLibrary.h @@ -0,0 +1,55 @@ +/** + * @file + * + * @author Mamadou Babaei + * + * @section LICENSE + * + * (The MIT License) + * + * Copyright (c) 2020 - 2023 SenseGlove + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * @section DESCRIPTION + * + * A data class containing the minimum required data for a hand's forward + * kinematics. + * Used in both kinematics and calibration. + */ + + +#pragma once + +#include "SGKismet/SGBlueprintFunctionLibrary.h" + +#include "SGGrabComponentKismetLibrary.generated.h" + +class AActor; +class UGrabComponent; + +UCLASS(meta=(ScriptName = "SesneGloveGrabComponentKismetLibrary")) +class SENSEGLOVEKISMET_API UGrabComponentKismetLibrary final : public USGBlueprintFunctionLibrary +{ + GENERATED_BODY() + +public: + UFUNCTION(BlueprintCallable, Category="SenseGlove | Components | Grab Component") + static bool IsGrabbable(const AActor* Actor); +}; \ No newline at end of file