Right now I'm using this function:
Code:
bool planeCollision2d(vector2 plane1, vector2 plane2)
{
vector2 vec;
vec = plane1 - plane2;
if(vec.dot_product(normalized(plane1)) > 1)
{
return false;
}
else return true;
}
In this way:
Code:
void check_paddle_collision()
{
if (planeCollision2d(border.topLeft, player1->paddle->getMaximum()))
{
player1->paddle->getLocation().y = 70;
}
else if(planeCollision2d(border.bottomLeft, player1->paddle->getMinimum()))
{
player1->paddle->getLocation().y = -70;
}
if (planeCollision2d(border.topRight, player2->paddle->getMaximum()))
{
player2->paddle->getLocation().y = 70;
}
else if(planeCollision2d(border.bottomRight, player2->paddle->getMinimum()))
{
player2->paddle->getLocation().y = -70;
}
}
And everything appears to be working.
Is there anything wrong with what I'm doing?