From 5549d90acaa3d95eee574c99a6c23b16cf4be007 Mon Sep 17 00:00:00 2001 From: seba Date: Fri, 25 Sep 2009 03:15:38 +0200 Subject: [PATCH] Added new collision functions for geotypes --- geotypes.cpp | 18 +++++++++++++++++- geotypes.h | 2 ++ 2 files changed, 19 insertions(+), 1 deletion(-) 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; };