#### Archived

This topic is now archived and is closed to further replies.

# view matrix quaternion rotation

This topic is 5421 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 rotate the view with quaternions...but somethings wrong with my code: -------------------------------------------------------- public void RotateCamera(float xAngle, float yAngle) { device.Transform.View = initialMatrix; Vector3 rightAxis = new Vector3(initialMatrix.M11, initialMatrix.M21, initialMatrix.M31); rightAxis.Normalize(); Vector3 upAxis = new Vector3(initialMatrix.M12, initialMatrix.M22, initialMatrix.M32); upAxis.Normalize(); Quaternion rotationRight = new Quaternion(rightAxis.X, rightAxis.Y, rightAxis.Z, xAngle); Quaternion rotationUp = new Quaternion(upAxis.X, upAxis.Y, upAxis.Z, yAngle); Quaternion rotation = Quaternion.Multiply(rotationRight, rotationUp); device.Transform.View *= Matrix.RotationQuaternion(rotation); } ------------------------------------------------- my idea: from the current view matrix, get the right vector (m11, m21, m31) and the up vector (m12, m22, m32)...just yaw and pitch, no roll...now i want to use quaternions to rotate about the right vector and the upvector and finally the view matrix about the product of both quaternions... language is c#...

##### Share on other sites
Why not do this?

Use the matrix to quaternion function to get the quaternion.

Create a rotation quaternion using the yawPitchRoll function.

Multiply them

and then convert it back to the rotation matrix.

That should do what you are looking for.

##### Share on other sites
If you''re multiplying the view matrix in place, couldn''t you just multiply it directly by the matrix generated by the quaternion?

"Sneftel is correct, if rather vulgar." --Flarelocke

##### Share on other sites
@ataru

which matrix should i convert to a quaternion?...my problem ist the update of the view matrix: th camera rotates as long as the user presses the right mouse button...when he releases the mouse button, i have to update the view matrix, so i set the initialmatrix from the code to the actual view matrix...but: the control "flips" when i press the right mouse button again...so before for a left to right rotation i moved the mouse from left to right...now from right to left...and, after the update, the view "jumps" to another position...everything works fine as long as i rotate the view...

is the general concept right?...

##### Share on other sites
You convert your view matrix to a quaternion. And for each mouse press, multiply the rotation quaternion by the one obtained from the view.

Then convert it back into a matrix, and set that matrix as your view.

ok, i''ll try it

1. 1
2. 2
3. 3
Rutin
13
4. 4
5. 5

• 26
• 10
• 9
• 9
• 11
• ### Forum Statistics

• Total Topics
633696
• Total Posts
3013394
×