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

65 lines
1.6 KiB

  1. /*
  2. * Copyright (C) 2020 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 "orbit-cam.hpp"
  20. #include "scene/camera.hpp"
  21. #include "configuration.hpp"
  22. #include <algorithm>
  23. #include <cmath>
  24. using namespace vmq::operators;
  25. camera_rig::camera_rig():
  26. camera(nullptr),
  27. translation{0.0f, 0.0f, 0.0f},
  28. rotation(vmq::identity_quaternion<float>),
  29. forward(global_forward),
  30. right(global_right),
  31. up(global_up)
  32. {}
  33. void camera_rig::attach(::camera* camera)
  34. {
  35. this->camera = camera;
  36. if (camera != nullptr)
  37. {
  38. camera->look_at(translation, translation + forward, up);
  39. }
  40. }
  41. void camera_rig::detach()
  42. {
  43. camera = nullptr;
  44. }
  45. void camera_rig::set_translation(const float3& translation)
  46. {
  47. this->translation = translation;
  48. }
  49. void camera_rig::set_rotation(const vmq::quaternion<float>& rotation)
  50. {
  51. this->rotation = rotation;
  52. // Calculate orthonormal basis
  53. forward = rotation * global_forward;
  54. up = rotation * global_up;
  55. right = rotation * global_right;
  56. }