Browse Source

Fixed infinite raycast returning results that were not hit by the ray.

Lasse Öörni 12 years ago
parent
commit
3f3d63280c

+ 4 - 4
Engine/Graphics/AnimatedModel.cpp

@@ -132,7 +132,7 @@ void AnimatedModel::ProcessRayQuery(const RayOctreeQuery& query, PODVector<RayQu
     }
 
     // Check ray hit distance to AABB before proceeding with bone-level tests
-    if (query.ray_.HitDistance(GetWorldBoundingBox()) > query.maxDistance_)
+    if (query.ray_.HitDistance(GetWorldBoundingBox()) >= query.maxDistance_)
         return;
 
     const Vector<Bone>& bones = skeleton_.GetBones();
@@ -153,7 +153,7 @@ void AnimatedModel::ProcessRayQuery(const RayOctreeQuery& query, PODVector<RayQu
             const BoundingBox& box = bone.boundingBox_;
             const Matrix3x4& transform = bone.node_->GetWorldTransform();
             distance = query.ray_.HitDistance(box.Transformed(transform));
-            if (distance > query.maxDistance_)
+            if (distance >= query.maxDistance_)
                 continue;
             if (level != RAY_AABB)
             {
@@ -161,7 +161,7 @@ void AnimatedModel::ProcessRayQuery(const RayOctreeQuery& query, PODVector<RayQu
                 Matrix3x4 inverse = transform.Inverse();
                 Ray localRay(inverse * query.ray_.origin_, inverse * Vector4(query.ray_.direction_, 0.0f));
                 distance = localRay.HitDistance(box);
-                if (distance > query.maxDistance_)
+                if (distance >= query.maxDistance_)
                     continue;
             }
         }
@@ -170,7 +170,7 @@ void AnimatedModel::ProcessRayQuery(const RayOctreeQuery& query, PODVector<RayQu
             boneSphere.center_ = bone.node_->GetWorldPosition();
             boneSphere.radius_ = bone.radius_;
             distance = query.ray_.HitDistance(boneSphere);
-            if (distance > query.maxDistance_)
+            if (distance >= query.maxDistance_)
                 continue;
         }
         else

+ 2 - 2
Engine/Graphics/CustomGeometry.cpp

@@ -85,7 +85,7 @@ void CustomGeometry::ProcessRayQuery(const RayOctreeQuery& query, PODVector<RayQ
         Matrix3x4 inverse(node_->GetWorldTransform().Inverse());
         Ray localRay(inverse * query.ray_.origin_, inverse * Vector4(query.ray_.direction_, 0.0f));
         float distance = localRay.HitDistance(boundingBox_);
-        if (distance <= query.maxDistance_)
+        if (distance < query.maxDistance_)
         {
             if (level == RAY_TRIANGLE)
             {
@@ -95,7 +95,7 @@ void CustomGeometry::ProcessRayQuery(const RayOctreeQuery& query, PODVector<RayQ
                     if (geometry)
                     {
                         distance = geometry->GetHitDistance(localRay);
-                        if (distance <= query.maxDistance_)
+                        if (distance < query.maxDistance_)
                         {
                             RayQueryResult result;
                             result.drawable_ = this;

+ 1 - 1
Engine/Graphics/Drawable.cpp

@@ -112,7 +112,7 @@ void Drawable::OnSetEnabled()
 void Drawable::ProcessRayQuery(const RayOctreeQuery& query, PODVector<RayQueryResult>& results)
 {
     float distance = query.ray_.HitDistance(GetWorldBoundingBox());
-    if (distance <= query.maxDistance_)
+    if (distance < query.maxDistance_)
     {
         RayQueryResult result;
         result.drawable_ = this;

+ 3 - 3
Engine/Graphics/Light.cpp

@@ -176,7 +176,7 @@ void Light::ProcessRayQuery(const RayOctreeQuery& query, PODVector<RayQueryResul
             Matrix3x4 inverse(node_->GetWorldTransform().Inverse());
             Ray localRay(inverse * query.ray_.origin_, inverse * Vector4(query.ray_.direction_, 0.0f));
             distance = localRay.HitDistance(GetWorldBoundingBox().Transformed(inverse));
-            if (distance > query.maxDistance_)
+            if (distance >= query.maxDistance_)
                 return;
         }
         break;
@@ -185,13 +185,13 @@ void Light::ProcessRayQuery(const RayOctreeQuery& query, PODVector<RayQueryResul
         if (lightType_ == LIGHT_SPOT)
         {
             distance = query.ray_.HitDistance(GetFrustum());
-            if (distance > query.maxDistance_)
+            if (distance >= query.maxDistance_)
                 return;
         }
         else // if (lightType_ == LIGHT_POINT)
         {
             distance = query.ray_.HitDistance(Sphere(node_->GetWorldPosition(), range_));
-            if (distance > query.maxDistance_)
+            if (distance >= query.maxDistance_)
                 return;
         }
         break;

+ 3 - 3
Engine/Graphics/Octree.cpp

@@ -277,7 +277,7 @@ void Octant::GetDrawablesInternal(OctreeQuery& query, bool inside) const
 void Octant::GetDrawablesInternal(RayOctreeQuery& query) const
 {
     float octantDist = query.ray_.HitDistance(cullingBox_);
-    if (octantDist > query.maxDistance_)
+    if (octantDist >= query.maxDistance_)
         return;
     
     if (drawables_.Size())
@@ -304,7 +304,7 @@ void Octant::GetDrawablesInternal(RayOctreeQuery& query) const
 void Octant::GetDrawablesOnlyInternal(RayOctreeQuery& query, PODVector<Drawable*>& drawables) const
 {
     float octantDist = query.ray_.HitDistance(cullingBox_);
-    if (octantDist > query.maxDistance_)
+    if (octantDist >= query.maxDistance_)
         return;
     
     if (drawables_.Size())
@@ -510,7 +510,7 @@ void Octree::RaycastSingle(RayOctreeQuery& query) const
     for (PODVector<Drawable*>::Iterator i = rayQueryDrawables_.Begin(); i != rayQueryDrawables_.End(); ++i)
     {
         Drawable* drawable = *i;
-        if (drawable->GetSortValue() <= Min(closestHit, query.maxDistance_))
+        if (drawable->GetSortValue() < Min(closestHit, query.maxDistance_))
         {
             unsigned oldSize = query.result_.Size();
             drawable->ProcessRayQuery(query, query.result_);

+ 2 - 2
Engine/Graphics/StaticModel.cpp

@@ -86,7 +86,7 @@ void StaticModel::ProcessRayQuery(const RayOctreeQuery& query, PODVector<RayQuer
         Matrix3x4 inverse(node_->GetWorldTransform().Inverse());
         Ray localRay(inverse * query.ray_.origin_, inverse * Vector4(query.ray_.direction_, 0.0f));
         float distance = localRay.HitDistance(boundingBox_);
-        if (distance <= query.maxDistance_)
+        if (distance < query.maxDistance_)
         {
             if (level == RAY_TRIANGLE)
             {
@@ -96,7 +96,7 @@ void StaticModel::ProcessRayQuery(const RayOctreeQuery& query, PODVector<RayQuer
                     if (geometry)
                     {
                         distance = geometry->GetHitDistance(localRay);
-                        if (distance <= query.maxDistance_)
+                        if (distance < query.maxDistance_)
                         {
                             RayQueryResult result;
                             result.drawable_ = this;

+ 2 - 2
Engine/Graphics/TerrainPatch.cpp

@@ -87,12 +87,12 @@ void TerrainPatch::ProcessRayQuery(const RayOctreeQuery& query, PODVector<RayQue
         Matrix3x4 inverse(node_->GetWorldTransform().Inverse());
         Ray localRay(inverse * query.ray_.origin_, inverse * Vector4(query.ray_.direction_, 0.0f));
         float distance = localRay.HitDistance(boundingBox_);
-        if (distance <= query.maxDistance_)
+        if (distance < query.maxDistance_)
         {
             if (level == RAY_TRIANGLE)
             {
                 distance = geometry_->GetHitDistance(localRay);
-                if (distance <= query.maxDistance_)
+                if (distance < query.maxDistance_)
                 {
                     RayQueryResult result;
                     result.drawable_ = this;