Kohi Game Engine
kcamera_system.h File Reference
#include "defines.h"
#include "math/math_types.h"

Go to the source code of this file.

Data Structures

struct  kcamera_system_config
 The camera system configuration. More...
 

Macros

#define DEFAULT_KCAMERA   0
 
#define INVALID_KCAMERA   INVALID_ID_U8
 

Typedefs

typedef struct kcamera_system_config kcamera_system_config
 The camera system configuration. More...
 
typedef u8 kcamera
 
typedef enum kcamera_type kcamera_type
 

Enumerations

enum  kcamera_type { KCAMERA_TYPE_2D , KCAMERA_TYPE_3D }
 

Functions

b8 kcamera_system_initialize (u64 *memory_requirement, void *state, void *config)
 Initializes the camera system. Should be called twice; once to get the memory requirement (passing state=0), and a second time passing an allocated block of memory to actually initialize the system. More...
 
void kcamera_system_shutdown (void *state)
 Shuts down the camera system. More...
 
KAPI kcamera kcamera_create (kcamera_type type, rect_2di vp_rect, vec3 position, vec3 euler_rotation, f32 fov_radians, f32 near_clip, f32 far_clip)
 Creates a new camera using the provided parameters and returns a handle to it. More...
 
KAPI kcamera kcamera_clone (kcamera camera)
 
KAPI void kcamera_destroy (kcamera camera)
 Releases the given camera. More...
 
KAPI kcamera kcamera_system_get_default (void)
 Gets a handle to the default camera. More...
 
KAPI vec3 kcamera_get_position (kcamera camera)
 
KAPI void kcamera_set_position (kcamera camera, vec3 position)
 
KAPI vec3 kcamera_get_euler_rotation (kcamera camera)
 
KAPI void kcamera_set_euler_rotation (kcamera camera, vec3 euler_rotation)
 
KAPI void kcamera_set_euler_rotation_radians (kcamera camera, vec3 euler_rotation_radians)
 
KAPI f32 kcamera_get_fov (kcamera camera)
 
KAPI void kcamera_set_fov (kcamera camera, f32 fov)
 
KAPI f32 kcamera_get_near_clip (kcamera camera)
 
KAPI void kcamera_set_near_clip (kcamera camera, f32 near_clip)
 
KAPI f32 kcamera_get_far_clip (kcamera camera)
 
KAPI void kcamera_set_far_clip (kcamera camera, f32 far_clip)
 
KAPI rect_2di kcamera_get_vp_rect (kcamera camera)
 
KAPI void kcamera_set_vp_rect (kcamera camera, rect_2di vp_rect)
 
KAPI kfrustum kcamera_get_frustum (kcamera camera)
 
KAPI mat4 kcamera_get_view (kcamera camera)
 
KAPI mat4 kcamera_get_transform (kcamera camera)
 
KAPI mat4 kcamera_get_projection (kcamera camera)
 
KAPI mat4 kcamera_get_projection_far_clipped (kcamera camera, f32 far)
 
KAPI vec3 kcamera_forward (kcamera camera)
 Returns a copy of the camera's forward vector. More...
 
KAPI vec3 kcamera_backward (kcamera camera)
 Returns a copy of the camera's backward vector. More...
 
KAPI vec3 kcamera_left (kcamera camera)
 Returns a copy of the camera's left vector. More...
 
KAPI vec3 kcamera_right (kcamera camera)
 Returns a copy of the camera's right vector. More...
 
KAPI vec3 kcamera_up (kcamera camera)
 Returns a copy of the camera's up vector. More...
 
KAPI vec3 kcamera_down (kcamera camera)
 Returns a copy of the camera's down vector. More...
 
KAPI void kcamera_move_direction (kcamera camera, vec3 direction, b8 normalize_dir, f32 amount)
 Moves the camera forward by the given amount. More...
 
KAPI void kcamera_move_forward (kcamera camera, f32 amount)
 Moves the camera forward by the given amount. More...
 
KAPI void kcamera_move_backward (kcamera camera, f32 amount)
 Moves the camera backward by the given amount. More...
 
KAPI void kcamera_move_left (kcamera camera, f32 amount)
 Moves the camera left by the given amount. More...
 
KAPI void kcamera_move_right (kcamera camera, f32 amount)
 Moves the camera right by the given amount. More...
 
