|
|
|
@ -1,3 +1,25 @@
|
|
|
|
|
/* libsegl - Sebas Extended GL Library
|
|
|
|
|
* Collection of Opengl/3D-Math helpers
|
|
|
|
|
*
|
|
|
|
|
* Copyright (c) 2008 by Sebastian Lohff, seba@seba-geek.de
|
|
|
|
|
* http://www.seba-geek.de
|
|
|
|
|
*
|
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
* Library General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "geotypes.h"
|
|
|
|
|
|
|
|
|
|
namespace segl {
|
|
|
|
@ -21,14 +43,7 @@ bool Sphere::collision(const Sphere &s) const {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool Sphere::collision(const Ray &r) const {
|
|
|
|
|
/*
|
|
|
|
|
// 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);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool Sphere::collision(const Box & b) const {
|
|
|
|
@ -36,7 +51,7 @@ bool Sphere::collision(const Box & b) const {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool Sphere::collision(const Plane &p) const {
|
|
|
|
|
return (p.dist(pos)<=radius);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool Sphere::inSphere(Punkt3D p) const {
|
|
|
|
@ -60,12 +75,12 @@ void Ray::set(Punkt3D _pos, Punkt3D _dir) {
|
|
|
|
|
dir = _dir;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Punkt3D Ray::get(float x) const {
|
|
|
|
|
Punkt3D Ray::get(float x) {
|
|
|
|
|
return pos + dir*x;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO: Heavy Testing
|
|
|
|
|
bool Ray::onRay(Punkt3D p, int rnd) const {
|
|
|
|
|
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;
|
|
|
|
@ -112,14 +127,14 @@ bool Ray::onRay(Punkt3D p, int rnd) const {
|
|
|
|
|
else if(g3)
|
|
|
|
|
return (r1 == r2);
|
|
|
|
|
else
|
|
|
|
|
return (r1 == r2 && r1 == r3);
|
|
|
|
|
return (r1 == r2 == r3);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float Ray::dist(Punkt3D p) const {
|
|
|
|
|
float Ray::dist(Punkt3D p) {
|
|
|
|
|
return abs(p - get( getParam(p) ));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float Ray::getParam(Punkt3D p, bool onray) const {
|
|
|
|
|
float Ray::getParam(Punkt3D p, bool onray) {
|
|
|
|
|
if(onray) {
|
|
|
|
|
if(!onRay(p))
|
|
|
|
|
return 0.0f;
|
|
|
|
@ -200,7 +215,7 @@ bool Plane::collision(const Plane &p) const {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float Plane::dist(Punkt3D p) const {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace segl
|
|
|
|
|