diff options
-rw-r--r-- | src/gui/ElementRenderer.cc | 3 | ||||
-rw-r--r-- | src/gui/GLWidget.cc | 60 | ||||
-rw-r--r-- | src/gui/Main.cc | 4 | ||||
-rw-r--r-- | src/gui/Makefile | 36 | ||||
-rw-r--r-- | src/gui/ParticleRenderer.cc | 21 | ||||
-rw-r--r-- | src/gui/ParticleRenderer.h | 21 | ||||
-rw-r--r-- | src/gui/Stage.cc | 15 | ||||
-rw-r--r-- | src/gui/Stage.h | 21 | ||||
-rw-r--r-- | src/gui/gui.pro | 4 | ||||
-rw-r--r-- | src/gui/moc_GLWidget.cpp | 69 | ||||
-rw-r--r-- | src/gui/util.cc | 5 | ||||
-rw-r--r-- | src/main/Accelerator.h | 2 | ||||
-rw-r--r-- | src/main/Particle.h | 7 | ||||
-rw-r--r-- | src/main/Vector3D.h | 10 | ||||
-rw-r--r-- | src/test/AccelTest.cc | 7 | ||||
-rw-r--r-- | src/test/ParticleTest.cc | 48 |
16 files changed, 206 insertions, 127 deletions
diff --git a/src/gui/ElementRenderer.cc b/src/gui/ElementRenderer.cc index 3dc22b1..a31b71b 100644 --- a/src/gui/ElementRenderer.cc +++ b/src/gui/ElementRenderer.cc @@ -19,12 +19,11 @@ namespace vhc { ElementRenderer::ElementRenderer() { - // TODO Auto-generated constructor stub } ElementRenderer::~ElementRenderer() { - // TODO Auto-generated destructor stub + } diff --git a/src/gui/GLWidget.cc b/src/gui/GLWidget.cc index d72c78d..0653ef2 100644 --- a/src/gui/GLWidget.cc +++ b/src/gui/GLWidget.cc @@ -11,6 +11,9 @@ using namespace vhc; + +int keys; + void axes() { glBegin(GL_LINES); glColor3d(1, 0, 0); @@ -51,6 +54,7 @@ void grid() { GLWidget::GLWidget (QWidget* parent) : QGLWidget (parent), wireframe(false), camera(), center() { + keys = 0; setMouseTracking(true); resize (sizeHint ()); } @@ -77,8 +81,9 @@ void GLWidget::resizeGL (int width, int height) { glViewport (0, 0, width, height); glMatrixMode (GL_PROJECTION); glLoadIdentity(); - gluPerspective(65.0, 1, 1.0, 10000.0); + gluPerspective(65.0, 4.0/3.0, 1.0, 10000.0); glMatrixMode (GL_MODELVIEW); + setCursor(QCursor(Qt::CrossCursor)); } void GLWidget::paintGL () { @@ -95,6 +100,7 @@ void GLWidget::paintGL () { center = QWidget::mapToGlobal(QPoint(this->size().width() / 2, this->size().height() / 2)); QCursor::setPos(center); + glScaled (100.0, 100.0, 100.0); @@ -106,6 +112,8 @@ void GLWidget::paintGL () { 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); @@ -117,7 +125,7 @@ void GLWidget::paintGL () { 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"; + //std::cout <<*ce << "\n"; ce->accept(*er); delete er; er = NULL; @@ -133,6 +141,7 @@ void GLWidget::mousePressEvent (QMouseEvent* event) { void GLWidget::mouseReleaseEvent (QMouseEvent* event) { } + void GLWidget::keyPressEvent (QKeyEvent* event) { Vector3D mv = Vector3D::Null; switch (event->key()) { @@ -140,16 +149,20 @@ void GLWidget::keyPressEvent (QKeyEvent* event) { qApp->quit(); break; case Qt::Key_A: - mv = mv - Vector3D::j; + //mv = mv - Vector3D::j; + keys |= 1; break; case Qt::Key_W: - mv = mv - Vector3D::i; + //mv = mv - Vector3D::i; + keys |= 2; break; case Qt::Key_D: - mv = mv + Vector3D::j; + //mv = mv + Vector3D::j; + keys |= 4; break; case Qt::Key_S: - mv = mv + Vector3D::i; + //mv = mv + Vector3D::i; + keys |= 8; break; case Qt::Key_Up: camera.addPitch(2 * M_PI / 100); @@ -171,20 +184,49 @@ void GLWidget::keyPressEvent (QKeyEvent* event) { 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 / 20); - camera.addPitch(1.0 * dpitch / 20); + camera.addHeading(1.0 * dheading / 200); + camera.addPitch(1.0 * dpitch / 200); updateGL(); } diff --git a/src/gui/Main.cc b/src/gui/Main.cc index cc9bf57..56974b7 100644 --- a/src/gui/Main.cc +++ b/src/gui/Main.cc @@ -16,9 +16,9 @@ int main(int argc, char *argv[]) QApplication app(argc, argv); GLWidget window; - vhc::Vector3D s = vhc::Vector3D::i; + window.showFullScreen(); - window.resize(QApplication::desktop()->size()); +// window.resize(QSize(500, 500)); window.setWindowTitle("Virtual Hadron Collider"); window.show(); diff --git a/src/gui/Makefile b/src/gui/Makefile index 179964e..75975e6 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 17:00:28 2011 +# Generated by qmake (2.01a) (Qt 4.7.0) on: Tue Apr 12 19:39:44 2011 # Project: gui.pro # Template: app # Command: /usr/bin/qmake -o Makefile gui.pro @@ -46,12 +46,18 @@ OBJECTS_DIR = $(BINDIR)/gui/ SOURCES = Main.cc \ GLWidget.cc \ ElementRenderer.cc \ - util.cc moc_GLWidget.cpp + 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/moc_GLWidget.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 \ @@ -160,7 +166,7 @@ qmake: FORCE 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 $(BINDIR)/gui/gui1.0.0/ && $(COPY_FILE) --parents Main.cc GLWidget.cc ElementRenderer.cc util.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 + $(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 $(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 @@ -181,13 +187,19 @@ 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 +compiler_moc_header_make_all: moc_GLWidget.cpp moc_Stage.cpp compiler_moc_header_clean: - -$(DEL_FILE) moc_GLWidget.cpp + -$(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 \ + 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 @@ -224,9 +236,21 @@ $(BINDIR)/gui/ElementRenderer.o: ElementRenderer.cc ElementRenderer.h \ $(BINDIR)/gui/util.o: util.cc $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $(BINDIR)/gui/util.o util.cc +$(BINDIR)/gui/Stage.o: Stage.cc Stage.h \ + Camera.h \ + ElementRenderer.h \ + ParticleRenderer.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $(BINDIR)/gui/Stage.o Stage.cc + +$(BINDIR)/gui/ParticleRenderer.o: ParticleRenderer.cc ParticleRenderer.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 diff --git a/src/gui/ParticleRenderer.cc b/src/gui/ParticleRenderer.cc new file mode 100644 index 0000000..48742bc --- /dev/null +++ b/src/gui/ParticleRenderer.cc @@ -0,0 +1,21 @@ +/* + * ParticleRenderer.cc + * + * Created on: Apr 12, 2011 + * Author: jakob + */ + +#include "ParticleRenderer.h" + +namespace vhc { + +ParticleRenderer::ParticleRenderer() { + // TODO Auto-generated constructor stub + +} + +ParticleRenderer::~ParticleRenderer() { + // TODO Auto-generated destructor stub +} + +} diff --git a/src/gui/ParticleRenderer.h b/src/gui/ParticleRenderer.h new file mode 100644 index 0000000..984f2e1 --- /dev/null +++ b/src/gui/ParticleRenderer.h @@ -0,0 +1,21 @@ +/* + * ParticleRenderer.h + * + * Created on: Apr 12, 2011 + * Author: jakob + */ + +#ifndef PARTICLERENDERER_H_ +#define PARTICLERENDERER_H_ + +namespace vhc { + +class ParticleRenderer { +public: + ParticleRenderer(); + virtual ~ParticleRenderer(); +}; + +} + +#endif /* PARTICLERENDERER_H_ */ diff --git a/src/gui/Stage.cc b/src/gui/Stage.cc index ad6bf60..318c2b8 100644 --- a/src/gui/Stage.cc +++ b/src/gui/Stage.cc @@ -5,25 +5,28 @@ * Author: jakob */ + #include "Stage.h" namespace vhc { -Stage::Stage(QWidget* parent): QGLWidget (parent), camera(), wireframe(false) { +Stage::Stage(QWidget* parent): QGLWidget (parent), elements(0), camera(), elementRenderer(new ElementRenderer), particleRenderer(), wireframe(false) { setMouseTracking(true); } -Stage::~Stage() {}; +Stage::~Stage() { + delete elementRenderer; elementRenderer = NULL; +}; -void GLWidget::initializeGL () { +void Stage::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); + gluPerspective(65.0, 1.6, 0.1, 10000.0); glClearColor (0, 0, 0, 1.0); } -void GLWidget::resizeGL (int width, int height) { +void Stage::resizeGL (int width, int height) { glViewport (0, 0, width, height); glMatrixMode (GL_PROJECTION); glLoadIdentity(); @@ -33,6 +36,4 @@ void GLWidget::resizeGL (int width, int height) { - - } diff --git a/src/gui/Stage.h b/src/gui/Stage.h index ffb6509..5e0a834 100644 --- a/src/gui/Stage.h +++ b/src/gui/Stage.h @@ -8,8 +8,13 @@ #ifndef STAGE_H_ #define STAGE_H_ +#include <vector> #include <QGLWidget> +#include <QtOpenGL> #include "Camera.h" +#include "ElementRenderer.h" +#include "ParticleRenderer.h" +#include "Element.h" namespace vhc { @@ -26,17 +31,21 @@ protected: void initializeGL(); void resizeGL (int width, int height); - void paintGL(); + //void paintGL(); - void mousePressEvent (QMouseEvent* event); - void mouseReleaseEvent (QMouseEvent* event); - void keyPressEvent (QKeyEvent* event); - void keyReleaseEvent (QKeyEvent* event); - void mouseMoveEvent(QMouseEvent* event); + //void mousePressEvent (QMouseEvent* event); + //void mouseReleaseEvent (QMouseEvent* event); + //void keyPressEvent (QKeyEvent* event); + //void keyReleaseEvent (QKeyEvent* event); + //void mouseMoveEvent(QMouseEvent* event); private: + std::vector<Element*> elements; + Camera camera; + ElementRenderer* elementRenderer; + ParticleRenderer particleRenderer; bool wireframe; diff --git a/src/gui/gui.pro b/src/gui/gui.pro index b56e8b3..495b5ef 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 -SOURCES += Main.cc GLWidget.cc Camera.h ElementRenderer.cc util.cc +HEADERS += GLWidget.h Camera.h ElementRenderer.h util.h Stage.h ParticleRenderer.h +SOURCES += Main.cc GLWidget.cc Camera.h ElementRenderer.cc util.cc Stage.cc ParticleRenderer.cc diff --git a/src/gui/moc_GLWidget.cpp b/src/gui/moc_GLWidget.cpp deleted file mode 100644 index e13e21d..0000000 --- a/src/gui/moc_GLWidget.cpp +++ /dev/null @@ -1,69 +0,0 @@ -/**************************************************************************** -** Meta object code from reading C++ file 'GLWidget.h' -** -** 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! -*****************************************************************************/ - -#include "GLWidget.h" -#if !defined(Q_MOC_OUTPUT_REVISION) -#error "The header file 'GLWidget.h' doesn't include <QObject>." -#elif Q_MOC_OUTPUT_REVISION != 62 -#error "This file was generated using the moc from 4.7.0. It" -#error "cannot be used with the include files from this version of Qt." -#error "(The moc has changed too much.)" -#endif - -QT_BEGIN_MOC_NAMESPACE -static const uint qt_meta_data_GLWidget[] = { - - // content: - 5, // revision - 0, // classname - 0, 0, // classinfo - 0, 0, // methods - 0, 0, // properties - 0, 0, // enums/sets - 0, 0, // constructors - 0, // flags - 0, // signalCount - - 0 // eod -}; - -static const char qt_meta_stringdata_GLWidget[] = { - "GLWidget\0" -}; - -const QMetaObject GLWidget::staticMetaObject = { - { &QGLWidget::staticMetaObject, qt_meta_stringdata_GLWidget, - qt_meta_data_GLWidget, 0 } -}; - -#ifdef Q_NO_DATA_RELOCATION -const QMetaObject &GLWidget::getStaticMetaObject() { return staticMetaObject; } -#endif //Q_NO_DATA_RELOCATION - -const QMetaObject *GLWidget::metaObject() const -{ - return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject; -} - -void *GLWidget::qt_metacast(const char *_clname) -{ - if (!_clname) return 0; - if (!strcmp(_clname, qt_meta_stringdata_GLWidget)) - return static_cast<void*>(const_cast< GLWidget*>(this)); - return QGLWidget::qt_metacast(_clname); -} - -int GLWidget::qt_metacall(QMetaObject::Call _c, int _id, void **_a) -{ - _id = QGLWidget::qt_metacall(_c, _id, _a); - if (_id < 0) - return _id; - return _id; -} -QT_END_MOC_NAMESPACE diff --git a/src/gui/util.cc b/src/gui/util.cc index 7dfb215..1efac67 100644 --- a/src/gui/util.cc +++ b/src/gui/util.cc @@ -24,7 +24,10 @@ void torus(double R, double r, double fraction, int slices, int stacks) { x = (R+r*cos(s*twopi/slices))*cos(t*twopi/stacks); y = (R+r*cos(s*twopi/slices))*sin(t*twopi/stacks); z = r * sin(s * twopi / slices); - glColor3d((rand() % 100) / 100.0, (rand() % 100) / 100.0, (rand() % 100) / 100.0); + double b = (rand() % 100) / 100.0; + bool white = (rand() % 3) == 0; + if (white) glColor3d(1, 1, 1); + else glColor3d(b, (rand() % 100) / 100.0, 1); glVertex3d(x, y, z); } } diff --git a/src/main/Accelerator.h b/src/main/Accelerator.h index 73e341a..48125da 100644 --- a/src/main/Accelerator.h +++ b/src/main/Accelerator.h @@ -47,7 +47,7 @@ public: /* Retourne un pointeur sur une particule de l'accélérateur, * il n'y a pas besoin d'avoir la particule elle-même. * Question : où mettre le 'delete' ? */ - Particle* getParticle(int rank) const { return particleCollec[rank-1]; } + Particle* getParticle(int rank) const { return particleCollec[rank-1]; rank} /** Retourne une représentation en chaîne de caractères de cet accélérateur. */ virtual std::string toString() const; diff --git a/src/main/Particle.h b/src/main/Particle.h index 8bbe375..1df2827 100644 --- a/src/main/Particle.h +++ b/src/main/Particle.h @@ -79,13 +79,16 @@ public: void 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())); + force = force + f.rotate(velocity.cross(f), (dt * f.norm()) / (2 * gamma * getMassKg() * velocity.norm())); } } - /** Retourne la masse de cette particule. */ + /** Retourne la masse de cette particule en GeV. */ double getMass() const {return mass;} + /** Retourne la masse de cette particule en Kg. */ + double getMassKg() const {return mass * 1E-9 * constants::e / constants::c2;} + /** Retourne la charge de cette particule. */ double getCharge() const {return charge;} diff --git a/src/main/Vector3D.h b/src/main/Vector3D.h index 5a836fd..a7764df 100644 --- a/src/main/Vector3D.h +++ b/src/main/Vector3D.h @@ -38,6 +38,9 @@ private: /** Composante z. */ double z; + /** Cache de norme. (-1 si pas encore calcule) */ + mutable double normCache; + public: /** Crée une nouvelle instance de <code>Vector3D</code>. @@ -45,7 +48,7 @@ public: * @param _y 2e composante * @param _z 3e composante */ - Vector3D(double _x, double _y, double _z) : x(_x), y(_y), z(_z) {}; + Vector3D(double _x, double _y, double _z) : x(_x), y(_y), z(_z), normCache(-1) {}; /** Retourne la composante x de ce vecteur. */ double getX() const {return x;}; @@ -95,7 +98,10 @@ public: Vector3D unit() const {return ~(*this);} /** Retourne la norme du vecteur. */ - double norm() const {return sqrt(dot(*this));} + double norm() const { + if (normCache == -1) normCache = sqrt(dot(*this)); + return normCache; + } /** Retourne la norme du vecteur au carre. */ double normSquare() const {return dot(*this);} diff --git a/src/test/AccelTest.cc b/src/test/AccelTest.cc index e3c40cd..d7cbe79 100644 --- a/src/test/AccelTest.cc +++ b/src/test/AccelTest.cc @@ -6,17 +6,16 @@ */ -#include "Accelerator.h" +//#include "Accelerator.h" #include <iostream> #include <string> #include <vector> -using namespace vhc; using namespace std; /** lance le test*/ //TODO test avec un accélérateur initialisé int main() { - Accelerator a(); - cout << a << endl; + //Accelerator a(); + //cout << a << endl; return 0; } diff --git a/src/test/ParticleTest.cc b/src/test/ParticleTest.cc index 30cd93a..d30aab0 100644 --- a/src/test/ParticleTest.cc +++ b/src/test/ParticleTest.cc @@ -8,6 +8,7 @@ #include <iostream> #include <string> #include <vector> +#include "constants.h" #include "StraightElement.h" #include "Dipole.h" #include "Quadrupole.h" @@ -17,24 +18,41 @@ using namespace vhc; using namespace std; -Particle particle(Vector3D(0,0,0), 5.1, constants::e, 150, Vector3D::i); -Element* element; +Element* element = NULL; +Particle* particle = NULL; void step(double h); +double toKg(double mGeV) { + return constants::e / constants::c2 * 1E9 * mGeV; +} + int main() { - //Particle p(Vector3D::Null, 0, 0); - //cout << p << endl; - element = new Dipole(Vector3D::Null, Vector3D::i-Vector3D::j, 0.2, 1.0, Vector3D(0, 0, 1) * particle.getGamma() * particle.getMass() * 1 * particle.getVelocity().norm() / particle.getCharge()); - cout << *element << endl; + Vector3D entry = Vector3D(0, 10, 0); + Vector3D exit = Vector3D(10, 0, 0); + double sectionRadius = 0.2; + double curvature = 0.1; + Vector3D direction = entry.cross(Vector3D::k); + + double mass = 5.1E-4; //GeV + double charge = constants::e; //C + double energy = 1; //GeV + + particle = new Particle(entry, mass, charge, energy, direction); + double Bz = particle->getGamma() * particle->getMassKg() * curvature * particle->getVelocity().norm() / particle->getCharge(); + cout << Bz << endl; + element = new Dipole(entry, exit, sectionRadius, curvature, Vector3D::k * Bz); + + cout << *element << endl; double t = 0; - double h = 1E-9; + double h = 1E-12; char c('0'); bool hit = false; do { - if (element->isOutside(particle)) hit = true; + if (element->isOutside(*particle)) hit = true; + cout << "t = " << t << endl; step(h); t += h; cin.get(c); @@ -45,17 +63,19 @@ int main() { } + + delete particle; delete element; return 0; } void step(double h) { - particle.applyMagneticForce(element->magneticFieldAt(particle.getPosition()), h); + particle->applyMagneticForce(element->magneticFieldAt(particle->getPosition()), h); - Vector3D a = particle.getForce() / (particle.getGamma() * particle.getMass()); - particle.setVelocity(particle.getVelocity() + a * h); - particle.setPosition(particle.getPosition() + particle.getVelocity() * h); - cout << particle << endl; - particle.setForce(Vector3D::Null); + Vector3D a = particle->getForce() / (particle->getGamma() * particle->getMassKg()); + particle->setVelocity(particle->getVelocity() + a * h); + particle->setPosition(particle->getPosition() + particle->getVelocity() * h); + cout << *particle << endl; + particle->setForce(Vector3D::Null); } |