[mutter/gbsneto/graphene-matrix: 19/41] cogl/matrix: Look-at using graphene matrices




commit b87a7a534f059244ce36bf499ef606e64557b51b
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Thu Sep 10 10:52:38 2020 -0300

    cogl/matrix: Look-at using graphene matrices

 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 d5bfa6c8e9..925379e8b5 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 (&center, 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);
-
-  /* Now we have unit sideways and forward-direction vectors calculate
-   * a new mutually perpendicular up vector. */
-  graphene_vec3_cross (&side, &forward, &up);
-
-  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);
+  graphene_matrix_init_look_at (&m, &eye, &center, &up);
 
-  cogl_matrix_translate (&tmp, -eye_position_x, -eye_position_y, -eye_position_z);
+  graphene_matrix_to_cogl_matrix (&m, &look_at);
+  look_at.flags = MAT_FLAG_GENERAL_3D | MAT_DIRTY_TYPE | MAT_DIRTY_INVERSE;
 
-  cogl_matrix_multiply (matrix, matrix, &tmp);
+  cogl_matrix_multiply (matrix, matrix, &look_at);
 }
 
 void


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]