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

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

void updatePlayerCamera(Camera3D * camera, Game * game) {
	Entity * player = getEntityFromWorld(game->world, 0);

	Vector3 direction = Vector3RotateByQuaternion((Vector3){0.0, 0.0, 1.0}, player->rotation);

	// Position.
	camera->position = Vector3Add(player->position, Vector3Scale(direction, CAMERA_DIS));

	// Target.
	camera->target = Vector3Add(camera->position, direction);

	// Up.
	camera->up = Vector3RotateByQuaternion((Vector3){0.0, 1.0, 0.0}, player->rotation);

	// camera->target = player->position;
	// camera->position = (Vector3){10.0, 10.0, 10.0};
	// camera->up = (Vector3){0.0, 1.0, 0.0};
}