Slope collision and openGL
I've got a pinball machine (a very lame one, but the point is to make it work as an assignment). I made the collisions with the sides and the top arch work, but i'm having trouble with two slopes at the bottom of the machine.
No matter how fast the ball comes in, the ball just sticks to the slope and slides along.
How can I make it bounce, like it does when it hits a vertical wall?
This is the piece of collision code:
Code:
if ( ypos <= (12.0+tan(alpha)*(xpos-33.0)) + R_ball/cos(alpha) & some other conditions )
{
phi = 0.5*M_PI + alpha;
theta = phi + atan(vx/vy) - 0.5*M_PI;
cosphi = cos(phi);
sinphi = sin(phi);
costheta = cos(theta);
v = sqrt( pow(vx, 2) + pow(vy, 2) );
vy = vy + 1.0*v*costheta*sinphi;
vx = vx + 1.0*v*costheta*cosphi;
}
(12.0+tan(alpha)*(xpos-33.0)) describes the line of the slope, so if y is smaller or equal to this value, the ball must change its speeds and direction, that's what the vy= and vx= do.
The way i read it now, it should work, but it doesnt. Does anyone know why?