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

63 lines
1.8 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 "scene/scene-object.hpp"
  20. #include "math/math.hpp"
  21. typename scene_object_base::transform_type scene_object_base::interpolate_transforms(const transform_type& x, const transform_type& y, float a)
  22. {
  23. return
  24. {
  25. math::lerp(x.translation, y.translation, a),
  26. math::nlerp(x.rotation, y.rotation, a),
  27. math::lerp(x.scale, y.scale, a),
  28. };
  29. }
  30. scene_object_base::scene_object_base():
  31. active(true),
  32. transform(math::identity_transform<float>, interpolate_transforms),
  33. culling_mask(nullptr)
  34. {}
  35. void scene_object_base::set_culling_mask(const bounding_volume_type* culling_mask)
  36. {
  37. this->culling_mask = culling_mask;
  38. }
  39. std::size_t scene_object_base::next_object_type_id()
  40. {
  41. static std::atomic<std::size_t> id{0};
  42. return id++;
  43. }
  44. void scene_object_base::update_tweens()
  45. {
  46. transform.update();
  47. }
  48. void scene_object_base::look_at(const vector_type& position, const vector_type& target, const vector_type& up)
  49. {
  50. transform[1].translation = position;
  51. transform[1].rotation = math::look_rotation(math::normalize(math::sub(target, position)), up);
  52. transformed();
  53. }
  54. void scene_object_base::transformed()
  55. {}