diff options
author | Jakob Odersky <jodersky@gmail.com> | 2011-04-03 20:50:45 +0000 |
---|---|---|
committer | Jakob Odersky <jodersky@gmail.com> | 2011-04-03 20:50:45 +0000 |
commit | 199fd6d577b914d083db9dd845e0b7f94960eac3 (patch) | |
tree | 157a3c0edeac68f00f5ce048fba237061d02aa53 /src/gui | |
parent | b0f200e3b07f3963d609d536e6abdde24b96ec21 (diff) | |
download | vhc-199fd6d577b914d083db9dd845e0b7f94960eac3.tar.gz vhc-199fd6d577b914d083db9dd845e0b7f94960eac3.tar.bz2 vhc-199fd6d577b914d083db9dd845e0b7f94960eac3.zip |
Essais graphiques, modifications du VisitorPattern.
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/ElementRenderer.cc | 40 | ||||
-rw-r--r-- | src/gui/ElementRenderer.h | 37 | ||||
-rw-r--r-- | src/gui/GElement.cc | 21 | ||||
-rw-r--r-- | src/gui/GElement.h | 28 | ||||
-rw-r--r-- | src/gui/GLWidget.cc | 14 | ||||
-rw-r--r-- | src/gui/Makefile | 19 | ||||
-rw-r--r-- | src/gui/graphicals.h | 35 | ||||
-rw-r--r-- | src/gui/gui.pro | 4 | ||||
-rw-r--r-- | src/gui/util.cc | 42 | ||||
-rw-r--r-- | src/gui/util.h | 28 |
10 files changed, 175 insertions, 93 deletions
diff --git a/src/gui/ElementRenderer.cc b/src/gui/ElementRenderer.cc new file mode 100644 index 0000000..6f28c13 --- /dev/null +++ b/src/gui/ElementRenderer.cc @@ -0,0 +1,40 @@ +/* + * ElementRenderer.cc + * + * Created on: Apr 2, 2011 + * Author: jakob + */ + +#include "ElementRenderer.h" +#include "Vector3D.h" + +namespace vhc { +using namespace util; + +ElementRenderer::ElementRenderer() { + // TODO Auto-generated constructor stub + +} + +ElementRenderer::~ElementRenderer() { + // TODO Auto-generated destructor stub +} + + +void ElementRenderer::visit(StraightElement* straight) { + +} + +void ElementRenderer::visit(Quadrupole* quadrupole) { + +} + +void ElementRenderer::visit(CurvedElement* curved) { + +} + +void ElementRenderer::visit(Dipole* dipole) { + +} + +} diff --git a/src/gui/ElementRenderer.h b/src/gui/ElementRenderer.h new file mode 100644 index 0000000..9d6ff75 --- /dev/null +++ b/src/gui/ElementRenderer.h @@ -0,0 +1,37 @@ +/* + * ElementRenderer.h + * + * Created on: Apr 2, 2011 + * Author: jakob + */ + +#ifndef ELEMENTRENDERER_H_ +#define ELEMENTRENDERER_H_ + +#include "ElementVisitor.h" + +namespace vhc { + + +class ElementRenderer: public ElementVisitor { + +public: + + ElementRenderer(); + + virtual ~ElementRenderer(); + + virtual void visit(StraightElement* straight); + + virtual void visit(Quadrupole* quadrupole); + + virtual void visit(CurvedElement* curved); + + virtual void visit(Dipole* dipole); + +}; + + +} + +#endif /* ELEMENTRENDERER_H_ */ diff --git a/src/gui/GElement.cc b/src/gui/GElement.cc deleted file mode 100644 index cbb3cae..0000000 --- a/src/gui/GElement.cc +++ /dev/null @@ -1,21 +0,0 @@ -/* - * GElement.cc - * - * Created on: Mar 31, 2011 - * Author: jakob - */ - -#include "GElement.h" - -namespace vhc { - -GElement::GElement() { - // TODO Auto-generated constructor stub - -} - -GElement::~GElement() { - // TODO Auto-generated destructor stub -} - -} diff --git a/src/gui/GElement.h b/src/gui/GElement.h deleted file mode 100644 index a62ff74..0000000 --- a/src/gui/GElement.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - * GElement.h - * - * Created on: Mar 31, 2011 - * Author: jakob - */ - -#ifndef GELEMENT_H_ -#define GELEMENT_H_ -#include "Element.h" - -namespace vhc { - -class GElement { - - Element& element; - -public: - GElement(Element& element); - - - virtual ~GElement(); - -}; - -} - -#endif /* GELEMENT_H_ */ diff --git a/src/gui/GLWidget.cc b/src/gui/GLWidget.cc index ee2bb59..391c5f5 100644 --- a/src/gui/GLWidget.cc +++ b/src/gui/GLWidget.cc @@ -1,15 +1,16 @@ #include <QtOpenGL> #include <math.h> #include "GLWidget.h" +#include "util.h" -void torus(int numc, int numt, double R = 1, double r = 0.1) { +void torus(int numc, int numt, double fraction = 1 , double R = 1, double r = 0.1) { 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 (j = 0; j <= numt / fraction ; j++) { for (k = 1; k >= 0; k--) { s = (i + k) % numc + 0.5; t = j % numt; @@ -25,6 +26,8 @@ void torus(int numc, int numt, double R = 1, double r = 0.1) { } } + + void axes() { glBegin(GL_LINES); glColor3d(1, 0, 0); @@ -101,9 +104,13 @@ void GLWidget::paintGL () { glPolygonMode(GL_FRONT, GL_LINE); glPolygonMode(GL_BACK, GL_LINE); - torus(12, 20, 1, 0.2); + torus(12, 20, 4, 1, 0.1); + + vhc::util::cylinder(0.1, 0, 2, 12, 20); + glPolygonMode(GL_FRONT, GL_FILL); glPolygonMode(GL_BACK, GL_FILL); + } void GLWidget::resizeGL (int width, int height) { @@ -149,4 +156,5 @@ void GLWidget::keyPressEvent (QKeyEvent* event) { } void GLWidget::keyReleaseEvent (QKeyEvent* event) { + } diff --git a/src/gui/Makefile b/src/gui/Makefile index e1f37a2..cd4970a 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: Sat Apr 2 21:37:01 2011 +# Generated by qmake (2.01a) (Qt 4.7.0) on: Sun Apr 3 21:53:36 2011 # Project: gui.pro # Template: app # Command: /usr/bin/qmake -o Makefile gui.pro @@ -45,10 +45,14 @@ OBJECTS_DIR = $(BINDIR)/gui/ SOURCES = Main.cc \ GLWidget.cc \ - Camera.cc moc_GLWidget.cpp + Camera.cc \ + ElementRenderer.cc \ + util.cc moc_GLWidget.cpp OBJECTS = $(BINDIR)/gui/Main.o \ $(BINDIR)/gui/GLWidget.o \ $(BINDIR)/gui/Camera.o \ + $(BINDIR)/gui/ElementRenderer.o \ + $(BINDIR)/gui/util.o \ $(BINDIR)/gui/moc_GLWidget.o DIST = /usr/share/qt4/mkspecs/common/g++.conf \ /usr/share/qt4/mkspecs/common/unix.conf \ @@ -158,7 +162,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 $(BINDIR)/gui/gui1.0.0/ && $(COPY_FILE) --parents Main.cc GLWidget.cc Camera.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 $(BINDIR)/gui/gui1.0.0/ && $(COPY_FILE) --parents Main.cc GLWidget.cc Camera.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 clean:compiler_clean @@ -207,12 +211,19 @@ compiler_clean: compiler_moc_header_clean $(BINDIR)/gui/Main.o: Main.cc GLWidget.h $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $(BINDIR)/gui/Main.o Main.cc -$(BINDIR)/gui/GLWidget.o: GLWidget.cc GLWidget.h +$(BINDIR)/gui/GLWidget.o: GLWidget.cc GLWidget.h \ + util.h $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $(BINDIR)/gui/GLWidget.o GLWidget.cc $(BINDIR)/gui/Camera.o: Camera.cc Camera.h $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $(BINDIR)/gui/Camera.o Camera.cc +$(BINDIR)/gui/ElementRenderer.o: ElementRenderer.cc ElementRenderer.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/moc_GLWidget.o: moc_GLWidget.cpp $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $(BINDIR)/gui/moc_GLWidget.o moc_GLWidget.cpp diff --git a/src/gui/graphicals.h b/src/gui/graphicals.h deleted file mode 100644 index c944e7e..0000000 --- a/src/gui/graphicals.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * graphicals.h - * - * Created on: Apr 2, 2011 - * Author: jakob - */ - -#ifndef GRAPHICALS_H_ -#define GRAPHICALS_H_ -#include "Element.h" - -namespace vhc { - -class Renderable { - -public: - - Renderable() {}; - - virtual ~Renderable() {}; - - virtual void render() const = 0; - -}; - -template <class T>; -class Graphical: public Renderable { -private: - T* element -}; - - -} - -#endif /* GRAPHICALS_H_ */ diff --git a/src/gui/gui.pro b/src/gui/gui.pro index fc82d3f..ee15909 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 -SOURCES += Main.cc GLWidget.cc Camera.cc +HEADERS += GLWidget.h Camera.h ElementRenderer.h util.h +SOURCES += Main.cc GLWidget.cc Camera.cc ElementRenderer.cc util.cc diff --git a/src/gui/util.cc b/src/gui/util.cc new file mode 100644 index 0000000..a92d5be --- /dev/null +++ b/src/gui/util.cc @@ -0,0 +1,42 @@ +/* + * util.cc + * + * Created on: Apr 2, 2011 + * Author: jakob + */ +#include <QtOpenGL> + +namespace vhc { +namespace util { + +void torus(double R, double r, double fraction, int slices, int stacks) { + int i, j, k; + double s, t, x, y, z, twopi; + + twopi = 2 * M_PI; + for (i = 0; i < slices; i++) { + glBegin(GL_QUAD_STRIP); + for (j = 0; j <= stacks * fraction ; j++) { + for (k = 1; k >= 0; k--) { + s = (i + k) % slices + 0.5; + t = j % 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, s/slices, t/slices); + glVertex3f(x, y, z); + } + } + glEnd(); + } +} + +void cylinder(double base, double top, double height, int slices, int stacks) { + GLUquadric* q = gluNewQuadric(); + gluCylinder(q, base, top, height, slices, stacks); + gluDeleteQuadric(q); +} + +} +} diff --git a/src/gui/util.h b/src/gui/util.h new file mode 100644 index 0000000..e1f7609 --- /dev/null +++ b/src/gui/util.h @@ -0,0 +1,28 @@ +/* + * util.h + * + * Created on: Apr 3, 2011 + * Author: jakob + */ + +#ifndef UTIL_H_ +#define UTIL_H_ + +namespace vhc { +namespace util { + +/** Dessine un tore autour de l'origine* + * @param R rayon du tore + * @param r rayon du "cylindre" du tore + * @param fraction fraction de tore a dessiner (1 = un tour) + * @param slices nombre de cotes du "cylindre" du tore + * @param stacks nombre de cotes du tore */ +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); + +} +} + +#endif /* UTIL_H_ */ |