From 488f51bd2c3a4687f6327d6212e6979201649611 Mon Sep 17 00:00:00 2001 From: Jakob Odersky Date: Wed, 6 Apr 2011 15:03:36 +0000 Subject: Amelioration de la camera, mise en scene de plusieurs elements. Debut d'implementation de la `vraie' classe de rendement graphique. --- src/gui/Camera.h | 2 +- src/gui/GLWidget.cc | 10 +++++----- src/gui/Main.cc | 2 +- src/gui/Makefile | 2 +- src/gui/Stage.cc | 38 ++++++++++++++++++++++++++++++++++++++ src/gui/Stage.h | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ src/gui/moc_GLWidget.cpp | 2 +- src/gui/util.cc | 37 +++++++++++++++++++++++++++++++++++++ src/gui/util.h | 8 ++++++++ 9 files changed, 140 insertions(+), 9 deletions(-) create mode 100644 src/gui/Stage.cc create mode 100644 src/gui/Stage.h (limited to 'src/gui') diff --git a/src/gui/Camera.h b/src/gui/Camera.h index fccd3f9..7c469aa 100644 --- a/src/gui/Camera.h +++ b/src/gui/Camera.h @@ -27,7 +27,7 @@ private: public: - Camera(): position(1, 1, 1), direction(1, 0, 0), up(0,0,1), heading(M_PI_4), pitch(-M_PI_4) {}; + Camera(): position(1, 1, 1), direction(-1, 0, 0), up(0,0,1), heading(M_PI_4), pitch(-M_PI_4) {}; virtual ~Camera() {}; void setView() { diff --git a/src/gui/GLWidget.cc b/src/gui/GLWidget.cc index a9c5e86..d72c78d 100644 --- a/src/gui/GLWidget.cc +++ b/src/gui/GLWidget.cc @@ -68,13 +68,12 @@ QSize GLWidget::sizeHint () const { void GLWidget::initializeGL () { glClearColor (0, 0, 0, 1.0); glEnable (GL_DEPTH_TEST); - gluPerspective(65.0, 4.0/3.0, 1.0, 10000.0); + //gluPerspective(65.0, 4.0/3.0, 1.0, 10000.0); glHint(GL_LINE_SMOOTH_HINT, GL_NICEST); glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST); } void GLWidget::resizeGL (int width, int height) { - center = QPoint(width / 2, height / 2); glViewport (0, 0, width, height); glMatrixMode (GL_PROJECTION); glLoadIdentity(); @@ -93,6 +92,7 @@ void GLWidget::paintGL () { glPopMatrix(); + center = QWidget::mapToGlobal(QPoint(this->size().width() / 2, this->size().height() / 2)); QCursor::setPos(center); glScaled (100.0, 100.0, 100.0); @@ -143,13 +143,13 @@ void GLWidget::keyPressEvent (QKeyEvent* event) { mv = mv - Vector3D::j; break; case Qt::Key_W: - mv = mv + Vector3D::i; + mv = mv - Vector3D::i; break; case Qt::Key_D: mv = mv + Vector3D::j; break; case Qt::Key_S: - mv = mv - Vector3D::i; + mv = mv + Vector3D::i; break; case Qt::Key_Up: camera.addPitch(2 * M_PI / 100); @@ -182,7 +182,7 @@ void GLWidget::keyReleaseEvent (QKeyEvent* event) { void GLWidget::mouseMoveEvent(QMouseEvent* event) { int dheading = -QCursor::pos().x() + center.x(); - int dpitch = QCursor::pos().y() - center.y(); + int dpitch = -QCursor::pos().y() + center.y(); camera.addHeading(1.0 * dheading / 20); camera.addPitch(1.0 * dpitch / 20); updateGL(); diff --git a/src/gui/Main.cc b/src/gui/Main.cc index 0e1c575..cc9bf57 100644 --- a/src/gui/Main.cc +++ b/src/gui/Main.cc @@ -18,7 +18,7 @@ int main(int argc, char *argv[]) GLWidget window; vhc::Vector3D s = vhc::Vector3D::i; - window.resize(500, 500); + window.resize(QApplication::desktop()->size()); window.setWindowTitle("Virtual Hadron Collider"); window.show(); diff --git a/src/gui/Makefile b/src/gui/Makefile index 9a05f2c..179964e 100644 --- a/src/gui/Makefile +++ b/src/gui/Makefile @@ -1,6 +1,6 @@ ############################################################################# # Makefile for building: $(BINDIR)/gui/gui -# Generated by qmake (2.01a) (Qt 4.7.0) on: Wed Apr 6 14:53:06 2011 +# Generated by qmake (2.01a) (Qt 4.7.0) on: Wed Apr 6 17:00:28 2011 # Project: gui.pro # Template: app # Command: /usr/bin/qmake -o Makefile gui.pro diff --git a/src/gui/Stage.cc b/src/gui/Stage.cc new file mode 100644 index 0000000..ad6bf60 --- /dev/null +++ b/src/gui/Stage.cc @@ -0,0 +1,38 @@ +/* + * Stage.cc + * + * Created on: Apr 6, 2011 + * Author: jakob + */ + +#include "Stage.h" + +namespace vhc { + +Stage::Stage(QWidget* parent): QGLWidget (parent), camera(), wireframe(false) { + setMouseTracking(true); +} + +Stage::~Stage() {}; + +void GLWidget::initializeGL () { + glEnable (GL_DEPTH_TEST); + glHint(GL_LINE_SMOOTH_HINT, GL_NICEST); + glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST); + //gluPerspective(65.0, 4.0/3.0, 1.0, 10000.0); + glClearColor (0, 0, 0, 1.0); +} + +void GLWidget::resizeGL (int width, int height) { + glViewport (0, 0, width, height); + glMatrixMode (GL_PROJECTION); + glLoadIdentity(); + gluPerspective(65.0, 1, 1.0, 10000.0); + glMatrixMode (GL_MODELVIEW); +} + + + + + +} diff --git a/src/gui/Stage.h b/src/gui/Stage.h new file mode 100644 index 0000000..ffb6509 --- /dev/null +++ b/src/gui/Stage.h @@ -0,0 +1,48 @@ +/* + * Stage.h + * + * Created on: Apr 6, 2011 + * Author: jakob + */ + +#ifndef STAGE_H_ +#define STAGE_H_ + +#include +#include "Camera.h" + + +namespace vhc { + +class Stage: public QGLWidget { + + Q_OBJECT + +public: + Stage(QWidget* parent); + virtual ~Stage(); + +protected: + + void initializeGL(); + void resizeGL (int width, int height); + void paintGL(); + + void mousePressEvent (QMouseEvent* event); + void mouseReleaseEvent (QMouseEvent* event); + void keyPressEvent (QKeyEvent* event); + void keyReleaseEvent (QKeyEvent* event); + void mouseMoveEvent(QMouseEvent* event); + +private: + + Camera camera; + + bool wireframe; + + +}; + +} + +#endif /* STAGE_H_ */ diff --git a/src/gui/moc_GLWidget.cpp b/src/gui/moc_GLWidget.cpp index e9961f2..e13e21d 100644 --- a/src/gui/moc_GLWidget.cpp +++ b/src/gui/moc_GLWidget.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** Meta object code from reading C++ file 'GLWidget.h' ** -** Created: Wed Apr 6 14:53:15 2011 +** Created: Wed Apr 6 16:24:21 2011 ** by: The Qt Meta Object Compiler version 62 (Qt 4.7.0) ** ** WARNING! All changes made in this file will be lost! diff --git a/src/gui/util.cc b/src/gui/util.cc index aaf7a63..7dfb215 100644 --- a/src/gui/util.cc +++ b/src/gui/util.cc @@ -38,5 +38,42 @@ void cylinder(double base, double top, double height, int slices, int stacks) { gluDeleteQuadric(q); } +void axes() { + glBegin(GL_LINES); + glColor3d(1, 0, 0); + glVertex3d(0, 0, 0); + glVertex3d(1, 0, 0); + glEnd(); + + glBegin(GL_LINES); + glColor3d(0, 1, 0); + glVertex3d(0, 0, 0); + glVertex3d(0, 1, 0); + glEnd(); + + glBegin(GL_LINES); + glColor3d(0, 0, 1); + glVertex3d(0, 0, 0); + glVertex3d(0, 0, 1); + glEnd(); +} + +void grid(int divisions) { + int size = divisions / 2; + glBegin(GL_LINES); + for (int i = 0; i <= 2 * size; ++i) { + glVertex3d(1.0 * (i - size) / size, -1, 0); + glVertex3d(1.0 * (i - size) / size, 1, 0); + }; + glEnd(); + glBegin(GL_LINES); + for (int i = 0; i <= 2 * size; ++i) { + glVertex3d(-1, 1.0 * (i - size) / size, 0); + glVertex3d(1, 1.0 * (i - size) / size, 0); + }; + glEnd(); +} + + } } diff --git a/src/gui/util.h b/src/gui/util.h index 4f8133a..6238ab7 100644 --- a/src/gui/util.h +++ b/src/gui/util.h @@ -22,6 +22,14 @@ void torus(double R, double r, double fraction, int slices = 12, int stacks = 20 void cylinder(double base, double top, double height, int slices = 12, int stacks = 20); +/** Dessine les axes unitaires d'un repere cartesien. + * Les axes ont les couleurs suivantes: x -> rouge, y -> vert, z -> bleu */ +void axes(); + +/** Dessine une grille sur le plan XY entre les coordonnees -1 et 1 des deux axes. + * Cette grille comporte divisions divisions.*/ +void grid(int divisions); + } } -- cgit v1.2.3