Browse Source

Simplify hit search as now the list is ordered.

Godzil 4 years ago
parent
commit
be6b472472
1 changed files with 4 additions and 13 deletions
  1. 4 13
      source/intersect.cpp

+ 4 - 13
source/intersect.cpp

@@ -55,21 +55,12 @@ void Intersect::add(Intersection i)
 Intersection Intersect::hit()
 {
     int i;
-    double minHit = DBL_MAX;
-    uint32_t curHit = -1;
-    for(i = 0; i < this->num; i++)
-    {
-        if ((this->list[i]->t >= 0) && (this->list[i]->t < minHit))
-        {
-            curHit = i;
-            minHit = this->list[i]->t;
-        }
-    }
 
-    if (curHit == -1)
+    for(i = 0; i < this->num; i++)
     {
-        return Intersection(0, nullptr);
+        if (this->list[i]->t >= 0)
+            return *this->list[i];
     }
 
-    return *this->list[curHit];
+    return Intersection(0, nullptr);
 }