Subastra
Loading...
Searching...
No Matches
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
9static void system_camera_move(system_req_t payload,
10 allocator_t temporary_allocator) {
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
26 allocator_t temporary_allocator) {
27 shader_t *shader_ptr = (shader_t *)payload.system_specific_data;
28 GLuint program = shader_ptr->gl_program;
29
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 =
39 rendering_ctx_set_projection(payload.rendering_ctx, program, projection);
40 break;
41 }
42}
43
44#endif
#define CAMERA_SPEED
Definition camera.h:7
static void system_camera_move(system_req_t payload, allocator_t temporary_allocator)
Definition camera.h:9
static void system_camera_set_projection(system_req_t payload, allocator_t temporary_allocator)
Definition camera.h:25
static void rendering_ctx_set_projection(rendering_ctx_t *ctx, GLuint program, mat4 projection)
Definition context.h:65
static vec2i input_vector(input_t *input)
Definition input.h:16
@ ENTITY_KIND_CAMERA
Definition entity.h:38
static mat4 entity_camera_calculate_projection(const rendering_ctx_t *ctx, const entity_t *entity)
Definition entity.h:93
A generic allocator type passed by value. Contains a fallback allocator and a set of function pointer...
Definition memory.h:30
Definition world.h:111
entity_t * entity
Definition world.h:114
Definition entity.h:44
entity_kind_t kind
Definition entity.h:45
vec2 chunk_local_position
Definition entity.h:51
Definition mat4.h:7
Small container and wrapper over OpenGL for shader-related things. In actually it is closer to what O...
Definition shader.h:15
GLuint gl_program
Definition shader.h:16
Definition require.h:51
input_t * input
Definition require.h:62
void * system_specific_data
Definition require.h:60
double delta_time
Definition require.h:65
rendering_ctx_t * rendering_ctx
Definition require.h:63
world_t * world
Definition require.h:61
Definition vec2.h:11
Definition vec2i.h:7
static vec2 vec2i_to_vec2(vec2i v)
{.x = (int)v.x, .y = (int)v.y)
Definition vec2i.h:23
static bool entity_iter_next(entity_iter_t *it)
Definition world.h:137
static entity_iter_t world_entity_iter(world_t *world)
Definition world.h:118