Broken Quaternion Camera
I've been working on various cameras for the last 2 months or so, but my QuatCam has been giving me relentless headaches.
If I am looking at an object from the front, it works well, and there is no Z rotation when using the "circular mouse" motion. However, when I look at an object from the side (along the x-axis) it appears to resort back to rotating. I am using two quaternions to rotate, one quat to store the rotation (quat) and one to store the change (dquat). If it helps at all, I update my camera like so:
//dquat->z = 0;
//dquat->Normalize();
quat->MultQuat(dquat);
//quat->z = 0;
//quat->Normalize();
Matrix4f rotation;
quat->GetMatrix(rotation);
Matrix4f translation = {
1,0,0,0,
0,1,0,0,
0,0,1,0,
position[0],position[1],position[2],1};
MultMatrix(rotation, translation, matrix);
The way I have it here, it works just like a regular quat should (the palm of your hand example can be seen: rotation around the "toward" axis). If I uncomment one or both of the zeroing parts, I do get normal behaviors if I do not move, but when I move to look at the side (or back even if both are uncommented) of an object, the rotations are thrown off.
I tested the quat order multiplication but that doesn't seem to be it. I seem to have located where the problem is coming from, but I'm not exactly sure how to fix it. My yaw and pitch functions look something like this:
void Camera::Pitch(float f) {
Vector4f axis = {f, 1, 0, 0};
dquat->FromAxisAngle(axis);
UpdateVectors();
}
void Camera::Yaw(float f) {
Vector4f axis = {f, 0, 1, 0};
dquat->FromAxisAngle(axis);
UpdateVectors();
}
It makes sense to me that this may be the source of my problems, as I am using constants in the creation of the quaternion. Though I'm not exactly sure what should be done about it or if it is, in fact, correct. The reason I think that this may be the source of my problems is that if I look forward at the object, the rotations appear to be fine. If I strafe to the side of the object (looking down the negative x axis), the vertical rotation appears to work, but the pitching from the original location of the camera is there as well. Also, if I look at the back of the object (the opposite direction I was initially facing), there doesn't appear to be any vertical movement at all, as the vertical pitch from the back seems to cancel out the vertical pitch from the front.
If you're a code zealot, interested in helping, looking for a free quatcam, or just bored at work, my source is available here.
Thanks for reading all that! [wink]
I do real things with imaginary numbers
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement