#include "structs.h"
-#define VEC3_UNROLL(v3) v3.x, v3.y, v3.z
+#define str(x) #x
+#define xstr(x) str(x)
+#define V3_UNROLL(v3) v3.x, v3.y, v3.z
+#define V3_FORMAT(v3) #v3 ":{%.4f %.4f %.4f}"
+
+#define MAT4_UNROLL(m) \
+ m.m0 , \
+ m.m1 , \
+ m.m2 , \
+ m.m3 , \
+ m.m4 , \
+ m.m5 , \
+ m.m6 , \
+ m.m7 , \
+ m.m8 , \
+ m.m9 , \
+ m.m10, \
+ m.m11, \
+ m.m12, \
+ m.m13, \
+ m.m14, \
+ m.m15
Vector2 fscreen_dims;
Camera3D cam;
Texture barrow_albedo;
Model barrow_model;
Mesh barrow_meshes[1U];
+
+// Absolute position of the center of the barrow model in the world
Vector3 barrow_position;
-Vector3 barrow_scale;
+
+// Dead center of the barrow, used for camera spawn etc
+Vector3 barrow_center;
+
+// Scale factor from image -> model
+Vector3 barrow_scale_factor;
+
+// Scaled dimensions of the barrow, barrow_scale_factor applied
+Vector3 barrow_size;
+
Vector3 barrow_rotation_axis;
float barrow_rotation;
Matrix barrow_mat;
Model floor_model;
Mesh floor_meshes[1U];
Vector3 floor_position;
-Vector3 floor_scale;
+Vector3 floor_size;
Vector3 floor_rotation_axis;
float floor_rotation;
float rotate_speed_decay = 0.10f;
Vector3 vec3_unit = {1.0f, 1.0f, 1.0f};
+Vector3 vec3_twos = {2.0f, 2.0f, 2.0f};
Vector3 vec3_010 = {0.0f, 1.0f, 0.0f};
Vector3 vec3_up = {0.0f, 1.0f, 0.0f};
Vector3 vec3_down = {0.0f, -1.0f, 0.0f};
+Vector3 vec3_zero = {0.0f, 0.0f, 0.0f};
Color orb_color = BLUE;
Color orb_target_color = BLUE;
Vector3 orb_directionality = {1.0f, 1.0f, 1.0f};
int map_visible = 0;
+int draw_barrow = 1;
typedef void(*renderfunc)();
typedef void(*controlfunc)();
void drawing_game_mode()
{
Vector2 from_center_coords = (Vector2){cam.position.x, cam.position.z};
- from_center_coords.x -= barrow_scale.x/2;
- from_center_coords.y += barrow_scale.z/2;
+ from_center_coords.x -= barrow_scale_factor.x/2;
+ from_center_coords.y += barrow_scale_factor.z/2;
/* -PI, PI */
player_angles.y = Vector2Angle(Vector2Normalize(from_center_coords), (Vector2){1.0f, 0.0f});
BeginMode3D(cam);
BeginShaderMode(shader);
- 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);
+ if (draw_barrow)
+ {
+ 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);
+ }
+
+ for (int n = 0; n < room_count; n++)
+ {
+ Vector3 each = room_positions[n];
+ DrawSphere(each, 0.25, RED);
+ }
- DrawSphere(room_positions[0], 0.25, RED);
+ for (int n = 0; n < spawn_spoke_count; n++)
+ {
+ Ray* each = &spawn_spoke_rays[n];
+ //DrawRay(*each, RED);
+ }
+ //DrawRay(player_collide_ray, RED);
EndShaderMode();
EndMode3D();
if(map_visible)
{
+ const int line_height = 32;
DrawFPS(fscreen_dims.x - 80, 10);
DrawTexturePro(floor_texture, minimap_src, minimap_dest, (Vector2){0.0f, 0.0f}, 0.0f, RAYWHITE);
- DrawText(TextFormat("cam x %f\ncam y %f\ncam z %f", cam.position.x, cam.position.y, cam.position.z), 0, 128, 16, GREEN);
- DrawText(TextFormat("tgt x %f\ntgt y %f\ntgt z %f", cam.target.x, cam.target.y, cam.target.z), 0, 128+64, 16, GREEN);
- DrawText(TextFormat("rot x %f\nrot y %f\nrot z %f", player_angles.x, player_angles.y, player_angles.z), 0, 128+(64*2), 16, GREEN);
- DrawText(TextFormat("ray hit %d\nlength %f", player_collision.hit, player_collision.distance), 0, 128+(64*3), 16, GREEN);
- DrawText(TextFormat("c x %f\nc y %f\nc z %f", room_positions[0].x, room_positions[0].y, room_positions[0].z), 0, 128+(64*4), 16, GREEN);
+ DrawText(TextFormat(V3_FORMAT(cam.position), V3_UNROLL(cam.position)), 0, 128, 16, GREEN);
+ DrawText(TextFormat(V3_FORMAT(cam.target), V3_UNROLL(cam.target)), 0, 128+line_height, 16, GREEN);
+ DrawText(TextFormat(V3_FORMAT(player_angles), V3_UNROLL(player_angles)), 0, 128+(line_height*2), 16, GREEN);
+ DrawText(TextFormat("ray hit:%d length %.2f" V3_FORMAT(player_collision.point), player_collision.hit, player_collision.distance, player_collision.point), 0, 128+(line_height*3), 16, GREEN);
+ 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);
}
}
static int status_phase = 0;
const float font_size = 32.0f;
const char format_string[] = "%s\n\n%3.2f%%";
- const char tribute_string[] = "This game is dedicated to the North American Muskrat, Ondatra Zibethicus";
+ const char tribute_string[] = "This game is dedicated to the North American Muskrat, Ondatra zibethicus";
ClearBackground(LIGHTGRAY);
DrawText(tribute_string,
{
static int status_phase = 0;
const char format_string[] = "%s\n\n%3.2f%%";
- const char tribute_string[] = "This game is dedicated to the North American Muskrat, Ondatra Zibethicus";
+ const char tribute_string[] = "This game is dedicated to the North American Muskrat, Ondatra zibethicus";
const char wait_string[] = "Generating resources...";
const int sector_speed = 2U;
const int sector_segments = 16;
cam.target.y -= DEG2RAD * 20.0;
}
- map_visible = 0;
- if (IsKeyDown(KEY_M))
+ if (IsKeyReleased(KEY_M))
+ {
+ map_visible = !map_visible;
+ }
+
+ if (IsKeyReleased(KEY_N))
{
- map_visible = 1;
+ draw_barrow = !draw_barrow;
+ }
+
+ if (IsKeyReleased(KEY_Z))
+ {
+ cam.position = barrow_center;
}
if (IsKeyReleased(KEY_ONE))
player_collision = GetRayCollisionMesh(player_collide_ray, barrow_model.meshes[0U], barrow_mat);
player_rotation = new_player_rotation;
- if (player_collision.distance >= 0.3f)
+ if (player_collision.hit && player_collision.distance < 0.89f)
{
- player_velocity = new_player_velocity;
+ player_velocity.x *= -1.05;
}
else
{
- player_velocity.x *= -1.05;
+ player_velocity = new_player_velocity;
}
switch(key)
{
/* Barrow resource setup. */
{
- barrow_position = (Vector3){0.0f, 0.0f, 0.0f};
barrow_image = LoadImage("./barrow.png");
barrow_albedo = LoadTexture("./barrow_albedo.png");
- barrow_scale = (Vector3){barrow_image.width/6.0f, 8.0f, barrow_image.height/6.0f};
+ 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(
+ (Vector3){barrow_albedo.width, 1.0f, barrow_albedo.height},
+ barrow_scale_factor);
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));
while(!IsImageReady(barrow_image)){}
while(!IsTextureReady(barrow_albedo)){}
barrow_model.materials[0].maps[MATERIAL_MAP_ROUGHNESS].texture = barrow_albedo;
barrow_model.materials[0].shader = shader;
- room_positions[0] = (Vector3){barrow_scale.x/2.0f, floor_position.y - 1.0f, -barrow_scale.z/2.0f};
- printf("sphere %f %f %f\n", VEC3_UNROLL(room_positions[0]));
+ 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_image = LoadImage("./floor.png");
floor_albedo = LoadTexture("./floor_albedo.png");
while(!IsImageReady(floor_image)){}
- floor_scale = (Vector3){floor_image.width/6.0f, 3.0f, floor_image.height/6.0f};
- floor_position = (Vector3){0.0f, -3.0f, -floor_scale.z};
+
+ 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)){}
/* Other resource setup. */
{
coffin_scale = (Vector3){1.5f, 1.5f, 1.5f};
- coffin_position = (Vector3){barrow_scale.x/2.0f, floor_position.y, -barrow_scale.z/2.0f};
+ coffin_position = (Vector3){barrow_scale_factor.x/2.0f, floor_position.y, -barrow_scale_factor.z/2.0f};
coffin_rotation_axis = (Vector3){0.0f, 0.0f, 0.0f};
coffin_rotation = 0.0f;
coffin_model = LoadModel("./assets/coffin_1.glb");
hand_position = (Vector2){0, fscreen_dims.y - (hand_01_image.height * hand_scale)};
hand_rotation = 0.0f;
}
+
+ /* Setup Rays for visualizing spawn contact points */
+ spawn_spoke_count = room_count;
+ spawn_spoke_rays = malloc(sizeof(Ray) * spawn_spoke_count);
+ for (int n = 0; n < spawn_spoke_count; n++)
+ {
+ Ray* each = &spawn_spoke_rays[n];
+ each->position = room_positions[n+1];
+ each->position = Vector3Add(each->position, barrow_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));
+ printf("\tfrom room position {%f %f %f}\n", V3_UNROLL(room_positions[n+1]));
+ }
+
+ /* 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;
+ Matrix mat_trans = MatrixTranslate(V3_UNROLL(bt));
+ Matrix mat_rot = MatrixRotate(barrow_rotation_axis, DEG2RAD * barrow_rotation);
+ Matrix mat_scale = MatrixScale(V3_UNROLL(bs));
+
+ barrow_mat = MatrixMultiply(MatrixMultiply(mat_trans, mat_scale), mat_rot);
+ }
}
/* 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 = (Camera3D){0};
- cam.position = barrow_position;
- cam.position.y -= 0.5f;
- cam.position.x = barrow_scale.x/2.0f;
- cam.position.z = (-barrow_scale.z/2.0f);
- cam.target = (Vector3){barrow_scale.x/2.0f, cam.position.y - 7.0f, cam.position.z/2.0f};
+ cam.position = barrow_center;
+ 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;
{
fscreen_dims = (Vector2){.x=screen_dims.x, .y=screen_dims.y};
- map_center = barrow_scale;
+ map_center = barrow_scale_factor;
map_center.x /= 2.0f;
map_center.z /= -2.0f;
map_center.y = -3.0f;
int func_idx = resource_state;
player_collide_point = cam.position;
- player_collide_point.y -= 1.0f;
+ //player_collide_point.y -= 1.0f;
controlfuncs[func_idx]();
- Matrix mat_trans = MatrixTranslate(barrow_position.x, barrow_position.y, barrow_position.z);
- Matrix mat_rot = MatrixRotate(barrow_rotation_axis, DEG2RAD * barrow_rotation);
- Matrix mat_scale = MatrixScale(barrow_scale.x, barrow_scale.y, barrow_scale.z);
- barrow_mat = MatrixMultiply(MatrixMultiply(mat_trans, mat_scale), mat_rot);
SetShaderValue(shader, cam_position_shader_loc, &cam.position, SHADER_UNIFORM_VEC3);
SetShaderValue(shader, screen_dims_shader_loc, &fscreen_dims, SHADER_UNIFORM_VEC2);