The more laws and order are made prominent, the more thieves and robbers there will be -- Lao Tsu Concept 1.12: Specifying Matrices For Transformation =================================================== Idea: ===== Since transformations such as translation, rotation etc are performed by matrix multiplications, one should be able to specify matrices explicitly to perform required transformations. Example Matrices: ================= The matrix corresponding to translation by the vector [Dx Dy Dz] is 1 0 0 Dx 0 1 0 Dy T(Dx,Dy,Dz) = 0 0 1 Dz 0 0 0 1 The matrix corresponding to rotation by an angle 'A' about the X axis is 1 0 0 0 0 cos(A) -sin(A) 0 Rx(A) = 0 sin(A) cos(A) 0 0 0 0 1 The matrix corresponding to rotation by an angle 'A' about the Y axis is cos(A) 0 sin(A) 0 0 1 0 0 Ry(A) = -sin(A) 0 cos(A) 0 0 0 0 1 The matrix corresponding to rotation by an angle 'A' about the Z axis is cos(A) -sin(A) 0 0 sin(A) cos(A) 0 0 Rz(A) = 0 0 1 0 0 0 0 1 The angle 'A' above is specified in degrees. The matrix corresponding to scaling about the origin by the factors Sx, Sy, and Sz (all non-zero) along the respective coordinate axes is Sx 0 0 0 0 Sy 0 0 S(Sx,Sy,Sz)= 0 0 Sz 0 0 0 0 1 The matrix corresponding to reflection about the XY plane is 1 0 0 0 0 1 0 0 S(1, 1, -1) = 0 0 -1 0 0 0 0 1 Experiment: =========== glMultMatrix(m) multiplies the current matrix with the one specified in 'm'. 'm' points to a 4x4 matrix of floating point values stored in column-major order. Hence for our example the Translation matrix given by : 1 0 0 3 0 1 0 0 Matrix = 0 0 1 0 0 0 0 1 woule be specified as follows: m = { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 3, 0, 0, 1} corresponding to elements [0], [1], [2], ... [15] Try changing the values of the matrix elements to perform the following: a) A translation of the cube 3 units along the X axis b) A translation of the cube 2 units along the X axis 3 units along the Y axis and 2 units along the -ve Z axis c) Perform a rotation of 30 degrees about the X axis d) Create a reflection along the XY plane Answers: ======== a) m = {1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 3, 0, 0, 1} b) m = {1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 2, 3, -2,1} c) m = {1, 0, 0, 0, 0, C, S, 0, 0, -S, C, 0, 0, 0, 0, 1} where C = cos(30) = 0.8659 and S = sin(30) = 0.5001 d) m = {1, 0, 0, 0, 0, 1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1}