aboutsummaryrefslogtreecommitdiff
path: root/src/cameras.c
blob: 6a960f56eb4c83e952499d64570dc52f39cec0a2 (plain)
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
#include "cameras.h"
#include "game.h"
#include "world.h"

// First person camera indeed.
void initFirstPersonCamera(Game * game, Camera3D * camera) {
	*camera = (Camera3D){
		.fovy = 90.0,
		.projection = CAMERA_PERSPECTIVE
	};
}

void updateFirstPersonCamera(Game * game, Camera3D * camera) {
	Entity * player = getEntityFromWorld(game->world, 0);
	Vector3 direction = Vector3RotateByQuaternion((Vector3){0.0, 0.0, 1.0}, player->rotation);

	camera->position = Vector3Add(player->position, Vector3Scale(direction, CAMERA_DIS));
	camera->target = Vector3Add(camera->position, direction);
	camera->up = Vector3RotateByQuaternion((Vector3){0.0, 1.0, 0.0}, player->rotation);
}

// Callbacks indeed.
const CameraInitCb cameraInitCallbacks[CAMERA_COUNT] = {
	initFirstPersonCamera
};

const CameraCb cameraCallbacks[CAMERA_COUNT] = {
	updateFirstPersonCamera
};

void initCameras(Game * game, Cameras cameras) {
	int i;

	for (i = 0; i < CAMERA_COUNT; ++i)
		cameraInitCallbacks[i](game, &cameras[i]);
}

void runCameraUpdate(Game * game, Cameras cameras, CameraId id) {
	cameraCallbacks[id](game, &cameras[id]);
}