aboutsummaryrefslogtreecommitdiffstats
path: root/src/yabs_core.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/yabs_core.cpp')
-rw-r--r--src/yabs_core.cpp82
1 files changed, 69 insertions, 13 deletions
diff --git a/src/yabs_core.cpp b/src/yabs_core.cpp
index fabfb09..60a74cc 100644
--- a/src/yabs_core.cpp
+++ b/src/yabs_core.cpp
@@ -6,25 +6,22 @@
/* ()__)____________))))) :^} */
/*********************************/
+#include <raylib.h>
#include <stdlib.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);
-}
+static yabs::Scene3D sc3d{
+ // camera
+ {{5.0f, 5.0f, 5.0f}, {0.0f, 0.0f, 0.0f}, {0.0f, 1.0f, 0.0f}, 45.0f, 0},
+ // movement
+ {0.0f, 0.0f},
+ // rotation
+ {0.0f, -0.2f, 0.0f},
+ // mouse
+ {0.0f, 0.0f}};
int draw(Model& model) {
// draw checkerboard model
@@ -71,6 +68,8 @@ int tick(Scene3D& scene_3d) {
scene_3d.movement.y += 0.12f;
if (IsKeyDown(KEY_LEFT_CONTROL))
scene_3d.movement.y -= 0.12f;
+ if (IsKeyPressed(KEY_ESCAPE))
+ return (0);
// apply movement
scene_3d.camera.position.x +=
@@ -89,6 +88,63 @@ int tick(Scene3D& scene_3d) {
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 (1);
+}
+
+void init_game()
+{
+ // create image
+ Image checked = GenImageChecked(2, 2, 1, 1, BLACK, GRAY);
+ Texture2D texture = LoadTextureFromImage(checked);
+ UnloadImage(checked);
+
+ // create model with image as texture
+ Model model = {};
+ model = LoadModelFromMesh(GenMeshCube(1.0f, 1.0f, 1.0f));
+ model.materials[0].maps[MATERIAL_MAP_DIFFUSE].texture = texture;
+
+ // setup camera
+ SetTargetFPS(60);
+ SetCameraMode(sc3d.camera, CAMERA_FIRST_PERSON);
+ 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();
+ bool alive = true;
+
+ while (alive)
+ {
+ BeginDrawing();
+ ClearBackground(GRAY);
+ BeginMode3D(sc3d.camera);
+
+ alive = tick(sc3d);
+ draw(model);
+
+ EndMode3D();
+ DrawFPS(0, 0);
+ DrawText("Controls: Mouse / WASD / SPACE/CTRL.", YABS_SCREENWIDTH - 400,
+ 0, 20, DARKGRAY);
+ EndDrawing();
+ }
+ UnloadTexture(texture);
+ UnloadModel(model);
+}
+
+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);
}