add clamp and dot2 functions.

This commit is contained in:
hyzboy 2020-09-30 14:16:30 +08:00
parent a24e522ffe
commit 1ad31f6f6b

View File

@ -106,6 +106,14 @@ namespace hgl
return Vector3f(src.x,src.y,z);
}
template<typename T>
inline T clamp(const T &v,const T &min_v,const T &max_v)
{
if(v<min_v)return min_v;
if(v>max_v)return max_v;
return v;
}
template<typename T>
inline T normalized(const T &v)
{
@ -130,6 +138,12 @@ namespace hgl
return v1.Dot(v2);
}
template<typename T>
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());