I'm currently trying to write some code that executes a rotation around an arbitrary point in 3d space around two angles (alpha & delta), where alpha is the rotation around the global y axis and delta is the rotation around the global x axis.
At first I used this piece of code (point is the point to be rotated, origin the point to rotate about):
D3DXMatrixTranslation(&moveToOrigin, -origin.x, -origin.y, -origin.z); D3DXMatrixTranslation(&moveBack, origin.x, origin.y, origin.z); D3DXMatrixRotationY(&yMat, alpha_rad); D3DXMatrixRotationX(&xMat, delta_rad); totalMat = moveToOrigin * xMat * yMat * moveBack; D3DXVec3TransformCoord(&result, &point, &totalMat);
The problem was that I got gimbal lock after e.g. rotating 90 degrees around y first and then rotating around x. Somehow it's clear that this causes a problem, since when I'm rotating around GLOBAL x after having rotated 90 degrees around y won't give any useful results.
Then I tried
D3DXQUATERNION qX, qY; D3DXQuaternionRotationAxis(&qX, &D3DXVECTOR3(1.0f,0,0), delta_rad); D3DXQuaternionRotationAxis(&qY, &D3DXVECTOR3(0,1.0f,0), alpha_rad); D3DXMatrixAffineTransformation(&totalMat, 1.0f, &origin, &(qX*qY), NULL); D3DXVec3TransformCoord(&result, &point, &totalMat);since you can read everywhere sth. like "using quaternions avoids gimbal lock", but obviously in this example DX handles the rotations the same as in the first one, since my rotation problems remain exactly the same with this piece of code.
So how can this problem be solved? Is there an alternative to using global rotation axes? Or how can I get code that properly rotates a point around another given point in 3d space around alpha, delta without any gimbal lock problems?
Thanks & greetings in advance.
Nico.












