Browse Source

Fixed raycasts.

Lasse Öörni 13 years ago
parent
commit
42f8b7854d
3 changed files with 56 additions and 39 deletions
  1. 19 14
      Engine/Graphics/CustomGeometry.cpp
  2. 19 14
      Engine/Graphics/StaticModel.cpp
  3. 18 11
      Engine/Graphics/TerrainPatch.cpp

+ 19 - 14
Engine/Graphics/CustomGeometry.cpp

@@ -90,29 +90,34 @@ void CustomGeometry::ProcessRayQuery(const RayOctreeQuery& query, PODVector<RayQ
         {
             if (level == RAY_TRIANGLE)
             {
-                // After a pretest using the OBB, do the actual test using triangle geometry
-                unsigned i = 0;
-                while (i < batches_.Size())
+                for (unsigned i = 0; i < batches_.Size(); ++i)
                 {
-                    Geometry* geometry = batches_[i++].geometry_;
+                    Geometry* geometry = batches_[i].geometry_;
                     if (geometry)
                     {
                         distance = geometry->GetHitDistance(localRay);
                         if (distance <= query.maxDistance_)
+                        {
+                            RayQueryResult result;
+                            result.drawable_ = this;
+                            result.node_ = node_;
+                            result.distance_ = distance;
+                            result.subObject_ = M_MAX_UNSIGNED;
+                            results.Push(result);
                             break;
+                        }
                     }
                 }
-                if (i == batches_.Size())
-                    break;
             }
-            
-            // If the code reaches here then we have a hit
-            RayQueryResult result;
-            result.drawable_ = this;
-            result.node_ = node_;
-            result.distance_ = distance;
-            result.subObject_ = M_MAX_UNSIGNED;
-            results.Push(result);
+            else
+            {
+                RayQueryResult result;
+                result.drawable_ = this;
+                result.node_ = node_;
+                result.distance_ = distance;
+                result.subObject_ = M_MAX_UNSIGNED;
+                results.Push(result);
+            }
         }
         break;
     }

+ 19 - 14
Engine/Graphics/StaticModel.cpp

@@ -91,29 +91,34 @@ void StaticModel::ProcessRayQuery(const RayOctreeQuery& query, PODVector<RayQuer
         {
             if (level == RAY_TRIANGLE)
             {
-                // After a pretest using the OBB, do the actual test using triangle geometry
-                unsigned i = 0;
-                while (i < batches_.Size())
+                for (unsigned i = 0; i < batches_.Size(); ++i)
                 {
-                    Geometry* geometry = batches_[i++].geometry_;
+                    Geometry* geometry = batches_[i].geometry_;
                     if (geometry)
                     {
                         distance = geometry->GetHitDistance(localRay);
                         if (distance <= query.maxDistance_)
+                        {
+                            RayQueryResult result;
+                            result.drawable_ = this;
+                            result.node_ = node_;
+                            result.distance_ = distance;
+                            result.subObject_ = M_MAX_UNSIGNED;
+                            results.Push(result);
                             break;
+                        }
                     }
                 }
-                if (i == batches_.Size())
-                    break;
             }
-            
-            // If the code reaches here then we have a hit
-            RayQueryResult result;
-            result.drawable_ = this;
-            result.node_ = node_;
-            result.distance_ = distance;
-            result.subObject_ = M_MAX_UNSIGNED;
-            results.Push(result);
+            else
+            {
+                RayQueryResult result;
+                result.drawable_ = this;
+                result.node_ = node_;
+                result.distance_ = distance;
+                result.subObject_ = M_MAX_UNSIGNED;
+                results.Push(result);
+            }
         }
         break;
     }

+ 18 - 11
Engine/Graphics/TerrainPatch.cpp

@@ -92,20 +92,27 @@ void TerrainPatch::ProcessRayQuery(const RayOctreeQuery& query, PODVector<RayQue
         {
             if (level == RAY_TRIANGLE)
             {
-                // Ater a pretest using the OBB, do the actual test using triangle geometry
                 distance = geometry_->GetHitDistance(localRay);
-                
-                if (distance > query.maxDistance_)
+                if (distance <= query.maxDistance_)
+                {
+                    RayQueryResult result;
+                    result.drawable_ = this;
+                    result.node_ = node_;
+                    result.distance_ = distance;
+                    result.subObject_ = M_MAX_UNSIGNED;
+                    results.Push(result);
                     break;
+                }
+            }
+            else
+            {
+                RayQueryResult result;
+                result.drawable_ = this;
+                result.node_ = node_;
+                result.distance_ = distance;
+                result.subObject_ = M_MAX_UNSIGNED;
+                results.Push(result);
             }
-            
-            // If the code reaches here then we have a hit
-            RayQueryResult result;
-            result.drawable_ = this;
-            result.node_ = node_;
-            result.distance_ = distance;
-            result.subObject_ = M_MAX_UNSIGNED;
-            results.Push(result);
         }
         break;
     }