Original Post
I have a question pertaining to camera yaw. It seems that the more I rotate in either direction, the harder it becomes to rotate. For example, it's near impossible to turn the camera completely around (180 degrees). Why does this happen? Pitching the camera is the same way, I can't get any further than looking straight up or straight down. How can I fix this? I'm sure this is a problem many people have, my code doesn't deviate much from the camera code out there. I'll post my code anyway.
void FirstPersonCamera::Pitch( FLOAT theta ) {
// Rotation about X
D3DXVECTOR3 view = look_ - eye_;
D3DXVECTOR3 yaw;
D3DXVec3Cross( &yaw, &view, &up_ );
D3DXVec3Normalize( &yaw, &yaw );
D3DXVECTOR4 newView;//, newUp;
//D3DXVECTOR3 view = look_ - eye_;
D3DXMATRIX rotationMatrix;
D3DXMatrixRotationAxis( &rotationMatrix, &yaw, theta );
D3DXVec3Transform( &newView, &view, &rotationMatrix );
//D3DXVec3Transform( &newUp, &up_, &rotationMatrix );
look_.y = eye_.y + newView.y;
//up_ = *(D3DXVECTOR3*)&newUp
//look_.z = eye_.z + newView.z;
}
void FirstPersonCamera::Yaw( FLOAT theta ) {
D3DXVECTOR4 newView;
D3DXVECTOR3 view = look_ - eye_;
D3DXMATRIX rotationMatrix;
D3DXMatrixRotationAxis( &rotationMatrix, &up_, theta );
D3DXVec3Transform( &newView, &view, &rotationMatrix );
//look_.y = eye_.y + newView.y;
look_.x = eye_.x + newView.x;
}
void FirstPersonCamera::HandleMouseInput( const POINT& center ) {
POINT p;
assert( GetCursorPos( &p ) );
if ( abs( p.x - center.x ) > threshHold ) {
LONG difference = center.x - p.x;
this->Yaw( -difference / 800.0f );
}
if ( abs( p.y - center.y ) > threshHold ) {
LONG difference = center.y - p.y;
this->Pitch( difference / 800.0f );
}
SetCursorPos( center.x, center.y );
}