From: Randy McShandy Date: Thu, 17 Oct 2024 03:41:56 +0000 (-0500) Subject: Second try. Probably cleaner X-Git-Url: http://git.mcshandy.xyz/gitweb.cgi?a=commitdiff_plain;h=d449c7da6d30cfbfdfcb4619a3c275f5e953640a;p=barrow_crawler Second try. Probably cleaner --- diff --git a/src/render_raylib.c b/src/render_raylib.c index b5b19c4..0711942 100644 --- a/src/render_raylib.c +++ b/src/render_raylib.c @@ -35,6 +35,7 @@ Vector2 fscreen_dims; Camera3D cam; +Vector3 cam_reset_position; Image barrow_image; Texture barrow_texture; Texture barrow_albedo; @@ -45,13 +46,14 @@ Mesh barrow_meshes[1U]; Vector3 barrow_position; // Dead center of the barrow, used for camera spawn etc -Vector3 barrow_center; +Vector3 map_center; // Scale factor from image -> model Vector3 barrow_scale_factor; +Vector3 floor_scale_factor; // Scaled dimensions of the barrow, barrow_scale_factor applied -Vector3 barrow_size; +Vector3 barrow_extent; Vector3 barrow_rotation_axis; float barrow_rotation; @@ -63,7 +65,7 @@ Texture floor_albedo; Model floor_model; Mesh floor_meshes[1U]; Vector3 floor_position; -Vector3 floor_size; +Vector3 floor_extent; Vector3 floor_rotation_axis; float floor_rotation; @@ -115,7 +117,7 @@ float orb_intensity = 1.0f; /* TODO: normalized distance from center, but lighti Vector3 orb_directionality = {1.0f, 1.0f, 1.0f}; int map_visible = 0; -int draw_barrow = 1; +int draw_collision_mesh = 1; typedef void(*renderfunc)(); typedef void(*controlfunc)(); @@ -151,17 +153,21 @@ void drawing_game_mode() BeginMode3D(cam); BeginShaderMode(shader); - if (draw_barrow) + DrawModelEx(floor_model, floor_position, floor_rotation_axis, floor_rotation, floor_extent, DARKGRAY); + DrawModelEx(barrow_model, barrow_position, barrow_rotation_axis, barrow_rotation, barrow_extent, DARKGRAY); + if (draw_collision_mesh) { - DrawModelEx(floor_model, floor_position, floor_rotation_axis, floor_rotation, floor_size, DARKGRAY); - DrawModelEx(barrow_model, barrow_position, barrow_rotation_axis, barrow_rotation, barrow_size, DARKGRAY); + //DrawMesh(barrow_model.meshes[0], barrow_model.materials[0], barrow_mat); } for (int n = 0; n < room_count; n++) { Vector3 each = room_positions[n]; - DrawSphere(each, 0.25, RED); + DrawSphere(each, 1.0, RED); } + DrawSphere(map_center, 1.0, BLUE); + DrawSphere(barrow_position, 1.0, GREEN); + DrawSphere(floor_position, 1.0, PURPLE); for (int n = 0; n < spawn_spoke_count; n++) { @@ -194,7 +200,8 @@ void drawing_game_mode() DrawText(TextFormat(V3_FORMAT(player_collide_ray.position), V3_UNROLL(player_collide_ray.position), V3_UNROLL(player_collide_ray.direction)), 0, 128+(line_height*4), 16, GREEN); DrawText(TextFormat(V3_FORMAT(room_positions[0]), V3_UNROLL(room_positions[0])), 0, 128+(line_height*5), 16, GREEN); DrawText(TextFormat(V3_FORMAT(barrow_position), V3_UNROLL(barrow_position)), 0, 128+(line_height*6), 16, GREEN); - DrawText(TextFormat(V3_FORMAT(barrow_size), V3_UNROLL(barrow_size)), 0, 128+(line_height*7), 16, GREEN); + DrawText(TextFormat(V3_FORMAT(floor_position), V3_UNROLL(floor_position)), 0, 128+(line_height*7), 16, GREEN); + DrawText(TextFormat(V3_FORMAT(barrow_size), V3_UNROLL(barrow_extent)), 0, 128+(line_height*8), 16, GREEN); } } @@ -290,12 +297,12 @@ void control_game_mode() if (IsKeyReleased(KEY_N)) { - draw_barrow = !draw_barrow; + draw_collision_mesh = !draw_collision_mesh; } if (IsKeyReleased(KEY_Z)) { - cam.position = barrow_center; + cam.position = cam_reset_position; } if (IsKeyReleased(KEY_ONE)) @@ -313,7 +320,7 @@ void control_game_mode() player_collision = GetRayCollisionMesh(player_collide_ray, barrow_model.meshes[0U], barrow_mat); player_rotation = new_player_rotation; - if (player_collision.hit && player_collision.distance < 0.89f) + if (player_collision.hit && player_collision.distance < 1.30f) { player_velocity.x *= -1.05; } @@ -352,20 +359,49 @@ void wait_initialize_shaders() void wait_initialize_resources() { + /* Floor resource setup. */ + { + floor_image = LoadImage("./floor.png"); + floor_albedo = LoadTexture("./floor_albedo.png"); + while(!IsImageReady(floor_image)){} + + floor_scale_factor = (Vector3){1.0f/8.0f, 8.0f, 1.0f/8.0f}; + floor_extent = Vector3Multiply( + (Vector3){floor_albedo.width, 1.0f, floor_albedo.height}, + floor_scale_factor); + + floor_position = vec3_zero; + floor_rotation_axis = vec3_zero; + floor_rotation = 0.0f; + + while(!IsTextureReady(floor_albedo)){} + floor_texture = LoadTextureFromImage(floor_image); + while(!IsTextureReady(floor_texture)){} + + floor_meshes[0U] = GenMeshHeightmap(floor_image, vec3_unit); + 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; + while(!IsModelReady(floor_model)){} + } + /* Barrow resource setup. */ { barrow_image = LoadImage("./barrow.png"); barrow_albedo = LoadTexture("./barrow_albedo.png"); - barrow_position = vec3_zero; - barrow_position.y += 3.0f; - barrow_scale_factor = (Vector3){1.0f/8.0f, 8.0f, 1.0f/8.0f}; - barrow_size = Vector3Multiply( + barrow_position = floor_position; + barrow_position.y += 2.0f; + barrow_scale_factor = (Vector3){1.0f/8.0f, 3.0f, 1.0f/8.0f}; + barrow_extent = Vector3Multiply( (Vector3){barrow_albedo.width, 1.0f, barrow_albedo.height}, barrow_scale_factor); + + barrow_position.z += barrow_extent.z; barrow_rotation_axis = (Vector3){1.0f, 0.0f, 0.0f}; barrow_rotation = 180.0f; printf("barrow_position: {%f %f %f}\n", V3_UNROLL(barrow_position)); - printf("barrow_size: {%f %f %f}\n", V3_UNROLL(barrow_size)); + printf("barrow_size: {%f %f %f}\n", V3_UNROLL(barrow_extent)); while(!IsImageReady(barrow_image)){} while(!IsTextureReady(barrow_albedo)){} @@ -378,47 +414,9 @@ void wait_initialize_resources() barrow_model.materials[0].maps[MATERIAL_MAP_ROUGHNESS].texture = barrow_albedo; barrow_model.materials[0].shader = shader; - room_positions[0] = barrow_position; - printf("sphere %f %f %f\n", V3_UNROLL(room_positions[0])); - for (int n = 1; n < room_count; n++) - { - // Scale room positions down from gentime positions - room_positions[n] = Vector3Multiply(room_positions[n], barrow_scale_factor); - printf("sphere %f %f %f\n", V3_UNROLL(room_positions[n])); - } - while(!IsModelReady(barrow_model)){} } - /* Floor resource setup. */ - { - floor_image = LoadImage("./floor.png"); - floor_albedo = LoadTexture("./floor_albedo.png"); - while(!IsImageReady(floor_image)){} - - floor_size = barrow_size; - floor_size.y = 3.0f; - - floor_position = barrow_position; - barrow_position.z += barrow_size.z; - barrow_position.y -= 0.5f; - floor_position.y -= barrow_position.y; - - floor_rotation_axis = (Vector3){0.0f, 0.0f, floor_image.width}; - floor_rotation = 0.0f; - - while(!IsTextureReady(floor_albedo)){} - floor_texture = LoadTextureFromImage(floor_image); - while(!IsTextureReady(floor_texture)){} - - floor_meshes[0U] = GenMeshHeightmap(floor_image, vec3_unit); - 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; - while(!IsModelReady(floor_model)){} - } - /* Other resource setup. */ { coffin_scale = (Vector3){1.5f, 1.5f, 1.5f}; @@ -438,6 +436,20 @@ void wait_initialize_resources() hand_rotation = 0.0f; } + printf("center room %f %f %f\n", V3_UNROLL(room_positions[0])); + for (int n = 0; n < room_count; n++) + { + // Scale room positions down from gentime positions + printf("room at %f %f %f\n", V3_UNROLL(room_positions[n])); + //room_positions[n].x -= barrow_image.width/2.0f; + room_positions[n].x -= 1.0f; + //room_positions[n].z -= barrow_image.height; + //room_positions[n] = Vector3Multiply(room_positions[n], barrow_scale_factor); + //room_positions[n] = Vector3Add(room_positions[n], barrow_size); + //room_positions[n] = Vector3Add(room_positions[n], map_center); + printf("room moved to %f %f %f\n", V3_UNROLL(room_positions[n])); + } + /* Setup Rays for visualizing spawn contact points */ spawn_spoke_count = room_count; spawn_spoke_rays = malloc(sizeof(Ray) * spawn_spoke_count); @@ -445,7 +457,7 @@ void wait_initialize_resources() { Ray* each = &spawn_spoke_rays[n]; each->position = room_positions[n+1]; - each->position = Vector3Add(each->position, barrow_position); + each->position = Vector3Add(each->position, floor_position); each->direction = Vector3Subtract(each->position, cam.position); printf("Initialized a ray at {%f %f %f} to {%f %f %f}\n", V3_UNROLL(each->position), V3_UNROLL(each->direction)); @@ -455,8 +467,10 @@ void wait_initialize_resources() /* Grab the full transformation matrix of the upper barrow for use in collision */ /* Apparently matrix work needs to be normalized. */ { - Vector3 bt = (Vector3){0.0, -0.3, -1.0f}; - Vector3 bs = barrow_size; + // The Y adjustment seems to be the difference between 1 and the + // height of the ceiling, then scaled 1/10th? + Vector3 bt = (Vector3){0.0, -0.8, -1.0f}; + Vector3 bs = barrow_extent; Matrix mat_trans = MatrixTranslate(V3_UNROLL(bt)); Matrix mat_rot = MatrixRotate(barrow_rotation_axis, DEG2RAD * barrow_rotation); Matrix mat_scale = MatrixScale(V3_UNROLL(bs)); @@ -468,18 +482,22 @@ void wait_initialize_resources() /* Values and things to do that have to have to be done after Raylib is initialized. */ void initialize_renderer() { - barrow_center = barrow_size; - barrow_center.x /= 2.0f; - barrow_center.z /= 2.0f; - barrow_center.y -= 6.5f; + cam_reset_position = map_center; + cam_reset_position.y = 1.0f; + map_center = floor_extent; + map_center.x /= 2.0f; + map_center.z /= 2.0f; cam = (Camera3D){0}; - cam.position = barrow_center; + cam.position = cam_reset_position; cam.target = cam.position; cam.target.x += 3.0f; cam.up = (Vector3){0.0f, 1.0f, 0.0f}; cam.fovy = 90.0f; cam.projection = CAMERA_PERSPECTIVE; + /* eye in the sky */ + //cam.position.y += 64; + /* I know these are good at 60 fps. Per-second speed to move to FPS/independent movement. */ diff --git a/src/utils.c b/src/utils.c index 1bc525e..47c8db2 100644 --- a/src/utils.c +++ b/src/utils.c @@ -105,7 +105,6 @@ int initialize(int worker_count, RD_Opts active_opt) int center_x = grid_size.x/2; int center_y = grid_size.y/2; float central_chamber_radius = barrow_radius/6; - room_positions[0] = (Vector3){.x = center_x, .y = 0.0f, .z = center_y}; for (int x = 0; x < grid_size.x; x++) { @@ -149,8 +148,8 @@ int initialize(int worker_count, RD_Opts active_opt) int seed_y = ((sinf(angle) * (dist_offset + (grid_size.y/4.0f))) + (grid_size.y/2.0f)); // TODO: One of these will probably have to be mirrored. - room_positions[n+1] = (Vector3){.x = seed_x, .y = 0.0f, .z = seed_y}; - printf("Set room %d to {%f %f %f}\n", n+1, VEC3_UNROLL(room_positions[n+1])); + room_positions[n] = (Vector3){.x = seed_x, .y = 0.0f, .z = seed_y}; + printf("Set room %d to {%f %f %f}\n", n, VEC3_UNROLL(room_positions[n])); grid[seed_x][seed_y].b = 1.0f; grid[seed_x][seed_y].c = 0.0f;