Hello everyone.

Yes, that's another camera rotation question Maybe I'm overlooking something, but anyways.

Problem #1:

When I rotate my camera around global Y, everything is OK untill it reaches the point of -90 or +90 degrees from initial rotation. Then suddenly it jumps right to the 180 degrees opposite!

Problem #2:

The unwanted rolling. I am rotating my camera around global Y for yaw and around camera's local X for pitch.

Yet, I am getting the roll. I've tried to use scene graph here to eliminate roll by attaching camera to a series of scene nodes: one for yaw, one for pitch; but there was no good.

________________

My code regarding rotations::

Quaternion::Quaternion( const Vector3f& axis, const float degrees ) { float radian = RADIANS( degrees ) * 0.5f; float sinHalf = std::sin( radian ); float cosHalf = std::cos( radian ); Vector3f a = axis.GetNorm(); this->x = a.x * sinHalf; this->y = a.y * sinHalf; this->z = a.z * sinHalf; this->w = cosHalf; } void Transform::RotateAxisAngle( const Vector3f& axis, const float degrees ) { Quaternion q( axis, degrees ); rotation = q * rotation; rotation.Normalize(); } Matrix4f Quaternion::GetRotationMatrix() const { Matrix4f R; R.InitIdentity(); R.m[0] = 1 - 2 * y * y - 2 * z * z; R.m[1] = 2 * x * y - 2* z* w; R.m[2] = 2 * x * z + 2 * y * w; R.m[4] = 2 * x * y + 2 * z * w; R.m[5] = 1 - 2 * x * x - 2 * z * z; R.m[6] = 2 * y * z - 2 * x * w; R.m[8] = 2 * x * z - 2 * y * w; R.m[9] = 2 * y * z + 2 * x * w; R.m[10] = 1 - 2 * x * x - 2 * y * y; return R; }

The above works fine, however, the following code might been screwing up something.

The code regarding camera matrices:

// this is called every frame, t is the reference to the parent's transformations; // V is the View matrix void Camera::Update( const core::Transform& t ) { core::Matrix4f R; R.InitCamera( t.GetForward(), t.GetUp() ); core::Matrix4f T; T.InitTranslation( t.position * -1.0f ); V = R * T; } core::Matrix4f Camera::GetVP() { return P * V; } // this is projection matrix: void Matrix4f::InitPerspective( const float fov, const float aspect, const float near, const float far ) { float tanHalfFov = std::tan( RADIANS( fov/2.0f ) ); float range = near - far; InitIdentity(); m[ 0 ] = 1.0f / ( tanHalfFov * aspect ); m[ 5 ] = 1.0f / tanHalfFov; m[ 10 ] = ( -near - far ) / range; m[ 11 ] = 2.0f * far * near / range; m[ 14 ] = 1.0f; m[ 15 ] = 0.0f; } // this is camera matrix: void Matrix4f::InitCamera( const Vector3f& forward, const Vector3f& up ) { Vector3f f = forward.GetNorm(); // actual normalized forward Vector3f r = up.GetNorm(); r = r.Cross( f ).GetNorm(); // actual right vector Vector3f u = f.Cross( r ).GetNorm(); // recalculated up InitIdentity(); m[ 0 ] = r.x; m[ 1 ] = r.y; m[ 2 ] = r.z; m[ 4 ] = u.x; m[ 5 ] = u.y; m[ 6 ] = u.z; m[ 8 ] = f.x; m[ 9 ] = f.y; m[ 10 ] = f.z; }

So, I suppose that the problem is coming from the View-Projection or Projection separately.

Could anyone help me to determine what the error exactly is ?

How do I eliminate unwanted rolling properly?

Thanks in advance.

_____

P.S.

1) Object rotations are working just fine. Only the camera rotations are screwed up.

2) My 4x4 matrices elements arranged like this ( they are one-dimensional arrays of float ):

| 0 1 2 3 |

| 4 5 6 7 |

| 8 9 10 11 |

| 12 13 14 15 |

My quaternions' elements are placed like the following:

x, y, z, w

3) Transform aggregates within itself Vector3 for position and scaling and Quaternion for rotation.

So, all my GameObjects have the Transform component.

4) Camera is implemented as a component and can be attached to any GameObject to inherit it's transformations.

Camera utilizes Matrix4f class.