neue collider, rumprobiererei mit defines

This commit is contained in:
Sebastian 2008-10-14 12:59:39 +02:00
parent 9a8fbaf759
commit bff2ad312d
5 changed files with 26 additions and 16 deletions

View File

@ -3,7 +3,6 @@
#include <iostream> #include <iostream>
#include <cmath> #include <cmath>
#include <SDL_opengl.h>
namespace segl { namespace segl {

View File

@ -21,7 +21,14 @@ bool Sphere::collision(const Sphere &s) const {
} }
bool Sphere::collision(const Ray &r) 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 { 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 { bool Sphere::collision(const Plane &p) const {
return true; return (p.dist(pos)<=radius);
} }
bool Sphere::inSphere(Punkt3D p) const { bool Sphere::inSphere(Punkt3D p) const {
@ -53,12 +60,12 @@ void Ray::set(Punkt3D _pos, Punkt3D _dir) {
dir = _dir; dir = _dir;
} }
Punkt3D Ray::get(float x) { Punkt3D Ray::get(float x) const {
return pos + dir*x; return pos + dir*x;
} }
// TODO: Heavy Testing // 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; float r1 = 0.0f, r2 = 0.0f, r3 = 0.0f;
short fcount = 0; short fcount = 0;
bool g1=true, g2=true, g3=true; bool g1=true, g2=true, g3=true;
@ -105,14 +112,14 @@ bool Ray::onRay(Punkt3D p, int rnd) {
else if(g3) else if(g3)
return (r1 == r2); return (r1 == r2);
else 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) )); 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) {
if(!onRay(p)) if(!onRay(p))
return 0.0f; return 0.0f;
@ -193,7 +200,7 @@ bool Plane::collision(const Plane &p) const {
} }
float Plane::dist(Punkt3D p) const { float Plane::dist(Punkt3D p) const {
} }
} // namespace segl } // namespace segl

View File

@ -5,6 +5,7 @@
namespace segl { namespace segl {
class Sphere;
class Ray; class Ray;
class Box; class Box;
class Plane; class Plane;
@ -38,10 +39,10 @@ class Ray {
Ray(Punkt3D _pos, Punkt3D _dir); Ray(Punkt3D _pos, Punkt3D _dir);
void set(Punkt3D _pos, Punkt3D _dir); void set(Punkt3D _pos, Punkt3D _dir);
Punkt3D get(float x); Punkt3D get(float x) const;
bool onRay(Punkt3D p, int rnd=-1); bool onRay(Punkt3D p, int rnd=-1) const;
float dist(Punkt3D p); float dist(Punkt3D p) const;
float getParam(Punkt3D p, bool onray=false); float getParam(Punkt3D p, bool onray=false) const;
bool collision(const Sphere &s) const; bool collision(const Sphere &s) const;
bool collision(const Ray &r) const; bool collision(const Ray &r) const;

View File

@ -3,6 +3,7 @@
#include <iostream> #include <iostream>
#include <cmath> #include <cmath>
#include <SDL_opengl.h>
#include "emath.h" #include "emath.h"
namespace segl { namespace segl {
@ -53,12 +54,13 @@ class Punkt2D {
} // namespace segl } // namespace segl
// #ifdef GLAPI
void glTexCoord2f(segl::Punkt2D); void glTexCoord2f(segl::Punkt2D);
float abs(segl::Punkt2D); float abs(segl::Punkt2D);
// Fixed Headers // Fixed Headers
void glTexCoordP2D(segl::Punkt2D p); void glTexCoordP2D(segl::Punkt2D p);
// #endif /* GLAPI */
#endif #endif

View File

@ -3,6 +3,7 @@
#include <iostream> #include <iostream>
#include <cmath> #include <cmath>
#include <SDL_opengl.h>
#include "emath.h" #include "emath.h"
namespace segl { namespace segl {
@ -62,7 +63,7 @@ class Punkt3D {
float abs(const segl::Punkt3D&); float abs(const segl::Punkt3D&);
// OpenGL-Functions for Punkt3D // OpenGL-Functions for Punkt3D
// #ifdef GLAPI
void glVertex3f(const segl::Punkt3D&); void glVertex3f(const segl::Punkt3D&);
void glTranslatef(const segl::Punkt3D&); void glTranslatef(const segl::Punkt3D&);
void glNormal3f(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 glRotateP3D(const float&, const segl::Punkt3D&);
void gluLookAt(const segl::Punkt3D &pos, const segl::Punkt3D &viewport, const segl::Punkt3D &normal); void gluLookAt(const segl::Punkt3D &pos, const segl::Punkt3D &viewport, const segl::Punkt3D &normal);
// #endif /* GLAPI */
#endif #endif