neue collider, rumprobiererei mit defines

master
Sebastian преди 16 години
родител 9a8fbaf759
ревизия bff2ad312d

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

@ -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

@ -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;

@ -3,6 +3,7 @@
#include <iostream>
#include <cmath>
#include <SDL_opengl.h>
#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

@ -3,6 +3,7 @@
#include <iostream>
#include <cmath>
#include <SDL_opengl.h>
#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

Зареждане…
Отказ
Запис