Browse Source

Align lens according to sun position and mouse position

master
C. J. Howard 3 years ago
parent
commit
eefbc0c301
4 changed files with 60 additions and 3 deletions
  1. +14
    -1
      src/game/states/play-state.cpp
  2. +39
    -2
      src/game/systems/tool-system.cpp
  3. +6
    -0
      src/game/systems/tool-system.hpp
  4. +1
    -0
      src/renderer/passes/outline-pass.cpp

+ 14
- 1
src/game/states/play-state.cpp View File

@ -44,9 +44,11 @@
#include "scene/model-instance.hpp"
#include "scene/scene.hpp"
#include "scene/camera.hpp"
#include "scene/directional-light.hpp"
#include "game/systems/control-system.hpp"
#include "game/systems/camera-system.hpp"
#include "game/systems/render-system.hpp"
#include "game/systems/tool-system.hpp"
#include "utility/fundamental-types.hpp"
#include "utility/gamma.hpp"
@ -64,6 +66,8 @@ void play_state_enter(game_context* ctx)
sky_pass->set_zenith_color(to_linear(float3{7.0f, 134.0f, 206.0f} / 255.0f));
//sky_pass->set_horizon_color(float3{0.002f, 0.158f, 0.250f});
//sky_pass->set_zenith_color(float3{0.002f, 0.158f, 0.250f});
ctx->tool_system->set_sun_direction(ctx->sun_direct->get_direction());
resource_manager* resource_manager = ctx->resource_manager;
entt::registry& ecs_registry = *ctx->ecs_registry;
@ -80,6 +84,7 @@ void play_state_enter(game_context* ctx)
ecs::archetype* pebble_archetype = resource_manager->load<ecs::archetype>("pebble.ent");
ecs::archetype* flashlight_archetype = resource_manager->load<ecs::archetype>("flashlight.ent");
ecs::archetype* flashlight_light_cone_archetype = resource_manager->load<ecs::archetype>("flashlight-light-cone.ent");
ecs::archetype* lens_light_cone_archetype = resource_manager->load<ecs::archetype>("lens-light-cone.ent");
// Create tools
forceps_archetype->assign(ecs_registry, ctx->forceps_entity);
@ -100,9 +105,17 @@ void play_state_enter(game_context* ctx)
lens_model_instance->set_culling_mask(&ctx->no_cull);
}
// Activate brush tools
// Create lens light cone and bind to lens
auto lens_light_cone = lens_light_cone_archetype->create(ecs_registry);
ec::bind_transform(ecs_registry, lens_light_cone, ctx->lens_entity);
// Activate lens tool
auto& active_tool_component = ecs_registry.get<ecs::tool_component>(ctx->lens_entity);
active_tool_component.active = true;
// Hide inactive tools
ec::assign_render_layers(ecs_registry, ctx->forceps_entity, 0);
ec::assign_render_layers(ecs_registry, ctx->brush_entity, 0);
// Create ant-hill
auto ant_hill_entity = ant_hill_archetype->create(ecs_registry);

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

@ -37,7 +37,19 @@ tool_system::tool_system(entt::registry& registry):
mouse_position{0, 0},
pick_enabled(true),
was_pick_enabled(pick_enabled)
{}
{
hand_angle_spring.z = 1.0f;
hand_angle_spring.w = hz_to_rads(8.0f);
hand_angle_spring.x1 = math::pi<float>;
hand_angle_spring.x0 = hand_angle_spring.x1;
hand_angle_spring.v = 0.0f;
pick_spring.z = 1.0f;
pick_spring.w = hz_to_rads(30.0f);
pick_spring.x1 = {0.0f, 0.0f, 0.0f};
pick_spring.x0 = pick_spring.x1;
pick_spring.v = {0.0f, 0.0f, 0.0f};
}
void tool_system::update(double t, double dt)
{
@ -79,6 +91,7 @@ void tool_system::update(double t, double dt)
{
a = mesh_result->t;
pick = picking_ray.extrapolate(a);
pick_spring.x1 = pick;
}
}
});
@ -97,6 +110,13 @@ void tool_system::update(double t, double dt)
if (math::dot(math::cross(camera_planar_direction, pick_planar_direction), float3{0, 1, 0}) < 0.0f)
pick_angle = -pick_angle;
}
// Determine target hand angle
hand_angle_spring.x1 = math::pi<float> - std::min<float>(0.5f, std::max<float>(-0.5f, ((mouse_position[0] / viewport[2]) - 0.5f) * 3.0f)) * math::pi<float>;
// Solve springs
solve_numeric_spring<float, float>(hand_angle_spring, dt);
solve_numeric_spring<float3, float>(pick_spring, dt);
// Move active tools to intersection location
registry.view<tool_component, transform_component>().each(
@ -113,7 +133,19 @@ void tool_system::update(double t, double dt)
if (intersection)
{
transform.transform.translation = pick + float3{0, tool.hover_distance, 0};
transform.transform.translation = pick_spring.x0 + float3{0, tool.hover_distance, 0};
}
if (tool.heliotropic)
{
math::quaternion<float> solar_rotation = math::rotation(float3{0, -1, 0}, sun_direction);
transform.transform.translation = pick_spring.x0 + solar_rotation * float3{0, tool.hover_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});
transform.transform.rotation = solar_rotation * hand_rotation;
}
//math::quaternion<float> rotation = math::angle_axis(orbit_cam->get_azimuth() + pick_angle, float3{0, 1, 0});
@ -143,6 +175,11 @@ void tool_system::set_pick(bool enabled)
pick_enabled = enabled;
}
void tool_system::set_sun_direction(const float3& direction)
{
sun_direction = direction;
}
void tool_system::handle_event(const mouse_moved_event& event)
{
if (pick_enabled && was_pick_enabled)

+ 6
- 0
src/game/systems/tool-system.hpp View File

@ -25,6 +25,7 @@
#include "event/input-events.hpp"
#include "event/window-events.hpp"
#include "utility/fundamental-types.hpp"
#include "animation/spring.hpp"
class camera;
class orbit_cam;
@ -42,6 +43,7 @@ public:
void set_orbit_cam(const orbit_cam* camera);
void set_viewport(const float4& viewport);
void set_pick(bool enabled);
void set_sun_direction(const float3& direction);
private:
virtual void handle_event(const mouse_moved_event& event);
@ -53,6 +55,10 @@ private:
float2 mouse_position;
bool was_pick_enabled;
bool pick_enabled;
float3 sun_direction;
numeric_spring<float, float> hand_angle_spring;
numeric_spring<float3, float> pick_spring;
};
#endif // ANTKEEPER_TOOL_SYSTEM_HPP

+ 1
- 0
src/renderer/passes/outline-pass.cpp View File

@ -64,6 +64,7 @@ void outline_pass::render(render_context* context) const
glDisable(GL_BLEND);
}
glDisable(GL_DEPTH_TEST);
glDisable(GL_CULL_FACE);
glCullFace(GL_BACK);

Loading…
Cancel
Save