shapeare

02-16-2012, 07:36 PM

I am using the library GLTools that comes with the book OpenGL SuperBible 5.

The orthographic projection building function provided by this library is (in column-major order):

void m3dMakeOrthographicMatrix(M3DMatrix44f mProjection, float xMin, float xMax,

float yMin, float yMax, float zMin, float zMax)

{

m3dLoadIdentity44(mProjection);

mProjection[0] = 2.0f / (xMax - xMin);

mProjection[5] = 2.0f / (yMax - yMin);

mProjection[10] = -2.0f / (zMax - zMin);

mProjection[12] = -((xMax + xMin)/(xMax - xMin));

mProjection[13] = -((yMax + yMin)/(yMax - yMin));

mProjection[14] = -((zMax + zMin)/(zMax - zMin));

mProjection[15] = 1.0f;

}

I am a little confused why mProjection[10] starts with a subtraction sign.

While referring to the book Fundamentals of Computer Graphics third edition, in section 7.1.2 The Orthographic Projection Transformation, the corresponding value to mProjection[10] is given as 2/(n-f), and mProjection[14] is given as -((n + f)/(n - f)),

that is something like:

m3dLoadIdentity44(mProjection);

mProjection[0] = 2.0f / (r-l);

mProjection[5] = 2.0f / (t-b);

mProjection[10] = 2.0f / (n-f);

mProjection[12] = -((r+l)/(r-l));

mProjection[13] = -((t+b)/(t-b));

mProjection[14] = -((n+f)/(n-f));

mProjection[15] = 1.0f;

where

l the left plane, r the right plane,

b the bottom plane, t the top plane,

n the near plane, f the far plane.

Personally, either must be wrong. But which one?

The orthographic projection building function provided by this library is (in column-major order):

void m3dMakeOrthographicMatrix(M3DMatrix44f mProjection, float xMin, float xMax,

float yMin, float yMax, float zMin, float zMax)

{

m3dLoadIdentity44(mProjection);

mProjection[0] = 2.0f / (xMax - xMin);

mProjection[5] = 2.0f / (yMax - yMin);

mProjection[10] = -2.0f / (zMax - zMin);

mProjection[12] = -((xMax + xMin)/(xMax - xMin));

mProjection[13] = -((yMax + yMin)/(yMax - yMin));

mProjection[14] = -((zMax + zMin)/(zMax - zMin));

mProjection[15] = 1.0f;

}

I am a little confused why mProjection[10] starts with a subtraction sign.

While referring to the book Fundamentals of Computer Graphics third edition, in section 7.1.2 The Orthographic Projection Transformation, the corresponding value to mProjection[10] is given as 2/(n-f), and mProjection[14] is given as -((n + f)/(n - f)),

that is something like:

m3dLoadIdentity44(mProjection);

mProjection[0] = 2.0f / (r-l);

mProjection[5] = 2.0f / (t-b);

mProjection[10] = 2.0f / (n-f);

mProjection[12] = -((r+l)/(r-l));

mProjection[13] = -((t+b)/(t-b));

mProjection[14] = -((n+f)/(n-f));

mProjection[15] = 1.0f;

where

l the left plane, r the right plane,

b the bottom plane, t the top plane,

n the near plane, f the far plane.

Personally, either must be wrong. But which one?