aboutsummaryrefslogtreecommitdiff
path: root/sons_of_sol/Updaters.hpp
blob: e2e8b2d7cb47d21dd4106a3a0ba1731f82a09b8f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#ifndef UPDATERS_HPP_
#define UPDATERS_HPP_

/*
 * Author: jrahm
 * created: 2013/12/08
 * Updaters.hpp: <description>
 */

#include "glox/GloxCommon.hpp"
#include "glox/GloxPoint.hpp"
#include "sons_of_sol/AIShip.hpp"

class EllipseUpdater : public AIShip::Updater {
 public:
  inline EllipseUpdater(const glox::GloxPoint<>& center,
                        const glox::GloxPoint<>& major,
                        const glox::GloxPoint<>& minor, float speed_factor)
      : m_center(center),
        m_major(major),
        m_minor(minor),
        m_speed(speed_factor) {
    m_a = major.getMagnitude();
    m_b = minor.getMagnitude();
  }

  inline glox::GloxPoint<> update(uint32_t time) {
    float t = m_speed * time;
    return m_center + (m_major * m_a * glox::GloxCos(t) +
                       m_minor * m_b * glox::GloxSin(t));
  }

 private:
  glox::GloxPoint<> m_center;
  glox::GloxPoint<> m_major;
  glox::GloxPoint<> m_minor;

  float m_a;
  float m_b;
  float m_speed;
};

#endif /* UPDATERS_HPP_ */