Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

QGLExaminerViewer Class Reference

Examiner viewer class. More...

#include <QGLExaminerViewer.h>

Inheritance diagram for QGLExaminerViewer:

QGLViewer QSceneTreeViewer QSimpleViewer List of all members.

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

Detailed Description

Examiner viewer class.

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').

Author:
Markus Janich
Here's an example for an inherited viewer (CSimpleViewer) which implements catching a key event when the key 'v' was pressed. It also shoes an application which instantiates an object of that viewer and implements the slots PaintGL(), ResizeGL() and InitializeGL() inside the render program (CSimpleRenderer).
Files for a derived viewer:
/*
 * 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;
}

Files for a program doing the rendering:
/*
 * 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;
}

Main program:
/*
 * 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;
}


Constructor & Destructor Documentation

QGLExaminerViewer::QGLExaminerViewer QWidget *  parent = 0,
const char *  name = 0,
const QGLWidget *  shareWidget = 0,
WFlags  f = 0,
bool  viewertype = true,
const QGLFormat &  format = QGLFormat::defaultFormat()
[inline]
 

Default Constructor.

QGLExaminerViewer::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()
[inline]
 

Constructor including a camera for the home position of the scene.

NOTE: The current camera will also be set to the given homecam.

QGLExaminerViewer::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()
[inline]
 

Constructor including the bounding box of the scene.

virtual QGLExaminerViewer::~QGLExaminerViewer  )  [inline, virtual]
 

Default Destructor.


Member Function Documentation

void QGLExaminerViewer::closeEvent QCloseEvent *  event  )  [protected, virtual]
 

Implements a handler for CloseEvents. The default emits a sigViewerClosed()-signal and then calls the closeEvent()-function of the QWidget-class.

virtual void QGLExaminerViewer::enableMouseEvents bool  state  )  [inline, virtual]
 

Reimplements inherited function to stop the timer if running.

Reimplemented from QGLViewer.

bool QGLExaminerViewer::eventFilter QObject *  pqObject,
QEvent *  pqEvent
[protected]
 

Implements inherited method.

void QGLExaminerViewer::init bool  viewertype  )  [private]
 

Initializes all stuff that is unique to all constructors.

void QGLExaminerViewer::keyPressEvent QKeyEvent *  event  )  [protected, virtual]
 

Implements a handler for keyPressEvents. You can overwrite this method in your derived class. Original implementation manage the following keys:
i : opens a box with this key definitions
CURSOR_UP : rotate "back" around x-axis
CURSOR_DOWN : rotate "to the front" around x-axis
CURSOR_LEFT : rotate left around y-axis
CURSOR_RIGHT : rotate right around y-axis
a : view all
s : set homecamera to current camera
h : set current camera to homecamera
p : toggle projectionmode
+ : zoom in
- : zoom out
ESC or q : exit application
CTRL+CURSOR_LEFT : translate to the left
CTRL+CURSOR_RIGHT : translate to the right
CTRL+CURSOR_UP : translate up
CTRL+CURSOR_DOWN : translate down
SHIFT+CURSOR_UP : move forward
SHIFT+CURSOR_DOWN : move back

Reimplemented in QSimpleViewer, and QSceneTreeViewer.

void QGLExaminerViewer::makeFullViewer  )  [protected, virtual]
 

Manage the layout of a fullviewer after it is constructed or 'setFullViewer(true)' is called.

void QGLExaminerViewer::makeSimpleViewer  )  [protected, virtual]
 

Manage the layout of a non-fullviewer after it is constructed or 'setFullViewer(false)' is called.

void QGLExaminerViewer::ManageMouseMove QMouseEvent *  event  )  [protected, virtual]
 

Implements the method from the derived class QGLViever.

Reimplemented from QGLViewer.

void QGLExaminerViewer::ManageMousePress QMouseEvent *  event  )  [protected, virtual]
 

Implements the method from the derived class QGLViever.

Reimplemented from QGLViewer.

void QGLExaminerViewer::ManageMouseRelease QMouseEvent *  event  )  [protected, virtual]
 

Implements the method from the derived class QGLViever.

Reimplemented from QGLViewer.

void QGLExaminerViewer::setCamera const CCamera Camera,
CameraType  which = CurrentCam
[virtual]
 

Reimplements inherited function for interaction with zoom-slider.

void QGLExaminerViewer::setFullViewer bool  state  )  [virtual]
 

Reimplements inherited function.

Reimplemented from QGLViewer.

void QGLExaminerViewer::sigViewerClosed void   )  [signal]
 

This signal is emitted when the window of the viewer is closed.

void QGLExaminerViewer::sltCamRotStep  )  [private, slot]
 

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.

void QGLExaminerViewer::sltCamXRotate int  iAngle  )  [private, slot]
 

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.

void QGLExaminerViewer::sltCamYRotate int  iAngle  )  [private, slot]
 

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.

void QGLExaminerViewer::sltGoHome  )  [protected, virtual, slot]
 

Reimplementes inherited function for interaction with zoom-slider and other GUI things.

Reimplemented from QGLViewer.

void QGLExaminerViewer::sltMenuToggleRenderMode  )  [private, slot]
 

Toggles the render mode by using the menu.

void QGLExaminerViewer::sltResetXSlider  )  [slot]
 

Sets the value of the slider which handles the rotationangle around the x-axis to zero.

void QGLExaminerViewer::sltResetYSlider  )  [slot]
 

Sets the value of the slider which handles the rotationangle around the y-axis to zero.

void QGLExaminerViewer::sltSaveVectors  )  [private, slot]
 

Saves the ViewUp direction in 'vUp' and the ViewRight direction in 'vRight'.

virtual void QGLExaminerViewer::sltSetCamera const CCamera cCamera  )  [inline, protected, virtual, slot]
 

This slot sets the current camera to the one passed by the argument.

void QGLExaminerViewer::sltSetRefreshRate  )  [private, slot]
 

Shows an dialog to enter a new refresh rate.

void QGLExaminerViewer::sltSetZoom int  zoom_factor  )  [private, slot]
 

Adjusts the camera while zooming.

void QGLExaminerViewer::sltSetZoomSlider const QString &  qText  )  [private, slot]
 

void QGLExaminerViewer::sltSetZoomSlider double  rdFovy  )  [private, slot]
 

Sets the value of the slider, which handles the fovy angle, to the new value. The allowed range goes from 0 to 180 (degrees).

void QGLExaminerViewer::sltSetZoomSlider int  scaling  )  [slot]
 

Sets the value of the slider, which handles the fovy angle, to the new value. The allowed range goes from 0 to 18000.

See also:
ScalingChanged(int)

void QGLExaminerViewer::sltSetZoomText int  n  )  [private, slot]
 

void QGLExaminerViewer::sltSwitchBehave  )  [inline, private, slot]
 

Switches between old and new mousehandling.

void QGLExaminerViewer::sltTimeOut  )  [inline, private, slot]
 

Manages the timeout for animation.

void QGLExaminerViewer::sltToggleDeco  )  [private, slot]
 

Toggles between full and simple viewer.

void QGLExaminerViewer::sltToggleRenderMode  )  [protected, virtual, slot]
 

Reimplementation of the inherited slot.

Reimplemented from QGLViewer.

void QGLExaminerViewer::sltToggleSpinning  )  [inline, private, slot]
 

Toggles spinning on and off.

void QGLExaminerViewer::sltToggleStereo  )  [virtual, slot]
 

Reimplementation of the inherited slot.

Reimplemented from QGLViewer.

void QGLExaminerViewer::sltToggleToolTips  )  [private, slot]
 

Toggles between the tooltip on and off. Initially the tooltips are off


Member Data Documentation

QWidget* QGLExaminerViewer::m_apqWidgets[NUM_WIDGETS] [private]
 

CV3D QGLExaminerViewer::m_cDir [private]
 

CV3D QGLExaminerViewer::m_cRight [private]
 

CV3D QGLExaminerViewer::m_cUp [private]
 

bool QGLExaminerViewer::m_fAnimationOn [private]
 

bool QGLExaminerViewer::m_fLeftButtonPressed [private]
 

bool QGLExaminerViewer::m_fMiddleButtonPressed [private]
 

bool QGLExaminerViewer::m_fOldBehave [private]
 

bool QGLExaminerViewer::m_fShiftPressed [private]
 

bool QGLExaminerViewer::m_fToolTips [private]
 

int QGLExaminerViewer::m_nDecoID [private]
 

int QGLExaminerViewer::m_nLastRotAngle [private]
 

int QGLExaminerViewer::m_nMousePosX [private]
 

int QGLExaminerViewer::m_nMousePosY [private]
 

int QGLExaminerViewer::m_nQuadrant [private]
 

int QGLExaminerViewer::m_nSelectionID [private]
 

int QGLExaminerViewer::m_nSpinOnOffID [private]
 

int QGLExaminerViewer::m_nStereoID [private]
 

int QGLExaminerViewer::m_nSwitchBehaveID [private]
 

int QGLExaminerViewer::m_nTTipsID [private]
 

int QGLExaminerViewer::m_nXDiff [private]
 

int QGLExaminerViewer::m_nYDiff [private]
 

QTimer * QGLExaminerViewer::m_pqTimeOut [private]
 

QTimer* QGLExaminerViewer::m_pqTimer [private]
 

QBoxLayout* QGLExaminerViewer::m_pqTopLayout [private]
 

QSlider* QGLExaminerViewer::m_pqXRot [private]
 

QSlider * QGLExaminerViewer::m_pqYRot [private]
 

QSlider * QGLExaminerViewer::m_pqZoom [private]
 

QLineEdit* QGLExaminerViewer::m_pqZoomText [private]
 

float QGLExaminerViewer::m_rfXAlpha [private]
 

float QGLExaminerViewer::m_rfYAlpha [private]
 


The documentation for this class was generated from the following files:
Generated on Wed Sep 14 15:59:42 2005 for QGLViewer by  doxygen 1.4.4