|
|
@ -23,10 +23,12 @@ |
|
|
|
#include "game/components/transform-component.hpp"
|
|
|
|
#include "scene/camera.hpp"
|
|
|
|
#include "animation/orbit-cam.hpp"
|
|
|
|
#include "animation/ease.hpp"
|
|
|
|
#include "geometry/mesh.hpp"
|
|
|
|
#include "geometry/intersection.hpp"
|
|
|
|
#include "math/math.hpp"
|
|
|
|
#include "game/entity-commands.hpp"
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
using namespace ecs; |
|
|
|
|
|
|
@ -51,12 +53,40 @@ tool_system::tool_system(entt::registry& registry): |
|
|
|
pick_spring.x0 = pick_spring.x1; |
|
|
|
pick_spring.v = {0.0f, 0.0f, 0.0f}; |
|
|
|
|
|
|
|
// Create descend animation
|
|
|
|
animation_channel<float>* channel = descend_animation.add_channel(0); |
|
|
|
descend_animation.set_interpolator(ease<float, double>::out_cubic); |
|
|
|
descend_animation.set_frame_callback |
|
|
|
( |
|
|
|
[this](int channel, const float& t) |
|
|
|
{ |
|
|
|
this->active_tool_distance = t; |
|
|
|
} |
|
|
|
); |
|
|
|
|
|
|
|
// Create descend animation
|
|
|
|
channel = ascend_animation.add_channel(0); |
|
|
|
ascend_animation.set_interpolator(ease<float, double>::out_cubic); |
|
|
|
ascend_animation.set_frame_callback |
|
|
|
( |
|
|
|
[this](int channel, const float& t) |
|
|
|
{ |
|
|
|
this->active_tool_distance = t; |
|
|
|
} |
|
|
|
); |
|
|
|
|
|
|
|
active_tool = entt::null; |
|
|
|
active_tool_distance = 0.0f; |
|
|
|
warp = true; |
|
|
|
tool_active = false; |
|
|
|
} |
|
|
|
|
|
|
|
void tool_system::update(double t, double dt) |
|
|
|
{ |
|
|
|
// Advance animations
|
|
|
|
ascend_animation.advance(dt); |
|
|
|
descend_animation.advance(dt); |
|
|
|
|
|
|
|
if (!camera) |
|
|
|
return; |
|
|
|
|
|
|
@ -116,11 +146,13 @@ void tool_system::update(double t, double dt) |
|
|
|
} |
|
|
|
|
|
|
|
// 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) * 1.0f)) * (math::pi<float> + math::half_pi<float>); |
|
|
|
hand_angle_spring.x1 = math::pi<float> - std::min<float>(0.5f, std::max<float>(-0.5f, ((mouse_position[0] / viewport[2]) - 0.5f) * 1.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( |
|
|
@ -136,10 +168,12 @@ void tool_system::update(double t, double dt) |
|
|
|
return; |
|
|
|
|
|
|
|
active_tool = entity; |
|
|
|
|
|
|
|
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.hover_distance, 0}; |
|
|
|
transform.local.translation = pick_spring.x0 + float3{0, tool_distance, 0}; |
|
|
|
} |
|
|
|
|
|
|
|
// Interpolate between left and right hand
|
|
|
@ -148,7 +182,7 @@ void tool_system::update(double t, double dt) |
|
|
|
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.hover_distance, 0}; |
|
|
|
transform.local.translation = pick_spring.x0 + solar_rotation * float3{0, tool_distance, 0}; |
|
|
|
|
|
|
|
transform.local.rotation = solar_rotation * hand_rotation; |
|
|
|
} |
|
|
@ -184,6 +218,8 @@ void tool_system::set_orbit_cam(const ::orbit_cam* orbit_cam) |
|
|
|
void tool_system::set_viewport(const float4& viewport) |
|
|
|
{ |
|
|
|
this->viewport = viewport; |
|
|
|
mouse_position.x = viewport[2] * 0.5f; |
|
|
|
mouse_position.y = viewport[3] * 0.5f; |
|
|
|
} |
|
|
|
|
|
|
|
void tool_system::set_pick(bool enabled) |
|
|
@ -198,6 +234,12 @@ void tool_system::set_sun_direction(const float3& direction) |
|
|
|
|
|
|
|
void tool_system::set_active_tool(entt::entity entity) |
|
|
|
{ |
|
|
|
if (active_tool == entity) |
|
|
|
return; |
|
|
|
|
|
|
|
const float descent_time = 0.1f; |
|
|
|
const float ascent_time = 0.1f; |
|
|
|
|
|
|
|
if (active_tool != entt::null) |
|
|
|
{ |
|
|
|
auto& tool = registry.get<tool_component>(active_tool); |
|
|
@ -211,11 +253,41 @@ void tool_system::set_active_tool(entt::entity entity) |
|
|
|
{ |
|
|
|
auto& tool = registry.get<tool_component>(active_tool); |
|
|
|
tool.active = true; |
|
|
|
|
|
|
|
active_tool_distance = tool.idle_distance; |
|
|
|
|
|
|
|
ec::warp_to(registry, active_tool, pick_spring.x0 + float3{0.0f, tool.idle_distance, 0.0f}); |
|
|
|
|
|
|
|
// Adjust descend and ascend animations
|
|
|
|
animation_channel<float>* channel = descend_animation.get_channel(0); |
|
|
|
channel->remove_keyframes(); |
|
|
|
channel->insert_keyframe({0.0, tool.idle_distance}); |
|
|
|
channel->insert_keyframe({descent_time, tool.active_distance}); |
|
|
|
|
|
|
|
channel = ascend_animation.get_channel(0); |
|
|
|
channel->remove_keyframes(); |
|
|
|
channel->insert_keyframe({0.0, tool.active_distance}); |
|
|
|
channel->insert_keyframe({ascent_time, tool.idle_distance}); |
|
|
|
} |
|
|
|
|
|
|
|
warp = true; |
|
|
|
} |
|
|
|
|
|
|
|
void tool_system::set_tool_active(bool active) |
|
|
|
{ |
|
|
|
tool_active = active; |
|
|
|
|
|
|
|
if (active) |
|
|
|
{ |
|
|
|
descend_animation.rewind(); |
|
|
|
descend_animation.play(); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
ascend_animation.rewind(); |
|
|
|
ascend_animation.play(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void tool_system::handle_event(const mouse_moved_event& event) |
|
|
|
{ |
|
|
|