PDA

View Full Version : Matrices



maedhros777
03-03-2010, 03:08 PM
I just ran this code, being curious to see OpenGL's matrix multiplication: main.cpp (http://docs.google.com/View?id=dd7xssbg_11hpwpm7d9) and I got the following result:

Modelview Identity:
Matrix:
7.92252e+33 5.60519e-45 0 0
5.95171e-39 3.21396e-39 3.21401e-39 3.2142e-39
7.92481e+33 7.8354e+33 NaN 7.92252e+33
7.92254e+33 5.95171e-39 3.21405e-39 5.95186e-39

Modelview Translation of 2, 2, 2:
Matrix:
7.92252e+33 5.60519e-45 0 0
5.95171e-39 3.21396e-39 3.21401e-39 3.2142e-39
7.92481e+33 7.8354e+33 NaN 7.92252e+33
7.92254e+33 5.95171e-39 3.21405e-39 5.95186e-39

Modelview Scaling of 2, 2, 2:
Matrix:
7.92252e+33 5.60519e-45 0 0
5.95171e-39 3.21396e-39 3.21401e-39 3.2142e-39
7.92481e+33 7.8354e+33 NaN 7.92252e+33
7.92254e+33 5.95171e-39 3.21405e-39 5.95186e-39

Projection Identity:
Matrix:
7.92252e+33 5.60519e-45 0 0
5.95171e-39 3.21396e-39 3.21401e-39 3.2142e-39
7.92481e+33 7.8354e+33 NaN 7.92252e+33
7.92254e+33 5.95171e-39 3.21405e-39 5.95186e-39

Projection glOrtho -2.0, 2.0, -2.0, 2.0, -2.0, 2.0:
Matrix:
7.92252e+33 5.60519e-45 0 0
5.95171e-39 3.21396e-39 3.21401e-39 3.2142e-39
7.92481e+33 7.8354e+33 NaN 7.92252e+33
7.92254e+33 5.95171e-39 3.21405e-39 5.95186e-39

Projection glFrustum -2.0, 2.0, -2.0, 2.0, 1.0, 10.0:
Matrix:
7.92252e+33 5.60519e-45 0 0
5.95171e-39 3.21396e-39 3.21401e-39 3.2142e-39
7.92481e+33 7.8354e+33 NaN 7.92252e+33
7.92254e+33 5.95171e-39 3.21405e-39 5.95186e-39


Process returned 0 (0x0) execution time : 0.125 s
Press any key to continue.

Shouldn't it start with the identity matrix? I have a feeling I made a mistake somewhere.

trinitrotoluene
03-03-2010, 03:20 PM
When you call the OpenGL matrix functions do you have a valid rendering context?

maedhros777
03-03-2010, 03:34 PM
Oh, you're right. :) I knew it would be a silly mistake like that. By the way, why does OpenGL need a valid rendering context for the matrices to make sense?

Stanley L
03-03-2010, 03:53 PM
The OpenGL matrix stack is stored with the context. If you switched rendering contexts and your matrix stack didn't change accordingly, that could make things rather difficult...

trinitrotoluene
03-03-2010, 03:54 PM
By the way, why does OpenGL need a valid rendering context for the matrices to make sense?
Don't forget that OpenGL API is a specification so, an OpenGL driver might implement matrix manipulation in hardware (accelerated on the video card) another driver might implement matrix manipulation in software (on the cpu). So the API is not able to perform anything before a valid rendering context is active. This explanation is oversimplified and hope is not wrong.

maedhros777
03-03-2010, 04:05 PM
Thanks for all your answers, I knew there must have been something wrong with values like "5.95171e-39" and "NaN" in an OpenGL matrix.