How do you avoid getting angry or upset because you perceived in your mind (and the impression is very strong) they do not want to hire you and you are wasting your time by remaining there
You need to have a positive attitude, always want to learn and patience.
First off, by going to interview you're investing your time (you could say gambling if you don't know the company very well) to have a chance for building relations and spot to work for them. So usually you would be well prepared and try your very best, likewise, they would try to explain company culture and job description and test you if you're a good fit for them. Since an interview is a way for both parties to know each other better.
From my experience, if the company didn't want you it would be caused by one thing or another which are not a good fit for them (either you are not attentive enough for doing detailed task which would be a required skill for your job later on, or you're impatient for doing tedious task which would be your required skill set later on, etc). Even then they would communicate to you the best as they could.
So if you're angry or upset because they do not want to hire you that's a bit unreasonable because you shouldn't be angry with them, but reflect on what you're missing out or didn't do well in the interview. Also, don't be afraid to respond with an alternative answer which isn't the straight-forward answer, because you need to be creative and show effort.
For example, if they say you don't have X skill but you have Y skill. You could try to say, I know I don't have the required skill but if I was given the chance I would be able to learn them and contribute to the company.
Finally, even if the interview is going so bad you could always brush it off as a way to gain experience for what to not do if you got the chance to be the interview later on.
If you can't then you need to practice, learn more about how to do it, and ask professional help.