mirror of
https://github.com/recp/cglm.git
synced 2026-02-17 03:39:05 +00:00
vec: implement pow(norm, 2)
we can avoid function calls with this func
This commit is contained in:
@@ -108,6 +108,23 @@ glm_vec_cross(vec3 a, vec3 b, vec3 d) {
|
|||||||
d[2] = a[0] * b[1] - a[1] * b[0];
|
d[2] = a[0] * b[1] - a[1] * b[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief norm * norm (magnitude) of vec
|
||||||
|
*
|
||||||
|
* we can use this func instead of calling norm * norm, because it would call
|
||||||
|
* sqrtf fuction twice but with this func we can avoid func call, maybe this is
|
||||||
|
* not good name for this func
|
||||||
|
*
|
||||||
|
* @param[in] vec vec
|
||||||
|
*
|
||||||
|
* @return norm * norm
|
||||||
|
*/
|
||||||
|
CGLM_INLINE
|
||||||
|
float
|
||||||
|
glm_vec_norm2(vec3 vec) {
|
||||||
|
return vec[0] * vec[0] + vec[1] * vec[1] + vec[2] * vec[2];
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @brief norm (magnitude) of vec3
|
* @brief norm (magnitude) of vec3
|
||||||
*
|
*
|
||||||
@@ -118,7 +135,25 @@ glm_vec_cross(vec3 a, vec3 b, vec3 d) {
|
|||||||
CGLM_INLINE
|
CGLM_INLINE
|
||||||
float
|
float
|
||||||
glm_vec_norm(vec3 vec) {
|
glm_vec_norm(vec3 vec) {
|
||||||
return sqrtf(vec[0] * vec[0] + vec[1] * vec[1] + vec[2] * vec[2]);
|
return sqrtf(glm_vec_norm2(vec));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief norm * norm (magnitude) of vec
|
||||||
|
*
|
||||||
|
* we can use this func instead of calling norm * norm, because it would call
|
||||||
|
* sqrtf fuction twice but with this func we can avoid func call, maybe this is
|
||||||
|
* not good name for this func
|
||||||
|
*
|
||||||
|
* @param[in] vec vec4
|
||||||
|
*
|
||||||
|
* @return norm * norm
|
||||||
|
*/
|
||||||
|
CGLM_INLINE
|
||||||
|
float
|
||||||
|
glm_vec4_norm2(vec4 vec) {
|
||||||
|
return vec[0] * vec[0] + vec[1] * vec[1]
|
||||||
|
+ vec[2] * vec[2] + vec[3] * vec[3];
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@@ -131,8 +166,7 @@ glm_vec_norm(vec3 vec) {
|
|||||||
CGLM_INLINE
|
CGLM_INLINE
|
||||||
float
|
float
|
||||||
glm_vec4_norm(vec4 vec) {
|
glm_vec4_norm(vec4 vec) {
|
||||||
return sqrtf(vec[0] * vec[0] + vec[1] * vec[1]
|
return sqrtf(glm_vec4_norm2(vec));
|
||||||
+ vec[2] * vec[2] + vec[3] * vec[3]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
|||||||
Reference in New Issue
Block a user