]> git.seodisparate.com - jumpartifact.com_demo_0/commitdiff
Test using a textured cube
authorStephen Seo <seo.disparate@gmail.com>
Fri, 4 Aug 2023 05:32:05 +0000 (14:32 +0900)
committerStephen Seo <seo.disparate@gmail.com>
Fri, 4 Aug 2023 05:32:05 +0000 (14:32 +0900)
Makefile
res/test_cube.obj [new file with mode: 0644]
res/test_cube_texture.png [new file with mode: 0644]
src/screen_trunner.cc
src/screen_trunner.h
wasm_build/Makefile

index c9e49f824b482ed029a55bc8d8ad53467db8fd95..b1ea6272a5e952bfc71af22615d96b018262a0a2 100644 (file)
--- 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 (file)
index 0000000..953752c
--- /dev/null
@@ -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 (file)
index 0000000..d4121d4
Binary files /dev/null and b/res/test_cube_texture.png differ
index f540d962813b73084dd98d990c6a64cf9b133fc2..2e8f39f1c93c0fbf53943567c9c18f0f93735d75 100644 (file)
@@ -14,15 +14,19 @@ TRunnerScreen::TRunnerScreen(std::weak_ptr<ScreenStack> 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();
index 0bea606d0d4a2fbb82621f41c93c6318e51bc80f..93f6a7530b413da4bb6edc312f00b1a95fc51a65 100644 (file)
@@ -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
index af00916faac89fe5473e6651b88e458472940159..263416140e5894a1e77c415c2b393dfe4c37196f 100644 (file)
@@ -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}