Browse Source

Makefileupdate: subdirs werden benutzt

glmenu: spielemenu erstellt
Punkt3D: aus emath.h raus, eigene header bekommen
Punkt2D: endlich erstellt
seba 12 years ago
parent
commit
a233128818
22 changed files with 811 additions and 278 deletions
  1. 14
    6
      Makefile
  2. 0
    206
      emath.cpp
  3. 3
    58
      emath.h
  4. 10
    5
      glfontengine.cpp
  5. 0
    0
      glgui/glgui.h
  6. 4
    3
      glgui/window.cpp
  7. 12
    0
      glmenu/Makefile
  8. 8
    0
      glmenu/glmenu.h
  9. 39
    0
      glmenu/menuitem.cpp
  10. 30
    0
      glmenu/menuitem.h
  11. 9
    0
      glmenu/menuitems.cpp
  12. 17
    0
      glmenu/menuitems.h
  13. 54
    0
      glmenu/menumanager.cpp
  14. 29
    0
      glmenu/menumanager.h
  15. 76
    0
      glmenu/menumenu.cpp
  16. 41
    0
      glmenu/menumenu.h
  17. 8
    0
      glsdlscreen.cpp
  18. 3
    0
      glsdlscreen.h
  19. 132
    0
      punkt2d.cpp
  20. 49
    0
      punkt2d.h
  21. 207
    0
      punkt3d.cpp
  22. 66
    0
      punkt3d.h

+ 14
- 6
Makefile View File

@@ -1,15 +1,19 @@
1 1
 COMPILER = g++
