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

Add matrix adjoint function #151

Closed
dustin-biser opened this issue Jan 5, 2014 · 4 comments
Closed

Add matrix adjoint function #151

dustin-biser opened this issue Jan 5, 2014 · 4 comments
Assignees
Milestone

Comments

@dustin-biser
Copy link

Looking through the matrix functions, I didn't see any functions that returns the adjoint of a matrix. Although it looks like the inverse functions are computing the adjoint as preliminary step.

The adjoint of a matrix is useful for things like computing a matrix for transforming lighting normals. "Real-Time Rendering, 3rd edition" pg.63, suggests to use the transpose of the adjoint of the model-view matrix for correctly transforming lighting normals. As glm currently stands, only the inverse method is available for this, which returns the input matrix's adjoint divided by the input matrix's determinant.

If an adjoint function was available it could be used instead of the inverse function to more efficiently compute the normal matrix by removing the unncessary division by the matrix's determinant.

@naruse
Copy link

naruse commented Jul 3, 2015

any update on this?, I just stumbled on this as well and hoped glm had this implemented.

@Groovounet Groovounet self-assigned this Jul 29, 2018
@Groovounet
Copy link
Member

Another old thing I didn't really investigate even if it's pretty trivial to implement...
https://en.wikipedia.org/wiki/Adjugate_matrix

@Groovounet
Copy link
Member

This feature was added to dev branch and should reach master branch for GLM 0.9.9.3 release.

Better now than never XD

@gszauer
Copy link

gszauer commented Apr 28, 2019

@Groovounet , I think this implementation of adjugate is actually transposed.

If i'm not mistaken, dividng the adjugate by the determinant of the matrix is supposed to equal the inverse of the matrix. inv(A) == (1 / det(A)) * Adj(A)

glm::mat4 mat = glm::rotate(glm::radians(90.0f), glm::vec3(1, 0, 0));
glm::mat4 inv = glm::inverse(mat);
glm::mat4 adj = glm::adjugate(mat);
float det = glm::determinant(mat);
glm::mat4 test = adj * (1.0f / det);

if (inv != test) {
	std::cout << "(1.0f / determinant) * adjugate != inverse\n";

	adj = glm::transpose(adj);
	test = adj * (1.0f / det);
	if (inv == test) {
		std::cout << "adjugate was transposed\n";
	}
}
else {
	std::cout << "(1.0f / determinant) * adjugate == inverse\n";
}

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

4 participants