-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcamera.c
More file actions
69 lines (51 loc) · 1.53 KB
/
Copy pathcamera.c
File metadata and controls
69 lines (51 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include "camera.h"
static camera_t camera;
void init_camera(vec3_t position, vec3_t direction) {
camera.position = position;
camera.position = direction;
camera.forward_velocity = vec3_new(0, 0, 0);
camera.yaw = 0.0;
camera.pitch = 0.0;
}
vec3_t get_camera_position(void) {
return camera.position;
}
vec3_t get_camera_direction(void) {
return camera.direction;
}
vec3_t get_camera_forward_velocity(void) {
return camera.forward_velocity;
}
float get_camera_yaw(void) {
return camera.yaw;
}
float get_camera_pitch(void) {
return camera.pitch;
}
void update_camera_position(vec3_t position) {
camera.position = position;
}
void update_camera_direction(vec3_t direction) {
camera.direction = direction;
}
void update_camera_forward_velocity(vec3_t forward_velocity) {
camera.forward_velocity = forward_velocity;
}
void rotate_camera_yaw(float angle) {
camera.yaw += angle;
}
void rotate_camera_pitch(float angle) {
camera.pitch += angle;
}
vec3_t get_camera_lookat_target(void) {
vec3_t target = { 0, 0, 1 };
mat4_t camera_yaw_rotation = mat4_make_rotation_y(camera.yaw);
mat4_t camera_pitch_rotation = mat4_make_rotation_x(camera.pitch);
mat4_t camera_rotation = mat4_identity();
camera_rotation = mat4_mul_mat4(camera_pitch_rotation, camera_rotation);
camera_rotation = mat4_mul_mat4(camera_yaw_rotation, camera_rotation);
vec4_t camera_direction = mat4_mul_vec4(camera_rotation, vec4_from_vec3(target));
camera.direction = vec3_from_vec4(camera_direction);
target = vec3_add(camera.position, camera.direction);
return target;
}