mirror of https://github.com/CGAL/cgal
Center the camera on the cursor at first tick of optical zoom
This commit is contained in:
parent
121a23d964
commit
b116a92be3
|
|
@ -1167,7 +1167,6 @@ protected:
|
||||||
QMap<WheelBindingPrivate, MouseActionPrivate> wheelBinding_;
|
QMap<WheelBindingPrivate, MouseActionPrivate> wheelBinding_;
|
||||||
QMap<ClickBindingPrivate, qglviewer::ClickAction> clickBinding_;
|
QMap<ClickBindingPrivate, qglviewer::ClickAction> clickBinding_;
|
||||||
::Qt::Key currentlyPressedKey_;
|
::Qt::Key currentlyPressedKey_;
|
||||||
bool z_is_pressed;
|
|
||||||
// S t a t e F i l e
|
// S t a t e F i l e
|
||||||
QString stateFileName_;
|
QString stateFileName_;
|
||||||
|
|
||||||
|
|
@ -1212,6 +1211,9 @@ protected:
|
||||||
bool is_sharing;
|
bool is_sharing;
|
||||||
bool is_linked;
|
bool is_linked;
|
||||||
QOpenGLContext* shared_context;
|
QOpenGLContext* shared_context;
|
||||||
|
// Zoom
|
||||||
|
bool _first_tick;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
//! Is used to know if the openGL context is 4.3 or ES 2.0.
|
//! Is used to know if the openGL context is 4.3 or ES 2.0.
|
||||||
//! @returns `true` if the context is 4.3.
|
//! @returns `true` if the context is 4.3.
|
||||||
|
|
|
||||||
|
|
@ -155,6 +155,7 @@ void CGAL::QGLViewer::defaultConstructor() {
|
||||||
is_sharing = false;
|
is_sharing = false;
|
||||||
is_linked = false;
|
is_linked = false;
|
||||||
shared_context = nullptr;
|
shared_context = nullptr;
|
||||||
|
_first_tick = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
CGAL_INLINE_FUNCTION
|
CGAL_INLINE_FUNCTION
|
||||||
|
|
@ -1544,6 +1545,17 @@ void CGAL::QGLViewer::wheelEvent(QWheelEvent *e) {
|
||||||
MouseActionPrivate map = wheelBinding_[wbp];
|
MouseActionPrivate map = wheelBinding_[wbp];
|
||||||
switch (map.handler) {
|
switch (map.handler) {
|
||||||
case qglviewer::CAMERA:
|
case qglviewer::CAMERA:
|
||||||
|
if(currentlyPressedKey_ == ::Qt::Key_Z && _first_tick)
|
||||||
|
{
|
||||||
|
_first_tick = false;
|
||||||
|
makeCurrent();
|
||||||
|
//orient camera to the cursor.
|
||||||
|
bool found = false;
|
||||||
|
qglviewer::Vec point;
|
||||||
|
point = camera()->pointUnderPixel(mapFromGlobal(QCursor::pos()), found);
|
||||||
|
if(found)
|
||||||
|
camera()->lookAt(point);
|
||||||
|
}
|
||||||
camera()->frame()->startAction(map.action, map.withConstraint);
|
camera()->frame()->startAction(map.action, map.withConstraint);
|
||||||
camera()->frame()->wheelEvent(e, camera());
|
camera()->frame()->wheelEvent(e, camera());
|
||||||
break;
|
break;
|
||||||
|
|
@ -2263,21 +2275,11 @@ void CGAL::QGLViewer::keyPressEvent(QKeyEvent *e) {
|
||||||
|
|
||||||
const ::Qt::Key key = ::Qt::Key(e->key());
|
const ::Qt::Key key = ::Qt::Key(e->key());
|
||||||
|
|
||||||
const ::Qt::KeyboardModifiers modifiers = e->modifiers();
|
|
||||||
|
|
||||||
if(key == ::Qt::Key_Z && ! e->isAutoRepeat())
|
if(key == ::Qt::Key_Z && ! e->isAutoRepeat())
|
||||||
{
|
{
|
||||||
makeCurrent();
|
_first_tick = true;
|
||||||
//orient camera to the cursor.
|
|
||||||
bool found = false;
|
|
||||||
qglviewer::Vec point;
|
|
||||||
point = camera()->pointUnderPixel(mapFromGlobal(QCursor::pos()), found);
|
|
||||||
if(!found)
|
|
||||||
return;
|
|
||||||
camera()->lookAt(point);
|
|
||||||
update();
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
const ::Qt::KeyboardModifiers modifiers = e->modifiers();
|
||||||
QMap<qglviewer::KeyboardAction, unsigned int>::ConstIterator it = keyboardBinding_
|
QMap<qglviewer::KeyboardAction, unsigned int>::ConstIterator it = keyboardBinding_
|
||||||
.begin(),
|
.begin(),
|
||||||
end =
|
end =
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue