Added new collision functions for geotypes

This commit is contained in:
seba 2009-09-25 03:15:38 +02:00
parent 1442cf02d5
commit 5549d90aca
2 changed files with 19 additions and 1 deletions

View File

@ -51,7 +51,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 {
@ -263,6 +263,22 @@ bool Plane::collision(const Plane &p) const {
return true; return true;
} }
bool Plane::onPlane(const Punkt3D &p) const {
return dist(p) == 0.0f;
}
bool Plane::getIntersectionPoint(const Ray &r, Punkt3D *p) const {
if(r.dir.calcAngle(norm) && !onPlane(r.pos))
return false;
if(!p)
return true;
float param = (pos*norm - r.pos*norm) / (r.dir*norm);
*p = r.get(param);
return true;
}
float Plane::dist(Punkt3D p) const { float Plane::dist(Punkt3D p) const {
return 0.0f; return 0.0f;
} }

View File

@ -103,6 +103,8 @@ class Plane {
bool collision(const Box & b) const; bool collision(const Box & b) const;
bool collision(const Plane &p) const; bool collision(const Plane &p) const;
bool onPlane(const Punkt3D &p) const;
bool getIntersectionPoint(const Ray &r, Punkt3D *p) const;
float dist(Punkt3D p) const; float dist(Punkt3D p) const;
}; };