Skip to main content
gamedev.net
🔒 Locked 🎮 Unity

Free camera

Started by jviruss 0 replies 600+ views
Original Post
jviruss
jviruss
Hello!!!,I have a new problem. I want do a free camera.To avoid the gimbal lock I thinked do it with quaternions the I did the next code: -------------------------------------------------- void FreeCamera::Yaw(float units) { Quaternion q1 = camera->GetOrientation(); Quaternion q2 = Quaternion::FromAxisRotation(units,Vector3(0,1,0)); q1 = q1*q2; camera->SetOrientation(q1); }; -------------------------------------------------- My Question is: If I have a quaternion with the camara rotation and I multiply this by a quaternion rotated by a angle from a axis,then the result of multiply the first by the second is as increment the rotation,it isn´t? If it is,why I have rare effects?,The camera rotate,but when I ´m in certain angle,the camera begin to rotate in another axis. Which is the problem???Somebody can explain me and give the solution. Very Thanks.
Zakwayda
Zakwayda
Quote:
Original post by jviruss
Hello!!!,I have a new problem.
I want do a free camera.To avoid the gimbal lock I thinked do it with quaternions the I did the next code:
The usual correction: whether you use quaternions and whether you're likely to encounter gimbal lock have absolutely nothing to do with each other. (Search the forums for 'quaternion gimbal lock' and you'll find a number of other threads on this topic.)
Quote:


--------------------------------------------------
void FreeCamera::Yaw(float units)
{
Quaternion q1 = camera->GetOrientation();
Quaternion q2 = Quaternion::FromAxisRotation(units,Vector3(0,1,0));
q1 = q1*q2;
camera->SetOrientation(q1);
};
--------------------------------------------------

My Question is:

If I have a quaternion with the camara rotation and I multiply this by a quaternion rotated by a angle from a axis,then the result of multiply the first by the second is as increment the rotation,it isn´t?

If it is,why I have rare effects?,The camera rotate,but when I ´m in certain angle,the camera begin to rotate in another axis.

Which is the problem???Somebody can explain me and give the solution.

Very Thanks.
Assuming standard quaternion multiplication order, it looks like your function applies a rotation about the local up axis (I assume you have similar functions for 'side' and 'forward'). This will give you 'free' 6DOF motion. (Note that you'll want to normalize your orientation quaternion occasionally to prevent drift.)

Now, I'm not sure from your description what the problem is, but keep in mind that with free rotation, accumulated yaw and pitch can result in perceived roll (relative to, say, the ground plane). If this isn't the behavior you want, then maybe 6DOF isn't really what you're looking for.

Can you describe the desired behavior?

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.