alexlarsson / gthree

Gthree is a GObject/Gtk+ port of three.js
MIT License
87 stars 13 forks source link

Decompose matrix in gthree_object_set_world_matrix() #30

Closed alexlarsson closed 5 years ago

alexlarsson commented 5 years ago

When this is done we can stop setting auto_update to FALSE if matrix is set in the GLTF loader.

alexlarsson commented 5 years ago

This requires graphene support for decomposing a matrix, @ebassi said exposing this was ok.

ebassi commented 5 years ago

What kind of API would you need?

Would something like this be enough:

bool
graphene_matrix_decompose (const graphene_matrix_t *m,
                           graphene_vec3_t         *translate_out,
                           graphene_vec3_t         *scale_out,
                           graphene_quaternion_t   *rotate_out,
                           graphene_vec4_t         *perspective_out,
                           graphene_vec3_t         *shear_out);

The "meh" bit is that the decomposition code for 2D matrices is slightly different, but it should be doable.

alexlarsson commented 5 years ago

In practice, gthree will only ever need translation, scale and rotation, as those are the properties it has for the node. Its just not gonna be possible to set a perspective matrix on a node, and then start to modify the translation expecting the perspective to stay. However, for completeness it makes sense for the api to have it.

For 2d matrices, do we even have any support for 2x2 or 3x3 (homogenous 2d) matrices?

ebassi commented 5 years ago

For 2d matrices, do we even have any support for 2x2 or 3x3 (homogenous 2d) matrices?

Yes, Graphene supports affine transformations, and has a separate code path for the decomposition and interpolation, based on the CSS spec.