shapeare

06-29-2012, 07: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{

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):

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;

}

else

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.

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):

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;

}

else

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.