Browse Source

Add marker tool and fix x-ray material sorting

master
C. J. Howard 4 years ago
parent
commit
6a5c459db3
7 changed files with 74 additions and 26 deletions
  1. +9
    -0
      src/game/bootloader.cpp
  2. +1
    -0
      src/game/game-context.hpp
  3. +3
    -0
      src/game/states/play-state.cpp
  4. +1
    -0
      src/game/systems/control-system.cpp
  5. +7
    -0
      src/game/systems/control-system.hpp
  6. +7
    -7
      src/game/systems/tool-system.cpp
  7. +46
    -19
      src/renderer/passes/material-pass.cpp

+ 9
- 0
src/game/bootloader.cpp View File

@ -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<mouse_moved_event>(ctx->control_system);
event_dispatcher->subscribe<mouse_moved_event>(ctx->camera_system);

+ 1
- 0
src/game/game-context.hpp View File

@ -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

+ 3
- 0
src/game/states/play-state.cpp View File

@ -80,6 +80,7 @@ void play_state_enter(game_context* ctx)
ecs::archetype* forceps_archetype = resource_manager->load<ecs::archetype>("forceps.ent");
ecs::archetype* lens_archetype = resource_manager->load<ecs::archetype>("lens.ent");
ecs::archetype* brush_archetype = resource_manager->load<ecs::archetype>("brush.ent");
ecs::archetype* marker_archetype = resource_manager->load<ecs::archetype>("marker.ent");
ecs::archetype* larva_archetype = resource_manager->load<ecs::archetype>("larva.ent");
ecs::archetype* pebble_archetype = resource_manager->load<ecs::archetype>("pebble.ent");
ecs::archetype* flashlight_archetype = resource_manager->load<ecs::archetype>("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);

+ 1
- 0
src/game/systems/control-system.cpp View File

@ -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

+ 7
- 0
src/game/systems/control-system.hpp View File

@ -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;

+ 7
- 7
src/game/systems/tool-system.cpp View File

@ -152,7 +152,8 @@ void tool_system::update(double t, double dt)
solve_numeric_spring<float, float>(hand_angle_spring, dt);
solve_numeric_spring<float3, float>(pick_spring, dt);
// Don't use spring for picking
pick_spring.x0 = pick_spring.x1;
// Move active tools to intersection location
registry.view<tool_component, transform_component>().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<float> hand_rotation = math::angle_axis(orbit_cam->get_azimuth() + hand_angle_spring.x0, float3{0, 1, 0});
math::quaternion<float> tilt_rotation = math::angle_axis(-orbit_cam->get_elevation(), float3{-1.0f, 0.0f, 0.0f});
if (tool.heliotropic)
{
math::quaternion<float> 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<float> rotation = hand_rotation * tilt_rotation;
transform.local.translation = pick_spring.x0 + rotation * float3{0, tool_distance, 0};
transform.local.rotation = rotation;
}
if (warp)

+ 46
- 19
src/renderer/passes/material-pass.cpp View File

@ -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());
}
}
}
}
}

Loading…
Cancel
Save