diff options
author | Jakob Odersky <jodersky@gmail.com> | 2011-04-17 20:51:10 +0000 |
---|---|---|
committer | Jakob Odersky <jodersky@gmail.com> | 2011-04-17 20:51:10 +0000 |
commit | 5c7b4e1372ec25a8df3af20afedb63349dddfdca (patch) | |
tree | a4ef8a2a8352377c09ab6a9c319c45ad8b6d2945 | |
parent | fa155ede4af523228b455015312f5ebbb0fec183 (diff) | |
download | vhc-5c7b4e1372ec25a8df3af20afedb63349dddfdca.tar.gz vhc-5c7b4e1372ec25a8df3af20afedb63349dddfdca.tar.bz2 vhc-5c7b4e1372ec25a8df3af20afedb63349dddfdca.zip |
Nettoyage dans gui.
-rw-r--r-- | src/gui/Camera.cc | 36 | ||||
-rw-r--r-- | src/gui/Camera.h | 33 | ||||
-rw-r--r-- | src/gui/GLWidget.cc | 232 | ||||
-rw-r--r-- | src/gui/GLWidget.h | 35 | ||||
-rw-r--r-- | src/gui/Main.cc | 1 | ||||
-rw-r--r-- | src/gui/Makefile | 272 | ||||
-rw-r--r-- | src/gui/gui.pro | 4 | ||||
-rw-r--r-- | src/main/Accelerator.h | 13 | ||||
-rw-r--r-- | src/main/Particle.cc | 2 | ||||
-rw-r--r-- | src/main/Vector3D.cc | 1 | ||||
-rw-r--r-- | src/main/Vector3D.h | 1 |
11 files changed, 61 insertions, 569 deletions
diff --git a/src/gui/Camera.cc b/src/gui/Camera.cc index 32f5773..65c80b7 100644 --- a/src/gui/Camera.cc +++ b/src/gui/Camera.cc @@ -7,4 +7,40 @@ #include "Camera.h" +namespace vhc { +Camera::Camera(): position(1, 1, 1), direction(-1, 0, 0), up(0,0,1), heading(M_PI_4), pitch(-M_PI_4) {}; + +Camera::~Camera(); + +void Camera::setView() { + Vector3D td = direction.rotate(Vector3D::j, pitch).rotate(Vector3D::k, heading);; //tranformed direction + Vector3D at = position + td; + + gluLookAt(position.getX(), position.getY(), position.getZ(), + at.getX(), at.getY(), at.getZ(), + up.getX(), up.getY(), up.getZ()); +} + +void Camera::addHeading(double h) { + heading += h; +} + +void Camera::addPitch(double h) { + pitch += h; + if (pitch <= -M_PI_2) pitch = -M_PI_2 + 0.001; + if (pitch >= M_PI_2) pitch = M_PI_2 - 0.001; +} + + +void Camera::move(const Vector3D& moveVector) { + Vector3D mv = moveVector.rotate(Vector3D::j, pitch).rotate(Vector3D::k, heading); + position = position + mv; +} + +Vector3D Camera::getPosition() const {return position;} +double Camera::getHeading() const {return heading;} +double Camera::getPitch() const {return pitch;} + + +} //vhc diff --git a/src/gui/Camera.h b/src/gui/Camera.h index f5ce954..8ea35d0 100644 --- a/src/gui/Camera.h +++ b/src/gui/Camera.h @@ -9,7 +9,6 @@ #define CAMERA_H_ #include <cmath> #include <QtOpenGL> -#include "exceptions.h" #include "Vector3D.h" namespace vhc { @@ -26,37 +25,21 @@ private: public: - Camera(): position(1, 1, 1), direction(-1, 0, 0), up(0,0,1), heading(M_PI_4), pitch(-M_PI_4) {}; + Camera(); virtual ~Camera() {}; - void setView() { - Vector3D td = direction.rotate(Vector3D::j, pitch).rotate(Vector3D::k, heading);; //tranformed direction - Vector3D at = position + td; + void setView(); - gluLookAt(position.getX(), position.getY(), position.getZ(), - at.getX(), at.getY(), at.getZ(), - up.getX(), up.getY(), up.getZ()); - } + void addHeading(double h); - void addHeading(double h) { - heading += h; - } + void addPitch(double h); - void addPitch(double h) { - pitch += h; - if (pitch <= -M_PI_2) pitch = -M_PI_2 + 0.001; - if (pitch >= M_PI_2) pitch = M_PI_2 - 0.001; - } + void move(const Vector3D& moveVector); - void move(const Vector3D& moveVector) { - Vector3D mv = moveVector.rotate(Vector3D::j, pitch).rotate(Vector3D::k, heading); - position = position + mv; - } - - Vector3D getPosition() {return position;} - double getHeading() {return heading;} - double getPitch() {return pitch;} + Vector3D getPosition() const; + double getHeading() const; + double getPitch() const; }; diff --git a/src/gui/GLWidget.cc b/src/gui/GLWidget.cc deleted file mode 100644 index 0653ef2..0000000 --- a/src/gui/GLWidget.cc +++ /dev/null @@ -1,232 +0,0 @@ -#include <QtOpenGL> -#include <math.h> -#include <iostream> -#include "GLWidget.h" -#include "StraightElement.h" -#include "ElementRenderer.h" -#include "CurvedElement.h" -#include "Dipole.h" -#include "util.h" -#include "Vector3D.h" - -using namespace vhc; - - -int keys; - -void axes() { - glBegin(GL_LINES); - glColor3d(1, 0, 0); - glVertex3d(0, 0, 0); // origin of the line - glVertex3d(1, 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, 1, 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, 1); // ending point of the line - glEnd(); -} - -void grid() { - int size = 10; - glColor3d(0.5, 0.5, 0.5); - 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(); - -} - - -GLWidget::GLWidget (QWidget* parent) - : QGLWidget (parent), wireframe(false), camera(), center() -{ - keys = 0; - setMouseTracking(true); - resize (sizeHint ()); -} - -GLWidget::~GLWidget () {} - -QSize GLWidget::minimumSizeHint () const { - return QSize (50, 50); -} - -QSize GLWidget::sizeHint () const { - return QSize (1000, 800); -} - -void GLWidget::initializeGL () { - glClearColor (0, 0, 0, 1.0); - glEnable (GL_DEPTH_TEST); - //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) { - glViewport (0, 0, width, height); - glMatrixMode (GL_PROJECTION); - glLoadIdentity(); - gluPerspective(65.0, 4.0/3.0, 1.0, 10000.0); - glMatrixMode (GL_MODELVIEW); - setCursor(QCursor(Qt::CrossCursor)); -} - -void GLWidget::paintGL () { - glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - glLoadIdentity (); - camera.setView(); - glPushMatrix(); - glScaled(100, 100, 100); - grid(); - axes(); - glPopMatrix(); - - - center = QWidget::mapToGlobal(QPoint(this->size().width() / 2, this->size().height() / 2)); - QCursor::setPos(center); - - - glScaled (100.0, 100.0, 100.0); - - - if (wireframe) { - glPolygonMode(GL_FRONT, GL_LINE); - glPolygonMode(GL_BACK, GL_LINE); - } else { - glPolygonMode(GL_FRONT, GL_FILL); - glPolygonMode(GL_BACK, GL_FILL); - } - - //glEnable (GL_BLEND); glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - //glColor4d(0,0,0.5, 0.2); - vhc::ElementRenderer* er = new vhc::ElementRenderer; - - vhc::StraightElement* se = new vhc::StraightElement(vhc::Vector3D::j, vhc::Vector3D::j + vhc::Vector3D::i, 0.2); - vhc::StraightElement* se2 = new vhc::StraightElement(vhc::Vector3D(2,0,0), vhc::Vector3D(2,-1,0), 0.2); - se->accept(*er); - //se.draw() - se2->accept(*er); - delete se; se = NULL; - delete se2; se2 = NULL; - - vhc::CurvedElement* ce = new vhc::Dipole(vhc::Vector3D(1,1,0), vhc::Vector3D::i * 2, 0.2, 1, vhc::Vector3D::Null); - //std::cout <<*ce << "\n"; - ce->accept(*er); - delete er; er = NULL; - - delete ce; ce = NULL; - -} - - - -void GLWidget::mousePressEvent (QMouseEvent* event) { -} - -void GLWidget::mouseReleaseEvent (QMouseEvent* event) { -} - - -void GLWidget::keyPressEvent (QKeyEvent* event) { - Vector3D mv = Vector3D::Null; - switch (event->key()) { - case Qt::Key_Escape: - qApp->quit(); - break; - case Qt::Key_A: - //mv = mv - Vector3D::j; - keys |= 1; - break; - case Qt::Key_W: - //mv = mv - Vector3D::i; - keys |= 2; - break; - case Qt::Key_D: - //mv = mv + Vector3D::j; - keys |= 4; - break; - case Qt::Key_S: - //mv = mv + Vector3D::i; - keys |= 8; - break; - case Qt::Key_Up: - camera.addPitch(2 * M_PI / 100); - break; - case Qt::Key_Down: - camera.addPitch(-2 * M_PI / 100); - break; - case Qt::Key_Right: - camera.addHeading(-2 * M_PI / 100); - break; - case Qt::Key_Left: - camera.addHeading(2 * M_PI / 100); - break; - case Qt::Key_R: - break; - case Qt::Key_Space: - wireframe = !wireframe; - break; - default: - break; - } - std::cout << event->text().toStdString() << std::endl; - std::cout << std::flush; - - if (keys & 1) mv = mv - Vector3D::j; - if (keys & 2) mv = mv - Vector3D::i; - if (keys & 4) mv = mv + Vector3D::j; - if (keys & 8) mv = mv + Vector3D::i; - - camera.move(mv); - updateGL(); - //repaint(); - - -} - -void GLWidget::keyReleaseEvent (QKeyEvent* event) { - switch (event->key()) { - case Qt::Key_A: - //mv = mv - Vector3D::j; - keys &= ~1; - break; - case Qt::Key_W: - //mv = mv - Vector3D::i; - keys &= ~2; - break; - case Qt::Key_D: - //mv = mv + Vector3D::j; - keys &= ~4; - break; - case Qt::Key_S: - //mv = mv + Vector3D::i; - keys &= ~8; - break; - default: - break; - } -} - -void GLWidget::mouseMoveEvent(QMouseEvent* event) { - int dheading = -QCursor::pos().x() + center.x(); - int dpitch = -QCursor::pos().y() + center.y(); - camera.addHeading(1.0 * dheading / 200); - camera.addPitch(1.0 * dpitch / 200); - updateGL(); - -} diff --git a/src/gui/GLWidget.h b/src/gui/GLWidget.h deleted file mode 100644 index a5408c3..0000000 --- a/src/gui/GLWidget.h +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef GLWIDGET_H -#define GLWIDGET_H - -#include <QGLWidget> -#include "Camera.h" - -class GLWidget : public QGLWidget -{ - Q_OBJECT - -public: - GLWidget (QWidget* parent = 0); - ~GLWidget (); - - QSize minimumSizeHint () const; - QSize sizeHint () const; - - bool wireframe; - vhc::Camera camera; - QPoint center; - - -protected: - - void initializeGL (); - void paintGL (); - void resizeGL (int width, int height); - void mousePressEvent (QMouseEvent* event); - void mouseReleaseEvent (QMouseEvent* event); - void keyPressEvent (QKeyEvent* event); - void keyReleaseEvent (QKeyEvent* event); - void mouseMoveEvent(QMouseEvent* event); -}; - -#endif diff --git a/src/gui/Main.cc b/src/gui/Main.cc index ac9e7a5..012c6ef 100644 --- a/src/gui/Main.cc +++ b/src/gui/Main.cc @@ -8,7 +8,6 @@ #include <iostream> #include <QApplication> #include <QWidget> -#include "GLWidget.h" #include "Stage.h" #include "Accelerator.h" #include "StraightElement.h" diff --git a/src/gui/Makefile b/src/gui/Makefile deleted file mode 100644 index 682ca97..0000000 --- a/src/gui/Makefile +++ /dev/null @@ -1,272 +0,0 @@ -############################################################################# -# Makefile for building: $(BINDIR)/gui/gui -# Generated by qmake (2.01a) (Qt 4.7.0) on: Sun Apr 17 22:20:53 2011 -# Project: gui.pro -# Template: app -# Command: /usr/bin/qmake -o Makefile gui.pro -############################################################################# - -####### Compiler, tools and options - -CC = gcc -CXX = g++ -DEFINES = -DQT_NO_DEBUG -DQT_OPENGL_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -CFLAGS = -pipe -O2 -Wall -W -D_REENTRANT $(DEFINES) -CXXFLAGS = -pipe -O2 -Wall -W -D_REENTRANT $(DEFINES) -INCPATH = -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4/QtOpenGL -I/usr/include/qt4 -I. -I$(SRCDIR)/main/ -I/usr/X11R6/include -I. -LINK = g++ -LFLAGS = -Wl,-O1 -LIBS = $(SUBLIBS) -L/usr/lib -L/usr/X11R6/lib -L$(BINDIR)/main -lvhc -lQtOpenGL -lQtGui -lQtCore -lGLU -lGL -lpthread -AR = ar cqs -RANLIB = -QMAKE = /usr/bin/qmake -TAR = tar -cf -COMPRESS = gzip -9f -COPY = cp -f -SED = sed -COPY_FILE = $(COPY) -COPY_DIR = $(COPY) -r -STRIP = strip -INSTALL_FILE = install -m 644 -p -INSTALL_DIR = $(COPY_DIR) -INSTALL_PROGRAM = install -m 755 -p -DEL_FILE = rm -f -SYMLINK = ln -f -s -DEL_DIR = rmdir -MOVE = mv -f -CHK_DIR_EXISTS= test -d -MKDIR = mkdir -p - -####### Output directory - -OBJECTS_DIR = $(BINDIR)/gui/ - -####### Files - -SOURCES = Main.cc \ - GLWidget.cc \ - ElementRenderer.cc \ - util.cc \ - Stage.cc \ - ParticleRenderer.cc moc_GLWidget.cpp \ - moc_Stage.cpp -OBJECTS = $(BINDIR)/gui/Main.o \ - $(BINDIR)/gui/GLWidget.o \ - $(BINDIR)/gui/ElementRenderer.o \ - $(BINDIR)/gui/util.o \ - $(BINDIR)/gui/Stage.o \ - $(BINDIR)/gui/ParticleRenderer.o \ - $(BINDIR)/gui/moc_GLWidget.o \ - $(BINDIR)/gui/moc_Stage.o -DIST = /usr/share/qt4/mkspecs/common/g++.conf \ - /usr/share/qt4/mkspecs/common/unix.conf \ - /usr/share/qt4/mkspecs/common/linux.conf \ - /usr/share/qt4/mkspecs/qconfig.pri \ - /usr/share/qt4/mkspecs/modules/qt_webkit_version.pri \ - /usr/share/qt4/mkspecs/features/qt_functions.prf \ - /usr/share/qt4/mkspecs/features/qt_config.prf \ - /usr/share/qt4/mkspecs/features/exclusive_builds.prf \ - /usr/share/qt4/mkspecs/features/default_pre.prf \ - /usr/share/qt4/mkspecs/features/release.prf \ - /usr/share/qt4/mkspecs/features/default_post.prf \ - /usr/share/qt4/mkspecs/features/warn_on.prf \ - /usr/share/qt4/mkspecs/features/qt.prf \ - /usr/share/qt4/mkspecs/features/unix/opengl.prf \ - /usr/share/qt4/mkspecs/features/unix/thread.prf \ - /usr/share/qt4/mkspecs/features/moc.prf \ - /usr/share/qt4/mkspecs/features/resources.prf \ - /usr/share/qt4/mkspecs/features/uic.prf \ - /usr/share/qt4/mkspecs/features/yacc.prf \ - /usr/share/qt4/mkspecs/features/lex.prf \ - /usr/share/qt4/mkspecs/features/include_source_dir.prf \ - gui.pro -QMAKE_TARGET = gui -DESTDIR = $(BINDIR)/gui/ -TARGET = $(BINDIR)/gui/gui - -first: all -####### Implicit rules - -.SUFFIXES: .o .c .cpp .cc .cxx .C - -.cpp.o: - $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<" - -.cc.o: - $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<" - -.cxx.o: - $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<" - -.C.o: - $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<" - -.c.o: - $(CC) -c $(CFLAGS) $(INCPATH) -o "$@" "$<" - -####### Build rules - -all: Makefile $(TARGET) - -$(TARGET): $(OBJECTS) - @$(CHK_DIR_EXISTS) $(BINDIR)/gui/ || $(MKDIR) $(BINDIR)/gui/ - $(LINK) $(LFLAGS) -o $(TARGET) $(OBJECTS) $(OBJCOMP) $(LIBS) - -Makefile: gui.pro /usr/share/qt4/mkspecs/linux-g++/qmake.conf /usr/share/qt4/mkspecs/common/g++.conf \ - /usr/share/qt4/mkspecs/common/unix.conf \ - /usr/share/qt4/mkspecs/common/linux.conf \ - /usr/share/qt4/mkspecs/qconfig.pri \ - /usr/share/qt4/mkspecs/modules/qt_webkit_version.pri \ - /usr/share/qt4/mkspecs/features/qt_functions.prf \ - /usr/share/qt4/mkspecs/features/qt_config.prf \ - /usr/share/qt4/mkspecs/features/exclusive_builds.prf \ - /usr/share/qt4/mkspecs/features/default_pre.prf \ - /usr/share/qt4/mkspecs/features/release.prf \ - /usr/share/qt4/mkspecs/features/default_post.prf \ - /usr/share/qt4/mkspecs/features/warn_on.prf \ - /usr/share/qt4/mkspecs/features/qt.prf \ - /usr/share/qt4/mkspecs/features/unix/opengl.prf \ - /usr/share/qt4/mkspecs/features/unix/thread.prf \ - /usr/share/qt4/mkspecs/features/moc.prf \ - /usr/share/qt4/mkspecs/features/resources.prf \ - /usr/share/qt4/mkspecs/features/uic.prf \ - /usr/share/qt4/mkspecs/features/yacc.prf \ - /usr/share/qt4/mkspecs/features/lex.prf \ - /usr/share/qt4/mkspecs/features/include_source_dir.prf \ - /usr/lib/libQtOpenGL.prl \ - /usr/lib/libQtGui.prl \ - /usr/lib/libQtCore.prl - $(QMAKE) -o Makefile gui.pro -/usr/share/qt4/mkspecs/common/g++.conf: -/usr/share/qt4/mkspecs/common/unix.conf: -/usr/share/qt4/mkspecs/common/linux.conf: -/usr/share/qt4/mkspecs/qconfig.pri: -/usr/share/qt4/mkspecs/modules/qt_webkit_version.pri: -/usr/share/qt4/mkspecs/features/qt_functions.prf: -/usr/share/qt4/mkspecs/features/qt_config.prf: -/usr/share/qt4/mkspecs/features/exclusive_builds.prf: -/usr/share/qt4/mkspecs/features/default_pre.prf: -/usr/share/qt4/mkspecs/features/release.prf: -/usr/share/qt4/mkspecs/features/default_post.prf: -/usr/share/qt4/mkspecs/features/warn_on.prf: -/usr/share/qt4/mkspecs/features/qt.prf: -/usr/share/qt4/mkspecs/features/unix/opengl.prf: -/usr/share/qt4/mkspecs/features/unix/thread.prf: -/usr/share/qt4/mkspecs/features/moc.prf: -/usr/share/qt4/mkspecs/features/resources.prf: -/usr/share/qt4/mkspecs/features/uic.prf: -/usr/share/qt4/mkspecs/features/yacc.prf: -/usr/share/qt4/mkspecs/features/lex.prf: -/usr/share/qt4/mkspecs/features/include_source_dir.prf: -/usr/lib/libQtOpenGL.prl: -/usr/lib/libQtGui.prl: -/usr/lib/libQtCore.prl: -qmake: FORCE - @$(QMAKE) -o Makefile gui.pro - -dist: - @$(CHK_DIR_EXISTS) $(BINDIR)/gui/gui1.0.0 || $(MKDIR) $(BINDIR)/gui/gui1.0.0 - $(COPY_FILE) --parents $(SOURCES) $(DIST) $(BINDIR)/gui/gui1.0.0/ && $(COPY_FILE) --parents GLWidget.h Camera.h ElementRenderer.h util.h Stage.h ParticleRenderer.h Renderer.h $(BINDIR)/gui/gui1.0.0/ && $(COPY_FILE) --parents Main.cc GLWidget.cc ElementRenderer.cc util.cc Stage.cc ParticleRenderer.cc $(BINDIR)/gui/gui1.0.0/ && (cd `dirname $(BINDIR)/gui/gui1.0.0` && $(TAR) gui1.0.0.tar gui1.0.0 && $(COMPRESS) gui1.0.0.tar) && $(MOVE) `dirname $(BINDIR)/gui/gui1.0.0`/gui1.0.0.tar.gz . && $(DEL_FILE) -r $(BINDIR)/gui/gui1.0.0 - - -clean:compiler_clean - -$(DEL_FILE) $(OBJECTS) - -$(DEL_FILE) *~ core *.core - - -####### Sub-libraries - -distclean: clean - -$(DEL_FILE) $(TARGET) - -$(DEL_FILE) Makefile - - -check: first - -mocclean: compiler_moc_header_clean compiler_moc_source_clean - -mocables: compiler_moc_header_make_all compiler_moc_source_make_all - -compiler_moc_header_make_all: moc_GLWidget.cpp moc_Stage.cpp -compiler_moc_header_clean: - -$(DEL_FILE) moc_GLWidget.cpp moc_Stage.cpp -moc_GLWidget.cpp: Camera.h \ - GLWidget.h - /usr/bin/moc-qt4 $(DEFINES) $(INCPATH) GLWidget.h -o moc_GLWidget.cpp - -moc_Stage.cpp: Camera.h \ - ElementRenderer.h \ - Renderer.h \ - ParticleRenderer.h \ - Stage.h - /usr/bin/moc-qt4 $(DEFINES) $(INCPATH) Stage.h -o moc_Stage.cpp - -compiler_rcc_make_all: -compiler_rcc_clean: -compiler_image_collection_make_all: qmake_image_collection.cpp -compiler_image_collection_clean: - -$(DEL_FILE) qmake_image_collection.cpp -compiler_moc_source_make_all: -compiler_moc_source_clean: -compiler_uic_make_all: -compiler_uic_clean: -compiler_yacc_decl_make_all: -compiler_yacc_decl_clean: -compiler_yacc_impl_make_all: -compiler_yacc_impl_clean: -compiler_lex_make_all: -compiler_lex_clean: -compiler_clean: compiler_moc_header_clean - -####### Compile - -$(BINDIR)/gui/Main.o: Main.cc GLWidget.h \ - Camera.h \ - Stage.h \ - ElementRenderer.h \ - Renderer.h \ - ParticleRenderer.h - $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $(BINDIR)/gui/Main.o Main.cc - -$(BINDIR)/gui/GLWidget.o: GLWidget.cc GLWidget.h \ - Camera.h \ - ElementRenderer.h \ - Renderer.h \ - util.h - $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $(BINDIR)/gui/GLWidget.o GLWidget.cc - -$(BINDIR)/gui/ElementRenderer.o: ElementRenderer.cc ElementRenderer.h \ - Renderer.h \ - util.h - $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $(BINDIR)/gui/ElementRenderer.o ElementRenderer.cc - -$(BINDIR)/gui/util.o: util.cc - $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $(BINDIR)/gui/util.o util.cc - -$(BINDIR)/gui/Stage.o: Stage.cc util.h \ - Stage.h \ - Camera.h \ - ElementRenderer.h \ - Renderer.h \ - ParticleRenderer.h - $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $(BINDIR)/gui/Stage.o Stage.cc - -$(BINDIR)/gui/ParticleRenderer.o: ParticleRenderer.cc ParticleRenderer.h \ - Renderer.h \ - util.h - $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $(BINDIR)/gui/ParticleRenderer.o ParticleRenderer.cc - -$(BINDIR)/gui/moc_GLWidget.o: moc_GLWidget.cpp - $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $(BINDIR)/gui/moc_GLWidget.o moc_GLWidget.cpp - -$(BINDIR)/gui/moc_Stage.o: moc_Stage.cpp - $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $(BINDIR)/gui/moc_Stage.o moc_Stage.cpp - -####### Install - -install: FORCE - -uninstall: FORCE - -FORCE: - diff --git a/src/gui/gui.pro b/src/gui/gui.pro index f82297f..3b68f40 100644 --- a/src/gui/gui.pro +++ b/src/gui/gui.pro @@ -10,5 +10,5 @@ LIBS += -L$(BINDIR)/main -lvhc QT += opengl # Input -HEADERS += GLWidget.h Camera.h ElementRenderer.h util.h Stage.h ParticleRenderer.h Renderer.h -SOURCES += Main.cc GLWidget.cc Camera.h ElementRenderer.cc util.cc Stage.cc ParticleRenderer.cc +HEADERS += Camera.h ElementRenderer.h util.h Stage.h ParticleRenderer.h Renderer.h +SOURCES += Camera.cc ElementRenderer.cc util.cc Stage.cc ParticleRenderer.cc Main.cc diff --git a/src/main/Accelerator.h b/src/main/Accelerator.h index c2df021..2c096fd 100644 --- a/src/main/Accelerator.h +++ b/src/main/Accelerator.h @@ -91,6 +91,19 @@ public: /** Fait évoluer l'accélérateur d'un lapse de temps dt. */ void step(double dt) { + for (int i = 0; i < particleCollec.size(); ++i) { + Particle& particle = *(particleCollec[i]); + particle.applyMagneticForce(particle.getElement()->magneticFieldAt(particle.getPosition()), dt); + + Vector3D a = particle.getForce() / (particle.getGamma() * particle.getMass()); + particle.setVelocity(particle.getVelocity() + a * dt); + } + + for (int i = 0; i < particleCollec.size(); ++i) { + Particle& particle = *(particleCollec[i]); + particle.setPosition(particle.getPosition() + particle.getVelocity() * dt); + particle.setForce(Vector3D::Null); + } } diff --git a/src/main/Particle.cc b/src/main/Particle.cc index 3609e01..c6c2af9 100644 --- a/src/main/Particle.cc +++ b/src/main/Particle.cc @@ -42,7 +42,7 @@ void Particle::applyForce(const Vector3D& f) {force = force + f;} void Particle::applyMagneticForce(const Vector3D& b, double dt) { if (b != Vector3D::Null) { Vector3D f = charge * velocity.cross(b); - force = force + f.rotate(velocity.cross(f), (dt * f.norm()) / (2 * gamma * mass * velocity.norm())); + applyForce(f.rotate(velocity.cross(f), (dt * f.norm()) / (2 * gamma * mass * velocity.norm()))); } } diff --git a/src/main/Vector3D.cc b/src/main/Vector3D.cc index 846ef03..44ccd47 100644 --- a/src/main/Vector3D.cc +++ b/src/main/Vector3D.cc @@ -7,6 +7,7 @@ #include <sstream> #include "Vector3D.h" +#include "exceptions.h" using namespace std; diff --git a/src/main/Vector3D.h b/src/main/Vector3D.h index 48a6c81..3c41147 100644 --- a/src/main/Vector3D.h +++ b/src/main/Vector3D.h @@ -9,7 +9,6 @@ #define VECTOR3D_H_ #include <math.h> -#include "exceptions.h" #include "Printable.h" namespace vhc { |