KAPI void kcamera_move_up (kcamera camera, f32 amount)
 Moves the camera up (straight along the y-axis, not the camera's up vector) by the given amount. More...
 
KAPI void kcamera_move_down (kcamera camera, f32 amount)
 Moves the camera down (straight along the y-axis, not the camera's up vector) by the given amount. More...
 
KAPI void kcamera_yaw (kcamera camera, f32 amount)
 Adjusts the camera's yaw by the given amount. More...
 
KAPI void kcamera_pitch (kcamera camera, f32 amount)
 Adjusts the camera's pitch by the given amount. More...
 

Macro Definition Documentation

◆ DEFAULT_KCAMERA

#define DEFAULT_KCAMERA   0

◆ INVALID_KCAMERA

#define INVALID_KCAMERA   INVALID_ID_U8

Typedef Documentation

◆ kcamera

typedef u8 kcamera

◆ kcamera_system_config

The camera system configuration.

◆ kcamera_type

typedef enum kcamera_type kcamera_type

Enumeration Type Documentation

◆ kcamera_type

Enumerator
KCAMERA_TYPE_2D 
KCAMERA_TYPE_3D 

Function Documentation

◆ kcamera_backward()

KAPI vec3 kcamera_backward ( kcamera  camera)

Returns a copy of the camera's backward vector.

Parameters
cameraA handle to a camera.
Returns
A copy of the camera's backward vector.

◆ kcamera_clone()

KAPI kcamera kcamera_clone ( kcamera  camera)

◆ kcamera_create()

KAPI kcamera kcamera_create ( kcamera_type  type,
rect_2di  vp_rect,
vec3  position,
vec3  euler_rotation,
f32  fov_radians,
f32  near_clip,
f32  far_clip 
)

Creates a new camera using the provided parameters and returns a handle to it.

Parameters
typeThe type of the camera to create. 2D = ortho projection, 3D = perspective projection.
vp_rectThe "viewport" rectange (i.e. the dimensions of the camera's "face").
positionThe camera starting position.
rotationThe camera starting rotation in Euler angles (pitch/yaw/roll) in radians.
fov_radians
near_clip
far_clip
Returns
A pointer to a camera if successful; 0 if an error occurs.

◆ kcamera_destroy()

KAPI void kcamera_destroy ( kcamera  camera)

Releases the given camera.

Parameters
nameThe camera to destroy.

◆ kcamera_down()

KAPI vec3 kcamera_down ( kcamera  camera)

Returns a copy of the camera's down vector.

Parameters
cameraA handle to a camera.
Returns
A copy of the camera's down vector.

◆ kcamera_forward()

KAPI vec3 kcamera_forward ( kcamera  camera)

Returns a copy of the camera's forward vector.

Parameters
cameraA handle to a camera.
Returns
A copy of the camera's forward vector.

◆ kcamera_get_euler_rotation()

KAPI vec3 kcamera_get_euler_rotation ( kcamera  camera)

◆ kcamera_get_far_clip()

KAPI f32 kcamera_get_far_clip ( kcamera  camera)

◆ kcamera_get_fov()

KAPI f32 kcamera_get_fov ( kcamera  camera)

◆ kcamera_get_frustum()

KAPI kfrustum kcamera_get_frustum ( kcamera  camera)

◆ kcamera_get_near_clip()

KAPI f32 kcamera_get_near_clip ( kcamera  camera)

◆ kcamera_get_position()

KAPI vec3 kcamera_get_position ( kcamera  camera)

◆ kcamera_get_projection()

KAPI mat4 kcamera_get_projection ( kcamera  camera)

◆ kcamera_get_projection_far_clipped()

KAPI mat4 kcamera_get_projection_far_clipped ( kcamera  camera,
f32  far 
)

◆ kcamera_get_transform()

KAPI mat4 kcamera_get_transform ( kcamera  camera)

◆ kcamera_get_view()

KAPI mat4 kcamera_get_view ( kcamera  camera)

◆ kcamera_get_vp_rect()

KAPI rect_2di kcamera_get_vp_rect ( kcamera  camera)

◆ kcamera_left()

KAPI vec3 kcamera_left ( kcamera  camera)

Returns a copy of the camera's left vector.

Parameters
cameraA handle to a camera.
Returns
A copy of the camera's left vector.

◆ kcamera_move_backward()

KAPI void kcamera_move_backward ( kcamera  camera,
f32  amount 
)

Moves the camera backward by the given amount.

Parameters
cameraA handle to a camera.
amountThe amount to move.

◆ kcamera_move_direction()

KAPI void kcamera_move_direction ( kcamera  camera,
vec3  direction,
b8  normalize_dir,
f32  amount 
)

Moves the camera forward by the given amount.

Parameters
cameraA handle to a camera.
directionA direction vector.
normalize_dirIndicates if direction should be normalized.
amountThe amount to move.

◆ kcamera_move_down()

KAPI void kcamera_move_down ( kcamera  camera,
f32  amount 
)

Moves the camera down (straight along the y-axis, not the camera's up vector) by the given amount.

Parameters
cameraA handle to a camera.
amountThe amount to move.

◆ kcamera_move_forward()

KAPI void kcamera_move_forward ( kcamera  camera,
f32  amount 
)

Moves the camera forward by the given amount.

Parameters
cameraA handle to a camera.
amountThe amount to move.

◆ kcamera_move_left()

KAPI void kcamera_move_left ( kcamera  camera,
f32  amount 
)

Moves the camera left by the given amount.

Parameters
cameraA handle to a camera.
amountThe amount to move.

◆ kcamera_move_right()

KAPI void kcamera_move_right ( kcamera  camera,
f32  amount 
)

Moves the camera right by the given amount.

Parameters
cameraA handle to a camera.
amountThe amount to move.

◆ kcamera_move_up()

KAPI void kcamera_move_up ( kcamera  camera,
f32  amount 
)

Moves the camera up (straight along the y-axis, not the camera's up vector) by the given amount.

Parameters
cameraA handle to a camera.
amountThe amount to move.

◆ kcamera_pitch()

KAPI void kcamera_pitch ( kcamera  camera,
f32  amount 
)

Adjusts the camera's pitch by the given amount.

Parameters
cameraA handle to a camera.
amountThe amount to adjust by.

◆ kcamera_right()

KAPI vec3 kcamera_right ( kcamera  camera)

Returns a copy of the camera's right vector.

Parameters
cameraA handle to a camera.
Returns
A copy of the camera's right vector.

◆ kcamera_set_euler_rotation()

KAPI void kcamera_set_euler_rotation ( kcamera  camera,
vec3  euler_rotation 
)

◆ kcamera_set_euler_rotation_radians()

KAPI void kcamera_set_euler_rotation_radians ( kcamera  camera,
vec3  euler_rotation_radians 
)

◆ kcamera_set_far_clip()

KAPI void kcamera_set_far_clip ( kcamera  camera,
f32  far_clip 
)

◆ kcamera_set_fov()

KAPI void kcamera_set_fov ( kcamera  camera,
f32  fov 
)

◆ kcamera_set_near_clip()

KAPI void kcamera_set_near_clip ( kcamera  camera,
f32  near_clip 
)

◆ kcamera_set_position()

KAPI void kcamera_set_position ( kcamera  camera,
vec3  position 
)

◆ kcamera_set_vp_rect()

KAPI void kcamera_set_vp_rect ( kcamera  camera,
rect_2di  vp_rect 
)

◆ kcamera_system_get_default()

KAPI kcamera kcamera_system_get_default ( void  )

Gets a handle to the default camera.

Returns
A handle to the default camera.

◆ kcamera_system_initialize()

b8 kcamera_system_initialize ( u64 memory_requirement,
void *  state,
void *  config 
)

Initializes the camera system. Should be called twice; once to get the memory requirement (passing state=0), and a second time passing an allocated block of memory to actually initialize the system.

Parameters
memory_requirementA pointer to hold the memory requirement as it is calculated.
stateA block of memory to hold the state or, if gathering the memory requirement, 0.
configThe configuration (camera_system_config) for this system.
Returns
True on success; otherwise false.

◆ kcamera_system_shutdown()

void kcamera_system_shutdown ( void *  state)

Shuts down the camera system.

Parameters
stateThe state block of memory.

◆ kcamera_up()

KAPI vec3 kcamera_up ( kcamera  camera)

Returns a copy of the camera's up vector.

Parameters
cameraA handle to a camera.
Returns
A copy of the camera's up vector.

◆ kcamera_yaw()

KAPI void kcamera_yaw ( kcamera  camera,
f32  amount 
)

Adjusts the camera's yaw by the given amount.

Parameters
cameraA handle to a camera.
amountThe amount to adjust by.