# rotating in local object space

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

## Recommended Posts

I need to rotate in the local object space along x or y axis. I have an arbitrary axis and an angle. The Matrix struct has a RotationQuaternion method but it rotates along the axis and I want to rotate along x or y axis depending on user input.

In short, I think I want to implement Yaw,Pitch,Roll in object space instead of world space.

The Rotation methods in the Matrix stuct also rotate in world space. Presently I have this, it rotates fine along z axis.

            view = Matrix.RotationQuaternion(Quaternion.RotationAxis(axis, MathHelper.ToRadians(cameraRotation))) * LookAtMatrix;

So i have an axis vector and I would like to rotate it either in X or Y axis depending on user input.

[Edited by - fkhan on September 28, 2010 9:22:30 PM]

##### Share on other sites
Quote:
 Original post by fkhanThe Rotation methods in the Matrix stuct also rotate in world space. Presently I have this, it rotates fine along z axis.
The rotation methods don't rotate in world space, or in local space; they simply build rotation matrices, which you can use as you please.

You can effect local-space rotations using a yaw-pitch-roll matrix by performing your matrix multiplications in the appropriate order. Just create a YPR matrix with the current x and y rotation delta values as input (you can skip z), and then multiply this with your orientation matrix either on the right or on the left, depending on what convention you're using. (Also, don't forget to orthogonalize/normalize occasionally, or you'll be likely to run into problems with accumulated numerical error.)

##### Share on other sites
The rotations are still off the axis of the model. I am also scaling my world matrix when loading models.

        public void UpdateCamera()        {            Matrix m_lookat = Matrix.LookAtRH(cameraPosition, cameraTarget, up_axis);            Vector3 axis = (sceneBoundingBox.Maximum + sceneBoundingBox.Minimum) / 2f;                                    Matrix m_translation = Matrix.Translation(axis);                        Matrix m_ypr = Matrix.RotationYawPitchRoll(cameraArc, cameraRotation, 0);            Matrix m_transformation = m_ypr * m_translation;                        view = world;            view.Invert();            view *= m_transformation * m_lookat;                        proj = Matrix.PerspectiveFovRH(MathHelper.ToRadians(FOV), 1.0f, 1.0f, 1000.0f);        }

##### Share on other sites
I can't really tell what's going on in your code (at least not without digging into it further), but it looks somewhat suspect to me. It looks like you're using the term 'axis' to refer to a point, and it also looks like you're incorporating an inverse view transform into the combined transform twice. Also, it's not clear from your code how the various transforms you're constructing are actually being used.

Maybe what you're doing makes sense and I'm just not getting it, but otherwise, I think I'd recommend backing up a bit and doing something simpler, such as getting an object with a camera attached simply to move around the scene successfully (if you haven't already done that).

If that's not helpful, perhaps you could post some more of your code and/or describe your problem in more detail.

##### Share on other sites

Well I was able to rotate in object space by. But now If the model is not placed near the origin, it simply does not show up. The cameraTarget is the center of boundingbox of all models in scene. My world matrix is scaled such that it fits the viewing frustum. Still the models do not show in the view.
If i reset the model transformation matrices m values(41,42,43) to zero then it shows up just fine.

Here's a snippet from updateCamera()

            Matrix rotationX = Matrix.RotationX((MathHelper.ToRadians(cameraArc)));            Matrix rotationY = Matrix.RotationY((MathHelper.ToRadians(cameraRotation)));            Matrix rotation = rotationX * rotationY;            Matrix translation = Matrix.Translation(cameraTarget);            Matrix transformation = rotation * translation;            transformation = Matrix.Invert(transformation);            Matrix m_lookat = Matrix.LookAtRH(cameraPosition, cameraTarget, up_axis);            view = transformation* m_lookat;            proj = Matrix.PerspectiveFovRH(MathHelper.ToRadians(FOV), 1.0f, nearclip, farclip);

1. 1
2. 2
Rutin
22
3. 3
4. 4
JoeJ
16
5. 5

• 14
• 29
• 9
• 11
• 11
• ### Forum Statistics

• Total Topics
631775
• Total Posts
3002278
×