From 1ad31f6f6b4fadbcbef85c3dd038c218d827b078 Mon Sep 17 00:00:00 2001 From: hyzboy Date: Wed, 30 Sep 2020 14:16:30 +0800 Subject: [PATCH] add clamp and dot2 functions. --- inc/hgl/math/Vector.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/inc/hgl/math/Vector.h b/inc/hgl/math/Vector.h index 9d44301..04a1ce9 100644 --- a/inc/hgl/math/Vector.h +++ b/inc/hgl/math/Vector.h @@ -106,6 +106,14 @@ namespace hgl return Vector3f(src.x,src.y,z); } + template + inline T clamp(const T &v,const T &min_v,const T &max_v) + { + if(vmax_v)return max_v; + return v; + } + template inline T normalized(const T &v) { @@ -130,6 +138,12 @@ namespace hgl return v1.Dot(v2); } + template + inline float dot2(const T &v) + { + return v.Dot(v); + } + inline float ray_angle_cos(const Ray &ray,const vec &pos) { return ray.dir.Dot((pos-ray.pos).Normalized());