Versionskram

Neue Geotypen
master
seba 16 年之前
父節點 393f1c9a65
當前提交 12d677afdb

@ -1,8 +1,8 @@
CC = g++
AR = ar
OBJECTS = punkt3d.o punkt2d.o emath.o emath_opengl.o color.o gldrawhelper.o glfontengine.o rect.o gltexture.o matrix.o quaternion.o rotationsmatrix.o glsdlscreen.o sdlfuncs.o fpsmanager.o glcamera.o catmullromspline.o extstring.o quader.o
OBJOPT = -Wall -c -DVERSION=$(VERSION) -O2 `sdl-config --cflags`
WINOPT = -Wall -c -DVERSION=$(VERSION) -O2 -I/usr/i586-mingw32msvc/include -I/usr/i586-mingw32msvc/include/SDL
OBJECTS = segl.o punkt3d.o punkt2d.o emath.o emath_opengl.o color.o gldrawhelper.o glfontengine.o rect.o gltexture.o matrix.o quaternion.o rotationsmatrix.o glsdlscreen.o sdlfuncs.o fpsmanager.o glcamera.o catmullromspline.o extstring.o quader.o geotypes.o
OBJOPT = -Wall -c -DVERSION=\"$(VERSION)\" -O2 `sdl-config --cflags`
WINOPT = -Wall -c -DVERSION=\"$(VERSION)\" -O2 -I/usr/i586-mingw32msvc/include -I/usr/i586-mingw32msvc/include/SDL
LIBLINK = -lc -shared -Wl,-soname,$(LIBNAME).so.$(LIBVERSION)
WINLINK = -L/usr/i586-mingw32msvc/lib /usr/i586-mingw32msvc/lib/SDL_image.lib -lmingw32 -shared -mwindows -lGL -lGLU -lSDL -lSDL_image /usr/i586-mingw32msvc/lib/SDL_image.lib /usr/i586-mingw32msvc/lib/SDL_image.dll
SUBDIRS = glgui glmenu model
@ -14,6 +14,8 @@ EXT = so.$(LIBVERSION)
.PHONY: windows
all: seglar lib
seglar: $(OBJECTS) subdirs
rm -f $(LIBNAME).a
$(AR) rcs $(LIBNAME).a $(OBJECTS) $(SUBDIROBJECTS)

