-
-
Notifications
You must be signed in to change notification settings - Fork 262
Clipspace implementations for left/righted-handed coordinate systems and [-1,1] and [0,1] clipspace #198
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
Conversation
This commit adds the function `glm_perspective_lh_zo`, modelled on the implementation of glm_perspective, but amended to provide a left-hand coordinate system expected by DirectX, Metal and Vulkan (per the GLM project's `glm/detail/setup.hpp`). It uses a clip-space of zero-to-one. The function is tested against a longhand version of the algorithm it seeks to implement as well as against the output of the GLM project's `glm::perspectiveLH_ZO` function. This commit adds a new subdirectory `test/glm_cmp` which contains a basic CMake file and `main.cpp`. An interested user should link or copy or clone the GLM project into this directory. The `main` function can be used to print the reference data used so others can verify behaviour in the future, or add new literal reference values.
This commit adds the RH/ZO perspective function. It does so in the new file `cam_rh_zo.h` and further refactors the LH variant into new file `cam_lh_zo.h`. This creates some churn in the tests and configuration files as new test files were added as well, and all these changes found their way into the build files. Tests passing on Linux.
This commit adds functions `glm_perspective_lh_no` and `glm_perspective_rh_no` to the code. Unit tests are added and this commit follows the new pattern of adding the a new file per coordinate-system and clip-space tuple. . Makefile.am updated . removed test/glm_cmp project stub . unit tests include naive implementations to as well as magic number ref-data generated by the corresponding GLM functions. No tests run yet on Windows or Mac.
Add the initial implementations of the left-handed and right-handed coordinate systems as well as clipspace depth values of [-1, 0] and [0, 1].
@michael-g @recp The tests are still failing but it's a start for some early reviewing |
Co-authored-by: Michael <michael.guyver@gmail.com>
Co-authored-by: Michael <michael.guyver@gmail.com>
Will hopefully do some more later on, but this is a huge amount of work you've done, @raedwulf. Awesome stuff. |
Hi @raedwulf, @michael-g, Sorry for the late response :/ Many thanks for this work, as @michael-g said this is a huge work. Should we separate files by Also there is a struct api, we should add wrappers fo this change into |
I'll look into the struct API. Currently we do have an extra separation for view too. Would proj just be the combination of ortho and persp? @recp |
Yes, but I'm not sure which way is better, separating them or joining them. There are lot of persp functions and maybe come more for both ortho and persp, in this case separating them may be good idea. |
#define CGLM_CLIP_CONTROL_LH_NO (CGLM_CLIP_CONTROL_LH_BIT | CGLM_CLIP_CONTROL_NO_BIT) | ||
#define CGLM_CLIP_CONTROL_RH_ZO (CGLM_CLIP_CONTROL_RH_BIT | CGLM_CLIP_CONTROL_ZO_BIT) | ||
#define CGLM_CLIP_CONTROL_RH_NO (CGLM_CLIP_CONTROL_RH_BIT | CGLM_CLIP_CONTROL_NO_BIT) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add these options to docs/source/opt.rst
? People can recognize the options quickly when reading docs.
Maybe this is not one of goal of the PR and out of scope, but I'm wonder that should cglm need anything else to support LH. For instance transforms (matrix rotations, quaternions, vector rotations...). Also there are frustum helpers in Actually users should achieve same rotation around X and Y by negating angle but Z should remain same I think. Maybe we should discuss these in another issue[s]. |
@raedwulf ping. I think we need to add tests for other functions too, after that we can merge this PR if there are no any issues |
Do you have a sense of how you'd like to approach the testing? We could continue with the small amount of work I've done and paste a load of magic numbers into the tests, or go ahead with the new repository which compares cglm implementations again the glm library? The former is much more of a unit test, obviously, but the latter has its own benefits. |
I looked into the struct API and I can get it done soonish :) thanks @michael-g that would be great! |
@michael-g I think we should add unit tests first then library-to-library test can be written later. The magic numbers could come from the math instead of glm directly, or both maybe, glm also needs tests... I have just created a repo called cglm-libtests, the name can be changed with better one...
Awesome! |
It would be nice to finish this work asap, I can merge this PR and we can add tests with new PRs maybe? @raedwulf @michael-g any progress? |
@recp Just a bit busy last few days, but I'll spend some time this weekend to finalise things with the struct api. |
@raedwulf great 🤗, thanks |
Sorry, I've been busy with work and family stuff. If only we could auto-gen a bunch of tests using results from GLM... |
I pushed the struct api stuff @recp @michael-g |
@raedwulf awesome work, There was no need to add clip control to default strruct api like this: CGLM_INLINE
mat4s
glms_frustum(float left, float right,
float bottom, float top,
float nearZ, float farZ) {
#if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO
return glms_frustum_lh_zo(left, right, bottom, top, nearZ, farZ);
#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO
return glms_frustum_lh_no(left, right, bottom, top, nearZ, farZ);
#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO
return glms_frustum_rh_zo(left, right, bottom, top, nearZ, farZ);
#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO
return glms_frustum_rh_no(left, right, bottom, top, nearZ, farZ);
#endif
} clip control already done in |
Now we need to add tests ;) |
Ahh, yeah that's true. That file could be reverted with no problems though. |
@raedwulf @michael-g I'm going to merge this PR, but let's improve this by adding tests, bug fixes with new PRs... This is still valid question for me: #198 (comment) Feel free to open issues and bring tests, bugfixes @raedwulf @michael-g many thanks for this work 🤗 |
@raedwulf @michael-g the PR is merged, many thanks 🤗 🎉 Let's write tests ;) |
@raedwulf, kudos, amazing work. Will try to contribute this week to the testing code. Again: is there a source of reference implementations? |
Hey @michael-g, they are based on the cglm source code and the glm code for the differences. |
@raedwulf Love this! Thank you so much for pushing this through. |
@warmwaffles thanks! We're still in the process of testing this and any feedback will be great! |
We should announce this feature after the tests are done e.g. reddit, gamedev... I'll try what I can... After used by community then more improvements can be made. Great to have great community 🎉 |
Wow, been following along this project for a while, glad to see it come to fruition, excellent work all at @michael-g @raedwulf and @recp for the insights, kudos 🥳 |
Quick question, are there noticeable to changes on how to use the library now? |
@quadroli thanks,
Actually not, just optionally it is possible to use other clipspaces rather than OpenGL's one now, if there are no any bugs |
Awesome 👍 |
No description provided.