@ -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 <http://www.gnu.org/licenses/>. | |||||
*/ | |||||
#include "animation/camera-rig.hpp" | |||||
#include "math/constants.hpp" | |||||
#include "configuration.hpp" | |||||
#include <algorithm> | |||||
#include <cmath> | |||||
camera_rig::camera_rig(): | |||||
camera(nullptr), | |||||
transform(math::identity_transform<float>), | |||||
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); | |||||
} | |||||
} |
@ -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 <http://www.gnu.org/licenses/>. | |||||
*/ | |||||
#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<float> quaternion_type; | |||||
typedef math::transform<float> 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 | |||||
@ -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 <http://www.gnu.org/licenses/>. | |||||
*/ | |||||
#include "animation/orbit-cam.hpp" | |||||
#include "scene/camera.hpp" | |||||
#include "math/math.hpp" | |||||
#include <algorithm> | |||||
#include <cmath> | |||||
#include <limits> | |||||
#include <iostream> | |||||
orbit_cam::orbit_cam(): | |||||
azimuth_limits({-std::numeric_limits<float>::infinity(), std::numeric_limits<float>::infinity()}), | |||||
elevation_limits({-std::numeric_limits<float>::infinity(), std::numeric_limits<float>::infinity()}), | |||||
focal_distance_limits({-std::numeric_limits<float>::infinity(), std::numeric_limits<float>::infinity()}), | |||||
fov_limits({-std::numeric_limits<float>::infinity(), std::numeric_limits<float>::infinity()}), | |||||
clip_near_limits({-std::numeric_limits<float>::infinity(), std::numeric_limits<float>::infinity()}), | |||||
clip_far_limits({-std::numeric_limits<float>::infinity(), std::numeric_limits<float>::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<float>; | |||||
azimuth_spring.w = math::two_pi<float>; | |||||
elevation_spring.w = math::two_pi<float>; | |||||
zoom_spring.w = math::two_pi<float>; | |||||
// 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<float3, float>(focal_point_spring, dt); | |||||
solve_numeric_spring<float, float>(azimuth_spring, dt); | |||||
solve_numeric_spring<float, float>(elevation_spring, dt); | |||||
solve_numeric_spring<float, float>(zoom_spring, dt); | |||||
// Calculate zoom-dependent variables | |||||
float focal_distance = math::log_lerp<float>(focal_distance_limits[1], focal_distance_limits[0], zoom_spring.x0); | |||||
float fov = math::log_lerp<float>(fov_limits[1], fov_limits[0], zoom_spring.x0); | |||||
float clip_near = math::log_lerp<float>(clip_near_limits[1], clip_near_limits[0], zoom_spring.x0); | |||||
float clip_far = math::log_lerp<float>(clip_far_limits[1], clip_far_limits[0], zoom_spring.x0); | |||||
// Calculate camera transform | |||||
transform_type transform = math::identity_transform<float>; | |||||
// 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<float>(azimuth_limits[0], std::min<float>(azimuth_limits[1], angle)); | |||||
} | |||||
void orbit_cam::set_elevation(float angle) | |||||
{ | |||||
elevation_spring.x0 = std::max<float>(elevation_limits[0], std::min<float>(elevation_limits[1], angle)); | |||||
} | |||||
void orbit_cam::set_zoom(float factor) | |||||
{ | |||||
zoom_spring.x0 = std::max<float>(0.0f, std::min<float>(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<float>(azimuth_limits[0], std::min<float>(azimuth_limits[1], angle)); | |||||
} | |||||
void orbit_cam::set_target_elevation(float angle) | |||||
{ | |||||
elevation_spring.x1 = std::max<float>(elevation_limits[0], std::min<float>(elevation_limits[1], angle)); | |||||
} | |||||
void orbit_cam::set_target_zoom(float factor) | |||||
{ | |||||
zoom_spring.x1 = std::max<float>(0.0f, std::min<float>(1.0f, factor)); | |||||
} | |||||
void orbit_cam::set_azimuth_limits(const std::array<float, 2>& limits) | |||||
{ | |||||
azimuth_limits = limits; | |||||
} | |||||
void orbit_cam::set_elevation_limits(const std::array<float, 2>& limits) | |||||
{ | |||||
elevation_limits = limits; | |||||
} | |||||
void orbit_cam::set_focal_distance_limits(const std::array<float, 2>& limits) | |||||
{ | |||||
focal_distance_limits = limits; | |||||
} | |||||
void orbit_cam::set_fov_limits(const std::array<float, 2>& limits) | |||||
{ | |||||
fov_limits = limits; | |||||
} | |||||
void orbit_cam::set_clip_near_limits(const std::array<float, 2>& limits) | |||||
{ | |||||
clip_near_limits = limits; | |||||
} | |||||
void orbit_cam::set_clip_far_limits(const std::array<float, 2>& 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; | |||||
} |
@ -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 <http://www.gnu.org/licenses/>. | |||||
*/ | |||||
#ifndef ANTKEEPER_ORBIT_CAM_HPP | |||||
#define ANTKEEPER_ORBIT_CAM_HPP | |||||
#include "camera-rig.hpp" | |||||
#include "animation/spring.hpp" | |||||
#include <array> | |||||
/** | |||||
* 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<float, 2>& limits); | |||||
void set_elevation_limits(const std::array<float, 2>& limits); | |||||
void set_focal_distance_limits(const std::array<float, 2>& limits); | |||||
void set_fov_limits(const std::array<float, 2>& limits); | |||||
void set_clip_near_limits(const std::array<float, 2>& limits); | |||||
void set_clip_far_limits(const std::array<float, 2>& 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<float3, float> focal_point_spring; | |||||
numeric_spring<float, float> azimuth_spring; | |||||
numeric_spring<float, float> elevation_spring; | |||||
numeric_spring<float, float> zoom_spring; | |||||
std::array<float, 2> azimuth_limits; | |||||
std::array<float, 2> elevation_limits; | |||||
std::array<float, 2> focal_distance_limits; | |||||
std::array<float, 2> fov_limits; | |||||
std::array<float, 2> clip_near_limits; | |||||
std::array<float, 2> 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 |
@ -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 <http://www.gnu.org/licenses/>. | |||||
*/ | |||||
#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 <iostream> | |||||
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<input::control*>* 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<float>(1.0f, rotate_ccw_control.get_current_value())); | |||||
if (rotate_cw_control.is_active()) | |||||
camera_system->pan(-rotation_speed * dt * std::min<float>(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<float, 2> 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<float>(max_speed, math::length(movement * max_speed)); | |||||
movement = math::normalize(movement) * speed; | |||||
const math::quaternion<float>& 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<float>) | |||||
flashlight_turns_i -= 1; | |||||
else if (mouse_angle - old_mouse_angle >= math::pi<float>) | |||||
flashlight_turns_i += 1; | |||||
flashlight_turns_f = (mouse_angle) / math::two_pi<float>; | |||||
flashlight_turns = flashlight_turns_i - flashlight_turns_f; | |||||
if (flashlight_entity != entt::null && nest) | |||||
{ | |||||
math::transform<float> flashlight_transform = math::identity_transform<float>; | |||||
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<float> + math::half_pi<float>, {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<float>(event.w), static_cast<float>(event.h)}); | |||||
} | |||||
} // namespace system | |||||
} // namespace entity |
@ -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 <http://www.gnu.org/licenses/>. | |||||
*/ | |||||
#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<mouse_moved_event>, | |||||
public event_handler<window_resized_event> | |||||
{ | |||||
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 | |||||