/** * @file * * @author Max Lammers * @author Mamadou Babaei * * @section LICENSE * * Copyright (c) 2020 - 2022 SenseGlove * * @section DESCRIPTION * * Represents a position or rotation in 3D Space. */ #pragma once #include #include #include "Platform.hpp" namespace SGCore { namespace Kinematics { /// Represents a vector with x,y,z coordinates. class SGCORE_API Vect3D; }// namespace Kinematics }// namespace SGCore /// Represents a vector with x,y,z coordinates. class SGCORE_API SGCore::Kinematics::Vect3D { public: /// Represents a vector with coordinates (0.0f, 0.0f, 0.0f). static const Vect3D& Zero(); /// Deserialize a Vect3D into a string representation static bool Deserialize(const std::string& str, Vect3D& out_result, char delimiter); private: struct Impl; std::unique_ptr Pimpl; public: /// Creates an empty vector (0, 0, 0) for internal use Vect3D(); /// Create a new instance of a 3D vector. Vect3D(float x, float y, float z); /** * The copy constructor. */ Vect3D(const Vect3D& rhs); /** * The move constructor. */ Vect3D(Vect3D&& rhs) noexcept; /// The basic destructor. virtual ~Vect3D(); public: /** * The copy assignment operator. */ Vect3D& operator=(const Vect3D& rhs); /** * The move assignment operator. */ Vect3D& operator=(Vect3D&& rhs) noexcept; public: // Overload + operator to add two Vect3 objects. Vect3D operator+(const Vect3D& vect3D) const; // Overload - operator to subtract two Vect3 objects. Vect3D operator-(const Vect3D& vect3D) const; // Overload - operator to scale a vector3 by a float Vect3D operator*(const float& scaleFactor) const; public: #if !defined ( SENSEGLOVE_UNREAL_ENGINE_PLUGIN ) [[nodiscard]] #endif /* !defined ( SENSEGLOVE_UNREAL_ENGINE_PLUGIN ) */ float GetX() const; void SetX(float x); #if !defined ( SENSEGLOVE_UNREAL_ENGINE_PLUGIN ) [[nodiscard]] #endif /* !defined ( SENSEGLOVE_UNREAL_ENGINE_PLUGIN ) */ float GetY() const; void SetY(float y); #if !defined ( SENSEGLOVE_UNREAL_ENGINE_PLUGIN ) [[nodiscard]] #endif /* !defined ( SENSEGLOVE_UNREAL_ENGINE_PLUGIN ) */ float GetZ() const; void SetZ(float z); public: /// Calculate the magnitude or 'length' of this Vector #if !defined ( SENSEGLOVE_UNREAL_ENGINE_PLUGIN ) [[nodiscard]] #endif /* !defined ( SENSEGLOVE_UNREAL_ENGINE_PLUGIN ) */ 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. #if !defined ( SENSEGLOVE_UNREAL_ENGINE_PLUGIN ) [[nodiscard]] #endif /* !defined ( SENSEGLOVE_UNREAL_ENGINE_PLUGIN ) */ float DistTo(const Vect3D& vect3D) const; /// Check if this Vector is roughly equal to another. #if !defined ( SENSEGLOVE_UNREAL_ENGINE_PLUGIN ) [[nodiscard]] #endif /* !defined ( SENSEGLOVE_UNREAL_ENGINE_PLUGIN ) */ bool Equals(const Vect3D& vect3D) const; /// Create a string representation of this Vector. #if !defined ( SENSEGLOVE_UNREAL_ENGINE_PLUGIN ) [[nodiscard]] #endif /* !defined ( SENSEGLOVE_UNREAL_ENGINE_PLUGIN ) */ std::string ToString() const; public: /// Convert a serialized Vect3D back into its class representation. /// /// #if !defined ( SENSEGLOVE_UNREAL_ENGINE_PLUGIN ) [[nodiscard]] #endif /* !defined ( SENSEGLOVE_UNREAL_ENGINE_PLUGIN ) */ std::string Serialize(char delimiter) const; };