diff --git a/src/game/bootloader.cpp b/src/game/bootloader.cpp index db55b69..7e72018 100644 --- a/src/game/bootloader.cpp +++ b/src/game/bootloader.cpp @@ -768,6 +768,7 @@ void setup_entities(game_context* ctx) ctx->flashlight_entity = ctx->ecs_registry->create(); ctx->forceps_entity = ctx->ecs_registry->create(); ctx->lens_entity = ctx->ecs_registry->create(); + ctx->marker_entity = ctx->ecs_registry->create(); ctx->focal_point_entity = ctx->ecs_registry->create(); } @@ -1011,6 +1012,7 @@ void setup_controls(game_context* ctx) ctx->input_event_router->add_mapping(key_mapping(ctx->control_system->get_equip_forceps_control(), nullptr, scancode::one)); ctx->input_event_router->add_mapping(key_mapping(ctx->control_system->get_equip_brush_control(), nullptr, scancode::two)); ctx->input_event_router->add_mapping(key_mapping(ctx->control_system->get_equip_lens_control(), nullptr, scancode::three)); + ctx->input_event_router->add_mapping(key_mapping(ctx->control_system->get_equip_marker_control(), nullptr, scancode::four)); ctx->input_event_router->add_mapping(mouse_button_mapping(ctx->control_system->get_use_tool_control(), nullptr, 1)); ctx->control_system->get_use_tool_control()->set_activated_callback @@ -1049,6 +1051,13 @@ void setup_controls(game_context* ctx) ctx->tool_system->set_active_tool(ctx->lens_entity); } ); + ctx->control_system->get_equip_marker_control()->set_activated_callback + ( + [ctx]() + { + ctx->tool_system->set_active_tool(ctx->marker_entity); + } + ); event_dispatcher->subscribe(ctx->control_system); event_dispatcher->subscribe(ctx->camera_system); diff --git a/src/game/game-context.hpp b/src/game/game-context.hpp index d64a560..de57f61 100644 --- a/src/game/game-context.hpp +++ b/src/game/game-context.hpp @@ -212,6 +212,7 @@ struct game_context entt::entity flashlight_entity; entt::entity forceps_entity; entt::entity lens_entity; + entt::entity marker_entity; entt::entity focal_point_entity; // Systems diff --git a/src/game/states/play-state.cpp b/src/game/states/play-state.cpp index 1a53ba5..a528853 100644 --- a/src/game/states/play-state.cpp +++ b/src/game/states/play-state.cpp @@ -80,6 +80,7 @@ void play_state_enter(game_context* ctx) ecs::archetype* forceps_archetype = resource_manager->load("forceps.ent"); ecs::archetype* lens_archetype = resource_manager->load("lens.ent"); ecs::archetype* brush_archetype = resource_manager->load("brush.ent"); + ecs::archetype* marker_archetype = resource_manager->load("marker.ent"); ecs::archetype* larva_archetype = resource_manager->load("larva.ent"); ecs::archetype* pebble_archetype = resource_manager->load("pebble.ent"); ecs::archetype* flashlight_archetype = resource_manager->load("flashlight.ent"); @@ -90,6 +91,7 @@ void play_state_enter(game_context* ctx) forceps_archetype->assign(ecs_registry, ctx->forceps_entity); lens_archetype->assign(ecs_registry, ctx->lens_entity); brush_archetype->assign(ecs_registry, ctx->brush_entity); + marker_archetype->assign(ecs_registry, ctx->marker_entity); // Create flashlight and light cone, set light cone parent to flashlight, and move both to underworld scene flashlight_archetype->assign(ecs_registry, ctx->flashlight_entity); @@ -115,6 +117,7 @@ void play_state_enter(game_context* ctx) ec::assign_render_layers(ecs_registry, ctx->forceps_entity, 0); ec::assign_render_layers(ecs_registry, ctx->brush_entity, 0); ec::assign_render_layers(ecs_registry, ctx->lens_entity, 0); + ec::assign_render_layers(ecs_registry, ctx->marker_entity, 0); // Activate lens tool ctx->tool_system->set_active_tool(ctx->lens_entity); diff --git a/src/game/systems/control-system.cpp b/src/game/systems/control-system.cpp index be0f27d..d86cab7 100644 --- a/src/game/systems/control-system.cpp +++ b/src/game/systems/control-system.cpp @@ -54,6 +54,7 @@ control_system::control_system(entt::registry& registry): control_set.add_control(&equip_lens_control); control_set.add_control(&equip_brush_control); control_set.add_control(&equip_forceps_control); + control_set.add_control(&equip_marker_control); control_set.add_control(&use_tool_control); // Set deadzone at 15% for all controls diff --git a/src/game/systems/control-system.hpp b/src/game/systems/control-system.hpp index 9023420..a5d3049 100644 --- a/src/game/systems/control-system.hpp +++ b/src/game/systems/control-system.hpp @@ -74,6 +74,7 @@ public: control* get_equip_lens_control(); control* get_equip_brush_control(); control* get_equip_forceps_control(); + control* get_equip_marker_control(); control* get_use_tool_control(); private: @@ -99,6 +100,7 @@ private: control equip_lens_control; control equip_brush_control; control equip_forceps_control; + control equip_marker_control; control use_tool_control; float zoom_speed; @@ -229,6 +231,11 @@ inline control* control_system::get_equip_forceps_control() return &equip_forceps_control; } +inline control* control_system::get_equip_marker_control() +{ + return &equip_marker_control; +} + inline control* control_system::get_use_tool_control() { return &use_tool_control; diff --git a/src/game/systems/tool-system.cpp b/src/game/systems/tool-system.cpp index 1ebdbc9..66bd01b 100644 --- a/src/game/systems/tool-system.cpp +++ b/src/game/systems/tool-system.cpp @@ -152,7 +152,8 @@ void tool_system::update(double t, double dt) solve_numeric_spring(hand_angle_spring, dt); solve_numeric_spring(pick_spring, dt); - + // Don't use spring for picking + pick_spring.x0 = pick_spring.x1; // Move active tools to intersection location registry.view().each( @@ -171,24 +172,23 @@ void tool_system::update(double t, double dt) float tool_distance = active_tool_distance;//(tool_active) ? tool.active_distance : tool.idle_distance; - if (intersection) - { - transform.local.translation = pick_spring.x0 + float3{0, tool_distance, 0}; - } // Interpolate between left and right hand math::quaternion hand_rotation = math::angle_axis(orbit_cam->get_azimuth() + hand_angle_spring.x0, float3{0, 1, 0}); + math::quaternion tilt_rotation = math::angle_axis(-orbit_cam->get_elevation(), float3{-1.0f, 0.0f, 0.0f}); + if (tool.heliotropic) { math::quaternion solar_rotation = math::rotation(float3{0, -1, 0}, sun_direction); transform.local.translation = pick_spring.x0 + solar_rotation * float3{0, tool_distance, 0}; - transform.local.rotation = solar_rotation * hand_rotation; } else { - transform.local.rotation = hand_rotation; + math::quaternion rotation = hand_rotation * tilt_rotation; + transform.local.translation = pick_spring.x0 + rotation * float3{0, tool_distance, 0}; + transform.local.rotation = rotation; } if (warp) diff --git a/src/renderer/passes/material-pass.cpp b/src/renderer/passes/material-pass.cpp index bad3980..ca5d77e 100644 --- a/src/renderer/passes/material-pass.cpp +++ b/src/renderer/passes/material-pass.cpp @@ -513,51 +513,78 @@ bool operation_compare(const render_operation& a, const render_operation& b) else if (!b.material) return true; - // Determine transparency - bool transparent_a = a.material->get_flags() & MATERIAL_FLAG_TRANSLUCENT; - bool transparent_b = b.material->get_flags() & MATERIAL_FLAG_TRANSLUCENT; + bool xray_a = a.material->get_flags() & MATERIAL_FLAG_X_RAY; + bool xray_b = b.material->get_flags() & MATERIAL_FLAG_X_RAY; - if (transparent_a) + if (xray_a) { - if (transparent_b) + if (xray_b) { - // A and B are both transparent, render back to front + // A and B are both xray, render back to front return (a.depth >= b.depth); } else { - // A is transparent, B is opaque. Render B first + // A is xray, B is not. Render B first return false; } } else { - if (transparent_b) + if (xray_b) { - // A is opaque, B is transparent. Render A first + // A is opaque, B is xray. Render A first return true; } else { - // A and B are both opaque - if (a.material->get_shader_program() == b.material->get_shader_program()) + // Determine transparency + bool transparent_a = a.material->get_flags() & MATERIAL_FLAG_TRANSLUCENT; + bool transparent_b = b.material->get_flags() & MATERIAL_FLAG_TRANSLUCENT; + + if (transparent_a) { - // A and B have the same shader - if (a.vertex_array == b.vertex_array) + if (transparent_b) { - // A and B have the same VAO, render front to back - return (a.depth < b.depth); + // A and B are both transparent, render back to front + return (a.depth >= b.depth); } else { - // Sort by VAO - return (a.vertex_array < b.vertex_array); + // A is transparent, B is opaque. Render B first + return false; } } else { - // A and B are both opaque and have different shaders, sort by shader - return (a.material->get_shader_program() < b.material->get_shader_program()); + if (transparent_b) + { + // A is opaque, B is transparent. Render A first + return true; + } + else + { + // A and B are both opaque + if (a.material->get_shader_program() == b.material->get_shader_program()) + { + // A and B have the same shader + if (a.vertex_array == b.vertex_array) + { + // A and B have the same VAO, render front to back + return (a.depth < b.depth); + } + else + { + // Sort by VAO + return (a.vertex_array < b.vertex_array); + } + } + else + { + // A and B are both opaque and have different shaders, sort by shader + return (a.material->get_shader_program() < b.material->get_shader_program()); + } + } } } }