59 #include <engine/config.hpp>
121 auto floor_body = std::make_unique<physics::rigid_body>();
122 auto floor_collider = std::make_shared<physics::plane_collider>(
math::fvec3{0.0f, 1.0f, 0.0f});
123 floor_collider->set_layer_mask(0b11);
124 floor_collider->set_material(std::make_shared<physics::collider_material>(1.0f, 0.5f, 1.0f));
125 floor_body->set_mass(0.0f);
126 floor_body->set_inertia(0.0f);
127 floor_body->set_collider(std::move(floor_collider));
133 auto worker_skeletal_mesh = std::make_unique<scene::skeletal_mesh>(worker_model);
139 worker_transform_component.
world = worker_transform_component.
local;
145 auto worker_collider = std::make_shared<physics::box_collider>(
math::fvec3{-1.0f, -1.0f, -1.0f},
math::fvec3{1.0f, 1.0f, 1.0f});
147 worker_collider->set_material(std::make_shared<physics::collider_material>(0.4f, 0.1f, 0.2f));
149 auto worker_body = std::make_unique<physics::rigid_body>();
151 worker_body->set_previous_position(worker_transform_component.
local.
translation);
152 worker_body->set_mass(0.1f);
153 worker_body->set_inertia(0.05f);
154 worker_body->set_angular_damping(0.5f);
155 worker_body->set_collider(std::move(worker_collider));
165 auto larva_skeletal_mesh = std::make_shared<scene::skeletal_mesh>(worker_phenome.
larva->
model);
167 const auto& larva_skeleton = larva_skeletal_mesh->get_model()->get_skeleton();
169 auto larva_ik_rig = std::make_shared<ik_rig>(*larva_skeletal_mesh);
171 auto no_twist_constraint = std::make_shared<swing_twist_ik_constraint>();
172 no_twist_constraint->set_twist_limit(0.0f, 0.0f);
177 for (std::size_t i = 0; i < larva_skeleton.get_bone_count(); ++i)
179 larva_ik_rig->set_constraint(
static_cast<bone_index_type>(i), no_twist_constraint);
182 const auto larva_ik_root_bone_index = *larva_skeleton.get_bone_index(
"abdomen3");
183 const auto larva_ik_effector_bone_index = *larva_skeleton.get_bone_index(
"head");
185 const auto& larva_head_absolute_transform = larva_skeletal_mesh->get_pose().get_absolute_transform(larva_ik_effector_bone_index);
186 const auto& larva_head_relative_transform = larva_skeletal_mesh->get_pose().get_relative_transform(larva_ik_effector_bone_index);
188 larva_ik_solver = std::make_shared<ccd_ik_solver>(*larva_ik_rig, larva_ik_root_bone_index, larva_ik_effector_bone_index);
189 larva_ik_solver->set_effector_position(larva_head_relative_transform *
math::fvec3{0.0f, 0.0f, -0.0f});
190 larva_ik_solver->set_goal_center(larva_head_absolute_transform.translation +
math::fvec3{0.2f, 0.2f, 0.5f});
194 larva_ik_rig->add_solver(larva_ik_solver);
207 double time_scale = 60.0;
219 const auto& viewport_size =
ctx.
window->get_viewport_size();
220 const float aspect_ratio =
static_cast<float>(viewport_size[0]) /
static_cast<float>(viewport_size[1]);
223 first_person_camera_rig_translation_spring_angular_frequency =
physics::s_to_rads(0.125f);
224 first_person_camera_rig_rotation_spring_angular_frequency =
physics::s_to_rads(0.125f);
226 first_person_camera_rig_min_elevation = 0.25f;
227 first_person_camera_rig_max_elevation = 150.0f;
230 first_person_camera_near_speed = 5.0f;
231 first_person_camera_far_speed = 140.0f;
232 first_person_camera_rig_pedestal_speed = 2.0f;
233 first_person_camera_rig_pedestal = 0.0f;
236 create_first_person_camera_rig();
239 satisfy_first_person_camera_rig_constraints();
292 sky_probe = std::make_shared<scene::light_probe>();
293 const std::uint32_t sky_probe_face_size = 128;
294 const auto sky_probe_mip_levels =
static_cast<std::uint32_t
>(std::bit_width(sky_probe_face_size));
295 sky_probe->set_luminance_texture
297 std::make_shared<gl::texture_cube>
299 std::make_shared<gl::image_view_cube>
301 std::make_shared<gl::image_cube>
311 std::make_shared<gl::sampler>
333 component.
object->set_translation({0.0f, 10.0f, 0.0f});
363 destroy_first_person_camera_rig();
368 void nest_selection_state::create_first_person_camera_rig()
374 first_person_camera_rig_transform.
world = first_person_camera_rig_transform.
local;
380 auto first_person_camera_rig_body = std::make_unique<physics::rigid_body>();
381 first_person_camera_rig_body->set_position({0, 10, 0});
382 first_person_camera_rig_body->set_mass(1.0f);
383 first_person_camera_rig_body->set_linear_damping(10.0f);
384 first_person_camera_rig_body->set_angular_damping(0.5f);
385 auto first_person_camera_rig_collider = std::make_shared<physics::sphere_collider>(1.0f);
386 auto camera_collider_material = std::make_shared<physics::collider_material>(0.0f, 0.0f, 0.0f);
390 first_person_camera_rig_collider->set_layer_mask(0b10);
391 first_person_camera_rig_collider->set_material(std::move(camera_collider_material));
392 first_person_camera_rig_body->set_collider(std::move(first_person_camera_rig_collider));
406 void nest_selection_state::destroy_first_person_camera_rig()
411 void nest_selection_state::set_first_person_camera_rig_pedestal(
float pedestal)
416 void nest_selection_state::move_first_person_camera_rig(
const math::fvec2& direction,
float factor)
421 void nest_selection_state::satisfy_first_person_camera_rig_constraints()
426 void nest_selection_state::setup_controls()
429 constexpr
float movement_speed = 200.0f;
431 auto move_first_person_camera_rig = [&](
const math::fvec2& direction,
float speed)
439 const math::fvec3 force = rotated_direction * speed;
443 movement_direction = direction;
444 this->movement_speed = speed;
448 first_person_camera_rig_eid,
451 component.force = force;
456 auto stop_first_person_camera_rig = [&]()
462 first_person_camera_rig_eid,
465 component.force = {0.0f, 0.0f, 0.0f};
473 [&, move_first_person_camera_rig](
const auto&
event)
477 const double sensitivity = 1.0 /
static_cast<double>(
ctx.
window->get_viewport_size().x());
495 const float sensitivity = 8.0f /
static_cast<float>(
ctx.
window->get_viewport_size().y());
504 first_person_camera_yaw -=
ctx.
mouse_pan_factor *
static_cast<double>(
event.difference.x());
506 first_person_camera_pitch =
std::min(math::half_pi<double>,
std::max(-math::half_pi<double>, first_person_camera_pitch));
514 first_person_camera_rig_eid,
517 component.object->set_rotation(first_person_camera_orientation);
523 first_person_camera_rig_eid,
526 component.body->set_previous_orientation(first_person_camera_orientation);
527 component.body->set_orientation(first_person_camera_orientation);
533 first_person_camera_rig_eid,
536 component.local.rotation = first_person_camera_orientation;
537 component.world.rotation = first_person_camera_orientation;
543 move_first_person_camera_rig(movement_direction, this->movement_speed);
549 action_subscriptions.emplace_back
553 [&, move_first_person_camera_rig](
const auto&
event)
555 move_first_person_camera_rig({0.0f, -1.0f}, movement_speed *
event.input_value);
559 action_subscriptions.emplace_back
563 [&, stop_first_person_camera_rig](
const auto&
event)
565 stop_first_person_camera_rig();
571 action_subscriptions.emplace_back
575 [&, move_first_person_camera_rig](
const auto&
event)
577 move_first_person_camera_rig({0, 1}, movement_speed *
event.input_value);
581 action_subscriptions.emplace_back
585 [&, stop_first_person_camera_rig](
const auto&
event)
587 stop_first_person_camera_rig();
593 action_subscriptions.emplace_back
597 [&, move_first_person_camera_rig](
const auto&
event)
599 move_first_person_camera_rig({-1, 0}, movement_speed *
event.input_value);
603 action_subscriptions.emplace_back
607 [&, stop_first_person_camera_rig](
const auto&
event)
609 stop_first_person_camera_rig();
615 action_subscriptions.emplace_back
619 [&, move_first_person_camera_rig](
const auto&
event)
621 move_first_person_camera_rig({1, 0}, movement_speed *
event.input_value);
625 action_subscriptions.emplace_back
629 [&, stop_first_person_camera_rig](
const auto&
event)
631 stop_first_person_camera_rig();
637 action_subscriptions.emplace_back
641 [&](
const auto&
event)
645 first_person_camera_rig_eid,
648 component.body->apply_central_impulse({0, 5.0f, 0});
656 action_subscriptions.emplace_back
660 [&](
const auto&
event)
664 first_person_camera_rig_eid,
667 component.
body->apply_central_impulse({0, -5.0f, 0});
772 void nest_selection_state::enable_controls()
777 void nest_selection_state::disable_controls()
std::unique_ptr< ant_genome > ant_cladogenesis(const ant_gene_pool &pool, URBG &urbg)
Generates an ant genome from a gene pool.
std::unique_ptr< render::model > ant_morphogenesis(const ant_phenome &phenome)
Generates a 3D model of an ant given its phenome.
std::uint16_t bone_index_type
Bone index type.
void refresh() noexcept
Resets the accumulated time (at) and frame timer, but not the elapsed fixed-rate update time.
Abstract base class for game states.
std::unique_ptr< scene::collection > surface_scene
input::action move_up_action
::frame_scheduler frame_scheduler
input::action move_down_action
input::action move_right_action
std::unique_ptr< screen_transition > fade_transition
std::shared_ptr< scene::camera > surface_camera
std::shared_ptr< ecoregion > active_ecoregion
input::action move_left_action
input::action move_forward_action
std::unique_ptr<::astronomy_system > astronomy_system
std::unique_ptr< resource_manager > resource_manager
std::unique_ptr< render::sky_pass > sky_pass
std::shared_ptr< app::window > window
std::queue< std::function< void()> > function_queue
std::shared_ptr< render::matvar_fvec3 > fade_transition_color
std::unique_ptr< entity::registry > entity_registry
input::action move_back_action
std::unique_ptr< app::input_manager > input_manager
std::unordered_map< hash::fnv1a32_t, entity::id > entities
nest_selection_state(::game &ctx)
virtual ~nest_selection_state()
void transition(float duration, bool reverse, animation< float >::interpolator_type interpolator, bool hide=true, const std::function< void()> &callback=nullptr)
void enable_game_controls(::game &ctx)
void disable_game_controls(::game &ctx)
void warp_to(entity::registry ®istry, entity::id eid, const math::fvec3 &position)
log_message< log_message_severity::trace, Args... > log_trace
Formats and logs a trace message.
Publish-subscribe messaging.
@ clamp_to_edge
Clamp to edge wrap mode.
@ linear
Linear filtering.
@ linear
Linear filtering.
quat< float > fquat
Quaternion with single-precision floating-point scalars.
T vertical_fov(T h, T r)
Calculates a vertical FoV given a horizontal FoV and aspect ratio.
constexpr vector< T, N > max(const vector< T, N > &x, const vector< T, N > &y)
Returns a vector containing the maximum elements of two vectors.
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 T radians(T degrees) noexcept
Converts an angle given in degrees to radians.
constexpr vector< T, N > min(const vector< T, N > &x, const vector< T, N > &y)
Returns a vector containing the minimum elements of two vectors.
T from_settings(T n, T t, T s)
Exposure value from exposure settings.
@ minimum
Coefficient of restitution is calculated as min(a, b).
@ minimum
Coefficient of friction is calculated as min(a, b).
constexpr T s_to_rads(T t) noexcept
Converts oscillation period to angular frequency.
void cosmogenesis(::game &ctx)
Creates the cosmos.
void create_observer(::game &ctx)
Creates the observer.
void enter_ecoregion(::game &ctx, const ecoregion &ecoregion)
Enters a ecoregion.
void set_time_scale(::game &ctx, double scale)
Sets rate at which time passes.
void set_time(::game &ctx, double t)
Sets the current time.
std::shared_ptr< render::model > model
3D model of the larva.
Complete set of ant phenes.
const ant_pupa_phene * pupa
const ant_larva_phene * larva
std::shared_ptr< render::model > cocoon_model
3D model of the cocoon, if present.
Container for templated easing functions.
entity::id create(entity::registry ®istry) const
Creates an instance of this archetype.
Quaternion composed of a real scalar part and imaginary vector part.
std::unique_ptr< physics::rigid_body > body
std::shared_ptr< scene::object_base > object
Winged aerial locomotion.