From 3b55f2f42b295f285fa0e4d7da8cd44e80adaf50 Mon Sep 17 00:00:00 2001 From: hyzboy Date: Thu, 27 Jan 2022 14:53:15 +0800 Subject: [PATCH] added IsNearlyEqual functions,updated PolarToVector function. --- inc/hgl/math/Vector.h | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/inc/hgl/math/Vector.h b/inc/hgl/math/Vector.h index e8828e3..113263c 100644 --- a/inc/hgl/math/Vector.h +++ b/inc/hgl/math/Vector.h @@ -22,7 +22,6 @@ namespace hgl using Vector3u=glm::uvec3; using Vector4u=glm::uvec4; - inline bool operator == (const Vector2f &lhs,const Vector2f &rhs) { if(lhs.x!=rhs.x)return(false); @@ -224,6 +223,21 @@ namespace hgl result.y = start.y + (end.y - start.y)*pos; } + inline bool IsNearlyEqual(const float v1,const float v2,const float gap) + { + return fabsf(v1-v2)<=gap; + } + + inline bool IsNearlyEqual(const Vector2f &v1,const Vector2f &v2,const float gap) + { + return length_squared_2d(v1,v2)<=(gap*gap); + } + + inline bool IsNearlyEqual(const Vector3f &v1,const Vector3f &v2,const float gap) + { + return length_squared(v1,v2)<=(gap*gap); + } + inline float ray_angle_cos(const Vector3f &ray_dir, const Vector3f &ray_pos, const Vector3f &pos) { return dot(ray_dir, normalized(pos - ray_pos)); @@ -251,14 +265,11 @@ namespace hgl result.y = center.y + ((source.x - center.x)*as + (source.y - center.y)*ac); } - inline const Vector3f PolarToVector3f(float yaw,float pitch) + inline const Vector3f PolarToVector(float yaw,float pitch) { - return Vector3f(sinf(yaw) * cosf(pitch), sinf(pitch), cosf(yaw) * cosf(pitch)); - } - - inline const Vector4f PolarToVector4f(float yaw,float pitch) - { - return Vector4f(sinf(yaw) * cosf(pitch), sinf(pitch), cosf(yaw) * cosf(pitch), 0); + return glm::normalize( Vector3f( cos(yaw )*cos(pitch), + sin(yaw )*cos(pitch), + sin(pitch))); } inline const Vector4f PointVector(const Vector3f &v)