diff --git a/Makefile b/Makefile index b038ac4..fa5622a 100755 --- a/Makefile +++ b/Makefile @@ -1,15 +1,19 @@ COMPILER = g++ -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 +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 +SUBDIRS = glgui glmenu +SUBDIROBJECTS = glgui/*.o glmenu/*.o VERSION = 0.0.1 LIBNAME = libsegl - -segllib: $(OBJECTS) - -seglar: $(OBJECTS) +seglar: $(OBJECTS) subdirs rm -f $(LIBNAME).a - ar rcs $(LIBNAME).a $(OBJECTS) + ar rcs $(LIBNAME).a $(OBJECTS) $(SUBDIROBJECTS) # ranlib $(LIBNAME).a + +segllib: $(OBJECTS) subdirs + +subdirs: + @for i in $(SUBDIRS); do $(MAKE) -C $$i; done %.o: %.cpp %.h $(COMPILER) -c `sdl-config --cflags` $< @@ -18,10 +22,14 @@ seglar: $(OBJECTS) glgui/glgui.a: cd glgui; $(MAKE); +glmenu/glmenu.a: + cd glmenu; $(MAKE); + testprog: seglar testprog.o g++ `sdl-config --libs` -lSDL_image -lGL -lGLU testprog.o -o testprog $(LIBNAME).a clean: rm -f $(OBJECTS) cd glgui; $(MAKE) clean + cd glmenu; $(MAKE) clean @echo Done cleaning... \ No newline at end of file diff --git a/emath.cpp b/emath.cpp index 70f4e97..3aada5f 100644 --- a/emath.cpp +++ b/emath.cpp @@ -1,211 +1,5 @@ #include "emath.h" -Punkt3D::Punkt3D() { - x = y = z = 0.0f; -} - -Punkt3D::Punkt3D(float _x, float _y, float _z) { - set(_x, _y, _z); -} - -void Punkt3D::set(float _x, float _y, float _z) { - x = _x; - y = _y; - z = _z; -} - -float Punkt3D::abs() { - return sqrt(x*x+y*y+z*z); -} - -Punkt3D Punkt3D::kreuzprodukt(const Punkt3D &b) { - Punkt3D erg; - erg.x = y*b.z - z*b.y; - erg.y = z*b.x - x*b.z; - erg.z = x*b.y - y*b.x; - - return erg; -} - -void Punkt3D::normalize() { - float a = abs(); - x /= a; - y /= a; - z /= a; -} - -Punkt3D Punkt3D::getNormalized() { - Punkt3D ret(*this); - ret.normalize(); - return ret; -} - -bool Punkt3D::isNormalized() { - return (abs()==1); -} - -float Punkt3D::calcAngle(Punkt3D b) { - if(abs()*b.abs()==0.0f) - return 0.0f; - return rad2deg(std::acos(((*this)*b)/(abs()*b.abs()))); -} - -Punkt3D Punkt3D::getOrtographic() { - Punkt3D erg; - if(!x) { - erg.x = 0.0f; - erg.y = z; - erg.z = -y; - } else if(!y) { - erg.x = z; - erg.y = 0; - erg.z = -x; - } else { - // z, oder genereller fall - erg.x = y; - erg.y = -x; - erg.z = 0.0f; - } - return erg; -} - -void Punkt3D::print(std::string coordname) { - if(coordname!="") - coordname.append(" "); - std::cout << coordname << "Coord: (" << x << ", " << y << ", " << z << ")" << std::endl; -} - - - -Punkt3D Punkt3D::operator+(const Punkt3D &b) { - Punkt3D c; - c.x = x + b.x; - c.y = y + b.y; - c.z = z + b.z; - - return c; -} - -Punkt3D Punkt3D::operator-(const Punkt3D &b) { - Punkt3D c; - c.x = x - b.x; - c.y = y - b.y; - c.z = z - b.z; - - return c; -} - -Punkt3D& Punkt3D::operator+=(const Punkt3D &b) { - x += b.x; - y += b.y; - z += b.z; - - return *this; -} - -Punkt3D& Punkt3D::operator-=(const Punkt3D &b) { - x -= b.x; - y -= b.y; - z -= b.z; - - return *this; -} - -Punkt3D Punkt3D::operator+(const float &_m) { - return Punkt3D(x+_m, y+_m, z+_m); -} - -Punkt3D Punkt3D::operator-(const float &_m) { - return Punkt3D(x-_m, y-_m, z-_m); -} - -Punkt3D Punkt3D::operator*(const float &_m) { - return Punkt3D(x*_m, y*_m, z*_m); -} - -Punkt3D Punkt3D::operator/(const float &_m) { - return Punkt3D(x/_m, y/_m, z/_m); -} - -Punkt3D& Punkt3D::operator+=(const float &_m) { - x += _m; - y += _m; - z += _m; - return *this; -} -Punkt3D& Punkt3D::operator-=(const float &_m) { - x -= _m; - y -= _m; - z -= _m; - return *this; -} -Punkt3D& Punkt3D::operator*=(const float &_m) { - x *= _m; - y *= _m; - z *= _m; - return *this; -} -Punkt3D& Punkt3D::operator/=(const float &_m) { - x /= _m; - y /= _m; - z /= _m; - return *this; -} - -float Punkt3D::operator*(const Punkt3D& _m) { - return x * _m.x + y * _m.y + z * _m.z; -} - -Punkt3D Punkt3D::operator-() { - return Punkt3D(-x, -y, -z); -} - -bool Punkt3D::operator==(const Punkt3D& b) { - return ( x==b.x && y==b.y && z==b.z); -} -bool Punkt3D::operator!=(const Punkt3D& b) { - return !(*this==b); -} -// Freunde - -Punkt3D operator+(const float& _m, const Punkt3D& b) { - return Punkt3D(b.x+_m, b.y+_m, b.z+_m); -} - -Punkt3D operator-(const float& _m, const Punkt3D& b) { - return Punkt3D(b.x-_m, b.y-_m, b.z-_m); -} - -Punkt3D operator*(const float& _m, const Punkt3D& b) { - return Punkt3D(b.x*_m, b.y*_m, b.z*_m); -} - -Punkt3D operator/(const float& _m, const Punkt3D& b) { - return Punkt3D(b.x/_m, b.y/_m, b.z/_m); -} - -float abs(Punkt3D p) { - return p.abs(); -} - -// OpenGL Funktionen für Punkt3D - -void glVertex3f(Punkt3D p) { - glVertex3f(p.x, p.y, p.z); -} - -void glTranslatef(Punkt3D p) { - glTranslatef(p.x, p.y, p.z); -} - -void glNormal(Punkt3D p) { - glNormal3f(p.x, p.y, p.z); -} - -void glRotatef(float deg, Punkt3D vec) { - glRotatef(deg, vec.x, vec.y, vec.z); -} - // Trigonometrische Funktionen float deg2rad(float deg) { diff --git a/emath.h b/emath.h index d230329..6a1a3c8 100644 --- a/emath.h +++ b/emath.h @@ -5,69 +5,14 @@ #include #include -class Punkt3D { - public: - Punkt3D(); - Punkt3D(float, float, float); - - float x, y, z; - - void set(float, float, float); - float abs(); - Punkt3D kreuzprodukt(const Punkt3D&); - void normalize(); - Punkt3D getNormalized(); - bool isNormalized(); - float calcAngle(Punkt3D); - Punkt3D getOrtographic(); - - void print(std::string=""); - - - // Operatoren - Punkt3D operator+(const Punkt3D&); - Punkt3D operator-(const Punkt3D&); - Punkt3D& operator+=(const Punkt3D&); - Punkt3D& operator-=(const Punkt3D&); - - Punkt3D operator+(const float&); - Punkt3D operator-(const float&); - Punkt3D operator*(const float&); - Punkt3D operator/(const float&); - Punkt3D& operator+=(const float&); - Punkt3D& operator-=(const float&); - Punkt3D& operator*=(const float&); - Punkt3D& operator/=(const float&); - - float operator*(const Punkt3D&); - - Punkt3D operator-(); - - bool operator==(const Punkt3D&); - bool operator!=(const Punkt3D&); - - friend Punkt3D operator+(const float&, const Punkt3D&); - friend Punkt3D operator-(const float&, const Punkt3D&); - friend Punkt3D operator*(const float&, const Punkt3D&); - friend Punkt3D operator/(const float&, const Punkt3D&); -}; - -float abs(Punkt3D); - -// OpenGL-Funktionen für Punkt3D - -void glVertex3f(Punkt3D); -void glTranslatef(Punkt3D); -void glNormal3f(Punkt3D); - -void glRotatef(float, Punkt3D); +#include "punkt3d.h" /* aus kompatibilitätsgründen */ float deg2rad(float deg); float rad2deg(float rad); - - // *grml* scheiss cmath-sinus +// diese beiden sinusfunktionenrechnen erst deg2rad +// wenn es sich nicht um 0, 90, 180, 270 oder ein vielfaches handelt float ssin(float); float scos(float); diff --git a/glfontengine.cpp b/glfontengine.cpp index 80ccb48..d00cf7a 100644 --- a/glfontengine.cpp +++ b/glfontengine.cpp @@ -94,7 +94,8 @@ bool GLFontEngine::fontSelect(std::string fontstr) { font = fontpool[fontstr]; else { //fallbackfont - ersten aus der liste - font = (fontpool.begin())->second; + font = (++fontpool.begin())->second; + std::cout << "font: " << font << std::endl; } return true; @@ -106,7 +107,7 @@ void GLFontEngine::renderText(std::string text, SDL_Rect pos) { void GLFontEngine::renderLine(std::string text, SDL_Rect pos) { // glColor4f(r, g, b, a); - + glMatrixMode(GL_TEXTURE); glLoadIdentity(); glMatrixMode(GL_MODELVIEW); @@ -123,7 +124,7 @@ void GLFontEngine::renderLine(std::string text, SDL_Rect pos) { for(unsigned int i=0; icharwidth*fsize); + if(fontloaded) + return (int)(moep.length()*(font->charwidth*fsize)); + else + return 1; } std::map GLFontEngine::fontpool; diff --git a/glgui/glgui.h b/glgui/glgui.h new file mode 100644 index 0000000..e69de29 diff --git a/glgui/window.cpp b/glgui/window.cpp index 0cc3e2f..d58fa31 100644 --- a/glgui/window.cpp +++ b/glgui/window.cpp @@ -33,7 +33,8 @@ SDL_Rect GLGuiWindow::getPos() { } GLGuiWindow::~GLGuiWindow() { - for(unsigned int i=0; i +#include "../glfontengine.h" +#include "../punkt2d.h" + +class MenuItem { + protected: + std::string caption; + std::string value; + + GLFontEngine fontengine; + std::string fontname; + int fontsizeadd; + + bool usevalue; + public: + MenuItem(std::string); + virtual ~MenuItem(); + + virtual void left() { }; + virtual void right() { }; + virtual void select() { }; + int getFontSizeAdd(); + + virtual void render(Punkt2D pos, bool center, int basefontsize, int maxwidth, int valuewidth, bool highlight); +}; + +#endif diff --git a/glmenu/menuitems.cpp b/glmenu/menuitems.cpp new file mode 100644 index 0000000..b288ffb --- /dev/null +++ b/glmenu/menuitems.cpp @@ -0,0 +1,9 @@ +#include "menuitems.h" + +MISendSDLEvent::MISendSDLEvent(std::string str, SDL_Event event) : MenuItem(str) { + sendevent = event; +} + +void MISendSDLEvent::select() { + SDL_PushEvent(&sendevent); +} diff --git a/glmenu/menuitems.h b/glmenu/menuitems.h new file mode 100644 index 0000000..3c4b361 --- /dev/null +++ b/glmenu/menuitems.h @@ -0,0 +1,17 @@ +#ifndef __MENUITEMS_H +#define __MENUITEMS_H + +#include +#include "menuitem.h" + +class MISendSDLEvent : public MenuItem { + private: + SDL_Event sendevent; + public: + MISendSDLEvent(std::string str, SDL_Event event); + + void select(); +}; + + +#endif diff --git a/glmenu/menumanager.cpp b/glmenu/menumanager.cpp new file mode 100644 index 0000000..3551ab7 --- /dev/null +++ b/glmenu/menumanager.cpp @@ -0,0 +1,54 @@ +#include "menumanager.h" + +MenuManager::MenuManager() { + aktuell = 0; +} + +void MenuManager::addMenu(MenuMenu *mm) { + menus.push_back(mm); + if(menus.size()==1) + aktuell = mm; +} + +bool MenuManager::changeMenu(MenuMenu *mm) { + for(unsigned int i=0; irender(); + GLFontEngine::regain3DbyPoppingMatrix(); +} + +void MenuManager::up() { + if(aktuell) + aktuell->up(); +} + +void MenuManager::down() { + if(aktuell) + aktuell->down(); +} + +void MenuManager::left() { + if(aktuell) + aktuell->left(); +} + +void MenuManager::right() { + if(aktuell) + aktuell->right(); +} + +void MenuManager::select() { + if(aktuell) + aktuell->select(); +} diff --git a/glmenu/menumanager.h b/glmenu/menumanager.h new file mode 100644 index 0000000..5c3fff9 --- /dev/null +++ b/glmenu/menumanager.h @@ -0,0 +1,29 @@ +#ifndef __MENUMANAGER_H +#define __MENUMANAGER_H + +#include + +#include "../glfontengine.h" +#include "menumenu.h" + + +class MenuManager { + private: + MenuMenu *aktuell; + + std::vector menus; + public: + MenuManager(); + + void addMenu(MenuMenu*); + bool changeMenu(MenuMenu*); + void render(); + + void up(); + void down(); + void left(); + void right(); + void select(); +}; + +#endif diff --git a/glmenu/menumenu.cpp b/glmenu/menumenu.cpp new file mode 100644 index 0000000..34c3867 --- /dev/null +++ b/glmenu/menumenu.cpp @@ -0,0 +1,76 @@ +#include "menumenu.h" + +MenuMenu::MenuMenu() { + itempos = 0; + centermenu = false; + centerScreenX = false; + basefontsize = 20; + maxwidth = 0; + valuewidth = 100; + offset = 20; +} + +void MenuMenu::setPos(const Punkt2D &p) { + menupos = p; +} + +void MenuMenu::setCenter(bool _c) { + centermenu = _c; +} + +void MenuMenu::setCenterScreenX(bool _c) { + centerScreenX = _c; +} + +void MenuMenu::setBaseFontSize(int _bfs) { + if(_bfs>0) + basefontsize = _bfs; +} + +void MenuMenu::setMaxWidth(int _mw) { + if(_mw>0) + maxwidth = _mw; +} + +void MenuMenu::addMenuItem(MenuItem* mi) { + menuitems.push_back(mi); +} + +void MenuMenu::up() { + if(itempos==0) + itempos = menuitems.size()-1; + else + itempos--; +} + +void MenuMenu::down() { + if(itempos==menuitems.size()-1) + itempos = 0; + else + itempos++; +} + +void MenuMenu::left() { + menuitems[itempos]->left(); +} + +void MenuMenu::right() { + menuitems[itempos]->right(); +} + +void MenuMenu::select() { + menuitems[itempos]->select(); +} + +void MenuMenu::render() { + Punkt2D pos = menupos; + if(centerScreenX) { + SDL_Surface *screen = SDL_GetVideoSurface(); + pos.x = screen->w/2; + } + + for(unsigned int i=0; irender(pos, centermenu, basefontsize, maxwidth, valuewidth, itempos==i); + pos.y += basefontsize + menuitems[i]->getFontSizeAdd() + offset; + } +} diff --git a/glmenu/menumenu.h b/glmenu/menumenu.h new file mode 100644 index 0000000..1d94417 --- /dev/null +++ b/glmenu/menumenu.h @@ -0,0 +1,41 @@ +#ifndef __MENUMENU_H +#define __MENUMENU_H + +#include +#include +#include "../punkt2d.h" +#include "menuitem.h" + +class MenuMenu { + private: + std::vector menuitems; + + int itempos; + Punkt2D menupos; + bool centermenu; + bool centerScreenX; + int basefontsize; + int offset; + int maxwidth; + int valuewidth; + public: + MenuMenu(); + + void setPos(const Punkt2D&); + void setCenter(bool); + void setCenterScreenX(bool); + void setBaseFontSize(int); + void setMaxWidth(int); + + void up(); + void down(); + void left(); + void right(); + void select(); + + + void addMenuItem(MenuItem*); + void render(); +}; + +#endif diff --git a/glsdlscreen.cpp b/glsdlscreen.cpp index d305fa6..c48670f 100644 --- a/glsdlscreen.cpp +++ b/glsdlscreen.cpp @@ -119,3 +119,11 @@ bool GLSDLScreen::apply() { return true; } + +int GLSDLScreen::getWidth() { + return width; +} + +int GLSDLScreen::getHeight() { + return height; +} diff --git a/glsdlscreen.h b/glsdlscreen.h index 132492a..dca61f5 100644 --- a/glsdlscreen.h +++ b/glsdlscreen.h @@ -34,6 +34,9 @@ class GLSDLScreen { bool isOK(); bool apply(); + + int getWidth(); + int getHeight(); }; #endif diff --git a/punkt2d.cpp b/punkt2d.cpp new file mode 100644 index 0000000..760d310 --- /dev/null +++ b/punkt2d.cpp @@ -0,0 +1,132 @@ +#include "punkt2d.h" + +Punkt2D::Punkt2D() { + x = y = 0.0f; +} + +Punkt2D::Punkt2D(float _x, float _y) { + set(_x, _y); +} + +void Punkt2D::set(float _x, float _y) { + x = _x; + y = _y; +} + +void Punkt2D::print(std::string coordname) { + if(coordname!="") + coordname.append(" "); + std::cout << coordname << "Coord: (" << x << ", " << y << ")" << std::endl; +} + + +Punkt2D Punkt2D::operator+(const Punkt2D &b) { + Punkt2D c; + c.x = x + b.x; + c.y = y + b.y; +// c.z = z + b.z; + + return c; +} + +Punkt2D Punkt2D::operator-(const Punkt2D &b) { + Punkt2D c; + c.x = x - b.x; + c.y = y - b.y; +// c.z = z - b.z; + + return c; +} + +Punkt2D& Punkt2D::operator+=(const Punkt2D &b) { + x += b.x; + y += b.y; +// z += b.z; + + return *this; +} + +Punkt2D& Punkt2D::operator-=(const Punkt2D &b) { + x -= b.x; + y -= b.y; +// z -= b.z; + + return *this; +} + +Punkt2D Punkt2D::operator+(const float &_m) { + return Punkt2D(x+_m, y+_m); +} + +Punkt2D Punkt2D::operator-(const float &_m) { + return Punkt2D(x-_m, y-_m); +} + +Punkt2D Punkt2D::operator*(const float &_m) { + return Punkt2D(x*_m, y*_m); +} + +Punkt2D Punkt2D::operator/(const float &_m) { + return Punkt2D(x/_m, y/_m); +} + +Punkt2D& Punkt2D::operator+=(const float &_m) { + x += _m; + y += _m; +// z += _m; + return *this; +} +Punkt2D& Punkt2D::operator-=(const float &_m) { + x -= _m; + y -= _m; +// z -= _m; + return *this; +} +Punkt2D& Punkt2D::operator*=(const float &_m) { + x *= _m; + y *= _m; +// z *= _m; + return *this; +} +Punkt2D& Punkt2D::operator/=(const float &_m) { + x /= _m; + y /= _m; +// z /= _m; + return *this; +} + +float Punkt2D::operator*(const Punkt2D& _m) { + return x * _m.x + y * _m.y; +} + +Punkt2D Punkt2D::operator-() { + return Punkt2D(-x, -y); +} + +bool Punkt2D::operator==(const Punkt2D& b) { + return ( x==b.x && y==b.y); +} +bool Punkt2D::operator!=(const Punkt2D& b) { + return !(*this==b); +} +// Freunde + +Punkt2D operator+(const float& _m, const Punkt2D& b) { + return Punkt2D(b.x+_m, b.y+_m); +} + +Punkt2D operator-(const float& _m, const Punkt2D& b) { + return Punkt2D(b.x-_m, b.y-_m); +} + +Punkt2D operator*(const float& _m, const Punkt2D& b) { + return Punkt2D(b.x*_m, b.y*_m); +} + +Punkt2D operator/(const float& _m, const Punkt2D& b) { + return Punkt2D(b.x/_m, b.y/_m); +} + +// float abs(Punkt2D p) { +// return p.abs(); +// } diff --git a/punkt2d.h b/punkt2d.h new file mode 100644 index 0000000..71778af --- /dev/null +++ b/punkt2d.h @@ -0,0 +1,49 @@ +#ifndef __PUNKT3D_H +#define __PUNKT3D_H + +#include +#include +#include "emath.h" + +class Punkt2D { + public: + Punkt2D(); + Punkt2D(float, float); + + float x, y; + + void set(float, float); + void print(std::string=""); + + // Operatoren + Punkt2D operator+(const Punkt2D&); + Punkt2D operator-(const Punkt2D&); + Punkt2D& operator+=(const Punkt2D&); + Punkt2D& operator-=(const Punkt2D&); + + Punkt2D operator+(const float&); + Punkt2D operator-(const float&); + Punkt2D operator*(const float&); + Punkt2D operator/(const float&); + Punkt2D& operator+=(const float&); + Punkt2D& operator-=(const float&); + Punkt2D& operator*=(const float&); + Punkt2D& operator/=(const float&); + + float operator*(const Punkt2D&); + + Punkt2D operator-(); + + bool operator==(const Punkt2D&); + bool operator!=(const Punkt2D&); + + friend Punkt2D operator+(const float&, const Punkt2D&); + friend Punkt2D operator-(const float&, const Punkt2D&); + friend Punkt2D operator*(const float&, const Punkt2D&); + friend Punkt2D operator/(const float&, const Punkt2D&); + +}; + +// float abs(Punkt3D); + +#endif diff --git a/punkt3d.cpp b/punkt3d.cpp new file mode 100644 index 0000000..1c2b8a8 --- /dev/null +++ b/punkt3d.cpp @@ -0,0 +1,207 @@ +#include "punkt3d.h" + +Punkt3D::Punkt3D() { + x = y = z = 0.0f; +} + +Punkt3D::Punkt3D(float _x, float _y, float _z) { + set(_x, _y, _z); +} + +void Punkt3D::set(float _x, float _y, float _z) { + x = _x; + y = _y; + z = _z; +} + +float Punkt3D::abs() { + return sqrt(x*x+y*y+z*z); +} + +Punkt3D Punkt3D::kreuzprodukt(const Punkt3D &b) { + Punkt3D erg; + erg.x = y*b.z - z*b.y; + erg.y = z*b.x - x*b.z; + erg.z = x*b.y - y*b.x; + + return erg; +} + +void Punkt3D::normalize() { + float a = abs(); + x /= a; + y /= a; + z /= a; +} + +Punkt3D Punkt3D::getNormalized() { + Punkt3D ret(*this); + ret.normalize(); + return ret; +} + +bool Punkt3D::isNormalized() { + return (abs()==1); +} + +float Punkt3D::calcAngle(Punkt3D b) { + if(abs()*b.abs()==0.0f) + return 0.0f; + return rad2deg(std::acos(((*this)*b)/(abs()*b.abs()))); +} + +Punkt3D Punkt3D::getOrtographic() { + Punkt3D erg; + if(!x) { + erg.x = 0.0f; + erg.y = z; + erg.z = -y; + } else if(!y) { + erg.x = z; + erg.y = 0; + erg.z = -x; + } else { + // z, oder genereller fall + erg.x = y; + erg.y = -x; + erg.z = 0.0f; + } + return erg; +} + +void Punkt3D::print(std::string coordname) { + if(coordname!="") + coordname.append(" "); + std::cout << coordname << "Coord: (" << x << ", " << y << ", " << z << ")" << std::endl; +} + + + +Punkt3D Punkt3D::operator+(const Punkt3D &b) { + Punkt3D c; + c.x = x + b.x; + c.y = y + b.y; + c.z = z + b.z; + + return c; +} + +Punkt3D Punkt3D::operator-(const Punkt3D &b) { + Punkt3D c; + c.x = x - b.x; + c.y = y - b.y; + c.z = z - b.z; + + return c; +} + +Punkt3D& Punkt3D::operator+=(const Punkt3D &b) { + x += b.x; + y += b.y; + z += b.z; + + return *this; +} + +Punkt3D& Punkt3D::operator-=(const Punkt3D &b) { + x -= b.x; + y -= b.y; + z -= b.z; + + return *this; +} + +Punkt3D Punkt3D::operator+(const float &_m) { + return Punkt3D(x+_m, y+_m, z+_m); +} + +Punkt3D Punkt3D::operator-(const float &_m) { + return Punkt3D(x-_m, y-_m, z-_m); +} + +Punkt3D Punkt3D::operator*(const float &_m) { + return Punkt3D(x*_m, y*_m, z*_m); +} + +Punkt3D Punkt3D::operator/(const float &_m) { + return Punkt3D(x/_m, y/_m, z/_m); +} + +Punkt3D& Punkt3D::operator+=(const float &_m) { + x += _m; + y += _m; + z += _m; + return *this; +} +Punkt3D& Punkt3D::operator-=(const float &_m) { + x -= _m; + y -= _m; + z -= _m; + return *this; +} +Punkt3D& Punkt3D::operator*=(const float &_m) { + x *= _m; + y *= _m; + z *= _m; + return *this; +} +Punkt3D& Punkt3D::operator/=(const float &_m) { + x /= _m; + y /= _m; + z /= _m; + return *this; +} + +float Punkt3D::operator*(const Punkt3D& _m) { + return x * _m.x + y * _m.y + z * _m.z; +} + +Punkt3D Punkt3D::operator-() { + return Punkt3D(-x, -y, -z); +} + +bool Punkt3D::operator==(const Punkt3D& b) { + return ( x==b.x && y==b.y && z==b.z); +} +bool Punkt3D::operator!=(const Punkt3D& b) { + return !(*this==b); +} +// Freunde + +Punkt3D operator+(const float& _m, const Punkt3D& b) { + return Punkt3D(b.x+_m, b.y+_m, b.z+_m); +} + +Punkt3D operator-(const float& _m, const Punkt3D& b) { + return Punkt3D(b.x-_m, b.y-_m, b.z-_m); +} + +Punkt3D operator*(const float& _m, const Punkt3D& b) { + return Punkt3D(b.x*_m, b.y*_m, b.z*_m); +} + +Punkt3D operator/(const float& _m, const Punkt3D& b) { + return Punkt3D(b.x/_m, b.y/_m, b.z/_m); +} + +float abs(Punkt3D p) { + return p.abs(); +} + +// OpenGL Funktionen für Punkt3D + +void glVertex3f(Punkt3D p) { + glVertex3f(p.x, p.y, p.z); +} + +void glTranslatef(Punkt3D p) { + glTranslatef(p.x, p.y, p.z); +} + +void glNormal(Punkt3D p) { + glNormal3f(p.x, p.y, p.z); +} + +void glRotatef(float deg, Punkt3D vec) { + glRotatef(deg, vec.x, vec.y, vec.z); +} diff --git a/punkt3d.h b/punkt3d.h new file mode 100644 index 0000000..730c0a9 --- /dev/null +++ b/punkt3d.h @@ -0,0 +1,66 @@ +#ifndef __PUNKT3D_h +#define __PUNKT3D_h + +#include +#include +#include "emath.h" + +class Punkt3D { + public: + Punkt3D(); + Punkt3D(float, float, float); + + float x, y, z; + + void set(float, float, float); + float abs(); + Punkt3D kreuzprodukt(const Punkt3D&); + void normalize(); + Punkt3D getNormalized(); + bool isNormalized(); + float calcAngle(Punkt3D); + Punkt3D getOrtographic(); + + void print(std::string=""); + + + // Operatoren + Punkt3D operator+(const Punkt3D&); + Punkt3D operator-(const Punkt3D&); + Punkt3D& operator+=(const Punkt3D&); + Punkt3D& operator-=(const Punkt3D&); + + Punkt3D operator+(const float&); + Punkt3D operator-(const float&); + Punkt3D operator*(const float&); + Punkt3D operator/(const float&); + Punkt3D& operator+=(const float&); + Punkt3D& operator-=(const float&); + Punkt3D& operator*=(const float&); + Punkt3D& operator/=(const float&); + + float operator*(const Punkt3D&); + + Punkt3D operator-(); + + bool operator==(const Punkt3D&); + bool operator!=(const Punkt3D&); + + friend Punkt3D operator+(const float&, const Punkt3D&); + friend Punkt3D operator-(const float&, const Punkt3D&); + friend Punkt3D operator*(const float&, const Punkt3D&); + friend Punkt3D operator/(const float&, const Punkt3D&); +}; + +float abs(Punkt3D); + +// OpenGL-Funktionen für Punkt3D + +void glVertex3f(Punkt3D); +void glTranslatef(Punkt3D); +void glNormal3f(Punkt3D); + +void glRotatef(float, Punkt3D); + + +#endif