aboutsummaryrefslogtreecommitdiff
path: root/src/playerCamera.c
blob: e7db15423b9869391175adc75a4336c57b6f407f (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
#include "playerCamera.h"
#include "game.h"

void initPlayerCamera(Camera3D * camera) {
	*camera = (Camera3D){
		.fovy = 90.0,
		.projection = CAMERA_PERSPECTIVE
	};
}

void updatePlayerCamera(Camera3D * camera, Game * game) {
	Entity * player = &game->world.entities[0];

	camera->target = player->position;

	Matrix m = QuaternionToMatrix(QuaternionInvert(player->rotation));
	Vector3 pos = (Vector3){0.0, CAMERA_DIS/2, -CAMERA_DIS};

	camera->position = (Vector3){
		m.m0 * pos.x + m.m1 * pos.y + m.m2 * pos.z,
		m.m4 * pos.x + m.m5 * pos.y + m.m6 * pos.z,
		m.m8 * pos.x + m.m9 * pos.y + m.m10 * pos.z
	};

	camera->position = Vector3Add(camera->position, player->position);
	camera->up = (Vector3){
		m.m1 + m.m2,
		m.m5 + m.m6,
		m.m9 + m.m10
	};
}