Orthonormalizing the camera/scene?

Started by
3 comments, last by kersh 23 years, 6 months ago
This problem I am having seems like a problem that should be talked about more, but I can''t find the information anywhere! You know in QuakeIII when you look freely around the world with the mouse? The scene always has the correct up vector; the scene never tilts after a few circles of the mouse. My games seem to have this problem. How can this be fixed? Does anyone know how to fix this? Does anyone know what I am talking about? =) thanks, --Jeff
Advertisement
By the way... I am using D3D, but the answer should closely be the same on any API..

--Jeff
Simple:

When you compute your view matrix you do it like this:

View = Translate(-Pos) * RotateY(-Yaw) * RotateX(-Pitch);

This will produce a view matrix that doesn''t roll around the z-axis, i.e when Pitch = 0 the camera-up will always be aligned with the world-up.

If you want to add a tilt to the camera afterwards (for example when hit) you just do this:

View = View * RotateZ(-Roll);

- WitchLord

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Hey WitchLoard:

My view matrix is computed simularly to what you stated:

// Hast to be in this order
ViewMatrix = RotationMatrix * TranslationMatrix;

I create my rotation matrices like this:
// Rotate Entire cube
void Rubik::RotateBy( float x, float y, float z )
{
static D3DMATRIX MatrixX, MatrixY, MatrixZ;

FLOAT fCos, fSin;

if( x != 0 )
{
fCos = (FLOAT)cos( x );
fSin = (FLOAT)sin( x );

MatrixX._11 = 1.0f; MatrixX._12 = 0.0f; MatrixX._13 = 0.0f; MatrixX._14 = 0.0f;
MatrixX._21 = 0.0f; MatrixX._22 = fCos; MatrixX._23 = fSin; MatrixX._24 = 0.0f;
MatrixX._31 = 0.0f; MatrixX._32 =-fSin; MatrixX._33 = fCos; MatrixX._34 = 0.0f;
MatrixX._41 = 0.0f; MatrixX._42 = 0.0f; MatrixX._43 = 0.0f; MatrixX._44 = 1.0f;

Rotation = Rotation * MatrixX;
}

if( y !=0 )
{
fCos = (FLOAT)cos( y );
fSin = (FLOAT)sin( y );

MatrixY._11 = fCos; MatrixY._12 = 0.0f; MatrixY._13 =-fSin; MatrixY._14 = 0.0f;
MatrixY._21 = 0.0f; MatrixY._22 = 1.0f; MatrixY._23 = 0.0f; MatrixY._24 = 0.0f;
MatrixY._31 = fSin; MatrixY._32 = 0.0f; MatrixY._33 = fCos; MatrixY._34 = 0.0f;
MatrixY._41 = 0.0f; MatrixY._42 = 0.0f; MatrixY._43 = 0.0f; MatrixY._44 = 1.0f;

Rotation = Rotation * MatrixY;
}
}

I still get the tilt around the Z-Axis...

Before...Using RenderWare, I was instructed to reset the y component of the Right vector, normalize it, and take a cross product with the up vector to determine the correct up vector. This maybe to much to do, but do you see anyother problems?

--Jeff
If you cross the right vector and the up vector you would get the forward vector...

I think the rest of your matrix stuff is right, isn''t it?!?

Try to use the forward vector and the up vector to generate the right vector, that''s better...

This topic is closed to new replies.

Advertisement