54 #include <ACG/GL/acg_glew.hh> 55 #include "QtExaminerViewer.hh" 58 #include <QApplication> 59 #include <QInputDialog> 62 #include "../GL/GLState.hh" 81 QStatusBar *_statusBar,
82 const QGLFormat* _format,
85 QtBaseViewer(_parent, _name, _statusBar, _format, _share, _options)
89 timer_ =
new QTimer(
this );
90 connect( timer_, SIGNAL(timeout()),
this, SLOT( slotAnimation()) );
92 allowRotation_ =
true;
96 wZoomFactorShift_ = 0.2;
106 switch (_event->type())
108 case QEvent::MouseButtonPress:
111 if (_event->modifiers() & Qt::ShiftModifier)
116 trackball_center_ = c;
117 trackball_radius_ = std::max(scene_radius_, (c-
glState().eye()).norm()*0.9f);
121 lastPoint_hitSphere_ =
mapToSphere( lastPoint2D_=_event->pos(),
131 case QEvent::MouseButtonDblClick:
134 flyTo(_event->pos(), _event->button()==Qt::MidButton);
139 case QEvent::MouseMove:
143 if (_event->modifiers() == Qt::ShiftModifier)
144 factor = wZoomFactorShift_;
147 if (_event->buttons() & (Qt::LeftButton | Qt::MidButton))
149 QPoint newPoint2D = _event->pos();
151 if ( (newPoint2D.x()<0) || (newPoint2D.x() > (int)
glWidth()) ||
152 (newPoint2D.y()<0) || (newPoint2D.y() > (int)
glHeight()) )
157 bool newPoint_hitSphere =
mapToSphere( newPoint2D, newPoint3D );
162 if ( (_event->buttons() & Qt::LeftButton) &&
163 (_event->buttons() & Qt::MidButton))
169 value_y = scene_radius_ * ((newPoint2D.y() - lastPoint2D_.y())) * 3.0 / (double)
glHeight();
177 value_y = ((newPoint2D.y() - lastPoint2D_.y())) * orthoWidth_ / (double)
glHeight();
178 orthoWidth_ -= value_y * factor;
187 else if (_event->buttons() & Qt::MidButton)
190 value_x = scene_radius_ * ((newPoint2D.x() - lastPoint2D_.x())) * 2.0 / (double)
glWidth();
191 value_y = scene_radius_ * ((newPoint2D.y() - lastPoint2D_.y())) * 2.0 / (double)
glHeight();
196 else if (allowRotation_ && (_event->buttons() & Qt::LeftButton) )
198 Vec3d axis(1.0,0.0,0.0);
201 if ( lastPoint_hitSphere_ ) {
203 if ( ( newPoint_hitSphere =
mapToSphere( newPoint2D,
205 axis = lastPoint3D_ % newPoint3D;
206 double cos_angle = ( lastPoint3D_ | newPoint3D );
207 if ( fabs(cos_angle) < 1.0 ) {
208 angle = acos( cos_angle ) * 180.0 / M_PI * factor ;
217 lastRotationAxis_ = axis;
218 lastRotationAngle_ = angle;
221 lastPoint2D_ = newPoint2D;
222 lastPoint3D_ = newPoint3D;
223 lastPoint_hitSphere_ = newPoint_hitSphere;
226 lastMoveTime_.restart();
233 case QEvent::MouseButtonRelease:
235 lastPoint_hitSphere_ =
false;
239 (_event->button() == Qt::LeftButton) &&
240 (!(_event->buttons() & Qt::MidButton)) &&
241 (lastMoveTime_.elapsed() < 10) &&
263 switch (_event->type()) {
264 case QEvent::MouseButtonPress: {
265 lastPoint_hitSphere_ =
mapToSphere(lastPoint2D_ = _event->pos(), lastPoint3D_);
271 case QEvent::MouseMove: {
274 if (_event->buttons() & Qt::LeftButton) {
275 QPoint newPoint2D = _event->pos();
277 if ((newPoint2D.x() < 0) || (newPoint2D.x() > (int)
glWidth()) || (newPoint2D.y() < 0)
278 || (newPoint2D.y() > (int)
glHeight()))
282 bool newPoint_hitSphere =
mapToSphere(newPoint2D, newPoint3D);
286 if (lastPoint_hitSphere_) {
287 Vec3d axis(1.0, 0.0, 0.0);
290 if ((newPoint_hitSphere =
mapToSphere(newPoint2D, newPoint3D))) {
291 axis = lastPoint3D_ % newPoint3D;
292 double cos_angle = (lastPoint3D_ | newPoint3D);
293 if (fabs(cos_angle) < 1.0) {
294 angle = acos(cos_angle) * 180.0 / M_PI;
301 lastPoint2D_ = newPoint2D;
302 lastPoint3D_ = newPoint3D;
303 lastPoint_hitSphere_ = newPoint_hitSphere;
324 double QtExaminerViewer::wheelZoomFactorShift(){
325 return wZoomFactorShift_;
330 void QtExaminerViewer::setWheelZoomFactor(
double _factor){
331 wZoomFactor_ = _factor;
336 void QtExaminerViewer::setWheelZoomFactorShift(
double _factor){
337 wZoomFactorShift_ = _factor;
344 double factor = wZoomFactor_;
346 if (_event->modifiers() == Qt::ShiftModifier)
347 factor = wZoomFactorShift_;
353 double d = -(double)_event->angleDelta().y() / 120.0 * 0.2 * factor * trackball_radius_/3;
361 double d = (double)_event->angleDelta().y() / 120.0 * 0.2 * factor * orthoWidth_;
380 if ( (_v2D.x() >= 0) && (_v2D.x() < (int)
glWidth()) &&
381 (_v2D.y() >= 0) && (_v2D.y() < (int)
glHeight()) )
383 double x = (double)(_v2D.x() - ((double)
glWidth() / 2.0)) / (
double)
glWidth();
384 double y = (double)(((
double)
glHeight() / 2.0) - _v2D.y()) / (
double)
glHeight();
385 double sinx = sin(M_PI * x * 0.5);
386 double siny = sin(M_PI * y * 0.5);
387 double sinx2siny2 = sinx * sinx + siny * siny;
391 _v3D[2] = sinx2siny2 < 1.0 ? sqrt(1.0 - sinx2siny2) : 0.0;
402 void QtExaminerViewer::slotAnimation()
408 rotate( lastRotationAxis_, lastRotationAngle_ );
413 static int msecs=0, count=0;
415 msecs += t.elapsed();
417 assert(statusbar_!=0);
419 sprintf( s,
"%.3f fps", (10000.0 / (
float)msecs) );
420 statusbar_->showMessage(s,2000);
Namespace providing different geometric functions concerning angles.
const GLMatrixd & inverse_modelview() const
get inverse modelview matrix
const GLMatrixd & modelview() const
get modelview matrix
VectorT< double, 3 > Vec3d