💿🐜 Antkeeper source code https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
2.0 KiB

  1. /*
  2. * Copyright (C) 2021 Christopher J. Howard
  3. *
  4. * This file is part of Antkeeper source code.
  5. *
  6. * Antkeeper source code is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * Antkeeper source code is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include "animation/camera-rig.hpp"
  20. #include "math/constants.hpp"
  21. #include "configuration.hpp"
  22. #include <algorithm>
  23. #include <cmath>
  24. camera_rig::camera_rig():
  25. camera(nullptr),
  26. transform(math::identity_transform<float>),
  27. forward(global_forward),
  28. right(global_right),
  29. up(global_up)
  30. {}
  31. void camera_rig::attach(scene::camera* camera)
  32. {
  33. this->camera = camera;
  34. if (camera != nullptr)
  35. {
  36. camera->set_transform(transform);
  37. }
  38. }
  39. void camera_rig::detach()
  40. {
  41. camera = nullptr;
  42. }
  43. void camera_rig::update_transform(const transform_type& transform)
  44. {
  45. this->transform = transform;
  46. // Calculate orthonormal basis
  47. forward = transform.rotation * global_forward;
  48. up = transform.rotation * global_up;
  49. right = transform.rotation * global_right;
  50. if (camera != nullptr)
  51. {
  52. camera->set_transform(transform);
  53. }
  54. }
  55. void camera_rig::update_projection(float fov, float aspect_ratio, float clip_near, float clip_far)
  56. {
  57. if (camera != nullptr)
  58. {
  59. camera->set_perspective(fov, aspect_ratio, clip_near, clip_far);
  60. }
  61. }
  62. void camera_rig::update_projection(float clip_left, float clip_right, float clip_bottom, float clip_top, float clip_near, float clip_far)
  63. {
  64. if (camera != nullptr)
  65. {
  66. camera->set_orthographic(clip_left, clip_right, clip_bottom, clip_top, clip_near, clip_far);
  67. }
  68. }