cogl/matrix: Apply look-at using Graphene

This commit is contained in:
Georges Basile Stavracas Neto 2019-02-28 08:32:27 -03:00
parent 8ff79c3b7d
commit a127360df1
No known key found for this signature in database
GPG Key ID: 886C17EE170D1385

View File

@ -713,52 +713,22 @@ cogl_matrix_look_at (CoglMatrix *matrix,
float world_up_y, float world_up_y,
float world_up_z) float world_up_z)
{ {
CoglMatrix tmp; graphene_matrix_t look_at, m;
graphene_vec3_t forward; graphene_vec3_t eye, center, up;
graphene_vec3_t side;
graphene_vec3_t up;
/* 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); graphene_vec3_init (&up, world_up_x, world_up_y, world_up_z);
graphene_matrix_init_look_at (&look_at, &eye, &center, &up);
/* Take the sideways direction as being perpendicular to the viewing cogl_matrix_to_graphene_matrix (matrix, &m);
* direction and the word up vector. */ graphene_matrix_transpose (&m, &m);
graphene_vec3_cross (&forward, &up, &side);
graphene_vec3_normalize (&side, &side);
/* Now we have unit sideways and forward-direction vectors calculate graphene_matrix_translate (&m, &GRAPHENE_POINT3D_INIT (-eye_position_x,
* a new mutually perpendicular up vector. */ -eye_position_y,
graphene_vec3_cross (&side, &forward, &up); -eye_position_z));
graphene_matrix_multiply (&m, &look_at, &m);
tmp.xx = graphene_vec3_get_x (&side); graphene_matrix_to_cogl_matrix (&m, matrix);
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;
cogl_matrix_translate (&tmp, -eye_position_x, -eye_position_y, -eye_position_z);
cogl_matrix_multiply (matrix, matrix, &tmp);
} }
void void