QGLExaminerViewer Class Reference
Examiner viewer class.
More...
#include <QGLExaminerViewer.h>
Inheritance diagram for QGLExaminerViewer:
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:
#ifndef QMYVIEWER__H
#define QMYVIEWER__H
#include <qlabel.h>
#include <qslider.h>
#include <qpushbutton.h>
#include <qlayout.h>
#include "QGLExaminerViewer.h"
#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
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
#ifndef QMYVIEWER__H
00036
#define QMYVIEWER__H
00037
00038
00039
00041
#include <qlabel.h>
00042
#include <qslider.h>
00043
#include <qpushbutton.h>
00044
#include <qlayout.h>
00045
00046
00047
00049
#include "QGLExaminerViewer.h"
00050
00051
00052
00054
#define ZOOMSCALING 100.0 // used for translating slidervalue to real (double) value.
00055
00056
00057
00067
class QSimpleViewer :
public QGLExaminerViewer {
00068 Q_OBJECT
00069
00070
public:
00071
00074
QSimpleViewer(
const CCamera &homecam, QWidget *parent=0,
00075
const char *name=0,
const QGLWidget *shareWidget=0,
00076 WFlags f=0,
bool viewertype=
true,
00077
const QGLFormat &format=QGLFormat::defaultFormat())
00078 :
QGLExaminerViewer(homecam, parent, name, shareWidget, f, viewertype, format) {};
00079
00081
virtual ~
QSimpleViewer() {};
00082
00083 signals:
00084
00086
void sigMyKey(
int);
00087
00088
00089
protected:
00090
00092
virtual void keyPressEvent(QKeyEvent *event);
00093
00094
private:
00095 };
00096
00097
#endif // QMYVIEWER__H
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00044
00046
#include <qlabel.h>
00047
#include <qslider.h>
00048
#include <qpushbutton.h>
00049
#include <qlayout.h>
00050
00051
00052
00054
#include "QSimpleViewer.h"
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
void QSimpleViewer::keyPressEvent(QKeyEvent *event)
00065
00066 {
00067
switch(event->state()) {
00068
case NoButton:
00069 cout << endl <<
"QSimpleViewer: Emitting the signal for the ";
00070 cout <<
"pressed key" << endl;
00071 emit(
sigMyKey(event->ascii()));
00072
break;
00073 }
00074
QGLExaminerViewer::keyPressEvent(event);
00075
00076
return;
00077 }
Files for a program doing the rendering:
#ifndef CRENDERER__H
#define CRENDERER__H
#include "QSimpleViewer.h"
#include <qmainwindow.h>
#include <qslider.h>
#include <qgl.h>
#include <math.h>
class CSimpleRenderer :
public QObject {
Q_OBJECT
public:
CSimpleRenderer(
QGLViewer*);
~
CSimpleRenderer();
QGLViewer* getViewer(
void) {
return m_pViewer; };
void MakeGlList();
private:
GLuint processHits(GLint hits, GLuint buffer[]);
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);
QGLViewer *m_pViewer;
GLuint m_glDispList;
bool m_afSelected[12];
bool m_fLeftButtonPressed;
bool m_fMiddleButtonPressed;
bool m_fRightButtonPressed;
CP3D m_cSphereCenter[12];
int m_nMousePosX, m_nMousePosY;
};
#endif // CRENDERER__H
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
#ifndef CRENDERER__H
00035
#define CRENDERER__H
00036
00037
00038
00040
#include "QSimpleViewer.h"
00041
00042
00044
#include <qmainwindow.h>
00045
#include <qslider.h>
00046
#include <qgl.h>
00047
00048
00049
00051
#include <math.h>
00052
00053
00054
00055
00062
class CSimpleRenderer :
public QObject {
00063 Q_OBJECT
00064
00065
00066
00067
public:
00068
CSimpleRenderer(
QGLViewer*);
00069
00070 ~
CSimpleRenderer();
00071
00072
QGLViewer* getViewer(
void) {
return m_pViewer; };
00073
00074
void MakeGlList();
00075
00076
private:
00078 GLuint processHits(GLint hits, GLuint buffer[]);
00079
00080
00081
00082
private slots:
00083
00085
void sltInitializeGL();
00086
00088
void sltResizeGL(
int w,
int h);
00089
00091
void sltPaintGL();
00092
00094
void sltManageSelection(QMouseEvent *pqEvent);
00095
00097
void sltManageRelease(QMouseEvent *pqEvent);
00098
00100
void sltManageMove(QMouseEvent *pqEvent);
00101
00103
void sltCatchKey(
int);
00104
00107
void sltResetSelection();
00108
00109
private:
00110
00112
void renderScene(
void);
00113
00115
void renderSolidSphere(
const CP3D &cCenter,
float radius,
00116
int n1,
int n2,
float lw=2.5);
00117
00119
void renderWireSphere(
const CP3D &cCenter,
float radius,
00120
int n1,
int n2,
float lw=2.5);
00121
00122
00123
00124
QGLViewer *m_pViewer;
00125
00126 GLuint m_glDispList;
00127
00128
bool m_afSelected[12];
00129
00130
bool m_fLeftButtonPressed;
00131
bool m_fMiddleButtonPressed;
00132
bool m_fRightButtonPressed;
00133
00134
CP3D m_cSphereCenter[12];
00135
00136
int m_nMousePosX, m_nMousePosY;
00137 };
00138
00139
#endif // CRENDERER__H
#include "CSimpleRenderer.h"
#include <qapplication.h>
#include <qstring.h>
#include <qgl.h>
#include <qmenubar.h>
#include <qpopupmenu.h>
#include <iostream.h>
#include <math.h>
#define SELECT_BUF_SIZE 512
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;
}
CSimpleRenderer::~CSimpleRenderer()
{
glDeleteLists(m_glDispList, 1);
}
void CSimpleRenderer::MakeGlList()
{
m_pViewer->
makeCurrent();
if (glIsList(m_glDispList))
glDeleteLists(m_glDispList, 1);
m_glDispList = glGenLists(1);
glNewList(m_glDispList, GL_COMPILE);
glLineWidth(1.5);
CP3D LowerLeft =
m_pViewer->
getCamera().
getBoundingBox().
getLowerLeft();
CP3D UpperRight =
m_pViewer->
getCamera().
getBoundingBox().
getUpperRight();
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;
}
void CSimpleRenderer::renderScene(
void)
{
float mat_specular[] = { .72, .8, .93, 1.0 };
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
renderWireSphere(m_cSphereCenter[11], 0.5,16,16,1.0);
return;
}
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;
}
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;
}
void CSimpleRenderer::sltCatchKey(
int nTmp)
{
cout <<
"CSimpleRenderer: Caught the signal! It is a " << nTmp;
cout <<
" (ascii)" << endl;
return;
}
void CSimpleRenderer::sltResetSelection()
{
int i;
for (i=0; i<12; i++)
m_afSelected[i] =
false;
m_pViewer->
sltUpdateView();
return;
}
void CSimpleRenderer::sltInitializeGL()
{
m_pViewer->
makeCurrent();
glClearColor(0.0, 0.0, 0.0, 0.0);
glShadeModel(GL_SMOOTH);
glMatrixMode(GL_MODELVIEW);
return;
}
void CSimpleRenderer::sltResizeGL(
int w,
int h)
{
return;
}
void CSimpleRenderer::sltPaintGL()
{
renderScene();
return;
}
void CSimpleRenderer::sltManageSelection(QMouseEvent *pqEvent)
{
GLuint selectBuf[
SELECT_BUF_SIZE];
GLint hits;
GLint viewport[4];
double ardVVolume[6];
unsigned int nChosen;
if ( pqEvent->button() == LeftButton ) {
m_fLeftButtonPressed =
true;
}
if ( pqEvent->button() == MidButton ) {
m_fMiddleButtonPressed =
true;
}
if ( pqEvent->button() == RightButton ) {
m_fRightButtonPressed =
true;
}
m_nMousePosX = pqEvent->x();
m_nMousePosY = pqEvent->y();
if(
m_fLeftButtonPressed) {
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();
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;
}
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++) {
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++) {
cout << *ptr <<
" ";
ptr++;
}
cout << endl;
}
}
else {
nChosen = 0;
}
cout <<
"Chosen sphere: " <<nChosen << endl;
return nChosen;
}
void CSimpleRenderer::sltManageRelease(QMouseEvent *pqEvent)
{
if ( pqEvent->button() == LeftButton ) {
m_fLeftButtonPressed =
false;
}
if ( pqEvent->button() == MidButton ) {
m_fMiddleButtonPressed =
false;
}
if ( pqEvent->button() == RightButton ) {
m_fRightButtonPressed =
false;
}
}
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();
m_nMousePosX = pqEvent->x();
m_nMousePosY = pqEvent->y();
for(i=0; i<12; i++) {
if(
m_afSelected[i]) {
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;
}
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00042
00044
#include "CSimpleRenderer.h"
00045
00046
00047
00049
#include <qapplication.h>
00050
#include <qstring.h>
00051
#include <qgl.h>
00052
#include <qmenubar.h>
00053
#include <qpopupmenu.h>
00054
00055
00057
#include <iostream.h>
00058
#include <math.h>
00059
00060
00062
#define SELECT_BUF_SIZE 512
00063
00064
00065
00066
00067
00068
00069
00070
CSimpleRenderer::CSimpleRenderer(
QGLViewer *pViewer)
00071 : QObject()
00072
00073 {
00074
int i;
00075
00076 m_pViewer = pViewer;
00077
00078
for (i=0; i<12; i++)
00079 m_afSelected[i] =
false;
00080
00081 m_fLeftButtonPressed = m_fMiddleButtonPressed = m_fRightButtonPressed =
false;
00082
00083 m_cSphereCenter[0] =
CP3D(0.0, 0.0, 1.0);
00084 m_cSphereCenter[1] = CP3D(-1.0, 0.0, 0.0);
00085 m_cSphereCenter[2] = CP3D(1.0, 0.0, 0.0);
00086 m_cSphereCenter[3] = CP3D(0.0, 0.0, -2.5);
00087 m_cSphereCenter[4] = CP3D(0.0, -3.0, 0.0);
00088 m_cSphereCenter[5] = CP3D(-3.5, 0.0, 0.0);
00089 m_cSphereCenter[6] = CP3D(0.0, 0.0, -1.0);
00090 m_cSphereCenter[7] = CP3D(0.0, 1.0, 0.0);
00091 m_cSphereCenter[8] = CP3D(0.0,-1.0, 0.0);
00092 m_cSphereCenter[9] = CP3D(0.0, 0.0, 2.5);
00093 m_cSphereCenter[10] = CP3D(0.0, 3.0, 0.0);
00094 m_cSphereCenter[11] = CP3D(3.5, 0.0, 0.0);
00095
00096 MakeGlList();
00097
00098
return;
00099 }
00100
00101
00102
00103
00104
00105
00106
00107
CSimpleRenderer::~CSimpleRenderer()
00108
00109 {
00110 glDeleteLists(m_glDispList, 1);
00111 }
00112
00113
00114
00115
00116
00117
00118
00119
void CSimpleRenderer::MakeGlList()
00120
00121 {
00122
m_pViewer->
makeCurrent();
00123
00124
00126
if (glIsList(m_glDispList))
00127 glDeleteLists(m_glDispList, 1);
00128
m_glDispList = glGenLists(1);
00129 glNewList(m_glDispList, GL_COMPILE);
00130
00131 glLineWidth(1.5);
00132
00133
00135
CP3D LowerLeft =
m_pViewer->
getCamera().
getBoundingBox().
getLowerLeft();
00136
CP3D UpperRight =
m_pViewer->
getCamera().
getBoundingBox().
getUpperRight();
00137
00138
00140 glColor3f(1.0, 1.0, 1.0);
00141 glBegin(GL_LINE_LOOP);
00142 glVertex3f(LowerLeft[0], LowerLeft[1], LowerLeft[2]);
00143 glVertex3f(UpperRight[0], LowerLeft[1], LowerLeft[2]);
00144 glVertex3f(UpperRight[0], UpperRight[1], LowerLeft[2]);
00145 glVertex3f(LowerLeft[0], UpperRight[1], LowerLeft[2]);
00146 glEnd();
00147
00148 glBegin(GL_LINE_LOOP);
00149 glVertex3f(LowerLeft[0], LowerLeft[1], UpperRight[2]);
00150 glVertex3f(UpperRight[0], LowerLeft[1], UpperRight[2]);
00151 glVertex3f(UpperRight[0], UpperRight[1], UpperRight[2]);
00152 glVertex3f(LowerLeft[0], UpperRight[1], UpperRight[2]);
00153 glEnd();
00154
00155 glBegin(GL_LINES);
00156 glVertex3f(LowerLeft[0], LowerLeft[1], LowerLeft[2]);
00157 glVertex3f(LowerLeft[0], LowerLeft[1], UpperRight[2]);
00158 glEnd();
00159
00160 glBegin(GL_LINES);
00161 glVertex3f(UpperRight[0], LowerLeft[1], LowerLeft[2]);
00162 glVertex3f(UpperRight[0], LowerLeft[1], UpperRight[2]);
00163 glEnd();
00164
00165 glBegin(GL_LINES);
00166 glVertex3f(UpperRight[0], UpperRight[1], LowerLeft[2]);
00167 glVertex3f(UpperRight[0], UpperRight[1], UpperRight[2]);
00168 glEnd();
00169
00170 glBegin(GL_LINES);
00171 glVertex3f(LowerLeft[0], UpperRight[1], LowerLeft[2]);
00172 glVertex3f(LowerLeft[0], UpperRight[1], UpperRight[2]);
00173 glEnd();
00174
00175 glEndList();
00176
00177
return;
00178 }
00179
00180
00181
00182
00183
00184
00185
00186
void CSimpleRenderer::renderScene(
void)
00187
00188 {
00189
float mat_specular[] = { .72, .8, .93, 1.0 };
00190
00191
00193 glCallList(m_glDispList);
00194
00195 glDepthFunc(GL_LEQUAL);
00196 glEnable(GL_DEPTH_TEST);
00197
00198 glEnable(GL_LINE_SMOOTH);
00199 glEnable(GL_BLEND);
00200 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
00201 glLineWidth(1.5);
00202
00203 glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
00204 glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 128.0);
00205
00206 glEnable(GL_LIGHT0);
00207 glEnable(GL_LIGHTING);
00208 glEnable(GL_NORMALIZE);
00209
00210
00211
if(
m_afSelected[0])
00212 glColor3f(1.0, 1.0, 1.0);
00213
else
00214 glColor3f(.5, .5, 1.0);
00215 glLoadName(1);
00216
renderSolidSphere(m_cSphereCenter[0], 1.0,16,16);
00217
00218
if(
m_afSelected[1])
00219 glColor3f(1.0, 1.0, 1.0);
00220
else
00221 glColor3f(1.0, 0.0, 0.0);
00222 glLoadName(2);
00223
renderSolidSphere(m_cSphereCenter[1], 1.0,16,16);
00224
00225
if(
m_afSelected[2])
00226 glColor3f(1.0, 1.0, 1.0);
00227
else
00228 glColor3f(0.0, 1.0, 0.0);
00229 glLoadName(3);
00230
renderSolidSphere(m_cSphereCenter[2], 1.0,16,16);
00231
00232
if(
m_afSelected[3])
00233 glColor3f(1.0, 1.0, 1.0);
00234
else
00235 glColor3f(0.0, 1.0, 1.0);
00236 glLoadName(4);
00237
renderSolidSphere(m_cSphereCenter[3], 0.5,8,8);
00238
00239
if(
m_afSelected[4])
00240 glColor3f(1.0, 1.0, 1.0);
00241
else
00242 glColor3f(1.0, 0.0, 1.0);
00243 glLoadName(5);
00244
renderSolidSphere(m_cSphereCenter[4], 0.5,8,8);
00245
00246
if(
m_afSelected[5])
00247 glColor3f(1.0, 1.0, 1.0);
00248
else
00249 glColor3f(1.0, 1.0, 0.0);
00250 glLoadName(6);
00251
renderSolidSphere(m_cSphereCenter[5], 0.5,8,8);
00252
00253 glDisable(GL_LIGHT0);
00254 glDisable(GL_LIGHTING);
00255
00256
if(
m_afSelected[6])
00257 glColor3f(1.0, 1.0, 1.0);
00258
else
00259 glColor3f(1.0, 1.0, 0.0);
00260 glLoadName(7);
00261
renderWireSphere(m_cSphereCenter[6], 1.0,16,16);
00262
00263
if(
m_afSelected[7])
00264 glColor3f(1.0, 1.0, 1.0);
00265
else
00266 glColor3f(0.0, 0.0, 1.0);
00267 glLoadName(8);
00268
renderWireSphere(m_cSphereCenter[7], 1.0,16,16);
00269
00270
if(
m_afSelected[8])
00271 glColor3f(1.0, 1.0, 1.0);
00272
else
00273 glColor3f(1.0, 0.0, 1.0);
00274 glLoadName(9);
00275
renderWireSphere(m_cSphereCenter[8], 1.0,16,16);
00276
00277
if(
m_afSelected[9])
00278 glColor3f(1.0, 1.0, 1.0);
00279
else
00280 glColor3f(1.0, 0.0, 0.0);
00281 glLoadName(10);
00282
renderWireSphere(m_cSphereCenter[9], 0.5,16,16,1.0);
00283
00284
if(
m_afSelected[10])
00285 glColor3f(1.0, 1.0, 1.0);
00286
else
00287 glColor3f(0.0, 1.0, 0.0);
00288 glLoadName(11);
00289
renderWireSphere(m_cSphereCenter[10], 0.5,16,16,1.0);
00290
00291
if(
m_afSelected[11])
00292 glColor3f(1.0, 1.0, 1.0);
00293
else
00294 glColor3f(0.0, 0.0, 1.0);
00295 glLoadName(12);
00296
renderWireSphere(m_cSphereCenter[11], 0.5,16,16,1.0);
00297
00298
00299
return;
00300 }
00301
00302
00303
00304
00305
00306
00307
00308
void CSimpleRenderer::renderSolidSphere(
const CP3D &cCenter,
float radius,
00309
int n1,
int n2,
float lw)
00310
00311 {
00312
static GLUquadricObj *quadObj;
00313
static int entry = 0;
00314
int sphere_slices = n1;
00315
int sphere_stacks = n2;
00316
00317 glEnable(GL_COLOR_MATERIAL);
00318 glPushMatrix();
00319 glTranslatef(cCenter.
getX(), cCenter.
getY(), cCenter.
getZ());
00320 quadObj = gluNewQuadric ();
00321
if (!entry) {
00322 gluQuadricDrawStyle (quadObj, (GLenum)GLU_FILL);
00323 gluQuadricOrientation(quadObj, (GLenum)GLU_OUTSIDE);
00324 gluQuadricNormals (quadObj, (GLenum)GLU_SMOOTH);
00325 }
00326 gluSphere (quadObj, radius, sphere_slices, sphere_stacks);
00327 gluDeleteQuadric(quadObj);
00328
00329 glPopMatrix();
00330 glDisable(GL_COLOR_MATERIAL);
00331
00332
return;
00333 }
00334
00335
00336
00337
00338
00339
00340
00341
void CSimpleRenderer::renderWireSphere(
const CP3D &cCenter,
float radius,
00342
int n1,
int n2,
float lw)
00343
00344 {
00345
static GLUquadricObj *quadObj;
00346
static int entry = 0;
00347
int sphere_slices = n1;
00348
int sphere_stacks = n2;
00349
00350 glLineWidth(lw);
00351 glEnable(GL_COLOR_MATERIAL);
00352 glPushMatrix();
00353 glTranslatef(cCenter.
getX(), cCenter.
getY(), cCenter.
getZ());
00354 quadObj = gluNewQuadric ();
00355
if (!entry) {
00356 gluQuadricDrawStyle (quadObj, (GLenum)GLU_LINE);
00357 gluQuadricOrientation(quadObj, (GLenum)GLU_OUTSIDE);
00358 gluQuadricNormals (quadObj, (GLenum)GLU_SMOOTH);
00359 }
00360 gluSphere (quadObj, radius, sphere_slices, sphere_stacks);
00361 gluDeleteQuadric(quadObj);
00362
00363 glPopMatrix();
00364 glDisable(GL_COLOR_MATERIAL);
00365
00366
return;
00367 }
00368
00369
00370
00371
00372
00373
00374
00375
void CSimpleRenderer::sltCatchKey(
int nTmp)
00376
00377 {
00378 cout <<
"CSimpleRenderer: Caught the signal! It is a " << nTmp;
00379 cout <<
" (ascii)" << endl;
00380
00381
return;
00382 }
00383
00384
00385
00386
00387
00388
00389
00390
void CSimpleRenderer::sltResetSelection()
00391
00392 {
00393
int i;
00394
00395
for (i=0; i<12; i++)
00396
m_afSelected[i] =
false;
00397
00398
m_pViewer->
sltUpdateView();
00399
00400
return;
00401 }
00402
00403
00404
00405
00406
00407
00408
00409
void CSimpleRenderer::sltInitializeGL()
00410
00411 {
00412
m_pViewer->
makeCurrent();
00413 glClearColor(0.0, 0.0, 0.0, 0.0);
00414 glShadeModel(GL_SMOOTH);
00415
00416 glMatrixMode(GL_MODELVIEW);
00417
00418
return;
00419 }
00420
00421
00422
00423
00424
00425
00426
00427
void CSimpleRenderer::sltResizeGL(
int w,
int h)
00428
00429 {
00430
return;
00431 }
00432
00433
00434
00435
00436
00437
00438
00439
void CSimpleRenderer::sltPaintGL()
00440
00441 {
00442
00444
renderScene();
00445
00446
return;
00447 }
00448
00449
00450
00451
00452
00453
00454
00455
void CSimpleRenderer::sltManageSelection(QMouseEvent *pqEvent)
00456
00457 {
00458 GLuint selectBuf[
SELECT_BUF_SIZE];
00459 GLint hits;
00460 GLint viewport[4];
00461
double ardVVolume[6];
00462
unsigned int nChosen;
00463
00464
00466
if ( pqEvent->button() == LeftButton ) {
00467
m_fLeftButtonPressed =
true;
00468 }
00469
if ( pqEvent->button() == MidButton ) {
00470
m_fMiddleButtonPressed =
true;
00471 }
00472
if ( pqEvent->button() == RightButton ) {
00473
m_fRightButtonPressed =
true;
00474 }
00475
00476
00478
m_nMousePosX = pqEvent->x();
00479
m_nMousePosY = pqEvent->y();
00480
00481
if(
m_fLeftButtonPressed) {
00482
00484
m_pViewer->
getCameraPtr()->
getVVolume(ardVVolume);
00485
m_pViewer->
makeCurrent();
00486
00487 glGetIntegerv(GL_VIEWPORT, viewport);
00488
00489 glSelectBuffer(SELECT_BUF_SIZE, selectBuf);
00490 glRenderMode(GL_SELECT);
00491
00492 glInitNames();
00493 glPushName(0);
00494
00495 glPushMatrix();
00496 glMatrixMode(GL_PROJECTION);
00497 glLoadIdentity();
00498
00499
00501 gluPickMatrix((GLdouble) m_nMousePosX,
00502 (GLdouble) (viewport[3] - m_nMousePosY),
00503 5.0, 5.0, viewport);
00504
if (
m_pViewer->
getProjectionMode() ==
QGLViewer::perspective)
00505 glFrustum(ardVVolume[0], ardVVolume[1], ardVVolume[2],
00506 ardVVolume[3], ardVVolume[4], ardVVolume[5]);
00507
else
00508 glOrtho(ardVVolume[0], ardVVolume[1], ardVVolume[2],
00509 ardVVolume[3], ardVVolume[4], ardVVolume[5]);
00510
00511 glMatrixMode(GL_MODELVIEW);
00512
renderScene();
00513
00514 glPopMatrix();
00515 glFlush();
00516
00517 hits = glRenderMode(GL_RENDER);
00518 nChosen =
processHits(hits, selectBuf);
00519
if(nChosen>0)
00520
m_afSelected[nChosen-1] =
m_afSelected[nChosen-1] ?
false :
true;
00521
00522
m_pViewer->
sltUpdateView();
00523 }
00524
00525
return;
00526 }
00527
00528
00529
00530
00531
00532
00533
00534 GLuint
CSimpleRenderer::processHits (GLint hits, GLuint buffer[])
00535
00536 {
00537
unsigned int i, j;
00538 GLuint names, nChosen, *ptr;
00539
float rfZValue, rfZ1;
00540
00541
00542
if(hits != 0) {
00543 nChosen = 1;
00544 rfZValue = (
float)*(buffer+1)/0x7fffffff;
00545
00546 cout <<
"Number of hits is = " << hits << endl;
00547 cout <<
"Now show all hits!" << endl;
00548 ptr = (GLuint *) buffer;
00549
00550
for (i=0; i<hits; i++) {
00551 names = *ptr;
00552 cout <<
"Number of names for this hit: " << ptr;
00553 ptr++;
00554 rfZ1 = (
float) *ptr/0x7fffffff;
00555 cout <<
" z1 = " << rfZ1;
00556 ptr++;
00557 cout <<
" z2 = " << (
float) *ptr/0x7fffffff << endl;
00558 ptr++;
00559 cout <<
" ..... and the names are: ";
00560
00561
if(rfZValue >= rfZ1) {
00562 rfZValue = rfZ1;
00563 nChosen = *ptr;
00564 }
00565
00566
for (j=0; j<names; j++) {
00567 cout << *ptr <<
" ";
00568 ptr++;
00569 }
00570 cout << endl;
00571 }
00572 }
00573
else {
00574 nChosen = 0;
00575 }
00576
00577 cout <<
"Chosen sphere: " <<nChosen << endl;
00578
00579
return nChosen;
00580 }
00581
00582
00583
00584
00585
00586
00587
00588
void CSimpleRenderer::sltManageRelease(QMouseEvent *pqEvent)
00589
00590 {
00591
00593
if ( pqEvent->button() == LeftButton ) {
00594
m_fLeftButtonPressed =
false;
00595 }
00596
if ( pqEvent->button() == MidButton ) {
00597
m_fMiddleButtonPressed =
false;
00598 }
00599
if ( pqEvent->button() == RightButton ) {
00600
m_fRightButtonPressed =
false;
00601 }
00602 }
00603
00604
00605
00606
00607
00608
00609
00610
void CSimpleRenderer::sltManageMove(QMouseEvent *pqEvent)
00611
00612 {
00613
int i, nDiffX, nDiffY;
00614
float rfDistance, rfTransX, rfTransY, rfVTan, rfHTan;
00615
CCamera *pCamera;
00616
CP3D cNewCenter;
00617
00618
if(
m_fMiddleButtonPressed) {
00619
00620 nDiffX = pqEvent->x() -
m_nMousePosX;
00621 nDiffY =
m_nMousePosY - pqEvent->y();
00622 pCamera =
m_pViewer->
getCameraPtr();
00623
00624
00626
m_nMousePosX = pqEvent->x();
00627
m_nMousePosY = pqEvent->y();
00628
00629
00631
for(i=0; i<12; i++) {
00632
if(
m_afSelected[i]) {
00633
00634 rfDistance = (
m_cSphereCenter[i] - pCamera->
getEyePos()).getNorm();
00635 rfVTan = tan(pCamera->
getFovy()/360.0*
M_PI);
00636 rfHTan = tan((pCamera->
getFovy()*pCamera->
getRatio()) / 360.0 *
M_PI);
00637 rfTransX = (rfHTan * float(nDiffX)) /
m_pViewer->
getDrawArea()->width() * rfDistance * 2.1;
00638 rfTransY = (rfVTan * float(nDiffY)) /
m_pViewer->
getDrawArea()->height() * rfDistance * 2.1;
00639
00640 cNewCenter = m_cSphereCenter[i]
00641 + pCamera->
getViewRight() * rfTransX
00642 + pCamera->
getViewUp() * rfTransY;
00643
if(pCamera->
getBoundingBox().
isInside(cNewCenter))
00644 m_cSphereCenter[i] = cNewCenter;
00645 }
00646 }
00647
00648
m_pViewer->
sltUpdateView();
00649
00650 }
00651
00652
return;
00653 }
Main program:
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <qapplication.h>
#include <qstring.h>
#include <qgl.h>
#include <qmenubar.h>
#include <qpopupmenu.h>
#include <QGLExaminerViewer.h>
#include <CP3D.h>
#include "CPlayerRenderer.h"
#include "CBoundingBox3D.h"
#include "QCameraPathPlayer.h"
int main(
int argc,
char *argv[])
{
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);
Q_CHECK_PTR(pViewer);
QCameraPathPlayer *pPlayer =
new QCameraPathPlayer(pViewer);
Q_CHECK_PTR(pPlayer);
pPlayer->show();
CPlayerRenderer *pRenderer =
new CPlayerRenderer(pViewer);
Q_CHECK_PTR(pRenderer);
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()));
app.setMainWidget(pViewer);
pViewer->resize(450, 420);
pViewer->show();
int nRet = app.exec();
delete pRenderer;
delete pPlayer;
delete pViewer;
return nRet;
}
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00036
#include <stdlib.h>
00037
#include <string.h>
00038
#include <stdio.h>
00039
00040
00042
#include <qapplication.h>
00043
#include <qstring.h>
00044
#include <qgl.h>
00045
#include <qmenubar.h>
00046
#include <qpopupmenu.h>
00047
00048
00050
#include <QGLExaminerViewer.h>
00051
#include <CP3D.h>
00052
00053
00055
#include "CPlayerRenderer.h"
00056
#include "CBoundingBox3D.h"
00057
#include "QCameraPathPlayer.h"
00058
00059
00060
00063
00064
00065
00066
00067
00070
int main(
int argc,
char *argv[])
00071 {
00072
00074 QApplication::setColorSpec(QApplication::CustomColor);
00075 QApplication app(argc,argv);
00076
00077 QGLFormat f;
00078 QGLFormat::setDefaultFormat(f);
00079
00080 QGLExaminerViewer *pViewer =
new QGLExaminerViewer(
CCamera(0.0, 0.0, -25.0,
00081 0.0, 0.0, 0.0,
00082 0.0, 1.0, 0.0,
00083
CBoundingBox3D(-4.0,-4.0,-4.0,
00084 4.0,4.0,4.0)),
00085 NULL,
"viewer", NULL, 0,
true, f);
00086
Q_CHECK_PTR(pViewer);
00087
00088 QCameraPathPlayer *pPlayer =
new QCameraPathPlayer(pViewer);
00089
Q_CHECK_PTR(pPlayer);
00090 pPlayer->show();
00091
00092
00093
00095 CPlayerRenderer *pRenderer =
new CPlayerRenderer(pViewer);
00096
Q_CHECK_PTR(pRenderer);
00097
00098
00100 QObject::connect(pViewer, SIGNAL(
sigInitGL()),
00101 pRenderer, SLOT(sltInitializeGL()));
00102 QObject::connect(pViewer, SIGNAL(
sigResizeGL(
int,
int)),
00103 pRenderer, SLOT(sltResizeGL(
int,
int)));
00104 QObject::connect(pViewer, SIGNAL(
sigRedrawGL()),
00105 pRenderer, SLOT(
sltPaintGL()));
00106
00107
00109 app.setMainWidget(pViewer);
00110 pViewer->resize(450, 420);
00111 pViewer->show();
00112
00113
int nRet = app.exec();
00114
00115
delete pRenderer;
00116
delete pPlayer;
00117
delete pViewer;
00118
00119
return nRet;
00120 }
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] |
|
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. |
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.
Reimplemented from QGLViewer. |
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
The documentation for this class was generated from the following files:
Generated on Wed Jul 28 02:09:13 2004 for QGLViewer by
1.3.7