cglm icon indicating copy to clipboard operation
cglm copied to clipboard

Reflect, code.

Open cheako opened this issue 6 years ago • 5 comments

/*!
 * @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);
}

cheako avatar Mar 19 '18 05:03 cheako

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.

recp avatar Mar 19 '18 11:03 recp

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);
}

DomGries avatar Mar 19 '19 10:03 DomGries

Would you mind to create a PR for this? 😁

recp avatar Mar 19 '19 10:03 recp

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.

DomGries avatar Mar 20 '19 09:03 DomGries

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...

recp avatar Mar 20 '19 20:03 recp