Jump to content

Matrix Transformation confuses me


photo

Recommended Posts

Sorry because this is too confusing to me. Maybe I am not good at both English and Math stuff. Maybe this document needs more work to get a better explaination for people like me.

First one,

image.png.061c2c2c9f77385701d571e63292a349.png

  • The text said that: "First three columns show directions of axes AND the scale of the origin",
  • But the figure said "rotation AND scale", I don't know how rotation and direction are the same terms. It is a confict between text and image figure. I know they are related somehow, but why don't use the same term ?
  • If this 4 x 4 matrix can contain all information of a node's transformation, then in green marked area, which element is for scale, which one is for rotation (*)? why don't point them out ?

Next one,

image.png.e5d14cc0213d5cf7160e24dc09c17128.png

  • With this figure, I expect that: Those elements on the diagonal is for scaling, can this be the answer for my above question, marked with (*) ?
  • If I use .getColumn3(1), does it mean this column will be selected (marked red below) ?

image.png.95b1fc0204edf058186be8554b026111.png

  • If it is not true, I expect: To select the first column, I must use .getColumn3(0) with 0 is the first column, then why don't you add a note like:
    • 0 is the first column (x axis)
    • 1 is the second Column (y axis)
    • and 2 is the last colum (z axis)

image.png.8b9f361906d27fef4936eb113e2d94a6.png

image.png

Another one,

  • Back to node's transform matrix, if diagonal elements is about scaling, how .getColumn3(int column) use one of scale element to get node direction (v1.x) ?

image.png.e8b0a8129287d506224dae94422fcbed.png

Edited by tipforeveryone
Link to comment

Hi tipforevewyone,

Let's start with the rotation-direction stuff...

A bit of basics first: each object has it's local coordinate system with a set of base vectors (v1, v2, v3) each having its direction in the world space. When you rotate your object, you actually change directions of these base vectors (while translation keeps directions unchanged). So, there's no conflict of terms here, they are used to complement each other (we can add a comment in brackets for clarification). 

Here is an illustration of the transformation matrix

image.png

 

Information about rotation and scale components of the matrix is given in the same article, just a couple of chapters below (see Rotation and Scaling).

As you can see from the picture above, you can't just get the diagonal elements to obtain scaling components of the matrix, as they represent scale+rotation (some operations are required, see below).

Now about the API Reference for the mat4 Class

Column and row indices are zero-based (the missing notice will be added), so to get the first column, you should use .getColumn3(0) .

The setScale(vec3) method of the mat4 class simply constructs a scaling matrix using the specified vector, as shown in the docs (all elements of the matrix except for the main diagonal are 0).

As for getting the current scale components from the matrix, you should use the getScale() method, which extracts the scale information from the matrix, doing the following:

mat3 rotate, rotation = mat3(*this);
// obtaining a normalized matrix (with 1-unit-scale), to get the scaling part
orthonormalize(rotate, rotation);
// calculating the scale components 
float sx = rotate.m00 * rotation.m00 + rotate.m10 * rotation.m10 + rotate.m20 * rotation.m20;
float sy = rotate.m01 * rotation.m01 + rotate.m11 * rotation.m11 + rotate.m21 * rotation.m21;
float sz = rotate.m02 * rotation.m02 + rotate.m12 * rotation.m12 + rotate.m22 * rotation.m22;

And the last thing about

Quote

if diagonal elements is about scaling, how .getColumn3(int column) use one of scale element to get node direction (v1.x) ?

Getting node's direction (Y axis) via the following:

Vec3 direction = node->getWorldTransform().getColumn3(1);

it's ok, as the diagonal elements are not about just scaling and the column contains the current coordinates of the local Y axis of the node, i.e. forward direction (as described above).

Hope this helps!

Missing notices will be added, as I mentioned above, and some images will be updated as well.

Thanks!

 

 

  • Like 4
Link to comment
×
×
  • Create New...