Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inverted clip space handedness terminology #435

Open
master30f opened this issue Dec 22, 2024 · 3 comments
Open

Inverted clip space handedness terminology #435

master30f opened this issue Dec 22, 2024 · 3 comments

Comments

@master30f
Copy link
Contributor

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

@recp
Copy link
Owner

recp commented Dec 24, 2024

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: #322

@master30f
Copy link
Contributor Author

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

@recp
Copy link
Owner

recp commented Jan 2, 2025

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants