Added new collision functions for geotypes
This commit is contained in:
parent
1442cf02d5
commit
5549d90aca
18
geotypes.cpp
18
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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue