Subastra
Loading...
Searching...
No Matches
src
systems
camera.h
Go to the documentation of this file.
1
#ifndef __H__SYSTEMS_CAMERA__
2
#define __H__SYSTEMS_CAMERA__
3
4
#include "../rendering/shader.h"
5
#include "
require.h
"
6
7
#define CAMERA_SPEED 2.5
8
9
static
void
system_camera_move
(
system_req_t
payload,
10
allocator_t
temporary_allocator) {
11
entity_iter_t
it =
world_entity_iter
(payload.
world
);
12
13
while
(
entity_iter_next
(&it)) {
14
entity_t
*ptr = it.
entity
;
15
if
(ptr->
kind
!=
ENTITY_KIND_CAMERA
)
16
continue
;
17
18
vec2i
inp =
input_vector
(payload.
input
);
19
vec2
wish =
20
vec2_scale(
vec2i_to_vec2
(inp),
CAMERA_SPEED
* payload.
delta_time
);
21
ptr->
chunk_local_position
= vec2_add(ptr->
chunk_local_position
, wish);
22
}
23
}
24
25
static
void
system_camera_set_projection
(
system_req_t
payload,
26
allocator_t
temporary_allocator) {
27
shader_t
*shader_ptr = (
shader_t
*)payload.
system_specific_data
;
28
GLuint program = shader_ptr->
gl_program
;
29
30
entity_iter_t
it =
world_entity_iter
(payload.
world
);
31
32
while
(
entity_iter_next
(&it)) {
33
entity_t
*ptr = it.
entity
;
34
if
(ptr->
kind
!=
ENTITY_KIND_CAMERA
)
35
continue
;
36
37
mat4
projection =
38
entity_camera_calculate_projection
(payload.
rendering_ctx
, ptr);
39
rendering_ctx_set_projection
(payload.
rendering_ctx
, program, projection);
40
break
;
41
}
42
}
43
44
#endif
CAMERA_SPEED
#define CAMERA_SPEED
Definition
camera.h:7
system_camera_move
static void system_camera_move(system_req_t payload, allocator_t temporary_allocator)
Definition
camera.h:9
system_camera_set_projection
static void system_camera_set_projection(system_req_t payload, allocator_t temporary_allocator)
Definition
camera.h:25
rendering_ctx_set_projection
static void rendering_ctx_set_projection(rendering_ctx_t *ctx, GLuint program, mat4 projection)
Definition
context.h:65
input_vector
static vec2i input_vector(input_t *input)
Definition
input.h:16
ENTITY_KIND_CAMERA
@ ENTITY_KIND_CAMERA
Definition
entity.h:38
entity_camera_calculate_projection
static mat4 entity_camera_calculate_projection(const rendering_ctx_t *ctx, const entity_t *entity)
Definition
entity.h:93
require.h
allocator_t
A generic allocator type passed by value. Contains a fallback allocator and a set of function pointer...
Definition
memory.h:30
entity_iter_t
Definition
world.h:111
entity_iter_t::entity
entity_t * entity
Definition
world.h:114
entity_t
Definition
entity.h:44
entity_t::kind
entity_kind_t kind
Definition
entity.h:45
entity_t::chunk_local_position
vec2 chunk_local_position
Definition
entity.h:51
mat4
Definition
mat4.h:7
shader_t
Small container and wrapper over OpenGL for shader-related things. In actually it is closer to what O...
Definition
shader.h:15
shader_t::gl_program
GLuint gl_program
Definition
shader.h:16
system_req_t
Definition
require.h:51
system_req_t::input
input_t * input
Definition
require.h:62
system_req_t::system_specific_data
void * system_specific_data
Definition
require.h:60
system_req_t::delta_time
double delta_time
Definition
require.h:65
system_req_t::rendering_ctx
rendering_ctx_t * rendering_ctx
Definition
require.h:63
system_req_t::world
world_t * world
Definition
require.h:61
vec2
Definition
vec2.h:11
vec2i
Definition
vec2i.h:7
vec2i_to_vec2
static vec2 vec2i_to_vec2(vec2i v)
{.x = (int)v.x, .y = (int)v.y)
Definition
vec2i.h:23
entity_iter_next
static bool entity_iter_next(entity_iter_t *it)
Definition
world.h:137
world_entity_iter
static entity_iter_t world_entity_iter(world_t *world)
Definition
world.h:118
Generated on Wed Jul 2 2025 16:57:45 for Subastra by
1.9.8