/** * @file * * @author Mamadou Babaei * * @section LICENSE * * (The MIT License) * * Copyright (c) 2020 - 2022 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 * * Data class containing all variables to draw or analyze a virtual hand * in different formats. */ #pragma once #include "Containers/Array.h" #include "Containers/UnrealString.h" #include "Math/Quat.h" #include "Math/Vector.h" #include "Templates/UniquePtr.h" #include "UObject/Object.h" #include "UObject/ObjectMacros.h" #include "SGCore/SGQuatArray.h" #include "SGCore/SGRotatorArray.h" #include "SGCore/SGVectorArray.h" #include "SGTypes/SGCoreTypes.h" #include "SGHandPose.generated.h" class USGBasicHandModel; class FSGHandPoseImpl; class USGHandPose; /** * Contains all variables required to draw or analyze a virtual hand. */ UCLASS(BlueprintType) class SENSEGLOVECORE_API USGHandPose final : public UObject { GENERATED_BODY() public: static USGHandPose* NewHandPose( UObject* Outer, const FSGHandPoseImpl& HandPoseImpl); public: /** * The default constructor. */ static USGHandPose* NewHandPose(UObject* Outer); static USGHandPose* NewHandPose( UObject* Outer, bool bRightHanded, const TArray>& JointPositions, const TArray>& JointRotations, const TArray>& HandAngles); /** * Create a new instance of HandPose. */ static USGHandPose* NewHandPose( UObject* Outer, bool bRightHanded, const TArray>& JointPositions, const TArray>& JointRotations, const TArray>& HandAngles); /** * Create a new instance of HandPose. */ static USGHandPose* NewHandPose( UObject* Outer, bool bRightHanded, const TArray& JointPositions, const TArray& JointRotations, const TArray& HandAngles); /** * Create a new instance of HandPose. */ static USGHandPose* NewHandPose( UObject* Outer, bool bRightHanded, const TArray& JointPositions, const TArray& JointRotations, const TArray& HandAngles); public: /** * Deserialize a HandPose back into usable values. */ static USGHandPose* Deserialize(UObject* Outer, const FString& SerializedString); /** * Generate a HandPose based on articulation angles (handAngles). */ static USGHandPose* FromHandAngles(UObject* Outer, const TArray>& HandAngles, bool bRightHanded, const USGBasicHandModel* HandDimensions); /** * Generate a HandPose based on articulation angles (handAngles), with a default HandModel. */ static USGHandPose* FromHandAngles(UObject* Outer, const TArray>& HandAngles, bool bRightHanded); /** * Create a new instance of a left or right handed Pose that is "idle"; in a neutral position. */ static USGHandPose* DefaultIdle(UObject* Outer, bool bRightHanded, const USGBasicHandModel* HandDimensions); /** * Create a new instance of a left or right handed Pose that is "idle"; in a neutral position. */ static USGHandPose* DefaultIdle(UObject* Outer, bool bRightHanded); /** * Generates a HandPose representing an 'open hand', used in calibration to determine finger extension. */ static USGHandPose* FlatHand(UObject* Outer, bool bRightHanded, const USGBasicHandModel* HandDimensions); /** * Generates a HandPose representing an 'open hand', used in calibration to determine finger extension. */ static USGHandPose* FlatHand(UObject* Outer, bool bRightHanded); /** * Generates a HandPose representing a 'thumbs up', used in calibration to determine finger flexion, thumb extension and adduction. */ static USGHandPose* ThumbsUp(UObject* Outer, bool bRightHanded, const USGBasicHandModel* HandDimensions); /** * Generates a HandPose representing a 'thumbs up', used in calibration to determine finger flexion, thumb extension and adduction. */ static USGHandPose* ThumbsUp(UObject* Outer, bool bRightHanded); /** * Generates a HandPose representing a 'fist', used in calibration to determine, thumb flexion and abduction. */ static USGHandPose* Fist(UObject* Outer, bool bRightHanded, const USGBasicHandModel* HandDimensions); /** * Generates a HandPose representing a 'fist', used in calibration to determine, thumb flexion and abduction. */ static USGHandPose* Fist(UObject* Outer, bool bRightHanded); private: struct FImpl; struct FImplDeleter { void operator()(const FImpl* P) const; }; TUniquePtr Pimpl; FImplDeleter PimplDeleter; public: /** * The default constructor. */ USGHandPose(); /** * Create a new instance of HandPose. */ USGHandPose(bool bRightHanded, const TArray>& JointPositions, const TArray>& JointRotations, const TArray>& HandAngles); /** * Create a new instance of HandPose. */ USGHandPose(bool bRightHanded, const TArray>& JointPositions, const TArray>& JointRotations, const TArray>& HandAngles); /** * Create a new instance of HandPose. */ USGHandPose(bool bRightHanded, const TArray& JointPositions, const TArray& JointRotations, const TArray& HandAngles); /** * */ USGHandPose(bool bRightHanded, const TArray& JointPositions, const TArray& JointRotations, const TArray& HandAngles); public: /** * The cast from underlying type constructor. */ explicit USGHandPose(const FSGHandPoseImpl& HandPoseImpl); public: /** * The destructor. */ virtual ~USGHandPose() override; protected: /** * Allows to set the underlying object after construction. */ void SetHandPoseImpl(const FSGHandPoseImpl& HandPoseImpl); public: /** * The cast to underlying type method. */ const FSGHandPoseImpl& ToHandPoseImpl() const; public: /** * Whether this HandPose was created to be a right- or left hand. */ bool IsRight() const; /** * Positions of all hand joints relative to the Sense Glove origin. From thumb to pinky, proximal to distal. */ TArray> GetJointPositions() const; /** * Quaternion rotations of all hand joints. From thumb to pinky, proximal to distal. */ TArray> GetJointRotationsQ() const; /** * Rotations of all hand joints. From thumb to pinky, proximal to distal. */ TArray> GetJointRotations() const; /** * Euler representations of all possible hand angles. From thumb to pinky, proximal to distal. */ TArray> GetHandAngles() const; public: /** * Returns true of these two hand poses are roughly equal. */ bool Equals(const USGHandPose* HandPose) const; /** * Returns the total flexion of a specific finger as a value between 0 (fully extended) and 1 (fully flexed). * * @remarks Useful for animation or for detecting gestures. */ float GetNormalizedFlexion(ESGFinger Finger, bool bClamp01 = true) const; /** * Returns the total flexion of a specific finger as a value between 0 (fully extended) and 1 (fully flexed). * * @remarks Useful for animation or for detecting gestures. */ TArray GetNormalizedFlexion(bool bClamp01 = true) const; public: /** * */ FString ToString(bool bShortFormat = false) const; /** * Serialize this HandPose into a string representation. */ FString SGSerialize() const; };