aboutsummaryrefslogtreecommitdiff
path: root/src/cameras.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/cameras.c')
-rw-r--r--src/cameras.c24
1 files changed, 21 insertions, 3 deletions
diff --git a/src/cameras.c b/src/cameras.c
index 6a960f5..1cf6cee 100644
--- a/src/cameras.c
+++ b/src/cameras.c
@@ -14,18 +14,36 @@ 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->position = Vector3Add(player->position, Vector3Scale(direction, FIRST_PERSON_CAMERA_DISTANCE));
camera->target = Vector3Add(camera->position, direction);
camera->up = Vector3RotateByQuaternion((Vector3){0.0, 1.0, 0.0}, player->rotation);
}
+void initThirdPersonCamera(Game * game, Camera3D * camera) {
+ *camera = (Camera3D){
+ .fovy = 90.0,
+ .projection = CAMERA_PERSPECTIVE
+ };
+}
+
+void updateThirdPersonCamera(Game * game, Camera3D * camera) {
+ Entity * player = getEntityFromWorld(game->world, 0);
+ Vector3 direction = Vector3RotateByQuaternion(THIRD_PERSON_CAMERA_DISTANCE, player->rotation);
+
+ camera->position = Vector3Add(player->position, direction);
+ camera->target = player->position;
+ camera->up = Vector3RotateByQuaternion((Vector3){0.0, 1.0, 0.0}, player->rotation);
+}
+
// Callbacks indeed.
const CameraInitCb cameraInitCallbacks[CAMERA_COUNT] = {
- initFirstPersonCamera
+ initFirstPersonCamera,
+ initThirdPersonCamera
};
const CameraCb cameraCallbacks[CAMERA_COUNT] = {
- updateFirstPersonCamera
+ updateFirstPersonCamera,
+ updateThirdPersonCamera
};
void initCameras(Game * game, Cameras cameras) {