diff --git a/3d-viewer/3d_rendering/ccamera.cpp b/3d-viewer/3d_rendering/ccamera.cpp index c47127ced2..60284ed028 100644 --- a/3d-viewer/3d_rendering/ccamera.cpp +++ b/3d-viewer/3d_rendering/ccamera.cpp @@ -106,6 +106,20 @@ void CCAMERA::Reset_T1() m_zoom_t1 = 1.0f; m_rotate_aux_t1 = SFVEC3F( 0.0f ); m_lookat_pos_t1 = m_board_lookat_pos_init; + + + // Since 0 = 2pi, we want to reset the angle to be the closest + // one to where we currently are. That ensures that we rotate + // the board around the smallest distance getting there. + if( m_rotate_aux_t0.x > M_PI ) + m_rotate_aux_t1.x = 2*M_PI; + + if( m_rotate_aux_t0.y > M_PI ) + m_rotate_aux_t1.y = 2*M_PI; + + if( m_rotate_aux_t0.z > M_PI ) + m_rotate_aux_t1.z = 2*M_PI; + } @@ -119,20 +133,20 @@ void CCAMERA::updateViewMatrix() void CCAMERA::updateRotationMatrix() { - normalise2PI( m_rotate_aux.x ); m_rotationMatrixAux = glm::rotate( glm::mat4( 1.0f ), m_rotate_aux.x, SFVEC3F( 1.0f, 0.0f, 0.0f ) ); + normalise2PI( m_rotate_aux.x ); - normalise2PI( m_rotate_aux.y ); m_rotationMatrixAux = glm::rotate( m_rotationMatrixAux, m_rotate_aux.y, SFVEC3F( 0.0f, 1.0f, 0.0f ) ); + normalise2PI( m_rotate_aux.y ); - normalise2PI( m_rotate_aux.z ); m_rotationMatrixAux = glm::rotate( m_rotationMatrixAux, m_rotate_aux.z, SFVEC3F( 0.0f, 0.0f, 1.0f ) ); + normalise2PI( m_rotate_aux.z ); m_parametersChanged = true; @@ -533,21 +547,18 @@ void CCAMERA::RotateZ( float aAngleInRadians ) void CCAMERA::RotateX_T1( float aAngleInRadians ) { m_rotate_aux_t1.x += aAngleInRadians; - normalise2PI( m_rotate_aux_t1.x ); } void CCAMERA::RotateY_T1( float aAngleInRadians ) { m_rotate_aux_t1.y += aAngleInRadians; - normalise2PI( m_rotate_aux_t1.y ); } void CCAMERA::RotateZ_T1( float aAngleInRadians ) { m_rotate_aux_t1.z += aAngleInRadians; - normalise2PI( m_rotate_aux_t1.z ); }