greggman / wgpu-matrix

Fast WebGPU 3d math library
https://wgpu-matrix.org
MIT License
298 stars 13 forks source link

error in mat3.inverse(), and suggestion #18

Open davidjeck opened 1 year ago

davidjeck commented 1 year ago

It seems like mat3.inverse() in version 2.4.0 actually computes the transpose of the inverse. mat4.inverse() is OK. I was trying to use gpu-matrix to compute a normal vector transformation matrix -- a mat3.normalMatrixFromMat4() function would be a good addition.

greggman commented 1 year ago

fixed

As for normalMatrixFromMat4, yea, I can see the point. I'd probably name it mat3.fromMat4Transpose or something like that.

davidjeck commented 1 year ago

Thanks, that was fast. This now works for computing the normal transformation matrix from the modelview matrix:

        wgpuMatrix.mat3.fromMat4(modelview,normalMatrix);
        wgpuMatrix.mat3.inverse(normalMatrix,normalMatrix);
        wgpuMatrix.mat3.transpose(normalMatrix,normalMatrix);

I will use wgpu-matrix for 3D WebGPU graphics in the next version of my on-line computer graphics textbook.