View Full Version : column major matrix multiplication

khdani

12-24-2009, 02:14 AM

Hello,

I've created a matrix class for use in OpenGL,

the matrix class uses two-dimensional float array,

how should I do multiplication of matrices correctly ?

Dark Photon

12-24-2009, 08:12 AM

Hello,

I've created a matrix class for use in OpenGL,

the matrix class uses two-dimensional float array,

how should I do multiplication of matrices correctly ?

A tip: OpenGL is column-major operator-on-the-left (e.g. P*V*M * v1 = v2)

This is the same as row-major operator-on-the-right (e.g. v1 * M*V*P = v2).

Flipping both results in a net-zero change in the math. You get exactly the same values in exactly the same memory locations.

So since C/C++ is row-major, do the second one. More here (http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=258188#Post2581 88). With this you can spoon your row-major operator-on-the-right matrices directly to OpenGL (which expects column-major operator-on-the-left matrices) via glLoadMatrixd, glMatrixLoadf, glUniformMatrix4fv, or whatever... No need to waste time on useless transpose operations.

Powered by vBulletin® Version 4.2.2 Copyright © 2014 vBulletin Solutions, Inc. All rights reserved.