# How do I extract the x angle from a rotation matrix

This topic is 4964 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I want to be able to limit my camera rotation so that I can only look up and down, which I believe is related to the X axis. To do this I need to extract the X angle from a rotation matrix. What maths do I need to do to achieve this? I'm trying to do this in VRML if interested. Thanks!

##### Share on other sites
A simple way would be to apply the matrix to a unit vector, and use trig n the result to calculate any angles you need. I'm sure there's another "proper" way of doing it.

The best thing would generally be to limit the angles before creating the rotation matrix in the first place. Then you avoid this problem entirely.

##### Share on other sites
It's a complete rotation matrix already that's why I need to extract it as I'm suck with it.

I need something like the below but for the x axis, but I don't know the maths to make it. Thanks!

function set_rotation (r)
{
// gets the Y axis
angle = -Math.atan2(r.x * r.z * (1 - Math.cos(r.angle)) +
r.y * Math.sin(r.angle), r.z * r.z * (1 - Math.cos(r.angle)) +
Math.cos(r.angle) );
rotation_changed = angle;
}

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 13
• 9
• 15
• 14
• 46
• ### Forum Statistics

• Total Topics
634060
• Total Posts
3015300
×