41 auto target_angles = spring_arm.
angles_spring.get_target_value();
42 target_angles.x() -= ctx.
mouse_tilt_factor *
static_cast<double>(
event.difference.y());
43 target_angles.y() -= ctx.
mouse_pan_factor *
static_cast<double>(
event.difference.x());
46 target_angles =
math::clamp(target_angles, spring_arm.min_angles, spring_arm.max_angles);
49 spring_arm.angles_spring.set_target_value(target_angles);
56 spring_arm.zoom -=
static_cast<double>(
event.difference.y()) /
static_cast<double>(ctx.
window->get_viewport_size().y());
59 spring_arm.zoom = std::min<double>(std::max<double>(spring_arm.zoom, 0.0), 1.0);
63 void load_camera_preset(::
game& ctx,std::uint8_t index)
68 void save_camera_preset(::
game& ctx,std::uint8_t index)
73 void step_camera_zoom(::
game& ctx,
double scale)
81 auto target_angles = spring_arm.
angles_spring.get_target_value();
84 target_angles.x() += (spring_arm.max_angles.x() - spring_arm.min_angles.x()) / ctx.
zoom_steps *
scale;
87 target_angles =
math::clamp(target_angles, spring_arm.min_angles, spring_arm.max_angles);
90 spring_arm.angles_spring.set_target_value(target_angles);
93 void update_relative_mouse_mode(::
game& ctx)
107 void load_or_save_camera_preset(::
game& ctx, std::uint8_t index)
111 save_camera_preset(ctx, index);
115 load_camera_preset(ctx, index);
127 [&](
const auto&
event)
129 if (ctx.camera_action_map.is_enabled())
131 handle_mouse_motion(ctx, event);
142 [&](
const auto&
event)
153 [&](
const auto&
event)
155 update_relative_mouse_mode(ctx);
163 [&](
const auto&
event)
165 update_relative_mouse_mode(ctx);
175 [&](
const auto&
event)
177 update_relative_mouse_mode(ctx);
204 [&](
const auto&
event)
206 update_relative_mouse_mode(ctx);
216 [&](
const auto&
event)
218 update_relative_mouse_mode(ctx);
226 [&](
const auto&
event)
228 update_relative_mouse_mode(ctx);
238 [&](
const auto&
event)
240 step_camera_zoom(ctx, static_cast<double>(ctx.camera_zoom_in_action.get_input_value()));
250 [&](
const auto&
event)
252 step_camera_zoom(ctx, -static_cast<double>(ctx.camera_zoom_out_action.get_input_value()));
262 [&](
const auto&
event)
264 if (ctx.active_camera_eid == entt::null)
278 [&](
const auto&
event)
280 if (ctx.active_camera_eid == entt::null)
296 [&](
const auto&
event)
298 if (ctx.active_camera_eid == entt::null)
312 [&](
const auto&
event)
314 if (ctx.active_camera_eid == entt::null)
330 [&](
const auto&
event)
332 if (ctx.active_camera_eid == entt::null)
346 [&](
const auto&
event)
348 if (ctx.active_camera_eid == entt::null)
364 [&](
const auto&
event)
366 if (ctx.active_camera_eid == entt::null)
380 [&](
const auto&
event)
382 if (ctx.active_camera_eid == entt::null)
398 [&](
const auto&
event)
400 if (ctx.active_camera_eid == entt::null || ctx.controlled_ant_eid == entt::null)
413 auto target_angles = spring_arm.angles_spring.get_target_value();
417 const auto camera_yaw_rotation =
math::angle_axis(target_angles.y(), {0.0, 1.0, 0.0});
418 const auto camera_pitchless_orientation =
math::normalize(spring_arm.up_rotation * camera_yaw_rotation);
422 const auto subject_forward = subject_rigid_body.get_transform().rotation *
math::fvec3{0, 0, 1};
425 const auto angular_difference =
math::signed_angle(camera_forward, subject_forward, camera_up);
428 target_angles.y() += angular_difference;
441 [&](
const auto&
event) {load_or_save_camera_preset(ctx, 0);}
448 [&](
const auto&
event) {load_or_save_camera_preset(ctx, 1);}
455 [&](
const auto&
event) {load_or_save_camera_preset(ctx, 2);}
462 [&](
const auto&
event) {load_or_save_camera_preset(ctx, 3);}
469 [&](
const auto&
event) {load_or_save_camera_preset(ctx, 4);}
476 [&](
const auto&
event) {load_or_save_camera_preset(ctx, 5);}
483 [&](
const auto&
event) {load_or_save_camera_preset(ctx, 6);}
490 [&](
const auto&
event) {load_or_save_camera_preset(ctx, 7);}
497 [&](
const auto&
event) {load_or_save_camera_preset(ctx, 8);}
504 [&](
const auto&
event) {load_or_save_camera_preset(ctx, 9);}
void setup_camera_controls(::game &ctx)
void disable_camera_controls(::game &ctx)
void enable_camera_controls(::game &ctx)
input::action camera_preset_3_action
input::action camera_preset_6_action
input::action camera_preset_8_action
input::action camera_preset_4_action
input::action camera_look_ahead_action
entity::id active_camera_eid
input::action camera_preset_9_action
std::vector< std::shared_ptr<::event::subscription > > event_subscriptions
input::action camera_preset_7_action
input::action camera_save_preset_action
double gamepad_tilt_factor
input::action_map camera_action_map
input::action camera_orbit_right_action
input::action camera_mouse_drag_action
input::action camera_preset_1_action
input::action camera_orbit_left_action
input::action camera_preset_5_action
std::shared_ptr< app::window > window
input::action camera_mouse_look_action
double gamepad_pan_factor
input::action camera_mouse_pick_action
input::action camera_preset_10_action
input::action camera_orbit_up_action
input::action camera_preset_2_action
entity::id controlled_ant_eid
input::action camera_orbit_down_action
std::unique_ptr< entity::registry > entity_registry
input::action camera_zoom_in_action
std::unique_ptr< app::input_manager > input_manager
input::action camera_mouse_zoom_action
input::action camera_zoom_out_action
Publish-subscribe messaging.
T signed_angle(const vector< T, 3 > &x, const vector< T, 3 > &y, const vector< T, 3 > &n)
Calculates the signed angle between two direction vectors about axis.
quaternion< T > normalize(const quaternion< T > &q)
Normalizes a quaternion.
quaternion< T > angle_axis(T angle, const vec3< T > &axis)
Creates a rotation from an angle and axis.
constexpr mat4< T > scale(const vec3< T > &v)
Constructs a scale matrix.
constexpr vector< T, N > clamp(const vector< T, N > &x, const vector< T, N > &min, const vector< T, N > &max)
Clamps the values of a vector's elements.
constexpr element_type & x() noexcept
Returns a reference to the first element.
constexpr element_type & y() noexcept
Returns a reference to the second element.
std::unique_ptr< physics::rigid_body > body
Attaches a camera to an entity using springs.
physics::numeric_spring< math::dvec3, double > angles_spring
Pitch, yaw, and roll angles spring.
math::dvec3 angular_velocities
Pitch, yaw, and roll velocities, in radians per second.