5 void vg_camera_lerp_angles( v3f a
, v3f b
, f32 t
, v3f d
)
7 d
[0] = vg_alerpf( a
[0], b
[0], t
);
8 d
[1] = vg_lerpf( a
[1], b
[1], t
);
9 d
[2] = vg_lerpf( a
[2], b
[2], t
);
12 /* lerp position, fov, and angles */
13 void vg_camera_lerp( vg_camera
*a
, vg_camera
*b
, f32 t
, vg_camera
*d
)
15 v3_lerp( a
->pos
, b
->pos
, t
, d
->pos
);
16 vg_camera_lerp_angles( a
->angles
, b
->angles
, t
, d
->angles
);
17 d
->fov
= vg_lerpf( a
->fov
, b
->fov
, t
);
20 void vg_camera_copy( vg_camera
*a
, vg_camera
*d
)
22 v3_copy( a
->pos
, d
->pos
);
23 v3_copy( a
->angles
, d
->angles
);
27 void vg_m4x3_transform_camera( m4x3f m
, vg_camera
*cam
)
29 m4x3_mulv( m
, cam
->pos
, cam
->pos
);
32 v3_angles_vector( cam
->angles
, v0
);
33 m3x3_mulv( m
, v0
, v0
);
35 v3_angles( v0
, cam
->angles
);
39 * 1) [angles, pos] -> transform
41 void vg_camera_update_transform( vg_camera
*cam
)
43 v4f qyaw
, qpitch
, qcam
;
44 q_axis_angle( qyaw
, (v3f
){ 0.0f
, 1.0f
, 0.0f
}, -cam
->angles
[0] );
45 q_axis_angle( qpitch
, (v3f
){ 1.0f
, 0.0f
, 0.0f
}, -cam
->angles
[1] );
47 q_mul( qyaw
, qpitch
, qcam
);
48 q_m3x3( qcam
, cam
->transform
);
49 v3_copy( cam
->pos
, cam
->transform
[3] );
53 * 2) [transform] -> transform_inverse, view matrix
55 void vg_camera_update_view( vg_camera
*cam
)
57 m4x4_copy( cam
->mtx
.v
, cam
->mtx_prev
.v
);
58 m4x3_invert_affine( cam
->transform
, cam
->transform_inverse
);
59 m4x3_expand( cam
->transform_inverse
, cam
->mtx
.v
);
63 * 3) [fov,nearz,farz] -> projection matrix
65 void vg_camera_update_projection( vg_camera
*cam
)
67 m4x4_copy( cam
->mtx
.p
, cam
->mtx_prev
.p
);
68 m4x4_projection( cam
->mtx
.p
, cam
->fov
,
69 (float)vg
.window_x
/ (float)vg
.window_y
,
70 cam
->nearz
, cam
->farz
);
74 * 4) [projection matrix, view matrix] -> previous pv, new pv
76 void vg_camera_finalize( vg_camera
*cam
)
78 m4x4_copy( cam
->mtx
.pv
, cam
->mtx_prev
.pv
);
79 m4x4_mul( cam
->mtx
.p
, cam
->mtx
.v
, cam
->mtx
.pv
);