Matrix Multiplication -- Basic Question

Started by
11 comments, last by Prongbuck 22 years ago
Hi there, I just bought the book OpenGL Game Programming and have been going through it slowly, being new to every aspect of OpenGL/3D math. So far things are fine but I've come across an example in the book that I havent been able to figure out and I'm curious if it's just me or the example is mistaken, here it is: (It's at the top of page 82 if you happen to have a copy)
      
|1 0  0    0   |   |x|   |   x   |
|0 1  0    0   | * |y| = |   y   |
|0 0  0 1/focus|   |z|   |  -1   |
|0 0 -1    0   |   |1|   |z/focus| 
  
is this correct? The way I figure it, in order to obtain the resulting matrix as is in the book the first matrix would have to look like this:
      
|1 0    0     0|
|0 1    0     0|
|0 0    0    -1|
|0 0 1/focus  0|
  
Any help is appreciated, thanks. Edited by - Prongbuck on April 3, 2002 5:13:50 PM
Advertisement
You''re right, I can''t see how they got that product from what they''ve given.
Isn't it due to row/column swapped format used in OpenGL ?
It's wrong in a mathematical manner but right in OpenGL manner. In fact you have to see :

Mathematical manner:
| 1  0    0     0 |   |x|   |    x    || 0  1    0     0 |   |y|   |    y    || 0  0    0    -1 | * |z| = |   -1    || 0  0 1/focus  0 |   |1|   | z/focus | 


OpenGL manner:
             | 1  0  0    0    |             | 0  1  0    0    || x y z 1| * | 0  0  0 1/focus | = | x  y  -1  z/focus |             | 0  0 -1    0    | 


Someone agree?

I know that I don't know nothing... Operation Ivy

[edited by - bloodscourge on April 3, 2002 6:41:06 PM]
I know that I don't know nothing... Operation Ivy
ProngBuck,

It must be a typo.

BloodScourge,

Your math is correct, but your comments are not. OpenGL does not do a "row/column swap". That is a myth coming from confusion with how OpenGL stores matrices in memory.

Your first example is how OpenGL does transformations and the second is how D3D does transformations and both are correct. One may be more popular, but that doesn''t matter.
Thanks for the replies, I''m loving this book so far but that error threw me. Now that that''s figured out I can turn the page
AnonPost, doesn''t OpenGL adopt row vector representation?

That representation is due to the fact that OpenGL packs vectors and matrices as one-dimensionnal arrays in memory. It avoids accesses costs with two-dimensionnal arrays (for matrices). That''s the reason why I think it''s better to swap row/column in your formula

It''s just a feeling... but results the same!

I know that I don''t know nothing... Operation Ivy
I know that I don't know nothing... Operation Ivy
...moreover the way OpenGl packs matrices allows easy extraction of their vectors!


I know that I don''t know nothing... Operation Ivy
I know that I don't know nothing... Operation Ivy
I don''t understand that distinction. If you store the transpose then to me you are using the transpose. I seem to be missing something here. It sounds like you are arguing that the order of the matrices didn''t change, but rather the definition of matrix multiplication changed. That is one view, but it isn''t the conventional view.
Keys to success: Ability, ambition and opportunity.
Why does OpenGL store the transpose instead of non-transpose?

Here is my way of thinking :

It is greater to manipulate a matrix with a one-dimensionnal array instead of a two dimensionnal : it allows you to reduce the cost of calculation in order to access an element. Thus matrices and vectors are only one-dimensionnal arrays. In this case it is more convenient to think with a row-vector representation. Moreover, in order to easily access basis vectors of a matrix, you have to store column vector linearly(for a column-vector representation : mathematical way (mostly)).
So it is more convenient to transpose the original matrix in order to be mathematically correct.

That's why :

Mathematical manner:
| 1  0    0     0 |   |x|   |    x    || 0  1    0     0 |   |y|   |    y    || 0  0    0    -1 | * |z| = |   -1    || 0  0 1/focus  0 |   |1|   | z/focus | 

OpenGL manner:
             | 1  0  0    0    |             | 0  1  0    0    || x y z 1| * | 0  0  0 1/focus | = | x  y  -1  z/focus |             | 0  0 -1    0    | 

One more thing : t(tB * tA) = A * B (A,B are matrices ; t is transpose)

[edited by - bloodscourge on April 5, 2002 4:04:16 PM]
I know that I don't know nothing... Operation Ivy
where :
| 1  0  0    0    | -> 1° axis (X homogeneous)| 0  1  0    0    | -> 2° axis (Y homogeneous)| 0  0  0 1/focus | -> 3° axis (Z homogeneous)| 0  0 -1    0    | -> homogeneous row  

memory packing :
| 1 0 0 0 || 0 1 0 0 || 0 0 0 1/focus || 0 0 -1 0 | 


[edited by - bloodscourge on April 5, 2002 3:59:30 PM]
I know that I don't know nothing... Operation Ivy

This topic is closed to new replies.

Advertisement