Thread: A question on the transformation pipeline in OpenGL superbible 5th

1. A question on the transformation pipeline in OpenGL superbible 5th

The author used the following data structure for the convenience of representing a frame of reference (on Page 168 of the book)
Code :
```class GLFrame{
protected：
float vLocation[3];
float vUp[3];
float vForward[3];

public:
...
}```

Then he provided a function that calculates a matrix which is unclear to me (on Page 168 of the book):
Code :
```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;

if(bRotationOnly == true)
{
matrix[12] = 0.0f;
matrix[13] = 0.0f;
matrix[14] = 0.0f;
}
else
m3dSetMatrixColumn44(matrix, vOrigin, 3);

matrix[15] = 1.0f;
}```

He used the matrix on Page 174 through
Code :
`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.

2. I assume modelViewMatrix is of type M3DMatrix44f? My guess is there is an overload of MultMatrix that takes a GLFrame, like so:

Code :
```void M3DMatrix44f::MultMatrix(const GLFrame& frame)
{
M3DMatrix44f frameMatrix;
frame.GetMatrix(frameMatrix);

this->MultMatrix(frameMatrix);
}```

This assumes that the signature of GetMatrix is actually:

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

Note the "&" to allow modifying the argument.

3. But the call of
GLFrame::GetMatrix() does not return an identity matrix by default. In fact, it is
Code :
```{-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:
Code :
```{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.

Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•