View Full Version : A question on the transformation pipeline in OpenGL superbible 5th

06-29-2012, 06:53 AM
The author used the following data structure for the convenience of representing a frame of reference (on Page 168 of the book)

class GLFrame{
float vLocation[3];
float vUp[3];
float vForward[3];


Then he provided a function that calculates a matrix which is unclear to me (on Page 168 of the book):

void GetMatrix(M3DMatrix44f matrix, bool bRotationOnly = false)
// Calculate the right side (x) vector, drop it right into the matrix
M3DVector3f vXAxis;
m3dCrossProduct3(vXAxis, vUp, vForward);

// Set matrix column does not fill in the fourth value...
m3dSetMatrixColumn44(matrix, vXAxis, 0);
matrix[3] = 0.0f;

// Y Column
m3dSetMatrixColumn44(matrix, vUp, 1);
matrix[7] = 0.0f;

// Z Column
m3dSetMatrixColumn44(matrix, vForward, 2);
matrix[11] = 0.0f;

// Translation (already done)
if(bRotationOnly == true)
matrix[12] = 0.0f;
matrix[13] = 0.0f;
matrix[14] = 0.0f;
m3dSetMatrixColumn44(matrix, vOrigin, 3);

matrix[15] = 1.0f;

He used the matrix on Page 174 through

modelViewMatrix.MultMatrix(spheres[i]); //it equals to multiply the matrix got from spheres[i].GetMatrix()

Here, spheres[i] is an object of the GLFrame class.
I think the author actually wanted to multiply the object's model transform matrix, but he misused the GetMatrix() function.
Could anyone help me verify my assumption?

Sorry for my rough description.

carsten neumann
07-02-2012, 01:30 PM
I assume modelViewMatrix is of type M3DMatrix44f? My guess is there is an overload of MultMatrix that takes a GLFrame, like so:

void M3DMatrix44f::MultMatrix(const GLFrame& frame)
M3DMatrix44f frameMatrix;


This assumes that the signature of GetMatrix is actually:

void GLFrame::GetMatrix(M3DMatrix44f& matrix, bool bRotationOnly = false) const

Note the "&" to allow modifying the argument.

07-02-2012, 06:40 PM
But the call of
GLFrame::GetMatrix() does not return an identity matrix by default. In fact, it is

{-1, 0, 0, 0,
0, 1, 0, 0,
0, 0,-1, 0,
0, 0, 0, 1
}//in column major

I expect it to be an identity matrix.

Because when GLFrame was first initialized,
vUp is {0, 1, 0},
vForward is {0, 0, -1},
vLocation is {0, 0, 0}
In the function GetMatrix(), the author first computed vRight which is the cross product of vUp and vForward, and then drop the three vectors into the resulting matrix:

{vRight_x, vRight_y, vRight_z, 0
vUp_x, vUp_y, vUp_z, 0
vForward_x, vForward_y, vForward_z, 0
vLocation_x, vLocation_y, vLocation_z, 1
}//in column major

but it should return an identity matrix.