ebassi / graphene

A thin layer of graphic data types
http://ebassi.github.io/graphene
Other
373 stars 80 forks source link

Identity matrix is treated as 2d, decomposing only xy scale #250

Closed ChristophHaag closed 1 month ago

ChristophHaag commented 2 years ago
#include <stdio.h>
#include <graphene.h>
int main() {
  graphene_matrix_t transform;
  graphene_matrix_init_identity (&transform);

  printf("is 2d: %d\n", graphene_matrix_is_2d(&transform));

  graphene_vec3_t transl;
  graphene_vec3_t scale;
  graphene_quaternion_t rot;
  graphene_vec3_t shear;
  graphene_vec4_t persp;
  bool ret = graphene_matrix_decompose (&transform,
                                        &transl,
                                        &scale,
                                        &rot,
                                        &shear,
                                        &persp);

  printf ("scale %f %f %f\n",
    graphene_vec3_get_x (&scale),
    graphene_vec3_get_y (&scale),
    graphene_vec3_get_z (&scale));
}

compiled with gcc $(pkg-config --libs --cflags graphene-1.0) graphene_matrix.c

Experienced behavior

is 2d: 1
scale 1.000000 1.000000 0.000000

Expected behavior

scale 1.000000 1.000000 1.000000

Operating system in use

Archlinux, graphene 1.10.8

SIMD implementation in use

Defaults on x86_64, Ryzen 3950X

ebassi commented 1 month ago

Well, technically an identity matrix is also a 2D matrix; you should classify matrices differently:

if (graphene_matrix_is_identity (&m))
  // identity
else if (graphene_matrix_is_2d (&m))
  // affine
else
  // 3D

The issue with the decomposition of an identity matrix is valid, though: graphene_matrix_decompose() should consider an identity matrix as a 3D matrix.