View Full Version : Could someone please explain post/pre multiplication of matrices?

dlk5730

07-11-2017, 12:30 PM

After calling glMultMatrix(m), is m pre or post-multiplied with the current matrix?

i.e.

current_matrix = m * current_matrix

or

current_matrix = current_matrix * m

*** Can you please point me to the paragraph in the OpenGL spec where pre-or-post multiplication is specified?

This is very important when developing a driver. Thank you all for your help!

EthanStark

07-11-2017, 01:10 PM

If you first translate by (50, 50) and then scale by two, you effectively translate by (50, 50) times two, i.e. (100, 100).

What you seem to need is to first scale by two (to have thing twice the size, but not yet moved or rotated) and only thereafter rotate and translate (without scaling affecting the translation), i.e.

[ 2 0 0 ] [ 0.707 0.707 0 ] [ 1.414 1.414 0 ]

[ 0 2 0 ] x [ -0.707 0.707 0 ] = [ -1.414 1.414 0 ]

[ 0 0 1 ] [ 50.000 50.000 1 ] [ 50.000 50.000 1 ]

dlk5730

07-11-2017, 02:48 PM

Thanks EthanStark. I also found the answer I was looking in the OpenGL spec 1.3, paragraph 2.10.2:

..."

If C is the current matrix and M is the matrix pointed to by MultMatrix’s argument,

then the resulting current matrix, C', is

C' = C * M:

"...

Q.E.D.

Corollary: read the spec carefully. The answer lies within.

================================================== ==================

If you first translate by (50, 50) and then scale by two, you effectively translate by (50, 50) times two, i.e. (100, 100).

What you seem to need is to first scale by two (to have thing twice the size, but not yet moved or rotated) and only thereafter rotate and translate (without scaling affecting the translation), i.e.

[ 2 0 0 ] [ 0.707 0.707 0 ] [ 1.414 1.414 0 ]

[ 0 2 0 ] x [ -0.707 0.707 0 ] = [ -1.414 1.414 0 ]

[ 0 0 1 ] [ 50.000 50.000 1 ] [ 50.000 50.000 1 ]

GClements

07-11-2017, 02:50 PM

After calling glMultMatrix(m), is m pre or post-multiplied with the current matrix?

i.e.

current_matrix = m * current_matrix

or

current_matrix = current_matrix * m

The latter (post-multiplied).

Can you please point me to the paragraph in the OpenGL spec where pre-or-post multiplication is specified?

For the OpenGL 1.0 specification (https://khronos.org/registry/OpenGL/specs/gl/glspec10.pdf), it's in §2.9.2, p25:

MultMatrix takes the same type argument as LoadMatrix, but multiplies the current matrix by the one pointed to and replaces the current matrix with the product. If C is the current matrix and M is the matrix pointed to by MultMatrix's argument, then the resulting current matrix, C', is

C' = C·M.

dlk5730

07-11-2017, 02:53 PM

Thanks GClements. I concur with your answer. It's neat that we both found the same answer in different versions of the spec. Cheers!

The latter (post-multiplied).

For the OpenGL 1.0 specification (https://khronos.org/registry/OpenGL/specs/gl/glspec10.pdf), it's in §2.9.2, p25:

Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.