From fb395a81ab0921d284c9e4904ff14503aaa31a5b Mon Sep 17 00:00:00 2001 From: Carsten Niehaus Date: Wed, 28 Jun 2006 20:50:14 +0000 Subject: [PATCH] Adding autorotation and the slots for zoomin/out. Benoit, I added the code but have no idea how to do it propery (no 3d-knowledge). I added long comments for you there. CCMAIL:jacob@math.jussieu.fr svn path=/trunk/KDE/kdeedu/kalzium/src/kalziumglwidget.h; revision=555971 --- kalzium/kalziumglwidget.cpp | 46 +++++++++++++++++++++++++++++++++++++ kalzium/kalziumglwidget.h | 24 ++++++++++++++++--- 2 files changed, 67 insertions(+), 3 deletions(-) diff --git a/kalzium/kalziumglwidget.cpp b/kalzium/kalziumglwidget.cpp index 1ca9145..3c3a4de 100644 --- a/kalzium/kalziumglwidget.cpp +++ b/kalzium/kalziumglwidget.cpp @@ -21,6 +21,7 @@ #include #include +#include #ifdef USE_FPS_COUNTER @@ -46,6 +47,10 @@ KalziumGLWidget::KalziumGLWidget( QWidget * parent ) ChooseStylePreset( PRESET_SPHERES_AND_BICOLOR_BONDS ); setMinimumSize( 100,100 ); + + QTimer *timer = new QTimer( this ); + connect( timer, SIGNAL( timeout() ), this, SLOT( rotate() ) ); + timer->start( 50 ); } KalziumGLWidget::~KalziumGLWidget() @@ -337,6 +342,29 @@ void KalziumGLWidget::mouseMoveEvent( QMouseEvent * event ) } } +void KalziumGLWidget::rotate( ) +{ + kDebug() << "KalziumGLWidget::rotate()" << endl; + //TODO at this place we need a nice way to rotate + //based on certain values. For example, we could use two + //bool variables for x and y rotation. If x is true the + //molecule will rotate in the x-axis, if false not. Same + //for y. + //As I have no idea what this code is doing I just copy&pasted + //everything from the mousewheel method... + glPushMatrix(); + glLoadIdentity(); + + //Benoit, I took those values pretty much at random, + //no idea what value is for what... :) + glRotated( 10.0, 0.0, 1.0, 0.0 ); + glRotated( 10.0, 1.0, 0.0, 0.0 ); + glMultMatrixd( m_RotationMatrix ); + glGetDoublev( GL_MODELVIEW_MATRIX, m_RotationMatrix ); + glPopMatrix(); + updateGL(); +} + void KalziumGLWidget::setupObjects() { int sphere_detail, cylinder_faces; @@ -429,6 +457,24 @@ inline GLFLOAT KalziumGLWidget::atomRadius() return m_atomRadiusCoeff * m_molMinBondLength; } +void KalziumGLWidget::slotZoomIn() +{ + //TODO + //This slot can be very easily accessed by simply calling it from + //the GUI. I guess we need a second pair of zoomin/out slots for + //a more finegrained zooming. For example, if we use the mousewheel + //for zooming, we might want to use the delta()-value of the mouse- + //wheel as a factor. + //But as I have no idea how zooming works in OpenGL I cannot do the + //coding... +} + +void KalziumGLWidget::slotZoomOut() +{ + //TODO + //Comment so slotZoomIn() +} + void KalziumGLWidget::slotSetMolecule( OpenBabel::OBMol* molecule ) { if ( !molecule ) return; diff --git a/kalzium/kalziumglwidget.h b/kalzium/kalziumglwidget.h index dd3ee42..29e58c9 100644 --- a/kalzium/kalziumglwidget.h +++ b/kalzium/kalziumglwidget.h @@ -152,10 +152,11 @@ class KalziumGLWidget : public QGLWidget virtual ~KalziumGLWidget(); /** - * returns a pointer to the molecule being worked on + * @return Returns a pointer to the molecule being worked on */ - inline OpenBabel::OBMol* molecule () const - { return m_molecule; } + OpenBabel::OBMol* molecule () const { + return m_molecule; + } signals: /** @@ -164,11 +165,28 @@ class KalziumGLWidget : public QGLWidget void atomsSelected( QList atoms ); public slots: + /** + * The autorotation timer ended so we have to move the molecule a bit more + * not needed I guess + */ + void rotate(); + /** * sets the molecule which will be displayed * @param molecule the molecule to render */ void slotSetMolecule( OpenBabel::OBMol* molecule ); + + /** + * zoom in by 10% + */ + void slotZoomIn(); + + /** + * zoom out by 10% + */ + void slotZoomOut(); + /** * Sets the detail-grade in a range from 0 to 2 -- 2.47.3