diff --git a/src/animation/camera-rig.cpp b/src/animation/camera-rig.cpp deleted file mode 100644 index dc05789..0000000 --- a/src/animation/camera-rig.cpp +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (C) 2021 Christopher J. Howard - * - * This file is part of Antkeeper source code. - * - * Antkeeper source code is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Antkeeper source code is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Antkeeper source code. If not, see . - */ - -#include "animation/camera-rig.hpp" -#include "math/constants.hpp" -#include "configuration.hpp" -#include -#include - -camera_rig::camera_rig(): - camera(nullptr), - transform(math::identity_transform), - forward(global_forward), - right(global_right), - up(global_up) -{} - -void camera_rig::attach(scene::camera* camera) -{ - this->camera = camera; - if (camera != nullptr) - { - camera->set_transform(transform); - } -} - -void camera_rig::detach() -{ - camera = nullptr; -} - -void camera_rig::update_transform(const transform_type& transform) -{ - this->transform = transform; - - // Calculate orthonormal basis - forward = transform.rotation * global_forward; - up = transform.rotation * global_up; - right = transform.rotation * global_right; - - if (camera != nullptr) - { - camera->set_transform(transform); - } -} - -void camera_rig::update_projection(float fov, float aspect_ratio, float clip_near, float clip_far) -{ - if (camera != nullptr) - { - camera->set_perspective(fov, aspect_ratio, clip_near, clip_far); - } -} - -void camera_rig::update_projection(float clip_left, float clip_right, float clip_bottom, float clip_top, float clip_near, float clip_far) -{ - if (camera != nullptr) - { - camera->set_orthographic(clip_left, clip_right, clip_bottom, clip_top, clip_near, clip_far); - } -} diff --git a/src/animation/camera-rig.hpp b/src/animation/camera-rig.hpp deleted file mode 100644 index 09b248e..0000000 --- a/src/animation/camera-rig.hpp +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright (C) 2021 Christopher J. Howard - * - * This file is part of Antkeeper source code. - * - * Antkeeper source code is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Antkeeper source code is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Antkeeper source code. If not, see . - */ - -#ifndef ANTKEEPER_CAMERA_RIG_HPP -#define ANTKEEPER_CAMERA_RIG_HPP - -#include "math/quaternion-type.hpp" -#include "math/transform-type.hpp" -#include "scene/camera.hpp" -#include "utility/fundamental-types.hpp" - - -/** - * Abstract base class for camera rigs which control the movement of cameras. - */ -class camera_rig -{ -public: - typedef math::quaternion quaternion_type; - typedef math::transform transform_type; - - camera_rig(); - - /** - * Updates the rig. - * - * @param dt Delta time. - */ - virtual void update(float dt) = 0; - - /** - * Attaches a camera to the rig. - * - * @param camera Camera to attach. - */ - void attach(scene::camera* camera); - - /** - * Detaches the camera from the rig. - */ - void detach(); - - - - /** - * Returns the attached camera. - */ - const scene::camera* get_camera() const; - - const float3& get_translation() const; - const quaternion_type& get_rotation() const; - const float3& get_forward() const; - const float3& get_right() const; - const float3& get_up() const; - -protected: - /** - * Updates the transform of the camera - */ - void update_transform(const transform_type& transform); - - void update_projection(float fov, float aspect_ratio, float clip_near, float clip_far); - void update_projection(float clip_left, float clip_right, float clip_bottom, float clip_top, float clip_near, float clip_far); - -private: - scene::camera* camera; - transform_type transform; - float3 forward; - float3 right; - float3 up; -}; - -inline const scene::camera* camera_rig::get_camera() const -{ - return camera; -} - -inline const float3& camera_rig::get_translation() const -{ - return transform.translation; -} - -inline const typename camera_rig::quaternion_type& camera_rig::get_rotation() const -{ - return transform.rotation; -} - -inline const float3& camera_rig::get_forward() const -{ - return forward; -} - -inline const float3& camera_rig::get_right() const -{ - return right; -} - -inline const float3& camera_rig::get_up() const -{ - return up; -} - -#endif // ANTKEEPER_CAMERA_RIG_HPP - diff --git a/src/animation/orbit-cam.cpp b/src/animation/orbit-cam.cpp deleted file mode 100644 index 729b4f2..0000000 --- a/src/animation/orbit-cam.cpp +++ /dev/null @@ -1,224 +0,0 @@ -/* - * Copyright (C) 2021 Christopher J. Howard - * - * This file is part of Antkeeper source code. - * - * Antkeeper source code is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Antkeeper source code is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Antkeeper source code. If not, see . - */ - -#include "animation/orbit-cam.hpp" -#include "scene/camera.hpp" -#include "math/math.hpp" -#include -#include -#include -#include - -orbit_cam::orbit_cam(): - azimuth_limits({-std::numeric_limits::infinity(), std::numeric_limits::infinity()}), - elevation_limits({-std::numeric_limits::infinity(), std::numeric_limits::infinity()}), - focal_distance_limits({-std::numeric_limits::infinity(), std::numeric_limits::infinity()}), - fov_limits({-std::numeric_limits::infinity(), std::numeric_limits::infinity()}), - clip_near_limits({-std::numeric_limits::infinity(), std::numeric_limits::infinity()}), - clip_far_limits({-std::numeric_limits::infinity(), std::numeric_limits::infinity()}) -{ - // Make all springs critically-damped - focal_point_spring.z = 1.0f; - azimuth_spring.z = 1.0f; - elevation_spring.z = 1.0f; - zoom_spring.z = 1.0f; - - // Init spring oscillation frequencies to 1 rad/s - focal_point_spring.w = math::two_pi; - azimuth_spring.w = math::two_pi; - elevation_spring.w = math::two_pi; - zoom_spring.w = math::two_pi; - - // Zero spring values and velocities - focal_point_spring.x1 = {0.0f, 0.0f, 0.0f}; - azimuth_spring.x1 = 0.0f; - elevation_spring.x1 = 0.0f; - zoom_spring.x1 = 0.0f; - reset_springs(); -} - -orbit_cam::~orbit_cam() -{} - -void orbit_cam::update(float dt) -{ - if (!get_camera()) - { - return; - } - - // Solve springs - solve_numeric_spring(focal_point_spring, dt); - solve_numeric_spring(azimuth_spring, dt); - solve_numeric_spring(elevation_spring, dt); - solve_numeric_spring(zoom_spring, dt); - - // Calculate zoom-dependent variables - float focal_distance = math::log_lerp(focal_distance_limits[1], focal_distance_limits[0], zoom_spring.x0); - float fov = math::log_lerp(fov_limits[1], fov_limits[0], zoom_spring.x0); - float clip_near = math::log_lerp(clip_near_limits[1], clip_near_limits[0], zoom_spring.x0); - float clip_far = math::log_lerp(clip_far_limits[1], clip_far_limits[0], zoom_spring.x0); - - // Calculate camera transform - transform_type transform = math::identity_transform; - - // Determine rotation - azimuth_rotation = math::angle_axis(azimuth_spring.x0, float3{0.0f, 1.0f, 0.0f}); - elevation_rotation = math::angle_axis(elevation_spring.x0, float3{-1.0f, 0.0f, 0.0f}); - transform.rotation = math::normalize(azimuth_rotation * elevation_rotation); - - // Determine translation - transform.translation = focal_point_spring.x0 + transform.rotation * float3{0.0f, 0.0f, focal_distance}; - - // Update camera transform - update_transform(transform); - - // Update camera projection - update_projection(fov, aspect_ratio, clip_near, clip_far); -} - -void orbit_cam::move(const float3& translation) -{ - set_target_focal_point(focal_point_spring.x1 + translation); -} - -void orbit_cam::pan(float angle) -{ - set_target_azimuth(azimuth_spring.x1 + angle); -} - -void orbit_cam::tilt(float angle) -{ - set_target_elevation(elevation_spring.x1 + angle); -} - -void orbit_cam::zoom(float factor) -{ - set_target_zoom(zoom_spring.x1 + factor); -} - -void orbit_cam::reset_springs() -{ - // Reset values - focal_point_spring.x0 = focal_point_spring.x1; - azimuth_spring.x0 = azimuth_spring.x1; - elevation_spring.x0 = elevation_spring.x1; - zoom_spring.x0 = zoom_spring.x1; - - // Reset velocities - focal_point_spring.v = {0.0f, 0.0f, 0.0f}; - azimuth_spring.v = 0.0f; - elevation_spring.v = 0.0f; - zoom_spring.v = 0.0f; -} - -void orbit_cam::set_aspect_ratio(float ratio) -{ - aspect_ratio = ratio; -} - -void orbit_cam::set_focal_point(const float3& point) -{ - focal_point_spring.x0 = point; -} - -void orbit_cam::set_azimuth(float angle) -{ - azimuth_spring.x0 = std::max(azimuth_limits[0], std::min(azimuth_limits[1], angle)); -} - -void orbit_cam::set_elevation(float angle) -{ - elevation_spring.x0 = std::max(elevation_limits[0], std::min(elevation_limits[1], angle)); -} - -void orbit_cam::set_zoom(float factor) -{ - zoom_spring.x0 = std::max(0.0f, std::min(1.0f, factor)); -} - -void orbit_cam::set_target_focal_point(const float3& point) -{ - focal_point_spring.x1 = point; -} - -void orbit_cam::set_target_azimuth(float angle) -{ - azimuth_spring.x1 = std::max(azimuth_limits[0], std::min(azimuth_limits[1], angle)); -} - -void orbit_cam::set_target_elevation(float angle) -{ - elevation_spring.x1 = std::max(elevation_limits[0], std::min(elevation_limits[1], angle)); -} - -void orbit_cam::set_target_zoom(float factor) -{ - zoom_spring.x1 = std::max(0.0f, std::min(1.0f, factor)); -} - -void orbit_cam::set_azimuth_limits(const std::array& limits) -{ - azimuth_limits = limits; -} - -void orbit_cam::set_elevation_limits(const std::array& limits) -{ - elevation_limits = limits; -} - -void orbit_cam::set_focal_distance_limits(const std::array& limits) -{ - focal_distance_limits = limits; -} - -void orbit_cam::set_fov_limits(const std::array& limits) -{ - fov_limits = limits; -} - -void orbit_cam::set_clip_near_limits(const std::array& limits) -{ - clip_near_limits = limits; -} - -void orbit_cam::set_clip_far_limits(const std::array& limits) -{ - clip_far_limits = limits; -} - -void orbit_cam::set_focal_point_oscillation(float frequency) -{ - focal_point_spring.w = frequency; -} - -void orbit_cam::set_azimuth_oscillation(float frequency) -{ - azimuth_spring.w = frequency; -} - -void orbit_cam::set_elevation_oscillation(float frequency) -{ - elevation_spring.w = frequency; -} - -void orbit_cam::set_zoom_oscillation(float frequency) -{ - zoom_spring.w = frequency; -} diff --git a/src/animation/orbit-cam.hpp b/src/animation/orbit-cam.hpp deleted file mode 100644 index 5e5b876..0000000 --- a/src/animation/orbit-cam.hpp +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Copyright (C) 2021 Christopher J. Howard - * - * This file is part of Antkeeper source code. - * - * Antkeeper source code is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Antkeeper source code is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Antkeeper source code. If not, see . - */ - -#ifndef ANTKEEPER_ORBIT_CAM_HPP -#define ANTKEEPER_ORBIT_CAM_HPP - -#include "camera-rig.hpp" -#include "animation/spring.hpp" -#include - -/** - * Rig which orbits around a focal point. - */ -class orbit_cam: public camera_rig -{ -public: - orbit_cam(); - virtual ~orbit_cam(); - virtual void update(float dt); - - /// @param direction Specifies the movement direction and speed scale on the XZ plane - void move(const float3& translation); - void pan(float angle); - void tilt(float angle); - void zoom(float factor); - - void reset_springs(); - - void set_aspect_ratio(float ratio); - - void set_focal_point(const float3& point); - void set_azimuth(float angle); - void set_elevation(float angle); - void set_zoom(float factor); - - void set_target_focal_point(const float3& point); - void set_target_azimuth(float angle); - void set_target_elevation(float angle); - void set_target_zoom(float factor); - - void set_azimuth_limits(const std::array& limits); - void set_elevation_limits(const std::array& limits); - void set_focal_distance_limits(const std::array& limits); - void set_fov_limits(const std::array& limits); - void set_clip_near_limits(const std::array& limits); - void set_clip_far_limits(const std::array& limits); - - void set_focal_point_oscillation(float frequency); - void set_azimuth_oscillation(float frequency); - void set_elevation_oscillation(float frequency); - void set_zoom_oscillation(float frequency); - - const float3& get_focal_point() const; - float get_azimuth() const; - float get_elevation() const; - float get_zoom() const; - const quaternion_type& get_azimuth_rotation() const; - const quaternion_type& get_elevation_rotation() const; - -private: - float aspect_ratio; - - numeric_spring focal_point_spring; - numeric_spring azimuth_spring; - numeric_spring elevation_spring; - numeric_spring zoom_spring; - - std::array azimuth_limits; - std::array elevation_limits; - std::array focal_distance_limits; - std::array fov_limits; - std::array clip_near_limits; - std::array clip_far_limits; - - quaternion_type azimuth_rotation; - quaternion_type elevation_rotation; -}; - -inline const float3& orbit_cam::get_focal_point() const -{ - return focal_point_spring.x0; -} - -inline float orbit_cam::get_azimuth() const -{ - return azimuth_spring.x0; -} - -inline float orbit_cam::get_elevation() const -{ - return elevation_spring.x0; -} - -inline float orbit_cam::get_zoom() const -{ - return zoom_spring.x0; -} - - -inline const typename camera_rig::quaternion_type& orbit_cam::get_azimuth_rotation() const -{ - return azimuth_rotation; -} - -inline const typename camera_rig::quaternion_type& orbit_cam::get_elevation_rotation() const -{ - return elevation_rotation; -} -#endif // ANTKEEPER_ORBIT_CAM_HPP diff --git a/src/entity/systems/control.cpp b/src/entity/systems/control.cpp deleted file mode 100644 index 563ac72..0000000 --- a/src/entity/systems/control.cpp +++ /dev/null @@ -1,242 +0,0 @@ -/* - * Copyright (C) 2021 Christopher J. Howard - * - * This file is part of Antkeeper source code. - * - * Antkeeper source code is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Antkeeper source code is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Antkeeper source code. If not, see . - */ - -#include "control.hpp" -#include "input/control.hpp" -#include "geom/intersection.hpp" -#include "animation/ease.hpp" -#include "math/math.hpp" -#include "entity/commands.hpp" -#include "entity/systems/camera.hpp" -#include "animation/orbit-cam.hpp" -#include "../../nest.hpp" -#include - -namespace entity { -namespace system { - -control::control(entity::registry& registry): - updatable(registry) -{ - control_set.add_control(&move_forward_control); - control_set.add_control(&move_back_control); - control_set.add_control(&move_right_control); - control_set.add_control(&move_left_control); - control_set.add_control(&rotate_ccw_control); - control_set.add_control(&rotate_cw_control); - control_set.add_control(&tilt_up_control); - control_set.add_control(&tilt_down_control); - control_set.add_control(&zoom_in_control); - control_set.add_control(&zoom_out_control); - control_set.add_control(&adjust_camera_control); - control_set.add_control(&ascend_control); - control_set.add_control(&descend_control); - control_set.add_control(&toggle_view_control); - control_set.add_control(&tool_menu_control); - control_set.add_control(&equip_lens_control); - control_set.add_control(&equip_brush_control); - control_set.add_control(&equip_forceps_control); - control_set.add_control(&equip_marker_control); - control_set.add_control(&equip_container_control); - control_set.add_control(&equip_twig_control); - control_set.add_control(&next_marker_control); - control_set.add_control(&previous_marker_control); - control_set.add_control(&use_tool_control); - control_set.add_control(&fast_forward_control); - control_set.add_control(&rewind_control); - control_set.add_control(&exposure_increase_control); - control_set.add_control(&exposure_decrease_control); - - // Set deadzone at 15% for all controls - const std::list* controls = control_set.get_controls(); - for (input::control* control: *controls) - { - control->set_deadzone(0.15f); - } - - /* - - zoom_speed = 5.0f; //1 - min_elevation = math::radians(-85.0f); - max_elevation = math::radians(85.0f); - near_focal_distance = 2.0f; - far_focal_distance = 200.0f; - near_movement_speed = 10.0f; - far_movement_speed = 80.0f; - near_fov = math::radians(80.0f); - far_fov = math::radians(35.0f); - near_clip_near = 0.1f; - far_clip_near = 5.0f; - near_clip_far = 100.0f; - far_clip_far = 2000.0f; - - nest = nullptr; - - mouse_angle = 0.0f; - old_mouse_angle = mouse_angle; - flashlight_turns = 0.0f; - flashlight_turns_i = 0; - flashlight_turns_f = 0.0f; - */ -} - -void control::update(double t, double dt) -{ - /* - - // Zoom camera - if (zoom_in_control.is_active()) - camera_system->zoom(zoom_speed * dt); - if (zoom_out_control.is_active()) - camera_system->zoom(-zoom_speed * dt); - - // Rotate camera - const float rotation_speed = math::radians(270.0f); - if (rotate_ccw_control.is_active()) - camera_system->pan(rotation_speed * dt * std::min(1.0f, rotate_ccw_control.get_current_value())); - if (rotate_cw_control.is_active()) - camera_system->pan(-rotation_speed * dt * std::min(1.0f, rotate_cw_control.get_current_value())); - - // Exposure - if (camera_system->get_camera()) - { - const float exposure = camera_system->get_camera()->get_exposure(); - const float exposure_rate = 0.1f; - if (exposure_increase_control.is_active()) - { - camera_system->get_camera()->set_exposure(exposure + exposure_rate); - std::cout << "exposure: " << (exposure + exposure_rate) << std::endl; - } - if (exposure_decrease_control.is_active()) - { - camera_system->get_camera()->set_exposure(exposure - exposure_rate); - std::cout << "exposure: " << (exposure - exposure_rate) << std::endl; - } - } - - // Move camera - float3 movement{0.0f, 0.0f, 0.0f}; - if (move_right_control.is_active()) - movement.x += move_right_control.get_current_value(); - if (move_left_control.is_active()) - movement.x -= move_left_control.get_current_value(); - if (move_forward_control.is_active()) - movement.z -= move_forward_control.get_current_value(); - if (move_back_control.is_active()) - movement.z += move_back_control.get_current_value(); - - if (math::length_squared(movement) != 0.0f) - { - std::array speed_limits = {15.0f, 100.0f}; - - float zoom = camera_system->get_orbit_cam()->get_zoom(); - float max_speed = math::log_lerp(speed_limits[1], speed_limits[0], zoom) * dt; - - float speed = std::min(max_speed, math::length(movement * max_speed)); - movement = math::normalize(movement) * speed; - - const math::quaternion& azimuth_rotation = camera_system->get_orbit_cam()->get_azimuth_rotation(); - movement = azimuth_rotation * movement; - - command::translate(registry, camera_subject_entity, movement); - } - - // Turn flashlight - float2 viewport_center = {(viewport[0] + viewport[2]) * 0.5f, (viewport[1] + viewport[3]) * 0.5f}; - float2 mouse_direction = math::normalize(mouse_position - viewport_center); - old_mouse_angle = mouse_angle; - mouse_angle = std::atan2(-mouse_direction.y, mouse_direction.x); - - if (mouse_angle - old_mouse_angle != 0.0f) - { - if (mouse_angle - old_mouse_angle <= -math::pi) - flashlight_turns_i -= 1; - else if (mouse_angle - old_mouse_angle >= math::pi) - flashlight_turns_i += 1; - - flashlight_turns_f = (mouse_angle) / math::two_pi; - flashlight_turns = flashlight_turns_i - flashlight_turns_f; - - if (flashlight_entity != entt::null && nest) - { - math::transform flashlight_transform = math::identity_transform; - - float flashlight_depth = nest->get_shaft_depth(*nest->get_central_shaft(), flashlight_turns); - - flashlight_transform.translation = {0.0f, -flashlight_depth, 0.0f}; - flashlight_transform.rotation = math::angle_axis(-flashlight_turns * math::two_pi + math::half_pi, {0, 1, 0}); - - command::set_transform(registry, flashlight_entity, flashlight_transform, false); - - if (underground_camera) - { - underground_camera->look_at({0, -flashlight_depth + 50.0f, 0}, {0, -flashlight_depth, 0}, {0, 0, -1}); - } - } - } - */ -} - -void control::set_viewport(const float4& viewport) -{ - this->viewport = viewport; -} - -void control::handle_event(const mouse_moved_event& event) -{ - /* - if (adjust_camera_control.is_active()) - { - bool invert_x = true; - bool invert_y = false; - - float rotation_factor = event.dx; - float elevation_factor = event.dy; - - if (invert_x) - { - rotation_factor *= -1.0f; - } - if (invert_y) - { - elevation_factor *= -1.0f; - } - - float rotation = math::radians(15.0f) * rotation_factor * timestep; - float tilt = math::radians(15.0f) * elevation_factor * timestep; - - camera_system->pan(rotation); - camera_system->tilt(tilt); - - } - else if (!adjust_camera_control.was_active()) - { - mouse_position[0] = event.x; - mouse_position[1] = event.y; - } - */ -} - -void control::handle_event(const window_resized_event& event) -{ - set_viewport({0.0f, 0.0f, static_cast(event.w), static_cast(event.h)}); -} - -} // namespace system -} // namespace entity diff --git a/src/entity/systems/control.hpp b/src/entity/systems/control.hpp deleted file mode 100644 index d6f0811..0000000 --- a/src/entity/systems/control.hpp +++ /dev/null @@ -1,270 +0,0 @@ -/* - * Copyright (C) 2021 Christopher J. Howard - * - * This file is part of Antkeeper source code. - * - * Antkeeper source code is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Antkeeper source code is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Antkeeper source code. If not, see . - */ - -#ifndef ANTKEEPER_ENTITY_SYSTEM_CONTROL_HPP -#define ANTKEEPER_ENTITY_SYSTEM_CONTROL_HPP - -#include "entity/systems/updatable.hpp" -#include "entity/id.hpp" -#include "event/event-handler.hpp" -#include "event/input-events.hpp" -#include "event/window-events.hpp" -#include "input/control.hpp" -#include "input/control-set.hpp" -#include "scene/model-instance.hpp" -#include "utility/fundamental-types.hpp" -#include "scene/camera.hpp" - -class nest; - -namespace entity { -namespace system { - -class camera; - -class control: - public updatable, - public event_handler, - public event_handler -{ -public: - control(entity::registry& registry); - - virtual void update(double t, double dt); - - void set_viewport(const float4& viewport); - - input::control_set* get_control_set(); - input::control* get_move_forward_control(); - input::control* get_move_back_control(); - input::control* get_move_left_control(); - input::control* get_move_right_control(); - input::control* get_rotate_ccw_control(); - input::control* get_rotate_cw_control(); - input::control* get_tilt_up_control(); - input::control* get_tilt_down_control(); - input::control* get_zoom_in_control(); - input::control* get_zoom_out_control(); - input::control* get_adjust_camera_control(); - input::control* get_ascend_control(); - input::control* get_descend_control(); - input::control* get_toggle_view_control(); - input::control* get_tool_menu_control(); - input::control* get_equip_lens_control(); - input::control* get_equip_brush_control(); - input::control* get_equip_forceps_control(); - input::control* get_equip_marker_control(); - input::control* get_equip_container_control(); - input::control* get_equip_twig_control(); - input::control* get_next_marker_control(); - input::control* get_previous_marker_control(); - input::control* get_use_tool_control(); - input::control* get_fast_forward_control(); - input::control* get_rewind_control(); - input::control* get_exposure_increase_control(); - input::control* get_exposure_decrease_control(); - -private: - virtual void handle_event(const mouse_moved_event& event); - virtual void handle_event(const window_resized_event& event); - - input::control_set control_set; - input::control move_forward_control; - input::control move_back_control; - input::control move_left_control; - input::control move_right_control; - input::control rotate_ccw_control; - input::control rotate_cw_control; - input::control tilt_up_control; - input::control tilt_down_control; - input::control zoom_in_control; - input::control zoom_out_control; - input::control adjust_camera_control; - input::control ascend_control; - input::control descend_control; - input::control toggle_view_control; - input::control tool_menu_control; - input::control equip_lens_control; - input::control equip_brush_control; - input::control equip_forceps_control; - input::control equip_marker_control; - input::control equip_container_control; - input::control equip_twig_control; - input::control next_marker_control; - input::control previous_marker_control; - input::control use_tool_control; - input::control fast_forward_control; - input::control rewind_control; - input::control exposure_increase_control; - input::control exposure_decrease_control; - - float2 mouse_position; - float4 viewport; -}; - -inline input::control_set* control::get_control_set() -{ - return &control_set; -} - -inline input::control* control::get_move_forward_control() -{ - return &move_forward_control; -} - -inline input::control* control::get_move_back_control() -{ - return &move_back_control; -} - -inline input::control* control::get_move_left_control() -{ - return &move_left_control; -} - -inline input::control* control::get_move_right_control() -{ - return &move_right_control; -} - -inline input::control* control::get_rotate_ccw_control() -{ - return &rotate_ccw_control; -} - -inline input::control* control::get_rotate_cw_control() -{ - return &rotate_cw_control; -} - -inline input::control* control::get_tilt_up_control() -{ - return &tilt_up_control; -} - -inline input::control* control::get_tilt_down_control() -{ - return &tilt_down_control; -} - -inline input::control* control::get_zoom_in_control() -{ - return &zoom_in_control; -} - -inline input::control* control::get_zoom_out_control() -{ - return &zoom_out_control; -} - -inline input::control* control::get_adjust_camera_control() -{ - return &adjust_camera_control; -} - -inline input::control* control::get_ascend_control() -{ - return &ascend_control; -} - -inline input::control* control::get_descend_control() -{ - return &descend_control; -} - -inline input::control* control::get_toggle_view_control() -{ - return &toggle_view_control; -} - -inline input::control* control::get_tool_menu_control() -{ - return &tool_menu_control; -} - -inline input::control* control::get_equip_lens_control() -{ - return &equip_lens_control; -} - -inline input::control* control::get_equip_brush_control() -{ - return &equip_brush_control; -} - -inline input::control* control::get_equip_forceps_control() -{ - return &equip_forceps_control; -} - -inline input::control* control::get_equip_marker_control() -{ - return &equip_marker_control; -} - -inline input::control* control::get_equip_container_control() -{ - return &equip_container_control; -} - -inline input::control* control::get_equip_twig_control() -{ - return &equip_twig_control; -} - -inline input::control* control::get_next_marker_control() -{ - return &next_marker_control; -} - -inline input::control* control::get_previous_marker_control() -{ - return &previous_marker_control; -} - -inline input::control* control::get_use_tool_control() -{ - return &use_tool_control; -} - -inline input::control* control::get_fast_forward_control() -{ - return &fast_forward_control; -} - -inline input::control* control::get_rewind_control() -{ - return &rewind_control; -} - -inline input::control* control::get_exposure_increase_control() -{ - return &exposure_increase_control; -} - -inline input::control* control::get_exposure_decrease_control() -{ - return &exposure_decrease_control; -} - -} // namespace system -} // namespace entity - -#endif // ANTKEEPER_ENTITY_SYSTEM_CONTROL_HPP - diff --git a/src/entity/systems/tool.cpp b/src/entity/systems/tool.cpp index cbd4ee4..03a4f65 100644 --- a/src/entity/systems/tool.cpp +++ b/src/entity/systems/tool.cpp @@ -23,7 +23,6 @@ #include "entity/components/transform.hpp" #include "event/event-dispatcher.hpp" #include "game/events/tool-events.hpp" -#include "animation/orbit-cam.hpp" #include "animation/ease.hpp" #include "geom/mesh.hpp" #include "geom/intersection.hpp" @@ -37,7 +36,6 @@ tool::tool(entity::registry& registry, ::event_dispatcher* event_dispatcher): updatable(registry), event_dispatcher(event_dispatcher), camera(nullptr), - orbit_cam(orbit_cam), viewport{0, 0, 0, 0}, mouse_position{0, 0}, pick_enabled(true), @@ -95,6 +93,7 @@ tool::~tool() void tool::update(double t, double dt) { + /* if (active_tool == entt::null) return; @@ -174,11 +173,6 @@ void tool::update(double t, double dt) registry.view().each( [&](entity::id entity_id, auto& tool, auto& transform) { - /* - if (registry.has(entity_id)) - { - - }*/ if (!tool.active) return; @@ -221,6 +215,7 @@ void tool::update(double t, double dt) }); was_pick_enabled = pick_enabled; + */ } void tool::set_camera(const scene::camera* camera) @@ -228,11 +223,6 @@ void tool::set_camera(const scene::camera* camera) this->camera = camera; } -void tool::set_orbit_cam(const ::orbit_cam* orbit_cam) -{ - this->orbit_cam = orbit_cam; -} - void tool::set_viewport(const float4& viewport) { this->viewport = viewport; diff --git a/src/entity/systems/tool.hpp b/src/entity/systems/tool.hpp index 113c4f9..282afc2 100644 --- a/src/entity/systems/tool.hpp +++ b/src/entity/systems/tool.hpp @@ -30,7 +30,6 @@ #include "animation/animation.hpp" #include "scene/camera.hpp" -class orbit_cam; class event_dispatcher; namespace entity { @@ -47,7 +46,6 @@ public: virtual void update(double t, double dt); void set_camera(const scene::camera* camera); - 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); @@ -64,7 +62,6 @@ private: event_dispatcher* event_dispatcher; const scene::camera* camera; - const orbit_cam* orbit_cam; float4 viewport; float2 mouse_position; bool was_pick_enabled; diff --git a/src/entity/systems/ui.cpp b/src/entity/systems/ui.cpp index 3081f0d..c78ee51 100644 --- a/src/entity/systems/ui.cpp +++ b/src/entity/systems/ui.cpp @@ -76,8 +76,12 @@ void ui::set_viewport(const float4& viewport) void ui::set_tool_menu_control(input::control* control) { tool_menu_control = control; - tool_menu_control->set_activated_callback(std::bind(&ui::open_tool_menu, this)); - tool_menu_control->set_deactivated_callback(std::bind(&ui::close_tool_menu, this)); + + if (tool_menu_control) + { + tool_menu_control->set_activated_callback(std::bind(&ui::open_tool_menu, this)); + tool_menu_control->set_deactivated_callback(std::bind(&ui::close_tool_menu, this)); + } } void ui::set_camera(scene::camera* camera) @@ -98,7 +102,7 @@ void ui::set_scene(scene::collection* collection) void ui::handle_event(const mouse_moved_event& event) { - if (tool_menu_control->is_active()) + if (tool_menu_control && tool_menu_control->is_active()) { tool_selection_vector.x += event.dx; tool_selection_vector.y += event.dy; diff --git a/src/game/bootloader.cpp b/src/game/bootloader.cpp index 76c851b..83c05bb 100644 --- a/src/game/bootloader.cpp +++ b/src/game/bootloader.cpp @@ -59,7 +59,6 @@ #include "entity/systems/camera.hpp" #include "entity/systems/collision.hpp" #include "entity/systems/constraint.hpp" -#include "entity/systems/control.hpp" #include "entity/systems/locomotion.hpp" #include "entity/systems/nest.hpp" #include "entity/systems/snapping.hpp" @@ -903,20 +902,11 @@ void setup_systems(game::context* ctx) ctx->render_system->add_layer(ctx->ui_scene); ctx->render_system->set_renderer(ctx->renderer); - // Setup control system - ctx->control_system = new entity::system::control(*ctx->entity_registry); - ctx->control_system->set_viewport(viewport); - ctx->control_system->get_adjust_camera_control()->set_activated_callback([ctx](){ ctx->app->set_relative_mouse_mode(true); ctx->tool_system->set_pick(false); }); - ctx->control_system->get_adjust_camera_control()->set_deactivated_callback([ctx](){ ctx->app->set_relative_mouse_mode(false); ctx->tool_system->set_pick(true); }); - event_dispatcher->subscribe(ctx->control_system); - event_dispatcher->subscribe(ctx->control_system); - // Setup UI system ctx->ui_system = new entity::system::ui(ctx->resource_manager); ctx->ui_system->set_camera(ctx->ui_camera); ctx->ui_system->set_scene(ctx->ui_scene); ctx->ui_system->set_viewport(viewport); - ctx->ui_system->set_tool_menu_control(ctx->control_system->get_tool_menu_control()); event_dispatcher->subscribe(ctx->ui_system); event_dispatcher->subscribe(ctx->ui_system); } @@ -1006,12 +996,12 @@ void setup_controls(game::context* ctx) ctx->camera_control_tilt_up = new input::control(); ctx->camera_control_tilt_down = new input::control(); - ctx->camera_controls = ctx->control_system->get_control_set(); // Application control mappings ctx->input_event_router->add_mapping(input::key_mapping(ctx->toggle_fullscreen_control, nullptr, input::scancode::f11)); ctx->input_event_router->add_mapping(input::key_mapping(ctx->screenshot_control, nullptr, input::scancode::f12)); + /* // Add menu control mappings ctx->input_event_router->add_mapping(input::key_mapping(ctx->menu_back_control, nullptr, input::scancode::escape)); ctx->input_event_router->add_mapping(input::key_mapping(ctx->menu_back_control, nullptr, input::scancode::backspace)); @@ -1094,31 +1084,6 @@ void setup_controls(game::context* ctx) ctx->input_event_router->add_mapping(input::key_mapping(ctx->control_system->get_equip_lens_control(), nullptr, input::scancode::five)); ctx->input_event_router->add_mapping(input::key_mapping(ctx->control_system->get_equip_marker_control(), nullptr, input::scancode::six)); - - ctx->input_event_router->add_mapping(input::key_mapping(ctx->camera_control_modifier, nullptr, input::scancode::left_shift)); - ctx->input_event_router->add_mapping(input::key_mapping(ctx->camera_control_dolly_forward, nullptr, input::scancode::w)); - ctx->input_event_router->add_mapping(input::game_controller_axis_mapping(ctx->camera_control_dolly_forward, nullptr, input::game_controller_axis::left_y, true)); - ctx->input_event_router->add_mapping(input::key_mapping(ctx->camera_control_dolly_backward, nullptr, input::scancode::s)); - ctx->input_event_router->add_mapping(input::game_controller_axis_mapping(ctx->camera_control_dolly_backward, nullptr, input::game_controller_axis::left_y, false)); - ctx->input_event_router->add_mapping(input::key_mapping(ctx->camera_control_truck_left, nullptr, input::scancode::a)); - ctx->input_event_router->add_mapping(input::game_controller_axis_mapping(ctx->camera_control_truck_left, nullptr, input::game_controller_axis::left_x, true)); - ctx->input_event_router->add_mapping(input::key_mapping(ctx->camera_control_truck_right, nullptr, input::scancode::d)); - ctx->input_event_router->add_mapping(input::game_controller_axis_mapping(ctx->camera_control_truck_right, nullptr, input::game_controller_axis::left_x, false)); - - ctx->input_event_router->add_mapping(input::mouse_wheel_mapping(ctx->camera_control_pedestal_up, nullptr, input::mouse_wheel_axis::positive_y)); - ctx->input_event_router->add_mapping(input::mouse_wheel_mapping(ctx->camera_control_pedestal_down, nullptr, input::mouse_wheel_axis::negative_y)); - - ctx->input_event_router->add_mapping(input::mouse_button_mapping(ctx->camera_control_mouse_rotate, nullptr, 3)); - ctx->input_event_router->add_mapping(input::mouse_motion_mapping(ctx->camera_control_mouse_left, nullptr, input::mouse_motion_axis::negative_x)); - ctx->input_event_router->add_mapping(input::mouse_motion_mapping(ctx->camera_control_mouse_right, nullptr, input::mouse_motion_axis::positive_x)); - ctx->input_event_router->add_mapping(input::mouse_motion_mapping(ctx->camera_control_mouse_down, nullptr, input::mouse_motion_axis::positive_y)); - ctx->input_event_router->add_mapping(input::mouse_motion_mapping(ctx->camera_control_mouse_up, nullptr, input::mouse_motion_axis::negative_y)); - - //ctx->input_event_router->add_mapping(input::key_mapping(ctx->control_system->get_next_marker_control(), nullptr, input::scancode::right_brace)); - //ctx->input_event_router->add_mapping(input::key_mapping(ctx->control_system->get_previous_marker_control(), nullptr, input::scancode::left_brace)); - - - float time_scale = ctx->config->get("time_scale"); ctx->control_system->get_fast_forward_control()->set_activated_callback ( @@ -1152,7 +1117,28 @@ void setup_controls(game::context* ctx) ctx->astronomy_system->set_time_scale(time_scale / seconds_per_day); } ); + */ + + ctx->input_event_router->add_mapping(input::key_mapping(ctx->camera_control_modifier, nullptr, input::scancode::left_shift)); + ctx->input_event_router->add_mapping(input::key_mapping(ctx->camera_control_dolly_forward, nullptr, input::scancode::w)); + ctx->input_event_router->add_mapping(input::game_controller_axis_mapping(ctx->camera_control_dolly_forward, nullptr, input::game_controller_axis::left_y, true)); + ctx->input_event_router->add_mapping(input::key_mapping(ctx->camera_control_dolly_backward, nullptr, input::scancode::s)); + ctx->input_event_router->add_mapping(input::game_controller_axis_mapping(ctx->camera_control_dolly_backward, nullptr, input::game_controller_axis::left_y, false)); + ctx->input_event_router->add_mapping(input::key_mapping(ctx->camera_control_truck_left, nullptr, input::scancode::a)); + ctx->input_event_router->add_mapping(input::game_controller_axis_mapping(ctx->camera_control_truck_left, nullptr, input::game_controller_axis::left_x, true)); + ctx->input_event_router->add_mapping(input::key_mapping(ctx->camera_control_truck_right, nullptr, input::scancode::d)); + ctx->input_event_router->add_mapping(input::game_controller_axis_mapping(ctx->camera_control_truck_right, nullptr, input::game_controller_axis::left_x, false)); + + ctx->input_event_router->add_mapping(input::mouse_wheel_mapping(ctx->camera_control_pedestal_up, nullptr, input::mouse_wheel_axis::positive_y)); + ctx->input_event_router->add_mapping(input::mouse_wheel_mapping(ctx->camera_control_pedestal_down, nullptr, input::mouse_wheel_axis::negative_y)); + ctx->input_event_router->add_mapping(input::mouse_button_mapping(ctx->camera_control_mouse_rotate, nullptr, 3)); + ctx->input_event_router->add_mapping(input::mouse_motion_mapping(ctx->camera_control_mouse_left, nullptr, input::mouse_motion_axis::negative_x)); + ctx->input_event_router->add_mapping(input::mouse_motion_mapping(ctx->camera_control_mouse_right, nullptr, input::mouse_motion_axis::positive_x)); + ctx->input_event_router->add_mapping(input::mouse_motion_mapping(ctx->camera_control_mouse_down, nullptr, input::mouse_motion_axis::positive_y)); + ctx->input_event_router->add_mapping(input::mouse_motion_mapping(ctx->camera_control_mouse_up, nullptr, input::mouse_motion_axis::negative_y)); + + // Make lens tool's model instance unculled, so its shadow is always visible. scene::model_instance* lens_model_instance = ctx->render_system->get_model_instance(ctx->lens_entity); if (lens_model_instance) @@ -1184,8 +1170,6 @@ void setup_callbacks(game::context* ctx) // Update controls ctx->application_controls->update(); ctx->menu_controls->update(); - ctx->camera_controls->update(); - ctx->control_system->update(t, dt); ctx->camera_control_modifier->update(); ctx->camera_control_mouse_rotate->update(); ctx->camera_control_mouse_left->update(); diff --git a/src/game/context.hpp b/src/game/context.hpp index 9365fba..d07cb69 100644 --- a/src/game/context.hpp +++ b/src/game/context.hpp @@ -53,7 +53,6 @@ class config_file; class final_pass; class material; class material_pass; -class orbit_cam; class pheromone_matrix; class resource_manager; class screen_transition; @@ -94,7 +93,6 @@ namespace entity class collision; class constraint; class locomotion; - class control; class snapping; class camera; class nest; @@ -262,7 +260,6 @@ struct context entity::system::camera* camera_system; entity::system::collision* collision_system; entity::system::constraint* constraint_system; - entity::system::control* control_system; entity::system::locomotion* locomotion_system; entity::system::nest* nest_system; entity::system::snapping* snapping_system; diff --git a/src/game/states/brood.cpp b/src/game/states/brood.cpp index b89c20c..bab8e95 100644 --- a/src/game/states/brood.cpp +++ b/src/game/states/brood.cpp @@ -28,9 +28,6 @@ #include "entity/components/constraints/spring-to.hpp" #include "entity/components/constraints/three-dof.hpp" #include "entity/components/constraint-stack.hpp" -#include "entity/systems/control.hpp" -#include "entity/systems/camera.hpp" -#include "entity/systems/tool.hpp" #include "animation/screen-transition.hpp" #include "animation/ease.hpp" #include "resources/resource-manager.hpp" @@ -164,26 +161,6 @@ void setup_camera(game::context* ctx) target_transform.world = target_transform.local; target_transform.warp = true; ctx->entity_registry->assign(target_eid, target_transform); - - /* - // 3DOF constraint - entity::id three_dof_eid = entity::command::create(*ctx->entity_registry, "underground_cam_3dof"); - entity::component::constraint::three_dof three_dof; - three_dof.yaw = 0.0f; - three_dof.pitch = 0.0f; - three_dof.roll = 0.0f; - ctx->entity_registry->assign(three_dof_eid, three_dof); - entity::component::constraint_stack_node node; - node.active = true; - node.weight = 1.0f; - node.next = entt::null; - ctx->entity_registry->assign(three_dof_eid, node); - - // Create target constraint stack component - entity::component::constraint_stack constraint_stack; - constraint_stack.head = three_dof_eid; - ctx->entity_registry->assign(target_eid, constraint_stack); - */ } // Create camera entity @@ -228,9 +205,6 @@ void setup_camera(game::context* ctx) spring.translation = {{0.0f, 0.0f, 0.0f}, {0.0f, 0.0f, 0.0f}, {0.0f, 0.0f, 0.0f}, 1.0f, math::two_pi}; spring.translation.w = hz_to_rads(8.0f); - //spring.rotation = {{1.0f, 0.0f, 0.0f, 0.0f}, {1.0f, 0.0f, 0.0f, 0.0f}, {0.0f, 0.0f, 0.0f, 0.0f}, 1.0f, math::two_pi}; - //spring.rotation.w = hz_to_rads(5.0f); - spring.spring_translation = true; spring.spring_rotation = false; ctx->entity_registry->assign(spring_constraint_eid, spring); @@ -249,22 +223,6 @@ void setup_camera(game::context* ctx) ctx->entity_registry->assign(camera_eid, constraint_stack); } - /* - entity::component::orbit_rig orbit; - orbit.azimuth_min = -std::numeric_limits::infinity(); - orbit.azimuth_max = std::numeric_limits::infinity(); - orbit.elevation_min = math::radians(-89.0f); - orbit.elevation_max = math::radians(89.0f); - orbit.dolly_min = 2.0f; - orbit.dolly_max = 200.0f; - orbit.fov_near = math::radians(80.0f); - orbit.fov_far = math::radians(35.0f); - orbit.clip_near_min = 0.1f; - orbit.clip_near_max = 5.0f; - orbit.clip_far_min = 100.0f; - orbit.clip_far_max = 5000.0f; - */ - ctx->underground_camera->set_exposure(0.0f); } @@ -277,7 +235,7 @@ void setup_controls(game::context* ctx) const float dolly_speed = 10.0f; const float truck_speed = dolly_speed; - const float pedestal_speed = 20.0f; + const float pedestal_speed = 30.0f; const float pan_speed = math::radians(8.0f); const float tilt_speed = pan_speed; @@ -431,7 +389,7 @@ void setup_controls(game::context* ctx) auto& three_dof = ctx->entity_registry->get(three_dof_eid); three_dof.pitch -= tilt_speed * value * (1.0f / 60.0f); - three_dof.pitch = std::max(math::radians(-89.9f), three_dof.pitch); + three_dof.pitch = std::max(math::radians(-90.0f), three_dof.pitch); } ); @@ -445,7 +403,7 @@ void setup_controls(game::context* ctx) auto& three_dof = ctx->entity_registry->get(three_dof_eid); three_dof.pitch += tilt_speed * value * (1.0f / 60.0f); - three_dof.pitch = std::min(math::radians(89.9f), three_dof.pitch); + three_dof.pitch = std::min(math::radians(90.0f), three_dof.pitch); } ); } diff --git a/src/game/states/forage.cpp b/src/game/states/forage.cpp index 2f253c4..5ca477e 100644 --- a/src/game/states/forage.cpp +++ b/src/game/states/forage.cpp @@ -24,8 +24,6 @@ #include "entity/components/terrain.hpp" #include "entity/components/transform.hpp" #include "entity/systems/astronomy.hpp" -#include "entity/systems/control.hpp" -#include "entity/systems/camera.hpp" #include "animation/screen-transition.hpp" #include "animation/ease.hpp" #include "resources/resource-manager.hpp" diff --git a/src/game/states/nuptial-flight.cpp b/src/game/states/nuptial-flight.cpp index 1d62dd1..1a7f370 100644 --- a/src/game/states/nuptial-flight.cpp +++ b/src/game/states/nuptial-flight.cpp @@ -21,7 +21,6 @@ #include "entity/archetype.hpp" #include "entity/systems/astronomy.hpp" #include "entity/systems/orbit.hpp" -#include "entity/systems/control.hpp" #include "entity/systems/camera.hpp" #include "entity/components/observer.hpp" #include "entity/components/transform.hpp"