💿🐜 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.

78 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 "scene/camera.hpp"
  21. #include "math/constants.hpp"
  22. #include "configuration.hpp"
  23. #include <algorithm>
  24. #include <cmath>
  25. camera_rig::camera_rig():
  26. camera(nullptr),
  27. transform(math::identity_transform<float>),
  28. forward(global_forward),
  29. right(global_right),
  30. up(global_up)
  31. {}
  32. void camera_rig::attach(::camera* camera)
  33. {
  34. this->camera = camera;
  35. if (camera != nullptr)
  36. {
  37. camera->set_transform(transform);
  38. }
  39. }
  40. void camera_rig::detach()
  41. {
  42. camera = nullptr;
  43. }
  44. void camera_rig::update_transform(const transform_type& transform)
  45. {
  46. this->transform = transform;
  47. // Calculate orthonormal basis
  48. forward = transform.rotation * global_forward;
  49. up = transform.rotation * global_up;
  50. right = transform.rotation * global_right;
  51. if (camera != nullptr)
  52. {
  53. camera->set_transform(transform);
  54. }
  55. }
  56. void camera_rig::update_projection(float fov, float aspect_ratio, float clip_near, float clip_far)
  57. {
  58. if (camera != nullptr)
  59. {
  60. camera->set_perspective(fov, aspect_ratio, clip_near, clip_far);
  61. }
  62. }
  63. void camera_rig::update_projection(float clip_left, float clip_right, float clip_bottom, float clip_top, float clip_near, float clip_far)
  64. {
  65. if (camera != nullptr)
  66. {
  67. camera->set_orthographic(clip_left, clip_right, clip_bottom, clip_top, clip_near, clip_far);
  68. }
  69. }