[osg-users] Matrix multiplication order

245 views
Skip to first unread message

Florian GOLESTIN

unread,
Mar 22, 2018, 5:48:48 AM3/22/18
to osg-...@lists.openscenegraph.org
Hi everyone !

I don't get why in GLSL you transform a vertex like this:


Code:
vec4 result = matrix * vertex;



While in OSG I have to do it in the reverse order :


Code:
osg::Vec4 result = vertex * matrix;



Is it due to the Matrices major mode that are different from OpenGL and OpenSceneGraph ?

Thanks for demystifying me!

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=73145#73145





_______________________________________________
osg-users mailing list
osg-...@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Robert Osfield

unread,
Mar 22, 2018, 7:04:55 AM3/22/18
to OpenSceneGraph Users
Hi Florian,

The difference is down to history, the OSG is row major chosen very
earliest days of the OSG (back in 2000) and OpenGL 1.x days, and
OpenGL GLSL ended choosing column major a few years later. The OpenGL
matrices are actually stored the same way as OSG matrices in main
memory.

To change the OSG to be the same convention would have broken user
applications that had already adopted the OSG so I chose not to change
the order once OpenGL GLSL came out. I now regret not just biting the
bullet and forcing the OSG community to swtich, it would have been
painful, but obviously would have easier for new developers. However,
now we even more code base that works with the OSG multiplication
order so it would be even more painful to convert across so we are
stuck.

Robert.

Florian GOLESTIN

unread,
Mar 22, 2018, 9:09:26 AM3/22/18
to osg-...@lists.openscenegraph.org
Hi Robert,

Thanks for the answer, I understand now.

I worked as a Support Engineer and understand the hard choice of breaking an API :)

Florian

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=73149#73149

Robert Osfield

unread,
Mar 22, 2018, 9:50:04 AM3/22/18
to OpenSceneGraph Users
On 22 March 2018 at 13:13, Florian GOLESTIN <florian....@gmail.com> wrote:
> Hi Robert,
>
> Thanks for the answer, I understand now.
>
> I worked as a Support Engineer and understand the hard choice of breaking an API :)

Paradoxically I would probably have made the change if I could have
broken the API and forced users to change the problematic code with
the compiler pinpointing the problems. With a change in convention
the code remains compatible so will compile without any issues but
will silently start behaving differently. Users would end up with
applications that compile and run but have these bugs lurking and
appearing in odd, difficult to understand ways.

Another paradox is that OpenGL matrices are stored in main memory as
row major, but the GLSL convention is column major.

Software engineering can just get a bit messy sometimes even when you
have the best of intentions!

Robert.
Reply all
Reply to author
Forward
0 new messages