Understanding PMatrix3D
in
Programming Questions
•
1 year ago
Hello,
I'm was wondering how PMatrix3D works behind the scene.
Initially I thought it's the same as an OpenGL Matrix:
(image from
http://www.songho.ca/opengl/gl_transform.html )
Data is stored in columns, 4th columns storing the translation.
I've done a basic test
- PMatrix3D m = new PMatrix3D();
- void setup(){
- size(300,300,P3D);
- resetMatrix();
- printMatrix();
- }
- void draw(){
- background(255);
- fill(0);
- pushMatrix();
- text(matrixToString(m),0,10);
- popMatrix();
- lights();
- fill(255);
- translate(width * .5,height * .5);
- rotateX((float)mouseY/height * PI);
- rotateY((float)mouseX/width * PI);
- pushMatrix();
- // m.translate(0,0,1);
- m.rotateX(radians(1));
- applyMatrix(m);
- noStroke();
- box(100);
- stroke(255,0,0);
- line(0,0,0,150,0,0);
- stroke(0,255,0);
- line(0,0,0,0,150,0);
- stroke(0,0,255);
- line(0,0,0,0,0,150);
- popMatrix();
- }
- String matrixToString(PMatrix3D m){
- return "[" + nf(m.m00,1,1) + " , " + nf(m.m10,1,1) + " , " + nf(m.m20,1,1) + " , " + nf(m.m30,1,1) + " ,\n" +
- " "+ nf(m.m01,1,1) + " , " + nf(m.m11,1,1) + " , " + nf(m.m21,1,1) + " , " + nf(m.m31,1,1) + " ,\n" +
- " "+ nf(m.m02,1,1) + " , " + nf(m.m12,1,1) + " , " + nf(m.m22,1,1) + " , " + nf(m.m32,1,1) + " ,\n" +
- " "+ nf(m.m03,1,1) + " , " + nf(m.m13,1,1) + " , " + nf(m.m23,1,1) + " , " + nf(m.m33,1,1) + " ]";
- }
and I think PMatrix3D uses columns like OpenGL, but stores the translation on the last row instead of the last column.
AFAIK DirectX uses rows, so it's the transposed version of the OpenGL matrix.
Are my assumptions about PMatrix3D correct ?
If so, any particular reason why it is that way ?
Thanks,
George
1