2
-OBJECTS = emath.o emath_opengl.o glcolor.o gldrawhelper.o glfontengine.o glrect.o gltexture.o matrix.o quaternion.o rotationsmatrix.o glsdlscreen.o sdlfuncs.o glgui/glgui.a
2
+OBJECTS = punkt3d.o punkt2d.o emath.o emath_opengl.o glcolor.o gldrawhelper.o glfontengine.o glrect.o gltexture.o matrix.o quaternion.o rotationsmatrix.o glsdlscreen.o sdlfuncs.o
3
+SUBDIRS = glgui glmenu
4
+SUBDIROBJECTS = glgui/*.o glmenu/*.o
3 5
 VERSION = 0.0.1
4 6
 LIBNAME = libsegl
5 7
 
6
-
7
-segllib: $(OBJECTS)
8
-
9
-seglar: $(OBJECTS)
8
+seglar: $(OBJECTS) subdirs
10 9
 	rm -f $(LIBNAME).a
11
-	ar rcs $(LIBNAME).a $(OBJECTS)
10
+	ar rcs $(LIBNAME).a $(OBJECTS) $(SUBDIROBJECTS)
12 11
 # 	ranlib $(LIBNAME).a
12
+
13
+segllib: $(OBJECTS) subdirs
14
+
15
+subdirs:
16
+	@for i in $(SUBDIRS); do $(MAKE) -C $$i; done
13 17
 	
14 18
 %.o: %.cpp %.h
15 19
 	$(COMPILER) -c `sdl-config --cflags` $<
@@ -18,10 +22,14 @@ seglar: $(OBJECTS)
18 22
 glgui/glgui.a:
19 23
 	cd glgui; $(MAKE);
20 24
 	
25
+glmenu/glmenu.a:
26
+	cd glmenu; $(MAKE);
27
+	
21 28
 testprog: seglar testprog.o
22 29
 	g++ `sdl-config --libs` -lSDL_image -lGL -lGLU testprog.o -o testprog $(LIBNAME).a 
23 30
 	
24 31
 clean:
25 32
 	rm -f $(OBJECTS)
26 33
 	cd glgui; $(MAKE) clean
34
+	cd glmenu; $(MAKE) clean
27 35
 	@echo Done cleaning...

+ 0
- 206
emath.cpp View File

@@ -1,211 +1,5 @@
1 1
 #include "emath.h"
2 2
 
3
-Punkt3D::Punkt3D() {
4
-	x = y = z = 0.0f;
5
-}
6
-
7
-Punkt3D::Punkt3D(float _x, float _y, float _z) {
8
-	set(_x, _y, _z);
9
-}
10
-
11
-void Punkt3D::set(float _x, float _y, float _z) {
12
-	x = _x;
13
-	y = _y;
14
-	z = _z;
15
-}
16
-
17
-float Punkt3D::abs() {
18
-	return sqrt(x*x+y*y+z*z);
19
-}
20
-
21
-Punkt3D Punkt3D::kreuzprodukt(const Punkt3D &b) {
22
-	Punkt3D erg;
23
-	erg.x = y*b.z - z*b.y;
24
-	erg.y = z*b.x - x*b.z;
25
-	erg.z = x*b.y - y*b.x;
26
-	
27
-	return erg;
28
-}
29
-
30
-void Punkt3D::normalize() {
31
-	float a = abs();
32
-	x /= a;
33
-	y /= a;
34
-	z /= a;
35
-}
36
-
37
-Punkt3D Punkt3D::getNormalized() {
38
-	Punkt3D ret(*this);
39
-	ret.normalize();
40
-	return ret;
41
-}
42
-
43
-bool Punkt3D::isNormalized() {
44
-	return (abs()==1);
45
-}
46
-
47
-float Punkt3D::calcAngle(Punkt3D b) {
48
-	if(abs()*b.abs()==0.0f)
49
-		return 0.0f;
50
-	return rad2deg(std::acos(((*this)*b)/(abs()*b.abs())));
51
-}
52
-
53
-Punkt3D Punkt3D::getOrtographic() {
54
-	Punkt3D erg;
55
-	if(!x) {
56
-		erg.x = 0.0f;
57
-		erg.y = z;
58
-		erg.z = -y;
59
-	} else if(!y) {
60
-		erg.x = z;
61
-		erg.y = 0;
62
-		erg.z = -x;
63
-	} else {
64
-		// z, oder genereller fall
65
-		erg.x = y;
66
-		erg.y = -x;
67
-		erg.z = 0.0f;
68
-	}
69
-	return erg;
70
-}
71
-
72
-void Punkt3D::print(std::string coordname) {
73
-	if(coordname!="")
74
-		coordname.append(" ");
75
-	std::cout << coordname << "Coord: (" << x << ", " << y << ", " << z << ")" << std::endl;
76
-}
77
-
78
-
79
-
80
-Punkt3D Punkt3D::operator+(const Punkt3D &b) {
81
-	Punkt3D c;
82
-	c.x =  x + b.x;
83
-	c.y =  y + b.y;
84
-	c.z =  z + b.z;
85
-	
86
-	return c;
87
-}
88
-
89
-Punkt3D Punkt3D::operator-(const Punkt3D &b) {
90
-	Punkt3D c;
91
-	c.x =  x - b.x;
92
-	c.y =  y - b.y;
93
-	c.z =  z - b.z;
94
-	
95
-	return c;
96
-}
97
-
98
-Punkt3D& Punkt3D::operator+=(const Punkt3D &b) {
99
-	x +=  b.x;
100
-	y +=  b.y;
101
-	z +=  b.z;
102
-	
103
-	return *this;
104
-}
105
-
106
-Punkt3D& Punkt3D::operator-=(const Punkt3D &b) {
107
-	x -=  b.x;
108
-	y -=  b.y;
109
-	z -=  b.z;
110
-	
111
-	return *this;
112
-}
113
-
114
-Punkt3D Punkt3D::operator+(const float &_m) {
115
-	return Punkt3D(x+_m, y+_m, z+_m);
116
-}
117
-
118
-Punkt3D Punkt3D::operator-(const float &_m) {
119
-	return Punkt3D(x-_m, y-_m, z-_m);
120
-}
121
-
122
-Punkt3D Punkt3D::operator*(const float &_m) {
123
-	return Punkt3D(x*_m, y*_m, z*_m);
124
-}
125
-
126
-Punkt3D Punkt3D::operator/(const float &_m) {
127
-	return Punkt3D(x/_m, y/_m, z/_m);
128
-}
129
-
130
-Punkt3D& Punkt3D::operator+=(const float &_m) {
131
-	x += _m;
132
-	y += _m;
133
-	z += _m;
134
-	return *this;
135
-}
136
-Punkt3D& Punkt3D::operator-=(const float &_m) {
137
-	x -= _m;
138
-	y -= _m;
139
-	z -= _m;
140
-	return *this;
141
-}
142
-Punkt3D& Punkt3D::operator*=(const float &_m) {
143
-	x *= _m;
144
-	y *= _m;
145
-	z *= _m;
146
-	return *this;
147
-}
148
-Punkt3D& Punkt3D::operator/=(const float &_m) {
149
-	x /= _m;
150
-	y /= _m;
151
-	z /= _m;
152
-	return *this;
153
-}
154
-
155
-float Punkt3D::operator*(const Punkt3D& _m) {
156
-	return x * _m.x + y * _m.y + z * _m.z;
157
-}
158
-
159
-Punkt3D Punkt3D::operator-() {
160
-	return Punkt3D(-x, -y, -z);
161
-}
162
-
163
-bool Punkt3D::operator==(const Punkt3D& b) {
164
-	return ( x==b.x && y==b.y && z==b.z);
165
-}
166
-bool Punkt3D::operator!=(const Punkt3D& b) {
167
-	return !(*this==b);
168
-}
169
-// Freunde
170
-
171
-Punkt3D operator+(const float& _m, const Punkt3D& b) {
172
-	return Punkt3D(b.x+_m, b.y+_m, b.z+_m);
173
-}
174
-
175
-Punkt3D operator-(const float& _m, const Punkt3D& b) {
176
-	return Punkt3D(b.x-_m, b.y-_m, b.z-_m);
177
-}
178
-
179
-Punkt3D operator*(const float& _m, const Punkt3D& b) {
180
-	return Punkt3D(b.x*_m, b.y*_m, b.z*_m);
181
-}
182
-
183
-Punkt3D operator/(const float& _m, const Punkt3D& b) {
184
-	return Punkt3D(b.x/_m, b.y/_m, b.z/_m);
185
-}
186
-
187
-float abs(Punkt3D p) {
188
-	return p.abs();
189
-}
190
-
191
-// OpenGL Funktionen für Punkt3D
192
-
193
-void glVertex3f(Punkt3D p) {
194
-	glVertex3f(p.x, p.y, p.z);
195
-}
196
-
197
-void glTranslatef(Punkt3D p) {
198
-	glTranslatef(p.x, p.y, p.z);
199
-}
200
-
201
-void glNormal(Punkt3D p) {
202
-	glNormal3f(p.x, p.y, p.z);
203
-}
204
-
205
-void glRotatef(float deg, Punkt3D vec) {
206
-	glRotatef(deg, vec.x, vec.y, vec.z);
207
-}
208
-
209 3
 // Trigonometrische Funktionen
210 4
 
211 5
 float deg2rad(float deg) {

+ 3
- 58
emath.h View File

@@ -5,69 +5,14 @@
5 5
 #include <cmath>
6 6
 #include <SDL_opengl.h>
7 7
 
8
-class Punkt3D {
9
-	public:
10
-		Punkt3D();
11
-		Punkt3D(float, float, float);
12
-		
13
-		float x, y, z;
14
-		
15
-		void set(float, float, float);
16
-		float abs();
17
-		Punkt3D kreuzprodukt(const Punkt3D&);
18
-		void normalize();
19
-		Punkt3D getNormalized();
20
-		bool isNormalized();
21
-		float calcAngle(Punkt3D);
22
-		Punkt3D getOrtographic();
23
-		
24
-		void print(std::string="");
25
-		
26
-		
27
-		// Operatoren
28
-		Punkt3D operator+(const Punkt3D&);
29
-		Punkt3D operator-(const Punkt3D&);
30
-		Punkt3D& operator+=(const Punkt3D&);
31
-		Punkt3D& operator-=(const Punkt3D&);
32
-		
33
-		Punkt3D operator+(const float&);
34
-		Punkt3D operator-(const float&);
35
-		Punkt3D operator*(const float&);
36
-		Punkt3D operator/(const float&);
37
-		Punkt3D& operator+=(const float&);
38
-		Punkt3D& operator-=(const float&);
39
-		Punkt3D& operator*=(const float&);
40
-		Punkt3D& operator/=(const float&);
41
-		
42
-		float operator*(const Punkt3D&);
43
-		
44
-		Punkt3D operator-();
45
-
46
-		bool operator==(const Punkt3D&);
47
-		bool operator!=(const Punkt3D&);
48
-		
49
-		friend Punkt3D operator+(const float&, const Punkt3D&);
50
-		friend Punkt3D operator-(const float&, const Punkt3D&);
51
-		friend Punkt3D operator*(const float&, const Punkt3D&);
52
-		friend Punkt3D operator/(const float&, const Punkt3D&);
53
-};
54
-
55
-float abs(Punkt3D);
56
-
57
-// OpenGL-Funktionen für Punkt3D
58
-
59
-void glVertex3f(Punkt3D);
60
-void glTranslatef(Punkt3D);
61
-void glNormal3f(Punkt3D);
62
-
63
-void glRotatef(float, Punkt3D);
8
+#include "punkt3d.h" /* aus kompatibilitätsgründen */
64 9
 
