From 2eeeabcff3ddbe66e592762e0087f624372305d1 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Sat, 13 Oct 2012 21:38:50 -0400 Subject: [PATCH] add Shot::get_elapsed_time() and Shot::get_duration() --- src/common/Shot.cc | 3 ++- src/common/Shot.h | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/common/Shot.cc b/src/common/Shot.cc index e437175..fa9618f 100644 --- a/src/common/Shot.cc +++ b/src/common/Shot.cc @@ -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; diff --git a/src/common/Shot.h b/src/common/Shot.h index 7f22fb6..c1c97a5 100644 --- a/src/common/Shot.h +++ b/src/common/Shot.h @@ -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