summaryrefslogtreecommitdiff
path: root/cogl
diff options
context:
space:
mode:
authorGeorges Basile Stavracas Neto <georges.stavracas@gmail.com>2020-09-10 10:52:38 -0300
committerGeorges Basile Stavracas Neto <georges.stavracas@gmail.com>2020-10-06 15:34:46 +0000
commit0dbd6d3a808f8459d6756db044330ad44c2308c3 (patch)
tree757653deb7b05259ffa9477bda659b97cebb2256 /cogl
parent2b7a73e0c3580cc41e5ed321dd6703a1f8409b0d (diff)
downloadmutter-0dbd6d3a808f8459d6756db044330ad44c2308c3.tar.gz
cogl/matrix: Look-at using graphene matrices
https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1439
Diffstat (limited to 'cogl')
-rw-r--r--cogl/cogl/cogl-matrix.c52
1 files 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 (&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