LibGame  v0.4.0
The LG Game Engine - Copyright (C) 2024 ETMSoftware
lg_camera.h
1 /*
2  * LibGame - Copyright (C) Emmanuel Thomas-Maurin 2011-2024
3  * All rights reserved
4  */
5 
6 #ifndef LG_CAMERA_H
7 #define LG_CAMERA_H
8 
9 /* Global default camera values */
10 
11 #define LG_CAMERA_ORIGIN 0.0, 0.0, 0.0 /* Initial camera or "eye" position */
12 #define LG_CAMERA_TARGET 0.0, 0.0, -1.0
13 #define LG_CAMERA_UP 0.0, 1.0, 0.0
14 
15 #define LG_V_FOV 45
16 #define LG_Z_NEAR 0.1 /* Usually in range [0.1, 1.0] */
17 #define LG_Z_FAR 1000.0 /* Usually >= 100.0 */
18 
19 typedef struct {
20  vec3_t position; /* Or "eye" position in world coords */
21  LG_Quat orientation; /* Must update target after setting/changing orientation */
22  vec3_t target; /* Target position in world coords - SHOULD ALWAYS ONLY BE UPDATED FROM ORIENTATION QUAT */
23  vec3_t up; /* Must be normalized */
24  float v_fov; /* Vertical field of view in deg */
25  float z_near; /* Clipping plane along the Z axis, always > 0 */
26  float z_far; /* Clipping plane along the Z axis, always > 0 */
27  mat4_t view_m; /* View/proj matrices - must be updated when position or orientation changes */
28  mat4_t proj_m;
29  mat4_t view_proj_m;
30  zboolean new_view; /* Dirty flag */
31  zboolean new_proj;
32  LG_InputState input_state; /* To capture user input */
33 } LG_Camera;
34 
35 typedef struct {
36  float a, b, c, d;
37 } LG_Plane;
38 
39 typedef struct {
40  LG_Plane left;
41  LG_Plane right;
42  LG_Plane bottom;
43  LG_Plane top;
44  LG_Plane near;
45  LG_Plane far;
46 } LG_Frustum;
47 
49 
51 
52 int lg_camera_set_all(LG_Camera *, vec3_t, vec3_t, vec3_t, float, float, float);
53 
55 
57 
59 
61 
63 
65 
66 int lg_camera_rotate_by_eu(LG_Camera *, LG_EulerAng, const char *);
67 
69 
70 int lg_camera_set_rot_by_eu(LG_Camera *, LG_EulerAng, const char *);
71 
73 
75 
76 zboolean is_in_frustum(vec3_t *, LG_Frustum *);
77 
78 zboolean lg_cuboid_is_in_frustum(LG_Cuboid *, LG_Frustum *, zboolean);
79 
80 zboolean lg_mesh_is_in_frustum(LG_Mesh *, LG_Frustum *, zboolean);
81 
82 void lg_camera_override_zfar(LG_Camera *, float);
83 
84 void lg_camera_orbit_around(LG_Camera *, vec3_t, float, float);
85 
87 
89 
91 
93 
95 
96 #endif /* LG_CAMERA_H */
LG_Mesh
Definition: lg_mesh.h:68
lg_point_to_norm_plane_distance
float lg_point_to_norm_plane_distance(vec3_t *v, LG_Plane *p)
Definition: lg_camera.c:584
lg_camera_override_zfar
void lg_camera_override_zfar(LG_Camera *cam, float z_far)
Definition: lg_camera.c:512
is_in_frustum
zboolean is_in_frustum(vec3_t *v, LG_Frustum *frustum)
Definition: lg_camera.c:448
lg_camera_init
int lg_camera_init(LG_Camera *cam)
Definition: lg_camera.c:100
LG_Cuboid
Definition: lg_3d_primitives.h:64
lg_update_all_cam_m
void lg_update_all_cam_m(LG_Camera *cam)
Definition: lg_camera.c:231
LG_Quat
Definition: lg_quaternions.h:29
lg_camera_set_all
int lg_camera_set_all(LG_Camera *cam, vec3_t position, vec3_t target, vec3_t up, float v_fov, float z_near, float z_far)
Definition: lg_camera.c:142
lg_camera_rotate_by_quat
int lg_camera_rotate_by_quat(LG_Camera *cam, LG_Quat q)
Definition: lg_camera.c:297
LG_InputState
Definition: lg_ui.h:55
LG_EulerAng
Definition: lg_quaternions.h:16
lg_camera_get_frustum
void lg_camera_get_frustum(LG_Camera *cam, LG_Frustum *frustum)
Definition: lg_camera.c:376
lg_camera
LG_Camera lg_camera()
Definition: lg_camera.c:77
lg_cuboid_is_in_frustum
zboolean lg_cuboid_is_in_frustum(LG_Cuboid *cuboid, LG_Frustum *frustum, zboolean fully)
Definition: lg_camera.c:470
lg_camera_set_rot_by_eu
int lg_camera_set_rot_by_eu(LG_Camera *cam, LG_EulerAng ang, const char *rot_order)
Definition: lg_camera.c:330
LG_Frustum
Definition: lg_camera.h:39
lg_frustum_info
void lg_frustum_info(LG_Frustum *frustum)
Definition: lg_camera.c:623
lg_mesh_is_in_frustum
zboolean lg_mesh_is_in_frustum(LG_Mesh *mesh, LG_Frustum *frustum, zboolean fully)
Definition: lg_camera.c:499
lg_plane_normalize
int lg_plane_normalize(LG_Plane *p)
Definition: lg_camera.c:544
vec3_t
Definition: math_3d.h:111
LG_Camera
Definition: lg_camera.h:19
lg_camera_compute_view_proj_matrix
mat4_t lg_camera_compute_view_proj_matrix(LG_Camera *cam)
Definition: lg_camera.c:218
lg_camera_reset
int lg_camera_reset(LG_Camera *cam)
Definition: lg_camera.c:176
lg_camera_compute_proj_matrix
mat4_t lg_camera_compute_proj_matrix(LG_Camera *cam)
Definition: lg_camera.c:203
lg_camera_info
void lg_camera_info(LG_Camera *cam)
Definition: lg_camera.c:594
lg_camera_compute_view_matrix
mat4_t lg_camera_compute_view_matrix(LG_Camera *cam)
Definition: lg_camera.c:189
lg_camera_orbit_around
void lg_camera_orbit_around(LG_Camera *cam, vec3_t center, float radius, float angle)
Definition: lg_camera.c:530
lg_point_to_plane_distance
float lg_point_to_plane_distance(vec3_t *v, LG_Plane *p)
Definition: lg_camera.c:571
lg_camera_move_to
int lg_camera_move_to(LG_Camera *cam, vec3_t transl)
Definition: lg_camera.c:251
lg_camera_set_rot_by_quat
int lg_camera_set_rot_by_quat(LG_Camera *cam, LG_Quat q)
Definition: lg_camera.c:344
lg_camera_rotate_by_eu
int lg_camera_rotate_by_eu(LG_Camera *cam, LG_EulerAng ang, const char *rot_order)
Definition: lg_camera.c:281
LG_Plane
Definition: lg_camera.h:35
mat4_t
Definition: math_3d.h:167