Original Post
I'm having trouble with, what I believe is, the rounding of angles in my C++ Pong clone.
I implemented a Ball with a velocity and an angle. The velocity is its current speed, and the angle is theta of the circle. The problem is when I test if I hit a barrier:
When the ball first starts moving (angle = 0, velocity = 1) it hits the right side of the screen and then has its angle = -180. The problem is that after it sets its angle to -180, the Y values start to decrease (which shouldn't happen since sin(-180) = 0).
I implemented a Ball with a velocity and an angle. The velocity is its current speed, and the angle is theta of the circle. The problem is when I test if I hit a barrier:
int x = location->getX() + cos(angle * PI / 180) * velocity;
int y = location->getY() + sin(angle * PI / 180) * velocity;
if (x < 0 || x > 1024)
{
angle -= 180;
}
if (y < 0 || y > 768)
{
angle -= 180;
}
location->setX(x);
location->setY(y);When the ball first starts moving (angle = 0, velocity = 1) it hits the right side of the screen and then has its angle = -180. The problem is that after it sets its angle to -180, the Y values start to decrease (which shouldn't happen since sin(-180) = 0).