1 #ifndef H_CAMERA
2 #define H_CAMERA
3 
4 #include "common.h"
5 
6 #define CAM_SPEED     (1 << 3)
7 #define CAM_ROT_SPEED (1 << 9)
8 #define CAM_ROT_X_MAX int16(85 * 0x8000 / 180)
9 
10 struct Camera {
11     vec3i pos;
12     int16 rotX, rotY;
13     int32 room;
14 
initCamera15     void init() {
16         pos.x = 75162;
17         pos.y = 2048;
18         pos.z = 5000;
19 
20         rotX = 0;
21         rotY = 16 << 8;
22 
23         //rotX = -0x1000;
24         //rotY = int16(0x8000);
25     }
26 
updateCamera27     void update() {
28         if (keys[IK_UP])    rotX -= CAM_ROT_SPEED;
29         if (keys[IK_DOWN])  rotX += CAM_ROT_SPEED;
30         if (keys[IK_LEFT])  rotY -= CAM_ROT_SPEED;
31         if (keys[IK_RIGHT]) rotY += CAM_ROT_SPEED;
32 
33         rotX = clamp(rotX, -CAM_ROT_X_MAX, CAM_ROT_X_MAX);
34 
35         matrixSetView(pos.x, pos.y, pos.z, rotX, rotY);
36 
37         Matrix &m = matrixGet();
38 
39         if (keys[IK_R]) {
40             pos.x += m[0].x * CAM_SPEED >> 10;
41             pos.y += m[0].y * CAM_SPEED >> 10;
42             pos.z += m[0].z * CAM_SPEED >> 10;
43         }
44 
45         if (keys[IK_L]) {
46             pos.x -= m[0].x * CAM_SPEED >> 10;
47             pos.y -= m[0].y * CAM_SPEED >> 10;
48             pos.z -= m[0].z * CAM_SPEED >> 10;
49         }
50 
51         if (keys[IK_A]) {
52             pos.x += m[2].x * CAM_SPEED >> 10;
53             pos.y += m[2].y * CAM_SPEED >> 10;
54             pos.z += m[2].z * CAM_SPEED >> 10;
55         }
56 
57         if (keys[IK_B]) {
58             pos.x -= m[2].x * CAM_SPEED >> 10;
59             pos.y -= m[2].y * CAM_SPEED >> 10;
60             pos.z -= m[2].z * CAM_SPEED >> 10;
61         }
62 
63         room = getRoomIndex(room, &pos);
64     }
65 };
66 
67 Camera camera;
68 
69 #endif