Comments (3)
The code in the article is the same as glmatrix
https://github.com/toji/gl-matrix/blob/21b745f3a8b095c4a5304978fa8ab131b76a5f9e/src/mat3.js#L294
which is the same as glm
which is the same as opengl
https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/glMultMatrix.xml
It's not a bug. It's what pretty much every graphics library calls "multiply"
In glm (C++) your example of M = TRS is written as
matrix = translation * rotation * scale
The math applied is the same as in this article. The order of storage is the same as well, translation is in offsets 12,13,14 in the matrix (well, offsets 7,8 for a 3x3 matrix)
Also, the confusing part is WebGL consider rows to be columns as mentioned in the this article. No transposing is going on. Only how the data is interpreted
from webgl2-fundamentals.
Yeah, I realize now that in multiply(a, b)
, both a
and b
are treated as column-major rather than row-major. That makes the result a*b
(a postmultiplied by b) as expected.
For the next person that gets tripped up here, I was thrown off because the naming of the variables is different than what you'd expect when using standard math notation, e.g. this series of variables:
var a00 = a[0 * 3 + 0];
var a01 = a[0 * 3 + 1];
var a02 = a[0 * 3 + 2];
...
Which I assumed referenced a matrix layout like this (row-major), because usually the first subscript denotes the row and the second subscript denotes the column in math. For instance, naively you might expect a02 to select the first row and the third column:
a00 a01 a02
a10 a11 a12
a20 a21 a22
But actually the variables in the code reference a matrix layout like this (column-major):
a00 a10 a20
a01 a11 a21
a02 a12 a22
I was also thrown off because the diagrams in the articles have the rows where columns would normally be and vice versa, as you wrote about here: https://webgl2fundamentals.org/webgl/lessons/webgl-matrix-vs-math.html
Anyway closing this and thanks for the response. Hopefully the comment helps the next person who gets confused.
from webgl2-fundamentals.
Thanks. If/when I write WebGPU articles I'll try to use more "math"y diagrams and explanations and point out the "rows are columns"
In another github issue I pointed out if you want to see the rows as columns you can write it like this
const xaxis = [xx, xy, xz, 0];
const yaxis = [yx, yy, yz, 0];
const zaxis = [zx, zy, zz, 0];
const trans = [tx, ty, tz, 1];
const matrix = [...xaxis, ...yaxis, ...zaxis, ...trans];
or maybe clearer
const column1 = [
xx,
xy,
xz,
0,
];
const column2 = [
yx,
yy,
yz,
0,
];
const column3 = [
zx,
zy,
zz,
0,
];
const column4 = [
tx,
ty,
tz,
1,
];
const matrix = [...column1, ...column2, ...column3, ...column4];
which if you squint can look like columns 😅
from webgl2-fundamentals.
Related Issues (20)
- “WebGL Matrices vs Math Matrices” is a row-major vs column-major issue
- [suggestion] Add Glossary to References
- Cannot see the Chinese version of the content
- fundamentals - gl.getAttribLocation - not compatible with webgl2 HOT 1
- Typo on WebGL2 Picking page HOT 3
- texture2d used instead of texture in sample code shader at the top of less code more fun HOT 1
- kScript is not defined HOT 1
- Bugs with code in WebGL2 3D Perspective Section HOT 2
- 2D Translation page refers to non-existing sample HOT 3
- Please make homepage less expensive.
- For Position Explain HOT 1
- Minor bug found in Webgl2 instancing example HOT 2
- broken links HOT 1
- Uncaught (in promise) Error: gl error: 1282 HOT 1
- The sample code for creating a texture is incorrect. HOT 1
- An example vertexAttribPointer call is missing the "normalized" param HOT 1
- WebGL2 - Reorganize Table of Contents or provide which order to read in
- Generic WebGL State Visualizer HOT 3
- Shadows Tutorial Continuation HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from webgl2-fundamentals.