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