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
|
#pragma once
#include <al/types.h>
enum {
CAMU_VIEW_NONE = 0,
CAMU_VIEW_AUTOFIT,
CAMU_VIEW_ZOOM,
CAMU_VIEW_DETACHED
};
enum {
CAMU_VIEW_ROTATION_0 = 0,
CAMU_VIEW_ROTATION_90,
CAMU_VIEW_ROTATION_180,
CAMU_VIEW_ROTATION_270,
CAMU_VIEW_ROTATION_360
};
enum {
CAMU_VR_DISABLED = 0,
CAMU_VR_180,
CAMU_VR_360
};
#define CAMU_DEFAULT_VIEW CAMU_VIEW_AUTOFIT
#define CAMU_DEFAULT_FOV 80.0
struct camu_view {
u8 mode;
u8 rotation;
u32 width;
u32 height;
s32 zindex;
f64 zoom;
f64 x_offset;
f64 y_offset;
f64 stretch;
f64 fov;
};
static inline const char *camu_view_rotation_name(u8 rotation)
{
switch (rotation) {
case CAMU_VIEW_ROTATION_0: return "0";
case CAMU_VIEW_ROTATION_90: return "90";
case CAMU_VIEW_ROTATION_180: return "180";
case CAMU_VIEW_ROTATION_270: return "270";
case CAMU_VIEW_ROTATION_360: return "360";
}
al_assert_and_return("");
}
// This handles wrapping backwards for negative numbers.
static inline u8 camu_view_normalize_rotation(s32 rotation)
{
return (u8)((rotation % CAMU_VIEW_ROTATION_360 + CAMU_VIEW_ROTATION_360) % CAMU_VIEW_ROTATION_360);
}
void camu_view_init(struct camu_view *view, u32 width, u32 height, u8 rotation);
void camu_view_calculate(struct camu_view *view, u32 window_width, u32 window_height);
bool camu_view_zoom_simple(struct camu_view *view, u32 window_width, u32 window_height, f64 x, f64 y, f64 v);
bool camu_view_pan_simple(struct camu_view *view, u32 window_width, u32 window_height, f64 dx, f64 dy);
bool camu_view_zoom_fov(struct camu_view *view, f64 v);
|