Perspective Matrix Mistake?

Started by
5 comments, last by Khaosifix 19 years, 4 months ago
Hello, I think I've spotted a unreported mistake in the book, "OpenGL Game Programming". On page 82 where Perspective Matrix are described. The author defines the OpenGL perspective matrix as :

| 1 0 0 0 |
| 0 1 0 0 |
| 0 0 0 1/focus |
| 0 0 -1 0 |

The author then multiplies the perspective matrix by a vector point :

M_P
| 1 0 0 0 |
| 0 1 0 0 |
| 0 0 0 1/focus |
| 0 0 -1 0 |

v
| x |
| y |
| z |
| 1 |

And gets this as the product :

| x |
| y |
| -1 |
| z/focus |

// shouldn't it be :

| x |
| y |
| 1/focus |
| -z |

// ?

~Khaosifix
---http://www.michaelbolton.comI constantly dream about Michael Bolton.
Advertisement
bump
---http://www.michaelbolton.comI constantly dream about Michael Bolton.
Is this example in matrix algebra or C code? If it's in C code then this is correct, since OpenGL uses column-major matrices, not row-major matrices, so the matrix defined by:
float mat4[16] = {	1, 0, 0, 0,	0, 1, 0, 0,	0, 0, 0, 1/focus,	0, 0, -1, 0}

is actually the matrix:
1 0 0 0
0 1 0 0
0 0 0 -1
0 0 1/focus 0

Enigma
Aw man. Thanks. Looking at it from a matrix algebra perspective its wrong but I didn't know about the column major thingy OpenGL does.

Why does OpenGL do that? It makes it more confusing IMO.
---http://www.michaelbolton.comI constantly dream about Michael Bolton.
I think they did it to optimize their vertex pipeline, the way they store it they can read the whole matrix continiously instead of hopping back and forth between the rows which costs some extra time. Not really sure though but that seems reasonable.
>>Why does OpenGL do that? It makes it more confusing<<

theres been a few explanations over the years perhaps google will help
Quote:
By Enigma
Is this example in matrix algebra or C code? If it's in C code then this is correct, since OpenGL uses column-major matrices, not row-major matrices, so the matrix defined by:

float mat4[16] = {

1, 0, 0, 0,

0, 1, 0, 0,

0, 0, 0, 1/focus,

0, 0, -1, 0

}


is actually the matrix:
1 0 0 0
0 1 0 0
0 0 0 -1
0 0 1/focus 0

Enigma




http://www.opengl.org/resources/faq/technical/transformations.htm#tran0005

The link speaks for itself.
---http://www.michaelbolton.comI constantly dream about Michael Bolton.

This topic is closed to new replies.

Advertisement