squared distance for vec3

This commit is contained in:
Recep Aslantas
2018-05-30 23:35:59 +03:00
parent 6b2b4b4f12
commit 3dc9070909
4 changed files with 38 additions and 3 deletions

View File

@@ -148,6 +148,10 @@ CGLM_EXPORT
void
glmc_vec_center(vec3 v1, vec3 v2, vec3 dest);
CGLM_EXPORT
float
glmc_vec_distance2(vec3 v1, vec3 v2);
CGLM_EXPORT
float
glmc_vec_distance(vec3 v1, vec3 v2);

View File

@@ -633,6 +633,21 @@ glm_vec_center(vec3 v1, vec3 v2, vec3 dest) {
glm_vec_scale(dest, 0.5f, dest);
}
/**
* @brief squared distance between two vectors
*
* @param[in] v1 vector1
* @param[in] v2 vector2
* @return returns squared distance (distance * distance)
*/
CGLM_INLINE
float
glm_vec_distance2(vec3 v1, vec3 v2) {
return glm_pow2(v2[0] - v1[0])
+ glm_pow2(v2[1] - v1[1])
+ glm_pow2(v2[2] - v1[2]);
}
/**
* @brief distance between two vectors
*
@@ -643,9 +658,7 @@ glm_vec_center(vec3 v1, vec3 v2, vec3 dest) {
CGLM_INLINE
float
glm_vec_distance(vec3 v1, vec3 v2) {
return sqrtf(glm_pow2(v2[0] - v1[0])
+ glm_pow2(v2[1] - v1[1])
+ glm_pow2(v2[2] - v1[2]));
return sqrtf(glm_vec_distance2(v1, v2));
}
/*!