diff --git a/CHANGELOG.md b/CHANGELOG.md index a783d49d..0a518892 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added + +- A new generic SenseGlove Debug module. + ### Fixed - Fix the wrist tracker miscalculations. @@ -141,4 +145,4 @@ This is a minor release focusing on adherence to the Unreal Engine Marketplace G ### Added -- Initial public release of the SenseGlove haptic API for Unreal Engine with support for Microsoft Windows and GNU/Linux. +- Initial public release of the SenseGlove haptic API for Unreal Engine with support for Microsoft Windows and GNU/Linux. \ No newline at end of file diff --git a/SenseGlove.uplugin b/SenseGlove.uplugin index 937b2055..c48eaef0 100644 --- a/SenseGlove.uplugin +++ b/SenseGlove.uplugin @@ -121,6 +121,16 @@ "Win64" ] }, + { + "Name": "SenseGloveDebug", + "Type": "Runtime", + "LoadingPhase": "PreDefault", + "WhitelistPlatforms": [ + "Android", + "Linux", + "Win64" + ] + }, { "Name": "SenseGloveEditor", "Type": "Editor", diff --git a/Source/SenseGlove/Private/SenseGlove/Components/SGWristTrackerComponent.cpp b/Source/SenseGlove/Private/SenseGlove/Components/SGWristTrackerComponent.cpp index fd888c76..43b6149a 100644 --- a/Source/SenseGlove/Private/SenseGlove/Components/SGWristTrackerComponent.cpp +++ b/Source/SenseGlove/Private/SenseGlove/Components/SGWristTrackerComponent.cpp @@ -37,15 +37,14 @@ #include "Animation/Skeleton.h" #include "Components/SkeletalMeshComponent.h" -#include "DrawDebugHelpers.h" #include "Engine/SkeletalMesh.h" -#include "Kismet/GameplayStatics.h" #include "UObject/ConstructorHelpers.h" #include "SGConnect/SGConnect.h" #include "SGCore/SGDeviceList.h" #include "SGCore/SGHapticGlove.h" #include "SGCore/SGHapticGloveHandProfiles.h" +#include "SGDebug/SGDebugGizmo.h" #include "SGLog/SGLog.h" #include "SGSettings/SGSettings.h" @@ -747,27 +746,19 @@ void USGWristTrackerComponent::FImpl::UpdateWristTrackingData() const void USGWristTrackerComponent::FImpl::DrawDebugGizmo() { - const UWorld* World{Owner->GetWorld()}; const FVector& Location{Owner->GetComponentLocation()}; const FRotator& Rotation{Owner->GetComponentRotation()}; const float Length = Owner->GetDebugWristTrackerGizmoLength(); const bool bPersistentLines = Owner->GetDebugWristTrackerGizmoPersistentLines(); - const float LifeTime = UGameplayStatics::GetWorldDeltaSeconds(World) - * Owner->GetDebugWristTrackerGizmoLifeTimeModifier(); + const float LifeTimeModifier = Owner->GetDebugWristTrackerGizmoLifeTimeModifier(); const float DepthPriority = Owner->GetDebugWristTrackerGizmoDepthPriority(); const float Thickness = Owner->GetDebugWristTrackerGizmoThickness(); const FColor& XAxisColor{Owner->GetDebugWristTrackerGizmoXAxisColor()}; const FColor& YAxisColor{Owner->GetDebugWristTrackerGizmoYAxisColor()}; const FColor& ZAxisColor{Owner->GetDebugWristTrackerGizmoZAxisColor()}; - const FVector XAxisLineEnd(Location + Rotation.RotateVector(FVector(Length, 0.0f, 0.0f))); - DrawDebugLine(World, Location, XAxisLineEnd, XAxisColor, bPersistentLines, LifeTime, DepthPriority, Thickness); - - const FVector YAxisLineEnd(Location + Rotation.RotateVector(FVector{0.0f, Length, 0.0f})); - DrawDebugLine(World, Location, YAxisLineEnd, YAxisColor, bPersistentLines, LifeTime, DepthPriority, Thickness); - - const FVector ZAxisLineEnd{Location + Rotation.RotateVector(FVector{0.0f, 0.0f, Length})}; - DrawDebugLine(World, Location, ZAxisLineEnd, ZAxisColor, bPersistentLines, LifeTime, DepthPriority, Thickness); + FSGDebugGizmo::Draw(Location, Rotation, Length, Thickness, XAxisColor, YAxisColor, ZAxisColor, + bPersistentLines, LifeTimeModifier, DepthPriority); } void USGWristTrackerComponent::FImplDeleter::operator()(const FImpl* P) const diff --git a/Source/SenseGlove/SenseGlove.Build.cs b/Source/SenseGlove/SenseGlove.Build.cs index 4835cb81..b328ec42 100644 --- a/Source/SenseGlove/SenseGlove.Build.cs +++ b/Source/SenseGlove/SenseGlove.Build.cs @@ -58,6 +58,7 @@ public class SenseGlove : ModuleRules "HeadMountedDisplay", "SenseGloveConnect", "SenseGloveCore", + "SenseGloveDebug", "SenseGloveLog", "SenseGloveSettings", "SenseGloveTypes", diff --git a/Source/SenseGloveDebug/Private/SGDebug/SGDebugGizmo.cpp b/Source/SenseGloveDebug/Private/SGDebug/SGDebugGizmo.cpp new file mode 100644 index 00000000..46a15e00 --- /dev/null +++ b/Source/SenseGloveDebug/Private/SGDebug/SGDebugGizmo.cpp @@ -0,0 +1,67 @@ +/** + * @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 "SGDebug/SGDebugGizmo.h" + +#include "DrawDebugHelpers.h" +#include "Engine/Engine.h" +#include "Kismet/GameplayStatics.h" +#include "Math/Color.h" +#include "Math/Rotator.h" +#include "Math/Vector.h" + +void FSGDebugGizmo::Draw( + const FVector& Location, const FRotator& Rotation, + const float Length, const float Thickness, + const FColor& XAxisColor, const FColor& YAxisColor, const FColor& ZAxisColor, + const bool bPersistentLines, const float LifeTimeModifier, const uint8 DepthPriority) +{ + if (!GEngine) + { + return; + } + + const UWorld* World{GEngine->GetWorld()}; + const float LifeTime = UGameplayStatics::GetWorldDeltaSeconds(World) * LifeTimeModifier; + + const FVector XAxisLineEnd(Location + Rotation.RotateVector(FVector(Length, 0.0f, 0.0f))); + DrawDebugLine(World, Location, XAxisLineEnd, XAxisColor, bPersistentLines, LifeTime, DepthPriority, Thickness); + + const FVector YAxisLineEnd(Location + Rotation.RotateVector(FVector{0.0f, Length, 0.0f})); + DrawDebugLine(World, Location, YAxisLineEnd, YAxisColor, bPersistentLines, LifeTime, DepthPriority, Thickness); + + const FVector ZAxisLineEnd{Location + Rotation.RotateVector(FVector{0.0f, 0.0f, Length})}; + DrawDebugLine(World, Location, ZAxisLineEnd, ZAxisColor, bPersistentLines, LifeTime, DepthPriority, Thickness); +} \ No newline at end of file diff --git a/Source/SenseGloveDebug/Private/SenseGloveDebug.cpp b/Source/SenseGloveDebug/Private/SenseGloveDebug.cpp new file mode 100644 index 00000000..6250ba53 --- /dev/null +++ b/Source/SenseGloveDebug/Private/SenseGloveDebug.cpp @@ -0,0 +1,42 @@ +/** + * @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 "SenseGloveDebug.h" + +#include "Modules/ModuleManager.h" + +#include "SenseGloveDebugModule.h" + +IMPLEMENT_MODULE(FSenseGloveDebugModule, SenseGloveDebug) diff --git a/Source/SenseGloveDebug/Private/SenseGloveDebug.h b/Source/SenseGloveDebug/Private/SenseGloveDebug.h new file mode 100644 index 00000000..60871018 --- /dev/null +++ b/Source/SenseGloveDebug/Private/SenseGloveDebug.h @@ -0,0 +1,38 @@ +/** + * @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 "CoreMinimal.h" \ No newline at end of file diff --git a/Source/SenseGloveDebug/Private/SenseGloveDebugModule.cpp b/Source/SenseGloveDebug/Private/SenseGloveDebugModule.cpp new file mode 100644 index 00000000..128d3524 --- /dev/null +++ b/Source/SenseGloveDebug/Private/SenseGloveDebugModule.cpp @@ -0,0 +1,62 @@ +/** + * @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 "SenseGloveDebugModule.h" + +#include "SGLog/SGLog.h" + +#define LOCTEXT_NAMESPACE "FSenseGloveDebugModule" + +void FSenseGloveDebugModule::StartupModule() +{ + SGLOG("Starting up SenseGloveDebug module..."); +} + +void FSenseGloveDebugModule::PreUnloadCallback() +{ + SGLOG("Unloading SenseGloveDebug module..."); +} + +void FSenseGloveDebugModule::PostLoadCallback() +{ + SGLOG("Loading of SenseGloveDebug module has succeeded!"); +} + +void FSenseGloveDebugModule::ShutdownModule() +{ + SGLOG("Shutting down SenseGloveDebug module..."); +} + +#undef LOCTEXT_NAMESPACE diff --git a/Source/SenseGloveDebug/Private/SenseGloveDebugModule.h b/Source/SenseGloveDebug/Private/SenseGloveDebugModule.h new file mode 100644 index 00000000..7a1bb13e --- /dev/null +++ b/Source/SenseGloveDebug/Private/SenseGloveDebugModule.h @@ -0,0 +1,51 @@ +/** + * @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 "Modules/ModuleInterface.h" + +#define LOCTEXT_NAMESPACE "SenseGloveDebug" + +class FSenseGloveDebugModule : public IModuleInterface +{ +public: + virtual void StartupModule() override; + virtual void PreUnloadCallback() override; + virtual void PostLoadCallback() override; + virtual void ShutdownModule() override; +}; + +#undef LOCTEXT_NAMESPACE diff --git a/Source/SenseGloveDebug/Public/SGDebug/SGDebugGizmo.h b/Source/SenseGloveDebug/Public/SGDebug/SGDebugGizmo.h new file mode 100644 index 00000000..e0f2eeec --- /dev/null +++ b/Source/SenseGloveDebug/Public/SGDebug/SGDebugGizmo.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 + * + * + */ + + +#pragma once + +class SENSEGLOVEDEBUG_API FSGDebugGizmo final +{ +public: + static void Draw( + const FVector& Location, const FRotator& Rotation, + float Length = 1.0f, + float Thickness = 1.0f, + const FColor& XAxisColor = FColor(1.0f, 0.0f, 0.0f, 1.0f), + const FColor& YAxisColor = FColor(0.0f, 1.0f, 0.0f, 1.0f), + const FColor& ZAxisColor = FColor(0.0f, 0.0f, 1.0f, 1.0f), + bool bPersistentLines = false, + float LifeTimeModifier = 1.1f, + uint8 DepthPriority = 0); + +public: + FSGDebugGizmo() = delete; + virtual ~FSGDebugGizmo() = delete; +}; \ No newline at end of file diff --git a/Source/SenseGloveDebug/SenseGloveDebug.Build.cs b/Source/SenseGloveDebug/SenseGloveDebug.Build.cs new file mode 100644 index 00000000..c616d541 --- /dev/null +++ b/Source/SenseGloveDebug/SenseGloveDebug.Build.cs @@ -0,0 +1,61 @@ +/** + * @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 + * + * + */ + + +using System; +using UnrealBuildTool; + +public class SenseGloveDebug : ModuleRules +{ + public SenseGloveDebug(ReadOnlyTargetRules Target) : base(Target) + { + PCHUsage = ModuleRules.PCHUsageMode.UseExplicitOrSharedPCHs; + + PublicDependencyModuleNames.AddRange( + new string[] + { + "Core", + } + ); + + PrivateDependencyModuleNames.AddRange( + new string[] + { + "CoreUObject", + "Engine", + "SenseGloveLog", + } + ); + } +}