[Mesa-dev] [PATCH 4/4] glsl: Add implementation of inverse() for mat2/3/4.

Olivier Galibert galibert at pobox.com
Wed Apr 18 21:49:52 PDT 2012


On Wed, Apr 18, 2012 at 06:40:32PM -0700, Eric Anholt wrote:
> +mat3 inverse(mat3 m)
> +{
> +   mat3 adj;
> +   adj[0][0] = + (m[1][1] * m[2][2] - m[2][1] * m[1][2]);
> +   adj[1][0] = - (m[1][0] * m[2][2] - m[2][0] * m[1][2]);
> +   adj[2][0] = + (m[1][0] * m[2][1] - m[2][0] * m[1][1]);
> +   adj[0][1] = - (m[0][1] * m[2][2] - m[2][1] * m[0][2]);
> +   adj[1][1] = + (m[0][0] * m[2][2] - m[2][0] * m[0][2]);
> +   adj[2][1] = - (m[0][0] * m[2][1] - m[2][0] * m[0][1]);
> +   adj[0][2] = + (m[0][1] * m[1][2] - m[1][1] * m[0][2]);
> +   adj[1][2] = - (m[0][0] * m[1][2] - m[1][0] * m[0][2]);
> +   adj[2][2] = + (m[0][0] * m[1][1] - m[1][0] * m[0][1]);
> +
> +   float det = (+ m[0][0] * (m[1][1] * m[2][2] - m[1][2] * m[2][1])
> +		- m[0][1] * (m[1][0] * m[2][2] - m[1][2] * m[2][0])
> +		+ m[0][2] * (m[1][0] * m[2][1] - m[1][1] * m[2][0]));

Do you think the compiler will notice these are adj[0][0], adj[1][0]
and adj[2][0]?

  OG.


More information about the mesa-dev mailing list