aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsalaaad2 <arthurdurant263@gmail.com>2022-06-09 23:15:04 +0200
committersalaaad2 <arthurdurant263@gmail.com>2022-06-09 23:15:04 +0200
commitb4491be787765044b7b2f0d00fb2c0342575a859 (patch)
tree1dec2eb5443d5b16a1ba24cb580b94fbdacfc0f8
parentmake everything better (diff)
downloadyabs-b4491be787765044b7b2f0d00fb2c0342575a859.tar.gz
yabs-b4491be787765044b7b2f0d00fb2c0342575a859.tar.bz2
yabs-b4491be787765044b7b2f0d00fb2c0342575a859.tar.xz
yabs-b4491be787765044b7b2f0d00fb2c0342575a859.tar.zst
yabs-b4491be787765044b7b2f0d00fb2c0342575a859.zip
doesntwork i gotta sleep :^\}
-rw-r--r--src/main.cpp79
-rw-r--r--src/yabs_core.cpp80
-rw-r--r--src/yabs_core.h6
3 files changed, 88 insertions, 77 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 8033d5a..491e1c5 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -6,10 +6,6 @@
/* ()__)____________))))) :^} */
/*********************************/
-#include <stdlib.h>
-#include "raylib.h"
-#include "raymath.h"
-
#include "yabs_core.h"
#include "yabs_utils.h"
@@ -39,15 +35,6 @@ int main(void) {
model.materials[0].maps[MATERIAL_MAP_DIFFUSE].texture = texture;
// setup camera
- SetCameraMode(sc3d.camera, CAMERA_FIRST_PERSON); // Set camera mode
- sc3d.camera.position = (Vector3){50.0f, 1.0f, 50.0f};
- sc3d.camera.target = (Vector3){50.0f, 1.0f, 50.0f};
- sc3d.camera.up = (Vector3){0.0f, 1.0f, 0.0f};
- sc3d.camera.fovy = 90.0f;
- sc3d.camera.projection = CAMERA_PERSPECTIVE;
-
- sc3d.rotation = (Vector3){0.0f, 0.0f, 0.0f};
- sc3d.lastMousePos = GetMousePosition();
SetTargetFPS(60);
// game loop
while (!WindowShouldClose()) {
@@ -85,7 +72,7 @@ int main(void) {
}
case (yabs::GAMEPLAY): {
while (game_state != yabs::NEXT) {
- yabs::core::draw(game_state);
+ yabs::core::draw(game_state, model);
}
break;
}
@@ -96,76 +83,22 @@ int main(void) {
break;
}
}
- // mouse look
- Vector2 mouseMovement =
- Vector2Subtract(GetMousePosition(), sc3d.lastMousePos);
- sc3d.lastMousePos = GetMousePosition();
- sc3d.rotation.x +=
- (mouseMovement.x * -YABS_CAMERA_MOUSE_MOVE_SENSITIVITY);
- sc3d.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
- sc3d.movement = (Vector3){0, 0, 0};
- sc3d.movement.x = (sinf(sc3d.rotation.x) * direction[1] -
- sinf(sc3d.rotation.x) * direction[0] -
- cosf(sc3d.rotation.x) * direction[3] +
- cosf(sc3d.rotation.x) * direction[2]) /
- YABS_PLAYER_MOVEMENT_SENSITIVITY;
- sc3d.movement.z = (cosf(sc3d.rotation.x) * direction[1] -
- cosf(sc3d.rotation.x) * direction[0] +
- sinf(sc3d.rotation.x) * direction[3] -
- sinf(sc3d.rotation.x) * direction[2]) /
- YABS_PLAYER_MOVEMENT_SENSITIVITY;
- // elevation
- if (IsKeyDown(KEY_SPACE))
- sc3d.movement.y += 0.12f;
- if (IsKeyDown(KEY_LEFT_CONTROL))
- sc3d.movement.y -= 0.12f;
-
- // apply movement
- sc3d.camera.position.x +=
- sc3d.movement.x / YABS_PLAYER_MOVEMENT_SENSITIVITY;
- sc3d.camera.position.y += sc3d.movement.y;
- sc3d.camera.position.z +=
- sc3d.movement.z / YABS_PLAYER_MOVEMENT_SENSITIVITY;
-
- Matrix translation = MatrixTranslate(0, 0, (10));
- Matrix rotation2 = MatrixRotateXYZ((Vector3){
- DOUBLEPI - sc3d.rotation.y, DOUBLEPI - sc3d.rotation.x, 0});
- Matrix transform = MatrixMultiply(translation, rotation2);
- // apply camera rotation
- sc3d.camera.target.x = sc3d.camera.position.x - transform.m12;
- sc3d.camera.target.y = sc3d.camera.position.y - transform.m13;
- sc3d.camera.target.z = sc3d.camera.position.z - transform.m14;
+ // draw
BeginDrawing();
ClearBackground(GRAY);
BeginMode3D(sc3d.camera);
-
- // 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);
- }
- }
-
+ yabs::core::tick(sc3d);
+ yabs::core::draw(game_state, model);
EndMode3D();
DrawFPS(0, 0);
DrawText("Controls: Mouse / WASD / SPACE/CTRL.", YABS_SCREENWIDTH - 400,
0, 20, DARKGRAY);
+
EndDrawing();
}
UnloadTexture(texture);
UnloadModel(model);
CloseWindow();
- return 0;
+ return (0);
}
diff --git a/src/yabs_core.cpp b/src/yabs_core.cpp
index 6252b14..8920f96 100644
--- a/src/yabs_core.cpp
+++ b/src/yabs_core.cpp
@@ -6,16 +6,92 @@
/* ()__)____________))))) :^} */
/*********************************/
+#include <stdlib.h>
+
#include "yabs_core.h"
+#include "raymath.h"
namespace yabs {
namespace core {
-int reset_camera(Scene3D const& scene_3d) {
+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 draw(gameState const& game_state) {
+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);
}
diff --git a/src/yabs_core.h b/src/yabs_core.h
index 15a6d4c..73c7543 100644
--- a/src/yabs_core.h
+++ b/src/yabs_core.h
@@ -43,9 +43,11 @@ namespace core {
// draw takes a reference to the game_state, which is checked on each frame
// for next level or death
-int reset_camera(Scene3D const& scene_3d);
+int reset_camera(Scene3D & scene_3d);
-int draw(gameState const& game_state);
+int draw(gameState const& game_state, Model & model);
+
+int tick(Scene3D & scene_3d);
} // namespace core