65 10
 float deg2rad(float deg);
66 11
 float rad2deg(float rad);
67 12
 
68
-
69
-
70 13
 // *grml* scheiss cmath-sinus
14
+// diese beiden sinusfunktionenrechnen erst deg2rad
15
+// wenn es sich nicht um 0, 90, 180, 270 oder ein vielfaches handelt
71 16
 float ssin(float);
72 17
 float scos(float);
73 18
 

+ 10
- 5
glfontengine.cpp View File

@@ -94,7 +94,8 @@ bool GLFontEngine::fontSelect(std::string fontstr) {
94 94
 		font = fontpool[fontstr];
95 95
 	else {
96 96
 		//fallbackfont - ersten aus der liste
97
-		font = (fontpool.begin())->second;
97
+		font = (++fontpool.begin())->second;
98
+		std::cout << "font: " << font << std::endl;
98 99
 	}
99 100
 		
100 101
 	return true;
@@ -106,7 +107,7 @@ void GLFontEngine::renderText(std::string text, SDL_Rect pos) {
106 107
 
107 108
 void GLFontEngine::renderLine(std::string text, SDL_Rect pos) {
108 109
 // 	glColor4f(r, g, b, a);
109
-
110
+	
110 111
 	glMatrixMode(GL_TEXTURE);
111 112
 	glLoadIdentity();
112 113
 	glMatrixMode(GL_MODELVIEW);
@@ -123,7 +124,7 @@ void GLFontEngine::renderLine(std::string text, SDL_Rect pos) {
123 124
 		for(unsigned int i=0; i<text.length(); i++) {
124 125
 			int ch = text[i];
125 126
 			if(ch<0) {
126
-				ch += 256; // char geht wohl in machen fällen nur von -128 bis +127
127
+				ch += 256; // char geht wohl in machen fällen nur von -128 bis +127 *hust*
127 128
 			}
128 129
 // 			std::cout << (int)text[i] << " ";
129 130
 			tex_x = ((ch-1)%16 / 16.0f);
@@ -156,10 +157,11 @@ void GLFontEngine::renderLine(std::string text, SDL_Rect pos) {
156 157
 }
157 158
 
158 159
 void GLFontEngine::renderLine(std::string str, int x, int y, bool center, SDL_Rect *rendered_to) {
160
+
159 161
 	SDL_Rect m = { x, y, getTextWidth(str), fsize};
162
+
160 163
 	if(center)
161 164
 		m.x = m.x - m.w/2;
162
-	
163 165
 	renderLine(str, m);
164 166
 	
165 167
 	if(rendered_to)
@@ -231,7 +233,10 @@ void GLFontEngine::getSDLRect(const std::string &str, SDL_Rect *r) {
231 233
 }
232 234
 
233 235
 int GLFontEngine::getTextWidth(const std::string &moep) {
234
-	return (int)(moep.length()*font->charwidth*fsize);
236
+	if(fontloaded)
237
+		return (int)(moep.length()*(font->charwidth*fsize));
238
+	else
239
+		return 1;
235 240
 }
236 241
 
237 242
 std::map<std::string, GLFont*> GLFontEngine::fontpool;

+ 0
- 0
glgui/glgui.h View File


+ 4
- 3
glgui/window.cpp View File

@@ -33,7 +33,8 @@ SDL_Rect GLGuiWindow::getPos() {
33 33
 }
34 34
 
35 35
 GLGuiWindow::~GLGuiWindow() {
36
-	for(unsigned int i=0; i<items.size(); i++) {
37
-		delete(items[i]);
38
-	}
36
+//	der der allokiert soll sich gefälligst drum kümmern
37
+// 	for(unsigned int i=0; i<items.size(); i++) {
38
+// 		delete(items[i]);
39
+// 	}
39 40
 }

+ 12
- 0
glmenu/Makefile View File

@@ -0,0 +1,12 @@
1
+COMPILER = g++
2
+OBJECTS = menumanager.o menumenu.o menuitem.o menuitems.o
3
+
4
+glguilib: $(OBJECTS)
5
+# 	rm glgui.a -f
6
+	ar crus glmenu.a $(OBJECTS)
7
+
8
+%.o: %.cpp %.h
9
+	$(COMPILER) -c `sdl-config --cflags` $<
10
+
11
+clean:
12
+	rm -f $(OBJECTS)

+ 8
- 0
glmenu/glmenu.h View File

@@ -0,0 +1,8 @@
1
+#ifndef __GLMENU_H
2
+
3
+#include "menumanager.h"
4
+#include "menumenu.h"
5
+#include "menuitem.h"
6
+#include "menuitems.h"
7
+
8
+#endif

+ 39
- 0
glmenu/menuitem.cpp View File

@@ -0,0 +1,39 @@
1
+#include "menuitem.h"
2
+
3
+MenuItem::MenuItem(std::string c) {
4
+	caption = c;
5
+	fontsizeadd = 0;
6
+	fontname = "menufont";
7
+	usevalue = false;
8
+	
9
+	fontengine.fontSelect(fontname);
10
+}
11
+
12
+void MenuItem::render(Punkt2D pos, bool center, int basefontsize, int maxwidth, int valuewidth, bool highlight) {
13
+	fontengine.setSize(basefontsize+fontsizeadd);
14
+	if(highlight)
15
+		fontengine.setColor(1.0f, 0.0f, 0.0f);
16
+	else
17
+		fontengine.setColor(1.0f, 1.0f, 1.0f);
18
+	
19
+	if(!usevalue) {
20
+		fontengine.renderLine(caption, pos.x, pos.y, center);
21
+	} else {
22
+		// center und position ggf. überarbeiten..
23
+		
24
+		Punkt2D tmp;
25
+		tmp = pos - valuewidth/2 - fontengine.getTextWidth(caption)/2;
26
+		fontengine.renderLine(caption, tmp.x, tmp.y, center);
27
+		tmp = pos + valuewidth/2;
28
+		fontengine.renderLine(value, tmp.x, tmp.y, false);
29
+	}
30
+}
31
+
32
+int MenuItem::getFontSizeAdd() {
33
+	return fontsizeadd;
34
+}
35
+
36
+MenuItem::~MenuItem() {
37
+	
38
+	
39
+}

+ 30
- 0
glmenu/menuitem.h View File

@@ -0,0 +1,30 @@
1
+#ifndef __MENUITEM_H
2
+#define __MENUITEM_H
3
+
4
+#include <string>
5
+#include "../glfontengine.h"
6
+#include "../punkt2d.h"
7
+
8
+class MenuItem {
9
+	protected:
10
+		std::string caption;
11
+		std::string value;
12
+		
13
+		GLFontEngine fontengine;
14
+		std::string fontname;
15
+		int fontsizeadd;
16
+		
17
+		bool usevalue;
18
+	public:
19
+		MenuItem(std::string);
20
+		virtual ~MenuItem();
21
+		
22
+		virtual void left() { };
23
+		virtual void right() { };
24
+		virtual void select() { };
25
+		int getFontSizeAdd();
26
+		
27
+		virtual void render(Punkt2D pos, bool center, int basefontsize, int maxwidth, int valuewidth, bool highlight);
28
+};
29
+
30
+#endif

+ 9
- 0
glmenu/menuitems.cpp View File

@@ -0,0 +1,9 @@
1
+#include "menuitems.h"
2
+
3
+MISendSDLEvent::MISendSDLEvent(std::string str, SDL_Event event) : MenuItem(str) {
4
+	sendevent = event;
5
+}
6
+
7
+void MISendSDLEvent::select() {
8
+	SDL_PushEvent(&sendevent);
9
+}

+ 17
- 0
glmenu/menuitems.h View File

@@ -0,0 +1,17 @@
1
+#ifndef __MENUITEMS_H
2
+#define __MENUITEMS_H
3
+
4
+#include <SDL.h>
5
+#include "menuitem.h"
6
+
7
+class MISendSDLEvent : public MenuItem {
8
+	private:
9
+		SDL_Event sendevent;
10
+	public:
11
+		MISendSDLEvent(std::string str, SDL_Event event);
12
+		
13
+		void select();
14
+};
15
+
16
+
17
+#endif

+ 54
- 0
glmenu/menumanager.cpp View File

@@ -0,0 +1,54 @@
1
+#include "menumanager.h"
2
+
3
+MenuManager::MenuManager() {
4
+	aktuell = 0;
5
+}
6
+
7
+void MenuManager::addMenu(MenuMenu *mm) {
8
+	menus.push_back(mm);
9
+	if(menus.size()==1)
10
+		aktuell = mm;
11
+}
12
+
13
+bool MenuManager::changeMenu(MenuMenu *mm) {
14
+	for(unsigned int i=0; i<menus.size(); i++) {
15
+		if(menus[i]==mm) {
16
+			aktuell = mm;
17
+			return true;
18
+		}
19
+	}
20
+	return false;
21
+}
22
+
23
+void MenuManager::render() {
24
+	glEnable(GL_TEXTURE_2D);
25
+	GLFontEngine::prepare2DbyPushingMatrix();
26
+	if(aktuell)
27
+		aktuell->render();
28
+	GLFontEngine::regain3DbyPoppingMatrix();
29
+}
30
+
31
+void MenuManager::up() {
32
+	if(aktuell)
33
+		aktuell->up();
34
+}
35
+
36
+void MenuManager::down() {
37
+	if(aktuell)
38
+		aktuell->down();
39
+}
40
+
41
+void MenuManager::left() {
42
+	if(aktuell)
43
+		aktuell->left();
44
+}
45
+
46
+void MenuManager::right() {
47
+	if(aktuell)
48
+		aktuell->right();
49
+}
50
+
51
+void MenuManager::select() {
52
+	if(aktuell)
53
+		aktuell->select();
54
+}

+ 29
- 0
glmenu/menumanager.h View File

@@ -0,0 +1,29 @@
1
+#ifndef __MENUMANAGER_H
2
+#define __MENUMANAGER_H
3
+
4
+#include <vector>
5
+
6
+#include "../glfontengine.h"
7
+#include "menumenu.h"
8
+
9
+
10
+class MenuManager {
11
+	private:
12
+		MenuMenu *aktuell;
13
+		
14
+		std::vector<MenuMenu*> menus;
15
+	public:
16
+		MenuManager();
17
+		
18
+		void addMenu(MenuMenu*);
19
+		bool changeMenu(MenuMenu*);
20
+		void render();
21
+		
22
+		void up();
23
+		void down();
24
+		void left();
25
+		void right();
26
+		void select();
27
+};
28
+
29
+#endif

+ 76
- 0
glmenu/menumenu.cpp View File

@@ -0,0 +1,76 @@
1
+#include "menumenu.h"
2
+
3
+MenuMenu::MenuMenu() {
4
+	itempos = 0;
5
+	centermenu = false;
6
+	centerScreenX = false;
7
+	basefontsize = 20;
8
+	maxwidth = 0;
9
+	valuewidth = 100;
10
+	offset = 20;
11
+}
12
+
13
+void MenuMenu::setPos(const Punkt2D &p) {
14
+	menupos = p;
15
+}
16
+
17
+void MenuMenu::setCenter(bool _c) {
18
+	centermenu = _c;
19
+}
20
+
21
+void MenuMenu::setCenterScreenX(bool _c) {
22
+	centerScreenX = _c;
23
+}
24
+
25
+void MenuMenu::setBaseFontSize(int _bfs) {
26
+	if(_bfs>0)
27
+		basefontsize = _bfs;
28
+}
29
+
30
+void MenuMenu::setMaxWidth(int _mw) {
31
+	if(_mw>0)
32
+		maxwidth = _mw;
33
+}
34
+
35
+void MenuMenu::addMenuItem(MenuItem* mi) {
36
+	menuitems.push_back(mi);
37
+}
38
+
39
+void MenuMenu::up() {
40
+	if(itempos==0)
41
+		itempos = menuitems.size()-1;
42
+	else
43
+		itempos--;
44
+}
45
+
46
+void MenuMenu::down() {
47
+	if(itempos==menuitems.size()-1)
48
+		itempos = 0;
49
+	else
50
+		itempos++;
51
+}
52
+
53
+void MenuMenu::left() {
54
+	menuitems[itempos]->left();
55
+}
56
+
57
+void MenuMenu::right() {
58
+	menuitems[itempos]->right();
59
+}
60
+
61
+void MenuMenu::select() {
62
+	menuitems[itempos]->select();
63
+}
64
+
65
+void MenuMenu::render() {
66
+	Punkt2D pos = menupos;
67
+	if(centerScreenX) {
68
+		SDL_Surface *screen = SDL_GetVideoSurface();
69
+		pos.x = screen->w/2;
70
+	}
71
+
72
+	for(unsigned int i=0; i<menuitems.size(); i++) {
73
+		menuitems[i]->render(pos, centermenu, basefontsize, maxwidth, valuewidth, itempos==i);
74
+		pos.y += basefontsize + menuitems[i]->getFontSizeAdd() + offset;
75
+	}
76
+}

+ 41
- 0
glmenu/menumenu.h View File

@@ -0,0 +1,41 @@
1
+#ifndef __MENUMENU_H
2
+#define __MENUMENU_H
3
+
4
+#include <vector>
5
+#include <SDL.h>
6
+#include "../punkt2d.h"
7
+#include "menuitem.h"
8
+
9
+class MenuMenu {
10
+	private:
11
+		std::vector<MenuItem*> menuitems;
12
+		
13
+		int itempos;
14
+		Punkt2D menupos;
15
+		bool centermenu;
16
+		bool centerScreenX;
17
+		int basefontsize;
18
+		int offset;
19
+		int maxwidth;
20
+		int valuewidth;
21
+	public:
22
+		MenuMenu();
23
+		
24
+		void setPos(const Punkt2D&);
25
+		void setCenter(bool);
26
+		void setCenterScreenX(bool);
27
+		void setBaseFontSize(int);
28
+		void setMaxWidth(int);
29
+		
30
+		void up();
31
+		void down();
32
+		void left();
33
+		void right();
34
+		void select();
35
+		
36
+		
37
+		void addMenuItem(MenuItem*);
38
+		void render();
39
+};
40
+
41
+#endif

+ 8
- 0
glsdlscreen.cpp View File

@@ -119,3 +119,11 @@ bool GLSDLScreen::apply() {
119 119
 	
120 120
 	return true;
121 121
 }
122
+
123
+int GLSDLScreen::getWidth() {
124
+	return width;
125
+}
126
+
127
+int GLSDLScreen::getHeight() {
128
+	return height;
129
+}

+ 3
- 0
glsdlscreen.h View File

@@ -34,6 +34,9 @@ class GLSDLScreen {
34 34
 		
35 35
 		bool isOK();
36 36
 		bool apply();
37
+		
38
+		int getWidth();
39
+		int getHeight();
37 40
 };
38 41
 
39 42
 #endif

+ 132
- 0
punkt2d.cpp View File

@@ -0,0 +1,132 @@
1
+#include "punkt2d.h"
2
+
3
+Punkt2D::Punkt2D() {
4
+	x = y = 0.0f;
5
+}
6
+
7
+Punkt2D::Punkt2D(float _x, float _y) {
8
+	set(_x, _y);
9
+}
10
+
11
+void Punkt2D::set(float _x, float _y) {
12
+	x = _x;
13
+	y = _y;
14
+}
15
+
16
+void Punkt2D::print(std::string coordname) {
17
+	if(coordname!="")
18
+		coordname.append(" ");
19
+	std::cout << coordname << "Coord: (" << x << ", " << y << ")" << std::endl;
20
+}
21
+
22
+
23
+Punkt2D Punkt2D::operator+(const Punkt2D &b) {
24
+	Punkt2D c;
25
+	c.x =  x + b.x;
26
+	c.y =  y + b.y;
27
+// 	c.z =  z + b.z;
28
+	
29
+	return c;
30
+}
31
+
32
+Punkt2D Punkt2D::operator-(const Punkt2D &b) {
33
+	Punkt2D c;
34
+	c.x =  x - b.x;
35
+	c.y =  y - b.y;
36
+// 	c.z =  z - b.z;
37
+	
38
+	return c;
39
+}
40
+
41
+Punkt2D& Punkt2D::operator+=(const Punkt2D &b) {
42
+	x +=  b.x;
43
+	y +=  b.y;
44
+// 	z +=  b.z;
45
+	
46
+	return *this;
47
+}
48
+
49
+Punkt2D& Punkt2D::operator-=(const Punkt2D &b) {
50
+	x -=  b.x;
51
+	y -=  b.y;
52
+// 	z -=  b.z;
53
+	
54
+	return *this;
55
+}
56
+
57
+Punkt2D Punkt2D::operator+(const float &_m) {
58
+	return Punkt2D(x+_m, y+_m);
59
+}
60
+
61
+Punkt2D Punkt2D::operator-(const float &_m) {
62
+	return Punkt2D(x-_m, y-_m);
63
+}
64
+
65
+Punkt2D Punkt2D::operator*(const float &_m) {
66
+	return Punkt2D(x*_m, y*_m);
67
+}
68
+
69
+Punkt2D Punkt2D::operator/(const float &_m) {
70
+	return Punkt2D(x/_m, y/_m);
71
+}
72
+
73
+Punkt2D& Punkt2D::operator+=(const float &_m) {
74
+	x += _m;
75
+	y += _m;
76
+// 	z += _m;
77
+	return *this;
78
+}
79
+Punkt2D& Punkt2D::operator-=(const float &_m) {
80
+	x -= _m;
81
+	y -= _m;
82
+// 	z -= _m;
83
+	return *this;
84
+}
85
+Punkt2D& Punkt2D::operator*=(const float &_m) {
86
+	x *= _m;
87
+	y *= _m;
88
+// 	z *= _m;
89
+	return *this;
90
+}
91
+Punkt2D& Punkt2D::operator/=(const float &_m) {
92
+	x /= _m;
93
+	y /= _m;
94
+// 	z /= _m;
95
+	return *this;
96
+}
97
+
98
+float Punkt2D::operator*(const Punkt2D& _m) {
99
+	return x * _m.x + y * _m.y;
100
+}
101
+
102
+Punkt2D Punkt2D::operator-() {
103
+	return Punkt2D(-x, -y);
104
+}
105
+
106
+bool Punkt2D::operator==(const Punkt2D& b) {
107
+	return ( x==b.x && y==b.y);
108
+}
109
+bool Punkt2D::operator!=(const Punkt2D& b) {
110
+	return !(*this==b);
111
+}
112
+// Freunde
113
+
114
+Punkt2D operator+(const float& _m, const Punkt2D& b) {
115
+	return Punkt2D(b.x+_m, b.y+_m);
116
+}
117
+
118
+Punkt2D operator-(const float& _m, const Punkt2D& b) {
119
+	return Punkt2D(b.x-_m, b.y-_m);
120
+}
121
+
122
+Punkt2D operator*(const float& _m, const Punkt2D& b) {
123
+	return Punkt2D(b.x*_m, b.y*_m);
124
+}
125
+
126
+Punkt2D operator/(const float& _m, const Punkt2D& b) {
127
+	return Punkt2D(b.x/_m, b.y/_m);
128
+}
129
+
130
+// float abs(Punkt2D p) {
131
+// 	return p.abs();
132
+// }

+ 49
- 0
punkt2d.h View File

@@ -0,0 +1,49 @@
1
+#ifndef __PUNKT3D_H
2
+#define __PUNKT3D_H
3
+
4
+#include <iostream>
5
+#include <cmath>
6
+#include "emath.h"
7
+
8
+class Punkt2D {
9
+	public:
10
+		Punkt2D();
11
+		Punkt2D(float, float);
12
+		
13
+		float x, y;
14
+		
15
+		void set(float, float);
16
+		void print(std::string="");
17
+		
18
+		// Operatoren
19
+		Punkt2D operator+(const Punkt2D&);
20
+		Punkt2D operator-(const Punkt2D&);
21
+		Punkt2D& operator+=(const Punkt2D&);
22
+		Punkt2D& operator-=(const Punkt2D&);
23
+		
24
+		Punkt2D operator+(const float&);
25
+		Punkt2D operator-(const float&);
26
+		Punkt2D operator*(const float&);
27
+		Punkt2D operator/(const float&);
28
+		Punkt2D& operator+=(const float&);
29
+		Punkt2D& operator-=(const float&);
30
+		Punkt2D& operator*=(const float&);
31
+		Punkt2D& operator/=(const float&);
32
+		
33
+		float operator*(const Punkt2D&);
34
+		
35
+		Punkt2D operator-();
36
+		
37
+		bool operator==(const Punkt2D&);
38
+		bool operator!=(const Punkt2D&);
39
+		
40
+		friend Punkt2D operator+(const float&, const Punkt2D&);
41
+		friend Punkt2D operator-(const float&, const Punkt2D&);
42
+		friend Punkt2D operator*(const float&, const Punkt2D&);
43
+		friend Punkt2D operator/(const float&, const Punkt2D&);
44
+		
45
+};
46
+
47
+// float abs(Punkt3D);
48
+
49
+#endif

+ 207
- 0
punkt3d.cpp View File

@@ -0,0 +1,207 @@
1
+#include "punkt3d.h"
2
+
3
+Punkt3D::Punkt3D() {
4
+	x = y = z = 0.0f;
5
+}
6
+
7
+Punkt3D::Punkt3D(float _x, float _y, float _z) {
8
+	set(_x, _y, _z);
9
+}
10
+
11
+void Punkt3D::set(float _x, float _y, float _z) {
12
+	x = _x;
13
+	y = _y;
14
+	z = _z;
15
+}
16
+
17
+float Punkt3D::abs() {
18
+	return sqrt(x*x+y*y+z*z);
19
+}
20
+
21
+Punkt3D Punkt3D::kreuzprodukt(const Punkt3D &b) {
22
+	Punkt3D erg;
23
+	erg.x = y*b.z - z*b.y;
24
+	erg.y = z*b.x - x*b.z;
25
+	erg.z = x*b.y - y*b.x;
26
+	
27
+	return erg;
28
+}
29
+
30
+void Punkt3D::normalize() {
31
+	float a = abs();
32
+	x /= a;
33
+	y /= a;
34
+	z /= a;
35
+}
36
+
37
+Punkt3D Punkt3D::getNormalized() {
38
+	Punkt3D ret(*this);
39
+	ret.normalize();
40
+	return ret;
41
+}
42
+
43
+bool Punkt3D::isNormalized() {
44
+	return (abs()==1);
45
+}
46
+
47
+float Punkt3D::calcAngle(Punkt3D b) {
48
+	if(abs()*b.abs()==0.0f)
49
+		return 0.0f;
50
+	return rad2deg(std::acos(((*this)*b)/(abs()*b.abs())));
51
+}
52
+
53
+Punkt3D Punkt3D::getOrtographic() {
54
+	Punkt3D erg;
55
+	if(!x) {
56
+		erg.x = 0.0f;
57
+		erg.y = z;
58
+		erg.z = -y;
59
+	} else if(!y) {
60
+		erg.x = z;
61
+		erg.y = 0;
62
+		erg.z = -x;
63
+	} else {
64
+		// z, oder genereller fall
65
+		erg.x = y;
66
+		erg.y = -x;
67
+		erg.z = 0.0f;
68
+	}
69
+	return erg;
70
+}
71
+
72
+void Punkt3D::print(std::string coordname) {
73
+	if(coordname!="")
74
+		coordname.append(" ");
75
+	std::cout << coordname << "Coord: (" << x << ", " << y << ", " << z << ")" << std::endl;
76
+}
77
+
78
+
79
+
80
+Punkt3D Punkt3D::operator+(const Punkt3D &b) {
81
+	Punkt3D c;
82
+	c.x =  x + b.x;
83
+	c.y =  y + b.y;
84
+	c.z =  z + b.z;
85
+	
86
+	return c;
87
+}
88
+
89
+Punkt3D Punkt3D::operator-(const Punkt3D &b) {
90
+	Punkt3D c;
91
+	c.x =  x - b.x;
92
+	c.y =  y - b.y;
93
+	c.z =  z - b.z;
94
+	
95
+	return c;
96
+}
97
+
98
+Punkt3D& Punkt3D::operator+=(const Punkt3D &b) {
99
+	x +=  b.x;
100
+	y +=  b.y;
101
+	z +=  b.z;
102
+	
103
+	return *this;
104
+}
105
+
106
+Punkt3D& Punkt3D::operator-=(const Punkt3D &b) {
107
+	x -=  b.x;
108
+	y -=  b.y;
109
+	z -=  b.z;
110
+	
111
+	return *this;
112
+}
113
+
114
+Punkt3D Punkt3D::operator+(const float &_m) {
115
+	return Punkt3D(x+_m, y+_m, z+_m);
116
+}
117
+
118
+Punkt3D Punkt3D::operator-(const float &_m) {
119
+	return Punkt3D(x-_m, y-_m, z-_m);
120
+}
121
+
122
+Punkt3D Punkt3D::operator*(const float &_m) {
123
+	return Punkt3D(x*_m, y*_m, z*_m);
124
+}
125
+
126
+Punkt3D Punkt3D::operator/(const float &_m) {
127
+	return Punkt3D(x/_m, y/_m, z/_m);
128
+}
129
+
130
+Punkt3D& Punkt3D::operator+=(const float &_m) {
131
+	x += _m;
132
+	y += _m;
133
+	z += _m;
134
+	return *this;
135
+}
136
+Punkt3D& Punkt3D::operator-=(const float &_m) {
137
+	x -= _m;
138
+	y -= _m;
139
+	z -= _m;
140
+	return *this;
141
+}
142
+Punkt3D& Punkt3D::operator*=(const float &_m) {
143
+	x *= _m;
144
+	y *= _m;
145
+	z *= _m;
146
+	return *this;
147
+}
148
+Punkt3D& Punkt3D::operator/=(const float &_m) {
149
+	x /= _m;
150
+	y /= _m;
151
+	z /= _m;
152
+	return *this;
153
+}
154
+
155
+float Punkt3D::operator*(const Punkt3D& _m) {
156
+	return x * _m.x + y * _m.y + z * _m.z;
157
+}
158
+
159
+Punkt3D Punkt3D::operator-() {
160
+	return Punkt3D(-x, -y, -z);
161
+}
162
+
163
+bool Punkt3D::operator==(const Punkt3D& b) {
164
+	return ( x==b.x && y==b.y && z==b.z);
165
+}
166
+bool Punkt3D::operator!=(const Punkt3D& b) {
167
+	return !(*this==b);
168
+}
169
+// Freunde
170
+
171
+Punkt3D operator+(const float& _m, const Punkt3D& b) {
172
+	return Punkt3D(b.x+_m, b.y+_m, b.z+_m);
173
+}
174
+
175
+Punkt3D operator-(const float& _m, const Punkt3D& b) {
176
+	return Punkt3D(b.x-_m, b.y-_m, b.z-_m);
177
+}
178
+
179
+Punkt3D operator*(const float& _m, const Punkt3D& b) {
180
+	return Punkt3D(b.x*_m, b.y*_m, b.z*_m);
181
+}
182
+
183
+Punkt3D operator/(const float& _m, const Punkt3D& b) {
184
+	return Punkt3D(b.x/_m, b.y/_m, b.z/_m);
185
+}
186
+
187
+float abs(Punkt3D p) {
188
+	return p.abs();
189
+}
190
+
191
+// OpenGL Funktionen für Punkt3D
192
+
193
+void glVertex3f(Punkt3D p) {
194
+	glVertex3f(p.x, p.y, p.z);
195
+}
196
+
197
+void glTranslatef(Punkt3D p) {
198
+	glTranslatef(p.x, p.y, p.z);
199
+}
200
+
201
+void glNormal(Punkt3D p) {
202
+	glNormal3f(p.x, p.y, p.z);
203
+}
204
+
205
+void glRotatef(float deg, Punkt3D vec) {
206
+	glRotatef(deg, vec.x, vec.y, vec.z);
207
+}

+ 66
- 0
punkt3d.h View File

@@ -0,0 +1,66 @@
1
+#ifndef __PUNKT3D_h
2
+#define __PUNKT3D_h
3
+
4
+#include <iostream>
5
+#include <cmath>
6
+#include "emath.h"
7
+
8
+class Punkt3D {
9
+	public:
10
+		Punkt3D();
11
+		Punkt3D(float, float, float);
12
+		
13
+		float x, y, z;
14
+		
15
+		void set(float, float, float);
16
+		float abs();
17
+		Punkt3D kreuzprodukt(const Punkt3D&);
18
+		void normalize();
19
+		Punkt3D getNormalized();
20
+		bool isNormalized();
21
+		float calcAngle(Punkt3D);
22
+		Punkt3D getOrtographic();
23
+		
24
+		void print(std::string="");
25
+		
26
+		
27
+		// Operatoren
28
+		Punkt3D operator+(const Punkt3D&);
29
+		Punkt3D operator-(const Punkt3D&);
30
+		Punkt3D& operator+=(const Punkt3D&);
31
+		Punkt3D& operator-=(const Punkt3D&);
32
+		
33
+		Punkt3D operator+(const float&);
34
+		Punkt3D operator-(const float&);
35
+		Punkt3D operator*(const float&);
36
+		Punkt3D operator/(const float&);
37
+		Punkt3D& operator+=(const float&);
38
+		Punkt3D& operator-=(const float&);
39
+		Punkt3D& operator*=(const float&);
40
+		Punkt3D& operator/=(const float&);
41
+		
42
+		float operator*(const Punkt3D&);
43
+		
44
+		Punkt3D operator-();
45
+
46
+		bool operator==(const Punkt3D&);
47
+		bool operator!=(const Punkt3D&);
48
+		
49
+		friend Punkt3D operator+(const float&, const Punkt3D&);
50
+		friend Punkt3D operator-(const float&, const Punkt3D&);
51
+		friend Punkt3D operator*(const float&, const Punkt3D&);
52
+		friend Punkt3D operator/(const float&, const Punkt3D&);
53
+};
54
+
55
+float abs(Punkt3D);
56
+
57
+// OpenGL-Funktionen für Punkt3D
58
+
59
+void glVertex3f(Punkt3D);
60
+void glTranslatef(Punkt3D);
61
+void glNormal3f(Punkt3D);
62
+
63
+void glRotatef(float, Punkt3D);
64
+
65
+
66
+#endif

Loading…
Cancel
Save