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->delta() / 120.0 * 0.2 * factor * trackball_radius_/3;
361 double d = (double)_event->delta() / 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.
void translate(const Vec3d &trans)
translate the scene and update modelview matrix
unsigned int glWidth() const
get width of QGLWidget
void signalSetView(const GLMatrixd &_modelview, const GLMatrixd &_inverse_modelview)
set view, used for synchronizing (cf. slotSetView())
const GLMatrixd & inverse_modelview() const
get inverse modelview matrix
GLState & glState()
get OpenGL state
virtual void viewWheelEvent(QWheelEvent *_event)
handle wheel events
bool mapToSphere(const QPoint &_p, Vec3d &_result) const
virtual trackball: map 2D screen point to unit sphere
void rotate_lights(Vec3d &_axis, double _angle)
rotete light sources
virtual void viewMouseEvent(QMouseEvent *_event)
handle mouse events
bool isUpdateLocked() const
void rotate(const Vec3d &axis, double angle)
rotate the scene (around its center) and update modelview matrix
VectorT< double, 3 > Vec3d
double wheelZoomFactor()
Factors for zooming with the wheel.
virtual void lightMouseEvent(QMouseEvent *_event)
handle mouse events
virtual void makeCurrent()
Makes this widget the current widget for OpenGL operations.
void updateProjectionMatrix()
updates projection matrix
virtual void updateGL()
Redraw scene. Triggers paint event for updating the view (cf. drawNow()).
ProjectionMode projectionMode() const
get current projection mode
const GLMatrixd & modelview() const
get modelview matrix
bool animation() const
Is animation enabled?
bool fast_pick(const QPoint &_mousePos, Vec3d &_hitPoint)
unsigned int glHeight() const
get height of QGLWidget
QtExaminerViewer(QWidget *_parent=0, const char *_name=0, QStatusBar *_statusBar=0, const QGLFormat *_format=0, const QtBaseViewer *_share=0, Options _options=DefaultOptions)
Constructor.
virtual void flyTo(const QPoint &_pos, bool _move_back)
Fly to. Get closer if _move_back=false, get more distant else.