From 508ef0976e1cc02d2f3b306dbec567f7ae919774 Mon Sep 17 00:00:00 2001 From: Mamadou Babaei Date: Wed, 3 May 2023 14:13:13 +0200 Subject: [PATCH] add a touch component intended to be used for force-feedback --- .../Components/SGTouchComponent.cpp | 102 ++++++++++++++++++ .../SenseGlove/Components/SGTouchComponent.h | 65 +++++++++++ .../SGTouchComponentKismetLibrary.cpp | 46 ++++++++ .../SGKismet/SGTouchComponentKismetLibrary.h | 55 ++++++++++ 4 files changed, 268 insertions(+) create mode 100644 Source/SenseGlove/Private/SenseGlove/Components/SGTouchComponent.cpp create mode 100644 Source/SenseGlove/Public/SenseGlove/Components/SGTouchComponent.h create mode 100644 Source/SenseGloveKismet/Private/SGKismet/SGTouchComponentKismetLibrary.cpp create mode 100644 Source/SenseGloveKismet/Public/SGKismet/SGTouchComponentKismetLibrary.h diff --git a/Source/SenseGlove/Private/SenseGlove/Components/SGTouchComponent.cpp b/Source/SenseGlove/Private/SenseGlove/Components/SGTouchComponent.cpp new file mode 100644 index 00000000..75662e1c --- /dev/null +++ b/Source/SenseGlove/Private/SenseGlove/Components/SGTouchComponent.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/SGTouchComponent.h" + +struct USGTouchComponent::FImpl +{ + /************************ + * Static methods + ************************/ + + /************************ + * Owner object + ************************/ + + USGTouchComponent* Owner; + + /************************ + * Constructor / Destructor + ************************/ + + explicit FImpl(USGTouchComponent* InOwner); + ~FImpl(); + + /************************ + * Default copy constructor & copy assignment operator + ************************/ + + FImpl(const FImpl& Rhs) = default; + FImpl& operator=(const FImpl& Rhs) = default; + + /************************ + * Methods + ************************/ +}; + +bool USGTouchComponent::IsTouchable(const AActor* Actor) +{ + if (ensureAlwaysMsgf(IsValid(Actor), TEXT("%s"), TEXT("ERROR: invalid actor!"))) + { + return false; + } + + const USGTouchComponent* TouchComponent = Cast( + Actor->GetComponentByClass(USGTouchComponent::StaticClass())); + if (!IsValid(TouchComponent)) + { + return false; + } + + return true; +} + +USGTouchComponent::USGTouchComponent(const FObjectInitializer& ObjectInitializer) + : Super(ObjectInitializer), + Pimpl(TUniquePtr(new FImpl{this}, PimplDeleter)) +{ +} + +USGTouchComponent::FImpl::FImpl(USGTouchComponent* InOwner) + : Owner(InOwner) +{ +} + +USGTouchComponent::FImpl::~FImpl() = default; + +void USGTouchComponent::FImplDeleter::operator()(const FImpl* P) const +{ + delete P; +} \ No newline at end of file diff --git a/Source/SenseGlove/Public/SenseGlove/Components/SGTouchComponent.h b/Source/SenseGlove/Public/SenseGlove/Components/SGTouchComponent.h new file mode 100644 index 00000000..90516b18 --- /dev/null +++ b/Source/SenseGlove/Public/SenseGlove/Components/SGTouchComponent.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 "SGTouchComponent.generated.h" + +class AActor; + +UCLASS(Blueprintable, BlueprintType, meta=(BlueprintSpawnableComponent)) +class SENSEGLOVE_API USGTouchComponent : public USceneComponent +{ + GENERATED_UCLASS_BODY() + +public: + static bool IsTouchable(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/SGTouchComponentKismetLibrary.cpp b/Source/SenseGloveKismet/Private/SGKismet/SGTouchComponentKismetLibrary.cpp new file mode 100644 index 00000000..3a29e24a --- /dev/null +++ b/Source/SenseGloveKismet/Private/SGKismet/SGTouchComponentKismetLibrary.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/SGTouchComponentKismetLibrary.h" + +#include "SenseGlove/Components/SGTouchComponent.h" + +bool UTouchComponentKismetLibrary::IsTouchable(const AActor* Actor) +{ + return USGTouchComponent::IsTouchable(Actor); +} \ No newline at end of file diff --git a/Source/SenseGloveKismet/Public/SGKismet/SGTouchComponentKismetLibrary.h b/Source/SenseGloveKismet/Public/SGKismet/SGTouchComponentKismetLibrary.h new file mode 100644 index 00000000..482d5a96 --- /dev/null +++ b/Source/SenseGloveKismet/Public/SGKismet/SGTouchComponentKismetLibrary.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 "SGTouchComponentKismetLibrary.generated.h" + +class AActor; +class UTouchComponent; + +UCLASS(meta=(ScriptName = "SesneGloveTouchComponentKismetLibrary")) +class SENSEGLOVEKISMET_API UTouchComponentKismetLibrary final : public USGBlueprintFunctionLibrary +{ + GENERATED_BODY() + +public: + UFUNCTION(BlueprintCallable, Category="SenseGlove | Components | Touch Component") + static bool IsTouchable(const AActor* Actor); +}; \ No newline at end of file