rotateObject() changes the coordinate system

I need some brainextension here. I hope you can understand what I am struggling with. Or at least explain me, why it is better like the way it is.
How can I rotate objects around the x axis and afterwards around the z axis or vice versa and get the same object orientation at the end? For me the sequence of these two operations should not matter. Please explain me why it does, and maybe how to get around it.
The coordinate system used byplacedObject()
stays in the initial orientation. If I do rotation calculations to move objects its getting very difficult to still use therotateObject()
function. But I have to, because I cannot extract the coordinates out of a 3D object and redraw it point by point. (code shared)

@spikey I might be misinterpreting but are you wanting one object to rotate and move around another object like how planets rotate around the sun?

3D rotations are done with transformation matrices. Multiplying by matrix being noncommutative (a * b has a different result than b * a) is just an intrinsic property of the math used.
So the short answer is, you can't. You always have to perform the rotations in the same order.

@Tratax you can absolutely look at it this way. What you are saying is the end target. Just use cubes instead of spheres. So not only the coordinates rotate, but also the cube itself. Therefore the coordinate sytem of both rotations need to have the same orientation. And the example shows that they change.

@Mincus you are right. I rechecked. I was wrong. They do not have to be oriented in the same way afterwards. Can you tell me if the rotation matrices are depending on the orientation of the coordinate sytem. Maybe i got matrices for thewrong coord system.

I use this rotation matrices:
I will provide more details, tonight.

This post is deleted!

I have two examples of this in my Robo 3D game.
Basically i took and scaled up the sin/cos demo code and then used the angle variable to control the direction and position of x/y movement, I then set the cameras position behind it and then rotated it around the player object, rotation of the player object was then adjusted so the player would rotate with the camera
I was thinking about putting an orb spinning around the players position but I'm waiting for the next patch as I suspect we'll have some new 3D functions
Eitherway, feel free to check the demo out!
SW818490599116

@Tratax thank you for your answer, I will check the example. And I came to a similar conclusion according to your orbidea (would love it): currently its super hard to spin an object in sync with an object in a certain distance, only using the functions we have in 3D. But I thought if I only get the math right, I could achieve it.
So, I end up that all code I check, FUZE or mine, is correct: e.g.
rotateObject()
> axis: OK, rotation: righthanded: OK the matrices above > righthanded: OK
 my own matrice multiplcation functions > checked with online calculator examples: OK
..so the only possibilities left is: I still have the math wrong or it is not possible yet. So, I recheck the math, part by part.

SW446496320709
My head is rotating. But my customObjects are just swirling. Maybe some one can spot the problem.

This post is deleted!

@spikey Awesome work! Mind sharing up the code? Curious to see how you've done this

@Tratax Yes, its shared, you should have a friend request hanging ;)
Actually, its not usefull yet, because I can not find out how to handle the selfrotation axis of the red object. In my cube game, I did this with ifs: if rotx, roty, rotz = 270/180/or what ever then switch rot axis of rotateObject() to {0,1,0} or what ever. But then the complexity blew off the roof when I joined 3D objects. So, I started this test program above to get the maths right first.

Isolation of the problem for the blue object (I updated the shared code as well):
I would like to use the same axis for rotation in C as in A.I try now to find out how to rotate my inital axis manually so it fits the axis used by rotateObject(). the other way would be to switch the rotation axis in the parameter of rotateObject().
I still have no clue, so if you know how to do it, I would be happy for any help.
Probably its just a small operation, but just cant see it. Thanks.

@Tratax thanks for letting me have a look. This was smart to put the cam behind the object, because the objectsaxis are always oriented like one is sitting in it. Though I can not use that principle, when having multiple objects. I give it another go. By the way, I like your wellthoughtout splash screen and design from pong, as well. Nice style.

code updated:
I could find a bug in the matrixmultiplication and found a way to revert the rotation on the blue rectangular cuboid. So, if I press j.left its left side is moving down (rotating around the old z, even after rotating it first around the yaxis.
But if I do only a 45° rotation the yaxis it swirls around its length axis. (?) Anyone knows somebody working with robotics?

I almost gave up. So, I would like to share that, to shorten your path, if you decide to do some 3D. I found out that there is a local coordinate system and global coordinate system if you program a 3D scene. (If you knew it, don't tell me now ;))
If you want to rotate multiple objects you have to track the rotation changes for every object to be able to call the rotateObject() for each object with the appropriate axis.It would be very helpful to have a rotateObjectGlobal() function that rotates all objects according to the global coordinate system.

@spikey This is a truly impressive series of posts, we commend you massively for this, showing your working out  it's awesome to see.
You're going to love (or maybe hate!) a few new functions coming in the next patch ;)

Thank you :) I am glad if this is interesting for others as well. Hey, I can imagine what you mean, haha, but the patch I am gonna love any way.

To be able to reuse the code I put it into a rotateCustomObject(customObjectHandle, axis, angle) function. And shared it (SW446496320709), if you are interested.
Maybe I will have to update it, because the movement was not tested yet, and I think also of being able to set a rotation origin :)
If you find bugs, thanks for the feedback  if you have a suggested fix, go ahead, thanks.