Browse Source

Added new collision functions for geotypes

seba 10 years ago
parent
commit
5549d90aca
2 changed files with 19 additions and 1 deletions
  1. 17
    1
      geotypes.cpp
  2. 2
    0
      geotypes.h

+ 17
- 1
geotypes.cpp View File

@@ -51,7 +51,7 @@ bool Sphere::collision(const Box & b) const {
51 51
 }
52 52
 
53 53
 bool Sphere::collision(const Plane &p) const {
54
-	return true;
54
+	return p.dist(pos) <= radius;
55 55
 }
56 56
 
57 57
 bool Sphere::inSphere(Punkt3D p) const {
@@ -263,6 +263,22 @@ bool Plane::collision(const Plane &p) const {
263 263
 	return true;
264 264
 }
265 265
 
266
+bool Plane::onPlane(const Punkt3D &p) const {
267
+	return dist(p) == 0.0f;
268
+}
269
+
270
+bool Plane::getIntersectionPoint(const Ray &r, Punkt3D *p) const {
271
+	if(r.dir.calcAngle(norm) && !onPlane(r.pos))
272
+		return false;
273
+	
274
+	if(!p)
275
+		return true;
276
+	
277
+	float param = (pos*norm - r.pos*norm) / (r.dir*norm);
278
+	*p = r.get(param);
279
+	return true;
280
+}
281
+
266 282
 float Plane::dist(Punkt3D p) const {
267 283
 	return 0.0f;
268 284
 }

+ 2
- 0
geotypes.h View File

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

Loading…
Cancel
Save