Pitch-Yaw mouse move feature

This commit is contained in:
Michel Mastriani 2020-09-27 11:59:09 -03:00
parent e41fca7b7d
commit 601c000b10
4 changed files with 61 additions and 7 deletions

View File

@ -114,6 +114,8 @@ public:
bool ApplyAll(); bool ApplyAll();
void SetRotation(double rot, bool stealth); void SetRotation(double rot, bool stealth);
void SetScale(double scale); void SetScale(double scale);
void SetPitch(double pitch);
void SetYaw(double yaw);
void SetCoordinateStatus(int rasX, int rasY, float worldX, float worldY); void SetCoordinateStatus(int rasX, int rasY, float worldX, float worldY);
void CenterScrollbars(); void CenterScrollbars();

View File

@ -928,6 +928,26 @@ void Fractorium::SetScale(double scale)
m_ScaleSpin->setValue(scale); m_ScaleSpin->setValue(scale);
} }
/// <summary>
/// Set the pitch.
/// This updates the spinner
/// </summary>
/// <param name="pitch">The pitch value</param>
void Fractorium::SetPitch(double pitch)
{
m_PitchSpin->setValue(pitch);
}
/// <summary>
/// Set the yaw.
/// This updates the spinner
/// </summary>
/// <param name="yaw">The yaw value</param>
void Fractorium::SetYaw(double yaw)
{
m_YawSpin->setValue(yaw);
}
template class FractoriumEmberController<float>; template class FractoriumEmberController<float>;
#ifdef DO_DOUBLE #ifdef DO_DOUBLE

View File

@ -19,7 +19,7 @@ enum class eHoverType : et { HoverNone, HoverXAxis, HoverYAxis, HoverTranslation
/// <summary> /// <summary>
/// Dragging an affine transform or panning, rotating or scaling the image. /// Dragging an affine transform or panning, rotating or scaling the image.
/// </summary> /// </summary>
enum class eDragState : et { DragNone, DragSelect, DragPanning, DragDragging, DragRotateScale }; enum class eDragState : et { DragNone, DragSelect, DragPanning, DragDragging, DragRotateScale, DragPitchYaw };
/// <summary> /// <summary>
/// Dragging with no keys pressed, shift, control or alt. /// Dragging with no keys pressed, shift, control or alt.
@ -137,6 +137,8 @@ private:
T m_CenterDownY; T m_CenterDownY;
T m_RotationDown; T m_RotationDown;
T m_ScaleDown; T m_ScaleDown;
T m_PitchDown;
T m_YawDown;
v4T m_BoundsDown; v4T m_BoundsDown;
v3T m_MouseWorldPos; v3T m_MouseWorldPos;

42
Source/Fractorium/GLWidget.cpp Normal file → Executable file
View File

@ -891,7 +891,7 @@ void GLEmberController<T>::MousePress(QMouseEvent* e)
m_DragState = eDragState::DragNone; m_DragState = eDragState::DragNone;
} }
} }
else if (e->button() == Qt::MiddleButton || (e->button() == Qt::RightButton && e->modifiers() & Qt::ShiftModifier))//Middle button or right button with shift key, do whole image translation. else if (e->button() == Qt::MiddleButton || (e->button() == Qt::RightButton && e->modifiers() & Qt::ShiftModifier && !(e->modifiers() & Qt::AltModifier)))//Middle button or right button with shift key, do whole image translation.
{ {
m_CenterDownX = ember->m_CenterX;//Capture where the center of the image is because this value will change when panning. m_CenterDownX = ember->m_CenterX;//Capture where the center of the image is because this value will change when panning.
m_CenterDownY = ember->m_CenterY; m_CenterDownY = ember->m_CenterY;
@ -901,11 +901,21 @@ void GLEmberController<T>::MousePress(QMouseEvent* e)
{ {
if (m_Fractorium->DrawImage()) if (m_Fractorium->DrawImage())
{ {
m_CenterDownX = ember->m_CenterX;//Capture these because they will change when rotating and scaling. m_CenterDownX = ember->m_CenterX;//Capture these because they will change when rotating and scaling.
m_CenterDownY = ember->m_CenterY; m_CenterDownY = ember->m_CenterY;
m_RotationDown = ember->m_Rotate;
m_ScaleDown = ember->m_PixelsPerUnit; if(GetAlt() && GetShift())
m_DragState = eDragState::DragRotateScale; {
m_PitchDown = ember->m_CamPitch * RAD_2_DEG_T;
m_YawDown = ember->m_CamYaw * RAD_2_DEG_T;
m_DragState = eDragState::DragPitchYaw;
}
else
{
m_RotationDown = ember->m_Rotate;
m_ScaleDown = ember->m_PixelsPerUnit;
m_DragState = eDragState::DragRotateScale;
}
} }
} }
} }
@ -1054,6 +1064,26 @@ void GLEmberController<T>::MouseMove(QMouseEvent* e)
m_Fractorium->SetRotation(ember->m_Rotate, true); m_Fractorium->SetRotation(ember->m_Rotate, true);
m_Fractorium->SetScale(std::max(T(10), m_ScaleDown + scale));//Will restart the rendering process. m_Fractorium->SetScale(std::max(T(10), m_ScaleDown + scale));//Will restart the rendering process.
} }
else if (m_DragState == eDragState::DragPitchYaw)//Pitching and yawing the whole image.
{
T pitch;
T yaw;
auto rotate = ember->m_Rotate;
if((rotate <= 45 && rotate >= -45) || (rotate >= 135) || (rotate <= -135))
{
pitch = m_PitchDown + (m_MouseWorldPos.y - m_MouseDownWorldPos.y) * 100;
yaw = m_YawDown + (m_MouseWorldPos.x - m_MouseDownWorldPos.x) * 100;
}
else
{
pitch = m_PitchDown + (m_MouseWorldPos.x - m_MouseDownWorldPos.x) * 100;
yaw = m_YawDown + (m_MouseWorldPos.y - m_MouseDownWorldPos.y) * 100;
}
m_Fractorium->SetPitch(pitch);
m_Fractorium->SetYaw(yaw);
}
else else
{ {
//If the user doesn't already have a key down, and they aren't dragging, clear the keys to be safe. //If the user doesn't already have a key down, and they aren't dragging, clear the keys to be safe.