Bouncing works... Kindof...
Need to fix for bottom and left cases
This commit is contained in:
parent
d2afef5090
commit
56af508ef4
@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
#define BALL_THICKNESS 25.0f
|
#define BALL_THICKNESS 25.0f
|
||||||
|
|
||||||
|
#define HALF_BALL_THICKNESS 12.5f
|
||||||
|
|
||||||
#define PADDLE_SPEED 5.0f
|
#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));
|
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.reset_rendered();
|
||||||
m_ball_batch.add_rendered(m_ball_pose);
|
m_ball_batch.add_rendered(m_ball_pose);
|
||||||
|
|
||||||
|
@ -27,8 +27,11 @@ namespace charcoal
|
|||||||
void rotate(const vec3& axis, float angle);
|
void rotate(const vec3& axis, float angle);
|
||||||
|
|
||||||
void set_orientation_matrix(const mat4& orientation_matrix) { m_orientation_matrix = orientation_matrix; }
|
void set_orientation_matrix(const mat4& orientation_matrix) { m_orientation_matrix = orientation_matrix; }
|
||||||
|
|
||||||
const mat4& get_orientation_matrix() const { return m_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:
|
protected:
|
||||||
mat4 m_orientation_matrix;
|
mat4 m_orientation_matrix;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user