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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
/*********************************/
/* YABS ( // */
/* main ( )/ */
/* by salade )(/ */
/* ________________ ( /) */
/* ()__)____________))))) :^} */
/*********************************/
#include <stdlib.h>
#include "raymath.h"
#include "yabs_core.h"
namespace yabs {
namespace core {
int reset_camera(Scene3D& scene_3d) {
SetCameraMode(scene_3d.camera, CAMERA_FIRST_PERSON);
scene_3d.camera.position = (Vector3){50.0f, 1.0f, 50.0f};
scene_3d.camera.target = (Vector3){50.0f, 1.0f, 50.0f};
scene_3d.camera.up = (Vector3){0.0f, 1.0f, 0.0f};
scene_3d.camera.fovy = 90.0f;
scene_3d.camera.projection = CAMERA_PERSPECTIVE;
scene_3d.rotation = (Vector3){0.0f, 0.0f, 0.0f};
scene_3d.lastMousePos = GetMousePosition();
return (0);
}
int draw(gameState const& game_state, Model& model) {
// draw checkerboard model
for (int x = 0; x < 50; x++) {
for (int z = 0; z < 50; z++) {
Vector3 position;
position.x = x;
position.y = 0;
position.z = z;
DrawModel(model, position, 1.0f, WHITE);
}
}
// end draw
return (0);
}
int tick(Scene3D& scene_3d) {
// mouse look
Vector2 mouseMovement =
Vector2Subtract(GetMousePosition(), scene_3d.lastMousePos);
scene_3d.lastMousePos = GetMousePosition();
scene_3d.rotation.x +=
(mouseMovement.x * -YABS_CAMERA_MOUSE_MOVE_SENSITIVITY);
scene_3d.rotation.y +=
(mouseMovement.y * -YABS_CAMERA_MOUSE_MOVE_SENSITIVITY);
// direction array
bool direction[4] = {IsKeyDown(KEY_W), IsKeyDown(KEY_S), IsKeyDown(KEY_D),
IsKeyDown(KEY_A)};
// compute movement
scene_3d.movement = (Vector3){0, 0, 0};
scene_3d.movement.x = (sinf(scene_3d.rotation.x) * direction[1] -
sinf(scene_3d.rotation.x) * direction[0] -
cosf(scene_3d.rotation.x) * direction[3] +
cosf(scene_3d.rotation.x) * direction[2]) /
YABS_PLAYER_MOVEMENT_SENSITIVITY;
scene_3d.movement.z = (cosf(scene_3d.rotation.x) * direction[1] -
cosf(scene_3d.rotation.x) * direction[0] +
sinf(scene_3d.rotation.x) * direction[3] -
sinf(scene_3d.rotation.x) * direction[2]) /
YABS_PLAYER_MOVEMENT_SENSITIVITY;
// elevation
if (IsKeyDown(KEY_SPACE))
scene_3d.movement.y += 0.12f;
if (IsKeyDown(KEY_LEFT_CONTROL))
scene_3d.movement.y -= 0.12f;
// apply movement
scene_3d.camera.position.x +=
scene_3d.movement.x / YABS_PLAYER_MOVEMENT_SENSITIVITY;
scene_3d.camera.position.y += scene_3d.movement.y;
scene_3d.camera.position.z +=
scene_3d.movement.z / YABS_PLAYER_MOVEMENT_SENSITIVITY;
Matrix translation = MatrixTranslate(0, 0, (10));
Matrix rotation2 =
MatrixRotateXYZ((Vector3){YABS_DOUBLEPI - scene_3d.rotation.y,
YABS_DOUBLEPI - scene_3d.rotation.x, 0});
Matrix transform = MatrixMultiply(translation, rotation2);
// apply camera rotation
scene_3d.camera.target.x = scene_3d.camera.position.x - transform.m12;
scene_3d.camera.target.y = scene_3d.camera.position.y - transform.m13;
scene_3d.camera.target.z = scene_3d.camera.position.z - transform.m14;
return (0);
}
} // namespace core
} // namespace yabs
|