-
Notifications
You must be signed in to change notification settings - Fork 0
/
camera.h
53 lines (38 loc) · 887 Bytes
/
camera.h
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
#ifndef CAMERA_H
#define CAMERA_H
#include "gfx.h"
typedef struct Camera_
{
Vector2f position;
float facing;
float height;
float near_clip;
float far_clip;
float aspect_ratio;
float hor_fov;
float near_x;
float near_y;
float far_x;
float far_y;
float proj;
} Camera;
static inline void init_camera( Camera* cam,
const float near_clip,
const float far_clip,
const float aspect_ratio,
const float hor_fov)
{
cam->near_clip = near_clip;
cam->far_clip = far_clip;
cam->aspect_ratio = aspect_ratio;
cam->hor_fov = hor_fov;
cam->position = ZERO_VECTOR2F;
cam->facing = 0.0f;
cam->height = 1.0f;
cam->near_x = tan(hor_fov) * near_clip;
cam->near_y = cam->near_x / aspect_ratio;
cam->far_x = tan(hor_fov) * far_clip;
cam->far_y = cam->far_x / aspect_ratio;
cam->proj = gfx.screen_res_x / (2.0f*tan(cam->hor_fov));
}
#endif