| 30 |
30 |
| 31 #include "datatypes.h" |
31 #include "datatypes.h" |
| 32 |
32 |
| 33 typedef struct asc_camera_s AscCamera; |
33 typedef struct asc_camera_s AscCamera; |
| 34 |
34 |
| 35 typedef asc_rect(*asc_camera_viewport_update_func)(asc_vec2u window_size); |
35 typedef void(*asc_camera_viewport_update_func)(AscCamera*, asc_vec2u window_size); |
| 36 typedef void(*asc_camera_projection_update_func)(AscCamera*, asc_vec2u window_size); |
36 typedef void(*asc_camera_update_func)(AscCamera*); |
| 37 |
37 |
| 38 struct asc_camera_s { |
38 struct asc_camera_s { |
| 39 asc_mat4f projection; |
39 asc_mat4f projection; |
| 40 asc_mat4f view; |
40 asc_mat4f view; |
| 41 /** |
41 /** |
| 42 * Does not need to be initialized. |
42 * Does not need to be initialized. |
| 43 * Will be updated every frame. |
43 * Will be updated every frame. |
| 44 */ |
44 */ |
| 45 asc_rect viewport; |
45 asc_rect viewport; |
| 46 /** |
|
| 47 * Function that gets invoked whenever the window sized changed. |
|
| 48 * Calculates the new drawing viewport. |
|
| 49 * If @c NULL, the entire window will be used. |
|
| 50 */ |
|
| 51 asc_camera_viewport_update_func viewport_update_func; |
46 asc_camera_viewport_update_func viewport_update_func; |
| 52 asc_camera_projection_update_func projection_update_func; |
47 asc_camera_update_func update_func; |
| 53 asc_color clear_color; |
48 asc_color clear_color; |
| 54 bool viewport_clear; |
49 bool viewport_clear; |
| 55 }; |
50 }; |
| 56 |
51 |
| 57 enum AscCameraType { |
52 enum AscCameraType { |
| 68 } ortho; |
63 } ortho; |
| 69 /*struct { |
64 /*struct { |
| 70 TODO: implement |
65 TODO: implement |
| 71 } perspective;*/ |
66 } perspective;*/ |
| 72 }; |
67 }; |
| |
68 /** |
| |
69 * Function that only gets invoked when the window size changed. |
| |
70 * Implementations should update the @c viewport rectangle |
| |
71 * and may update the projection matrix as well. |
| |
72 */ |
| 73 asc_camera_viewport_update_func viewport_update_func; |
73 asc_camera_viewport_update_func viewport_update_func; |
| 74 asc_camera_projection_update_func projection_update_func; |
74 /** |
| |
75 * Function that is invoked every frame. |
| |
76 * Example use: update the position of the camera to follow an object. |
| |
77 */ |
| |
78 asc_camera_update_func update_func; |
| 75 /** |
79 /** |
| 76 * Indicates whether the viewport for this camera shall be cleared before rendering. |
80 * Indicates whether the viewport for this camera shall be cleared before rendering. |
| 77 * The active drawing color will be used as the clear color (can be changed in the camera struct, afterward). |
81 * The active drawing color will be used as the clear color (can be changed in the camera struct, afterward). |
| 78 */ |
82 */ |
| 79 asc_color clear_color; |
83 asc_color clear_color; |
| 86 |
90 |
| 87 void asc_camera_ortho(AscCamera *camera, asc_rect rect); |
91 void asc_camera_ortho(AscCamera *camera, asc_rect rect); |
| 88 |
92 |
| 89 |
93 |
| 90 /** |
94 /** |
| 91 * Updates the camera with the new window viewport. |
|
| 92 * |
|
| 93 * This is automatically called when a window resizes. |
|
| 94 * It should not be necessary to call this function manually. |
|
| 95 * |
|
| 96 * @param camera the camera |
|
| 97 * @param window_size the new window size |
|
| 98 */ |
|
| 99 void asc_camera_update_viewport(AscCamera *camera, asc_vec2u window_size); |
|
| 100 |
|
| 101 /** |
|
| 102 * Shorter version of updating an orthographic camera which assumes the top right corner at (0,0). |
95 * Shorter version of updating an orthographic camera which assumes the top right corner at (0,0). |
| 103 * |
96 * |
| 104 * @attention The camera MUST have been initialized with asc_camera_ortho() at position (0,0). |
97 * @attention The camera MUST have been initialized with asc_camera_ortho() at position (0,0). |
| 105 * |
98 * |
| 106 * @note This function can be used as an asc_camera_projection_update_func to keep the orthographic projection |
99 * @note This function can be used as an asc_camera_viewport_update_func to keep the orthographic projection |
| 107 * aligned with the window size (useful for UIs or backdrops). |
100 * aligned with the window size (useful for UIs or backdrops). |
| 108 * |
101 * |
| 109 * @param camera the camera |
102 * @param camera the camera |
| 110 * @param size the new size |
103 * @param size the new size |
| |
104 * @see asc_camera_ortho() |
| 111 */ |
105 */ |
| 112 void asc_camera_ortho_update_size(AscCamera *camera, asc_vec2u size); |
106 void asc_camera_ortho_update_size(AscCamera *camera, asc_vec2u size); |
| 113 |
107 |
| 114 #endif //ASCENSION_CAMERA_H |
108 #endif //ASCENSION_CAMERA_H |