Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

#29 mat3 and mat4 transpose when converting toList and back

closed-rejected
nobody
None
5
2010-04-05
2010-04-01
Alex
No

When converting a mat3 or mat4 to list and back, the result is the original matrix, but transposed.

Example:

>>> m = mat3(1).rotation(1, (0,0,1))
>>> m
=>
(0.540302, -0.841471, 0)
(0.841471, 0.540302, 0)
(0, 0, 1)

>>> m.toList()
=>
[0.54030230586813977,
0.8414709848078965,
0.0,
-0.8414709848078965,
0.54030230586813977,
0.0,
0.0,
0.0,
1.0]

>>> mat3(m.toList())
=>
(0.540302, 0.841471, 0)
(-0.841471, 0.540302, 0)
(0, 0, 1)

The same happens to mat4, i.e. x, y, z move from right column onto bottom line.

Discussion

  • Matthias Baas
    Matthias Baas
    2010-04-05

    • status: open --> closed-rejected
     
  • Matthias Baas
    Matthias Baas
    2010-04-05

    I admit that this is a bit unfortunate, but I wouldn't call it a bug. The behavior is actually documented. In the section about the constructor it says that elements must be given in row-major order and it also says that toList() returns elements in column-major order by default (but you could make the above work by explicitly setting the rowmajor argument to True when calling toList()).
    The rationale to pick column-major order as the default for toList() was to allow the result to be directly passed to OpenGL or RenderMan calls.
    If I were to write the package again, I would probably change the constructor so that it uses column-major order as well, but changing that now would potentially break all programs that already make use of the matrix classes and this particular kind of constructor.

    Cheers,

    - Matthias -