# Inline-Building a World (SRT) Matrix

Currently, to construct a world matrix, I have the following code:

return FromScale(scale) * rotation.RotMatrix * FromTranslation(translation);


However, this is constructing three matrices, and then applying two multiply operations between them in order to assembly the final world matrix.

However, I'm pretty sure there must be an algorithm or listing for constructing the SRT matrix 'in-place', by doing the necessary multiplications for each matrix element first, and then simply assembling the resultant matrix from that.

However, I can't seem to find a reference for that anywhere; the closest I found was for an SRT transformation with a rotation around a single axis.

Can anyone show me how to make an 'inline' SRT matrix? Or TRS, I don't mind. Row-major or column-major is fine, also.

A homogenous transformation matrix (aka a "World matrix") is a 4x4 matrix that defines the translation and rotation of one coordinate system with respect to another. It looks like this:

H = [xx, xy, xz, tx;
yx, yy, yz, ty;
zx, zy, zz, tz;
0,  0,  0,  1];


(Note on notation: This just lays out the matrix row by row. Each row is separated by a semicolon)

The rotation part (the upper 3x3 block [xx, xy, xz; ... zz]) are the axes of the new coordinate system with respect to the old coordinate system as column vectors. In your case, this block is the variable you've called RotationMatrix. By scaling the rotation matrix uniformly, you can change the scale of the coordinate system.

The upper right 3x1 column vector [tx, ty, tz] is the translation of the new coordinate system with respect to the old coordinate system. It's the variable you've called translation.

To construct the matrix inline, do this:

 // A 3x3 scaled rotation matrix
R = [x-axis * scale; y-axis * scale; z-axis * scale];
// A 3x1 translation vector
t = [translation];
// The final transformation
H = [ R ... t;
0 ... 1];

// Therefore:
H = [xx * scale, xy * scale, xz * scale, tx;
yx * scale, yy * scale, yz * scale, ty;
zx * scale, zy * scale, zz * scale, tz;
0,  0,  0,  1];


This is assuming that you do not want the translation vector to be scaled.

• Hi, thanks for the answer. I'm not quite sure I understand the syntax of your solution: Would you be able to provide an expanded answer? I'm not a mathematician, haha :) Mar 2, 2015 at 19:35
• I made a few edits to make it more verbose. Can I ask what you have trouble understanding? Mar 2, 2015 at 19:40
• That's it, after your expansion there I understood everything, thank you. Mar 3, 2015 at 16:59