summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Odersky <jodersky@gmail.com>2011-04-15 15:48:34 +0000
committerJakob Odersky <jodersky@gmail.com>2011-04-15 15:48:34 +0000
commit269a25fce9fcf3da10bbe420f81e2bf3a4de01ab (patch)
tree99b05c22d827a7b2a6f64da3625acc9aadcffb42
parentdab913dc3865bc2cc3cff99cc9afb052cc1447aa (diff)
downloadvhc-269a25fce9fcf3da10bbe420f81e2bf3a4de01ab.tar.gz
vhc-269a25fce9fcf3da10bbe420f81e2bf3a4de01ab.tar.bz2
vhc-269a25fce9fcf3da10bbe420f81e2bf3a4de01ab.zip
Resolu probleme avec rendement a l'envers d'elements courbes. Interface graphique amelioree.
-rw-r--r--src/gui/Camera.h4
-rw-r--r--src/gui/ElementRenderer.cc20
-rw-r--r--src/gui/Main.cc10
-rw-r--r--src/gui/Makefile2
-rw-r--r--src/gui/Stage.cc20
-rw-r--r--src/gui/util.cc1
6 files changed, 32 insertions, 25 deletions
diff --git a/src/gui/Camera.h b/src/gui/Camera.h
index 109bef9..dc5b614 100644
--- a/src/gui/Camera.h
+++ b/src/gui/Camera.h
@@ -54,6 +54,10 @@ public:
position = position + mv;
}
+ Vector3D getPosition() {return position;}
+ double getHeading() {return heading;}
+ double getPitch() {return pitch;}
+
};
}
diff --git a/src/gui/ElementRenderer.cc b/src/gui/ElementRenderer.cc
index 01b27a0..14d7fc6 100644
--- a/src/gui/ElementRenderer.cc
+++ b/src/gui/ElementRenderer.cc
@@ -5,6 +5,7 @@
* Author: jakob
*/
+#include <iostream>
#include <QtOpenGL>
#include <math.h>
#include "ElementRenderer.h"
@@ -49,25 +50,34 @@ void ElementRenderer::visit(StraightElement* straight) {
}
void ElementRenderer::visit(Quadrupole* quadrupole) {
- if (quadrupole->getFocusingCoefficient() > 1) glColor4d(0.4, 0, 0, 0.9);
- else glColor4d(0, 0, 0.4, 0.9);
+ if (quadrupole->getFocusingCoefficient() > 1)
+ glColor4d(0.4, 0, 0, 0.9);
+ else
+ glColor4d(0.4, 0.2, 0.2, 0.9);
drawStraight(quadrupole);
}
void ElementRenderer::visit(Dipole* dipole) {
- glColor4d(0.4, 0, 0.6, 0.9);
+ glColor4d(0.2, 0, 0.4, 0.9);
glPushMatrix();
glTranslated(dipole->getCurvatureCenter().getX(), dipole->getCurvatureCenter().getY(), dipole->getCurvatureCenter().getZ());
Vector3D d = dipole->getExitPosition() - dipole->getCurvatureCenter();
Vector3D axis = Vector3D::i.cross(d);
double angle = asin(axis.norm() / d.norm());
- glRotated(angle * 180 / M_PI, axis.getX(), axis.getY(), axis.getZ());
+
+ std::cout << "axis: " << axis << "\n";
+ std::cout << "angle: " << angle * 180 / M_PI << "\n";
+ std::cout << "for element " << *dipole << "\n";
+ if (d != -Vector3D::i)
+ glRotated(angle * 180 / M_PI, axis.getX(), axis.getY(), axis.getZ());
+ else
+ glRotated(180, 0, 0, 1); //handle degenerate case
//double fraction
util::torus(d.norm(),
dipole->getSectionRadius(),
- dipole->getAngle() / (2 * M_PI), SLICES, 200);// * dipole->getAngle() * d.norm());
+ dipole->getAngle() / (2 * M_PI), SLICES, 200); // * dipole->getAngle() * d.norm());
glPopMatrix();
}
diff --git a/src/gui/Main.cc b/src/gui/Main.cc
index f0eb3cd..ac9e7a5 100644
--- a/src/gui/Main.cc
+++ b/src/gui/Main.cc
@@ -5,6 +5,7 @@
* Author: jakob
*/
+#include <iostream>
#include <QApplication>
#include <QWidget>
#include "GLWidget.h"
@@ -38,15 +39,6 @@ int main(int argc, char *argv[])
{
QApplication app(argc, argv);
- //GLWidget window;
- vhc::Accelerator accelerator;
- vhc::StraightElement se = vhc::StraightElement(vhc::Vector3D::j, vhc::Vector3D::j + vhc::Vector3D::i, 0.2);
- vhc::StraightElement se2 = vhc::StraightElement(vhc::Vector3D(2,0,0), vhc::Vector3D(2,-1,0), 0.2);
- vhc::CurvedElement* ce = new vhc::Dipole(vhc::Vector3D(1,1,0), vhc::Vector3D::i * 2, 0.2, 1, vhc::Vector3D::Null);
- accelerator.add(se);
- accelerator.add(se2);
- accelerator.add(*ce);
-
FODO e1 = FODO(Vector3D(3, 2, 0), Vector3D(3, -2, 0), 0.2, 1.0, 5.0);
Dipole e2 = Dipole(e1.getExitPosition(), Vector3D(2, -3, 0), 0.2, 1);
FODO e3 = FODO(e2.getExitPosition(), Vector3D(-2, -3, 0), 0.2, 1, 5.0);
diff --git a/src/gui/Makefile b/src/gui/Makefile
index 410ecc6..2b3b256 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 13 15:26:23 2011
+# Generated by qmake (2.01a) (Qt 4.7.0) on: Fri Apr 15 17:44:57 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
index d7c6ee1..d9c3541 100644
--- a/src/gui/Stage.cc
+++ b/src/gui/Stage.cc
@@ -32,7 +32,7 @@ void Stage::resizeGL (int width, int height) {
glViewport (0, 0, width, height);
glMatrixMode (GL_PROJECTION);
glLoadIdentity();
- gluPerspective(65.0, 1.0 * width / height, 1.0, 10000.0);
+ gluPerspective(65.0, 1.0 * width / height, 0.1, 100.0);
glMatrixMode (GL_MODELVIEW);
}
@@ -41,20 +41,20 @@ void Stage::paintGL() {
glLoadIdentity();
camera.setView();
-
-
+ renderText(0,12,QString("camera coordinates:") + camera.getPosition().toString().c_str());
+ axes();
glPushMatrix();
- glScaled(100, 100, 100);
+ glScaled(10, 10, 10);
glColor3d(0.5, 0.5, 0.5);
grid(20);
- axes();
glPopMatrix();
+
center = QWidget::mapToGlobal(QPoint(this->size().width() / 2, this->size().height() / 2));
QCursor::setPos(center);
- glScaled (100.0, 100.0, 100.0);
+// glScaled (100.0, 100.0, 100.0);
switch (displayMode) {
@@ -151,10 +151,10 @@ void Stage::keyPressEvent (QKeyEvent* event) {
break;
}
- if (keys & 1) mv = mv - 3 * Vector3D::j;
- if (keys & 2) mv = mv - 3 * Vector3D::i;
- if (keys & 4) mv = mv + 3 * Vector3D::j;
- if (keys & 8) mv = mv + 3 * Vector3D::i;
+ if (keys & 1) mv = mv - 0.1 * Vector3D::j;
+ if (keys & 2) mv = mv - 0.1 * Vector3D::i;
+ if (keys & 4) mv = mv + 0.1 * Vector3D::j;
+ if (keys & 8) mv = mv + 0.1 * Vector3D::i;
camera.move(mv);
updateGL();
diff --git a/src/gui/util.cc b/src/gui/util.cc
index 8ca463e..11ac013 100644
--- a/src/gui/util.cc
+++ b/src/gui/util.cc
@@ -24,6 +24,7 @@ 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(0, 1 - 1.0 * j / (stacks * fraction), 1.0 * j / (stacks * fraction));
glVertex3d(x, y, z);
}
}