@ -11,7 +11,7 @@ FPSManager::FPSManager(int _fps) {
void FPSManager::setFPS(int _fps) {
if(_fps<1 || _fps > 500)
return;
return;
tickrate = 1000.0f/(float)_fps;
}

@ -11,20 +11,28 @@ Sphere::Sphere() {
radius = 1.0f;
}
bool Sphere::collision(const Sphere &s) {
bool Sphere::collision(const Sphere &s) const {
return ((pos-s.pos)*(pos-s.pos))<((radius+s.radius)*(radius+s.radius));
}
bool Sphere::collision(const Ray &r) {
bool Sphere::collision(const Ray &r) const {
return true;
}
bool Sphere::collision(const Box & b) {
bool Sphere::collision(const Box & b) const {
return true;
}
bool Sphere::collision(const Plane &p) const {
return true;
}
bool Sphere::collision(const Plane &p) {
bool Sphere::inSphere(Punkt3D p) const {
return abs(pos-p)<=radius;
}
Punkt3D Sphere::getPos() const {
return pos;
}
Ray::Ray() {
@ -32,17 +40,96 @@ Ray::Ray() {
}
Ray::Ray(Punkt3D _pos, Punkt3D _dir) {
set(_pos, _dir);
}
void Ray::set(Punkt3D _pos, Punkt3D _dir) {
pos = _pos;
dir = _dir;
}
bool Ray::collision(const Sphere &s) {
Punkt3D Ray::get(float x) {
return pos + dir*x;
}
// TODO: Heavy Testing
bool Ray::onRay(Punkt3D p, int rnd) {
float r1 = 0.0f, r2 = 0.0f, r3 = 0.0f;
short fcount = 0;
bool g1=true, g2=true, g3=true;
Punkt3D f = p-pos;
if(dir.x==0.0f) {
if(f.x!=0.0f)
return false;
g1 = false;
fcount++;
} else
r1 = f.x / dir.x;
if(dir.y==0.0f) {
if(f.y!=0.0f)
return false;
g2 = false;
fcount++;
} else
r2 = f.y / dir.y;
if(dir.z==0.0f) {
if(f.z!=0.0f)
return false;
g2 = false;
fcount++;
} else
r2 = f.z / dir.z;
if(fcount>=2)
return true;
if(rnd>=0) {
// TODO:Implement rounding
// r1 = round(r1, rnd);
// r2 = round(r2, rnd);
// r3 = round(r3, rnd);
}
if(g1)
return (r2 == r3);
else if(g2)
return (r1 == r3);
else if(g3)
return (r1 == r2);
else
return (r1 == r2 == r3);
}
float Ray::dist(Punkt3D p) {
return abs(p - get( getParam(p) ));
}
float Ray::getParam(Punkt3D p, bool onray) {
if(onray) {
if(!onRay(p))
return 0.0f;
}
return -((pos-p)*dir) / (dir*dir);
}
bool Ray::collision(const Sphere &s) const {
return s.collision(*this);
}
bool Ray::collision(const Ray &r);
bool Ray::collision(const Box & b);
bool Ray::collision(const Plane &p);
bool Ray::collision(const Ray &r) const {
return true;
}
bool Ray::collision(const Box & b) const {
return true;
}
bool Ray::collision(const Plane &p) const {
return true;
}
Box::Box() {
max.set(1.0f, 1.0f, 1.0f);
@ -53,20 +140,20 @@ Box::Box(Punkt3D _min, Punkt3D _max) {
max = _max;
}
bool Box::collision(const Sphere &s) {
bool Box::collision(const Sphere &s) const {
return s.collision(*this);
}
bool Box::collision(const Ray &r) {
bool Box::collision(const Ray &r) const {
return r.collision(*this);
}
bool Box::collision(const Box & b) {
bool Box::collision(const Box & b) const {
return true;
}
bool Box::collision(const Plane &p) {
bool Box::collision(const Plane &p) const {
return true;
}
Plane::Plane() {
@ -84,20 +171,24 @@ Plane::Plane(float x, float y, float z, float a) {
norm.normalize();
}
bool Plane::collision(const Sphere &s) {
bool Plane::collision(const Sphere &s) const {
return s.collision(*this);
}
bool Plane::collision(const Ray &r) {
bool Plane::collision(const Ray &r) const {
return r.collision(*this);
}
bool Plane::collision(const Box & b) {
bool Plane::collision(const Box & b) const {
return b.collision(*this);
}
bool Plane::collision(const Plane &p) {
bool Plane::collision(const Plane &p) const {
return true;
}
float Plane::dist(Punkt3D p) const {
}
} // namespace segl

@ -6,7 +6,7 @@
namespace segl {
class Ray;
class Box
class Box;
class Plane;
@ -18,10 +18,13 @@ class Sphere {
Sphere(Punkt3D _pos, float radius);
Sphere();
bool collision(const Sphere &s);
bool collision(const Ray &r);
bool collision(const Box & b);
bool collision(const Plane &p);
bool collision(const Sphere &s) const;
bool collision(const Ray &r) const;
bool collision(const Box & b) const;
bool collision(const Plane &p) const;
bool inSphere(Punkt3D p) const;
Punkt3D getPos() const;
};
class Ray {
@ -32,10 +35,16 @@ class Ray {
Ray();
Ray(Punkt3D _pos, Punkt3D _dir);
bool collision(const Sphere &s);
bool collision(const Ray &r);
bool collision(const Box & b);
bool collision(const Plane &p);
void set(Punkt3D _pos, Punkt3D _dir);
Punkt3D get(float x);
bool onRay(Punkt3D p, int rnd=-1);
float dist(Punkt3D p);
float getParam(Punkt3D p, bool onray=false);
bool collision(const Sphere &s) const;
bool collision(const Ray &r) const;
bool collision(const Box & b) const;
bool collision(const Plane &p) const;
};
class Box {
@ -46,10 +55,10 @@ class Box {
Box();
Box(Punkt3D _min, Punkt3D _max);
bool collision(const Sphere &s);
bool collision(const Ray &r);
bool collision(const Box & b);
bool collision(const Plane &p);
bool collision(const Sphere &s) const;
bool collision(const Ray &r) const;
bool collision(const Box & b) const;
bool collision(const Plane &p) const;
};
class Plane {
@ -61,10 +70,14 @@ class Plane {
Plane(Punkt3D _pos, Punkt3D _norm);
Plane(float x, float y, float z, float a);
bool collision(const Sphere &s);
bool collision(const Ray &r);
bool collision(const Box & b);
bool collision(const Plane &p);
bool collision(const Sphere &s) const;
bool collision(const Ray &r) const;
bool collision(const Box & b) const;
bool collision(const Plane &p) const;
float dist(Punkt3D p) const;
};
} // namespace segl
#endif

@ -3,8 +3,8 @@
#include <iostream>
#include <string>
#include <SDL/SDL.h>
#include <SDL/SDL_opengl.h>
#include <SDL.h>
#include <SDL_opengl.h>
#include "textlabel.h"

@ -3,8 +3,8 @@
#include <iostream>
#include <string>
#include <SDL/SDL.h>
#include <SDL/SDL_opengl.h>
#include <SDL.h>
#include <SDL_opengl.h>
class GLGuiObject {
protected:

@ -3,8 +3,8 @@
#include <iostream>
#include <string>
#include <SDL/SDL.h>
#include <SDL/SDL_opengl.h>
#include <SDL.h>
#include <SDL_opengl.h>
#include "object.h"
#include "../color.h"

@ -4,8 +4,8 @@
#include <iostream>
#include <string>
#include <vector>
#include <SDL/SDL.h>
#include <SDL/SDL_opengl.h>
#include <SDL.h>
#include <SDL_opengl.h>
#include "../color.h"
#include "../gldrawhelper.h"

@ -216,7 +216,7 @@ bool LoadOBJ::load(Model *m) {
minz = std::min(minz, m->meshdata[i].z);
maxz = std::max(maxz, m->meshdata[i].z);
}
std::cout << "(" << minx << ", " << maxx << ") " << "(" << miny << ", " << maxy << ") " << "(" << minz << ", " << maxz << ") " << std::endl;
// std::cout << "(" << minx << ", " << maxx << ") " << "(" << miny << ", " << maxy << ") " << "(" << minz << ", " << maxz << ") " << std::endl;
m->boundingbox.d.set(minx, miny, minz);
m->boundingbox.a.set(minx, miny, maxz);
m->boundingbox.b.set(maxx, miny, maxz);

@ -25,6 +25,18 @@ float Punkt2D::abs() {
return sqrt(x*x + y*y);
}
void Punkt2D::normalize() {
float a = abs();
x /= a;
y /= a;
}
Punkt2D Punkt2D::getNormalized() const {
Punkt2D ret(*this);
ret.normalize();
return ret;
}
Punkt2D Punkt2D::operator+(const Punkt2D &b) {
Punkt2D c;
c.x = x + b.x;

@ -18,6 +18,9 @@ class Punkt2D {
void print(std::string="");
float abs();
void normalize();
Punkt2D getNormalized() const;
// Operatoren
Punkt2D operator+(const Punkt2D&);
Punkt2D operator-(const Punkt2D&);

@ -16,11 +16,11 @@ void Punkt3D::set(float _x, float _y, float _z) {
z = _z;
}
float Punkt3D::abs() {
float Punkt3D::abs() const {
return sqrt(x*x+y*y+z*z);
}
Punkt3D Punkt3D::kreuzprodukt(const Punkt3D &b) {
Punkt3D Punkt3D::kreuzprodukt(const Punkt3D &b) const {
Punkt3D erg;
erg.x = y*b.z - z*b.y;
erg.y = z*b.x - x*b.z;
@ -36,23 +36,23 @@ void Punkt3D::normalize() {
z /= a;
}
Punkt3D Punkt3D::getNormalized() {
Punkt3D Punkt3D::getNormalized() const {
Punkt3D ret(*this);
ret.normalize();
return ret;
}
bool Punkt3D::isNormalized() {
return (abs()==1);
bool Punkt3D::isNormalized() const {
return (abs()==1.0f);
}
float Punkt3D::calcAngle(Punkt3D b) {
float Punkt3D::calcAngle(Punkt3D b) const {
if(abs()*b.abs()==0.0f)
return 0.0f;
return rad2deg(std::acos(((*this)*b)/(abs()*b.abs())));
}
Punkt3D Punkt3D::getOrtographic() {
Punkt3D Punkt3D::getOrtographic() const {
Punkt3D erg;
if(!x) {
erg.x = 0.0f;
@ -71,7 +71,7 @@ Punkt3D Punkt3D::getOrtographic() {
return erg;
}
Punkt3D Punkt3D::getOrtographic2() {
Punkt3D Punkt3D::getOrtographic2() const {
Punkt3D nullvec;
Punkt3D erg;
erg.set(y, -x, 0.0f);
@ -84,13 +84,13 @@ Punkt3D Punkt3D::getOrtographic2() {
return erg;
}
void Punkt3D::print(std::string coordname) {
void Punkt3D::print(std::string coordname) const {
if(coordname!="")
coordname.append(" ");
std::cout << coordname << "Coord: (" << x << ", " << y << ", " << z << ")" << std::endl;
}
Punkt3D Punkt3D::operator+(const Punkt3D &b) {
Punkt3D Punkt3D::operator+(const Punkt3D &b) const {
Punkt3D c;
c.x = x + b.x;
c.y = y + b.y;
@ -99,7 +99,7 @@ Punkt3D Punkt3D::operator+(const Punkt3D &b) {
return c;
}
Punkt3D Punkt3D::operator-(const Punkt3D &b) {
Punkt3D Punkt3D::operator-(const Punkt3D &b) const {
Punkt3D c;
c.x = x - b.x;
c.y = y - b.y;
@ -124,19 +124,19 @@ Punkt3D& Punkt3D::operator-=(const Punkt3D &b) {
return *this;
}
Punkt3D Punkt3D::operator+(const float &_m) {
Punkt3D Punkt3D::operator+(const float &_m) const {
return Punkt3D(x+_m, y+_m, z+_m);
}
Punkt3D Punkt3D::operator-(const float &_m) {
Punkt3D Punkt3D::operator-(const float &_m) const {
return Punkt3D(x-_m, y-_m, z-_m);
}
Punkt3D Punkt3D::operator*(const float &_m) {
Punkt3D Punkt3D::operator*(const float &_m) const {
return Punkt3D(x*_m, y*_m, z*_m);
}
Punkt3D Punkt3D::operator/(const float &_m) {
Punkt3D Punkt3D::operator/(const float &_m) const {
return Punkt3D(x/_m, y/_m, z/_m);
}
@ -165,18 +165,18 @@ Punkt3D& Punkt3D::operator/=(const float &_m) {
return *this;
}
float Punkt3D::operator*(const Punkt3D& _m) {
float Punkt3D::operator*(const Punkt3D& _m) const {
return x * _m.x + y * _m.y + z * _m.z;
}
Punkt3D Punkt3D::operator-() {
Punkt3D Punkt3D::operator-() const {
return Punkt3D(-x, -y, -z);
}
bool Punkt3D::operator==(const Punkt3D& b) {
bool Punkt3D::operator==(const Punkt3D& b) const {
return ( x==b.x && y==b.y && z==b.z);
}
bool Punkt3D::operator!=(const Punkt3D& b) {
bool Punkt3D::operator!=(const Punkt3D& b) const {
return !(*this==b);
}
@ -204,46 +204,46 @@ std::ostream &operator<<(std::ostream &ostr, const segl::Punkt3D &r) {
} // namespace segl
float abs(segl::Punkt3D p) {
float abs(const segl::Punkt3D &p) {
return p.abs();
}
// OpenGL Funktionen f<>r Punkt3D
void glVertex3f(segl::Punkt3D p) {
void glVertex3f(const segl::Punkt3D &p) {
glVertex3f(p.x, p.y, p.z);
}
void glTranslatef(segl::Punkt3D p) {
void glTranslatef(const segl::Punkt3D &p) {
glTranslatef(p.x, p.y, p.z);
}
void glNormal3f(segl::Punkt3D p) {
void glNormal3f(const segl::Punkt3D &p) {
glNormal3f(p.x, p.y, p.z);
}
void glRotatef(float deg, segl::Punkt3D vec) {
void glRotatef(const float &deg, const segl::Punkt3D &vec) {
glRotatef(deg, vec.x, vec.y, vec.z);
}
// Funktionen mit richtgen bezeichnern
void glVertexP3D(segl::Punkt3D p) {
void glVertexP3D(const segl::Punkt3D &p) {
glVertex3f(p.x, p.y, p.z);
}
void glTranslateP3D(segl::Punkt3D p) {
void glTranslateP3D(const segl::Punkt3D &p) {
glTranslatef(p.x, p.y, p.z);
}
void glNormalP3D(segl::Punkt3D p) {
void glNormalP3D(const segl::Punkt3D &p) {
glNormal3f(p.x, p.y, p.z);
}
void glRotateP3D(float deg, segl::Punkt3D vec) {
void glRotateP3D(const float &deg, const segl::Punkt3D &vec) {
glRotatef(deg, vec.x, vec.y, vec.z);
}
void gluLookAt(segl::Punkt3D pos, segl::Punkt3D viewport, segl::Punkt3D normal) {
void gluLookAt(const segl::Punkt3D &pos, const segl::Punkt3D &viewport, const segl::Punkt3D &normal) {
gluLookAt( pos.x, pos.y, pos.z,
viewport.x, viewport.y, viewport.z,
normal.x, normal.y, normal.z );

@ -16,39 +16,39 @@ class Punkt3D {
float x, y, z;
void set(float, float, float);
float abs();
Punkt3D kreuzprodukt(const Punkt3D&);
float abs() const;
Punkt3D kreuzprodukt(const Punkt3D&) const;
void normalize();
Punkt3D getNormalized();
bool isNormalized();
float calcAngle(Punkt3D);
Punkt3D getOrtographic();
Punkt3D getOrtographic2();
Punkt3D getNormalized() const;
bool isNormalized() const;
float calcAngle(Punkt3D b) const;
Punkt3D getOrtographic() const;
Punkt3D getOrtographic2() const;
void print(std::string="");
void print(std::string="") const;
// Operatoren
Punkt3D operator+(const Punkt3D&);
Punkt3D operator-(const Punkt3D&);
Punkt3D operator+(const Punkt3D&) const;
Punkt3D operator-(const Punkt3D&) const;
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&) const;
Punkt3D operator-(const float&) const;
Punkt3D operator*(const float&) const;
Punkt3D operator/(const float&) const;
Punkt3D& operator+=(const float&);
Punkt3D& operator-=(const float&);
Punkt3D& operator*=(const float&);
Punkt3D& operator/=(const float&);
float operator*(const Punkt3D&);
float operator*(const Punkt3D&) const;
Punkt3D operator-();
Punkt3D operator-() const;
bool operator==(const Punkt3D&);
bool operator!=(const Punkt3D&);
bool operator==(const Punkt3D&) const;
bool operator!=(const Punkt3D&) const;
friend Punkt3D operator+(const float&, const Punkt3D&);
friend Punkt3D operator-(const float&, const Punkt3D&);
@ -59,22 +59,22 @@ class Punkt3D {
} // namespace segl
float abs(segl::Punkt3D);
float abs(const segl::Punkt3D&);
// OpenGL-Functions for Punkt3D
void glVertex3f(segl::Punkt3D);
void glTranslatef(segl::Punkt3D);
void glNormal3f(segl::Punkt3D);
void glVertex3f(const segl::Punkt3D&);
void glTranslatef(const segl::Punkt3D&);
void glNormal3f(const segl::Punkt3D&);
void glRotatef(float, segl::Punkt3D);
void glRotatef(const float&, const segl::Punkt3D&);
// Funktionen mit richtgen bezeichnern
void glVertexP3D(segl::Punkt3D);
void glTranslateP3D(segl::Punkt3D);
void glNormalP3D(segl::Punkt3D);
void glVertexP3D(const segl::Punkt3D&);
void glTranslateP3D(const segl::Punkt3D&);
void glNormalP3D(const segl::Punkt3D&);
void glRotateP3D(float, segl::Punkt3D);
void gluLookAt(segl::Punkt3D pos, segl::Punkt3D viewport, segl::Punkt3D normal);
void glRotateP3D(const float&, const segl::Punkt3D&);
void gluLookAt(const segl::Punkt3D &pos, const segl::Punkt3D &viewport, const segl::Punkt3D &normal);
#endif

Loading…
取消
儲存