improved "ray_intersection_angle" functions.
This commit is contained in:
parent
bbb7daa6c2
commit
a75acfabd1
@ -262,11 +262,40 @@ namespace hgl
|
|||||||
return length_squared(v1,v2)<=(gap*gap);
|
return length_squared(v1,v2)<=(gap*gap);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline float ray_angle_cos(const Vector3f &ray_dir, const Vector3f &ray_pos, const Vector3f &pos)
|
/**
|
||||||
|
* 计算射线与点的夹角(cos)
|
||||||
|
*/
|
||||||
|
inline float ray_intersection_angle_cos(const Vector3f &ray_dir, const Vector3f &ray_pos, const Vector3f &pos)
|
||||||
{
|
{
|
||||||
return dot(ray_dir, normalized(pos - ray_pos));
|
return dot(ray_dir, normalized(pos - ray_pos));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 计算射线与点的夹角(弧度)
|
||||||
|
*/
|
||||||
|
inline float ray_intersection_angle_radian(const Vector3f &ray_dir, const Vector3f &ray_pos, const Vector3f &pos)
|
||||||
|
{
|
||||||
|
double val=dot(ray_dir, normalized(pos - ray_pos));
|
||||||
|
|
||||||
|
if(val>1)return 0;
|
||||||
|
if(val<-1)return HGL_PI;
|
||||||
|
|
||||||
|
return acos(val);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 计算射线与点的夹角(角度)
|
||||||
|
*/
|
||||||
|
inline float ray_intersection_angle_degree(const Vector3f &ray_dir, const Vector3f &ray_pos, const Vector3f &pos)
|
||||||
|
{
|
||||||
|
double val=dot(ray_dir, normalized(pos - ray_pos));
|
||||||
|
|
||||||
|
if(val>1)return 0;
|
||||||
|
if(val<-1)return 180;
|
||||||
|
|
||||||
|
return rad2deg(acos(val));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 做一个2D旋转计算
|
* 做一个2D旋转计算
|
||||||
* @param result 结果
|
* @param result 结果
|
||||||
|
Loading…
x
Reference in New Issue
Block a user