   Preserving scaling in a transform matrix
  I've been wondering how to preserve the scaling of a transform matrix once I've set the rotations like so:void CMatrix::setRotationRadians(const util::CVector3d& v){/*http://www.gamedev.net/reference/articles/article1691.asp#Q36"Altogether, over 75% of all matrix operations are spent processingarithmetic expressions which lead to either zero or one.""Using basic matrix calculations, the operation count would reach 128 multiplications, 96 additions and  80 assignments operations. Using the optimised algorithm, only 12 multiplications, 6 subtractions and 18 assignment operations are required. So, it is obvious that by using the optimised algorithm, a performance achievement of 1000% is achieved!" */float cx = cos( v.x );float sx = sin( v.x );float cy = cos( v.y );float sy = sin( v.y );float cz = cos( v.z );float sz = sin( v.z );float cxsy = cx * sy;float sxsy = sx * sy;m_mat[0] = cy * cz;m_mat[1] = -cy * sz;m_mat[2] = sy;m_mat[4] = sxsy * cz + cx * sz;m_mat[5] = -sxsy * sz + cx * cz;m_mat[6] = -sx * cy;m_mat[8] = -cxsy * cz + sx * sz;m_mat[9] = cxsy * sz + sx * cz;m_mat[10] = cx * cy;// We leave the following line out because we only want to set the 3x3 submatrix that represents rotation, and// we don't want to change anything else.//m_mat[3] = m_mat[7] = m_mat[11] = m_mat[12] = m_mat[13] = m_mat[14] = 0;m_mat[15] = 1;}To set the scaling, I have to multiply the transform matrix by a scaling matrix. Am I going to have to keep a seperate copy of the scaling factors, and whenever the rotation is changed, multiply it by the scaling matrix again?Or is there another way of preserving the scaling when settingthe rotation matrix?   
  With Euler angle construction like you're doing, there's probably no way to update the rotation without adding the scale back in from scratch.However, it can be a good idea to store such transforms separately anyway and concatenate them when needed. In most cases the cost of concatenation will not be a problem, but if you're concerned about it you can do a 'shorthand' scaling by simply multiplying the basis vectors of the rotation matrix by the scale factors (assuming the order of transformations is scale followed by rotation).   ;Quote:Original post by jykassuming the order of transformations is scale followed by rotationI'm not quite sure. To set the scale right now, I'm setting the rotation and translation and then multiplying it all by a scaling matrix.So I would assume that the order of transformations was a rotation followed by a scale. Am I right in this? How would it differ if it was the other way around?   ;Quote:Original post by EndarSo I would assume that the order of transformations was a rotation followed by a scale. Am I right in this? How would it differ if it was the other way around?Scale followed by rotation is more common, but which one you're doing depends on multiplication order and whether you're using row or column vectors. With row vectors:M = S*R; // Scale followed by rotationM = R*S; // Rotation followed by scaleWith column vectors:M = S*R; // Rotation followed by scaleM = R*S; // Scale followed by rotation;Quote:Original post by jykM = R*S; // Scale followed by rotationThis one is me. I'm using column vectors.   