# Orbiting object around local axis of another one with GLM.

Hi,
I’ve got problem trying to rotate object based on the second one rotation. I read a lot of internet’s posts about translating, rotating, translating, changing order of translations does nothing in this case.
I’ve got a few object (for example 4, representing local coordinates systems) and with the rotation of the one local coord. system by local axis i want next ones to follow this rotation, for example:

1. Rotate 2nd coo. system by the value of “qz” (done by quaternions) by local x Axis.
2. Rotate 3rd co. system by the same angle and by the same axis (2nd system’s local x Axis), that it would look like it was orbiting 2nd coo. system.
3. Rotate 4th co. system like 3rd, but of course, the orbit should be different.

For now, i try to rotate only 2 local coordinates systems.
My code, axisModel is the first local coordinate system:

``````
x = sin(qx / 2);
y = sin(qy / 2);
z = sin(qz / 2);
w = cos(qw / 2);
quat Quaternion = quat(w, x, z, y);
mat4 quaternionRotationMatrix = toMat4(Quaternion);
axisModel = axisModel * quaternionRotationMatrix;

``````

now the part to rotate second coordinate system, axisMVPs[currentPart] is second coordinate system:

``````			tempResultAxis = axisMVPs[currentPart].ModelMatrix;
xAxis.x = axisModel;
xAxis.y = axisModel;
xAxis.z = axisModel;

yAxis.x = axisModel;
yAxis.y = axisModel;
yAxis.z = axisModel;

zAxis.x = axisModel;
zAxis.y = axisModel;
zAxis.z = axisModel;
double x = 0, y = 0, z = 0;
x = -tempResultAxis;
y = -tempResultAxis;
z = -tempResultAxis;
tempResultAxis = glm::translate(tempResultAxis, vec3(-(x + axisModel), -(z + axisModel), -(y + axisModel)));
tempResultAxis = glm::rotate(tempResultAxis, qz, yAxis);
tempResultAxis = glm::rotate(tempResultAxis, qy, zAxis);
tempResultAxis = glm::rotate(tempResultAxis, qx, xAxis);
tempResultAxis = glm::translate(tempResultAxis, vec3((x + axisModel), (z + axisModel), (y + axisModel)));

axisMVPs[currentPart].ModelMatrix = tempResultAxis;

``````

It gives me unpredictable movement of second model, if it is not in the same position of first local coordinate system - if they have the same xyz coordinates and their axes are parallel, they work perfectly. What is wrong with my code? 