Added Area.h

This commit is contained in:
2024-08-02 22:31:31 +08:00
parent 7589d62732
commit 866f69034b
6 changed files with 98 additions and 26 deletions

View File

@@ -261,19 +261,19 @@ namespace hgl
return from + (to - from) * alpha;
}
inline bool is_nearly_equal(const float v1,const float v2,const float deviation=HGL_FLOAT_SMALL)
inline bool is_nearly_equal(const float v1,const float v2,const float deviation=HGL_FLOAT_KINDA_SMALL)
{
return fabsf(v1-v2)<=HGL_FLOAT_SMALL;
return fabsf(v1-v2)<=deviation;
}
inline bool is_nearly_equal(const Vector2f &v1,const Vector2f &v2,const float deviation=HGL_FLOAT_SMALL)
inline bool is_nearly_equal(const Vector2f &v1,const Vector2f &v2,const float deviation=HGL_FLOAT_KINDA_SMALL)
{
return length_squared_2d(v1,v2)<=HGL_FLOAT_SMALL;
return length_squared_2d(v1,v2)<=deviation;
}
inline bool is_nearly_equal(const Vector3f &v1,const Vector3f &v2,const float deviation=HGL_FLOAT_SMALL)
inline bool is_nearly_equal(const Vector3f &v1,const Vector3f &v2,const float deviation=HGL_FLOAT_KINDA_SMALL)
{
return length_squared(v1,v2)<=HGL_FLOAT_SMALL;
return length_squared(v1,v2)<=deviation;
}
/**
@@ -413,5 +413,15 @@ namespace hgl
&&IsNearlyEqual(a.y,b.y)
&&IsNearlyEqual(a.z,b.z);
}
inline const Vector3f LerpDirection(const Vector3f &center,const Vector3f &from_direction,const Vector3f &to_direction,const float alpha)
{
return glm::normalize(center + (from_direction - center) * alpha + (to_direction - center) * alpha);
}
inline const Vector3f SLerpDirection(const Vector3f &center,const Vector3f &from,const Vector3f &to,const float alpha)
{
return glm::normalize(glm::slerp(from - center, to - center, alpha) + center);
}
}//namespace hgl
#endif//HGL_ALGORITHM_MATH_VECTOR_INCLUDE