Vector3 barrow_scale;
Vector3 barrow_rotation_axis;
float barrow_rotation;
+Matrix barrow_mat;
Image floor_image;
Texture floor_texture;
int screen_dims_shader_loc;
int map_center_shader_loc;
+Vector3 player_collide_point;
+Ray player_collide_ray;
+RayCollision player_collision;
Vector3 player_velocity;
Vector3 player_rotation;
Vector3 map_center;
Vector3 vec3_unit = {1.0f, 1.0f, 1.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};
void process_inputs()
{
- /* I guess GetRayCollisionMesh is the best solution here
- but cameras don't know what they're touching so I'll
- have to roll my own movement */
+ Vector3 new_player_velocity = player_velocity;
+ Vector3 new_player_rotation = player_rotation;
KeyboardKey key = GetKeyPressed();
do
{
if (IsKeyDown(KEY_W) || IsKeyDown(KEY_K))
{
- player_velocity.x = forward_speed;
+ new_player_velocity.x = forward_speed;
}
else if (IsKeyDown(KEY_S) || IsKeyDown(KEY_J))
{
- player_velocity.x = -forward_speed;
+ new_player_velocity.x = -forward_speed;
}
if (IsKeyDown(KEY_A) || IsKeyDown(KEY_H))
{
- player_rotation.x = -rotate_speed;
+ new_player_rotation.x = -rotate_speed;
}
else if (IsKeyDown(KEY_D) || IsKeyDown(KEY_L))
{
- player_rotation.x = rotate_speed;
+ new_player_rotation.x = rotate_speed;
}
if (IsKeyDown(KEY_T))
if (IsKeyDown(KEY_R))
{
- player_velocity.z += 0.005f;
+ new_player_velocity.z += 0.005f;
}
else if (IsKeyDown(KEY_F))
{
- player_velocity.z -= 0.005f;
+ new_player_velocity.z -= 0.005f;
}
if (IsKeyDown(KEY_SPACE) || IsKeyDown(KEY_LEFT_SHIFT) || IsKeyDown(KEY_RIGHT_SHIFT))
{
- //player_velocity.x *= 2.0f;
+ //new_player_velocity.x *= 2.0f;
+ }
+
+ /* Collision test */
+ /* Cast straight up */
+ player_collide_ray = (Ray){cam.position, vec3_up};
+ player_collision = GetRayCollisionMesh(player_collide_ray, barrow_model.meshes[0U], barrow_mat);
+ player_rotation = new_player_rotation;
+ if (player_collision.distance >= 0.3f)
+ {
+ player_velocity = new_player_velocity;
+ }
+ else
+ {
+ player_velocity.x *= -1.05;
}
switch(key)
coffin_rotation = 0.0f;
coffin_model = LoadModel("./assets/coffin_1.glb");
while(!IsModelReady(coffin_model)){}
- //coffin_model.materials[0] = *LoadMaterials("./assets/coffin_1.mtl", &coffin_material_count);
- //while(!IsMaterialReady(coffin_model.materials[0])){}
coffin_model.materials[0].shader = shader;
cam = (Camera3D){0};
SetTargetFPS(target_fps);
while (!WindowShouldClose())
{
+ player_collide_point = cam.position;
+ player_collide_point.y -= 1.0f;
process_inputs();
+ 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);
+ barrow_model.transform = barrow_mat;
+
SetShaderValue(shader, cam_position_shader_loc, &cam.position, SHADER_UNIFORM_VEC3);
SetShaderValue(shader, screen_dims_shader_loc, &fscreen_dims, SHADER_UNIFORM_VEC2);
SetShaderValue(shader, map_center_shader_loc, &map_center, SHADER_UNIFORM_VEC3);
BeginMode3D(cam);
BeginShaderMode(shader);
DrawModelEx(coffin_model, coffin_position, coffin_rotation_axis, coffin_rotation, coffin_scale, DARKGRAY);
- DrawModelEx(barrow_model, barrow_position, barrow_rotation_axis, barrow_rotation, barrow_scale, 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);
- //DrawSphere(map_center, 1.0f, RED);
+ DrawMesh(barrow_model.meshes[0], barrow_model.materials[0], barrow_mat);
+ DrawRay(player_collide_ray, WHITE);
EndShaderMode();
EndMode3D();
DrawTexturePro(barrow_texture, minimap_src, minimap_dest, (Vector2){0.0f, 0.0f}, 0.0f, RAYWHITE);
DrawFPS(fscreen_dims.x - 80, 10);
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("ray hit %d\nlength %f", player_collision.hit, player_collision.distance), 0, 256, 16, GREEN);
EndDrawing();
/* Decay forward velocity and rotation */