So I'm new to working with a 3D space and not sure how to fix my problem, I basically have a turret that rotates along its Z axis, and pitches along it's Y but after rotating 180 on the Z axis the turret points down as I completely understand despite being unexpected.
I have a fiddle with what I'm working on here https://jsfiddle.net/2v4ezmaz/2/
So the question is, how do I make it rotate like it does in blender where the barrel end stays pointing up while rotating the z? After lots of reading it's all to do with cross vectors since the .rotation property is euler angles which I think is my problem. I need to use quaternions but I can't logically see what needs to happen.
My brain is thinking of it as needing to reset the rotation back to its default then apply Z rotation and apply the Y rotation, but that can't be right.
After reading http://blog.wolfire.com/2010/07/Linear-algebra-for-game-developers-part-4 I'm sure my answer is there somewhere but I cant think what the code needs to be to do what i want.
Any pointers would be super helpful since my brain is fried reading/trying vector and matrix rotations.