]> git.mcshandy.xyz Git - barrow_crawler/commitdiff
Flipped barrow mesh and start rendering a distinct floor
authorRandy McShandy <randy@mcshandy.xyz>
Thu, 9 May 2024 02:23:49 +0000 (21:23 -0500)
committerRandy McShandy <randy@mcshandy.xyz>
Thu, 9 May 2024 02:23:49 +0000 (21:23 -0500)
src/main.c
src/render_raylib.c
src/utils.c

index 7f7d7d063bddb48b3b924bc0093c3eb151eba9f3..456c15ee604ecb517f54d3363243710906c57fcc 100755 (executable)
@@ -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();
index 0f0fab28fe8e24786f93c74886b02129af98ef0a..9dc62fac85914973748eb939a218e00c760dc1e3 100644 (file)
@@ -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();
 
index 9771659e34d252d0279a570bb5d7319b1bb7c6e2..6fe514a2a827b8c480c4b4ddf23cc0b2f8bac127 100644 (file)
@@ -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;
 }