add Shot::get_elapsed_time() and Shot::get_duration()
This commit is contained in:
parent
db0704a799
commit
2eeeabcff3
@ -57,11 +57,12 @@ Shot::Shot(const Vector2f & origin, double direction, double target_dist)
|
|||||||
m_speed = target_dist / m_cos_a /
|
m_speed = target_dist / m_cos_a /
|
||||||
sqrt(2 * (target_dist * m_sin_a / m_cos_a + INITIAL_SHOT_HEIGHT) /
|
sqrt(2 * (target_dist * m_sin_a / m_cos_a + INITIAL_SHOT_HEIGHT) /
|
||||||
GRAVITY);
|
GRAVITY);
|
||||||
|
m_duration = target_dist / (m_speed * m_cos_a);
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3f Shot::get_position()
|
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 horiz_dist = m_speed * m_cos_a * time;
|
||||||
float z = INITIAL_SHOT_HEIGHT + m_speed * m_sin_a * time -
|
float z = INITIAL_SHOT_HEIGHT + m_speed * m_sin_a * time -
|
||||||
GRAVITY * time * time / 2.0;
|
GRAVITY * time * time / 2.0;
|
||||||
|
@ -9,6 +9,11 @@ class Shot
|
|||||||
public:
|
public:
|
||||||
Shot(const sf::Vector2f & origin, double direction, double target_dist);
|
Shot(const sf::Vector2f & origin, double direction, double target_dist);
|
||||||
sf::Vector3f get_position();
|
sf::Vector3f get_position();
|
||||||
|
double get_elapsed_time()
|
||||||
|
{
|
||||||
|
return m_clock.getElapsedTime().asSeconds();
|
||||||
|
}
|
||||||
|
double get_duration() { return m_duration; }
|
||||||
protected:
|
protected:
|
||||||
sf::Vector2f m_origin;
|
sf::Vector2f m_origin;
|
||||||
sf::Vector2f m_direction;
|
sf::Vector2f m_direction;
|
||||||
@ -16,6 +21,7 @@ class Shot
|
|||||||
double m_cos_a;
|
double m_cos_a;
|
||||||
double m_sin_a;
|
double m_sin_a;
|
||||||
sf::Clock m_clock;
|
sf::Clock m_clock;
|
||||||
|
double m_duration;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user