From 4f42f6ae18ca5fb7257441e368862f3df573f2bf Mon Sep 17 00:00:00 2001 From: Randy McShandy Date: Wed, 8 May 2024 21:23:49 -0500 Subject: [PATCH] Flipped barrow mesh and start rendering a distinct floor --- src/main.c | 3 ++- src/render_raylib.c | 56 ++++++++++++++++++++++++++++++++++----------- src/utils.c | 8 +++++++ 3 files changed, 53 insertions(+), 14 deletions(-) diff --git a/src/main.c b/src/main.c index 7f7d7d0..456c15e 100755 --- a/src/main.c +++ b/src/main.c @@ -22,7 +22,8 @@ int main(int argc, char** argv) } barrow.max_iterations *= 1; -#ifdef ENABLE_BARROWGEN +#define ENABLE_BARROWGEN 0 +#if ENABLE_BARROWGEN generate_rd(8, barrow, grid, grid_size); #endif start_render_loop(); diff --git a/src/render_raylib.c b/src/render_raylib.c index 0f0fab2..9dc62fa 100644 --- a/src/render_raylib.c +++ b/src/render_raylib.c @@ -9,13 +9,23 @@ Camera3D cam; Image barrow_image; Texture barrow_texture; -Texture albedo_texture; +Texture barrow_albedo; Model barrow_model; Mesh barrow_meshes[1U]; -Material barrow_material; -Matrix barrow_transform; Vector3 barrow_position; Vector3 barrow_scale; +Vector3 barrow_rotation_axis; +float barrow_rotation; + +Image floor_image; +Texture floor_texture; +Texture floor_albedo; +Model floor_model; +Mesh floor_meshes[1U]; +Vector3 floor_position; +Vector3 floor_scale; +Vector3 floor_rotation_axis; +float floor_rotation; Shader shader; int cam_position_shader_loc; @@ -29,6 +39,8 @@ float forward_speed_decay = 0.05f; float rotate_speed = 0.8f; float rotate_speed_decay = 0.10f; +Vector3 unit_vec3 = {1.0f, 1.0f, 1.0f}; + void process_inputs() { /* I guess GetRayCollisionMesh is the best solution here @@ -76,30 +88,47 @@ void initialize_renderer() screen_dims_shader_loc = GetShaderLocation(shader, "screen_dims"); while(!IsShaderReady(shader)){} - //barrow_position = (Vector3){-8.0f, 0.0f, -8.0f}; - barrow_position = (Vector3){-8.0f, 0.0f, -8.0f}; + barrow_position = (Vector3){0.0f, 0.0f, 0.0f}; barrow_image = LoadImage("./barrow.png"); - albedo_texture = LoadTexture("./barrow_albedo.png"); + barrow_albedo = LoadTexture("./barrow_albedo.png"); barrow_scale = (Vector3){barrow_image.width/6.0f, 8.0f, barrow_image.height/6.0f}; + barrow_rotation_axis = (Vector3){1.0f, 0.0f, 0.0f}; + barrow_rotation = 180.0f; while(!IsImageReady(barrow_image)){} barrow_texture = LoadTextureFromImage(barrow_image); while(!IsTextureReady(barrow_texture)){} - while(!IsTextureReady(albedo_texture)){} + while(!IsTextureReady(barrow_albedo)){} + + floor_image = LoadImage("./floor.png"); + floor_albedo = LoadTexture("./floor_albedo.png"); + floor_scale = (Vector3){floor_image.width/6.0f, 1.0f, floor_image.height/6.0f}; + floor_position = (Vector3){0.0f, -3.0f, -floor_scale.z}; + floor_rotation_axis = (Vector3){0.0f, 0.0f, floor_image.width}; + floor_rotation = 0.0f; + + while(!IsImageReady(floor_image)){} + while(!IsTextureReady(floor_albedo)){} /* Might want to replace barrow_scale with just img dimensions. */ - barrow_meshes[0U] = GenMeshHeightmap(barrow_image, barrow_scale); + barrow_meshes[0U] = GenMeshHeightmap(barrow_image, unit_vec3); barrow_model = LoadModelFromMesh(barrow_meshes[0]); - barrow_model.materials[0].maps[MATERIAL_MAP_ALBEDO].texture = albedo_texture; - barrow_model.materials[0].maps[MATERIAL_MAP_ROUGHNESS].texture = albedo_texture; + barrow_model.materials[0].maps[MATERIAL_MAP_ALBEDO].texture = barrow_albedo; + barrow_model.materials[0].maps[MATERIAL_MAP_ROUGHNESS].texture = barrow_albedo; barrow_model.materials[0].shader = shader; + floor_meshes[0U] = GenMeshHeightmap(floor_image, unit_vec3); + floor_model = LoadModelFromMesh(floor_meshes[0]); + floor_model.materials[0].maps[MATERIAL_MAP_ALBEDO].texture = floor_albedo; + floor_model.materials[0].maps[MATERIAL_MAP_ROUGHNESS].texture = floor_albedo; + floor_model.materials[0].shader = shader; + cam = (Camera3D){0}; cam.position = barrow_position; - cam.position.y += 2.0f; + cam.position.y -= 0.5f; cam.position.x = barrow_scale.x/2 + barrow_position.x; - cam.target = (Vector3){0.0f, cam.position.y * 0.1, 0.0f}; + cam.target = (Vector3){0.0f, cam.position.y - 12.0f, 0.0f}; cam.up = (Vector3){0.0f, 1.0f, 0.0f}; cam.fovy = 75.0f; cam.projection= CAMERA_PERSPECTIVE; @@ -128,7 +157,8 @@ void start_render_loop() BeginMode3D(cam); BeginShaderMode(shader); - DrawModel(barrow_model, barrow_position, 1.0f, DARKGRAY); + DrawModelEx(barrow_model, barrow_position, barrow_rotation_axis, barrow_rotation, barrow_scale, DARKGRAY); + DrawModelEx(floor_model, floor_position, floor_rotation_axis, floor_rotation, floor_scale, DARKGRAY); EndShaderMode(); EndMode3D(); diff --git a/src/utils.c b/src/utils.c index 9771659..6fe514a 100644 --- a/src/utils.c +++ b/src/utils.c @@ -194,9 +194,13 @@ int generate_rd(int worker_count, RD_Opts active_opt, FVec2 **grid_buffer, IVec2 } char mesh_name[64] = {0}; + char floor_mesh_name[64] = {0}; char albedo_name[64] = {0}; + char floor_albedo_name[64] = {0}; sprintf(mesh_name, "./%s.png", active_opt.name); sprintf(albedo_name, "./%s_albedo.png", active_opt.name); + sprintf(floor_mesh_name, "./floor.png"); + sprintf(floor_albedo_name, "./floor_albedo.png"); stbir_resize_uint8_linear( (unsigned char*)mesh_buffer, pgrid_size.x, pgrid_size.y, sizeof(uint8_t) * pgrid_size.x, @@ -210,6 +214,10 @@ int generate_rd(int worker_count, RD_Opts active_opt, FVec2 **grid_buffer, IVec2 stbi_write_png(mesh_name, pgrid_size.x*img_export_scale.x, pgrid_size.y*img_export_scale.y, 1, large_mesh_buffer, pgrid_size.x * sizeof(uint8_t)*img_export_scale.x); stbi_write_png(albedo_name, pgrid_size.x*img_export_scale.x, pgrid_size.y*img_export_scale.y, 4, large_albedo_buffer, pgrid_size.x * sizeof(uint32_t)*img_export_scale.x); + stbi_flip_vertically_on_write(1); + stbi_write_png(floor_mesh_name, pgrid_size.x*img_export_scale.x, pgrid_size.y*img_export_scale.y, 1, large_mesh_buffer, pgrid_size.x * sizeof(uint8_t)*img_export_scale.x); + stbi_write_png(floor_albedo_name, pgrid_size.x*img_export_scale.x, pgrid_size.y*img_export_scale.y, 4, large_albedo_buffer, pgrid_size.x * sizeof(uint32_t)*img_export_scale.x); + cleanup(); return 0; } -- 2.49.0