cglm
cglm copied to clipboard
Reflect, code.
/*!
* @brief reflect vector across a plain identified by it's normal
* and store result in dest
*
* @param[in] I input
* @param[in] N normalized normal
* @param[out] dest reflected vector
*/
CGLM_INLINE
void
glm_vec4_reflect(vec4 I, vec4 N, vec4 dest) {
vec4 mul1;
#ifdef CGLM_BE_MY_MOM
glm_vec4_normalize(N);
#endif
glm_vec4_scale(N, glm_vec4_dot(N, I) * 2.0f, mul1);
glm_vec4_sub(I, mul1, dest);
}
Would you mind to create a PR for this?
- 2 spaces instead of TAB[s]
- vec3 version
If we want to create call version like glmc_vec4_reflect
then the macro will be problem here, cglm must be rebuild with this macro.
I think we don't need the temporary variable and the macro (normal should be expected to be normalized by user before):
/*!
* @brief reflect vector across a plain identified by it's normal
* and store result in dest
*
* @param[in] v input
* @param[in] n normalized normal
* @param[out] dest reflected vector
*/
CGLM_INLINE
void
glm_vec4_reflect(vec4 v, vec4 n, vec4 dest) {
glm_vec4_scale(n, glm_vec4_dot(n, v) * 2.0f, dest);
glm_vec4_sub(v, dest, dest);
}
Would you mind to create a PR for this? 😁
glm also has SSE2 code for the vec4 variant: https://github.com/g-truc/glm/blob/master/glm/simd/geometric.h#L94
Would you mind to create a PR for this?
Sorry but I don't know SIMD and can't even test it.
Thanks for sharing that. I'll implement this in the future.
FWIW, for vec4 functions even if we won't use SIMD directly; since vec4 functions are optimized with SIMD, using vec4 functions may give similar assembly output to pure SIMD implementation. Using pure SIMD or glmm_
api will save some load/store...