# HPB rotation to rotation around axis

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 05/11/2003 at 15:51, xxxxxxxx wrote:

Hi,

how can I convert rotation of object (obtained using GetRot(), i.e. HPB vector) to rotations around x,y,z axis? I've been trying to do it this way:

Matrix mrz = Matrix::rotateZ(rz);
Matrix mry = Matrix::rotateY(ry);
Matrix mrx = Matrix::rotateX(rx);
return mrz * mry * mrx;

where the matrices are 4x4 OpenGL matrices and rotate{X,Y,Z} are rotations around axis X, Y and Z respectively and the argument is in radians. It's same as this sequence of OpenGL calls:

Is this correct or does Cinema4D use different semantics? I can't make it work...

Thanks!

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 21/11/2003 at 07:47, xxxxxxxx wrote:

Why use XYZ rotations? GL directly allows to set a Matrix. (If you still need the rotation thingy, take a look at GraphicsGems 4, they have source code for calculating rotations from a matrix).
Matrix mg=op->GetMg();
Real c;
c = mg.v1.x;
c = mg.v1.y;
c = mg.v1.z;
c = 0;
c = mg.v2.x;
c = mg.v2.y;
c = mg.v2.z;
c = 0;
c = mg.v3.x;
c = mg.v3.y;
c = mg.v3.z;
c = 0;
c = mg.off.x;
c = mg.off.y;
c = mg.off.z;
c = 1;

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 22/11/2003 at 04:35, xxxxxxxx wrote:

Quote: _Why use XYZ rotations? GL directly allows to set a Matrix.
>
> * * *
_

Why, because I need them, I didn't say I'm using OpenGL. Besides, the matrix would still not be usable in OpenGL because c4d uses left-handed coordinate system and OpenGL uses right handed-one.

I figured it out in the meantime, so in case anybody ever needs something similar, it's like this:
C4d uses left-handed system. HPB rotation translates to rotation about axes in this way: H is rotation around (0,-1,0) axis (y-axis, the angle is negated), P around (-1,0,0) and B around (0,0-1). Accounting for OpenGL's right-handed system, the rotations will become
rx = p
ry = h
rz = -b
When applying the rotation, the order is rotY(ry)*rotX(rx)*rotZ(rz)