summaryrefslogtreecommitdiff
path: root/src/camera/camera.h
blob: b8d3b61447ef0896f24d9fa2c0261986704fbc69 (plain)
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#ifndef HONEY_CAMERA_H
#define HONEY_CAMERA_H

/** @file camera.h
 *
 * @brief Define the basic honey_camera struct, associated functions,
 * and common camera variants.
 */

#include "../common.h"

enum honey_camera_projection {
  HONEY_PERSPECTIVE,
  HONEY_ORTHOGRAPHIC,
};

typedef struct {
  vec3 position;
  vec3 angle; /* pitch, yaw, roll */
  vec3 look_direction;
  vec3 up;
  vec3 right;
  mat4 view;
  mat4 projection;
  enum honey_camera_projection projection_type;
  float aspect_ratio;
  float near, far;
  float fov;
  float ortho_left;
  float ortho_right;
  float ortho_top;
  float ortho_bottom;
} honey_camera;

/** @brief Create a new camera.
 *
 * The full camera creation function. Most of the time, you will probably use either
 * honey_camera_new_perspective() or honey_camera_new_projection() instead.
 *
 * @param[out] camera Pointer to the destination honey_camera.
 * @param[in] position The position of the camera.
 * @param[in] angle The Euler angles (pitch, yaw, roll) of the camera.
 * @param[in] projection_type The type of projection to use.
 * @param[in] aspect_ratio The aspect ratio of the camera. Set to zero if using orthographic projection.
 * @param[in] near The distance of the near plane.
 * @param[in] far The distance of the far plane.
 * @param[in] fov The field of view. Set to zero if using orthographic projection.
 * @param[in] left The leftmost distance. Set to zero if using perspective projection.
 * @param[in] right The rightmost distance. Set to zero if using perspective projection.
 * @param[in] top The uppermost distance. Set to zero if using perspective projection.
 * @param[in] bottom The lowest distance. Set to zero if using perspective projection.
 */
void honey_camera_new(honey_camera* camera,
                      vec3 position,
                      vec3 angle,
                      enum honey_camera_projection projection_type,
                      float aspect_ratio,
                      float near, float far,
                      float fov,
                      float left, float right, float top, float bottom);

/** @brief Create a camera with a perspective projection matrix.
 *
 * @param[out] camera Pointer to the destination honey_camera.
 * @param[in] position The position of the camera.
 * @param[in] angle The Euler angles (pitch, yaw, roll) of the camera.
 * @param[in] aspect_ratio The aspect ratio of the camera.
 * @param[in] near The distance of the near plane.
 * @param[in] far The distance of the far plane.
 * @param[in] fov The field of view. 
 */
void honey_camera_new_perspective(honey_camera* camera,
                                  vec3 position,
                                  vec3 angle,
                                  float aspect_ratio,
                                  float near, float far,
                                  float fov);

/** @brief Create a camera with an orthographic projection matrix.
 *
 * @param[out] camera Pointer to the destination honey_camera.
 * @param[in] position The position of the camera.
 * @param[in] angle The Euler angles (pitch, yaw, roll) of the camera.
 * @param[in] near The distance of the near plane.
 * @param[in] far The distance of the far plane.
 * @param[in] left The leftmost distance.
 * @param[in] right The rightmost distance.
 * @param[in] top The uppermost distance.
 * @param[in] bottom The lowest distance.
 */
void honey_camera_new_orthographic(honey_camera* camera,
                                   vec3 position,
                                   vec3 angle,
                                   float near, float far,
                                   float left, float right, float top, float bottom);

/** @brief (Re-)Calculate a camera's look_direction.
 *
 * @param[in] Pointer to the camera to re-calculate.
 */
void honey_camera_calculate_look_direction(honey_camera* camera);

/** @brief (Re-)Calculate a camera's up vector.
 *
 * @param[in] Pointer to the camera to re-calculate.
 */
void honey_camera_calculate_up(honey_camera* camera);

/** @brief (Re-)Calculate a camera's right vector.
 *
 * @param[in] Pointer to the camera to re-calculate.
 */
void honey_camera_calculate_right(honey_camera* camera);

/** @brief (Re-)Calculate a camera's view matrix. 
 *
 * This function need only be called when the camera has been moved in some way.
 *
 * @param[in] camera Pointer to the camera to re-calculate.
 */
void honey_camera_calculate_view(honey_camera* camera);

/** @brief (Re-)Calculate a camera's projection matrix.
 *
 * This function need only be called when the projection has changes in some way.
 * Most commonly, this would be changing the FOV.
 *
 * @param[in] camera Pointer to the camera to re-calculate.
 */
void honey_camera_calculate_projection(honey_camera* camera);

#endif