Bouncing works... Kindof...

Need to fix for bottom and left cases
This commit is contained in:
elipzer 2018-10-17 19:53:36 -04:00
parent d2afef5090
commit 56af508ef4
2 changed files with 31 additions and 0 deletions

View File

@ -16,6 +16,8 @@
#define BALL_THICKNESS 25.0f
#define HALF_BALL_THICKNESS 12.5f
#define PADDLE_SPEED 5.0f
@ -77,6 +79,32 @@ void MyPongScene::update(float delta_time, clock_t clock)
{
m_ball_pose.translate(glm::vec3(m_ball_direction * m_ball_speed * delta_time, 0.0f));
vec3 ball_position = m_ball_pose.get_position();
// Bounce Top and Bottom
if (ball_position.y + HALF_BALL_THICKNESS + OUTLINE_INWARDS > m_screen_size.y / 2.0f)
{
m_ball_direction.y = -glm::abs(m_ball_direction.y);
}
if (ball_position.y - HALF_BALL_THICKNESS - OUTLINE_INWARDS < -m_screen_size.y / 2.0f)
{
m_ball_direction.y = glm::abs(m_ball_direction.y);
}
// Bounce Left Right (temp)
if (ball_position.x + HALF_BALL_THICKNESS + OUTLINE_INWARDS > m_screen_size.x / 2.0f)
{
m_ball_direction.x = -glm::abs(m_ball_direction.x);
}
if (ball_position.x - HALF_BALL_THICKNESS - OUTLINE_INWARDS < -m_screen_size.x / 2.0f)
{
m_ball_direction.x = glm::abs(m_ball_direction.x);
}
m_ball_batch.reset_rendered();
m_ball_batch.add_rendered(m_ball_pose);

View File

@ -27,8 +27,11 @@ namespace charcoal
void rotate(const vec3& axis, float angle);
void set_orientation_matrix(const mat4& orientation_matrix) { m_orientation_matrix = orientation_matrix; }
const mat4& get_orientation_matrix() const { return m_orientation_matrix; }
vec3 get_position() const { return vec3(m_orientation_matrix[3][0], m_orientation_matrix[3][1], m_orientation_matrix[3][2]); }
protected:
mat4 m_orientation_matrix;
};