28 lines
803 B
C
28 lines
803 B
C
|
#include "camera.h"
|
||
|
|
||
|
t_matrix4 camera_look_at(const t_camera *const camera) {
|
||
|
/* from cglm */
|
||
|
const t_fvec3 f = m_vec_norm(m_vec_sub(camera->pos, camera->target));
|
||
|
const t_fvec3 r = m_vec_norm(m_vec_cross(f, camera->up));
|
||
|
const t_fvec3 u = m_vec_cross(f, r);
|
||
|
|
||
|
t_matrix4 result;
|
||
|
|
||
|
result.row[0].x = r.x;
|
||
|
result.row[0].y = u.x;
|
||
|
result.row[0].z =-f.x;
|
||
|
result.row[1].x = r.y;
|
||
|
result.row[1].y = u.y;
|
||
|
result.row[1].z =-f.y;
|
||
|
result.row[2].x = r.z;
|
||
|
result.row[2].y = u.z;
|
||
|
result.row[2].z =-f.z;
|
||
|
result.row[3].x =-m_vec_dot(r, camera->pos);
|
||
|
result.row[3].y =-m_vec_dot(u, camera->pos);
|
||
|
result.row[3].z = m_vec_dot(f, camera->pos);
|
||
|
result.row[0].w = result.row[1].w = result.row[2].w = 0.0f;
|
||
|
result.row[3].w = 1.0f;
|
||
|
|
||
|
return result;
|
||
|
}
|