summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorJakob Odersky <jodersky@gmail.com>2011-03-30 18:40:50 +0000
committerJakob Odersky <jodersky@gmail.com>2011-03-30 18:40:50 +0000
commitd84ecd9ecbdc97459f76ba374fbdd815a0c8964c (patch)
tree14c4a5a76b7afa4a838525c6b23db9d2b20b042f /src/gui
parentb1729c8ac1eaf48e78f7163983842ec00774fa10 (diff)
downloadvhc-d84ecd9ecbdc97459f76ba374fbdd815a0c8964c.tar.gz
vhc-d84ecd9ecbdc97459f76ba374fbdd815a0c8964c.tar.bz2
vhc-d84ecd9ecbdc97459f76ba374fbdd815a0c8964c.zip
Essais avec OpenGL
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/GLWidget.cc81
-rw-r--r--src/gui/GLWidget.h6
-rw-r--r--src/gui/Main.cc2
-rw-r--r--src/gui/Makefile2
-rw-r--r--src/gui/moc_GLWidget.cpp2
5 files changed, 83 insertions, 10 deletions
diff --git a/src/gui/GLWidget.cc b/src/gui/GLWidget.cc
index 60d411b..4fb43fa 100644
--- a/src/gui/GLWidget.cc
+++ b/src/gui/GLWidget.cc
@@ -1,9 +1,56 @@
#include <QtOpenGL>
+#include <math.h>
#include "GLWidget.h"
+void torus(int numc, int numt) {
+ int i, j, k;
+ double s, t, x, y, z, twopi;
+
+ twopi = 2 * M_PI;
+ for (i = 0; i < numc; i++) {
+ glBegin(GL_QUAD_STRIP);
+ for (j = 0; j <= numt; j++) {
+ for (k = 1; k >= 0; k--) {
+ s = (i + k) % numc + 0.5;
+ t = j % numt;
+
+ x = (1+.1*cos(s*twopi/numc))*cos(t*twopi/numt);
+ y = (1+.1*cos(s*twopi/numc))*sin(t*twopi/numt);
+ z = .1 * sin(s * twopi / numc);
+ glColor3d(0, s/numc, t/numc);
+ glVertex3f(x, y, z);
+ }
+ }
+ glEnd();
+ }
+}
+
+void axes() {
+ glBegin(GL_LINES);
+ glColor3d(1, 0, 0);
+ glVertex3d(0, 0, 0); // origin of the line
+ glVertex3d(100, 0, 0); // ending point of the line
+ glEnd();
+ glBegin(GL_LINES);
+ glColor3d(0, 1, 0);
+ glVertex3d(0, 0, 0); // origin of the line
+ glVertex3d(0, 100, 0); // ending point of the line
+ glEnd();
+ glBegin(GL_LINES);
+ glColor3d(0, 0, 1);
+ glVertex3d(0, 0, 0); // origin of the line
+ glVertex3d(0, 0, 100); // ending point of the line
+ glEnd();
+
+}
+
+
GLWidget::GLWidget (QWidget* parent)
: QGLWidget (parent)
{
+ eyeX = 0;
+ eyeY = 0;
+ eyeZ = 10;
resize (sizeHint ());
}
@@ -18,7 +65,7 @@ QSize GLWidget::sizeHint () const {
}
void GLWidget::initializeGL () {
- glClearColor (255, 255, 255, 1.0);
+ glClearColor (0, 0, 0, 1.0);
glEnable (GL_DEPTH_TEST);
gluPerspective(65.0, 4.0/3, 1.0, 1000.0);
}
@@ -26,9 +73,9 @@ void GLWidget::initializeGL () {
void GLWidget::paintGL () {
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity ();
- //gluLookAt(0,0,0,
- // 0,0,0,
- // 0,0,1);
+ gluLookAt(eyeX,eyeY,eyeZ,
+ 0,0,0,
+ 0,1000,0);
//glTranslated (0.0, 0.0, -10.0);
//glColor3d (0.0, 0.0, 1.0);
//glScaled (300.0, 300.0, 300.0);
@@ -45,13 +92,20 @@ void GLWidget::paintGL () {
glColor3d(0,1,0);
glVertex3d (300 + 10, -300, 0.0);
glEnd ();
+
+
+ axes();
+
+ glColor3d(0,0,1);
+ glScaled(300,300,300);
+ torus(80, 250);
}
void GLWidget::resizeGL (int width, int height) {
glViewport (0, 0, width, height);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
- glOrtho (-width, width, -height, height, -100.0, 100.0);
+ glOrtho (-width, width, -height, height, -1000.0, 1000.0);
glMatrixMode (GL_MODELVIEW);
}
@@ -67,11 +121,26 @@ void GLWidget::keyPressEvent (QKeyEvent* event) {
qApp->quit();
break;
case Qt::Key_Up:
- qApp->quit();
+ eyeZ += 10;
+ break;
+ case Qt::Key_Down:
+ eyeZ -= 10;
+ break;
+ case Qt::Key_Right:
+ eyeX += 10;
+ break;
+ case Qt::Key_Left:
+ eyeX -= 10;
+ break;
+ case Qt::Key_R:
+ eyeX = 0;
+ eyeY = 0;
+ eyeZ = 10;
break;
default:
break;
}
+ repaint();
}
void GLWidget::keyReleaseEvent (QKeyEvent* event) {
diff --git a/src/gui/GLWidget.h b/src/gui/GLWidget.h
index b2cd02d..73124f5 100644
--- a/src/gui/GLWidget.h
+++ b/src/gui/GLWidget.h
@@ -13,8 +13,12 @@ public:
QSize minimumSizeHint () const;
QSize sizeHint () const;
+ double eyeX;
+ double eyeY;
+ double eyeZ;
+
protected:
-
+
void initializeGL ();
void paintGL ();
void resizeGL (int width, int height);
diff --git a/src/gui/Main.cc b/src/gui/Main.cc
index 9842a03..0e1c575 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(250, 150);
+ window.resize(500, 500);
window.setWindowTitle("Virtual Hadron Collider");
window.show();
diff --git a/src/gui/Makefile b/src/gui/Makefile
index aed836b..52f8f7f 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: Tue Mar 29 20:46:53 2011
+# Generated by qmake (2.01a) (Qt 4.7.0) on: Wed Mar 30 20:40:02 2011
# Project: gui.pro
# Template: app
# Command: /usr/bin/qmake -o Makefile gui.pro
diff --git a/src/gui/moc_GLWidget.cpp b/src/gui/moc_GLWidget.cpp
index bef8a88..b6be50e 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: Mon Mar 28 20:36:46 2011
+** Created: Tue Mar 29 22:54:38 2011
** by: The Qt Meta Object Compiler version 62 (Qt 4.7.0)
**
** WARNING! All changes made in this file will be lost!