2023-08-02 10:59:06 +00:00
|
|
|
#include "screen_trunner.h"
|
|
|
|
|
|
|
|
// standard library includes
|
|
|
|
#include <raylib.h>
|
|
|
|
|
|
|
|
#include <cassert>
|
|
|
|
#include <cmath>
|
|
|
|
|
|
|
|
// local includes
|
|
|
|
#include "3d_helpers.h"
|
|
|
|
|
|
|
|
TRunnerScreen::TRunnerScreen(std::weak_ptr<ScreenStack> stack)
|
|
|
|
: Screen(stack),
|
|
|
|
camera{Vector3{0.0F, 0.0F, 0.0F}, Vector3{0.0F, 0.0F, -1.0F},
|
|
|
|
Vector3{0.0F, 1.0F, 0.0F}, 80.0F, CAMERA_PERSPECTIVE},
|
|
|
|
flags(),
|
2023-08-04 05:32:05 +00:00
|
|
|
TEMP_cube_model(LoadModel("res/test_cube.obj")),
|
|
|
|
TEMP_cube_texture(LoadTexture("res/test_cube_texture.png")),
|
2023-08-02 10:59:06 +00:00
|
|
|
TEMP_matrix(get_identity_matrix()),
|
2023-08-04 05:32:05 +00:00
|
|
|
TEMP_permanent_matrix(get_identity_matrix()),
|
|
|
|
TEMP_value(0.0F),
|
|
|
|
TEMP_current_state(0) {
|
|
|
|
TEMP_cube_model.materials[0].maps[MATERIAL_MAP_DIFFUSE].texture =
|
|
|
|
TEMP_cube_texture;
|
|
|
|
}
|
2023-08-02 10:59:06 +00:00
|
|
|
|
|
|
|
TRunnerScreen::~TRunnerScreen() {
|
2023-08-04 05:32:05 +00:00
|
|
|
UnloadTexture(TEMP_cube_texture);
|
|
|
|
UnloadModel(TEMP_cube_model);
|
2023-08-02 10:59:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool TRunnerScreen::update(float dt) {
|
2023-08-04 02:42:11 +00:00
|
|
|
TEMP_value += TEMP_VALUE_INC_RATE * dt;
|
|
|
|
if (TEMP_value < PI / 2.0F) {
|
|
|
|
TEMP_matrix = get_rotation_matrix_about_z(TEMP_value);
|
|
|
|
} else if (TEMP_value < PI) {
|
2023-08-04 05:32:05 +00:00
|
|
|
if (TEMP_current_state == 0) {
|
|
|
|
TEMP_current_state = 1;
|
|
|
|
TEMP_permanent_matrix =
|
|
|
|
TEMP_permanent_matrix * get_rotation_matrix_about_z(PI / 2.0F);
|
|
|
|
} else if (TEMP_current_state != 1) {
|
|
|
|
assert(!"unreachable");
|
|
|
|
}
|
2023-08-04 02:42:11 +00:00
|
|
|
TEMP_matrix = get_rotation_matrix_about_y(TEMP_value - PI / 2.0F);
|
|
|
|
} else if (TEMP_value < PI * 3.0F / 2.0F) {
|
2023-08-04 05:32:05 +00:00
|
|
|
if (TEMP_current_state == 1) {
|
|
|
|
TEMP_current_state = 2;
|
|
|
|
TEMP_permanent_matrix =
|
|
|
|
TEMP_permanent_matrix * get_rotation_matrix_about_y(PI / 2.0F);
|
|
|
|
} else if (TEMP_current_state != 2) {
|
|
|
|
assert(!"unreachable");
|
|
|
|
}
|
2023-08-04 02:42:11 +00:00
|
|
|
TEMP_matrix = get_rotation_matrix_about_x(TEMP_value - PI);
|
|
|
|
} else {
|
2023-08-04 05:32:05 +00:00
|
|
|
if (TEMP_current_state == 2) {
|
|
|
|
TEMP_current_state = 0;
|
|
|
|
TEMP_permanent_matrix =
|
|
|
|
TEMP_permanent_matrix * get_rotation_matrix_about_x(PI / 2.0F);
|
|
|
|
} else {
|
|
|
|
assert(!"unreachable");
|
|
|
|
}
|
2023-08-04 02:42:11 +00:00
|
|
|
TEMP_value -= PI * 3.0F / 2.0F;
|
|
|
|
TEMP_matrix = get_rotation_matrix_about_z(TEMP_value);
|
|
|
|
}
|
2023-08-02 10:59:06 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TRunnerScreen::draw() {
|
|
|
|
BeginDrawing();
|
|
|
|
ClearBackground(PixelToColor(Pixel::PIXEL_SKY));
|
|
|
|
BeginMode3D(camera);
|
|
|
|
|
2023-08-04 05:32:05 +00:00
|
|
|
// DrawMesh(TEMP_cube, TEMP_default_material, TEMP_matrix *
|
|
|
|
// TEMP_offset_matrix);
|
|
|
|
DrawModel(Model{.transform = TEMP_cube_model.transform *
|
|
|
|
TEMP_permanent_matrix * TEMP_matrix,
|
|
|
|
.meshCount = TEMP_cube_model.meshCount,
|
|
|
|
.materialCount = TEMP_cube_model.materialCount,
|
|
|
|
.meshes = TEMP_cube_model.meshes,
|
|
|
|
.materials = TEMP_cube_model.materials,
|
|
|
|
.meshMaterial = TEMP_cube_model.meshMaterial,
|
|
|
|
.boneCount = TEMP_cube_model.boneCount,
|
|
|
|
.bones = TEMP_cube_model.bones,
|
|
|
|
.bindPose = TEMP_cube_model.bindPose},
|
|
|
|
Vector3{0.0F, 0.0F, -4.0F}, 1.0F, WHITE);
|
2023-08-02 10:59:06 +00:00
|
|
|
|
|
|
|
EndMode3D();
|
|
|
|
EndDrawing();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
Color TRunnerScreen::PixelToColor(Pixel p) {
|
|
|
|
switch (p) {
|
|
|
|
case PIXEL_BLANK:
|
|
|
|
return Color{0, 0, 0, 0};
|
|
|
|
case PIXEL_BLACK:
|
|
|
|
return Color{0, 0, 0, 255};
|
|
|
|
case PIXEL_RED:
|
|
|
|
return Color{255, 50, 50, 255};
|
|
|
|
case PIXEL_GREEN:
|
|
|
|
return Color{50, 255, 50, 255};
|
|
|
|
case PIXEL_BLUE:
|
|
|
|
return Color{50, 50, 255, 255};
|
|
|
|
case PIXEL_YELLOW:
|
|
|
|
return Color{255, 255, 0, 255};
|
|
|
|
case PIXEL_CYAN:
|
|
|
|
return Color{0, 255, 255, 255};
|
|
|
|
case PIXEL_MAGENTA:
|
|
|
|
return Color{255, 0, 255, 255};
|
|
|
|
case PIXEL_ORANGE:
|
|
|
|
return Color{255, 200, 0, 255};
|
|
|
|
case PIXEL_BROWN:
|
|
|
|
return Color{180, 130, 0, 255};
|
|
|
|
case PIXEL_TURQUOISE:
|
|
|
|
return Color{0, 255, 200, 255};
|
|
|
|
case PIXEL_SKY:
|
|
|
|
return Color{168, 178, 255, 255};
|
|
|
|
case PIXEL_WHITE:
|
|
|
|
return Color{255, 255, 255, 255};
|
|
|
|
default:
|
|
|
|
assert(!"unreachable");
|
|
|
|
return Color{0, 0, 0, 255};
|
|
|
|
}
|
|
|
|
}
|