Browse Source

Fixed sphere-ray collision

Sebastian 10 years ago
parent
commit
1442cf02d5
1 changed files with 4 additions and 5 deletions
  1. 4
    5
      geotypes.cpp

+ 4
- 5
geotypes.cpp View File

@@ -65,14 +65,13 @@ Punkt3D Sphere::getPos() const {
65 65
 int Sphere::getIntersectionParam(const Ray &ray, float *param1, float *param2) {
66 66
 	int numerg;
67 67
 	// ax^2 + bx + c = 0
68
-	segl::Punkt3D ehv(1.0f, 1.0f, 1.0f);
69
-	float a = ray.dir*ehv;
70
-	float b = 2*(ray.pos*ehv + pos*ehv);
71
-	float c = ray.pos*ray.pos + pos*pos - 2*(ray.pos*pos) - radius*radius;
68
+	float a = ray.dir * ray.dir;
69
+	float b = 2 * ray.dir * (ray.pos - pos);
70
+	float c = ray.pos * ray.pos - 2 * ray.pos * pos + pos * pos - radius * radius;
72 71
 	
73 72
 	float p = b/a;
74 73
 	float q = c/a;
75
-	
74
+	std::cout << p << " " << q << std::endl;
76 75
 	if((p*p)/4.0f<q) {
77 76
 		numerg = 0;
78 77
 	} else if((p*p)/4.0f==q) {

Loading…
Cancel
Save