Strange rotation near origin

This topic is 1780 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Hi guys.

To make it short: I'm currently programming a camera-view to move around freely in world space, and I'm getting a strange rotation-behaviour when my camera is close to the world origin (0,0,0).

Normally I would want it to rotate around itself (around an axis pointing to its right and one pointing upwards) when moving the mouse the corresponding directions, which it does, until the view gets close to 0,0,0, then it starts rotating around some other axis, but definitely not around itself.

Heres the code doing the work:

Update function for the camera, being called every frame:

void Camera::Update()
{
if( fwd || back || left || right || rotate )
{
View = XMMatrixLookAtLH( EyePos, Focus, UpDir );

ForwardVec = XMFLOAT3( View._13, View._23, View._33);
RightVec = XMFLOAT3( View._11, View._21, 0.0f );

if( rotate )
Rotate();

View = XMMatrixInverse( &dump, XMMatrixMultiply( XMMatrixInverse( &dump, View ), Rotation) ); //Rotation being applied here

ForwardVec = XMFLOAT3( View._13, View._23, View._33);
RightVec = XMFLOAT3( View._11, View._21, 0.0f );

if( fwd )
Forward();

if( back )
Backwards();

if( left )
Left();

if( right )
Right();

Translation = XMMatrixTranslation( Offset.x, Offset.y, Offset.z );

View = XMMatrixInverse( &dump, XMMatrixMultiply( XMMatrixInverse( &dump, View ), Translation) );

cb.mView = XMMatrixTranspose( View );
m_pImmediateContext->UpdateSubresource( pConstantBuffer, 0, NULL, &cb, 0, 0 );
}
}


Heres the Rotate() function

void Camera::Rotate()
{

AngleYaw += (float)pInput->GetMouseDelta().x * RotationSpeed;
AnglePitch += (float)pInput->GetMouseDelta().y * RotationSpeed;

Clamp( &AnglePitch, -90.0f * RotationSpeed * 4, 90.0f * RotationSpeed * 4 );

Rotation = XMMatrixRotationAxis( XMLoadFloat3( &RightVec ), AnglePitch );
Rotation *= XMMatrixRotationAxis( UpVec, AngleYaw );
}


Share on other sites

Hm, no ideas ? Can someone at least tell me if I'm rotating the view-matrix correctly ?

1. 1
Rutin
34
2. 2
3. 3
4. 4
5. 5

• 12
• 14
• 9
• 9
• 9
• Forum Statistics

• Total Topics
633334
• Total Posts
3011408
• Who's Online (See full list)

There are no registered users currently online

×