Test using a textured cube

This commit is contained in:
Stephen Seo 2023-08-04 14:32:05 +09:00
parent f0ce6520f4
commit 8bc8bdf0c5
6 changed files with 100 additions and 12 deletions

View file

@ -4,7 +4,7 @@ else
COMMON_FLAGS = -DNDEBUG -O3 COMMON_FLAGS = -DNDEBUG -O3
endif endif
CXX_FLAGS = -Wall -Wextra -Wpedantic -Weffc++ ${COMMON_FLAGS} CXX_FLAGS = -Wall -Wextra -Wpedantic -Weffc++ ${COMMON_FLAGS} -std=c++20
LINKER_FLAGS = -lraylib LINKER_FLAGS = -lraylib
OBJDIR = objdir OBJDIR = objdir

44
res/test_cube.obj Normal file
View file

@ -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

BIN
res/test_cube_texture.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

View 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}, 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}, Vector3{0.0F, 1.0F, 0.0F}, 80.0F, CAMERA_PERSPECTIVE},
flags(), flags(),
TEMP_cube(GenMeshCube(2.0F, 2.0F, 2.0F)), TEMP_cube_model(LoadModel("res/test_cube.obj")),
TEMP_default_material(LoadMaterialDefault()), TEMP_cube_texture(LoadTexture("res/test_cube_texture.png")),
TEMP_matrix(get_identity_matrix()), TEMP_matrix(get_identity_matrix()),
TEMP_offset_matrix(translate_matrix_z(-4.0F)), TEMP_permanent_matrix(get_identity_matrix()),
TEMP_value(0.0F) {} TEMP_value(0.0F),
TEMP_current_state(0) {
TEMP_cube_model.materials[0].maps[MATERIAL_MAP_DIFFUSE].texture =
TEMP_cube_texture;
}
TRunnerScreen::~TRunnerScreen() { TRunnerScreen::~TRunnerScreen() {
UnloadMesh(TEMP_cube); UnloadTexture(TEMP_cube_texture);
UnloadMaterial(TEMP_default_material); UnloadModel(TEMP_cube_model);
} }
bool TRunnerScreen::update(float dt) { bool TRunnerScreen::update(float dt) {
@ -30,10 +34,31 @@ bool TRunnerScreen::update(float dt) {
if (TEMP_value < PI / 2.0F) { if (TEMP_value < PI / 2.0F) {
TEMP_matrix = get_rotation_matrix_about_z(TEMP_value); TEMP_matrix = get_rotation_matrix_about_z(TEMP_value);
} else if (TEMP_value < PI) { } 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); TEMP_matrix = get_rotation_matrix_about_y(TEMP_value - PI / 2.0F);
} else if (TEMP_value < PI * 3.0F / 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); TEMP_matrix = get_rotation_matrix_about_x(TEMP_value - PI);
} else { } 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_value -= PI * 3.0F / 2.0F;
TEMP_matrix = get_rotation_matrix_about_z(TEMP_value); TEMP_matrix = get_rotation_matrix_about_z(TEMP_value);
} }
@ -45,7 +70,19 @@ bool TRunnerScreen::draw() {
ClearBackground(PixelToColor(Pixel::PIXEL_SKY)); ClearBackground(PixelToColor(Pixel::PIXEL_SKY));
BeginMode3D(camera); 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(); EndMode3D();
EndDrawing(); EndDrawing();

View file

@ -41,11 +41,17 @@ class TRunnerScreen : public Screen {
const Camera3D camera; const Camera3D camera;
std::bitset<64> flags; std::bitset<64> flags;
Mesh TEMP_cube; Model TEMP_cube_model;
Material TEMP_default_material; Texture2D TEMP_cube_texture;
Matrix TEMP_matrix; Matrix TEMP_matrix;
Matrix TEMP_offset_matrix; Matrix TEMP_permanent_matrix;
float TEMP_value; float TEMP_value;
/*
* 0 - rotating about z
* 1 - rotating about y
* 2 - rotating about x
*/
int TEMP_current_state;
}; };
#endif #endif

View file

@ -27,11 +27,12 @@ CXX = source ${HOME}/git/emsdk/emsdk_env.sh && em++
all: | format jumpartifact.com_demo_0.html all: | format jumpartifact.com_demo_0.html
jumpartifact.com_demo_0.html: ${SOURCES} ${HEADERS} 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 \ -s USE_GLFW=3 -I../wasm_include -L../wasm_lib -lraylib \
--shell-file custom_shell.html \ --shell-file custom_shell.html \
-sEXPORTED_FUNCTIONS=_main \ -sEXPORTED_FUNCTIONS=_main \
-sEXPORTED_RUNTIME_METHODS=ccall \ -sEXPORTED_RUNTIME_METHODS=ccall \
--preload-file ../res \
${OTHER_FLAGS} \ ${OTHER_FLAGS} \
${SOURCES} ${SOURCES}