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

57 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 "samara-system.hpp"
  20. #include "game/components/transform-component.hpp"
  21. #include "game/components/samara-component.hpp"
  22. #include "math/math.hpp"
  23. #include "utility/fundamental-types.hpp"
  24. using namespace ecs;
  25. samara_system::samara_system(entt::registry& registry):
  26. entity_system(registry)
  27. {}
  28. void samara_system::update(double t, double dt)
  29. {
  30. registry.view<samara_component, transform_component>().each(
  31. [&](auto entity, auto& samara, auto& transform)
  32. {
  33. samara.angle += samara.chirality * math::radians(360.0f * 6.0f) * dt;
  34. transform.local.translation += samara.direction * 20.0f * (float)dt;
  35. transform.local.rotation =
  36. math::angle_axis(samara.angle, float3{0, 1, 0}) *
  37. math::angle_axis(math::radians(20.0f), float3{1, 0, 0}) *
  38. ((samara.chirality < 0.0f) ? math::angle_axis(math::radians(180.0f), float3{0, 0, -1}) : math::quaternion<float>{1, 0, 0, 0});
  39. if (transform.local.translation.y < 0.0f)
  40. {
  41. const float zone = 200.0f;
  42. transform.local.translation.x = math::random(-zone, zone);
  43. transform.local.translation.y = math::random(100.0f, 150.0f);
  44. transform.local.translation.z = math::random(-zone, zone);
  45. transform.warp = true;
  46. samara.chirality = (math::random(0.0f, 1.0f) < 0.5f) ? -1.0f : 1.0f;
  47. }
  48. });
  49. }