"One" thing that may have happened (really a combination of many) is that after studying intently you began to either hyperventilate or have an anxiety attack from holding your breath. The intense studying was fresh in your mind and may also have triggered your mind/thoughts... and when you passed out from holding your breath (without realizing you were) it created the "dream"... the time/space continuum regarding the mind and dreams is unfathomable...happens in split seconds.... the good feelings could have come from increased endorphin activity from the experience, thus creating the good feelings.
Not saying that is what happened, just giving a brief idea.