I might add that it's really not healthy to tie your sense of self-worth to how you are performing in a class. Everyone who really pushes themselves will get to a point where they feel challenged or even overwhelmed and sometimes burned out.
Also, you could be hitting the undergraduate "wall" - something that happens to most students at some point.
All through high school, those students who have an affinity for STEM subjects tend to do quite well in them, often without much effort. That's because they're more-or-less taking classes with the general population. In that pool it's relatively easy to come out on top through natural aptitude.
Then they get to university and go through a bottleneck because people who didn't do well in these subjects in high school tend not to study them in university. As they move from year to year through undergrad, they keep passing through similar bottlenecks. The course material gets more challenging, their peers get sharper, and the instructors more specialized.
That's not to mention the outside factors of students acclimatizing to life on their own and learning to take care of themselves, or "how to adult" properly. Sometimes, when you have a demanding schedule all it takes is a single wrench in the works to throw you off--noisy neighbors, getting sick, landlord raises your rent forcing you to work an extra shift per week at a part-time job, a professor whose teaching style you don't jive with--and all of a sudden you go from on top of things to struggling just to keep your head above water.
There's also a tendency to get buried by material you "have to" learn about, leaving no time for the material you "want to" read about. All of a sudden your passion starts to dwindle. (One secret to getting around this is making time for your own independent reading. It's NOT wasted time.)