233 lines
5.1 KiB
C++
233 lines
5.1 KiB
C++
/**
|
|
* @file
|
|
*
|
|
* @author Mamadou Babaei <mamadou@senseglove.com>
|
|
*
|
|
* @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
|
|
*
|
|
*
|
|
*/
|
|
|
|
|
|
#pragma once
|
|
|
|
#include "Containers/UnrealString.h"
|
|
#include "Math/Vector.h"
|
|
#include "Runtime/Launch/Resources/Version.h"
|
|
#include "Templates/UniquePtr.h"
|
|
|
|
#include "SGCoreImpl/SGPlatform.h"
|
|
|
|
namespace SGCore
|
|
{
|
|
namespace Kinematics
|
|
{
|
|
class Vect3D;
|
|
}
|
|
}
|
|
|
|
class SENSEGLOVECOREIMPL_API FSGVect3DImpl
|
|
{
|
|
public:
|
|
typedef SGCore::Kinematics::Vect3D FVect3DType;
|
|
|
|
public:
|
|
/**
|
|
* Represents a vector with coordinates (0, 0, 0).
|
|
*/
|
|
static const FSGVect3DImpl& Zero();
|
|
|
|
/**
|
|
* Serialize a FSGVect3DImpl into a string representation.
|
|
*/
|
|
static bool Deserialize(const FString& String, FSGVect3DImpl& OutResult, ANSICHAR Delimiter);
|
|
|
|
private:
|
|
struct FImpl;
|
|
|
|
struct FImplDeleter
|
|
{
|
|
void operator()(const FImpl* P) const;
|
|
};
|
|
|
|
TUniquePtr<FImpl, FImplDeleter> Pimpl;
|
|
FImplDeleter PimplDeleter;
|
|
|
|
public:
|
|
/**
|
|
* Creates an empty vector (0, 0, 0) for internal use.
|
|
*/
|
|
FSGVect3DImpl();
|
|
|
|
/**
|
|
* Create a new instance of a 3D vector.
|
|
*/
|
|
FSGVect3DImpl(float X, float Y, float Z);
|
|
|
|
public:
|
|
/**
|
|
* The cast from underlying type constructor.
|
|
*/
|
|
explicit FSGVect3DImpl(const FVect3DType& Vect3D);
|
|
|
|
/**
|
|
* The cast from FVector type constructor.
|
|
*/
|
|
explicit FSGVect3DImpl(const FVector& Vector);
|
|
|
|
public:
|
|
/**
|
|
* The copy constructor.
|
|
*/
|
|
FSGVect3DImpl(const FSGVect3DImpl& Rhs);
|
|
|
|
/**
|
|
* The move constructor.
|
|
*/
|
|
FSGVect3DImpl(FSGVect3DImpl&& Rhs)
|
|
#if SG_CPP17
|
|
noexcept
|
|
#endif /* SG_CPP17 */
|
|
;
|
|
|
|
public:
|
|
/**
|
|
* The destructor.
|
|
*/
|
|
virtual ~FSGVect3DImpl();
|
|
|
|
public:
|
|
/**
|
|
* The copy assignment operator.
|
|
*/
|
|
FSGVect3DImpl& operator=(const FSGVect3DImpl& Rhs);
|
|
|
|
/**
|
|
* The move assignment operator.
|
|
*/
|
|
FSGVect3DImpl& operator=(FSGVect3DImpl&& Rhs)
|
|
#if SG_CPP17
|
|
noexcept
|
|
#endif /* SG_CPP17 */
|
|
;
|
|
|
|
public:
|
|
/**
|
|
* The cast to underlying type method.
|
|
*/
|
|
const FVect3DType& ToVect3D() const;
|
|
|
|
/**
|
|
* The cast to FVector type method.
|
|
*/
|
|
FVector ToFVector() const;
|
|
|
|
public:
|
|
/**
|
|
* Overload + operator to add two SGVect3Impl objects.
|
|
*/
|
|
FSGVect3DImpl operator+(const FSGVect3DImpl& Vect3DImpl) const;
|
|
|
|
/**
|
|
* Overload - operator to subtract two SGVect3Impl objects.
|
|
*/
|
|
FSGVect3DImpl operator-(const FSGVect3DImpl& Vect3DImpl) const;
|
|
|
|
/**
|
|
* Overload - operator to scale a vector3 by a float.
|
|
*/
|
|
FSGVect3DImpl operator*(const float& ScaleFactor) const;
|
|
|
|
public:
|
|
/**
|
|
* Get the x-component of the 3D vector in cm.
|
|
*/
|
|
float GetX() const;
|
|
|
|
/**
|
|
* Set the x-component of the 3D vector in cm.
|
|
*/
|
|
void SetX(float X);
|
|
|
|
/**
|
|
* Get the y-component of the 3D vector in cm.
|
|
*/
|
|
float GetY() const;
|
|
|
|
/**
|
|
* Set the y-component of the 3D vector in cm.
|
|
*/
|
|
void SetY(float Y);
|
|
|
|
/**
|
|
* Get the z-component of the 3D vector in cm.
|
|
*/
|
|
float GetZ() const;
|
|
|
|
/**
|
|
* Set the z-component of the 3D vector in cm.
|
|
*/
|
|
void SetZ(float Z);
|
|
|
|
public:
|
|
/**
|
|
* Calculate the magnitude or 'length' of this Vector in cm.
|
|
*/
|
|
float Magnitude() const;
|
|
|
|
/**
|
|
* Returns this vector normalized to have a Magnitude on 1.
|
|
*/
|
|
void Normalize();
|
|
|
|
/**
|
|
* Scale all elements of this vector by a certain factor.
|
|
*/
|
|
void Scale(float Factor);
|
|
|
|
/**
|
|
* Calculate the distance between this Vector and another one in cm.
|
|
*/
|
|
float DistTo(const FSGVect3DImpl& Vect3DImpl) const;
|
|
|
|
/**
|
|
* Check if this Vector is roughly equal to another.
|
|
*/
|
|
bool Equals(const FSGVect3DImpl& Vect3DImpl) const;
|
|
|
|
/**
|
|
* Create a string representation of this Vector.
|
|
*/
|
|
FString ToString() const;
|
|
|
|
public:
|
|
/**
|
|
* Convert a serialized FSGVect3DImpl back into its class representation.
|
|
*/
|
|
FString Serialize(ANSICHAR Delimiter) const;
|
|
};
|