Search code examples
c#mathmatrixcollada

How do I convert a 4x4 matrix from translation, rotation and scale transformations?


I have 3 transformations of the human skeleton (example of hips bone):

  <node id="hips" name="hips_bone" type="JOINT">
    <translate>0 0.941045 -0.02637</translate>
    <rotate sid="rotateZ">0 0 1 90</rotate>
    <rotate sid="rotateY">0 1 0 -12.0004</rotate>
    <rotate sid="rotateX">1 0 0 0</rotate>
    <scale>1 1 1</scale>
  </node>

Is there a way to convert this data into 4x4 matrix? (I suppose we can throw scale transformation off because it's always 1 1 1).

To be more precise the result I want to achieve:

<matrix sid="matrix">
  0.978148 -0.207912 0.000000 0.000000
  0.207912 0.978148 0.000000 -0.000012
  -0.000000 0.000000 1.000000 0.000000
  0.000000 0.000000 0.000000 1.000000
</matrix>

(the result matrix is not equal to the transformations data above).

And is there any useful structures in c# to work with 4x4 matrices?


Solution

  • If you want to use 3D graphics with C# you could use dedicated framework, e.g OpenTK (https://www.nuget.org/packages/OpenTK/). It provides a way to use OpenGL functionalities with C#. It also has many useful methods to deal with transformations, including using 4x4 matrices. With OpenTK library you can get also some sample projects to see how it works, or get through one of the tutorials (e.g. http://genericgamedev.com/tutorials/opengl-in-csharp-an-object-oriented-introduction-to-opentk/).

    What I liked about OpenTK was also the fact that it could be injected into WinForms or WPF project just like any other control or usds in Game Window mode similar to the one used in OpenGL.

    I hope I could help.