 # Question on locking rotation with matrices

From the wikipedia article on rotation matrices I gathered that rotations about the z-axis have the form:

``````cos(theta) -sin(theta) 0
sin(theta)  cos(theta) 0
0           0          1
``````

Is taking a matrix for a rotation in all three dimensions and setting the 0s and 1s an appropriate way to lock the rotation to the z-axis? It basically works, but seems inelegant.

You should read the complete article. This is a matrix for a rotation around one axis. To be more specific the z-axis. This has nothing to do with locking. The 3D Engine calculates the rotation by multiplying the rotation matrices for all three axis. The order of the multiplication determines the final orientation in space.

Usually you do not need to care the transformation matrices. The BGE is doing that for you.

You might want to explain what you want to achive. What object should do what?
There is often a very simple solution out there ;).

Monster

I suggest:

``````gameObject.applyRotation([0,0,YawAngle],flag)
gameObject.applyRotation([0,PitchAngle,0],flag)
gameObject.applyRotation([RollAngle,0,0],flag)
``````

in order to lock rotations around z, y, or x-axis respectively.
“flag” is an integer indicationg whether the rotation occurs around local (flag=1) or global (flag=0) axis. Angles are in radians.
Please note that rotations are incremental.

mb

I have a mouse look script that rotates on the z and x axes, but I want my character to only rotate on the z-axis. I don’t want to directly control the character’s orientation with mouse movement, but it might work out better.

How do people usually do this?

Ah, thank you SolarLune. Eulers may be just what I need. I saw the class in the mathutils docs, but didn’t quite understand them :S

So I read a bit on Euler’s rotation theorem (thank you wikipedia). It helps to see how all of these are related.

Perfect!