685 TVector3(
const SizeType InX,
const SizeType InY,
const SizeType InZ)
699 #if LK_MATH_VECTOR3_EXPLICIT_GLM_CONSTRUCTOR
700 explicit TVector3(
const glm::vec3& InVec)
704 : X(
static_cast<SizeType
>(InVec.x))
705 , Y(
static_cast<SizeType
>(InVec.y))
706 , Z(
static_cast<SizeType
>(InVec.z))
712 #if LK_MATH_VECTOR3_EXPLICIT_GLM_CONSTRUCTOR
715 X =
static_cast<SizeType
>(Other.X);
716 Y =
static_cast<SizeType
>(Other.Y);
717 Z =
static_cast<SizeType
>(Other.Z);
721 TVector3& operator=(
const glm::vec3& Other)
723 X =
static_cast<SizeType
>(Other.x);
724 Y =
static_cast<SizeType
>(Other.y);
725 Z =
static_cast<SizeType
>(Other.z);
738 TVector3& operator+=(
const glm::vec3& Other)
754 TVector3& operator-=(
const glm::vec3& Other)
764 return TVector3((X + Other.X), (Y + Other.Y), (Z + Other.Z));
767 TVector3 operator+(
const glm::vec3& Other)
const
769 return TVector3((X + Other.x), (Y + Other.y), (Z + Other.z));
774 return TVector3((X - Other.X), (Y - Other.Y), (Z - Other.Z));
777 TVector3 operator-(
const glm::vec3& Other)
const
779 return TVector3((X - Other.x), (Y - Other.y), (Z - Other.z));
782 TVector3 operator/(
const float Value)
const
784 LK_CORE_ASSERT(Value != 0.0f,
"Division by zero");
785 return TVector3((X / Value), (Y / Value), (Z / Value));
790 LK_CORE_ASSERT((Other.X != 0.0f) && (Other.Y != 0.0f) && (Other.Z != 0.0f),
"Division by zero");
791 return TVector3((X / Other.X), (Y / Other.Y), (Z / Other.Z));
794 TVector3 operator/(
const glm::vec3& Other)
const
796 LK_CORE_ASSERT((Other.x != 0.0f) && (Other.y != 0.0f) && (Other.z != 0.0f),
"Division by zero");
797 return TVector3((X / Other.x), (Y / Other.y), (Z / Other.z));
800 TVector3 operator*(
const float Value)
const
806 return TVector3((X * Value), (Y * Value), (Z * Value));
811 return TVector3((X * Other.X), (Y * Other.Y), (Z * Other.Z));
814 TVector3 operator*(
const glm::vec3& Other)
const
816 return TVector3((X * Other.x), (Y * Other.y), (Z * Other.z));
819 bool operator==(
const TVector3& Other)
const
821 #if defined(LK_MATH_VECTOR3_BOOL_OPERATOR_USE_EPSILON)
822 static constexpr SizeType Epsilon =
static_cast<SizeType
>(1e-5);
823 return ((std::abs(X - Other.X) < Epsilon)
824 && (std::abs(Y - Other.Y)) < Epsilon)
825 && (std::abs(Z - Other.Z) < Epsilon));
827 return ((X == Other.X) && (Y == Other.Y) && (Z == Other.Z));
831 bool operator!=(
const TVector3& Other)
const
833 return !(*
this == Other);
836 bool operator==(
const glm::vec3& Other)
const
838 #if defined(LK_MATH_VECTOR3_BOOL_OPERATOR_USE_EPSILON)
839 static constexpr SizeType Epsilon =
static_cast<SizeType
>(1e-5);
840 return ((std::abs(X - Other.X) < Epsilon)
841 && (std::abs(Y - Other.Y)) < Epsilon)
842 && (std::abs(Z - Other.Z) < Epsilon));
844 return ((X == Other.x) && (Y == Other.y) && (Z == Other.z));
848 bool operator!=(
const glm::vec3& Other)
const
850 return !(*
this == Other);
856 template<
typename VectorTypeA,
typename VectorTypeB>
857 static SizeType
Dot(
const VectorTypeA& A,
const VectorTypeB& B)
859 using ReturnType = SizeType;
866 template<
typename VectorTypeA,
typename VectorTypeB>
867 static SizeType
Distance(
const VectorTypeA& A,
const VectorTypeB& B)
869 using ReturnType = SizeType;
878 template<
typename VectorTypeA,
typename VectorTypeB>
881 using ReturnType = SizeType;
885 template<
typename VectorTypeA,
typename VectorTypeB>
892 FORCEINLINE
void Normalize()
894 const SizeType Magnitude = std::sqrt((X * X) + (Y * Y) + (Z * Z));
900 FORCEINLINE
void NormalizeSafe()
902 const SizeType Magnitude = std::sqrt((X * X) + (Y * Y) + (Z * Z));
903 if (Magnitude >
static_cast<SizeType
>(0))
911 LK_CORE_WARN_TAG(
"Vector3",
"Vector could not be normalized with magnitude: {}", Magnitude);
915 template<
typename VectorType>
916 static TVector3<SizeType> Normalize(
const VectorType& Vector)
918 using ReturnType = TVector3<SizeType>;
919 return Math::Internal::Vector3Impl::Normalize<SizeType, VectorType, ReturnType, false>::Calculate(Vector);
922 template<
typename VectorType>
923 static TVector3<SizeType> NormalizeSafe(
const VectorType& Vector)
925 using ReturnType = TVector3<SizeType>;
926 return Math::Internal::Vector3Impl::Normalize<SizeType, VectorType, ReturnType, true>::Calculate(Vector);
929 template<
typename VectorTypeA,
typename VectorTypeB,
typename ReturnType = TVector3<SizeType>>
930 static ReturnType Min(
const VectorTypeA& A,
const VectorTypeB& B)
932 return Math::Internal::Vector3Impl::Min<SizeType, VectorTypeA, VectorTypeB, ReturnType>::Calculate(A, B);
935 template<
typename VectorTypeA,
typename VectorTypeB,
typename ReturnType = TVector3<SizeType>>
936 static ReturnType Max(
const VectorTypeA& A,
const VectorTypeB& B)
938 return Math::Internal::Vector3Impl::Max<SizeType, VectorTypeA, VectorTypeB, ReturnType>::Calculate(A, B);
941 template<
typename VectorType>
942 static VectorType Inverse(
const VectorType& Vector)
944 return Math::Internal::Vector3Impl::Inverse<SizeType, VectorType, VectorType, false>::Calculate(Vector);
947 template<
typename VectorType>
948 static VectorType InverseSafe(
const VectorType& Vector)
950 return Math::Internal::Vector3Impl::Inverse<SizeType, VectorType, VectorType, true>::Calculate(Vector);
953 FORCEINLINE std::string ToString()
const
955 return LK_FMT_LIB::format(
"({:.2f}, {:.2f}, {:.2f})", X, Y, Z);
958 FORCEINLINE
friend std::ostream& operator<<(std::ostream& os,
const TVector3& Vector)
960 os << *Vector.ToString();
965 template<
typename VectorType>
966 VectorType As()
const
968 return VectorType(X, Y, Z);
971 template<
typename VectorType,
typename = std::enable_if_t<std::is_same_v<VectorType, glm::vec3>>>
972 VectorType As()
const
974 return glm::vec3(X, Y, Z);
978 static_assert(std::disjunction_v<
979 std::is_same<SizeType, int>,
980 std::is_same<SizeType, uint16_t>,
981 std::is_same<SizeType, uint32_t>,
982 std::is_same<SizeType, uint64_t>,
983 std::is_same<SizeType, int16_t>,
984 std::is_same<SizeType, int32_t>,
985 std::is_same<SizeType, int64_t>,
986 std::is_same<SizeType, float>,
987 std::is_same<SizeType, double>
988 >,
"TVector3 can only be instantiated with int, float or double types");
991 #if LK_MATH_VECTOR_ANONYMOUS_STRUCT
994 struct { SizeType X, Y, Z; };
995 struct { SizeType R, G, B; };
996 struct { SizeType S, T, P; };
999 union { SizeType X, R, S; };
1000 union { SizeType Y, G, T; };
1001 union { SizeType Z, B, P; };