# OpenGL Perspective Matrix Mistake?

This topic is 5116 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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

bump

##### Share on other sites
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

##### Share on other sites
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.

##### Share on other sites
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.

##### Share on other sites
>>Why does OpenGL do that? It makes it more confusing<<

theres been a few explanations over the years perhaps google will help

##### Share on other sites
Quote:
 By EnigmaIs 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 0Enigma

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

1. 1
2. 2
Rutin
20
3. 3
khawk
17
4. 4
A4L
14
5. 5

• 12
• 16
• 26
• 10
• 11
• ### Forum Statistics

• Total Topics
633758
• Total Posts
3013713
×