Add basic tranlation functionality to the viewer

Had to separate zoom and translate matrices to stop the zoom being
applied to itelf. This also required adding separate get/set functions
for each matrix and a GetcombinedMatrix() funtion.

Added those functions ot other files where needed ut may be wrong. Need
to look at export.cpp

Also changed the mouse move and press events to make translation work.
This commit is contained in:
Thomas Wilshaw
2020-06-16 11:53:34 +01:00
parent f107c9bba1
commit 2174100342
4 changed files with 62 additions and 11 deletions
+3 -3
View File
@@ -78,7 +78,7 @@ ViewerWidget::ViewerWidget(QWidget *parent) :
connect(display_widget_, &ViewerDisplayWidget::CursorColor, this, &ViewerWidget::CursorColor);
connect(display_widget_, &ViewerDisplayWidget::ColorProcessorChanged, this, &ViewerWidget::ColorProcessorChanged);
connect(display_widget_, &ViewerDisplayWidget::ColorManagerChanged, this, &ViewerWidget::ColorManagerChanged);
connect(sizer_, &ViewerSizer::RequestMatrix, display_widget_, &ViewerDisplayWidget::SetMatrix);
connect(sizer_, &ViewerSizer::RequestMatrix, display_widget_, &ViewerDisplayWidget::SetMatrixZoom);
sizer_->SetWidget(display_widget_);
// Create waveform view when audio is connected and video isn't
@@ -322,9 +322,9 @@ void ViewerWidget::SetOverrideSize(int width, int height)
void ViewerWidget::SetMatrix(const QMatrix4x4 &mat)
{
display_widget_->SetMatrix(mat);
display_widget_->SetMatrixZoom(mat);
foreach (ViewerWindow* vw, windows_) {
vw->display_widget()->SetMatrix(mat);
vw->display_widget()->SetMatrixZoom(mat);
}
}
+48 -4
View File
@@ -56,12 +56,24 @@ ViewerDisplayWidget::~ViewerDisplayWidget()
ContextCleanup();
}
void ViewerDisplayWidget::SetMatrix(const QMatrix4x4 &mat)
void ViewerDisplayWidget::SetMatrixTranslate(const QMatrix4x4 &mat)
{
matrix_ = mat;
translate_matrix_ = mat;
update();
}
void ViewerDisplayWidget::SetMatrixZoom(const QMatrix4x4 &mat)
{
scale_matrix_ = mat;
update();
}
QMatrix4x4 ViewerDisplayWidget::GetCompleteMatrix()
{
QMatrix4x4 mat;
return scale_matrix_ * translate_matrix_ * mat;
}
void ViewerDisplayWidget::SetSignalCursorColorEnabled(bool e)
{
signal_cursor_color_ = e;
@@ -145,6 +157,13 @@ void ViewerDisplayWidget::mousePressEvent(QMouseEvent *event)
return;
}
if (event->button() == Qt::MiddleButton) {
printf("Middle Button Clicked\n");
position_ = event->pos();
printf("x: %d, y:%d\n", position_.x(), position_.y());
return;
}
QOpenGLWidget::mousePressEvent(event);
if (event->button() == Qt::LeftButton) {
@@ -154,6 +173,23 @@ void ViewerDisplayWidget::mousePressEvent(QMouseEvent *event)
void ViewerDisplayWidget::mouseMoveEvent(QMouseEvent *event)
{
if (event->buttons() & Qt::MiddleButton) {
printf("Move\n");
QPointF delta = event->pos() - position_;
delta.setX(delta.x() / width());
delta.setY(delta.y() / height());
//this->move(this->pos()+new_position);
//QPoint new_pos = this->pos() + delta;
QMatrix4x4 mat;
//mat.translate(static_cast<float>(new_pos.x()) / width(), static_cast<float>(-1 * new_pos.y()) / height());
printf("x: %f, y:%f\n", delta.x(), delta.y());
mat = GetMatrixTranslate();
mat.translate(delta.x(), -1.0f * delta.y());
SetMatrixTranslate(mat);
position_ = event-> pos();
return;
}
if (gizmo_click_) {
gizmos_->GizmoMove(event->pos(), QVector2D(GetTexturePosition(size())), gizmo_drag_time_);
return;
@@ -169,7 +205,7 @@ void ViewerDisplayWidget::mouseMoveEvent(QMouseEvent *event)
static_cast<float>(event->y()) / static_cast<float>(height()) * 2.0f - 1.0f,
0);
pixel_pos = pixel_pos * matrix_.inverted();
pixel_pos = pixel_pos * GetCompleteMatrix().inverted();
int frame_x = qRound((pixel_pos.x() + 1.0f) * 0.5f * last_loaded_buffer_->width());
int frame_y = qRound((pixel_pos.y() + 1.0f) * 0.5f * last_loaded_buffer_->height());
@@ -194,6 +230,11 @@ void ViewerDisplayWidget::mouseReleaseEvent(QMouseEvent *event)
QOpenGLWidget::mouseReleaseEvent(event);
}
QMatrix4x4 ViewerDisplayWidget::GetMatrixTranslate()
{
return translate_matrix_;
}
void ViewerDisplayWidget::initializeGL()
{
ManagedDisplayWidget::initializeGL();
@@ -231,8 +272,11 @@ void ViewerDisplayWidget::paintGL()
// Bind retrieved texture
f->glBindTexture(GL_TEXTURE_2D, texture_.texture());
//QMatrix4x4 mat;
//mat = scale_matrix_ * translate_matrix_ * mat;
// Blit using the color service
color_service()->ProcessOpenGL(true, matrix_);
color_service()->ProcessOpenGL(true, GetCompleteMatrix());
// Release retrieved texture
f->glBindTexture(GL_TEXTURE_2D, 0);
+10 -3
View File
@@ -66,7 +66,9 @@ public:
virtual ~ViewerDisplayWidget() override;
const QMatrix4x4& GetMatrix();
QMatrix4x4 GetMatrixTranslate();
QMatrix4x4 GetCompleteMatrix();
const ViewerSafeMarginInfo& GetSafeMargin() const;
void SetSafeMargins(const ViewerSafeMarginInfo& safe_margin);
@@ -83,7 +85,8 @@ public slots:
*
* Set this if you want the drawing to pass through some sort of transform (most of the time you won't want this).
*/
void SetMatrix(const QMatrix4x4& mat);
void SetMatrixTranslate(const QMatrix4x4& mat);
void SetMatrixZoom(const QMatrix4x4& mat);
/**
* @brief Enables or disables whether this color at the cursor should be emitted
@@ -158,7 +161,9 @@ private:
/**
* @brief Drawing matrix (defaults to identity)
*/
QMatrix4x4 matrix_;
QMatrix4x4 translate_matrix_;
QMatrix4x4 scale_matrix_;
#ifdef Q_OS_LINUX
static bool nouveau_check_done_;
@@ -178,6 +183,8 @@ private:
FramePtr last_loaded_buffer_;
QPoint position_;
private slots:
/**
* @brief Slot to connect just before the OpenGL context is destroyed to clean up resources
+1 -1
View File
@@ -59,7 +59,7 @@ void ViewerWindow::SetResolution(int width, int height)
mat.scale(1.0f, window_ar / image_ar, 1.0f);
}
display_widget_->SetMatrix(mat);
display_widget_->SetMatrixZoom(mat);
}
void ViewerWindow::Play(const int64_t& start_timestamp, const int& playback_speed, const rational &timebase)