cglm icon indicating copy to clipboard operation
cglm copied to clipboard

Inverted clip space handedness terminology

Open master30f opened this issue 11 months ago • 3 comments

CGLM_CLIP_CONTROL_LH_BIT has a comment that says it's for Vulkan and CGLM_CLIP_CONTROL_RH_BIT says it's for OpenGL, even though Vulkan uses right-handed clip space coordinates while OpenGL uses left-handed ones, so I'm not sure whether to believe the names or the comments...

master30f avatar Dec 22 '24 13:12 master30f

Hi @master30f,

CGLM_CLIP_CONTROL_LH_BIT and CGLM_CLIP_CONTROL_RH_BIT are used to determine CGLM_CLIP_CONTROL_LH/RH_ZO/NO

You can check include/cglm/cam.h, include/cglm/project.h to see the usage.

...
CGLM_INLINE
void
glm_ortho_aabb(vec3 box[2], mat4 dest) {
#if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO
  glm_ortho_aabb_lh_zo(box, dest);
#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO
  glm_ortho_aabb_lh_no(box, dest);
#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO
  glm_ortho_aabb_rh_zo(box, dest);
#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO
  glm_ortho_aabb_rh_no(box, dest);
#endif
}
...

Also like

CGLM_INLINE
void
glm_lookat(vec3 eye, vec3 center, vec3 up, mat4 dest) {
#if CGLM_CONFIG_CLIP_CONTROL & CGLM_CLIP_CONTROL_LH_BIT
  glm_lookat_lh(eye, center, up, dest);
#elif CGLM_CONFIG_CLIP_CONTROL & CGLM_CLIP_CONTROL_RH_BIT
  glm_lookat_rh(eye, center, up, dest);
#endif
}

RH/LH_BIT used to select RH or LH impl.

There maybe other places to take into account, see: https://github.com/recp/cglm/issues/322

recp avatar Dec 24 '24 20:12 recp

Hi @recp, thanks for the reply.

I don't think I got my point across very well. I understand that the flags are used to control whether to use functions made for a left or right handed clip space. The problem lies in their names. The flag which is to be used with Vulkan is, if I'm not mistaken, CGLM_FORCE_LEFT_HANDED, but Vulkan uses a right-handed clip space (OpenGL is the one who uses a left-handed one), so the flag and by extension all other mentions should be flipped (I think). (so CGLM_FORCE_LEFT_HANDED -> CGLM_FORCE_RIGHT_HANDED, etc.)

master30f avatar Dec 29 '24 19:12 master30f

@master30f thanks for the suggestion,

The definitions are the same as in https://github.com/g-truc/glm/blob/master/glm/detail/setup.hpp#L566.

RH/LH flags are mostly used to define world/view space handedness, not NDC. The default implementation of these functions is RH, which can be switched using these flags/bits. I don’t see a strong reason to flip them.

Let’s wait for more feedback

recp avatar Jan 02 '25 11:01 recp