Jump to content
  • Advertisement
Sign in to follow this  
Khaosifix

OpenGL Perspective Matrix Mistake?

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

If you intended to correct an error in the post then please contact us.

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

Share this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!