60 #include <engine/config.hpp>
128 light_probe = std::make_shared<scene::light_probe>();
145 auto light_rectangle_material = std::make_shared<render::material>(*light_rectangle_model->get_groups().front().material);
146 light_rectangle_emissive = std::static_pointer_cast<render::matvar_fvec3>(light_rectangle_material->get_variable(
"emissive"));
148 auto light_rectangle_static_mesh = std::make_shared<scene::static_mesh>(light_rectangle_model);
149 light_rectangle_static_mesh->set_material(0, light_rectangle_material);
170 auto worker_skeletal_mesh = std::make_unique<scene::skeletal_mesh>(worker_model);
176 worker_transform_component.
world = worker_transform_component.
local;
182 auto cocoon_static_mesh = std::make_shared<scene::static_mesh>(worker_phenome.
pupa->
cocoon_model);
190 component.
object->set_translation({-4.0f, 0.0f, 4.0f});
198 color_checker_scene_component.
object->set_translation({0, 0, 4});
204 auto larva_skeletal_mesh = std::make_shared<scene::skeletal_mesh>(worker_phenome.
larva->
model);
212 component.
object->set_translation({4.0f, 0.0f, 4.0f});
233 double time_scale = 60.0;
241 const auto& viewport_size =
ctx.
window->get_viewport_size();
242 const float aspect_ratio =
static_cast<float>(viewport_size[0]) /
static_cast<float>(viewport_size[1]);
245 create_third_person_camera_rig();
275 navmesh_bvh = std::make_unique<geom::bvh>(*navmesh);
288 destroy_third_person_camera_rig();
293 void nest_view_state::create_third_person_camera_rig()
298 third_person_camera_rig_camera.
layer_mask = 2;
304 set_third_person_camera_zoom(third_person_camera_zoom);
305 set_third_person_camera_rotation(third_person_camera_yaw, third_person_camera_pitch);
306 update_third_person_camera();
309 void nest_view_state::destroy_third_person_camera_rig()
314 void nest_view_state::set_third_person_camera_zoom(
double zoom)
317 third_person_camera_zoom = std::min<double>(std::max<double>(zoom, 0.0), 1.0);
324 third_person_camera_focal_plane_height =
ease<double, double>::out_sine(third_person_camera_far_focal_plane_height, third_person_camera_near_focal_plane_height, third_person_camera_zoom);
325 third_person_camera_focal_plane_width = third_person_camera_focal_plane_height *
ctx.
underground_camera->get_aspect_ratio();
328 third_person_camera_focal_distance = third_person_camera_focal_plane_height * 0.5 / std::tan(third_person_camera_vfov * 0.5);
333 void nest_view_state::set_third_person_camera_rotation(
double yaw,
double pitch)
335 third_person_camera_yaw = yaw;
336 third_person_camera_pitch =
std::min(math::half_pi<double>,
std::max(-math::half_pi<double>, pitch));
338 third_person_camera_yaw_rotation =
math::angle_axis(third_person_camera_yaw, {0.0, 1.0, 0.0});
339 third_person_camera_pitch_rotation =
math::angle_axis(third_person_camera_pitch, {-1.0, 0.0, 0.0});
340 third_person_camera_orientation =
math::normalize(third_person_camera_yaw_rotation * third_person_camera_pitch_rotation);
343 void nest_view_state::zoom_third_person_camera(
double zoom)
345 set_third_person_camera_zoom(third_person_camera_zoom + zoom);
348 void nest_view_state::translate_third_person_camera(
const math::dvec3& direction,
double magnitude)
351 magnitude *= third_person_camera_focal_plane_height * third_person_camera_speed;
354 const math::dvec3 rotated_direction = third_person_camera_yaw_rotation * direction;
356 third_person_camera_focal_point += rotated_direction * magnitude;
363 const double yaw = third_person_camera_yaw -
ctx.
mouse_pan_factor *
static_cast<double>(
event.difference.x());
364 const double pitch = third_person_camera_pitch +
ctx.
mouse_tilt_factor *
static_cast<double>(
event.difference.y());
366 set_third_person_camera_rotation(yaw, pitch);
373 if (!mouse_look && !mouse_grip && !mouse_zoom)
384 third_person_camera_focal_plane_width * (
static_cast<double>(-
event.difference.x()) / (viewport_size.
x() - 1.0)),
386 third_person_camera_focal_plane_height * (
static_cast<double>(-
event.difference.y()) / (viewport_size.
y() - 1.0)),
389 if (third_person_camera_pitch < 0.0)
391 translation.z() *= -1.0;
394 third_person_camera_focal_point += third_person_camera_yaw_rotation * translation;
399 rotate_third_person_camera(
event);
404 const double zoom_speed = -1.0 /
static_cast<double>(
ctx.
window->get_viewport_size().y());
405 zoom_third_person_camera(
static_cast<double>(
event.difference.y()) * zoom_speed);
408 update_third_person_camera();
411 void nest_view_state::update_third_person_camera()
419 const auto& viewport_size =
ctx.
window->get_viewport_size();
424 static_cast<float>(mouse_position.
x()) /
static_cast<float>(viewport_size.
x() - 1) * 2.0f - 1.0f,
425 (1.0f -
static_cast<float>(mouse_position.
y()) /
static_cast<float>(viewport_size.
y() - 1)) * 2.0f - 1.0f
431 return camera.pick(mouse_ndc);
434 void nest_view_state::setup_controls()
590 std::bind_front(&nest_view_state::handle_mouse_motion,
this)
595 action_subscriptions.emplace_back
599 [&](
const auto&
event)
602 update_third_person_camera();
608 action_subscriptions.emplace_back
612 [&](
const auto&
event)
631 action_subscriptions.emplace_back
635 [&](
const auto&
event)
654 action_subscriptions.emplace_back
658 [&](
const auto&
event)
660 zoom_third_person_camera(1.0 /
static_cast<double>(third_person_camera_zoom_step_count));
661 update_third_person_camera();
667 action_subscriptions.emplace_back
671 [&](
const auto&
event)
673 zoom_third_person_camera(-1.0 /
static_cast<double>(third_person_camera_zoom_step_count));
674 update_third_person_camera();
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.
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::rectangle_light > underground_rectangle_light
input::action move_up_action
::frame_scheduler frame_scheduler
input::action move_down_action
input::action move_right_action
std::shared_ptr< scene::camera > underground_camera
std::unique_ptr< screen_transition > fade_transition
std::shared_ptr< ecoregion > active_ecoregion
std::unique_ptr< render::material_pass > underground_material_pass
input::action move_left_action
std::unique_ptr< resource_manager > resource_manager
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< scene::collection > underground_scene
std::unique_ptr< app::input_manager > input_manager
std::unordered_map< hash::fnv1a32_t, entity::id > entities
Boundary representation (B-rep) of a mesh.
nest_view_state(::game &ctx)
virtual ~nest_view_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)
log_message< log_message_severity::trace, Args... > log_trace
Formats and logs a trace message.
log_message< log_message_severity::info, Args... > log_info
Formats and logs an info message.
Publish-subscribe messaging.
void generate_face_normals(brep_mesh &mesh)
Generates the math::fvec3 face attribute "normal" for a B-rep mesh.
void generate_vertex_normals(brep_mesh &mesh)
Generates the math::fvec3 vertex attribute "normal" for a B-rep mesh.
dvec< 2 > dvec2
n-dimensional vector of double-precision floating-point numbers.
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.
quaternion< T > rotation(const vec3< T > &from, const vec3< T > &to, T tolerance=T{1e-6})
Constructs a quaternion representing the minimum rotation from one direction to another direction.
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.
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.
float mean_mesosoma_length
Mean mesosoma length (Weber's length), in centimeters.
std::shared_ptr< render::model > model
3D model of the larva.
Complete set of ant phenes.
const ant_body_size_phene * body_size
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.
static T out_sine(const T &x, const T &y, S a)
Half of a line proceeding from an initial point.
static quaternion rotate_x(scalar_type angle)
Returns a quaternion representing a rotation about the x-axis.
constexpr element_type & x() noexcept
Returns a reference to the first element.
constexpr element_type & y() noexcept
Returns a reference to the second element.
static constexpr vector one() noexcept
Returns a vector of ones, where every element is equal to one.
std::shared_ptr< scene::object_base > object