From bff2ad312de404454e9413a9cd93ea861387a1eb Mon Sep 17 00:00:00 2001 From: Sebastian Date: Tue, 14 Oct 2008 12:59:39 +0200 Subject: [PATCH] neue collider, rumprobiererei mit defines --- emath.h | 1 - geotypes.cpp | 23 +++++++++++++++-------- geotypes.h | 9 +++++---- punkt2d.h | 4 +++- punkt3d.h | 5 +++-- 5 files changed, 26 insertions(+), 16 deletions(-) diff --git a/emath.h b/emath.h index 45047e8..6dd2af7 100644 --- a/emath.h +++ b/emath.h @@ -3,7 +3,6 @@ #include #include -#include namespace segl { diff --git a/geotypes.cpp b/geotypes.cpp index 84f8d5f..c17f03a 100644 --- a/geotypes.cpp +++ b/geotypes.cpp @@ -21,7 +21,14 @@ bool Sphere::collision(const Sphere &s) const { } bool Sphere::collision(const Ray &r) const { - return true; + /* + // way more complex (i think), maybe usefull to calc the collpoints + const float bsum = r.dir.x + r.dir.y + r.dir.z; + float p = (2.0f*(r.pos*r.dir)-pos*r.dir) / bsum; + float q = (r.pos*r.pos-2.0f*r.pos*pos+pos*pos-radius*radius) / bsum; + return (p*p/4.0f-q >= 0.0f); + */ + return (r.dist(pos)<=radius); } bool Sphere::collision(const Box & b) const { @@ -29,7 +36,7 @@ bool Sphere::collision(const Box & b) const { } bool Sphere::collision(const Plane &p) const { - return true; + return (p.dist(pos)<=radius); } bool Sphere::inSphere(Punkt3D p) const { @@ -53,12 +60,12 @@ void Ray::set(Punkt3D _pos, Punkt3D _dir) { dir = _dir; } -Punkt3D Ray::get(float x) { +Punkt3D Ray::get(float x) const { return pos + dir*x; } // TODO: Heavy Testing -bool Ray::onRay(Punkt3D p, int rnd) { +bool Ray::onRay(Punkt3D p, int rnd) const { float r1 = 0.0f, r2 = 0.0f, r3 = 0.0f; short fcount = 0; bool g1=true, g2=true, g3=true; @@ -105,14 +112,14 @@ bool Ray::onRay(Punkt3D p, int rnd) { else if(g3) return (r1 == r2); else - return (r1 == r2 == r3); + return (r1 == r2 && r1 == r3); } -float Ray::dist(Punkt3D p) { +float Ray::dist(Punkt3D p) const { return abs(p - get( getParam(p) )); } -float Ray::getParam(Punkt3D p, bool onray) { +float Ray::getParam(Punkt3D p, bool onray) const { if(onray) { if(!onRay(p)) return 0.0f; @@ -193,7 +200,7 @@ bool Plane::collision(const Plane &p) const { } float Plane::dist(Punkt3D p) const { - + } } // namespace segl diff --git a/geotypes.h b/geotypes.h index 7deb7c4..8e9e824 100644 --- a/geotypes.h +++ b/geotypes.h @@ -5,6 +5,7 @@ namespace segl { +class Sphere; class Ray; class Box; class Plane; @@ -38,10 +39,10 @@ class Ray { Ray(Punkt3D _pos, Punkt3D _dir); 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); + Punkt3D get(float x) const; + bool onRay(Punkt3D p, int rnd=-1) const; + float dist(Punkt3D p) const; + float getParam(Punkt3D p, bool onray=false) const; bool collision(const Sphere &s) const; bool collision(const Ray &r) const; diff --git a/punkt2d.h b/punkt2d.h index 52e68a9..1bb5580 100644 --- a/punkt2d.h +++ b/punkt2d.h @@ -3,6 +3,7 @@ #include #include +#include #include "emath.h" namespace segl { @@ -53,12 +54,13 @@ class Punkt2D { } // namespace segl +// #ifdef GLAPI void glTexCoord2f(segl::Punkt2D); float abs(segl::Punkt2D); // Fixed Headers void glTexCoordP2D(segl::Punkt2D p); - +// #endif /* GLAPI */ #endif diff --git a/punkt3d.h b/punkt3d.h index 6363c89..139e2ae 100644 --- a/punkt3d.h +++ b/punkt3d.h @@ -3,6 +3,7 @@ #include #include +#include #include "emath.h" namespace segl { @@ -62,7 +63,7 @@ class Punkt3D { float abs(const segl::Punkt3D&); // OpenGL-Functions for Punkt3D - +// #ifdef GLAPI void glVertex3f(const segl::Punkt3D&); void glTranslatef(const segl::Punkt3D&); void glNormal3f(const segl::Punkt3D&); @@ -76,5 +77,5 @@ void glNormalP3D(const segl::Punkt3D&); void glRotateP3D(const float&, const segl::Punkt3D&); void gluLookAt(const segl::Punkt3D &pos, const segl::Punkt3D &viewport, const segl::Punkt3D &normal); - +// #endif /* GLAPI */ #endif