When you straighten your leg, the quadricep muscles pull on the quadricep tendon, which pulls the kneecap to make the knee extend. When you bend it, the hamstring muscles contract and pull the tibia backward, causing the knee to flex.