diff --git a/geotypes.cpp b/geotypes.cpp index 79f0f7b..8bd60f1 100644 --- a/geotypes.cpp +++ b/geotypes.cpp @@ -51,7 +51,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 { @@ -263,6 +263,22 @@ bool Plane::collision(const Plane &p) const { 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 { return 0.0f; } diff --git a/geotypes.h b/geotypes.h index c2037fd..fd6bb42 100644 --- a/geotypes.h +++ b/geotypes.h @@ -103,6 +103,8 @@ class Plane { bool collision(const Box & b) 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; };