add Shot::get_elapsed_time() and Shot::get_duration()

This commit is contained in:
Josh Holtrop 2012-10-13 21:38:50 -04:00
parent db0704a799
commit 2eeeabcff3
2 changed files with 8 additions and 1 deletions

View File

@ -57,11 +57,12 @@ Shot::Shot(const Vector2f & origin, double direction, double target_dist)
m_speed = target_dist / m_cos_a /
sqrt(2 * (target_dist * m_sin_a / m_cos_a + INITIAL_SHOT_HEIGHT) /
GRAVITY);
m_duration = target_dist / (m_speed * m_cos_a);
}
Vector3f Shot::get_position()
{
float time = m_clock.getElapsedTime().asSeconds();
float time = get_elapsed_time();
float horiz_dist = m_speed * m_cos_a * time;
float z = INITIAL_SHOT_HEIGHT + m_speed * m_sin_a * time -
GRAVITY * time * time / 2.0;

View File

@ -9,6 +9,11 @@ class Shot
public:
Shot(const sf::Vector2f & origin, double direction, double target_dist);
sf::Vector3f get_position();
double get_elapsed_time()
{
return m_clock.getElapsedTime().asSeconds();
}
double get_duration() { return m_duration; }
protected:
sf::Vector2f m_origin;
sf::Vector2f m_direction;
@ -16,6 +21,7 @@ class Shot
double m_cos_a;
double m_sin_a;
sf::Clock m_clock;
double m_duration;
};
#endif