-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcamera.c
More file actions
25 lines (23 loc) · 695 Bytes
/
camera.c
File metadata and controls
25 lines (23 loc) · 695 Bytes
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
#include "camera.h"
#include "config.h"
#include "map.h"
#include <math.h>
void move(Camera *cm, int dir, double dt) {
double next_x = cm->pos.x + cm->dir.x * SPEED * dir * dt;
double next_y = cm->pos.y + cm->dir.y * SPEED * dir * dt;
if (!wall(next_x, cm->pos.y)) {
cm->pos.x = next_x;
}
if (!wall(cm->pos.x, next_y)) {
cm->pos.y = next_y;
}
}
void rotate(Camera *cm, int dir, double dt) {
double x = cm->dir.x;
double y = cm->dir.y;
double theta = ANGULAR_SPEED * dir * dt;
cm->dir.x = x * cos(theta) - y * sin(theta);
cm->dir.y = x * sin(theta) + y * cos(theta);
cm->plane.x = -(cm->dir.y * PLANE_HWIDTH);
cm->plane.y = (cm->dir.x * PLANE_HWIDTH);
}