#include <QGLExaminerViewer.h>
Inheritance diagram for QGLExaminerViewer:
Public Slots | |
void | sltResetXSlider () |
void | sltResetYSlider () |
void | sltSetZoomSlider (int scaling) |
virtual void | sltToggleStereo () |
Signals | |
void | sigViewerClosed (void) |
Public Member Functions | |
QGLExaminerViewer (QWidget *parent=0, const char *name=0, const QGLWidget *shareWidget=0, WFlags f=0, bool viewertype=true, const QGLFormat &format=QGLFormat::defaultFormat()) | |
QGLExaminerViewer (const CCamera &homecam, QWidget *parent=0, const char *name=0, const QGLWidget *shareWidget=0, WFlags f=0, bool viewertype=true, const QGLFormat &format=QGLFormat::defaultFormat()) | |
QGLExaminerViewer (const CBoundingBox3D &cBBox, QWidget *parent=0, const char *name=0, const QGLWidget *shareWidget=0, WFlags f=0, bool viewertype=true, const QGLFormat &format=QGLFormat::defaultFormat()) | |
virtual | ~QGLExaminerViewer () |
virtual void | setCamera (const CCamera &Camera, CameraType which=CurrentCam) |
virtual void | setFullViewer (bool state) |
virtual void | enableMouseEvents (bool state) |
Protected Slots | |
virtual void | sltToggleRenderMode () |
virtual void | sltGoHome () |
virtual void | sltSetCamera (const CCamera &cCamera) |
Protected Member Functions | |
virtual void | keyPressEvent (QKeyEvent *event) |
virtual void | closeEvent (QCloseEvent *event) |
virtual void | ManageMouseMove (QMouseEvent *event) |
virtual void | ManageMousePress (QMouseEvent *event) |
virtual void | ManageMouseRelease (QMouseEvent *event) |
bool | eventFilter (QObject *pqObject, QEvent *pqEvent) |
virtual void | makeFullViewer () |
virtual void | makeSimpleViewer () |
Private Slots | |
void | sltCamXRotate (int iAngle) |
void | sltCamYRotate (int iAngle) |
void | sltSetZoom (int zoom_factor) |
void | sltSetZoomSlider (double rdFovy) |
void | sltSetZoomSlider (const QString &qText) |
void | sltSetZoomText (int n) |
void | sltSaveVectors () |
void | sltCamRotStep () |
void | sltToggleDeco () |
void | sltToggleToolTips () |
void | sltToggleSpinning () |
void | sltSwitchBehave () |
void | sltMenuToggleRenderMode () |
void | sltTimeOut () |
void | sltSetRefreshRate () |
Private Member Functions | |
void | init (bool viewertype) |
Private Attributes | |
int | m_nMousePosX |
int | m_nMousePosY |
int | m_nXDiff |
int | m_nYDiff |
float | m_rfXAlpha |
float | m_rfYAlpha |
int | m_nQuadrant |
CV3D | m_cUp |
CV3D | m_cRight |
CV3D | m_cDir |
int | m_nLastRotAngle |
bool | m_fLeftButtonPressed |
bool | m_fMiddleButtonPressed |
QBoxLayout * | m_pqTopLayout |
QSlider * | m_pqXRot |
QSlider * | m_pqYRot |
QSlider * | m_pqZoom |
QLineEdit * | m_pqZoomText |
QTimer * | m_pqTimer |
QTimer * | m_pqTimeOut |
QWidget * | m_apqWidgets [NUM_WIDGETS] |
int | m_nSelectionID |
int | m_nDecoID |
int | m_nTTipsID |
int | m_nSpinOnOffID |
int | m_nSwitchBehaveID |
int | m_nStereoID |
bool | m_fToolTips |
bool | m_fAnimationOn |
bool | m_fOldBehave |
bool | m_fShiftPressed |
This is a viewer which inherits functionality from the baseclass QGLViewer. It implements the necessary functions which handle the mouseevents and creates a layoutmanager to handle the frame with the QGLWidget in it. It also creates some buttons and sliders which have new functionalities and it handles input from keyboard (try pressing 'i').
/* * QSimpleViewer.h * $Id: QSimpleViewer.h,v 1.3 2001/11/15 16:54:51 guenth Exp $ * * Copyright (C) 1999, 2000 Markus Janich, Michael Meissner * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * As a special exception to the GPL, the QGLViewer authors (Markus * Janich, Michael Meissner, Richard Guenther, Alexander Buck and Thomas * Woerner) give permission to link this program with Qt (non-)commercial * edition, and distribute the resulting executable, without including * the source code for the Qt (non-)commercial edition in the source * distribution. * */ // Description : Class inherits from QGLExaminerViewer // Purpose : Overloads the catch key method and emits an own key signal #ifndef QMYVIEWER__H #define QMYVIEWER__H // Qt #include <qlabel.h> #include <qslider.h> #include <qpushbutton.h> #include <qlayout.h> // Own #include "QGLExaminerViewer.h" // Defines #define ZOOMSCALING 100.0 // used for translating slidervalue to real (double) value. class QSimpleViewer : public QGLExaminerViewer { Q_OBJECT public: QSimpleViewer(const CCamera &homecam, QWidget *parent=0, const char *name=0, const QGLWidget *shareWidget=0, WFlags f=0, bool viewertype=true, const QGLFormat &format=QGLFormat::defaultFormat()) : QGLExaminerViewer(homecam, parent, name, shareWidget, f, viewertype, format) {}; virtual ~QSimpleViewer() {}; signals: void sigMyKey(int); protected: virtual void keyPressEvent(QKeyEvent *event); private: }; #endif // QMYVIEWER__H
/* * QSimpleViewer.cpp * $Id: QSimpleViewer.cpp,v 1.2 2001/11/15 16:54:51 guenth Exp $ * * Copyright (C) 1999, 2000 Markus Janich, Michael Meissner * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * As a special exception to the GPL, the QGLViewer authors (Markus * Janich, Michael Meissner, Richard Guenther, Alexander Buck and Thomas * Woerner) give permission to link this program with Qt (non-)commercial * edition, and distribute the resulting executable, without including * the source code for the Qt (non-)commercial edition in the source * distribution. * */ // Description : Class inherits from QGLExaminerViewer // Purpose : Overloads the catch key method and emits an own key signal // QT #include <qlabel.h> #include <qslider.h> #include <qpushbutton.h> #include <qlayout.h> // Own #include "QSimpleViewer.h" // Function : keyPressEvent // Parameters : QKeyEvent *event // Purpose : Catch any key and emit a signal containing the // key's ascii code // Comments : void QSimpleViewer::keyPressEvent(QKeyEvent *event) /********************************************************************/ { switch(event->state()) { case NoButton: cout << endl << "QSimpleViewer: Emitting the signal for the "; cout << "pressed key" << endl; emit(sigMyKey(event->ascii())); break; } QGLExaminerViewer::keyPressEvent(event); return; }
/* * CSimpleRenderer.h * $Id: CSimpleRenderer.h,v 1.3 2001/11/15 16:54:51 guenth Exp $ * * Copyright (C) 1999, 2000 Markus Janich, Michael Meissner * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * As a special exception to the GPL, the QGLViewer authors (Markus * Janich, Michael Meissner, Richard Guenther, Alexander Buck and Thomas * Woerner) give permission to link this program with Qt (non-)commercial * edition, and distribute the resulting executable, without including * the source code for the Qt (non-)commercial edition in the source * distribution. * */ // Description : Definition of an example renderer drawing a cube // in wire frame and catching a key signal #ifndef CRENDERER__H #define CRENDERER__H // Own #include "QSimpleViewer.h" // Qt #include <qmainwindow.h> #include <qslider.h> #include <qgl.h> // System #include <math.h> class CSimpleRenderer : public QObject { Q_OBJECT //****** All methods ****** public: CSimpleRenderer(QGLViewer*); ~CSimpleRenderer(); QGLViewer* getViewer(void) { return m_pViewer; }; void MakeGlList(); private: GLuint processHits(GLint hits, GLuint buffer[]); // **** All the slots ***** private slots: void sltInitializeGL(); void sltResizeGL(int w, int h); void sltPaintGL(); void sltManageSelection(QMouseEvent *pqEvent); void sltManageRelease(QMouseEvent *pqEvent); void sltManageMove(QMouseEvent *pqEvent); void sltCatchKey(int); void sltResetSelection(); private: void renderScene(void); void renderSolidSphere(const CP3D &cCenter, float radius, int n1, int n2, float lw=2.5); void renderWireSphere(const CP3D &cCenter, float radius, int n1, int n2, float lw=2.5); //****** All data ****** QGLViewer *m_pViewer; GLuint m_glDispList; bool m_afSelected[12]; // select state of the spheres bool m_fLeftButtonPressed; // saves left button state bool m_fMiddleButtonPressed; // saves middle button state bool m_fRightButtonPressed; // saves right button state CP3D m_cSphereCenter[12]; // saves centers of the spheres int m_nMousePosX, m_nMousePosY; // last mouse position }; #endif // CRENDERER__H
/* * CSimpleRenderer.cpp * $Id: CSimpleRenderer.cpp,v 1.2 2001/11/15 16:54:51 guenth Exp $ * * Copyright (C) 1999, 2000 Markus Janich, Michael Meissner * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * As a special exception to the GPL, the QGLViewer authors (Markus * Janich, Michael Meissner, Richard Guenther, Alexander Buck and Thomas * Woerner) give permission to link this program with Qt (non-)commercial * edition, and distribute the resulting executable, without including * the source code for the Qt (non-)commercial edition in the source * distribution. * */ // Description : Implementation of the example renderer // Own #include "CSimpleRenderer.h" // Qt #include <qapplication.h> #include <qstring.h> #include <qgl.h> #include <qmenubar.h> // only for the menu #include <qpopupmenu.h> // only for the menu // System #include <iostream.h> #include <math.h> // defines #define SELECT_BUF_SIZE 512 // Function : CSimpleRenderer // Parameters : // Purpose : // Comments : CSimpleRenderer::CSimpleRenderer(QGLViewer *pViewer) : QObject() /******************************************************************/ { int i; m_pViewer = pViewer; for (i=0; i<12; i++) m_afSelected[i] = false; m_fLeftButtonPressed = m_fMiddleButtonPressed = m_fRightButtonPressed = false; m_cSphereCenter[0] = CP3D(0.0, 0.0, 1.0); m_cSphereCenter[1] = CP3D(-1.0, 0.0, 0.0); m_cSphereCenter[2] = CP3D(1.0, 0.0, 0.0); m_cSphereCenter[3] = CP3D(0.0, 0.0, -2.5); m_cSphereCenter[4] = CP3D(0.0, -3.0, 0.0); m_cSphereCenter[5] = CP3D(-3.5, 0.0, 0.0); m_cSphereCenter[6] = CP3D(0.0, 0.0, -1.0); m_cSphereCenter[7] = CP3D(0.0, 1.0, 0.0); m_cSphereCenter[8] = CP3D(0.0,-1.0, 0.0); m_cSphereCenter[9] = CP3D(0.0, 0.0, 2.5); m_cSphereCenter[10] = CP3D(0.0, 3.0, 0.0); m_cSphereCenter[11] = CP3D(3.5, 0.0, 0.0); MakeGlList(); return; } // Function : ~CSimpleRenderer // Parameters : // Purpose : // Comments : CSimpleRenderer::~CSimpleRenderer() /**************************************************************/ { glDeleteLists(m_glDispList, 1); } // Function : MakeGlList // Parameters : // Purpose : // Comments : void CSimpleRenderer::MakeGlList() /**************************************************************/ { m_pViewer->makeCurrent(); // generate display list for bounding box if (glIsList(m_glDispList)) glDeleteLists(m_glDispList, 1); m_glDispList = glGenLists(1); glNewList(m_glDispList, GL_COMPILE); glLineWidth(1.5); // Determine bounding box CP3D LowerLeft = m_pViewer->getCamera().getBoundingBox().getLowerLeft(); CP3D UpperRight = m_pViewer->getCamera().getBoundingBox().getUpperRight(); // Draw box glColor3f(1.0, 1.0, 1.0); glBegin(GL_LINE_LOOP); glVertex3f(LowerLeft[0], LowerLeft[1], LowerLeft[2]); glVertex3f(UpperRight[0], LowerLeft[1], LowerLeft[2]); glVertex3f(UpperRight[0], UpperRight[1], LowerLeft[2]); glVertex3f(LowerLeft[0], UpperRight[1], LowerLeft[2]); glEnd(); glBegin(GL_LINE_LOOP); glVertex3f(LowerLeft[0], LowerLeft[1], UpperRight[2]); glVertex3f(UpperRight[0], LowerLeft[1], UpperRight[2]); glVertex3f(UpperRight[0], UpperRight[1], UpperRight[2]); glVertex3f(LowerLeft[0], UpperRight[1], UpperRight[2]); glEnd(); glBegin(GL_LINES); glVertex3f(LowerLeft[0], LowerLeft[1], LowerLeft[2]); glVertex3f(LowerLeft[0], LowerLeft[1], UpperRight[2]); glEnd(); glBegin(GL_LINES); glVertex3f(UpperRight[0], LowerLeft[1], LowerLeft[2]); glVertex3f(UpperRight[0], LowerLeft[1], UpperRight[2]); glEnd(); glBegin(GL_LINES); glVertex3f(UpperRight[0], UpperRight[1], LowerLeft[2]); glVertex3f(UpperRight[0], UpperRight[1], UpperRight[2]); glEnd(); glBegin(GL_LINES); glVertex3f(LowerLeft[0], UpperRight[1], LowerLeft[2]); glVertex3f(LowerLeft[0], UpperRight[1], UpperRight[2]); glEnd(); glEndList(); return; } // Function : renderScene // Parameters : ... // Purpose : // Comments : void CSimpleRenderer::renderScene(void) /**************************************************************/ { float mat_specular[] = { .72, .8, .93, 1.0 }; // render bounding box glCallList(m_glDispList); glDepthFunc(GL_LEQUAL); glEnable(GL_DEPTH_TEST); glEnable(GL_LINE_SMOOTH); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glLineWidth(1.5); glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular); glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 128.0); glEnable(GL_LIGHT0); glEnable(GL_LIGHTING); glEnable(GL_NORMALIZE); if(m_afSelected[0]) glColor3f(1.0, 1.0, 1.0); else glColor3f(.5, .5, 1.0); glLoadName(1); // assign name '1' which will reply in selectionmode renderSolidSphere(m_cSphereCenter[0], 1.0,16,16); if(m_afSelected[1]) glColor3f(1.0, 1.0, 1.0); else glColor3f(1.0, 0.0, 0.0); glLoadName(2); // assign name '2' which will reply in selectionmode renderSolidSphere(m_cSphereCenter[1], 1.0,16,16); if(m_afSelected[2]) glColor3f(1.0, 1.0, 1.0); else glColor3f(0.0, 1.0, 0.0); glLoadName(3); // assign name '3' which will reply in selectionmode renderSolidSphere(m_cSphereCenter[2], 1.0,16,16); if(m_afSelected[3]) glColor3f(1.0, 1.0, 1.0); else glColor3f(0.0, 1.0, 1.0); glLoadName(4); // assign name '4' which will reply in selectionmode renderSolidSphere(m_cSphereCenter[3], 0.5,8,8); if(m_afSelected[4]) glColor3f(1.0, 1.0, 1.0); else glColor3f(1.0, 0.0, 1.0); glLoadName(5); // assign name '5' which will reply in selectionmode renderSolidSphere(m_cSphereCenter[4], 0.5,8,8); if(m_afSelected[5]) glColor3f(1.0, 1.0, 1.0); else glColor3f(1.0, 1.0, 0.0); glLoadName(6); // assign name '6' which will reply in selectionmode renderSolidSphere(m_cSphereCenter[5], 0.5,8,8); glDisable(GL_LIGHT0); glDisable(GL_LIGHTING); if(m_afSelected[6]) glColor3f(1.0, 1.0, 1.0); else glColor3f(1.0, 1.0, 0.0); glLoadName(7); // assign name '7' which will reply in selectionmode renderWireSphere(m_cSphereCenter[6], 1.0,16,16); if(m_afSelected[7]) glColor3f(1.0, 1.0, 1.0); else glColor3f(0.0, 0.0, 1.0); glLoadName(8); // assign name '8' which will reply in selectionmode renderWireSphere(m_cSphereCenter[7], 1.0,16,16); if(m_afSelected[8]) glColor3f(1.0, 1.0, 1.0); else glColor3f(1.0, 0.0, 1.0); glLoadName(9); // assign name '9' which will reply in selectionmode renderWireSphere(m_cSphereCenter[8], 1.0,16,16); if(m_afSelected[9]) glColor3f(1.0, 1.0, 1.0); else glColor3f(1.0, 0.0, 0.0); glLoadName(10); // assign name '10' which will reply in selectionmode renderWireSphere(m_cSphereCenter[9], 0.5,16,16,1.0); if(m_afSelected[10]) glColor3f(1.0, 1.0, 1.0); else glColor3f(0.0, 1.0, 0.0); glLoadName(11); // assign name '11' which will reply in selectionmode renderWireSphere(m_cSphereCenter[10], 0.5,16,16,1.0); if(m_afSelected[11]) glColor3f(1.0, 1.0, 1.0); else glColor3f(0.0, 0.0, 1.0); glLoadName(12); // assign name '12' which will reply in selectionmode renderWireSphere(m_cSphereCenter[11], 0.5,16,16,1.0); return; } // Function : renderSolidSphere // Parameters : ... // Purpose : // Comments : void CSimpleRenderer::renderSolidSphere(const CP3D &cCenter, float radius, int n1,int n2,float lw) /**************************************************************/ { static GLUquadricObj *quadObj; static int entry = 0; int sphere_slices = n1; int sphere_stacks = n2; glEnable(GL_COLOR_MATERIAL); glPushMatrix(); glTranslatef(cCenter.getX(), cCenter.getY(), cCenter.getZ()); quadObj = gluNewQuadric (); if (!entry) { gluQuadricDrawStyle (quadObj, (GLenum)GLU_FILL); gluQuadricOrientation(quadObj, (GLenum)GLU_OUTSIDE); gluQuadricNormals (quadObj, (GLenum)GLU_SMOOTH); } gluSphere (quadObj, radius, sphere_slices, sphere_stacks); gluDeleteQuadric(quadObj); glPopMatrix(); glDisable(GL_COLOR_MATERIAL); return; } // Function : renderWireSphere // Parameters : ... // Purpose : // Comments : void CSimpleRenderer::renderWireSphere(const CP3D &cCenter, float radius, int n1,int n2,float lw) /**************************************************************/ { static GLUquadricObj *quadObj; static int entry = 0; int sphere_slices = n1; int sphere_stacks = n2; glLineWidth(lw); glEnable(GL_COLOR_MATERIAL); glPushMatrix(); glTranslatef(cCenter.getX(), cCenter.getY(), cCenter.getZ()); quadObj = gluNewQuadric (); if (!entry) { gluQuadricDrawStyle (quadObj, (GLenum)GLU_LINE); gluQuadricOrientation(quadObj, (GLenum)GLU_OUTSIDE); gluQuadricNormals (quadObj, (GLenum)GLU_SMOOTH); } gluSphere (quadObj, radius, sphere_slices, sphere_stacks); gluDeleteQuadric(quadObj); glPopMatrix(); glDisable(GL_COLOR_MATERIAL); return; } // Function : sltCatchKey // Parameters : int nTmp // Purpose : // Comments : void CSimpleRenderer::sltCatchKey(int nTmp) /**************************************************************/ { cout << "CSimpleRenderer: Caught the signal! It is a " << nTmp; cout << " (ascii)" << endl; return; } // Function : sltResetSelection // Parameters : // Purpose : Slot to reset selection // Comments : void CSimpleRenderer::sltResetSelection() /**************************************************************/ { int i; for (i=0; i<12; i++) m_afSelected[i] = false; m_pViewer->sltUpdateView(); return; } // Function : sltInitializeGL // Parameters : // Purpose : Set up the OpenGL rendering state // Comments : void CSimpleRenderer::sltInitializeGL() /**************************************************************/ { m_pViewer->makeCurrent(); glClearColor(0.0, 0.0, 0.0, 0.0); // Let OpenGL clear to black glShadeModel(GL_SMOOTH); // enable flat shading glMatrixMode(GL_MODELVIEW); return; } // Function : sltResizeGL // Parameters : // Purpose : // Comments : if something special should be done after resizing void CSimpleRenderer::sltResizeGL(int w, int h) /**************************************************************/ { return; } // Function : sltPaintGL // Parameters : // Purpose : Slot for paint "events" // Comments : Actual openGL commands for drawing box are performed void CSimpleRenderer::sltPaintGL() /**************************************************************/ { // now render your own stuff renderScene(); return; } // Function : sltManageSelection // Parameters : // Purpose : // Comments : void CSimpleRenderer::sltManageSelection(QMouseEvent *pqEvent) /**************************************************************/ { GLuint selectBuf[SELECT_BUF_SIZE]; // HARD coded limit!!! GLint hits; GLint viewport[4]; double ardVVolume[6]; unsigned int nChosen; // Save state of mouse buttons if ( pqEvent->button() == LeftButton ) { m_fLeftButtonPressed = true; } if ( pqEvent->button() == MidButton ) { m_fMiddleButtonPressed = true; } if ( pqEvent->button() == RightButton ) { m_fRightButtonPressed = true; } // save mouse position m_nMousePosX = pqEvent->x(); m_nMousePosY = pqEvent->y(); if(m_fLeftButtonPressed) { // get camera data m_pViewer->getCameraPtr()->getVVolume(ardVVolume); m_pViewer->makeCurrent(); glGetIntegerv(GL_VIEWPORT, viewport); glSelectBuffer(SELECT_BUF_SIZE, selectBuf); glRenderMode(GL_SELECT); glInitNames(); glPushName(0); glPushMatrix(); glMatrixMode(GL_PROJECTION); glLoadIdentity(); // create 10x10 pixel picking region near cursor location. gluPickMatrix((GLdouble) m_nMousePosX, (GLdouble) (viewport[3] - m_nMousePosY), 5.0, 5.0, viewport); if (m_pViewer->getProjectionMode() == QGLViewer::perspective) glFrustum(ardVVolume[0], ardVVolume[1], ardVVolume[2], ardVVolume[3], ardVVolume[4], ardVVolume[5]); else glOrtho(ardVVolume[0], ardVVolume[1], ardVVolume[2], ardVVolume[3], ardVVolume[4], ardVVolume[5]); glMatrixMode(GL_MODELVIEW); renderScene(); glPopMatrix(); glFlush(); hits = glRenderMode(GL_RENDER); nChosen = processHits(hits, selectBuf); if(nChosen>0) m_afSelected[nChosen-1] = m_afSelected[nChosen-1] ? false : true; m_pViewer->sltUpdateView(); } return; } // Function : processHits // Parameters : // Purpose : processHits prints out the contents of the selection array // Comments : GLuint CSimpleRenderer::processHits (GLint hits, GLuint buffer[]) /**************************************************************/ { unsigned int i, j; GLuint names, nChosen, *ptr; float rfZValue, rfZ1; if(hits != 0) { nChosen = 1; rfZValue = (float)*(buffer+1)/0x7fffffff; cout << "Number of hits is = " << hits << endl; cout << "Now show all hits!" << endl; ptr = (GLuint *) buffer; for (i=0; i<hits; i++) { // for each hit names = *ptr; cout << "Number of names for this hit: " << ptr; ptr++; rfZ1 = (float) *ptr/0x7fffffff; cout << " z1 = " << rfZ1; ptr++; cout << " z2 = " << (float) *ptr/0x7fffffff << endl; ptr++; cout << " ..... and the names are: "; if(rfZValue >= rfZ1) { rfZValue = rfZ1; nChosen = *ptr; } for (j=0; j<names; j++) { // for each name cout << *ptr << " "; ptr++; } cout << endl; } } else { nChosen = 0; } cout << "Chosen sphere: " <<nChosen << endl; return nChosen; } // Function : sltManageRelease // Parameters : // Purpose : // Comments : void CSimpleRenderer::sltManageRelease(QMouseEvent *pqEvent) /**************************************************************/ { // Save state of mouse buttons if ( pqEvent->button() == LeftButton ) { m_fLeftButtonPressed = false; } if ( pqEvent->button() == MidButton ) { m_fMiddleButtonPressed = false; } if ( pqEvent->button() == RightButton ) { m_fRightButtonPressed = false; } } // Function : sltManageMove // Parameters : // Purpose : // Comments : void CSimpleRenderer::sltManageMove(QMouseEvent *pqEvent) /**************************************************************/ { int i, nDiffX, nDiffY; float rfDistance, rfTransX, rfTransY, rfVTan, rfHTan; CCamera *pCamera; CP3D cNewCenter; if(m_fMiddleButtonPressed) { nDiffX = pqEvent->x() - m_nMousePosX; nDiffY = m_nMousePosY - pqEvent->y(); pCamera = m_pViewer->getCameraPtr(); // save mouse position m_nMousePosX = pqEvent->x(); m_nMousePosY = pqEvent->y(); // now do the move for(i=0; i<12; i++) { if(m_afSelected[i]) { // calculations just heuristic. Don't really try to understand it. rfDistance = (m_cSphereCenter[i] - pCamera->getEyePos()).getNorm(); rfVTan = tan(pCamera->getFovy()/360.0*M_PI); rfHTan = tan((pCamera->getFovy()*pCamera->getRatio()) / 360.0 * M_PI); rfTransX = (rfHTan * float(nDiffX)) / m_pViewer->getDrawArea()->width() * rfDistance * 2.1; rfTransY = (rfVTan * float(nDiffY)) / m_pViewer->getDrawArea()->height() * rfDistance * 2.1; cNewCenter = m_cSphereCenter[i] + pCamera->getViewRight() * rfTransX + pCamera->getViewUp() * rfTransY; if(pCamera->getBoundingBox().isInside(cNewCenter)) m_cSphereCenter[i] = cNewCenter; } } m_pViewer->sltUpdateView(); } return; }
/* * CameraPathPlayer.cpp * * Copyright (C) 2001 Michael Meissner, Alexander Buck * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * As a special exception to the GPL, the QGLViewer authors (Markus * Janich, Michael Meissner, Richard Guenther, Alexander Buck and Thomas * Woerner) give permission to link this program with Qt (non-)commercial * edition, and distribute the resulting executable, without including * the source code for the Qt (non-)commercial edition in the source * distribution. * */ /* [tw] 2001/04/29 initial version */ // System #include <stdlib.h> #include <string.h> #include <stdio.h> // Qt #include <qapplication.h> #include <qstring.h> #include <qgl.h> #include <qmenubar.h> // only for the menu #include <qpopupmenu.h> // only for the menu // QGLViewer #include <QGLExaminerViewer.h> #include <CP3D.h> // Own #include "CPlayerRenderer.h" #include "CBoundingBox3D.h" #include "QCameraPathPlayer.h" // // // // // M A I N // // // // // int main(int argc, char *argv[]) { // start Qt stuff QApplication::setColorSpec(QApplication::CustomColor); QApplication app(argc,argv); QGLFormat f; QGLFormat::setDefaultFormat(f); QGLExaminerViewer *pViewer = new QGLExaminerViewer(CCamera(0.0, 0.0, -25.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, CBoundingBox3D(-4.0,-4.0,-4.0, 4.0,4.0,4.0)), NULL, "viewer", NULL, 0, true, f); // fullviewer Q_CHECK_PTR(pViewer); QCameraPathPlayer *pPlayer = new QCameraPathPlayer(pViewer); Q_CHECK_PTR(pPlayer); pPlayer->show(); // generate new renderer CPlayerRenderer *pRenderer = new CPlayerRenderer(pViewer); Q_CHECK_PTR(pRenderer); // Connect signals of pPlayer with slots of renderer QObject::connect(pViewer, SIGNAL(sigInitGL()), pRenderer, SLOT(sltInitializeGL())); QObject::connect(pViewer, SIGNAL(sigResizeGL(int,int)), pRenderer, SLOT(sltResizeGL(int,int))); QObject::connect(pViewer, SIGNAL(sigRedrawGL()), pRenderer, SLOT(sltPaintGL())); // Launch pPlayer app.setMainWidget(pViewer); pViewer->resize(450, 420); pViewer->show(); int nRet = app.exec(); delete pRenderer; delete pPlayer; delete pViewer; return nRet; }
|
Default Constructor. |
|
Constructor including a camera for the home position of the scene.
|
|
Constructor including the bounding box of the scene. |
|
Default Destructor. |
|
Implements a handler for CloseEvents. The default emits a sigViewerClosed()-signal and then calls the closeEvent()-function of the QWidget-class. |
|
Reimplements inherited function to stop the timer if running. Reimplemented from QGLViewer. |
|
Implements inherited method. |
|
Initializes all stuff that is unique to all constructors. |
|
Implements a handler for keyPressEvents. You can overwrite this method in your derived class. Original implementation manage the following keys: Reimplemented in QSimpleViewer, and QSceneTreeViewer. |
|
Manage the layout of a fullviewer after it is constructed or 'setFullViewer(true)' is called. |
|
Manage the layout of a non-fullviewer after it is constructed or 'setFullViewer(false)' is called. |
|
Implements the method from the derived class QGLViever. Reimplemented from QGLViewer. |
|
Implements the method from the derived class QGLViever. Reimplemented from QGLViewer. |
|
Implements the method from the derived class QGLViever. Reimplemented from QGLViewer. |
|
Reimplements inherited function for interaction with zoom-slider. Reimplemented from QGLViewer. |
|
Reimplements inherited function. Reimplemented from QGLViewer. |
|
This signal is emitted when the window of the viewer is closed. |
|
Rotates the camera around the x- and y-axis depending on the values saved in 'm_nXDiff', 'm_nYDiff', 'm_rfXAlpha' and 'm_rfYAlpha'. Usually it will be connected with a Timer for animated rotation. |
|
Rotate camera around the x-axis with an angle of 'iAngle' degrees. This slot emits the signal sigCameraChanged() for the application which owns the viewer. |
|
Rotate camera around the y-axis with an angle of 'iAngle' degrees. This slot emits the signal sigCameraChanged() for the application which owns the viewer. |
|
Reimplementes inherited function for interaction with zoom-slider and other GUI things. Reimplemented from QGLViewer. |
|
Toggles the render mode by using the menu. |
|
Sets the value of the slider which handles the rotationangle around the x-axis to zero. |
|
Sets the value of the slider which handles the rotationangle around the y-axis to zero. |
|
Saves the ViewUp direction in 'vUp' and the ViewRight direction in 'vRight'. |
|
This slot sets the current camera to the one passed by the argument. |
|
Shows an dialog to enter a new refresh rate. |
|
Adjusts the camera while zooming. |
|
|
|
Sets the value of the slider, which handles the fovy angle, to the new value. The allowed range goes from 0 to 180 (degrees). |
|
Sets the value of the slider, which handles the fovy angle, to the new value. The allowed range goes from 0 to 18000.
|
|
|
|
Switches between old and new mousehandling. |
|
Manages the timeout for animation. |
|
Toggles between full and simple viewer. |
|
Reimplementation of the inherited slot. Reimplemented from QGLViewer. |
|
Toggles spinning on and off. |
|
Reimplementation of the inherited slot. Reimplemented from QGLViewer. |
|
Toggles between the tooltip on and off. Initially the tooltips are off |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|