Modifying the view matrix

Started by
11 comments, last by Trienco 12 years, 6 months ago
Quaternions fit 3D rotations much better then matrices. Especially if you want interpolations.
Advertisement

Quaternions fit 3D rotations much better then matrices. Especially if you want interpolations.


I haven't added a quaternion class yet but it's on my to-do list. I could add one to fix this problem but because I've hit a brick wall in my knowledge with this method I want to know how to solve it this way even if I do end up using quaternions in the future.
I've fixed this and am just adding a reply in case I forget what I did or anyone else comes across this problem.

Basically, Trienco was right in that I needed to rotate the yaw about the world's up axis and this is what I did to achieve that:


//Transpose the rotation portion of the view matrix to get the inverse rotation.
Matrix viewRotation = mView;
mView.SetColumn(3) = Vector(0.0f, 0.0f, 0.0f, 1.0f); //Mask off the translation portion of the view matrix.
Matrix viewRotationInverse = viewRotation.GetTransposed();

Matrix yawRotation = Matrix::CreateYRotation(yawChange);
Matrix pitchRotation = Matrix::CreateXRotation(pitchChange);

//Apply the rotation changes. Rotate the yaw around the world's up axis and the pitch around the local left axis.
mView = viewRotation * yawRotation * viewRotationInverse * pitchRotation * mView;

//Orthonormalise in case of floating point error.
mView.Orthonormalise();

Matrix translation = Matrix44::CreateTranslation(xChange, yChange, zChange);
mView = translation * mView;


I did have some issues with floating point error, which is why the call to Orthonormalise() is required, but other than that it all works fine.

I did have some issues with floating point error, which is why the call to Orthonormalise() is required, but other than that it all works fine.


This might be slightly less of a problem with quaterions (though they still need to be unit length too).

But I'm a big fan of understanding the principle behind it before going "this is too complicated, I'll just copy/paste this quaternion stuff, it's way easier". If dealing with rotation matrices is too complicated for some, how is it easier to deal with multidimensional complex numbers and a theory so unintuitive that the world of math has ditched the whole concept in favour of vectors and matrices over a hundred years ago? They have their uses, but it's kind of depressing when you see people use them for everything, because they're "cool" and end up creating a convoluted and overcomplicated mess by not having any idea what they are doing (and just applying trial and error until it seems to be right). Plus, whatever benefit you get out of them must be worth the overhead of all the conversions.
f@dzhttp://festini.device-zero.de

This topic is closed to new replies.

Advertisement