Commit 7dd89c1e authored by Hans-Christian Ebke's avatar Hans-Christian Ebke

Added constrained rotation option in normal navigation mode to QtBaseViewer.


git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@17606 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 360c7cac
......@@ -157,6 +157,7 @@ glViewer::glViewer( QGraphicsScene* _scene,
pickCache_(0),
updatePickCache_(true),
pickCacheSupported_(true),
constrainedRotationAxis_(std::numeric_limits<double>::quiet_NaN(), 0, 0),
clickEvent_(QEvent::MouseButtonPress, QPoint (), Qt::NoButton, Qt::NoButton, Qt::NoModifier),
properties_(_properties),
glstate_(0),
......@@ -1467,7 +1468,7 @@ void glViewer::mousePressEvent(QGraphicsSceneMouseEvent* _e)
glScene_->update ();
// right button pressed => popup menu (ignore here)
if (_e->button() != Qt::RightButton )
if (allowConstrainedRotation() || _e->button() != Qt::RightButton )
{
switch (properties_.actionMode())
{
......@@ -1807,7 +1808,9 @@ void glViewer::handleNormalNavigation( QMouseEvent* _event ) {
}
}
lastPoint_hitSphere_ = mapToSphere(lastPoint2D_ = pos, lastPoint3D_);
lastPoint_hitSphere_ = mapToSphere(pos, lastPoint3D_);
lastPoint2D_ = pos;
std::cout << "Set lastPoint2D_ to " << pos.x() << ", " << pos.y() << std::endl;
isRotating_ = true;
timer_->stop();
......@@ -1826,7 +1829,7 @@ void glViewer::handleNormalNavigation( QMouseEvent* _event ) {
factor = properties_.wheelZoomFactorShift();
// mouse button should be pressed
if (_event->buttons() & (Qt::LeftButton | Qt::MidButton)) {
if (_event->buttons() & (Qt::LeftButton | Qt::MidButton | Qt::RightButton)) {
QPoint newPoint2D = pos;
ACG::Vec3d newPoint3D;
......@@ -1918,9 +1921,46 @@ void glViewer::handleNormalNavigation( QMouseEvent* _event ) {
lastRotationAxis_ = axis;
lastRotationAngle_ = angle;
} else if (allowConstrainedRotation() && (_event->buttons() & Qt::RightButton)) {
//ACG::Vec3d axis(constrainedRotationAxis_);
//double angle(0.0);
if (lastPoint_hitSphere_) {
const QPoint dragVector = newPoint2D - lastPoint2D_;
const double dragLength = dragVector.y();
//ACG::Vec2d(dragVector.x(), dragVector.y()).norm();
const double angle = -dragLength * factor;
/*
{
makeCurrent();
const ACG::Vec3d center =
properties_.trackballCenter();
const ACG::Vec3d t =
startViewMatrix_.transform_point(center);
glstate_->set_modelview(startViewMatrix_);
glstate_->translate(-t[0], -t[1], -t[2],
ACG::MULT_FROM_LEFT);
glstate_->rotate(angle,
constrainedRotationAxis_[0],
constrainedRotationAxis_[1],
constrainedRotationAxis_[2],
ACG::MULT_FROM_LEFT);
glstate_->translate(t[0], t[1], t[2],
ACG::MULT_FROM_LEFT);
}
*/
ACG::Vec3d center(glWidth()/2.0, glHeight()/2.0);
rotate(constrainedRotationAxis_, angle, unproject(center));
lastRotationAxis_ = constrainedRotationAxis_;
lastRotationAngle_ = angle;
}
}
lastPoint2D_ = newPoint2D;
std::cout << "Set lastPoint2D_ to " << newPoint2D.x() << ", " << newPoint2D.y() << std::endl;
lastPoint3D_ = newPoint3D;
lastPoint_hitSphere_ = newPoint_hitSphere;
......
/*===========================================================================*\
* *
* OpenFlipper *
* Copyright (C) 2001-2011 by Computer Graphics Group, RWTH Aachen *
* Copyright (C) 2001-2011 by Computer Graphics Group, RWTH achen *
* www.openflipper.org *
* *
*--------------------------------------------------------------------------- *
......@@ -90,7 +90,7 @@
#include <vector>
#include <string>
#include <limits>
//== FORWARDDECLARATIONS ======================================================
......@@ -850,6 +850,19 @@ private:
void allowRotation( bool _mode ) { allowRotation_ = _mode; };
bool allowRotation() { return allowRotation_; };
void allowConstrainedRotation(const ACG::Vec3d &axis) {
constrainedRotationAxis_ = axis;
}
bool allowConstrainedRotation() {
return constrainedRotationAxis_[0] == constrainedRotationAxis_[0];
}
const ACG::Vec3d &getConstrainedRotationAxis() {
return constrainedRotationAxis_;
}
void disallowConstrainedRotation() {
constrainedRotationAxis_[0] = std::numeric_limits<double>::quiet_NaN();
}
private slots:
void slotAnimation();
......@@ -887,6 +900,7 @@ private:
// animation stuff
ACG::Vec3d lastRotationAxis_;
ACG::Vec3d constrainedRotationAxis_;
double lastRotationAngle_;
QTime lastMoveTime_;
QTimer* timer_;
......@@ -896,6 +910,7 @@ private:
QTime clickTime_;
QMouseEvent clickEvent_;
/** @} */
//===========================================================================
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment