From 0dbd6d3a808f8459d6756db044330ad44c2308c3 Mon Sep 17 00:00:00 2001 From: Georges Basile Stavracas Neto Date: Thu, 10 Sep 2020 10:52:38 -0300 Subject: [PATCH] cogl/matrix: Look-at using graphene matrices https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1439 --- cogl/cogl/cogl-matrix.c | 52 ++++++++--------------------------------- 1 file changed, 10 insertions(+), 42 deletions(-) diff --git a/cogl/cogl/cogl-matrix.c b/cogl/cogl/cogl-matrix.c index d5bfa6c8e..925379e8b 100644 --- a/cogl/cogl/cogl-matrix.c +++ b/cogl/cogl/cogl-matrix.c @@ -1946,54 +1946,22 @@ cogl_matrix_look_at (CoglMatrix *matrix, float world_up_y, float world_up_z) { - CoglMatrix tmp; - graphene_vec3_t forward; - graphene_vec3_t side; + graphene_matrix_t m; + graphene_vec3_t eye; + graphene_vec3_t center; graphene_vec3_t up; + CoglMatrix look_at; - /* Get a unit viewing direction vector */ - graphene_vec3_init (&forward, - object_x - eye_position_x, - object_y - eye_position_y, - object_z - eye_position_z); - graphene_vec3_normalize (&forward, &forward); - + graphene_vec3_init (&eye, eye_position_x, eye_position_y, eye_position_z); + graphene_vec3_init (¢er, object_x, object_y, object_z); graphene_vec3_init (&up, world_up_x, world_up_y, world_up_z); - /* Take the sideways direction as being perpendicular to the viewing - * direction and the word up vector. */ - graphene_vec3_cross (&forward, &up, &side); - graphene_vec3_normalize (&side, &side); + graphene_matrix_init_look_at (&m, &eye, ¢er, &up); - /* Now we have unit sideways and forward-direction vectors calculate - * a new mutually perpendicular up vector. */ - graphene_vec3_cross (&side, &forward, &up); + graphene_matrix_to_cogl_matrix (&m, &look_at); + look_at.flags = MAT_FLAG_GENERAL_3D | MAT_DIRTY_TYPE | MAT_DIRTY_INVERSE; - tmp.xx = graphene_vec3_get_x (&side); - tmp.yx = graphene_vec3_get_y (&side); - tmp.zx = graphene_vec3_get_z (&side); - tmp.wx = 0; - - tmp.xy = graphene_vec3_get_x (&up); - tmp.yy = graphene_vec3_get_y (&up); - tmp.zy = graphene_vec3_get_z (&up); - tmp.wy = 0; - - tmp.xz = -graphene_vec3_get_x (&forward); - tmp.yz = -graphene_vec3_get_y (&forward); - tmp.zz = -graphene_vec3_get_z (&forward); - tmp.wz = 0; - - tmp.xw = 0; - tmp.yw = 0; - tmp.zw = 0; - tmp.ww = 1; - - tmp.flags = (MAT_FLAG_GENERAL_3D | MAT_DIRTY_TYPE | MAT_DIRTY_INVERSE); - - cogl_matrix_translate (&tmp, -eye_position_x, -eye_position_y, -eye_position_z); - - cogl_matrix_multiply (matrix, matrix, &tmp); + cogl_matrix_multiply (matrix, matrix, &look_at); } void