tipforeveryone Posted May 14, 2020 Share Posted May 14, 2020 (edited) 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, This page: https://developer.unigine.com/en/docs/2.11/code/fundamentals/matrix_transformations/index?rlang=cpp 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, In page https://developer.unigine.com/en/docs/2.11/api/library/math/class.mat4?rlang=cpp#setScale_const_vec3_ref_void 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) ? 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) 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) ? Edited May 14, 2020 by tipforeveryone Link to comment
fox Posted May 15, 2020 Share Posted May 15, 2020 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 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! 4 Link to comment
tipforeveryone Posted May 15, 2020 Author Share Posted May 15, 2020 Thanks for a clear explaination, glad to know all of these will be updated in document soon :) Link to comment
Recommended Posts