diff --git a/Makefile b/Makefile index c9e49f8..b1ea627 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ else COMMON_FLAGS = -DNDEBUG -O3 endif -CXX_FLAGS = -Wall -Wextra -Wpedantic -Weffc++ ${COMMON_FLAGS} +CXX_FLAGS = -Wall -Wextra -Wpedantic -Weffc++ ${COMMON_FLAGS} -std=c++20 LINKER_FLAGS = -lraylib OBJDIR = objdir diff --git a/res/test_cube.obj b/res/test_cube.obj new file mode 100644 index 0000000..953752c --- /dev/null +++ b/res/test_cube.obj @@ -0,0 +1,44 @@ +# Blender 3.6.0 +# www.blender.org +o Cube +v -1.000000 1.000000 1.000000 +v -1.000000 -1.000000 1.000000 +v -1.000000 1.000000 -1.000000 +v -1.000000 -1.000000 -1.000000 +v 1.000000 1.000000 1.000000 +v 1.000000 -1.000000 1.000000 +v 1.000000 1.000000 -1.000000 +v 1.000000 -1.000000 -1.000000 +vn -0.0000 1.0000 -0.0000 +vn -0.0000 -0.0000 -1.0000 +vn 1.0000 -0.0000 -0.0000 +vn -0.0000 -1.0000 -0.0000 +vn -1.0000 -0.0000 -0.0000 +vn -0.0000 -0.0000 1.0000 +vt 0.875000 0.500000 +vt 0.625000 0.750000 +vt 0.625000 0.500000 +vt 0.375000 1.000000 +vt 0.375000 0.750000 +vt 0.625000 0.000000 +vt 0.375000 0.250000 +vt 0.375000 0.000000 +vt 0.375000 0.500000 +vt 0.125000 0.750000 +vt 0.125000 0.500000 +vt 0.625000 0.250000 +vt 0.875000 0.750000 +vt 0.625000 1.000000 +s 0 +f 5/1/1 3/2/1 1/3/1 +f 3/2/2 8/4/2 4/5/2 +f 7/6/3 6/7/3 8/8/3 +f 2/9/4 8/10/4 6/11/4 +f 1/3/5 4/5/5 2/9/5 +f 5/12/6 2/9/6 6/7/6 +f 5/1/1 7/13/1 3/2/1 +f 3/2/2 7/14/2 8/4/2 +f 7/6/3 5/12/3 6/7/3 +f 2/9/4 4/5/4 8/10/4 +f 1/3/5 3/2/5 4/5/5 +f 5/12/6 1/3/6 2/9/6 diff --git a/res/test_cube_texture.png b/res/test_cube_texture.png new file mode 100644 index 0000000..d4121d4 Binary files /dev/null and b/res/test_cube_texture.png differ diff --git a/src/screen_trunner.cc b/src/screen_trunner.cc index f540d96..2e8f39f 100644 --- a/src/screen_trunner.cc +++ b/src/screen_trunner.cc @@ -14,15 +14,19 @@ TRunnerScreen::TRunnerScreen(std::weak_ptr 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(), - TEMP_cube(GenMeshCube(2.0F, 2.0F, 2.0F)), - TEMP_default_material(LoadMaterialDefault()), + TEMP_cube_model(LoadModel("res/test_cube.obj")), + TEMP_cube_texture(LoadTexture("res/test_cube_texture.png")), TEMP_matrix(get_identity_matrix()), - TEMP_offset_matrix(translate_matrix_z(-4.0F)), - TEMP_value(0.0F) {} + 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; +} TRunnerScreen::~TRunnerScreen() { - UnloadMesh(TEMP_cube); - UnloadMaterial(TEMP_default_material); + UnloadTexture(TEMP_cube_texture); + UnloadModel(TEMP_cube_model); } bool TRunnerScreen::update(float dt) { @@ -30,10 +34,31 @@ bool TRunnerScreen::update(float dt) { if (TEMP_value < PI / 2.0F) { TEMP_matrix = get_rotation_matrix_about_z(TEMP_value); } else if (TEMP_value < PI) { + 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"); + } TEMP_matrix = get_rotation_matrix_about_y(TEMP_value - PI / 2.0F); } else if (TEMP_value < PI * 3.0F / 2.0F) { + 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"); + } TEMP_matrix = get_rotation_matrix_about_x(TEMP_value - PI); } else { + 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"); + } TEMP_value -= PI * 3.0F / 2.0F; TEMP_matrix = get_rotation_matrix_about_z(TEMP_value); } @@ -45,7 +70,19 @@ bool TRunnerScreen::draw() { ClearBackground(PixelToColor(Pixel::PIXEL_SKY)); BeginMode3D(camera); - DrawMesh(TEMP_cube, TEMP_default_material, TEMP_matrix * TEMP_offset_matrix); + // 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); EndMode3D(); EndDrawing(); diff --git a/src/screen_trunner.h b/src/screen_trunner.h index 0bea606..93f6a75 100644 --- a/src/screen_trunner.h +++ b/src/screen_trunner.h @@ -41,11 +41,17 @@ class TRunnerScreen : public Screen { const Camera3D camera; std::bitset<64> flags; - Mesh TEMP_cube; - Material TEMP_default_material; + Model TEMP_cube_model; + Texture2D TEMP_cube_texture; Matrix TEMP_matrix; - Matrix TEMP_offset_matrix; + Matrix TEMP_permanent_matrix; float TEMP_value; + /* + * 0 - rotating about z + * 1 - rotating about y + * 2 - rotating about x + */ + int TEMP_current_state; }; #endif diff --git a/wasm_build/Makefile b/wasm_build/Makefile index af00916..2634161 100644 --- a/wasm_build/Makefile +++ b/wasm_build/Makefile @@ -27,11 +27,12 @@ CXX = source ${HOME}/git/emsdk/emsdk_env.sh && em++ all: | format jumpartifact.com_demo_0.html jumpartifact.com_demo_0.html: ${SOURCES} ${HEADERS} - ${CXX} -o jumpartifact.com_demo_0.html \ + ${CXX} -std=c++20 -o jumpartifact.com_demo_0.html \ -s USE_GLFW=3 -I../wasm_include -L../wasm_lib -lraylib \ --shell-file custom_shell.html \ -sEXPORTED_FUNCTIONS=_main \ -sEXPORTED_RUNTIME_METHODS=ccall \ + --preload-file ../res \ ${OTHER_FLAGS} \ ${SOURCES}