/********************************************************/ /* */ /* */ /* This method transforms a Tuple based on a */ /* tranformation matrix */ /********************************************************/ Tuple Tuple::matrixMultiply(float m[]) { // m is a 4x4 matrix stored in column-major order // in a length 16 array // // to compute the multiplication we should convert // this into a 4-tuple with a 1 in the new dimension // perform the multiplication, then strip off the // last dimension // // the following achieves the same effect // without the conversion Tuple tmp(0,0,0); for (int j=0; j<3; j++) { // for each row of the matrix for (int k=0; k<3; k++) { // for each column tmp[j] += m[j+4*k]*data[k]; // the matrix is column-major } tmp[j]+=m[j+12]; } return tmp; }