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

glm::adjugate ? #246

Open
ghost opened this issue Mar 27, 2022 · 4 comments
Open

glm::adjugate ? #246

ghost opened this issue Mar 27, 2022 · 4 comments

Comments

@ghost
Copy link

ghost commented Mar 27, 2022

Hello there,

I am currently using cglm in my game engine and was wondering if there is an implementation of adjugate in cglm?
here how the function looks like from glm C++ library

image

Thank you.

@recp
Copy link
Owner

recp commented Mar 28, 2022

Hi @wobes1

Thanks for your feedback,

We can add this function to cglm, I will work on it asap if anyone wont before me

It is similar to inverse just without determinant division

@ghost
Copy link
Author

ghost commented Mar 28, 2022

Thank you for your reply @recp

Wow, I really appreciate the reactivity! Sorry I couldn't contribute myself, I lack proper knowledge of cglm and complex matrices operations, but will be happy to learn

Cheers

EDIT:

oh so just without this part?
image

@ghost
Copy link
Author

ghost commented Mar 29, 2022

Yes I believe this is it:

CGLM_INLINE
void glm_mat3_adjugate(mat3 mat, mat3 dest) {
  float det;
  float a = mat[0][0], b = mat[0][1], c = mat[0][2], d = mat[1][0], e = mat[1][1], f = mat[1][2],
        g = mat[2][0], h = mat[2][1], i = mat[2][2];

  dest[0][0] = e * i - f * h;
  dest[0][1] = -(b * i - h * c);
  dest[0][2] = b * f - e * c;
  dest[1][0] = -(d * i - g * f);
  dest[1][1] = a * i - c * g;
  dest[1][2] = -(a * f - d * c);
  dest[2][0] = d * h - g * e;
  dest[2][1] = -(a * h - g * b);
  dest[2][2] = a * e - b * d;
}

Please let me know if something is off. Thank you!

@recp
Copy link
Owner

recp commented Mar 29, 2022

Yes that's it! But with correct indents/alignment ;)

CGLM_INLINE
void
glm_mat3_adjugate(mat3 mat, mat3 dest) {
  float a = mat[0][0], b = mat[0][1], c = mat[0][2],
        d = mat[1][0], e = mat[1][1], f = mat[1][2],
        g = mat[2][0], h = mat[2][1], i = mat[2][2];

  dest[0][0] =   e * i - f * h;
  dest[0][1] = -(b * i - h * c);
  dest[0][2] =   b * f - e * c;
  dest[1][0] = -(d * i - g * f);
  dest[1][1] =   a * i - c * g;
  dest[1][2] = -(a * f - d * c);
  dest[2][0] =   d * h - g * e;
  dest[2][1] = -(a * h - g * b);
  dest[2][2] =   a * e - b * d;
}

maybe glm_mat3_adj() could be used for the name but not sure.

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

1 participant